Skip to content
Search

WAV

lastmod 2021-11-05created 2014-03-177 edits

WAV or WAVE, short for Waveform audio format (also Wave audio format), is a Microsoft and IBM audio file format standard for playing audio on personal computers. It is a variant of the RIFF bitstream format method for storing data in chunks, and is very close to the IFFF format used on the Amiga and the AIFF format used on Macintosh computers. It is the default format used on Windows systems for raw audio. On Windows, WAV is not limited to uncompressed formats; various compression codecs can be used. However, starting with Windows Vista, the default supported format changed to WMA.

WAV is an uncompressed audio format used for program sounds and general-level recording, but for professional recording, uncompressed formats other than WAV are often used more. For reference, some radio stations use the uncompressed WAV format instead of the compressed audio format MP2.

Wav merge

If the FMT Sub-chunk header information of the wave files is identical, the PCM data can be merged as follows.

#include <stdio.h>
#include <Windows.h>

#pragma pack (push, 1)
struct WaveHeader
{
    // RIFF header.
    char ChunkID[4];
    unsigned int ChunkSize;
    char Format[4];

    // FMT Header.
    char SubChunk1ID[4];
    unsigned int SubChunk1Size;
    short AudioFormat;
    short NumChannels;
    unsigned int SampleRate;
    unsigned int ByteRate;
    short BlockAlign;
    short BitsPerSample;

    // DATA Header.
    char SubChunk2ID[4];
    unsigned int SubChunk2Size;
};
#pragma pack (pop)

int _tmain(int argc, _TCHAR* argv[])
{
    FILE * rf1 = fopen("1.wav", "rb");
    FILE * rf2 = fopen("2.wav", "rb");

    FILE * wf = fopen("12.wav", "wb");

    if (rf1 != NULL && rf2 != NULL && wf != NULL) {
        WaveHeader rf1_wave_header = {0,};
        WaveHeader rf2_wave_header = {0,};

        fread(&rf1_wave_header, sizeof(WaveHeader), 1, rf1);
        fread(&rf2_wave_header, sizeof(WaveHeader), 1, rf2);

        BYTE * rf1_pcm = new BYTE [rf1_wave_header.SubChunk2Size];
        BYTE * rf2_pcm = new BYTE [rf2_wave_header.SubChunk2Size];

        memset(rf1_pcm, 0x00, sizeof(*rf1_pcm) * rf1_wave_header.SubChunk2Size);
        memset(rf2_pcm, 0x00, sizeof(*rf2_pcm) * rf2_wave_header.SubChunk2Size);

        // Read pcm data
        int read_count1 = fread(rf1_pcm, sizeof(BYTE), rf1_wave_header.SubChunk2Size, rf1);
        int read_count2 = fread(rf2_pcm, sizeof(BYTE), rf2_wave_header.SubChunk2Size, rf2);

        // merge
        WaveHeader wf_wave_header = {0,};
        memcpy(&wf_wave_header, &rf1_wave_header, sizeof(rf1_wave_header));

        // calc.
        wf_wave_header.ChunkSize += rf2_wave_header.SubChunk2Size;
        wf_wave_header.SubChunk2Size += rf2_wave_header.SubChunk2Size;

        // file write.
        fwrite(&wf_wave_header, sizeof(wf_wave_header), 1, wf);
        fwrite(rf1_pcm, sizeof(BYTE), rf1_wave_header.SubChunk2Size, wf);
        fwrite(rf2_pcm, sizeof(BYTE), rf2_wave_header.SubChunk2Size, wf);
    }

    fclose(rf1);
    fclose(rf2);
    fclose(wf);

    return 0;
}

Favorite site

References


  1. Marocchino.blogspot.jp-cat_wave_to_wave.zip ↩

  2. Sunparkmi-wave_file_format.zip ↩

  3. Crystalcube.co.kr-wave_file_format.zip ↩

  4. Psychoria.blog.me_-_wave_format.pdf ↩

  5. Naver.gogil.kr_-_wave_format_and_mmio.pdf ↩

author Zer0 sitemap