简体   繁体   中英

Concatenate .wav files in C++

How can I, using a function, library, whatever I have to, concatenate two .wav files? The input should be the absolute paths, and the output an audio file created and placed (not just played) somewhere, it doesn't really matter where.

I am writing a Mac command line application in XCode 6.

The .wav file format is a very simple format, consisting of the fixed header that defines the audio file's properties; namely the endian-ness, the number of channels, and the sampling rate. Its documentation is widely defined on the intertubes.

Off the top of my head I don't recall if any common library offers a convenient way to do this (it's worth looking through libsndfile's API documentation , for something that would fit the bill).

In any case, it shouldn't be too tough to read the headers of both WAV files, to check their format, and then create the output file. If both WAV files have the same endian-ness, number of channels, and sampling rate, the procedure is trivial, otherwise you will have to resample/remix at least one of the files.

There is a very simple, lightweight and mature open source C API library for reading-writing several common audio file formats . I haven't worked with it for a while, if I remember well, it has routines for opening a sound file for writing, seeking the end, appending data from another file and updating the header. I hope this can help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM