Jump to content

  • Log In with Google      Sign In   
  • Create Account

big loop with big array


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
10 replies to this topic

#1 lomateron   Members   -  Reputation: 363

Like
0Likes
Like

Posted 26 June 2012 - 04:58 AM

I have this big array and this big {for} loop to fill this array
the loop reads a soundfile, and writes it to the array, the sound data is simple, 3minutes of 10hz constant
so the sound data should be something that starts 0,1,2,3,4,...65534 then goes down and up and down again and again

but debuggin i found that when it gets aproximately to the 200 loop the data that reads will stay the same so it will fill the array with the same value from that point until it finishes loop. the soundfile can be changed to another music that has same format and the same happens, why?

[source lang="cpp"] D3DXVECTOR4 dd[7935489]; //the big array, it is located up in the head of the program. //Data of sound BYTE id[40]; unsigned int ivb; unsigned short p1[2]; //right and left 1 unsigned short p2[2]; //right and left 2 FILE * fp; fp = fopen("12.wav","r"); fread(id,sizeof(BYTE),40,fp);//read unessesary info of sound fread(&ivb,sizeof(unsigned int),1,fp);// read the sized of the data unsigned int ss= ivb/4;// calculate num of samples unsigned int i; for(i=0;i < (ss/2);i++)//fill part of the array with all sound data { fread(p1,sizeof(unsigned short),2,fp); fread(p2,sizeof(unsigned short),2,fp); dd[i]=D3DXVECTOR4(float(p1[0]),float(p1[1]),float(p2[0]),float(p2[1])); }[/source]

Edited by lomateron, 26 June 2012 - 05:05 AM.


Sponsor:

#2 rip-off   Moderators   -  Reputation: 8762

Like
0Likes
Like

Posted 26 June 2012 - 05:43 AM

What have you tried?

#3 lomateron   Members   -  Reputation: 363

Like
0Likes
Like

Posted 26 June 2012 - 06:04 AM

does it looks complex?,its simple man,if you know about how to make soundfiles, but i want to know if someone had that same problem.
with just that code and a soundfile,16 bits 2channels 44100samples/second, you can try it yourself and see.

and yes i just wasted like a day to get to this. I created code that was based on that array so i had to recheck it, it took me time...like a day

Edited by lomateron, 26 June 2012 - 06:12 AM.


#4 jeroenb   Members   -  Reputation: 257

Like
3Likes
Like

Posted 26 June 2012 - 06:50 AM

I have no clue about the file format. I only can suggest to check if your variables are initialized correctly. A verification whether or not you are reading past the end might reveal a problem as well.

I would also suggest to open the file as binary ("rb").

Crafter 2D: the open source 2D game framework

Blog: Crafter 2D
Twitter: @crafter_2d


#5 mhagain   Crossbones+   -  Reputation: 8284

Like
0Likes
Like

Posted 26 June 2012 - 07:04 AM

I would also suggest to open the file as binary ("rb").

This is most likely it. Opening a binary file as text can cause interesting things to happen, such as data read being interpreted differently.

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.


#6 lomateron   Members   -  Reputation: 363

Like
0Likes
Like

Posted 26 June 2012 - 07:05 AM

well the variables are initialized the same way you can see them in the code

reading past the end--nop because the loop is around 2 million times and the data starts to get repeated at the 220 loop



the problem isn't in the soundfile, i had opened it(http://ie.microsoft....L5/TypedArrays/),i have played it too ,and i have opened with that code other soundfiles and at some point near the start the array starts to be filled with the same data until loop finishes.

Edited by lomateron, 26 June 2012 - 07:06 AM.


#7 lomateron   Members   -  Reputation: 363

Like
0Likes
Like

Posted 26 June 2012 - 07:20 AM

This was wrong

Edited by lomateron, 26 June 2012 - 08:09 AM.


#8 lomateron   Members   -  Reputation: 363

Like
0Likes
Like

Posted 26 June 2012 - 07:54 AM

cant find the problem

#9 mark ds   Members   -  Reputation: 1486

Like
0Likes
Like

Posted 26 June 2012 - 08:39 AM

My first guess would be that the value of ivb is being read wrong?

Put a breakpoint on the for loop and make a note of the variables.

On other words, you need to make sure (ss/2) is the expected size for your data.

Edited by mark ds, 26 June 2012 - 09:37 AM.


#10 Cornstalks   Crossbones+   -  Reputation: 6991

Like
0Likes
Like

Posted 26 June 2012 - 09:25 AM

I'm going to ask you a series of questions, and I want you to give specific and detailed answers:
  • Did you do what jeroenb suggested and open the file as a binary file (as "rb") (you should be doing this anyway, even if your problem persists)?
  • Are you checking the status of the file with ferror and feof?
  • Are you sure fread is reading the requested number of bytes (it can read fewer than requested)?
  • Are you 100% sure this is a 16-bit, 2 channel PCM WAV file?
  • Have you properly read the "unnecessary info of sound" and verified that you're getting what you expect in the header?
  • Is ivb == size of the file in bytes - 44?

Also, 16 bit PCM WAV files use signed numbers (you should be using short), not unsigned numbers (you shouldn't be using unsigned short) (you'll get the wrong values). And sizeof(BYTE) isn't intuitive, as a BYTE should always have a size of 1 (and if it's more than that for some broken reason, you'll read too much and go past the header).

Edited by Cornstalks, 26 June 2012 - 10:31 AM.

[ I was ninja'd 71 times before I stopped counting a long time ago ] [ f.k.a. MikeTacular ] [ My Blog ] [ SWFer: Gaplessly looped MP3s in your Flash games ]

#11 lomateron   Members   -  Reputation: 363

Like
-1Likes
Like

Posted 26 June 2012 - 03:39 PM

solved, putting the "b" to read as binary solves it.




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.



PARTNERS