Jump to content

View more

Image of the Day

雑魚は多めにして、爽快感重視にしつつ・・・(´・ω・`)
早いとこ、ベースを作って、完成にもっていかないとね。
タイトルもまだ迷ってるだよなぁ。 
#indiedev  #indiegame #screenshotsaturday https://t.co/IwVbswGrhe
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

reading .wav file

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
5 replies to this topic

#1 lomateron   Members   

491
Like
0Likes
Like

Posted 24 June 2012 - 04:05 PM

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 -32768 and 32767 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 -32768 or 32767 somehere but it doesnt.

OOPS posted in game programming it was for general programming.how can i move it.

Edited by lomateron, 24 June 2012 - 04:16 PM.


#2 mhagain   Members   

13154
Like
0Likes
Like

Posted 24 June 2012 - 05:17 PM

Array/pointer "equivalence" - should be:
fread(p1,sizeof(short),2,fp);

(Note the missing '&' before p1).

Edited by mhagain, 24 June 2012 - 05:18 PM.

It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.


#3 zacaj   Members   

663
Like
0Likes
Like

Posted 24 June 2012 - 05:17 PM

I dont think you need the & in front of p1 when p1 is an array.

#4 lomateron   Members   

491
Like
0Likes
Like

Posted 24 June 2012 - 06:06 PM

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.

Edited by lomateron, 24 June 2012 - 06:37 PM.


#5 BeerNutts   Members   

4379
Like
0Likes
Like

Posted 24 June 2012 - 08:55 PM

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)

#6 lomateron   Members   

491
Like
0Likes
Like

Posted 25 June 2012 - 04:58 PM

I solved it, instead of using

short p1[2];
I used
unsigned short p1[2];

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




Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.