Skip to content
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

Getting Smooth, Synced Play and record audio on the R Pi with Sounddevice #577

Open
grondeau opened this issue Jan 20, 2025 · 0 comments
Open

Comments

@grondeau
Copy link

I am attempting to generate short sound stimulus bursts and record the results using the R Pi. Several issues have come up and been fairly well solved. these include:

  1. I'm using ultra sound so needed more than 48k sample rate. Microphones are I2S mems devices running at 64000 sps. Playback uses common USB sound card with 96000 sps. Hence the two streams are running at different sample rates. (the USB device will not run at 64k)
  2. An InputStream and OuputStream were set up for these devices with call back functions. Everything works, but it became clear that the two streams did not run at the same "real time" rate based on the expected 64k and 96k sample rates. Since I'm sending out only short bursts of sound, I found a work-around that involved shifting the "active" sound inside the "chirp block" using the timing provided by the callback functions. I also found I could 'trim the drift' by adjusting the number of frames in the block by one or two counts so the drift would either let the recording fall behind or get ahead of the playback over time.
  3. This leaves the real problem I'm left with, which is underflows on the microphone recording channel. These have been intermittent but regular on the order of one event/minute using 50ms data blocks. When looking carefully at the timing, I found that the Callback was happening almost exactly as the buffer became full. There seemed to be no allowance for any "time slop" to deal with the buffer.
  4. I also tried a blocking stream.read instead of the callback. That seems to work slightly better - maybe reducing the number or events by a factor of two or so, but it did not eliminate them. My suspicion is that operating system events are getting in the way of a timely buffer read. Any idea about what I can do to solve this. (something like a "disable interrupts" function for a microprocessor that would ensure nothing is getting in the way of my read?)

I suspect the problem may be with the I2S mic driver... I'm using this: https://github.com/PaulCreaserML/rpi-i2s-audio
Even though the mics are specified only to 64ksps, I found they will work at 96ksps. Hence I thought maybe I could use a single bidirectional stream with only one clock rate... But, trying that, I could not get the mic device to be accepted by ,if I recall, PortAudio.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant