I am not that great with C++ but I am trying to write code that will be able to import 2 wave files I have - the first file is my sine wave sweep file the second is my impulse response of the room. Once imported I wish to de-convolve the sine sweep tone from the impulse response of the room and so leaving just the sound of the rooms acoustics.

I have no idea how to write the code to perform deconvolution I have read numerous pages be its very confusing can some one help me write this code or point me in the write direction.

I have started to try to understand Convolution by creating 2 sine waves in Excel then save the data as text files and use these as my two files to import into my C++ code and convolve - this appears to work as the C++output looks the same as what I have crated in Excel.

If some one can help I will be very grateful.

8 Years
Discussion Span
Last Post by nucleon

Here's a piece of a program I wrote to play with PCM wave files. It displays the header information. Run it on both of your files and post the results back here. The filename is hardcoded in the first line of main. Uncomment the last line if you need to pause the console.

// Reference: http://ccrma.stanford.edu/courses/422/projects/WaveFormat/

#include <iostream>
#include <fstream>
using namespace std;

// These types must be set to the correct number of bits.
// These should be good for a 32-bit computer.
typedef unsigned char  UINT8;
typedef unsigned short UINT16;
typedef unsigned       UINT32;
typedef signed char    INT8;
typedef short          INT16;
typedef int            INT32;

struct RIFFDescriptor {
    char  id[4];
    UINT32  chunkSize;
    char  fmt[4];

struct SubChunk1 {
    char    id[4];
    UINT32  size;
    UINT16  audioFormat;
    UINT16  numChannels;
    UINT32  sampleRate;
    UINT32  byteRate;
    UINT16  blockAlign;
    UINT16  bitsPerSample;

struct SubChunk2 {
    char    id[4];
    UINT32  size;

int main() {
    ifstream f("your.wav", ios::binary);

    RIFFDescriptor rd;
    f.read((char*)&rd, sizeof(rd));

    cout << "RIFFDescriptor\n";
    cout << "  id:            \""
         << rd.id[0] << rd.id[1] << rd.id[2] << rd.id[3] << "\"\n";
    cout << "  chunkSize:     "
         << rd.chunkSize << '\n';
    cout << "  fmt:           \""
         << rd.fmt[0] << rd.fmt[1] << rd.fmt[2] << rd.fmt[3] << "\"\n";

    SubChunk1 sc1;
    f.read((char*)&sc1, sizeof(sc1));

    cout << "SubChunk1\n";
    cout << "  id:            \""
         << sc1.id[0] << sc1.id[1] << sc1.id[2] << sc1.id[3] << "\"\n";
    cout << "  size:          " << sc1.size          << '\n';
    cout << "  audioFormat:   " << sc1.audioFormat   << '\n';
    cout << "  numChannels:   " << sc1.numChannels   << '\n';
    cout << "  sampleRate:    " << sc1.sampleRate    << '\n';
    cout << "  byteRate:      " << sc1.byteRate      << '\n';
    cout << "  blockAlign:    " << sc1.blockAlign    << '\n';
    cout << "  bitsPerSample: " << sc1.bitsPerSample << '\n';

    SubChunk2 sc2;
    f.read((char*)&sc2, sizeof(sc2));
    UINT32 numSamples = sc2.size / (sc1.numChannels * sc1.bitsPerSample / 8);
    cout << "SubChunk2\n";
    cout << "  id:            \""
         << sc2.id[0] << sc2.id[1] << sc2.id[2] << sc2.id[3] << "\"\n";
    cout << "  size:          " << sc2.size
         << "  (numSamples: "   << numSamples << ")\n";

// cin.get(); // uncomment for pause
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.