Best place to update AudioPlayHead in host app


#1

I am developing a host application and maintaining an AudioPlayHead. The app also uses an AudioProcessorPlayer. My current implementation is working but I am concerned that I may just be getting lucky because I am not sure if audio device callbacks get called asynchronously. The graphProcessor uses the playhead’s sampleCounter from the code below. Is this OK?

    deviceManager.addAudioCallback (&graphPlayer);
    deviceManager.addAudioCallback (&Playhead::getInstance());

...

void Playhead::audioDeviceIOCallback (const float** const inputChannelData,
                                                  const int numInputChannels,
                                                  float** const outputChannelData,
                                                  const int numOutputChannels,
                                                  const int numSamples)
{
    // silence out
    for (int i = 0; i < numOutputChannels; ++i)
    {
        zeromem (outputChannelData[i], sizeof (float) * (size_t) numSamples);
    }

    if (playing)
        sampleCounter += numSamples;
}

void Playhead::audioDeviceAboutToStart (AudioIODevice* device)
{
    sampleCounter = 0;
}

bool Playhead::getCurrentPosition(CurrentPositionInfo& result)
{
...
    result.timeInSamples = sampleCounter;
...
    return true;
}