ofSoundBuffer corrupted last sample

Hello Everyone,

I have a little problem using ofSoundBuffer.
I’m streaming sound from a MS WASAPI microphone device through ofSoundStream.
Everything works fine except the final sample in the ofSoundBuffer is nonsense. (e.g. -8.10599937e+36).
This only occurs with a sample-rate of 44100 - so my first guess is there’s some sloppy re-sampling somewhere upstream. Anyone ever encountered something like this?


Hello @2666hz did you test with other mics too? Which platform do you use?
can you post a minimal code to reproduce your issue?

Hi @2666hz there is a bug in the resampling algorithm. So if your sound card is setup to a different sample rate than what you set the ofSoundStream with it will resample and this bug will show up.

OK. Thanks.
Now my question is - why is it resampling?
I am only ever using samplerates from ofSoundDevice.sampleRates - do these not mean that the device supports these rates “natively”? or is the device capable of these samplerates, but actually setting the native samplerate done somehow elsewhere?

The issues is that the sound device sample rate is set via the OS or some hardware specific software/control panel. As far as I can recall, OF is not capable of setting the hardware’s sample rate. Thus, when you setup OF to use a sample rate different than the one that is set to the hardware, it will need to resample. Thus, the easy way is to set up your computer’s sample rate and then use that same samplerate in openFrameworks.

not sure which platform are you in, but in macOs you can check system sample rate in an application called Audio Midi Setup

@dimitre I guess that windows because he is using MS WASAPI

1 Like

Yes - windows 10.

In my application, is there any way to get this “native” sample-rate?
Can I programmatically ensure that no re-sampling will take place?


there might be a way to get that sample rate in windows but I am not sure. I dont use windows that much.

you could but it can be quite cumbersome. Let me know if you figured this out, otherwise I can check. I can not recall it from the top of my head.