1. WAV functions

To: Daryl van den Brink

Do you know a good algorithm to combine two or more WAV files?

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.

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'd post the code but its not ready for serious reviewing yet - most is 
very experimental.

-- 

cheers,
Derek Parnell

new topic     » topic index » view message » categorize

2. Re: WAV functions

You've tried just summing them up and clamping the result to fit inside 16 
bits ?

new topic     » goto parent     » topic index » view message » categorize

3. Re: WAV functions

Derek,

I'm working on a vaguely related problem, *maybe* this would work:

*maybe:*

1.  find  the "number of bits per sample" (8, 16 or 24?)(8 would be 256 bits
of resolution, I think), presuming it's the same for each sample you want to
mix together, so you can know what "zero" is (ie, no amplitude in the wave,
flat "wave", no up/down oscillation) ; I'm assuming that for 8-bit it's 128,
etc.

2.  subtract the "zero" value from every sample point value, for each sample
you want to mix (now allowing for negative numbers, of course); this way you
have sets of values that go up & down from actual zero;

3.  now add them all together, point by corresponding point;

4.  find the most positive and negative value in that summed set;  figure a
divide-by value that would make the absolute value of the biggest of those
max/min into the loudest value you want, equal to or lower than the
resolution.  Since the result is now zero referenced, apply that divisor to
every sample point;

5.  and finally, re-add the "zero" value to each point.

Dan Moyer

----- Original Message -----
From: "Derek Parnell" <ddparnell at bigpond.com>
To: "EUforum" <EUforum at topica.com>
Sent: Thursday, May 22, 2003 7:00 PM
Subject: WAV functions


>
>
> To: Daryl van den Brink
>
> Do you know a good algorithm to combine two or more WAV files?
>
> 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.
>
> 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'd post the code but its not ready for serious reviewing yet - most is
> very experimental.
>
> --
>
> cheers,
> Derek Parnell
>
>
>
> TOPICA - Start your own email discussion group. FREE!
>
>

new topic     » goto parent     » topic index » view message » categorize

4. Re: WAV functions

>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 message » categorize

5. Re: WAV functions

I forgot to mention that the normalising algorithm will also work for 
decreasing
the volume to fit inside 16 bit integers.  You can then just add samples 
together
without averaging them (euphoria 31-bit integers give you lots of room for
overflow here, you only need to worry about distortion when the wave is 
written
to a file).  There will be less "loss of information" if you do it this way.

regards,
Daryl Van Den Brink

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu