Re: How to merge .wav files

From: Tassilo v. Parseval (tassilo.von.parseval_at_rwth-aachen.de)
Date: 10/01/04


Date: Fri, 1 Oct 2004 08:48:01 +0200

Also sprach Jarson:

> I'm building a web-based message alert system in Perl (CGI) using voice TTS.
> Each web client will get a custom voice message that will actually consist
> of selected .wav files merged together to appear as one. My problem, is
> that I don't know how to handle .wav files to merge them properly under
> Perl.

Merging two .wav files is relatively easy. All you have to do is going
sample-wise through both of them in parallel, add the two samples (a
sample is just a signed integer) and write the new value to another
file. You can do the reading with Audio::WAV::Read::read() and writing
with Audio::WAV::Write::write().

Some things to watch for: You have to truncate values when they would go
beyond the maximum or minimum range of the bitrate. For 16 bits the
range is +/- 2**15 - 1. Otherwise they wrap around. Then the two .wav
files should have the same format. If file one is stereo and the second
one mono you always read two samples of the first file and one of the
second and add the second value to the first two values. When they
differ in bitrate you have to convert the samples of the file with the
lower bitrate accordingly (a 8 bit sampling-rate means that you have to
distribute the values in the range (-128 .. 127) to values in the range of
(-2**15 .. 2**15 - 1). Most of the time this distribution happens
evenly. Different sample frequency means that you skip certain samples
in the file with the higher frequency.

Tassilo

-- 
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval


Relevant Pages

  • Re: Dual layer DVD question
    ... You really, and I mean REALLY, need to be using AC3 for your audio ... instead of wav files. ... Presently we cheat on bitrate to make things fit. ... How much of a compromise is it to reprocess an mp2 file to ...
    (rec.video.desktop)
  • Re: white iPod earphones THD
    ... difference between wav files and mp3s before, ... up to 320 k bps, roughly doubling the bitrate every step. ...
    (rec.audio.pro)
  • Re: Compression Format and Bit Rate for Portable Audio Devices
    ... I agree with Arny on the wav files, if I could I would do all my music in ... wav but for now I'm using 256K bitrate for everything. ... listening to these mp3's on my ipod, but also in my car via my neo-35 car ... Eric Hicks (MS-MVP Mobile Devices) ...
    (microsoft.public.pocketpc.multimedia)
  • Re: vb.net combine two byte arrays
    ... translating it): ... I have two wav files I am trying to combine into a single ... > byte array from the second file correctly. ... > only the first file being saved to the test.wav file and not the second ...
    (microsoft.public.dotnet.framework.aspnet)