English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Asm / Hardware

 
 
Thread Tools
Old 22 April 2021, 07:05   #1
pushead
Registered User
 
Join Date: May 2019
Location: Norway
Posts: 32
CIA or vertical blank/copper interrupt for playing music in an intro?

Hi,

Hope that someone can point me in the right direction here :-)

I'm working on a little intro here, but when it comes to playing music I just can't quite understand what's the "best practice" here. Coming from the C64 I'm used to call the music player once pr. frame. On the Amiga I beleive I can do this by trigger an interrupt with the Copper or on each Vertical Blank (music ticks 50 times/s).

But I notice that quite a few of the Amiga music modules use a different speeds? In order to cope for that the CIA interrupt is used to exactly trigger the playback at the right time. That makes good sense to me, but that would mean that it's much harder to time other effects in the intro? Since the CIA interrupts would be "out of sync" in respect for the framerate I don't see how I can make effects that don't risk interfere with CIA interrupts?

Or am I missing something vital here? Is it normal to use both CIA and Copper interrupts together in an intro/demo?
pushead is offline  
Old 22 April 2021, 08:41   #2
dodke
Registered User
 
Join Date: Feb 2018
Location: London / UK
Posts: 112
Usually you use all the different interrupts. What kind of interference are you worried about?
If something needs to happen at a very specific time then you would do it using the copperlist. I don't think anyone really writes code that follows the scanlines on the Amiga when you have the copper.
dodke is offline  
Old 22 April 2021, 08:52   #3
pushead
Registered User
 
Join Date: May 2019
Location: Norway
Posts: 32
Quote:
Originally Posted by dodke View Post
Usually you use all the different interrupts. What kind of interference are you worried about?
If something needs to happen at a very specific time then you would do it using the copperlist. I don't think anyone really writes code that follows the scanlines on the Amiga when you have the copper.
Ok, let's think of this as an example: say that I've got an intro where I play some music (via CIA interrupts) and a scrolltext that is updated / shifted by the blitter each frame (via a Copper interrupt that trigger a blit at a specific rasterline). What happens if the CIA interrupt triggers first (music playing) and before the CIA interrupt is complete, the Copper interrupt triggers. I beleive that the Copper will then set the flag in the INTREQ, but the interrupt handler will not be invoked since the CPU is now handling the the CIA interrupt? This would lead to glitches I beleive?

Or am I missing the point here? :-)
pushead is offline  
Old 22 April 2021, 09:06   #4
Galahad/FLT
Going nowhere
 
Galahad/FLT's Avatar
 
Join Date: Oct 2001
Location: United Kingdom
Age: 50
Posts: 8,986
Ok, so what you can do is load any prospective music you are using into Protracker first and it will tell you once it starts playing whether its vblank or cia.

The reason for cia is for those module playing speeds that won't be played accurately by vblank because of being too slow whilst playing.

The other thing you can do, is simply use PHX's playroutine, which takes care of ALL that shit for you, sets up the correct interrupt and plays all mods at the required speed.

Do a search on here, or someone will point you to it, but its such a good playroutine that pretty much everyone over the past 7 (?) years just uses it.

I've used in my Atari ST ports, cracktros, PHX uses it in all his games (Trap Runner series etc), and I know its used by others because its easy to implement, works in all Assemblers and is idiot proof
Galahad/FLT is offline  
Old 22 April 2021, 09:18   #5
pushead
Registered User
 
Join Date: May 2019
Location: Norway
Posts: 32
Quote:
Originally Posted by Galahad/FLT View Post
Ok, so what you can do is load any prospective music you are using into Protracker first and it will tell you once it starts playing whether its vblank or cia.

The reason for cia is for those module playing speeds that won't be played accurately by vblank because of being too slow whilst playing.

The other thing you can do, is simply use PHX's playroutine, which takes care of ALL that shit for you, sets up the correct interrupt and plays all mods at the required speed.

Do a search on here, or someone will point you to it, but its such a good playroutine that pretty much everyone over the past 7 (?) years just uses it.

I've used in my Atari ST ports, cracktros, PHX uses it in all his games (Trap Runner series etc), and I know its used by others because its easy to implement, works in all Assemblers and is idiot proof

Ok, thanks! After a quick Google search I found this:

https://aminet.net/package/mus/play/ptplayer

I guess this is the PHX player you are referring to? I'll check it out! Thanks!
pushead is offline  
Old 22 April 2021, 09:33   #6
roondar
Registered User
 
Join Date: Jul 2015
Location: The Netherlands
Posts: 3,408
Yeah, that's PHX's player
roondar is offline  
Old 22 April 2021, 09:48   #7
Antiriad_UK
OCS forever!
 
Antiriad_UK's Avatar
 
