ASPiK SDK
Loading...
Searching...
No Matches
Audio Input and Output Samples

We will need to decode the ChannelIOConfig variable for the audio data and pick up the audio input data samples, process them, and then write our audio outputs into the audioOutputFrame array according to the output channel IO configuration. You may adapt this code as your plug requires it. The stock processAudioFrame function your plugin is created with looks something like this at the head of the function.

// --- fire any MIDI events for this sample interval
processFrameInfo.midiEventQueue->fireMidiEvents(processFrameInfo.currentFrame);
// --- do per-frame smoothing
doParameterSmoothing();
// --- Synth or FX Plugin?
if (getPluginType() == kFXPlugin)
{
// do FX stuff
}
//

From this point on, we will assume that we are processing for a FX plugin and we'll omit those enclosing curly brackets for brevity. All ASPiK plugins will by default accommodate mono-mono, mono-stereo and stereo-stereo formats. You can add more channel formats as you like. Each new blank ASPiK plugin will pass audio from input to output directly. You will then modify the code to do some meaningful processing. The audio data samples arrive in slots in the audioInputFrame and audioOutputFrame arrays and we use standard C++ array notation to access them. We might write something like this to pick up the input samples, process them through some interesting audio processing function then and pass the resulting samples to the outputs:

// --- get left and right input samples
double xn_L = processFrameInfo.audioInputFrame[0];
double xn_R = processFrameInfo.audioInputFrame[1];
// --- process them to create outputs
double yn_L = doSomeCoolAudioProcessing(xn_L);
double yn_R = doSomeCoolAudioProcessing(xn_R);
// --- send audio out
processFrameInfo.audioOutputFrame[0] = yn_L;
processFrameInfo.audioOutputFrame[1] = yn_R;
//

From this example, it should be obvious how to pick up input samples and write output samples. If we were processing a 5.1 input, we might write something like this instead:

// --- 5.1
double leftIn = processFrameInfo.audioInputFrame[0];
double rightIn = processFrameInfo.audioInputFrame[1];
double lfeIn = processFrameInfo.audioInputFrame[2];
double leftSurroundIn = processFrameInfo.audioInputFrame[3];
double rightSurroundIn= processFrameInfo.audioInputFrame[4];
//

To decode our three I/O combinations, we use the following code:

// --- Mono-In/Mono-Out
if(processFrameInfo.channelIOConfig.inputChannelFormat == kCFMono &&
processFrameInfo.channelIOConfig.outputChannelFormat = kCFMono)
{
// --- DO mono-in --> mono out processing
}
// --- Mono-In/Stereo-Out
if(processFrameInfo.channelIOConfig.inputChannelFormat == kCFMono &&
processFrameInfo.channelIOConfig.outputChannelFormat == kCFStereo)
{
// --- DO mono-in --> stereo out processing
}
// --- Stereo-In/Stereo-Out
if(processFrameInfo.channelIOConfig.inputChannelFormat == kCFStereo &&
processFrameInfo.channelIOConfig.outputChannelFormat == kCFStereo)
{
// --- DO stereo-in --> stereo out processing
}
//

You can modify the channel decoding logic to suit your own taste. One thing to note is that this function (like all of the PluginBase functions) returns a boolean variable to signify whether we actually processed data or not. We can return true from inside each of those curly bracket sets and return false if none of our channel combinations are supported.