Click here to Skip to main content
Licence 
First Posted 16 Jun 2003
Views 123,709
Bookmarked 64 times

Concatenating Wave Files

By | 16 Jun 2003 | Article
An article about concatenating .WAV files "on the fly"

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

About the Author

Furer Alexander

Web Developer

Israel Israel

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralDifferent sample rates/bps Pinmemberpimb23:46 13 Aug '09  
Questionsomething need u help Pinmembernaohboy21:46 25 Feb '08  
Questioncan u guide me i am new for mixer control Pinmemberrajneshmalik2:21 30 Aug '07  
Generalhelp me please about how i could read a waw file and write its values to a tex file Pinmembervangurad6660:52 3 May '07  
AnswerRe: help me please about how i could read a waw file and write its values to a tex file PinmemberFurer Alexander4:17 3 May '07  
GeneralCombine .WAV's from timecode value Pinmembercharliev6:01 4 Feb '07  
GeneralUsing EVC4 Pinmemberdano1810:24 7 Mar '06  
GeneralAmplitude Equalisation at bounderies PinmemberYash850:48 6 Mar '06  
GeneralPlaying the concatenated file without saving to disk PinmemberYash8511:02 8 Feb '06  
AnswerRe: Playing the concatenated file without saving to disk PinmemberFurer Alexander12:42 8 Feb '06  
GeneralRe: Playing the concatenated file without saving to disk PinmemberYash8512:40 11 Feb '06  
GeneralRe: Playing the concatenated file without saving to disk PinmemberFurer Alexander0:36 12 Feb '06  
Generalthis site is pointless and knowone cares PinsussAnonymous17:15 1 Aug '05  
GeneralThat demo zip is rubbish PinsussAnonymous17:13 1 Aug '05  
Generalpoo head PinsussAnonymous17:10 1 Aug '05  
GeneralProblem with MS SoundRec32 PinmemberB.Damian1:01 23 Mar '05  
GeneralRe: Problem with MS SoundRec32 PinmemberKoray Balci6:40 22 Jun '06  
Generalvery interesting Pinmemberabaddon32523:00 24 Feb '05  
GeneralWAV file mixing PinmemberNightfox15:55 16 Feb '05  
Generalgreat!! Pinmemberuttam h10:07 6 Mar '04  
QuestionConcatenating AVI Files ? Pinmemberattckboy3:04 2 Aug '03  
AnswerRe: Concatenating AVI Files ? PinmemberDaFrawg22:05 26 May '04  
Generalconvert one wave type to another Pinmemberpearlmagic23:33 13 Jul '03  
QuestionConcatenating MPG Files ? Pinmemberwobble5:08 20 Jun '03  
AnswerRe: Concatenating MPG Files ? PinmemberMarkusStrobl22:56 22 Jun '03  

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.

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