Join Date: Mar 2019
Location: Birmingham, UK
Posts: 418
Quote:
Originally Posted by pushead View Post
What happens if the CIA interrupt triggers first (music playing) and before the CIA interrupt is complete, the Copper interrupt triggers. I beleive that the Copper will then set the flag in the INTREQ, but the interrupt handler will not be invoked since the CPU is now handling the the CIA interrupt? This would lead to glitches I beleive?
As others said use PHX's routine for most cases. I use in my intros too.

For scenario above. Cia interrupt for music players is level6 (high priority) and usually only takes a few scan lines to execute. Because of the module timing it will generally occur at a different scan line each frame. For example on frame 1 the cia interrupt may be around scanline 10, on frame 2 it may be 30, basically it could happen anywhere. (Interesting to watch it move around with WinUAE visual debugger)

If you are triggering a lev3 interrupt with the copper alongside PHX's player with cia interrupt then usually will have two outcomes:
1. Lev 6 CIA interrupt is currently executing when copper requests lev3 interrupt
- Lev3 interrupt can't interrupt lev6, so lev3 interrupt only starts once lev6 interrupt finished

2. Lev 3 interrupt is currently executing, cia lev6 requested
- Lev6 cia CAN interrupt lev3, once lev6 finished continues with lev3

So yes, you have to think a little bit about some scenarios where this could cause an issue. For example if you have a very precise "wait for line x" with the cpu in a lev3 then it could potentially miss that check periodically if the music player happened at the same time. So often safer to "wait for line greater than". In practice it's usually fine and you just start the music playing and forget about it
Antiriad_UK is offline  
Old 22 April 2021, 10:00   #8
dodke
Registered User
 
Join Date: Feb 2018
Location: London / UK
Posts: 112
a few things come to mind,
a) scrolling can be done using hardware and you generally only need to update the pointers every 16 pixels on OCS. The pointers and scroll registers in the copperlist can be updated somewhere in the vertical blank for example. The new letters in the scroller can be blit whenever at least a frame in advance outside of the visible screen.
b) Generally there should be enough memory for double / triple buffers and copperlists so most things can be prepared well ahead. Rarely you need to worry about specific rasterlines.
c) sync using the player variables for position or effects.
dodke is offline  
Old 22 April 2021, 12:00   #9
pink^abyss
Registered User
 
Join Date: Aug 2018
Location: Untergrund/Germany
Posts: 408
Quote:
Originally Posted by pushead View Post
But I notice that quite a few of the Amiga music modules use a different speeds?

Easiest solution is to never use CIA timed modules
Seriously, 99.99% of OCS intros and demos don't use CIA timing for playing ProTracker. If the musician knows before then it's not a problem to avoid CIA timing..
pink^abyss is offline  
Old 22 April 2021, 12:00   #10
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
Usually you don't have to rely on interrupts which are only valid for one specific scan line. Many raster line dependent modifications can be done by the Copper, without interrupts. Otherwise a music player running via Level-6 and lasting longer than a raster line is a problem, of course (not that I experienced that as a real problem, in the past).

