OfSoundStream - get buffer length from device

Hi,
is it possible to retrieve the settings (buffer, sample rate etc.) from the audio device?

the audio examples in OF show buffer length defined ahead of time, hard coded in the program. I had been working this way and it worked fine until I changed my ASIO driver today.

I have a audio-event timing things running in the audio thread, and now if my ASIO driver is not set to the same buffer length I hard-coded in the program, audio events either speed up or slow down - presumably because the device is not using the buffer length requested by OF.

I have reasons to want to use this new driver, so is it possible to retrieve the settings (buffer, sample rate etc.) from the device so I can set the buffer length correctly on startup and make sure my audio event timing is correct regardless of the device’s buffer length?

Thanks

What you are askinkg for is not implemented but it is really easy if you want to modify some core stuff.
openFrameworks uses RTAudio to deal with all the sound hardware across all the supported OSs.
The following line is where the ofSoundstream setups its internal rtAudio object. https://github.com/openframeworks/openFrameworks/blob/master/libs/openFrameworks/sound/ofRtAudioSoundStream.cpp#L178

As you can see, the bufferSize argument is passed as a pointer. This is because it will be modified if the hardware will actually use something else.
So, what you need to modify, atleast in the begining, is if bufferSize is the same as the setting you passed.
After the aforementioned line paste the following

if(bufferSize != settings.bufferSize){
	cout << "Audio hardware returned a different buffer size than the passed setting." << endl;
	cout << "Passed: " << settings.bufferSize << endl;
	cout << "Returned: " << bufferSize << endl;
}

Check rtAudio’s documentation here. The bufferFrames argument is the one we are talking about.

1 Like

Thanks Roy - that’s really helpful

1 Like