Closed StephanVerbeeck closed 4 years ago
Hello 👋 ,
Encoding a wav is a synchronous operation. It will also call the streamers synchronously. So when it comes to done <- true
in your callback, it waits for another goroutine to receive the data but there is none. The generateNoise
is executing the wav.Encode
still and it hasn't reached the <-done
yet.
The speaker is asynchronous so you don't get this error.
The speaker is asynchronous
Thanks!, I have changed my test code accordingly and now it works
I am still not sure if this is not an inconsistency (the decoding of a file for playback being asynchronous while the encoding of a file is synchronous). I can always put the encoding in a GO routine as work-around (but does need some documenting of this fact though).
func generateNoise() {
f, err := os.Create(`output.wav`)
if err != nil {
log.Fatal(err)
}
format := beep.Format{
SampleRate: 44100,
NumChannels: 2,
Precision: 2,
}
audible := false
if audible {
done := make(chan bool)
streamer := beep.Seq(beep.Take(format.SampleRate.N(5*time.Second), &Noise{}), beep.Callback(func() {
done <- true
}))
speaker.Init(format.SampleRate, format.SampleRate.N(time.Second/10))
speaker.Play(streamer)
<-done // wait for stream to be done
} else {
streamer := beep.Seq(beep.Take(format.SampleRate.N(5*time.Second), &Noise{}))
err = wav.Encode(f, streamer, format)
if err != nil {
log.Fatal(err)
}
}
}
I was unable to locate example code or comment line that shows/documents how to use the wav encoding functionality provided by "github.com/faiface/beep/wav".
I tried to get it going without any documentation but the code does not seem to be functional? (where is the module test?)
go version go1.14.4 windows/amd64