separating channels to array using libsndfile

D

debug

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


#include <sndfile.h>

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);


}


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);
}

fclose(out);

return 0;
}
 
V

Victor Bazarov

debug said:
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?

You mean, besides posting to the wrong newsgroup?

Your question is about the audio file format. C++ _language_ has no
definition of those. Please find an appropriate newsgroup for your
inquiry. Perhaps something with "multimedia" in its name, or maybe
"audio"... If there aren't any of those, you can start by asking in the
newsgroup for your OS.

And before posting again, make sure to read the FAQ:
http://www.parashift.com/c++-faq-lite/

Good luck!

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top