av/audio/pcm/pcm_test.go

39 lines
912 B
Go

package pcm
import (
"bytes"
"io/ioutil"
"log"
"testing"
)
// TestResample accepts an input pcm file (assumed to be mono and using 16-bit samples) and outputs a resampled pcm file.
// Input and output file names can be specified as arguments.
func TestResample(t *testing.T) {
inPath := "../../../test/test-data/av/input/sweep_400Hz_20000Hz_-3dBFS_5s_48khz.pcm"
expPath := "../../../test/test-data/av/output/sweep_400Hz_20000Hz_resampled_48to8kHz.pcm"
// Read input pcm.
inPcm, err := ioutil.ReadFile(inPath)
if err != nil {
log.Fatal(err)
}
// Resample pcm.
resampled, err := Resample(inPcm, 48000, 8000, 1, 16)
if err != nil {
log.Fatal(err)
}
// Read expected resampled pcm.
exp, err := ioutil.ReadFile(expPath)
if err != nil {
log.Fatal(err)
}
// Compare result with expected.
if !bytes.Equal(resampled, exp) {
t.Error("Resampled data does not match expected result.")
}
}