Forums | developer.brewmp.com Forums | developer.brewmp.com

Developer

Forums

Forums:

I've been writing a simple game. Now i want to add sound, i used ISound and ISoundPlayer. The problem is the game no longer run smoothly, whenever a sound is played or stop, the FPS of the game drop from 60 to 40. I think its notify functions take too much time. :(
How to solve this?

Sorry for my bad english. :p

Hi,
I think your game has good frame rate. My game only has 20 FPS. When the game starts 3D animation, the frame rate goes down to 15 FPS.
I guess you don't use streaming because you use ISound and ISoundPlayer. For these APIs, I don't think it's possible to avoid the delay. I use streaming, so I start the streaming first, and feed IMedia the sound data when necessary. in this case, there is no delay because playback is started in advance.
Good luck.

Hi,
I think your game has good frame rate. My game only has 20 FPS. When the game starts 3D animation, the frame rate goes down to 15 FPS.
I guess you don't use streaming because you use ISound and ISoundPlayer. For these APIs, I don't think it's possible to avoid the delay. I use streaming, so I start the streaming first, and feed IMedia the sound data when necessary. in this case, there is no delay because playback is started in advance.
Good luck.

lugia wrote:I've been writing a simple game. Now i want to add sound, i used ISound and ISoundPlayer. The problem is the game no longer run smoothly, whenever a sound is played or stop, the FPS of the game drop from 60 to 40. I think its notify functions take too much time. :(
How to solve this?
Sorry for my bad english. :p
Make sure and use a buffer as an audio source rather than a file.
This way you can pre-load all of your sounds into memory. That being said,
those are pretty good frame rates for mobile.

lugia wrote:I've been writing a simple game. Now i want to add sound, i used ISound and ISoundPlayer. The problem is the game no longer run smoothly, whenever a sound is played or stop, the FPS of the game drop from 60 to 40. I think its notify functions take too much time. :(
How to solve this?
Sorry for my bad english. :p
Make sure and use a buffer as an audio source rather than a file.
This way you can pre-load all of your sounds into memory. That being said,
those are pretty good frame rates for mobile.

I tried like you guys said but it didn't work. :( :(
My sound class looks like this

class CGameSound{private:    ISound * pISound;
public:    CGameSound ()    {        ISHELL_CreateInstance (pIShell, AEECLSID_SOUND, (void**) &pISound);        ISOUND_RegisterNotify (pISound, NULL, NULL);    }        void beep()    {        AEESoundToneData a;
        a.eTone         = 5;        a.wDuration = 2000;
        ISOUND_PlayTone (pISound, a);    }}

