RaspberryPi recording increase buffer size

My Python program to record sound has problems with overruns.
I am using threads to do the reording and do FFT’s simultaneously. It works most of the time but there are occaisional gaps and read errors.
I am using pyalsaaudio to connect to ALSA.
I think I need a bigger input buffer to avoid the overruns, but I can’t seem to do this in pyalsaaudio. There is a method to do this - .set periodsize, but it doesn’t do anything.
Is there a way in the ALSA.config files to set a default buffer size?

Thanks!

Hi Debbie,

Thank you for posting your question about recording with the Raspberry Pi. I assume you are using our USB-Audio adapter.

I’m not at work as I answer this, but tomorrow when I am, I will check on my Raspberry Pi, and also consult with our in-house expert on the USB-Audio.

Thanks!

David
Plugable Support

I found the answer at this link:
https://bugs.launchpad.net/ubuntu/+so…

This is also relevant:
http://alsa.opensrc.org/Dmix

The ALSA docs leave a lot to the imagination, so I don’t quite see what how all these commands work, but this /etc/asound.conf file allows you to change the buffer size for both pyalsaaudio and Pyaudio.

defaults.ctl.card 0
defaults.pcm.card 0

pcm.card0 {
type hw
card 0
}

pcm.dmixer {
type dmix
ipc_key 1025
slave {
pcm “hw:0,0”
period_time 0
period_size 2048
buffer_size 32768 # change buffer
rate 48000
}
bindings {
0 0
1 1
}
}
pcm.skype {
type asym

playback.pcm “dmixer”
capture.pcm “card0”
}

pcm.!default {
type plug
slave.pcm “skype”
}

Thanks for posting the answer!

David