mirror of
https://github.com/pion/mediadevices.git
synced 2025-10-05 08:36:55 +08:00
Define basic audio data interface
This commit is contained in:

committed by
Lukas Herman

parent
edc2ada757
commit
450f882c50
61
pkg/wave/wave_test.go
Normal file
61
pkg/wave/wave_test.go
Normal file
@@ -0,0 +1,61 @@
|
||||
package wave
|
||||
|
||||
import (
|
||||
"math"
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestConvert(t *testing.T) {
|
||||
cases := map[string]struct {
|
||||
in []Sample
|
||||
typ SampleFormat
|
||||
expected []Sample
|
||||
}{
|
||||
"Int16ToFloat32": {
|
||||
in: []Sample{
|
||||
Int16Sample(-0x1000),
|
||||
Int16Sample(-0x100),
|
||||
Int16Sample(0x0),
|
||||
Int16Sample(0x100),
|
||||
Int16Sample(0x1000),
|
||||
},
|
||||
typ: Float32SampleFormat,
|
||||
expected: []Sample{
|
||||
Float32Sample(-math.Pow(2, -4)),
|
||||
Float32Sample(-math.Pow(2, -8)),
|
||||
Float32Sample(0.0),
|
||||
Float32Sample(math.Pow(2, -8)),
|
||||
Float32Sample(math.Pow(2, -4)),
|
||||
},
|
||||
},
|
||||
"Float32ToInt16": {
|
||||
in: []Sample{
|
||||
Float32Sample(-math.Pow(2, -4)),
|
||||
Float32Sample(-math.Pow(2, -8)),
|
||||
Float32Sample(0.0),
|
||||
Float32Sample(math.Pow(2, -8)),
|
||||
Float32Sample(math.Pow(2, -4)),
|
||||
},
|
||||
typ: Int16SampleFormat,
|
||||
expected: []Sample{
|
||||
Int16Sample(-0x1000),
|
||||
Int16Sample(-0x100),
|
||||
Int16Sample(0x0),
|
||||
Int16Sample(0x100),
|
||||
Int16Sample(0x1000),
|
||||
},
|
||||
},
|
||||
}
|
||||
for name, c := range cases {
|
||||
c := c
|
||||
t.Run(name, func(t *testing.T) {
|
||||
for i := range c.in {
|
||||
s := c.typ.Convert(c.in[i])
|
||||
if !reflect.DeepEqual(c.expected[i], s) {
|
||||
t.Errorf("Convert result differs, expected: %v, got: %v", c.expected[i], s)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user