Author Topic: sound & music question  (Read 2374 times)

0 Members and 1 Guest are viewing this topic.

Offline ervin

  • Supporter
  • 6128 Plus
  • *
  • Posts: 1.417
  • Country: au
    • index.php?action=treasury
  • Liked: 1110
  • Likes Given: 1321
sound & music question
« on: 08: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?
 
« Last Edit: 08:15, 21 June 12 by ervin »
My (cancelled) entry for the CPCRetroDev 2017 Competition http://www.cpcwiki.eu/forum/programming/my-cpcretrodev-2017-entry/
FAST line drawing in CPCtelera http://www.cpcwiki.eu/forum/programming/drawing-lines-with-cpctelera-sdcc/
RUNCPC My entry for the CPCRetroDev 2015 Competition http://www.cpc-power.com/index.php?page=detail&num=12494

Offline arnoldemu

  • Supporter
  • 6128 Plus
  • *
  • Posts: 5.336
  • Country: gb
    • Unofficial Amstrad WWW Resource
  • Liked: 2278
  • Likes Given: 3478
Re: sound & music question
« Reply #1 on: 11:38, 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

Offline Axelay

  • 6128 Plus
  • ******
  • Posts: 587
  • Country: au
  • Liked: 385
  • Likes Given: 88
Re: sound & music question
« Reply #2 on: 13:12, 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.

Offline ralferoo

  • Supporter
  • 6128 Plus
  • *
  • Posts: 970
  • Country: gb
  • Liked: 583
  • Likes Given: 222
Re: sound & music question
« Reply #3 on: 15:40, 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.

Offline ervin

  • Supporter
  • 6128 Plus
  • *
  • Posts: 1.417
  • Country: au
    • index.php?action=treasury
  • Liked: 1110
  • Likes Given: 1321
Re: sound & music question
« Reply #4 on: 16: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.

My (cancelled) entry for the CPCRetroDev 2017 Competition http://www.cpcwiki.eu/forum/programming/my-cpcretrodev-2017-entry/
FAST line drawing in CPCtelera http://www.cpcwiki.eu/forum/programming/drawing-lines-with-cpctelera-sdcc/
RUNCPC My entry for the CPCRetroDev 2015 Competition http://www.cpc-power.com/index.php?page=detail&num=12494

Offline arnoldemu

  • Supporter
  • 6128 Plus
  • *
  • Posts: 5.336
  • Country: gb
    • Unofficial Amstrad WWW Resource
  • Liked: 2278
  • Likes Given: 3478
Re: sound & music question
« Reply #5 on: 16:13, 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

Offline MacDeath

  • Chaotic post writer and mock-up specialist
  • Supporter
  • 6128 Plus
  • *
  • Posts: 4.068
  • Country: fr
  • Liked: 1183
  • Likes Given: 667
Re: sound & music question
« Reply #6 on: 07: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.

Offline ervin

  • Supporter
  • 6128 Plus
  • *
  • Posts: 1.417
  • Country: au
    • index.php?action=treasury
  • Liked: 1110
  • Likes Given: 1321
Re: sound & music question
« Reply #7 on: 07:39, 22 June 12 »
 :laugh:
 
If I had any interest in the PLUS series, then I may do so.
Unfortunately...
My (cancelled) entry for the CPCRetroDev 2017 Competition http://www.cpcwiki.eu/forum/programming/my-cpcretrodev-2017-entry/
FAST line drawing in CPCtelera http://www.cpcwiki.eu/forum/programming/drawing-lines-with-cpctelera-sdcc/
RUNCPC My entry for the CPCRetroDev 2015 Competition http://www.cpc-power.com/index.php?page=detail&num=12494

Offline arnoldemu

  • Supporter
  • 6128 Plus
  • *
  • Posts: 5.336
  • Country: gb
    • Unofficial Amstrad WWW Resource
  • Liked: 2278
  • Likes Given: 3478
Re: sound & music question
« Reply #8 on: 11:40, 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