I call beep() when a button is pressed. When the sound played and when it stoped, the game stoped for a moment.
I also tried with ISoundPlayer, IMedia. I set up the stream in the constructor and call ISOUNDPLAYER_Play(), or IMEDIA_Play() in beep(). It also didnt work :(
I thought ISOUND_PlayTone() would run fast cause it plays some built-in tones.
So now i think calling notify functions takes too much time, not loading the sound. Or where did i do wrong ? :( :(
PS, I'm learning brew, this game is very simple, hence the framerate is high. :p

I tried like you guys said but it didn't work. :( :(
My sound class looks like this

class CGameSound{private:    ISound * pISound;
public:    CGameSound ()    {        ISHELL_CreateInstance (pIShell, AEECLSID_SOUND, (void**) &pISound);        ISOUND_RegisterNotify (pISound, NULL, NULL);    }        void beep()    {        AEESoundToneData a;
        a.eTone         = 5;        a.wDuration = 2000;
        ISOUND_PlayTone (pISound, a);    }}

I call beep() when a button is pressed. When the sound played and when it stoped, the game stoped for a moment.
I also tried with ISoundPlayer, IMedia. I set up the stream in the constructor and call ISOUNDPLAYER_Play(), or IMEDIA_Play() in beep(). It also didnt work :(
I thought ISOUND_PlayTone() would run fast cause it plays some built-in tones.
So now i think calling notify functions takes too much time, not loading the sound. Or where did i do wrong ? :( :(
PS, I'm learning brew, this game is very simple, hence the framerate is high. :p

lugia wrote:I tried like you guys said but it didn't work. :( :(
My sound class looks like this

class CGameSound{private:    ISound * pISound;
public:    CGameSound ()    {        ISHELL_CreateInstance (pIShell, AEECLSID_SOUND, (void**) &pISound);        ISOUND_RegisterNotify (pISound, NULL, NULL);    }        void beep()    {        AEESoundToneData a;
        a.eTone         = 5;        a.wDuration = 2000;
        ISOUND_PlayTone (pISound, a);    }}

I call beep() when a button is pressed. When the sound played and when it stoped, the game stoped for a moment.
I also tried with ISoundPlayer, IMedia. I set up the stream in the constructor and call ISOUNDPLAYER_Play(), or IMEDIA_Play() in beep(). It also didnt work :(
I thought ISOUND_PlayTone() would run fast cause it plays some built-in tones.
So now i think calling notify functions takes too much time, not loading the sound. Or where did i do wrong ? :( :(
PS, I'm learning brew, this game is very simple, hence the framerate is high. :p
I wouldn't use PlayTone(). If you want that kind of sound then use
.midi and load it into a malloc'd buffer first before
calling ISOUNDPLAYER_SetInfo with the buffer.

lugia wrote:I tried like you guys said but it didn't work. :( :(
My sound class looks like this

class CGameSound{private:    ISound * pISound;
public:    CGameSound ()    {        ISHELL_CreateInstance (pIShell, AEECLSID_SOUND, (void**) &pISound);        ISOUND_RegisterNotify (pISound, NULL, NULL);    }        void beep()    {        AEESoundToneData a;
        a.eTone         = 5;        a.wDuration = 2000;
        ISOUND_PlayTone (pISound, a);    }}

I call beep() when a button is pressed. When the sound played and when it stoped, the game stoped for a moment.
I also tried with ISoundPlayer, IMedia. I set up the stream in the constructor and call ISOUNDPLAYER_Play(), or IMEDIA_Play() in beep(). It also didnt work :(
I thought ISOUND_PlayTone() would run fast cause it plays some built-in tones.
So now i think calling notify functions takes too much time, not loading the sound. Or where did i do wrong ? :( :(
PS, I'm learning brew, this game is very simple, hence the framerate is high. :p
I wouldn't use PlayTone(). If you want that kind of sound then use
.midi and load it into a malloc'd buffer first before
calling ISOUNDPLAYER_SetInfo with the buffer.

jmiller2 wrote:I wouldn't use PlayTone(). If you want that kind of sound then use
.midi and load it into a malloc'd buffer first before
calling ISOUNDPLAYER_SetInfo with the buffer.
Yeah, i've already tried that but the problem still arised :confused:

jmiller2 wrote:I wouldn't use PlayTone(). If you want that kind of sound then use
.midi and load it into a malloc'd buffer first before
calling ISOUNDPLAYER_SetInfo with the buffer.
Yeah, i've already tried that but the problem still arised :confused:

lugia wrote:Yeah, i've already tried that but the problem still arised :confused:
Then I think what you want to do is look at your game loop.
Check the MS each time and adjust accordingly so that the
game runs smooth. Take your actual and not anticipated framerate
and set your timer accordingly.

lugia wrote:Yeah, i've already tried that but the problem still arised :confused:
Then I think what you want to do is look at your game loop.
Check the MS each time and adjust accordingly so that the
game runs smooth. Take your actual and not anticipated framerate
and set your timer accordingly.

Thank you for ur advice. My game loop is quite simple, i used AEECallback & ISHELL_SetTimerEx just like the SpriteGame example downloaded on Brew website. :D
The interval between 2 game loops is about 15ms. It increased to 60ms at the time when the sound started playing, and to 120ms when the sound stoped playing.
I adjusted the timer callback so that the framerate's about 18FPS. At this time, the interval between loops was about 55ms. It didn't change when the sound started playing, but still went to 120ms (sometimes 170ms) when the sound stoped playing. Hence now the game only delay when the sound stop playing.
I dont want framerate that low, maybe i should give up on the sound :mad:

Thank you for ur advice. My game loop is quite simple, i used AEECallback & ISHELL_SetTimerEx just like the SpriteGame example downloaded on Brew website. :D
The interval between 2 game loops is about 15ms. It increased to 60ms at the time when the sound started playing, and to 120ms when the sound stoped playing.
I adjusted the timer callback so that the framerate's about 18FPS. At this time, the interval between loops was about 55ms. It didn't change when the sound started playing, but still went to 120ms (sometimes 170ms) when the sound stoped playing. Hence now the game only delay when the sound stop playing.
I dont want framerate that low, maybe i should give up on the sound :mad:

lugia wrote:Thank you for ur advice. My game loop is quite simple, i used AEECallback & ISHELL_SetTimerEx just like the SpriteGame example downloaded on Brew website. :D
The interval between 2 game loops is about 15ms. It increased to 60ms at the time when the sound started playing, and to 120ms when the sound stoped playing.
I adjusted the timer callback so that the framerate's about 18FPS. At this time, the interval between loops was about 55ms. It didn't change when the sound started playing, but still went to 120ms (sometimes 170ms) when the sound stoped playing. Hence now the game only delay when the sound stop playing.
I dont want framerate that low, maybe i should give up on the sound :mad:
While much of this depends upon the device you are testing against,
none of that sounds right to me. Most modern BREW devices should have
no problem with a full screen (plus other stuff) blits to get at least 15-20fps.
Playing background midi shouldn't affect it much. I suspect you are still doing
something wrong either in your sound callback function or in the basic code.
ISOUNDPLAYER_StopSound does not cause a CPU hit in my experience.
I never noticed sound causing much of a CPU hit even with old BREW devices
as long as ISOUNDPLAYER_SetInfo was using BUFFER type and not file.
With any file I/O all bets are off.

lugia wrote:Thank you for ur advice. My game loop is quite simple, i used AEECallback & ISHELL_SetTimerEx just like the SpriteGame example downloaded on Brew website. :D
The interval between 2 game loops is about 15ms. It increased to 60ms at the time when the sound started playing, and to 120ms when the sound stoped playing.
I adjusted the timer callback so that the framerate's about 18FPS. At this time, the interval between loops was about 55ms. It didn't change when the sound started playing, but still went to 120ms (sometimes 170ms) when the sound stoped playing. Hence now the game only delay when the sound stop playing.
I dont want framerate that low, maybe i should give up on the sound :mad:
While much of this depends upon the device you are testing against,
none of that sounds right to me. Most modern BREW devices should have
no problem with a full screen (plus other stuff) blits to get at least 15-20fps.
Playing background midi shouldn't affect it much. I suspect you are still doing
something wrong either in your sound callback function or in the basic code.
ISOUNDPLAYER_StopSound does not cause a CPU hit in my experience.
I never noticed sound causing much of a CPU hit even with old BREW devices
as long as ISOUNDPLAYER_SetInfo was using BUFFER type and not file.
With any file I/O all bets are off.

Thanks, I'll recheck whole project. Recently i dont have enough time. :D

Thanks, I'll recheck whole project. Recently i dont have enough time. :D

I teared down the whole project until there're only the game loop and the sound player, and still didn't find anything wrong.
The game still delays when the sound plays & stops. I tested on the simulator (there're no brew device around here).
There's this attachment, anyone help pls. :(

I teared down the whole project until there're only the game loop and the sound player, and still didn't find anything wrong.
The game still delays when the sound plays & stops. I tested on the simulator (there're no brew device around here).
There's this attachment, anyone help pls. :(