(Hint: Also don't try to synchronise your program by busy-waiting for a specific raster line - which may not happen, when using a complex Level-6 interrupt routine like a player!)

If you have music, which doesn't use special tempo settings, then a Level-3 VERTB-based play routine can be useful in such a scenario. In ptplayer I also decided to use Level-6 interrupts to avoid busy-waiting (e.g. to reenable Audio DMA for a new note, after the previous one has been cut).

There are three strategies to make a player work without Level-6 timer interrupts:
  1. Use busy-waiting and waste many more raster lines for nothing (not recommended!). Many early players did that.
  2. Use audio interrupts. Quite complicated to handle for each channel, and level-4 will still break your level-3 interrupts.
  3. Delay DMA-enable and setting the loop-pointers until the following VERTB.
I never tried the third option and don't know how well it works. I also didn't feel motivated enough to implement such an option into ptplayer (and make the code more complicated and unreadable).

I remember that ThePlayer 6.1 has such a VERTB-option. So it might be better suited for demo development. The main feature of ptplayer is the integration of sound effects, required by games.
phx is offline  
Old 22 April 2021, 12:03   #11
Antiriad_UK
OCS forever!
 
Antiriad_UK's Avatar
 
Join Date: Mar 2019
Location: Birmingham, UK
Posts: 418
Quote:
Originally Posted by phx View Post
I remember that ThePlayer 6.1 has such a VERTB-option. So it might be better suited for demo development. The main feature of ptplayer is the integration of sound effects, required by games.
Yes this is the thing I miss with ptplayer. Being able to have a non-cia module and run the player at a chosen time (for example, during blitter screen clear) can really help get some effects running in a frame. With cia you just have to accept the raster time tax :/
Antiriad_UK is offline  
Old 22 April 2021, 12:21   #12
pushead
Registered User
 
Join Date: May 2019
Location: Norway
Posts: 32
Thanks everyone! Really appreciate it! Based on all your advice and tips I'll make some test cases for myself - learning by doing!
pushead is offline  
Old 22 April 2021, 15:47   #13
pink^abyss
Registered User
 
Join Date: Aug 2018
Location: Untergrund/Germany
Posts: 408
Quote:
Originally Posted by phx View Post
Delay DMA-enable and setting the loop-pointers until the following VERTB.I never tried the third option and don't know how well it works. I also didn't feel motivated enough to implement such an option into ptplayer (and make the code more complicated and unreadable).
This will introduce artifacts depending on the samples used. I would not recommend it.

I still have to remove the busy loop in PreTracker replayer and just disable dma, let the player code run, and only then busy loop if its still needed... However, perhaps we overcomplicate the rastertime optimization on Amiga. When looking on C64 there its quite common that replayers take 25-30 rasterlines and they stil have enough rastertime to usually do much nicer demos then us amiga folks
pink^abyss is offline  
Old 22 April 2021, 18:24   #14
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
Quote:
Originally Posted by pink^abyss View Post
This will introduce artifacts depending on the samples used. I would not recommend it.
I was afraid of something like that.
Then there is no sane way to do a VERTB-player without timer interrupts. Hmm... maybe you could do a Copper interrupt, 10 lines after VERTB? But this would make player integration more complicated as the copper list is controlled by the main program.
phx is offline  
Old 22 April 2021, 18:50   #15
pink^abyss
Registered User
 
Join Date: Aug 2018
Location: Untergrund/Germany
Posts: 408
Quote:
Originally Posted by pushead View Post
Thanks everyone! Really appreciate it! Based on all your advice and tips I'll make some test cases for myself - learning by doing!

One benefit when you call your replayer with a Copper interrupt is that you can achieve better blitter performance. The reason is that the Blitter will get stalled when DISPLAY DMA is also active (because Blitter has lower priority).
The effects gets bigger the slower your replayer is.
pink^abyss is offline  
Old 23 April 2021, 11:48   #16
defor
Registered User
 
Join Date: Jun 2020
Location: Brno
Posts: 90
Quote:
Originally Posted by phx View Post
I was afraid of something like that.
Then there is no sane way to do a VERTB-player without timer interrupts. Hmm... maybe you could do a Copper interrupt, 10 lines after VERTB? But this would make player integration more complicated as the copper list is controlled by the main program.
P6112-Example.S says:
Code:
; 3    COPPER mode. No F20 or higher commands must be used in the song.
;     - (requires a timed call to P61_Music and a timed copper command 
;        11 scanlines later to set sound DMA.)
Is this somehow related to what you wrote? 11 lines, 10 lines... sounds quite similar to me. Just asking out of pure curiosity.
defor is offline  
Old 23 April 2021, 13:11   #17
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
Quote:
Originally Posted by defor View Post
Is this somehow related to what you wrote? 11 lines, 10 lines... sounds quite similar to me.
Yes. I didn't have the exact number in my mind. I just remembered that old players busy-waited for approximately 10 raster lines. Looks like P61 already offers a solution via Copper interrupt? Nice.
phx is offline  
Old 23 April 2021, 13:16   #18
DanScott
Lemon. / Core Design
 
DanScott's Avatar
 
Join Date: Mar 2016
Location: Tier 5
Posts: 1,209
Quote:
Originally Posted by phx View Post
Yes. I didn't have the exact number in my mind. I just remembered that old players busy-waited for approximately 10 raster lines. Looks like P61 already offers a solution via Copper interrupt? Nice.
Is it a copper interrupt? Or is it just a write to DMACON done with the copper list? (This is how Leonards LSP player does it)
DanScott is online now  
Old 23 April 2021, 13:48   #19
defor
Registered User
 
Join Date: Jun 2020
Location: Brno
Posts: 90
Quote:
Originally Posted by DanScott View Post
Is it a copper interrupt? Or is it just a write to DMACON done with the copper list? (This is how Leonards LSP player does it)
I think it's the latter one.
defor is offline  
Old 23 April 2021, 17:16   #20
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
Quote:
Originally Posted by DanScott View Post
Is it a copper interrupt? Or is it just a write to DMACON done with the copper list?
I always thought this is the only way to cause a copper interrupt. Are there others?
phx is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
CIA periodic interrupt jotd Coders. Asm / Hardware 12 02 January 2021 21:22
Extended Vertical Blank sandruzzo Coders. Asm / Hardware 9 23 October 2019 15:17
Vertical blank and Bobs geldo79 Coders. Asm / Hardware 4 21 October 2019 10:04
example of a CIA timer interrupt in assembler using cia.resource Apollo Coders. Asm / Hardware 3 05 July 2013 08:40
CIA timer interrupt handler called twice during mod playback absence Coders. General 5 16 March 2009 18:55

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 12:16.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.16041 seconds with 13 queries