debugdom 0 Newbie Poster

Hi-

I'm really new to c+ (this is day two) and I'm trying to write a program that will allow me to write audio data from a wave file into two arrays for the left channel and the right channel, i've pieced together this code so far and its definitely grabbing something from the wave file however i've no idea if its writing out left or right data or even a combination of the two.

any ideas what I could be doing wrong?

thanks

domm

int ReadWave::waveFileToArray(){
	
	//sndfile obj + soundfile info object
	SNDFILE *sf;
	
   SF_INFO info;
	
   int num;
	int num_items;

	int numFrames;
	int sampleRate;
	int channels;

	int i;
	int j;
	
   FILE *out;
	
	
	SNDFILE *outWave;
	// open the wave

	info.format = 0;
   sf = sf_open(filePath, SFM_READ,&info);
   if (sf == NULL)
       {
       printf("Failed to open the file.\n");
       exit(-1);
	}
	
	numFrames = info.frames;
   sampleRate = info.samplerate;
   channels = info.channels;
	
	num_items = numFrames * channels;


	vector <int> buffer(num_items);

	num = sf_read_int(sf, &buffer[0], num_items);
	sf_close(sf);



	
	for (i = 0; i < num; i += channels){
     	
			rawWaveDataArray.push_back(buffer[i]);
			

	}

	
	printf("the array size is: %d \n", rawWaveDataArray.size());
	
   printf("frames=%d\n", numFrames);
   printf("samplerate=%d\n", sampleRate);
   printf("channels=%d\n",channels);

   printf("num_items=%d\n",num_items);
	printf("Read %d items\n", num);
	
	for(i = 0; i < rawWaveDataArray.size(); i++){
		printf("%d\n", rawWaveDataArray[i]);
	}

   fclose(out);

	return 0;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.