0

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;

  }

[...]
Rama
  • 3,222
  • 2
  • 11
  • 26
Nick
  • 328
  • 3
  • 10

1 Answers1

0

No need for setPosition, the player will sync to the next beat. Just call play(true) for a re-sync.

Gabor Szanto
  • 1,329
  • 8
  • 12
  • Hi Gabor I have general beat sync running, no problem with that. But I want to sync to an absolute position not only to the beat grid. I get the absolute `msPositionMaster` and `currentBPM` from my custom metronome class. I want all the players to sync to its absolute position. Tempo should also be adjusted to the metronome but will not change during playback. When I use `setPosition` what position is needed? Pre or post timestretch position? – Nick Mar 22 '17 at 12:16
  • The player always tracks position properly regardless time stretching. Position should reflect the position to start playback from. Make sure that position falls onto your custom beatgrid though! – Gabor Szanto Mar 22 '17 at 15:17