I am mixing two 16bit PCM samples into a short buffer.
// This is our buffer for PCM audio data
mp3Buffer = new short[minBufferSize];
wavBuffer = new short[minBufferSize];
mixedBuffer = new short[minBufferSize];
I am filling these buffers with samples from both the mp3 and wav files. I found out that the wav file will always be in mono and the mp3 will always be stereo.
I've read that if you "Just allocate a buffer twice the size of the original PCM data, and for every sample in the original buffer put it twice in the new buffer"
short[] stereoWavBuffer = new short[minBufferSize];
int k = 1;
for (int j = 0; j < minBufferSize / 2; j += 2)
{
stereoWavBuffer[j] = wavBuffer[j];
stereoWavBuffer[k] = wavBuffer[k];
k += 2;
}
// TO DO - Add the 2 buffers together
for (int i = 0; i < minBufferSize; i++){
mixedBuffer[i] = (short)(mp3Buffer[i] + stereoWavBuffer[i]);
}
track.write(mixedBuffer, 0, minBufferSize);
}
How can I accomplish this? I tried this but the wav audio now is at regular speed but sounds like chipmunk.