How do I make background sound?
- Ast A. Moore
- Rick Dangerous
- Posts: 2641
- Joined: Mon Nov 13, 2017 3:16 pm
Re: How do I make background sound?
Found another interesting example: Moonlight Madness. It’s two-channel, naturally choppy, but not as grating as Manic Miner, and doesn’t seem to conflict with other sound effects.
Every man should plant a tree, build a house, and write a ZX Spectrum game.
Author of A Yankee in Iraq, a 50 fps shoot-’em-up—the first game to utilize the floating bus on the +2A/+3,
and zasm Z80 Assembler syntax highlighter.
Author of A Yankee in Iraq, a 50 fps shoot-’em-up—the first game to utilize the floating bus on the +2A/+3,
and zasm Z80 Assembler syntax highlighter.
Re: How do I make background sound?
From what I can remember when I programmed the sound effects (not music) code on Quadron, I had the 50Hz interrupt handler checking a pointer variable that if non-0 would step through a list of encoded frequencies each frame. These 'frequencies' were really the delay introduced between turning the sound bit on and off and then OUTted to the sound port. Higher numbers meant bigger delays hence lower notes, and consequently a slight slow down of the rest of the game. But this was a lot better than calling the 100% CPU hogging BEEP routine!
The list of encoded frequencies were made by trial and error. I kind of got the feel for it after a while and got some quite varied sound effects in the end! To prepare them I think I had a simple BASIC program reading through a list with READ and DATA statements and POKEing them into memory to form the list ready for the interrupt routine. Doing it in BASIC made editing and changes easier.
Once I had all the sound effect lists ready it was just a case of saving them out with SAVE "sfx" CODE xxxxx,xxx so that it could be included by the assembler later.
The list of encoded frequencies were made by trial and error. I kind of got the feel for it after a while and got some quite varied sound effects in the end! To prepare them I think I had a simple BASIC program reading through a list with READ and DATA statements and POKEing them into memory to form the list ready for the interrupt routine. Doing it in BASIC made editing and changes easier.
Once I had all the sound effect lists ready it was just a case of saving them out with SAVE "sfx" CODE xxxxx,xxx so that it could be included by the assembler later.
Cosmium
https://cosmium.itch.io/
https://cosmium.itch.io/
- Turtle_Quality
- Manic Miner
- Posts: 506
- Joined: Fri Dec 07, 2018 10:19 pm
Re: How do I make background sound?
I've been wondering the same about background sound, I'm very slowly writing a game that will be in assembly (New Year's Resolution), and probably overcomplicating the whole thing for myself.
Back in the day I used nested loops to make differing sound effects, with increasing/falling pitch or weird combinations to make sound patterns -sirens, quacks (using a duck nested loop obviously) etc... I had some code (long lost) that would "sing" text by plotting the pixels of a word in a pseudo random way at the same time as sounding a note (or two). By maintaining the sound after a updating each byte on screen the sound was continous.
I'm guessing that most in game sound engines work by playing some sound on the interrupt before the graphics render, or play sound after the graphics render up until the interrupt, giving it a stuttered effect ; sound for half a frame then silent.
I'm wondering if it's feasible to embed very frequent calls to a continous sound engine, after each sprite row and other items in the game loop, maybe every 60 t states or thereabouts, to enable smooth sound fx. The continuous sound engine would then need to decide if it's time for a click and decide the next frequency. It could use the r register and a small delay loop to ensure consistent number of t states before a click. Just don't keep resetting the r register, not on a real speccy. Did the refresh occur when R = 127 ? Maybe set it to 127 then for a timer reset.
I'm still musing and doing the maths to see if this feasible. The game I'm working on should not be too CPU intensive on it's own so I reckon I can make 50fps with sound. And I'm talking about the beeper here obviously, not the AY chip. And I'm aiming just to make sound effects rather than backround music (although some of the best fx are musical and need a good pitch : the Penetrator bugle call before the game starts, a congratulatory "tada" effect etc..)
Back in the day I used nested loops to make differing sound effects, with increasing/falling pitch or weird combinations to make sound patterns -sirens, quacks (using a duck nested loop obviously) etc... I had some code (long lost) that would "sing" text by plotting the pixels of a word in a pseudo random way at the same time as sounding a note (or two). By maintaining the sound after a updating each byte on screen the sound was continous.
I'm guessing that most in game sound engines work by playing some sound on the interrupt before the graphics render, or play sound after the graphics render up until the interrupt, giving it a stuttered effect ; sound for half a frame then silent.
I'm wondering if it's feasible to embed very frequent calls to a continous sound engine, after each sprite row and other items in the game loop, maybe every 60 t states or thereabouts, to enable smooth sound fx. The continuous sound engine would then need to decide if it's time for a click and decide the next frequency. It could use the r register and a small delay loop to ensure consistent number of t states before a click. Just don't keep resetting the r register, not on a real speccy. Did the refresh occur when R = 127 ? Maybe set it to 127 then for a timer reset.
I'm still musing and doing the maths to see if this feasible. The game I'm working on should not be too CPU intensive on it's own so I reckon I can make 50fps with sound. And I'm talking about the beeper here obviously, not the AY chip. And I'm aiming just to make sound effects rather than backround music (although some of the best fx are musical and need a good pitch : the Penetrator bugle call before the game starts, a congratulatory "tada" effect etc..)
Definition of loop : see loop