Hi all,
I don't know if I can ask these technical questions right here, but I will give it a try...
I need to merge WAV-files (front and rear) 32 bit float into one WAV-file. I already have written some Java-code to
handle WAV-files (e.g. updating pitch information in the files etc.) and now want to write the code to merge/mix front and rear files into one WAV-file.
On the internet I have found several sources which are proposing the following:
1) Read the data-chunk of the Front and Rear file and convert those values to 32-bit float. That means for every 4 bytes I convert it to a long (4 bytes)
and then convert value to : sample = (value / maxRange) - 1 (so we have values between -1.0 and 1.0) and maxrange = 2^(32 - 1).
2) I do the scaling for both Front and Rear and the mixed values = (scaled-front + scaled-rear) / 2.0.
3) Now I convert the mixed-scale value back to a long and put it in the data-chunk of the WAV-file.
However it is now working as expected, the mixed value is generating a bad signal with a lot of noise.
I have tried with Adobe Audition and Audacity to mix the Front and Rear and via inspecting the data-chunk of the mixed file from both of the application to see
how the mixing is really done, however also without success.
Some example code, to get an idea what I am doing:
...
float maxRange = (float) Math.pow(2, (bytesPerSample * - 1); // for 32-bit -> 2147483648
for (int i = 0; i < buffer.length / bytesPerSample; i++)
{
long valueFront = getIntFromBuffer(buffer, offset, bytesPerSample);
long valueRear = getIntFromBuffer(dataRearChunk, offset + 8, bytesPerSample);
float samplef1 = ((float) valueFront) / maxRange - 1.0f;
float samplef2 = ((float) valueRear) / maxRange - 1.0f;
float mixed = (samplef1 + samplef2) / 2.0f;
mixed += 1.0f;
mixed *= maxRange;
long outputSample = (long) mixed;
putIntIntoBuffer(buffer, offset, bytesPerSample, outputSample);
offset += bytesPerSample;
}
...
Any feedback is welcome!
Regards,
Gerald
I don't know if I can ask these technical questions right here, but I will give it a try...
I need to merge WAV-files (front and rear) 32 bit float into one WAV-file. I already have written some Java-code to
handle WAV-files (e.g. updating pitch information in the files etc.) and now want to write the code to merge/mix front and rear files into one WAV-file.
On the internet I have found several sources which are proposing the following:
1) Read the data-chunk of the Front and Rear file and convert those values to 32-bit float. That means for every 4 bytes I convert it to a long (4 bytes)
and then convert value to : sample = (value / maxRange) - 1 (so we have values between -1.0 and 1.0) and maxrange = 2^(32 - 1).
2) I do the scaling for both Front and Rear and the mixed values = (scaled-front + scaled-rear) / 2.0.
3) Now I convert the mixed-scale value back to a long and put it in the data-chunk of the WAV-file.
However it is now working as expected, the mixed value is generating a bad signal with a lot of noise.
I have tried with Adobe Audition and Audacity to mix the Front and Rear and via inspecting the data-chunk of the mixed file from both of the application to see
how the mixing is really done, however also without success.
Some example code, to get an idea what I am doing:
...
float maxRange = (float) Math.pow(2, (bytesPerSample * - 1); // for 32-bit -> 2147483648
for (int i = 0; i < buffer.length / bytesPerSample; i++)
{
long valueFront = getIntFromBuffer(buffer, offset, bytesPerSample);
long valueRear = getIntFromBuffer(dataRearChunk, offset + 8, bytesPerSample);
float samplef1 = ((float) valueFront) / maxRange - 1.0f;
float samplef2 = ((float) valueRear) / maxRange - 1.0f;
float mixed = (samplef1 + samplef2) / 2.0f;
mixed += 1.0f;
mixed *= maxRange;
long outputSample = (long) mixed;
putIntIntoBuffer(buffer, offset, bytesPerSample, outputSample);
offset += bytesPerSample;
}
...
Any feedback is welcome!
Regards,
Gerald