Hi,
I have been struggling with this one for many hours now. Code compiles fine but when I run it I get a 'bus error'. No more details are given by the program. I have narrowed it down to when I call fread.
Code:
#include <math.h>
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
#define _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES
using namespace std;
char *wave;
char *data;
char *riff;
unsigned long int length;
unsigned int fs, numchannel, bytes, byterate, chunksize, vectsize;
short nframes, fstart, fend, comp, bits;
int toggle = 0;
int *l, *r;
...........
int main(){
//open .wav file and verify header works fine problem occurs below
...
int *r;
int *l;
int left;
int right;
for(int i = 0; i <=50; i++){
if(toggle%2 == 0){
fread(l, 4, 1, audio);
left = *l;
channelL.push_back(left);
cout <<channelL.at(left)<<endl;
}
if (toggle%2 == 1){
fread(r, bytes, 1, audio);
right = *r;
channelR.push_back(right);
cout <<channelR.at(right)<<endl;
}
toggle = toggle++;
}
}
It works fine if I just replace left and right with k and j and increment the counters. The problem is when I call fread. I am sure it is something so obvious.