Barry Mann wrote:
In , on 12/26/04
at 09:16 PM, (ranjeet) said:
[ ... ]
what I observed that the resultant mixed wav file whcih I got has
the
low
volume, and this is obvious that as i am dividing the value of
each
sample by
two. So it is decreasing the amplitude level.
By dividing by two you are throwing away one bit of resolution. Quiet
passages may have only had three or four bits to begin with, throwing
one of them away is very unfortunate. After a few generations of
this,
there may be nothing left of the original samples.
You could temporarily convert the 8-bit files to 16 or 24-bits. If
you
can, use extended precision calculations (32 or 48-bits -- or more)
during the mixing process, then pare the final mix down to 8-bits.
Extended precision routines will take longer, but you are less likely
to suffer some sort of truncation problem.
Rather than mix your 10 files two at a time, try to find (or write)
some software that will work on more files on a pass. Hopefully, this
software will use appropriate precision.
The point that all of you are missing is that the very act of
truncating the final sum is what is causing the problem. Doing
so introduces pretty serious truncation artifacts, ESPECIALLY
if you're only doing 8 bits worth of precision to begin with.
If you are going to take a loinger precision word and truncate,
you HAVE to dither, otherwise you will be getting exactly the
effects described by the original poster. While dithering will
raise the overall noise floor, done properly, you will not have
the severe distortion artifacts described. Dithering is the
addition of a small amount of random noise, on the order of
about +-1/2 LSB of the final result BEFORE tunrcating.
If it were me (and I have done this sort of thing for a number
of clients in the past), I'd use a combination of dithering and
simple first-order residue noise shaping. Assume, for the moment,
that a series of 8 bit values have been added together and that
the sum lives in a 16 bit integer (we'll assume two's complement
representation for the time being). We'll further assume that
the significant data resides in the top 8 bits, and we want to
truncate down to 8 bits, discarding the bottom 8 bits. We just
can't discard them, becuase it represents real data (and doing
an integer divide IS discarding these lower bits: don't do that!)
Let's further assume we have good quality random number generator
that will generate an 7 bit signed random number, and we have a
local static storage for a 16 bit signed value.
Now, each time you need to convert a 16 bit to an 8 bit sample,
first add in the value of the residue (whose initial value is
0). Then add in a random 7 bit value. NOW get rid of the bottom
8 bits, and that's left is your 8 bit dithered sample in the top
8 bits of your 16 bit value. BUT, before you do anything else,
subtract that trincated value from the original, and store the
result in the local static residue for the next sample.
Repeat for each subsequent sample.
You can tweak the amount of random noise vs the amount of residue
you use until it soiunds right for your application, but this
should help your cause quite a bit.