SuperpoweredAdvancedAudioPlayer
has built in beat syncing which works well. But I want to sync the player to the absolute position of my metronome and tried to do so by setting this position with the players setPosition (double ms, bool andStop, bool synchronisedStart)
method in every processing loop. This works as long as the player plays in its original bpm. When I change the tempo and the playback gets timestretched I get distorted audio.
I tried to set the position to the position of the master as well as to the calculated position of the player in its original tempo (masterPositionMs
* playerBpm
/ masterBpm
). I also tried this with beat synchronization on and off.
What am I doing wrong? Any better way to do absolute syncing?
bool MyAudioSession::process(short int *in_out, unsigned int numberOfInputSamples) {
float currentBPM = metronome->getBpm();
double msElapsedSinceLastMasterBeat = metronome->getMsElapsedSinceLastBeat();
double msPositionMaster = metronome->getPositionMs();
bool silence = true;
if(metronome->process(stereoOutputBuffer, !silence, numberOfInputSamples, volMetronome))
silence = false;
for (int i = 0; i < audioPlayers.size(); i++) {
if(audioPlayers[i]->playing) {
audioPlayers[i]->setPosition(
(msPositionMaster * audioPlayers[i]->bpm / currentBPM) + audioPlayers[i]->firstBeatMs,
!metronome->isPlaying(),
SYNCHRONISED_START);
}
if(audioPlayers[i]->process(stereoOutputBuffer, !silence, numberOfInputSamples, audioPlayers[i]->volume, currentBPM, msElapsedSinceLastMasterBeat))
silence = false;
}
[...]