mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 19:28:57 +01:00
audio/internal/convert: split some tests
This commit is contained in:
parent
f6c9c88f78
commit
f36ea4125d
@ -61,47 +61,49 @@ func TestStereoF32(t *testing.T) {
|
|||||||
}
|
}
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
tc := tc
|
tc := tc
|
||||||
for _, mono := range []bool{false, true} {
|
t.Run(tc.Name, func(t *testing.T) {
|
||||||
mono := mono
|
for _, mono := range []bool{false, true} {
|
||||||
t.Run(fmt.Sprintf("%s (mono=%t)", tc.Name, mono), func(t *testing.T) {
|
mono := mono
|
||||||
var inBytes, outBytes []byte
|
t.Run(fmt.Sprintf("mono=%t", mono), func(t *testing.T) {
|
||||||
for _, v := range tc.In {
|
var inBytes, outBytes []byte
|
||||||
b := math.Float32bits(v)
|
for _, v := range tc.In {
|
||||||
inBytes = append(inBytes, byte(b), byte(b>>8), byte(b>>16), byte(b>>24))
|
b := math.Float32bits(v)
|
||||||
if mono {
|
inBytes = append(inBytes, byte(b), byte(b>>8), byte(b>>16), byte(b>>24))
|
||||||
// As the source is mono, the output should be stereo.
|
if mono {
|
||||||
outBytes = append(outBytes, byte(b), byte(b>>8), byte(b>>16), byte(b>>24), byte(b), byte(b>>8), byte(b>>16), byte(b>>24))
|
// As the source is mono, the output should be stereo.
|
||||||
} else {
|
outBytes = append(outBytes, byte(b), byte(b>>8), byte(b>>16), byte(b>>24), byte(b), byte(b>>8), byte(b>>16), byte(b>>24))
|
||||||
outBytes = append(outBytes, byte(b), byte(b>>8), byte(b>>16), byte(b>>24))
|
} else {
|
||||||
}
|
outBytes = append(outBytes, byte(b), byte(b>>8), byte(b>>16), byte(b>>24))
|
||||||
}
|
|
||||||
s := convert.NewStereoF32(bytes.NewReader(inBytes), mono)
|
|
||||||
var got []byte
|
|
||||||
for {
|
|
||||||
var buf [97]byte
|
|
||||||
n, err := s.Read(buf[:])
|
|
||||||
got = append(got, buf[:n]...)
|
|
||||||
if err != nil {
|
|
||||||
if err != io.EOF {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
}
|
||||||
break
|
|
||||||
}
|
}
|
||||||
// Shifting by incomplete bytes should not affect the result.
|
s := convert.NewStereoF32(bytes.NewReader(inBytes), mono)
|
||||||
for i := 0; i < 4*2; i++ {
|
var got []byte
|
||||||
if _, err := s.Seek(int64(i), io.SeekCurrent); err != nil {
|
for {
|
||||||
|
var buf [97]byte
|
||||||
|
n, err := s.Read(buf[:])
|
||||||
|
got = append(got, buf[:n]...)
|
||||||
|
if err != nil {
|
||||||
if err != io.EOF {
|
if err != io.EOF {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
// Shifting by incomplete bytes should not affect the result.
|
||||||
|
for i := 0; i < 4*2; i++ {
|
||||||
|
if _, err := s.Seek(int64(i), io.SeekCurrent); err != nil {
|
||||||
|
if err != io.EOF {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
want := outBytes
|
||||||
want := outBytes
|
if !bytes.Equal(got, want) {
|
||||||
if !bytes.Equal(got, want) {
|
t.Errorf("got: %v, want: %v", got, want)
|
||||||
t.Errorf("got: %v, want: %v", got, want)
|
}
|
||||||
}
|
})
|
||||||
})
|
}
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user