- APPENDIX I -
Creating sound effects and music is possible with either of two
system calls. Dosound() processes commands in a supplied
buffer during interrupt processing (50 times per second). It is
best suited, therefore, at playing musical passages while program
flow continues. Giaccess() provides register-level control
over the PSG resulting in a higher level of flexibility and constant
updating by the application. This makes Giaccess() more
suited for short sound effects.
The function definitions of Dosound() and Giaccess()
both reference the register numbers of the PSG. It should be noted
that registers 14 and 15 actually control periperals connected
to Port A and Port B of the PSG. The PSG's registers are assigned
as follows:
THE PROGRAMMABLE
SOUND GENERATOR
Controlling the PSG
Name |
| Meaning |
---|---|---|
PSG_APITCHLOW
PSG_BPITCHHIGH |
| Set the pitch of the PSG's channel A to the value in registers 0 and 1. Register 0 contains the lower 8 bits of the frequency and the lower 4 bits of register 1 contain the upper 4 bits of the frequency's 12-bit value. |
PSG_BPITCHLOW
PSG_BPITCHHIGH |
| Set the pitch of the PSG's channel B to the value in registers 0 and 1. Register 0 contains the lower 8 bits of the frequency and the lower 4 bits of register 1 contain the upper 4 bits of the frequency's 12-bit value. |
PSG_CPITCHLOW
PSG_CPITCHHIGH |
| Set the pitch of the PSG's channel C to the value in registers 0 and 1. Register 0 contains the lower 8 bits of the frequency and the lower 4 bits of register 1 contain the upper 4 bits of the frequency's 12-bit value. |
PSG_NOISEPITCH |
| The lower five bits of this register set the pitch of white noise. The lower the value, the higher the pitch. |
PSG_MODE |
| This register contains an eight bit map which determines various aspects of sound generation. Setting each bit on causes the following actions:Name Bit Mask Meaning
PSG_ENABLEA 0x01 Chnl A tone enable PSG_ENABLEB 0x02 Chnl B tone enable PSG_ENABLEC 0x04 Chnl C tone enablePSG_NOISEA 0x08 Chnl A white noise onPSG_NOISEB 0x10 Chnl B white noise on PSG_NOISEC 0x20 Chnl C white noise onPSG_PRTAOUT 0x40 Port A: 0 = input 1 = output PSG_PRTBOUT 0x80 Port B: 0 - input 1 = output |
PSG_AVOLUME |
| This register controls the volume of channel A. Values from 0-15 are absolute volumes with 0 being the softest and 15 being the loudest. Setting bit 4 causes the PSG to ignore the volume setting and to use the envelope setting in register 13. |
PSG_BVOLUME |
| This register controls the volume of channel B. Values from 0-15 are absolute volumes with 0 being the softest and 15 being the loudest. Setting bit 4 causes the PSG to ignore the volume setting and to use the envelope setting in register 13. |
PSG_CVOLUME |
| This register controls the volume of channel C. Values from 0-15 are absolute volumes with 0 being the softest and 15 being the loudest. Setting bit 4 causes the PSG to ignore the volume setting and to use the envelope setting in register 13. |
PSG_FREQLOW
PSG_FREQHIGH |
| Register 11 contains the low byte and register 12 contains the high byte of the frequency of the waveform specified in register 13. This value may range from 0 to 65535. |
PSG_ENVELOPE |
| The lower four bits of the register contain a value which defines the envelope wavefrom of the PSG. The best definition of values is obtained through experimentation. |
PSG_PORTA |
| This register accesses Port A of the Yamaha PSG. It is recommended that the functions Ongibit() and Offgibit() be used to access this register. |
PSG_PORTB |
| This register accesses Port B of the Yamaha PSG. This register is currently assigned to the data in/out line of the Centronics Parallel port. |
The following table lists the twelve-bit value required to produce the desired musical tones with the PSG's tone generators A, B, and C. The upper nibble of the value is placed into the 'coarse-tuning' register and the lower BYTE is placed into the 'fine-tuning' register. In addition, because the PSG must approximate musical frequencies according to an equal-tempered scale, the ideal and actual frequencies are also listed.
Note |
|
| Value | |
---|---|---|---|---|
C1 |
|
|
0xD5D | |
C#1 |
|
|
0xC9C | |
D1 |
|
|
0xBE7 | |
D#1 |
|
|
0xB3C | |
E1 |
|
|
0xA9B | |
F1 |
|
|
0xA02 | |
F#1 |
|
|
0x973 | |
G1 |
|
|
0x8EB | |
G#1 |
|
|
0x86B | |
A1 |
|
|
0x7F2 | |
A#1 |
|
|
0x780 | |
B1 |
|
|
0x714 | |
C2 |
|
|
0x6AE | |
C#2 |
|
|
0x64E | |
D2 |
|
|
0x5F4 | |
D#2 |
|
|
0x59E | |
E2 |
|
|
0x54D | |
F2 |
|
|
0x501 | |
F#2 |
|
|
0x4B9 | |
G2 |
|
|
0x475 | |
G#2 |
|
| 0x435 | |
A2 |
|
| 0x3F9 | |
A#2 |
|
| 0x3C0 | |
B2 |
|
| 0x38A | |
C3 |
|
| 0x357 | |
C#3 |
|
| 0x327 | |
D3 |
|
| 0x2FA | |
D#3 |
|
| 0x2CF | |
E3 |
|
| 0x2A7 | |
F3 |
|
| 0x281 | |
F#3 |
|
| 0x25D | |
G3 |
|
| 0x23B | |
G#3 |
|
| 0x21B | |
A3 |
|
| 0x1FC | |
A#3 |
|
| 0x1E0 | |
B3 |
|
| 0x1C5 | |
C4 |
|
| 0x1AC | |
C#4 |
|
| 0x194 | |
D4 |
|
| 0x17D | |
D#4 |
|
| 0x168 | |
E4 |
|
| 0x153 | |
F4 |
|
| 0x140 | |
F#4 |
|
| 0x12E | |
G4 |
|
| 0x11D | |
G#4 |
|
| 0x10D | |
A4 |
|
| 0xFE | |
A#4 |
|
| 0xF0 | |
B4 |
|
| 0xE2 | |
C5 |
|
| 0xD6 | |
C#5 |
|
| 0xCA | |
D5 |
|
| 0xBE | |
D#5 |
|
| 0xB4 | |
E5 |
|
| 0xAA | |
F5 |
|
| 0xA0 | |
F#5 |
|
| 0x97 | |
G5 |
|
| 0x8F | |
G#5 |
|
| 0x87 | |
A5 |
|
| 0x7F | |
A#5 |
|
| 0x78 | |
B5 |
|
| 0x71 | |
C6 |
|
| 0x6B | |
C#6 |
|
| 0x65 | |
D6 |
|
| 0x5F | |
D#6 |
|
| 0x5A | |
E6 |
|
| 0x55 | |
F6 |
|
| 0x50 | |
F#6 |
|
| 0x4C | |
G6 |
|
| 0x47 | |
G#6 |
|
| 0x43 | |
A6 |
|
| 0x40 | |
A#6 |
|
| 0x3C | |
B6 |
|
| 0x39 | |
C7 |
|
| 0x35 | |
C#7 |
|
| 0x32 | |
D7 |
|
| 0x30 | |
D#7 |
|
| 0x2D | |
E7 |
|
| 0x2A | |
F7 |
|
| 0x28 | |
F#7 |
|
| 0x26 | |
G7 |
|
| 0x24 | |
G#7 |
|
| 0x22 | |
A7 |
|
| 0x20 | |
A#7 |
|
| 0x1E | |
B7 |
|
| 0x1C | |
C8 |
|
| 0x1B | |
C#8 |
|
| 0x19 | |
D8 |
|
| 0x18 | |
D#8 |
|
| 0x16 | |
E8 |
|
| 0x15 | |
F8 |
|
| 0x14 | |
F#8 |
|
| 0x13 | |
G8 |
|
| 0x12 | |
G#8 |
|
| 0x11 | |
A8 |
|
| 0x10 | |
A#8 |
|
| 0xF | |
B8 |
|
| 0xE |
An envelope may be applied to sounds generated by the PSG. Registers 11 and 12 specifiy the frequency of this envelope and the low four bits of register 13 specifies the envelope shape as follows (an 'x' digit means either 0 or 1):