Wav file to stereo file. HELP!

I was wondering if anyone could help me with a wav file. I need to change it into a stereo file. Please help
Let me know if you figure this one out! I think we may be in the same class lol
Wave files store a stream of samples. Typically each sample is either one byte (if 8-bit audio) or 2 bytes (if 16-bit audio).

With a mono file, there is one channel, so there is only one sequence of samples:

SSSSSSSSSS

In a stereo file, there are two channels (left and right), and they are stored interleaved, which means the file alternates between left and right samples:

LRLRLRLRLRLRLRLRLRLR

All it takes to convert a mono wav to a stereo wav is:

1) modify the header to indicate the file is stereo
2) duplicate each sample (so you turn a single sample 'S' into two samples 'L' and 'R')
How would you modify this code to convert it to stereo?

#include <iostream>
#include <fstream>
#include <string>
#include <assert.h>
#include "stdint.h"

struct WaveHeader {
char riffChunkID[4];
int32_t dataSize;
char riffType[4];
char waveChunkID[4];
int32_t waveChunkSize;
uint16_t compressionCode;
uint16_t numChannels;
uint32_t sampleRate;
uint32_t averageBytesPerSec;
uint16_t blockAlign;
int16_t significantBitsPerSec;
// Extra Param Size not used in PCM
char dataChunkID[4];
int32_t dataChunkSize;

} ;


static char const *const INPUT_WAVEFILE = "D:\\class\\drum.wav";
static char const *const OUTPUT_WAVEFILE = "D:\\class\\output.wav";

using namespace std;

class Wave {
private:
ifstream wav;
WaveHeader header;
int16_t* waveData;
int numSamples;
public:

bool openWave(string fileName) {
wav.open(fileName, ios::binary);
if(wav.fail()){
cout << "Failed to locate input file" << endl;
return false;
} else {
return readWave();
}
};


bool readWave() {
// Read in the file
//
wav.read((char*)(&header), sizeof(WaveHeader));
numSamples = header.dataChunkSize / 2;
cout << numSamples << endl;
// Create a dynamic array of samples
waveData = new int16_t[numSamples];
wav.read((char*)(waveData), header.dataChunkSize);
return true;
The assignment states we have to create an array that splits it into two and then we have to create a processor which will take in stereo signal.
I am not sure how that is all done. I have created an array but am unsure what to add in it and I have created processors as well that will delay the sound.
Does yours resemble this at all? I'm pretty confused.


#include <iostream>
#include <fstream>
#include <string>
#include <assert.h>
#include "stdint.h"

struct WaveHeader {
char riffChunkID[4];
int32_t dataSize;
char riffType[4];
char waveChunkID[4];
int32_t waveChunkSize;
uint16_t compressionCode;
uint16_t numChannels;
uint32_t sampleRate;
uint32_t averageBytesPerSec;
uint16_t blockAlign;
int16_t significantBitsPerSec;
// Extra Param Size not used in PCM
char dataChunkID[4];
int32_t dataChunkSize;

} ;


static char const *const INPUT_WAVEFILE = "D:\\class\\drum.wav";
static char const *const OUTPUT_WAVEFILE = "D:\\class\\output.wav";

using namespace std;

class Wave {
private:
ifstream wav;
WaveHeader header;
int32_t* waveData;
int numSamples;
public:

bool openWave(string fileName) {
wav.open(fileName, ios::binary);
if(wav.fail()){
cout << "Failed to locate input file" << endl;
return false;
} else {
return readWave();
}
};


bool readWave() {
// Read in the file
//
wav.read((char*)(&header), sizeof(WaveHeader));
numSamples = header.dataChunkSize / 2;
cout << numSamples << endl;
// Create a dynamic array of samples
waveData = new int16_t[numSamples * 2];
int wavaDataIndex = 0;
for (int n = 0; n < numSamples; n+=2){


ifstream OpenFile("drum.wav",ios::binary);
ofstream SaveFile("output.wav",ios::binary);

wav.read((char*)(waveData), header.dataChunkSize);
wav.read((char*)(waveData), header.dataChunkSize);
}
return true;





class Processor {

public:
process();

short** buffers = new short *[NumChannels];

for (int i = 0; i < NumChannels; i++) buffers[i] = new short[NumSamples]{
}
for (int i = 0; i < NumSamples; i ++) {
for (int j = 0; j < NumChannels; j++){
}
}

protected:

};

// Main entry point
int main()
{
Wave inputWave;
bool success = inputWave.openWave(INPUT_WAVEFILE);
if(!success){
exit(1);
}
Topic archived. No new replies allowed.