I\'m building a karaoke app using Phonegap for Ios.
I have audio files in the www/assets folder that I am able to play using the media.play()function
This al
I would suggest to mix the PCM directly. If you initialize a buffer that overlaps the time frames of both tracks, then the formula is additive:
mix(a,b) = a+b - a*b/65535.
This formula depends on unsigned 16bit integers. Here's an example:
SInt16 *bufferA, SInt16 *bufferB;
NSInteger bufferLength;
SInt16 *outputBuffer;
for ( NSInteger i=0; i 0 && bufferB[i] > 0 ) {
// If both samples are positive, mixed signal must have an amplitude between the greater of
// A and B, and the maximum permissible positive amplitude
outputBuffer[i] = (bufferA[i] + bufferB[i]) - ((bufferA[i] * bufferB[i])/INT16_MAX);
} else {
// If samples are on opposite sides of the 0-crossing, mixed signal should reflect
// that samples cancel each other out somewhat
outputBuffer[i] = bufferA[i] + bufferB[i];
}
}
This can be a very effective way to handle signed 16 bit audio. Go here for the source.