0

While going over all questions and answers related to "Mixing 2 wav files", most of the answers suggested - convert bytes from each wav file to shorts, get average of the shorts and write to output byte array. I also read that in multi channel uncompressed PCM wav files (2 channel 16 bit and 44100 samples per second ) in my case, the data for each channel is stored in interlaced format, so in the data chunk- the first byte would be for channel 1, second for channel 2, third for channle 1, 4th for ch2 and so on. To get the fastest conversion - most suggested using either Buffer.BlockCopy or Array.ConvertAll as options.

Won't this actually distort the data? As the 1st short value would actually be byte ch1 + byte ch2. And so also for the other file - when the addition is done- for the averaging- we are basically forcing the overflow from the channel 2 bytes to go onto channel1 bytes thus distorting data in both channels.

I tried the above options and I get a noticeable distortion of the signal at the area of overlap between 2 files that I want merged.

Once alternative I think which would keep the channel data separate is to first divide the byte data by 2 and then add..and write to the output, going to try this out now and will post.

Peter O.
  • 32,158
  • 14
  • 82
  • 96
  • Could you specify a language? – user123 May 10 '13 at 14:01
  • Shouldn't you actually *add* them, not average them? – Joey May 10 '13 at 14:03
  • @Magtheridon96 : its c# winforms application built using vs2010 – user2313152 May 14 '13 at 13:23
  • @Joey If I simply add, then there are very high chances of data overflow- I inspected the bytes from the inot file and many values are very close to 255, so If I simply add the 2 - wont there be overflow ? – user2313152 May 14 '13 at 13:24
  • I would add and then if it goes greater than 255 then set it to 255. – VoronoiPotato May 14 '13 at 13:37
  • @ VoronoiPotato - Yes I guess I should retain the signals as accurate as I can till the limit cases and only adjust for values shooting above the limits.. but wont that add a huge amount of processing ? one if condition for each sample- there are 44100 samples per second of audio file... – user2313152 May 14 '13 at 13:45
  • The reason for reading as bytes was simply due to limilation in reading from stream - fs.Read - reads byte by byte- so the conversion from byte to short is necessary. – user2313152 May 14 '13 at 14:07

0 Answers0