|
- package stdinpcm
-
- import (
- "bytes"
- "context"
- "testing"
- "time"
- )
-
- func TestSourceReadsPCMChunks(t *testing.T) {
- // Two stereo frames (S16LE): [0,0] and [32767,-32768]
- raw := []byte{
- 0x00, 0x00, 0x00, 0x00,
- 0xff, 0x7f, 0x00, 0x80,
- }
- src := New("stdin-test", bytes.NewReader(raw), 44100, 2, 2)
- if err := src.Start(context.Background()); err != nil {
- t.Fatalf("start: %v", err)
- }
- defer src.Stop()
-
- select {
- case chunk := <-src.Chunks():
- if chunk.Channels != 2 {
- t.Fatalf("channels=%d", chunk.Channels)
- }
- if len(chunk.Samples) != 4 {
- t.Fatalf("samples=%d want 4", len(chunk.Samples))
- }
- case <-time.After(1 * time.Second):
- t.Fatal("timed out waiting for chunk")
- }
- }
|