I am making a music application where I need to join the user's voice with the instrumental music. In achieving this, I need to decode the instrumental music into PCM and combine it with user's voice. The algorithm I used to combine the music is this:
int sample1 = ...;
int sample2 = ...;
int combinedSample = sample1+sample2;
combinedSample /= 2;
However, the result is very annoying. The sound is not audible, the voice cannot be listened. When I open the resulting PCM file in Audacity, it looks like this (weird):
Also, I tried this formula and the result is not expected.
int sample1 = ....;
int sample2 = ....;
int combinedSample = sample1+sample2;
if (combinedSample >= 32767) {
combinedSample = 32767;
} else if (combinedSample <= -32768) {
combinedSample = -32768;
}