Outputting Sound
The speaker can be supplied with one of three frequencies derived from the horizontal line frequency of the video circuitry.
On an NTSC machine, with a horizontal line frequency of approximately 15,734.26 Hz:
4V = 15,734.26 / 16 ≈ 983.39 Hz
8V = 15,734.26 / 32 ≈ 491.70 Hz
32V = 15,734.26 / 128 ≈ 122.92 Hz
On a PAL machine, with a horizontal line frequency of 15,625 Hz:
4V = 15,625 / 16 ≈ 976.56 Hz
8V = 15,625 / 32 ≈ 488.28 Hz
32V = 15,625 / 128 ≈ 122.07 Hz
If you want to make any other sounds or music try the improved PlaySong subroutine. It's not optimal for the early systems - it sounds much like a broken speaker... The second generation of systems has improved support for this and most of these also have sound on the tv so you can adjust the volume.
In VES Pac-man the "Pac-man theme" is played before start and the PlaySong routine is also used for the other sound effects.
How to: You examine the frequencies of the sound effect you want in very tiny steps and then mimic it playing very short notes with the correct medium frequency at that time, the shorter pieces it's divided into the better...
The PlaySong routine doesn't allow for any other computing while it's running, the song data and other computing (moving graphics perhaps) has to be done alternating in small portions if these are to be combined.
Sound is controlled by the upper two bits of port 5, 00 means silence and then the three standard beeps:
LI %01000000 ; 1kHz beep $40
OUTS 5
LI %10000000 ; 500Hz beep $80
OUTS 5
LI %11000000 ; 120Hz beep $C0
OUTS 5
Sound will decay rather quickly (about 50 ms before quiet) due to the intentional hardware layout. Port needs to reinit to keep the sound on.
Here's an example of a creative sound effect from Sean Riddles Lights Out:
;make a bad sound
li $3f ; r1 loaded with $3f
lr 1,a
sndloop:
li $80 ; $80 loaded into A
outs 5 ; send data to port
lis 1 ; A=1
lr 5,a ; load r5 with 1
pi delay ; run the syscall "delay" (very short, only 1)
lis 0 ; same as clr
outs 5 ; send 0 on port
ds 1 ; r1 decreased
bf 4,sndloop ; run the loop again until r1 is 0
Making sound effects with the PlaySong routine
Easiest example is Pac-man, e5frog studied the frequencies of the Pac-man's eating sound, the siren, death etc in very short pieces. Then set the data in the F8 to play that approximated medium frequency for exactly the same amount of time. I e it was hacked in little pieces, analyzed, thrown away and put together again with brand new pieces.
Recorded sound samples from a real Arcade Machine were analyzed. The result came out quite fine!
Here's the result from Pac-man's eating sound:
; Pac-man eats db 1,116,1,116,1,116,1,163,1,163,2,178,3,191,3,202 db 20,255 db 3,207,3,199,2,191,1,172,1,172,1,161,2,161,3,161 db 20,255 ; repeated over and over again
There is also a siren in the background all the time that resulted in this data:
; Pac-man background siren db 3,157,3,165,3,173,4,181,4,188,4,194,4,198,4,202,4,205,4,208,4,211,4,213 db 4,211,4,208,4,205,4,202,4,198,4,194,4,188,4,181,3,173,3,165 ; repeated over and over again
Unfortunately they can't be heard in the game, it couldn't be used because they take to much cpu-time... Perhaps there could be simultaneous music and effects some day - if that's handled by a second processor or a mock multitasking song playing routine...
For now there's only a click when Pac-man eats his pills and an extra sound when monsters are blue. Death is accurately mimicked - no need for graphics speed there since everything is still and Pac-man only changes into his death-sprite between the partial PlaySong routines.
Like so:
;--------------------------------------------------------------------------- ; Dying Song ;--------------------------------------------------------------------------- sfx.dying.0: .byte 4,189,4,188,4,184,4,182,4,181 .byte 4,182,4,185,4,188,4,190,4,192,4,193 .byte 4,184,4,182,4,179,4,176,3,173,3,171 .byte 3,173,3,176,4,179,4,182,4,185,4,186 .byte 0 sfx.dying.1: .byte 3,179,3,176,3,173,3,170,3,165,3,163 .byte 3,165,3,170,3,173,3,176,3,179,3,181 .byte 3,165,3,161,3,157,3,152,2,147,2,143 .byte 0 sfx.dying.2: .byte 2,147,2,152,3,157,3,161,3,166,3,168 .byte 3,155,3,152,3,147,2,141,2,139,2,128 .byte 2,135,2,138 .byte 0 sfx.dying.3: .byte 2,126,3,170,3,192,4,205,5,214,6,220 .byte 7,224,7,229,8,232,9,234,10,255 .byte 2,126,3,170,3,192,4,205,5,214,6,220 .byte 7,224,7,229,8,232,9,234 .byte 0 ; end of song
There's also this:
;--------------------------------------------------------------------------- ; Extra Pac-man sound at 10000 points ;--------------------------------------------------------------------------- sfx.extraPacman: .byte 6,121,6,122,12 .byte 190,6,192,6,121,6,122,12 .byte 190,6,192,6,121,6,122,12 .byte 190,6,192,6,121,6,122,12 .byte 190,6,192,6,121,6,122,12 .byte 190,6,192,6,121,6,122,12 .byte 190,6,192,6,121,6,122,12 .byte 190,6,192,6,121,6,122,12 .byte 190,6,192,6,121,6,122,12 .byte 190,6,192,6,121,6,122,12 .byte 190,6,192,0