Difference between revisions of "Outputting Sound"

From veswiki
Jump to: navigation, search
 
Line 1: Line 1:
You can originally make 3 sounds- a 120Hz beep, a 500Hz beep or a 1kHz beep.
+
The speaker can be supplied with one of three frequencies derived from the horizontal line frequency of the video circuitry.
  
Coming up are recordings of various sounds mentioned.
+
On an NTSC machine, with a horizontal line frequency of approximately 15,734.26 Hz:<br>
 
+
4V  = 15,734.26 / 16  ≈ 983.39 Hz<br>
If you want to make any other sounds try the improved [[Snippet:Playsong|PlaySong]] subroutine, this however sounds like a broken speaker on the early systems. System II has improved support for this and most of these also have sound on the tv (where you can change the volume).
+
8V  = 15,734.26 / 32  ≈ 491.70 Hz<br>
 +
32V = 15,734.26 / 128 ≈ 122.92 Hz<br>
 +
<br>
 +
On a PAL machine, with a horizontal line frequency of 15,625 Hz:<br>
 +
4V  = 15,625 / 16  ≈ 976.56 Hz<br>
 +
8V  = 15,625 / 32  ≈ 488.28 Hz<br>
 +
32V = 15,625 / 128 ≈ 122.07 Hz<br>
 +
<br>
 +
If you want to make any other sounds or music try the improved [[Snippet:Playsong|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 [[Homebrew:Pac-Man|Pac-man]] the "Pac-man theme" is played before start and the PlaySong routine is also used for the other sound effects.  
 
In VES [[Homebrew:Pac-Man|Pac-man]] the "Pac-man theme" is played before start and the PlaySong routine is also used for the other sound effects.  
  
Line 10: Line 18:
 
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.
 
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.
  
As different machines run on different clock speeds (1.78MHz, 2.00MHz etc) the pitch of the sound varies between PAL, NTSC and also between first and second generation PAL machines.
 
  
 
Sound is controlled by the upper two bits of port 5, 00 means silence and then the three standard beeps:
 
Sound is controlled by the upper two bits of port 5, 00 means silence and then the three standard beeps:
Line 24: Line 31:
 
                 OUTS 5</pre>
 
                 OUTS 5</pre>
  
 
+
Sound will decay rather quickly (about 50 ms before quiet) due to the intentional hardware layout.
You might need a pause after, not to turn sound off immediately and a
+
Port needs to reinit to keep the sound on.
 
 
                clr
 
                outs 5
 
  
  

Latest revision as of 16:59, 28 August 2026

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