Re: WAV functions

new topic     » goto parent     » topic index » view thread      » older message » newer message

>To: Daryl van den Brink
>
>Do you know a good algorithm to combine two or more WAV files?

You mean mixing them together? The simple way is just to add the
corrosponding sample values.  Averaging also works well if you want to
be sure there won't be any distortion.

>I've written an amusement for myself. Its a little application that I can 
>use to write music with. It works on the principle of creating 'voice' 
>tracks and then combining them into the final WAV file. The current 
>algorithm I use sort of works, but it has the side-effect of diminishing 
>the volume of the sound. Also, when working with lots of tracks, some 
>distortions are introduced.
>
>In fact I've tried a few algorithms but none have really worked well. The 
>ones that have given me the most promising results have been ...
>
>a) Find the geometric mean of the corresponding sample values.
>b) Find the arthimetric mean of the corresponding sample values.
>c) Find the geometric mean of the absolute value of the corresponding 
>sample values.

I haven't tried geometric mean at all, but I know arithmetic mean works
reasonably well.  If you want to make sure the sound volume remains the
same you could try normalising the mixed wave.  Here's how it works:

1. Scan the entire wave to find the maximum absolute sample value.
2. calculate a "multiplying factor" = 32767 / (max. abs. sample value)
(assuming the wave is 16 bit.  use 127 for 8 bit waves)
3. multiply every sample in the wave by this multiplying factor.

This will increase the volume as much as it can without distortion 
occurring.
You can replace 32767 with the maximum desired sample value if you don't
want it to be the loudest possible.

>But I'm thinking that I really need to use the delta between adjacent 
>samples instead. I haven't tried this yet because I really don't know 
>enough about the subject.

I've tried setting every sample in a wave to the difference between it and 
the
previous sample.  It sounds a lot like the original with all the bass taken 
out.  I
don't think this would be useful for mixing sounds together.

>I'd post the code but its not ready for serious reviewing yet - most is 
>very experimental.
>
>--
>
>cheers,
>Derek Parnell

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu