-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
What am I doing wrong trying to encode a stream from Portaudio as a .wav? #21
Comments
I'm not in front of my computer but if I recall correctly, it doesn't seem that you are using the port audio API properly. Your buffer isn't 7s long and I believe port audio has some sort of callback mechanism when the buffer is ready to be dumped |
Also you need to close the encoder to add the right headers to the file |
did you manage to make them work together? |
This code successfully saves a wav file, but the resulting file has weird clicking in the audio. NOTE: audioFile, err := os.Create(path.Join(dir, "audio.wav"))
if err != nil {
return err
}
defer audioFile.Close()
e := wav.NewEncoder(audioFile, sampleRate, 32, 1, 1)
defer e.Close()
buf := audio.IntBuffer{
Format: audio.FormatMono44100,
SourceBitDepth: 32,
}
for _, sample := range s.Audio {
buf.Data = append(buf.Data, int(sample))
}
err = e.Write(&buf)
if err != nil {
return err
} |
The problem I was having was that I wasn't waiting until there was enough audio to fill the buffer, and that was causing samples to get recorded twice. for avail := 0; avail < len(in); avail, _ = stream.AvailableToRead() {
time.Sleep(time.Second / sampleRate * time.Duration(len(in)-avail))
} |
The only array type that portaudio and audio.IntBuffer both support is float32[]. When I run this code, nothing gets recorded. The file is silent. I don't know if this is the right place for this, but what the heck am I doing wrong? Is it something to do with converting to float32?
The text was updated successfully, but these errors were encountered: