Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 568
  • Last Modified:

Mixing of wave files

Hi experts,
   
     I am developing a Multimedia application which is used to mix wave files. Upto now the mixing algorithm is implemented only for 16-bit wave files. If user is going to mix 8-bit,24-bit or 32-bit wave files our mixing algorithm fails. Is it possible to convert 8-bit ,24-bit,32-bit etc. wave files into 16-bit wave file without loss in Quality Or If there is general algoritms which is used to mix diffrent types of wave files. Source code or algorithm will be very helpful.
0
HanuSoftware
Asked:
HanuSoftware
1 Solution
 
chip3dCommented:
Hi,

you can convert 8bit wavefiles to 16bit without loss, but not 24bit and 32bit files. The transformation is quite easy. Just shift the values to convert .

unsigned char *wave; // your wave signal
unsigned long val = 0;
unsigned char *pval = reinterpret_cast<unsigend char*>(&val);

// now copy the 8, 24 or 32bit value of wavestream (in this case a bytestream)
// 8bit
pval[0] = wave[x];
// shift to 16 bit
val << 8;

// 24bit
pval[0] = wave[x];
pval[1] = wave[x+1];
pval[2] = wave[x+2];
// shift to 16 bit
val >> 8;

// 32bit
pval[0] = wave[x];
pval[1] = wave[x+1];
pval[2] = wave[x+2];
pval[3] = wave[x+3];
// shift to 16 bit
val >> 16;

After conversion you can write back the value to a 16bit stream
wave16[x] = pval[0];
wave16[x+1] = pval[1];

the same way you can convert to any other bitrate.

To mix the streams, first convert all streams to the same format.
Then convert the bytes to one value. Same as above...
Now you can add the values. One way is just to make the sum. But you have to clamp the values if you get an overflow (not good, you will hear artefacts when playing the file.) One solution to avoid the artefacts, is to search for the highest peak and scale the hole stream, so the higest peak will fit in the valuerange. You can also just add the streams and part through the numbers of them: val = val1/3 + val2/3 + val3/3...

here you can download the source for a windows realtime mixer: http://www.codeguru.com/cpp/g-m/multimedia/audio/article.php/c4725/

hope this will help you

chip3d



0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now