In what format are your files ?
Explanation of the code above:
- Transform the samples of each signal from Short to Float: float samplef1 = music1 / 128.0f; (between -1 to 1)
- Add the two values and divide by 2 : float mixed = (samplef1 + samplef2) / 2;
- Limit the signals to 1 and -1 if (mixed < -1.0f)
mixed = -1.0f;
- Transform the sum sample back to Short: byte outputSample = (byte) (mixed * 128.0f);