chore: establish local platform baseline
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
package media
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestValidateAudioWAVPCM16(t *testing.T) {
|
||||
content := syntheticWAV(8000, 1, 800)
|
||||
if code := validateAudio("wav_pcm_s16le", 100, content); code != "" {
|
||||
t.Fatalf("valid WAV rejected with %s", code)
|
||||
}
|
||||
if code := validateAudio("wav_pcm_s16le", 101, content); code != "DURATION_MISMATCH" {
|
||||
t.Fatalf("duration mismatch code = %s", code)
|
||||
}
|
||||
if code := validateAudio("opus", 100, content); code != "CODEC_VALIDATION_UNAVAILABLE" {
|
||||
t.Fatalf("unsupported codec code = %s", code)
|
||||
}
|
||||
}
|
||||
|
||||
func syntheticWAV(sampleRate uint32, channels uint16, samples int) []byte {
|
||||
dataSize := samples * int(channels) * 2
|
||||
content := make([]byte, 44+dataSize)
|
||||
copy(content[0:4], "RIFF")
|
||||
binary.LittleEndian.PutUint32(content[4:8], uint32(len(content)-8))
|
||||
copy(content[8:12], "WAVE")
|
||||
copy(content[12:16], "fmt ")
|
||||
binary.LittleEndian.PutUint32(content[16:20], 16)
|
||||
binary.LittleEndian.PutUint16(content[20:22], 1)
|
||||
binary.LittleEndian.PutUint16(content[22:24], channels)
|
||||
binary.LittleEndian.PutUint32(content[24:28], sampleRate)
|
||||
binary.LittleEndian.PutUint32(content[28:32], sampleRate*uint32(channels)*2)
|
||||
binary.LittleEndian.PutUint16(content[32:34], channels*2)
|
||||
binary.LittleEndian.PutUint16(content[34:36], 16)
|
||||
copy(content[36:40], "data")
|
||||
binary.LittleEndian.PutUint32(content[40:44], uint32(dataSize))
|
||||
return content
|
||||
}
|
||||
Reference in New Issue
Block a user