#7528 - Wildginger - Thu Jun 19, 2003 11:00 am
Hi all,
I have used Chris Stricklands audio code examples, to get my game playing sound effects. All is working fine, but I have since gone from moving my character tile by tile, to smooth scrolling. Only now, the puase while the sound effect is being played, is very noticeable, and I would like to get rid of it.
How do you all stop your sound effects? Im counting the vblanks at the moment, as in Chris's tutorials, but he does mention using a timer to generate an interrupt request.
Is this the best way? And does anyone have some sample code on how this is done?
Thanks in advance for any help,
_________________
---
Wildginger (aka JimTownsend)
#7542 - tepples - Thu Jun 19, 2003 5:23 pm
This should work:
Load timer 1 with your sample rate. Load timer 2 with 65536 minus the number and set it to cascade off timer 1.
But note that if you're playing two separate sound effects on the two DSound channels, you won't be able to cascade them both (a timer can cascade only from the previous timer); you'll have to think of something more tricky.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.
#7561 - Ninja - Thu Jun 19, 2003 8:40 pm
At the moment, I don't really have my audio code set up properly, but here's what I am doing.
I have set one of my timers to overflow every millisecond. When that happens, an interupt occurs, and I increment a global u32 that I have set up. Incrementing every millisecond, the u32 won't overflow for 50 days, and I consider that to be an acceptable bug. I can't see anyone leaving their GBA on for 50 days straight.
With that u32, I can time pretty much everything in my program at the cost of a few bytes. I use it to time my sprite animations, and I use it to time my audio as well. When the end of the audio stream happens, I shut down the DMA channel, and everyone's happy. :)
There's probably a far better way of achieving good timing, but that's the way that I do it, as it's easy to code, and it's effective.
#7564 - tepples - Thu Jun 19, 2003 9:21 pm
Ninja wrote: |
I have set one of my timers to overflow every millisecond. |
I have set one of my timers to overflow every 16.74 milliseconds. In fact, I don't even need to use one of the four programmable timers for this because this rate is built into the GBA's display controller.
Quote: |
Incrementing every millisecond, the u32 won't overflow for 50 days, and I consider that to be an acceptable bug. I can't see anyone leaving their GBA on for 50 days straight. |
Microsoft engineers thought precisely the same thing when making Windows 95, but the "49 day uptime freeze" headlined in the news media... about 50 days after Windows 95 was released. It might be a good idea to reset this clock at Game Over.
Quote: |
With that u32, I can time pretty much everything in my program at the cost of a few bytes. I use it to time my sprite animations |
Sprite animations should run once every vblank for smoothest display.
Quote: |
There's probably a far better way of achieving good timing, but that's the way that I do it, as it's easy to code, and it's effective. |
Is it easier than timing your game off vblank?
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.
#7583 - Wildginger - Fri Jun 20, 2003 11:08 am
Hi all,
Thanks for the replys.
After much playing around I went for the global counter approach, and all seems to be working nicely!
I might look into it more when I get a bit more experienced at it, but it will do the job nicely for now :)
Thanks again,
_________________
---
Wildginger (aka JimTownsend)
#7647 - Ninja - Sun Jun 22, 2003 11:41 am
tepples wrote: |
Ninja wrote: | I have set one of my timers to overflow every millisecond. |
I have set one of my timers to overflow every 16.74 milliseconds. In fact, I don't even need to use one of the four programmable timers for this because this rate is built into the GBA's display controller. |
Point taken. But I am simple minded, and I really like to have nice even numbers to work with. I will mention that the GetTickCount() function I have made actually takes the place of a timer in many situations though, so I am not sure that I really need all 4 timers.
tepples wrote: |
Quote: | Incrementing every millisecond, the u32 won't overflow for 50 days, and I consider that to be an acceptable bug. I can't see anyone leaving their GBA on for 50 days straight. |
Microsoft engineers thought precisely the same thing when making Windows 95, but the "49 day uptime freeze" headlined in the news media... about 50 days after Windows 95 was released. It might be a good idea to reset this clock at Game Over. |
Actually, when the variable overflows, it screws up my animations for half a second, and that's about it. I try not to allow bugs that could seriously harm the game into the code. However, I think that if I were coding an OS, I would never do things this way. That was just careless and stupid of Microsoft. A PC is a far cry from a handheld.
tepples wrote: |
Quote: | With that u32, I can time pretty much everything in my program at the cost of a few bytes. I use it to time my sprite animations |
Sprite animations should run once every vblank for smoothest display. |
Well, I do run the sprite once every vblank. It's just that I don't change the frame until a set time is past.
tepples wrote: |
Quote: | There's probably a far better way of achieving good timing, but that's the way that I do it, as it's easy to code, and it's effective. |
Is it easier than timing your game off vblank? |
For some reason I was never able to get accurate timing off the vblank. :( I imagine I was doing something wrong, but it didn't work for me.