0

I have 3 files, two are mono, one are stereo. I want to play them together. Currently my code is like this but seems the output is not correct.

bool silence = !player1->process(stereoBuffer, false, numberOfSamples, vol);
silence = !(playerLeft->process(stereoBuffer, !silence, numberOfSamples,vol));
silence = !(playerRight->process(stereoBuffer, !silence, numberOfSamples,vol));
if (!silence) {
        SuperpoweredFloatToShortInt(stereoBuffer, output, numberOfSamples);
        return true;
    }

Anyone know what is wrong here? I think i should use this method

void SuperpoweredFloatToShortIntInterleave(float *inputLeft, float *inputRight, short int *output, unsigned int numberOfSamples);

With 2 buffers for left and right, but then how can I add the data of the player1 into those 2 buffers? Please help.

tsengvn
  • 88
  • 5

1 Answers1

1

You need to logical OR the silence value with playerLeft and playerRight, because it can already be true after player1.

silence |= !playerLeft->process(...
silence |= !playerRight->process(...

You can also "flip" silence to "hasAudio" for an easier understanding:

bool hasAudio = player1->process(stereoBuffer, false, ...
hasAudio |= playerLeft->process(stereoBuffer, hasAudio, ...
hasAudio |= playerRight->process(stereoBuffer, hasAudio, ...
Gabor Szanto
  • 1,329
  • 8
  • 12
  • thanks for your answer, ya we can re-write like that. What I mean is, my 2 mono files convert into one stereo buffer. What I want is to output those 2 mono to the left and the right, not merged into one – tsengvn Oct 25 '18 at 13:24
  • You need to output each player into separate buffers. They will output interleaved stereo audio. For a mono source it means left and right in the buffers will be the same. Then use a function from SuperpoweredSimple.h to mix them into an output buffer. – Gabor Szanto Oct 26 '18 at 06:23