0
0

Hi,

I have just downloaded fmod for ce and am having a problem playing a simple wav file.

I am writing a game and I am trying to play a wav when the player hits the fire button. On hitting the fire button there is a long delay and then the sound will play. The sound will then not play again until the player has hit and shot several more missiles.

The wav file has the following properties:-

Length 0.60 secs
Size 13438 bytes
Format PCM 22.050kHz, 8bit, Mono

The code I am using to initialise fmod is as follows:-

stream=NULL;

FSOUND_SetMixer(FSOUND_MIXER_AUTODETECT);
FSOUND_SetBufferSize(600);
if (!FSOUND_Init(22050, 32,FSOUND_INIT_GLOBALFOCUS))
{
}
FILE * fp;
int length;
char * data;

fp = fopen(“shoot2.wav”, “rb”);
if (!fp)
{
FSOUND_Close();
}
fseek(fp, 0, SEEK_END);
length = ftell(fp);
fseek(fp, 0, SEEK_SET);

data = (char *)malloc(length);
fread(data, length, 1, fp);
fclose(fp);

stream = FSOUND_Stream_OpenFile(data, FSOUND_NORMAL | FSOUND_LOADMEMORY , length);

and to play the sound I use:-
streamchan = FSOUND_Stream_Play(FSOUND_FREE, stream);

Please could somebody tell me where I am going wrong.

Thanks in advance
Bad

  • You must to post comments
0
0

I am using GAPI and not HDC. I don’t know if that makes a difference

Cheers
Bad

  • You must to post comments
0
0

Brett,

Thanks for the reply. I was using fmod in my game over a network link and in debug mode on my ipaq. I only put the FSOUND_SetBufferSize(600) because when I pressed the fire button I got a stutter before the sound effect was played in full which I was trying to fix. Running in release mode without the link things seemed to get better, though there is still a delay.

I have not tried removing the FSOUND_SetBufferSize command yet as I am not at home, but I will later today.

With this topic I just wanted to confirm that I am using the correct commands in the correct sequence to play the .wav from memory, am I?

Also, in your testing, what .wav format did you find to be most suitable for the iPaq (freq,mono/stereo/8/16bit)?

Thanks in advance
Bad

<font size=-1>[ This Message was edited by: BadBazza on 2001-11-29 03:36 ]</font>

  • You must to post comments
0
0

Thanks Brett,

I will try FSOUND_Stream_SetPosition(stream, 0) later on today and let you know the outcome.

Cheers
Bad

  • You must to post comments
0
0

Brett,

We seem to be getting somewhere :smile:

The sound starts exactly at the right time, but if the player hits the fire button twice in succession the sound of the missile is only heard once. In fact it is another 5 or 6 fire button presses before another sound can be heard. Is there something that I have not done?

Do I have to do something after the FSOUND_Stream_Play?

Thanks in advance
Bad

  • You must to post comments
0
0

Do I need FSOUND_Stream_SetEndCallback(stream, endcallback, 0); and FSOUND_Stream_SetSynchCallback(stream, endcallback, 0);

with a callback function?

Thanks in advance
Bad

  • You must to post comments
0
0

Brett… Help!!

I think I’ve found the problem but I don’t know how to fix it :sad:

I have put diagnostics on my game and ran it. I then pressed the fire button 10 times in slow succession. The first time and the last time the wav was played correctly, the other 8 times no sound was made.

after the line
streamchan = FSOUND_Stream_Play(FSOUND_FREE, stream);
I logged the value of streamchan. The first time it was 4096. It was also 4096 for the next 9 presses (where no sound was made) however for the last press the value changed to 4097 and the wav played

What am I doing wrong?

Thanks in advance
Bad

  • You must to post comments
0
0

Thanks Brett, I will try that out tomorrow. Can I still load it into memory and play it from there?

Thanks
Barry

  • You must to post comments
0
0

Hi,

I think that method automatically loads the file into memory. Its good for games because you load all the samples during startup then there is no delay in the game when you play them. Plus you can play them multiple times at once.

I have code for that working fine. If you email me I’d be happy to send it to you.

regards,

Simon.
simon@strategicassault.com

  • You must to post comments
0
0

Simon,

Thank you for your response and I may take you up on your offer. But first I am going to try and get it working for myself (helps me understand what I am doing) though if I do get it working it may be interesting to compare methods.

Thanks again
Bad

  • You must to post comments
Showing 9 results
Your Answer

Please first to submit.