Request an audio context

iris-sdk creates an audio processing context to process an individual stream of audio. An audio context is created using by passing an audio context request to the create audio context function. This function returns an audio context config describing the context that was actually created.

At a minimum an audio context request must populate the processors attribute naming the types of processor to be applied. Multiple processors may be chained together. Valid values for processors can be obtained from the available processors attribute in the received Info after successful initialisation.

// Create an audio processing context
Iris::AudioContextRequest configRequest;
configRequest.sampleRate = 48000;
configRequest.processors = {"clarity"};
Iris::AudioContextConfig config = Iris::createAudioContext(configRequest);

Note

There are two different ways to let the audio context know what kind of audio it will be receiving.

If you have a fixed sample rate and/or buffer size, eg from a streaming callback, and you want the audio context to adapt to deal with that input, set the sample rate and/or buffer length attributes in the audio context request appropriately. Depending on the exact processing chain requested this may incur extra overhead of internal resampling and or buffering.

If you are able to adapt your input audio to the optimal input to the context, eg processing data from a file, then leave the sample rate and/or buffer length empty. After the context has been created you can inspect the configuration to see the ideal sample rate and buffer size for the created context. In this scenario you may need to handle resampling and / or buffering before passing the audio data to the context.

The create audio context function returns an audio context config. Check for an error code before continuing (0 is no error).

// Check for context creation errors
if (config.error == Iris::Constants::ERROR_SAMPLE_RATE_MISMATCH) {
  std::cout << "processors with differing internal sample rates were requested in the audio context request" << std::endl;
}
if (config.error == Iris::Constants::ERROR_PROCESSOR_UNSUPPORTED) {
  std::cout << "an unknown processor was requested in the audio context request" << std::endl;
}

The context id attribute of the audio context config will be used for all subsequent interactions with this context. The sample rate and buffer length attributes indicate the data the context is expecting to see.

Note

Do not call init() before creating each context. init() only needs to be called ONCE at the start.