wave file data 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


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

Keith Thompson

debug said:
I'm really new to c+ (this is day two) and I'm trying to write a
[...]

Apparently so. It's spelled "C++", not "C+", and they discuss it in
comp.lang.c++, not comp.lang.c.

[...]
int ReadWave::waveFileToArray(){

Yup, that looks like C++.
//sndfile obj + soundfile info object
SNDFILE *sf;

I don't see a declaration of SNDFILE, which almost certainly means
that you haven't shown us the #include directive for the header that
declares it.

You'll have a much better chance of getting meaningful help if you
post a small, self-contained, compilable program that exhibits the
problem. Describing precisely what the problem is, if you can manage
it, will also be helpful.

I can't tell from your code whether you have a C++ problem or a
problem with whatever library you're using. comp.lang.c++ is
certainly a better place for your question than comp.lang.c, but a
form that discusses the library (which isn't part of the language)
might be even better.

[snip]
 
D

debug

debug said:
I'm really new to c+ (this is day two) and I'm trying to write a

[...]

Apparently so.  It's spelled "C++", not "C+", and they discuss it in
comp.lang.c++, not comp.lang.c.

[...]
int ReadWave::waveFileToArray(){

Yup, that looks like C++.
   //sndfile obj + soundfile info object
   SNDFILE *sf;

I don't see a declaration of SNDFILE, which almost certainly means
that you haven't shown us the #include directive for the header that
declares it.

You'll have a much better chance of getting meaningful help if you
post a small, self-contained, compilable program that exhibits the
problem.  Describing precisely what the problem is, if you can manage
it, will also be helpful.

I can't tell from your code whether you have a C++ problem or a
problem with whatever library you're using.  comp.lang.c++ is
certainly a better place for your question than comp.lang.c, but a
form that discusses the library (which isn't part of the language)
might be even better.

[snip]

--
Keith Thompson (The_Other_Keith) (e-mail address removed)  <http://www.ghoti.net/~kst>
Nokia
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"

Oops! Sorry.
 

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

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,818
Latest member
Brigette36

Latest Threads

Top