News:

Printed Amstrad Addict magazine announced, check it out here!

Main Menu
avatar_ervin

sound & music question

Started by ervin, 06:11, 21 June 12

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

ervin

Hi all.

Quick question for you all...

In the game I am developing, I abuse the stack a heck of a lot, and turn interrupts on and off constantly in order to use as many speed-up tricks as I can.

Now, because the amount of time taken to draw each frame can vary (and is in fact unpredictable, because I am using adaptive screen refreshing), will I have problems with sound/music, especially considering that interrupts are turned off/on 50 times during the screen update phase?

arnoldemu

Quote from: ervin on 06:11, 21 June 12
Hi all.

Quick question for you all...

In the game I am developing, I abuse the stack a heck of a lot, and turn interrupts on and off constantly in order to use as many speed-up tricks as I can.

Now, because the amount of time taken to draw each frame can vary (and is in fact unpredictable, because I am using adaptive screen refreshing), will I have problems with sound/music, especially considering that interrupts are turned off/on 50 times during the screen update phase?
possibly. you may miss the interrupt that happens during vsync. you could try clearing the interrupt counter to see if that helps.
My games. My Games
My website with coding examples: Unofficial Amstrad WWW Resource

Axelay

Quote from: ervin on 06:11, 21 June 12

Now, because the amount of time taken to draw each frame can vary (and is in fact unpredictable, because I am using adaptive screen refreshing), will I have problems with sound/music, especially considering that interrupts are turned off/on 50 times during the screen update phase?


Do you use interupts for anything?  If you're turning them on and off so often, maybe they could just be left off?


But if interupts can't be relied upon, and you have such a variable frame rate, I'm not sure what you could do other than try to break your screen refreshing process down into blocks of a known time unit you can keep track of.

ralferoo

Quote from: ervin on 06:11, 21 June 12
Now, because the amount of time taken to draw each frame can vary (and is in fact unpredictable, because I am using adaptive screen refreshing), will I have problems with sound/music, especially considering that interrupts are turned off/on 50 times during the screen update phase?
Possibly, possibly not. The information here is helpful: Interrupt Generation Facility of the Amstrad Gate Array

The key thing to take away from this is that the counter is always reset after a VSYNC. Now, you may or may not get a resulting interrupt on line 2 from that, but you always will on line 54 if you haven't disabled interrupts in the mean time. So, if you know that ballpark your code always takes somewhere between 87%-99% of the frame rate and you have to disable interrupts for a long period, this may help you get back in sync.

If you can batch this work into smaller chunks, as you are doing - 50 times per frame is about 6 lines, so if you disable interrupts, do some work and re-enable them, the interrupt will be triggered after the instruction after the EI finishes. If the interrupt return happens less than 32 lines after the interrupt was originally due, you'll continue to stick to the 52 line cycle, although obviously each particular interrupt could be delayed. But, most importantly, if you disable interrupts for less than 12 lines, you know that you can still rely on checking the VSYNC pulse in the interrupt handler and being able to identify the top of the screen interrupt.

Whether the random frame-by-frame delay to the audio will be noticeable, that is debatable. Some will argue yes, some no. Again, the smaller the time between interrupts the better, alternatively, you could implement a simple task switcher, and do house keeping tasks that don't require disabling interrupts after the interrupt with vblank, knowing that the next interrupt is always line 54 and a good point to do the music and then switch back to the code that needs to enable / disable frequently.

ervin

Thanks for all the information guys.

Ralferoo - thanks for all the info - very helpful.

However, I'm now thinking that music may not be feasible... the frame rate can fluctuate a bit due to the fact that the screen display is faster when there are smaller sprites on the screen. Maybe I'll just have simple sound effects during the game.

Doesn't really matter - in my brain it's just a simple game wrapped around some cool graphical techniques.


arnoldemu

Quote from: ervin on 14:06, 21 June 12
Thanks for all the information guys.

Ralferoo - thanks for all the info - very helpful.

However, I'm now thinking that music may not be feasible... the frame rate can fluctuate a bit due to the fact that the screen display is faster when there are smaller sprites on the screen. Maybe I'll just have simple sound effects during the game.

Doesn't really matter - in my brain it's just a simple game wrapped around some cool graphical techniques.

In my games I use interrupts for playing music, scanning the keyboard and triggering the "present" (switching the double buffering so you can see what you have drawn).

So it may be possible for the music to run this way. You only need 1 interrupt per frame to see the vsync and you will be ok.

The other alternative is to split the work into 50hz chunks and call the music player after each chunk. the rate should be ok for the sound to be good.

the other alternative is to program a particular repeating sound and use the hardware envelopes of the ay. You could get some kind of space like repeating sound that may work, and you only need to update it every now and then to stop it being annoying.
(Some c64 demos use this, but they have more flexibility with their volume envelopes).




My games. My Games
My website with coding examples: Unofficial Amstrad WWW Resource

MacDeath

Just do your game for PLUS and make good use of the few DMA sound channel ...


;D

ok, it was trolling.

ervin

 :laugh:

If I had any interest in the PLUS series, then I may do so.
Unfortunately...

arnoldemu

Quote from: MacDeath on 05:37, 22 June 12
Just do your game for PLUS and make good use of the few DMA sound channel ...


;D

ok, it was trolling.
it's a useful troll ;)
My games. My Games
My website with coding examples: Unofficial Amstrad WWW Resource

Powered by SMFPacks Menu Editor Mod