ofSoundStreamSetup() deprecated - what's setApi()?

Hi, I’m trying to use ofxMaxim for sample playback, which requires using ofSoundStreamSetup() to set the buffer size, sample rate etc. However, I’m getting a warning that this function is deprecated. Unfortunately this deprecation (or what it’s been updated to) isn’t mentioned on the class documentation page.

I was poking around and saw this post that shows how to create an ofSoundStream object and pass it a settings object instead of using ofSoundStreamSetup(), which seems to be the updated way to do it. However it uses a setApi() function, and I have no idea what that is and can’t find out anything about it.

What is this function, and what am I passing it? Is there updated docs? Thanks for any tips.

Hey @no_u , I haven’t used these classes but I’ll see if I can help a bit. Maybe one of the OF audio gurus will reply if I’ve gotten this all wrong.

There is a pretty detailed writeup about ofSoundStream in the documentation. It looks like it discusses the ofSoundStreamSetup(), but it may be of some help in general.

The soundBufferExample (in the /examples/sound folder) uses an ofSoundStreamSettings object to setup an ofSoundStream. The .setApi() function is not called on the settings object. So you could try setting up the ofSoundStream in a similar way (without calling .setApi()).

ofSoundStreamSettings::setApi() takes an ofSoundDevice::Api (an enum in the class) as an argument. There is an UNSPECIFIED option in the enum that appears to be the default when I modify ofApp::setup() in the soundBufferExample (macOS):

    ofSoundStreamSettings settings;
    ofLogNotice() << settings.getApi(); // prints 0
    ofLogNotice() << ofSoundDevice::Api::UNSPECIFIED; // prints 0
    ofLogNotice() << ofSoundDevice::Api::OSX_CORE; // prints 6

If you look in ofSoundBaseTypes.h, you’ll see some of the different options in the enum (ALSA, PULSE, OSX_CORE, MS_ASIO, etc). So presumably if you need to call this function, you’d do it according to what platform you are on and what “audio system” you would like to use. So, to specify Jack with Linux, you would do something like:

ofSoundStreamSettings settings;
settings.setApi(ofSoundDevice::Api::JACK);
// call other functions for settings

I hope this helps. I have a feeling you don’t have to specify the api unless you have a specific need to do so.