reading .wav file

Started by
4 comments, last by lomateron 11 years, 9 months ago
Here i am reading the sound data chunk part of a wav file:

16bit, 2 channels
The sound is a music with all kinds of frequencies.
[source lang="cpp"]short p1[2]; //array were a sample of sound will be, right and left sound.

for(int i=0; i < 1000000 ;i++)
{
fread(&p1,sizeof(short),2,fp);
}[/source]


so after this i am debuging the for loop, checking the value of p1[0] and p1[1]
Logically the value should be between -[color=#000000][background=rgb(183, 203, 237)]32768 and [/background][color=#000000][background=rgb(183, 203, 237)]32767[/background] but it just goes between like -67 to 20.
why is that?
I made the soundfile with code and i can play it in windows media, so i know the data should have a -[color=#000000][background=rgb(183, 203, 237)]32768 or [/background][color=#000000][background=rgb(183, 203, 237)]32767[/background] somehere but it doesnt.

OOPS posted in game programming it was for general programming.how can i move it.
Advertisement
Array/pointer "equivalence" - should be:
fread(p1,sizeof(short),2,fp);

(Note the missing '&' before p1).

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

I dont think you need the & in front of p1 when p1 is an array.
Still same values, why is that?
i am checking what are the max and min values that p1 gets during all the loop and they are still the same.
1st, no &, as mentioned above, since p1 is already a pointer (an array, really, but p1 points to a memory location).
2nd, use unsigned short when reading the data out.
3rd, I would also use a hex-editor to open the file, and look at the actual file data and see what it's supposed to look like. And, I would do it in Hex. The values are probably OK.

My Gamedev Journal: 2D Game Making, the Easy Way

---(Old Blog, still has good info): 2dGameMaking
-----
"No one ever posts on that message board; it's too crowded." - Yoga Berra (sorta)

I solved it, instead of using

short[color=#282828][font=Consolas,] [/font]p1[2];
[color=black][font=Consolas,]I used[/font]
unsigned short[color=#282828][font=Consolas,] [/font]p1[2];

ANd now the values inside p1 goes from 0 to 65534.

This topic is closed to new replies.

Advertisement