Game music
Moderator: Moderators
Game music
Hi,
I've always wondered how the programming for in-game music is achieved. Does the programmer set up an interrupt that jumps to a music routine? Or do you manually jump during the vertical blank? How does the music regulate its tempo if you are just manually jumping every 1/50th second to a music routine?
Thanks!
kelp
I've always wondered how the programming for in-game music is achieved. Does the programmer set up an interrupt that jumps to a music routine? Or do you manually jump during the vertical blank? How does the music regulate its tempo if you are just manually jumping every 1/50th second to a music routine?
Thanks!
kelp
MZ-80A Secrets
http://mz-80a.com
http://mz-80a.com
-
- Vic 20 Hobbyist
- Posts: 128
- Joined: Sun Dec 26, 2010 1:51 pm
Re: Game music
It is usually jsr'ed to in the IRQ. Tempo wise you have a decent amount of wiggle, as in practice you'll be holding notes; even a sixteenth note needs to be sustained for several screen refreshes.
Music is done using tables, with values to feed into the registers, and a value to determine length. Each time the routine is called, the length is decremented or compared, and if it's over, the next note/length in the table is grabbed.
Music is done using tables, with values to feed into the registers, and a value to determine length. Each time the routine is called, the length is decremented or compared, and if it's over, the next note/length in the table is grabbed.
- Kweepa
- Vic 20 Scientist
- Posts: 1303
- Joined: Fri Jan 04, 2008 5:11 pm
- Location: Austin, Texas
- Occupation: Game maker
Re: Game music
Here's an example, from Doom:
https://github.com/Kweepa/vicdoom/blob/ ... laysound.s
It works pretty much as malcontent describes.
I didn't change the interrupt frequency away from its default 60Hz.
https://github.com/Kweepa/vicdoom/blob/ ... laysound.s
It works pretty much as malcontent describes.
I didn't change the interrupt frequency away from its default 60Hz.
Re: Game music
If you require raster splits for graphics purposes in your code then it's a good idea to also call the music synchronized with the screen update.
I tend to do that always unless there is a specific reason.
I tend to do that always unless there is a specific reason.
Re: Game music
As ever I applaud this forum and its forumites
always receive many a helpful answer when I pose these (probably newbie) questions...
thanks!
kelp

thanks!
kelp
MZ-80A Secrets
http://mz-80a.com
http://mz-80a.com
Re: Game music
Actually, on a similar topic to this (and bear with me because I really am pretty new to writing games). Sound effects in games, are these done in a similar way to the music? In my younger years when I did actually try writing my own games the sound would always stop the rest of the program, i.e. the action on screen would halt while the sound played. Obviously, I wasn't writing in machine language or assembly then... just BASIC. I'm guessing from the above answers that it's a pretty similar method to the music?
kelp
kelp
MZ-80A Secrets
http://mz-80a.com
http://mz-80a.com
Re: Game music
Not sure about anyone else but my sounds in Pooyan are actually small tunes. I have two music players. The effects player steals channels from the background music as needed.
Sent from my Nexus 5 using Tapatalk
Sent from my Nexus 5 using Tapatalk
Re: Game music
.....So I can play a sound effect or tune by just setting a value in memory that gets polled during the IRQ handler
Sent from my Nexus 5 using Tapatalk
Sent from my Nexus 5 using Tapatalk
- Mike
- Herr VC
- Posts: 5134
- Joined: Wed Dec 01, 2004 1:57 pm
- Location: Munich, Germany
- Occupation: electrical engineer
Re: Game music
Really?kelp7 wrote:[...](and bear with me because I really am pretty new to writing games).[...]
http://sleepingelephant.com/ipw-web/bul ... php?t=2904
... and to quote from this posting in 2008:
Sorry, but ...I [...] am going to jump straight in at the deep end with machine language rather than BASIC. (Simply because i've written other games in machine code on other machines).

- Kweepa
- Vic 20 Scientist
- Posts: 1303
- Joined: Fri Jan 04, 2008 5:11 pm
- Location: Austin, Texas
- Occupation: Game maker
Re: Game music
Doom's sound effects are similar to the music - the code is in the same file.
I use the noise channel exclusively for sound effects, but I pause the music because the volume for the effects needs to be cranked up to be heard.
I use the noise channel exclusively for sound effects, but I pause the music because the volume for the effects needs to be cranked up to be heard.
Re: Game music
Would it possible to do it like this?
- first interrupt cycle silents noise-channels, sets volume to 8, plays music note
- second interrupt cycle silents music-channels, sets volume to 15, plays noise channel
- repeat
No idea if that would sound as one would expect (low music, loud noise).
- first interrupt cycle silents noise-channels, sets volume to 8, plays music note
- second interrupt cycle silents music-channels, sets volume to 15, plays noise channel
- repeat
No idea if that would sound as one would expect (low music, loud noise).
Re: Game music
Haha, yep. I'd still consider myself a newbie. Any 'games' I may have written before were pretty basic themselves and I understand a reasonable amount of programming theory (iteration, jumps, etc) but there are plenty of things I still have no clue aboutMike wrote:Really?kelp7 wrote:[...](and bear with me because I really am pretty new to writing games).[...]
http://sleepingelephant.com/ipw-web/bul ... php?t=2904
... and to quote from this posting in 2008:
Sorry, but ...I [...] am going to jump straight in at the deep end with machine language rather than BASIC. (Simply because i've written other games in machine code on other machines).

kelp
MZ-80A Secrets
http://mz-80a.com
http://mz-80a.com
Re: Game music
...and thanks everyone for the rest of the replies! Very helpful and does shed light on how these things work...
MZ-80A Secrets
http://mz-80a.com
http://mz-80a.com