Click here to Skip to main content
11,581,397 members (61,903 online)
Click here to Skip to main content

Concatenating Wave Files

, 16 Jun 2003 134.9K 2.2K 65
Rate this:
Please Sign up or sign in to vote.
An article about concatenating .WAV files "on the fly"
<!-- Add the rest of your HTML here -->

Introduction

Those who deal with voiceprints and prompts often should have prerecorded waves for testing/development, and sometimes you want to output a "joined wave", and even more better - get it dynamically. This article tries to solve this problem and create merged wave output "on the fly".

Background

It would be good for you to have a brief overview about wave format.

Using the code

The main points of CWave class are it's constructor :

CWave(string fileName) throw(LPCSTR);

and operator+

CWave operator+(const CWave& w) const throw(LPCSTR);

The concatenation is implemented as follows:

CWave CWave::operator+ (const CWave &w) const{
    if (fmt.wFormatTag!=w.fmt.wFormatTag)
        throw "Can't concatenate waves with different format tags";
    CWave ret_val;
    ret_val.fmt = w.fmt;
    ret_val.riff = w.riff;
    ret_val.data = w.data;
    ret_val.data.dataSIZE= data.dataSIZE+w.data.dataSIZE;

     
    ret_val.extraParamLength = w.extraParamLength;
    ret_val.extraParam = w.extraParam;
    ret_val.wave = new BYTE[ret_val.data.dataSIZE];
    memcpy(ret_val.wave,wave,data.dataSIZE);
    memcpy(ret_val.wave+data.dataSIZE,w.wave,w.data.dataSIZE);

    string folder = getFileFolder(fileName);
    string title1 = getFileTitle(fileName);
    string title2 = getFileTitle(w.fileName);
    
    
    ret_val.fileName = folder;
    ret_val.fileName.append(title1);
    ret_val.fileName.append(title2);
    ret_val.fileName.append(".wav");

    return ret_val;
}

The usage is very simple:

CWave wave1("a1.wav");
CWave wave("b7.wav");
CWave wave3(wave1+wave2);
wave3.saveToFile();
//by default fileName of wave3 instance is concatenation of wave1 and wave2 fileNames
//wave3.getFileName()=="a1b7.wav"
//you can specify another fileName by:
//wave3.setFileName("anotherName.wav");

Limitations

For the time being the CWave class can deal with PCM waves, extraParams and "fact" chunks in wave header. You can parse another chunks if your waves contain ones. Also, the two wave files must have the same encoding format.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Furer Alexander
Web Developer
Israel Israel
No Biography provided

You may also be interested in...

Comments and Discussions

 
GeneralDifferent sample rates/bps Pin
pimb213-Aug-09 3:46
memberpimb213-Aug-09 3:46 
Questionsomething need u help Pin
naohboy25-Feb-08 21:46
membernaohboy25-Feb-08 21:46 
Questioncan u guide me i am new for mixer control Pin
rajneshmalik30-Aug-07 2:21
memberrajneshmalik30-Aug-07 2:21 
Generalhelp me please about how i could read a waw file and write its values to a tex file Pin
vangurad6663-May-07 0:52
membervangurad6663-May-07 0:52 
AnswerRe: help me please about how i could read a waw file and write its values to a tex file Pin
Furer Alexander3-May-07 4:17
memberFurer Alexander3-May-07 4:17 
GeneralCombine .WAV's from timecode value Pin
charliev4-Feb-07 6:01
membercharliev4-Feb-07 6:01 
GeneralUsing EVC4 Pin
dano187-Mar-06 10:24
memberdano187-Mar-06 10:24 
GeneralAmplitude Equalisation at bounderies Pin
Yash856-Mar-06 0:48
memberYash856-Mar-06 0:48 
GeneralPlaying the concatenated file without saving to disk Pin
Yash858-Feb-06 11:02
memberYash858-Feb-06 11:02 
AnswerRe: Playing the concatenated file without saving to disk Pin
Furer Alexander8-Feb-06 12:42
memberFurer Alexander8-Feb-06 12:42 
GeneralRe: Playing the concatenated file without saving to disk Pin
Yash8511-Feb-06 12:40
memberYash8511-Feb-06 12:40 
GeneralRe: Playing the concatenated file without saving to disk Pin
Furer Alexander12-Feb-06 0:36
memberFurer Alexander12-Feb-06 0:36 
Generalthis site is pointless and knowone cares Pin
Anonymous1-Aug-05 17:15
sussAnonymous1-Aug-05 17:15 
GeneralThat demo zip is rubbish Pin
Anonymous1-Aug-05 17:13
sussAnonymous1-Aug-05 17:13 
Generalpoo head Pin
Anonymous1-Aug-05 17:10
sussAnonymous1-Aug-05 17:10 
GeneralProblem with MS SoundRec32 Pin
B.Damian23-Mar-05 1:01
memberB.Damian23-Mar-05 1:01 
GeneralRe: Problem with MS SoundRec32 Pin
Koray Balci22-Jun-06 6:40
memberKoray Balci22-Jun-06 6:40 
Generalvery interesting Pin
abaddon32524-Feb-05 23:00
memberabaddon32524-Feb-05 23:00 
GeneralWAV file mixing Pin
Nightfox16-Feb-05 15:55
memberNightfox16-Feb-05 15:55 
Generalgreat!! Pin
uttam h6-Mar-04 10:07
memberuttam h6-Mar-04 10:07 
QuestionConcatenating AVI Files ? Pin
attckboy2-Aug-03 3:04
memberattckboy2-Aug-03 3:04 
AnswerRe: Concatenating AVI Files ? Pin
DaFrawg26-May-04 22:05
memberDaFrawg26-May-04 22:05 
Generalconvert one wave type to another Pin
pearlmagic13-Jul-03 23:33
memberpearlmagic13-Jul-03 23:33 
QuestionConcatenating MPG Files ? Pin
wobble20-Jun-03 5:08
memberwobble20-Jun-03 5:08 
AnswerRe: Concatenating MPG Files ? Pin
MarkusStrobl22-Jun-03 22:56
memberMarkusStrobl22-Jun-03 22:56 
GeneralI like it. Pin
Adrian Edmonds18-Jun-03 20:28
sussAdrian Edmonds18-Jun-03 20:28 
GeneralGood Article! Pin
Caio Proiete18-Jun-03 7:07
memberCaio Proiete18-Jun-03 7:07 
GeneralTwo Things Pin
Gregor Brandt17-Jun-03 13:35
memberGregor Brandt17-Jun-03 13:35 
GeneralRe: Two Things Pin
Ed Koolen26-Aug-05 0:00
sussEd Koolen26-Aug-05 0:00 
GeneralPretty Good!! Pin
WREY17-Jun-03 8:36
memberWREY17-Jun-03 8:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150603.1 | Last Updated 17 Jun 2003
Article Copyright 2003 by Furer Alexander
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid