VOGONS


First post, by SoftCat

User metadata
Rank Member
Rank
Member

Can someone explain to me how the sound engine works in the game Digger when playing background music?

Reply 1 of 5, by reenigne

User metadata
Rank Oldbie
Rank
Oldbie

I can! Instead of using square waves as PC speaker music usually does, Digger's music uses pulses - it sets PIT channel 0 to the frequency corresponding to the musical note it wants to play, and in the IRQ0 (interrupt 8 ) handler it sets the speaker to the "1" position, waits for a period of time (the pulse width) with a CPU loop, and then sets the speaker to the "0" position again. The amount of time the CPU spins for in between controls the width of the pulse, which essentially corresponds to the volume of the waveform. Then this volume (or pulse width) is modulated to create a volume envelope so that the notes "fade out" instead of remaining at constant volume for their entire duration. So that gives it a much more dynamic sound, but also a "thinner" one (especially when the duty cycle of the pulses is low).

Reply 2 of 5, by SoftCat

User metadata
Rank Member
Rank
Member
reenigne wrote on Yesterday, 16:21:

I can! Instead of using square waves as PC speaker music usually does, Digger's music uses pulses - it sets PIT channel 0 to the frequency corresponding to the musical note it wants to play, and in the IRQ0 (interrupt 8 ) handler it sets the speaker to the "1" position, waits for a period of time (the pulse width) with a CPU loop, and then sets the speaker to the "0" position again. The amount of time the CPU spins for in between controls the width of the pulse, which essentially corresponds to the volume of the waveform. Then this volume (or pulse width) is modulated to create a volume envelope so that the notes "fade out" instead of remaining at constant volume for their entire duration. So that gives it a much more dynamic sound, but also a "thinner" one (especially when the duty cycle of the pulses is low).

I see, thank you very much for your answer! So the decay time depends on the note frequency? Also, unlike PWM, the maximum volume for a square wave is 50%, and it decreases symmetrically as the pulse width increases or decreases?

If possible, please take a look at the question about CGA.
Re: CGA pseudo-graphic modes

Reply 3 of 5, by reenigne

User metadata
Rank Oldbie
Rank
Oldbie

The decay time sort of depends on the note frequency - at higher frequencies you need a smaller pulse width to get a given duty cycle percentage. So if you decrease the pulse width by a constant amount of time each second, it'll take longer to go away. I don't remember offhand how Digger determined the pulse width for a given frequency and point in the decay time.

A square wave is just a pulse wave with 50% duty cycle and is in some sense the "loudest" sound that you can make of a given frequency using waveforms that are limited to a specific range (0..1 in this case). Yes, the volume decreases as the duty cycle changes in either direction from there.

Reply 4 of 5, by SoftCat

User metadata
Rank Member
Rank
Member
reenigne wrote on Yesterday, 20:33:

The decay time sort of depends on the note frequency - at higher frequencies you need a smaller pulse width to get a given duty cycle percentage. So if you decrease the pulse width by a constant amount of time each second, it'll take longer to go away. I don't remember offhand how Digger determined the pulse width for a given frequency and point in the decay time.

A square wave is just a pulse wave with 50% duty cycle and is in some sense the "loudest" sound that you can make of a given frequency using waveforms that are limited to a specific range (0..1 in this case). Yes, the volume decreases as the duty cycle changes in either direction from there.

I see, thank you very much for your reply!
I wonder if it's possible to implement sigma-delta modulation or regular pulse-density modulation with a Bayer or blue noise vector (1 x N matrix) for sound on an IBM PC (XT)? In other words, is it possible to precisely select commands by cycle?

Reply 5 of 5, by reenigne

User metadata
Rank Oldbie
Rank
Oldbie

If you're targeting slower computers (like a 4.77MHz 8088) you very quickly run into limitations of how fast you can toggle the speaker in software and do something else at the same time (like decompress audio from some format that lets you fit more than a tiny sample into 640kB).