•  Back 
  •  Main 
  •  Index 
  •  Tree View 
  •  Cross references 
  •  %About 
  •  Show info about hypertext 
  •  View a new file 
Topic       : The ATARI Compendium
Author      : Scott Sanders / JAY Software
Version     : 1.25 (20/6/2003)
Subject     : Documentation
Nodes       : 1117
Index Size  : 32614
HCP-Version : 6
Compiled on : Atari
@charset    : UTF-8
@lang       : en
@default    : 
@help       : %About
@options    : +g -i -t4 +y +z
@width      : 100
View Ref-File<invalid destination page 1581>
                                                                     AI
                    The Programmable Sound Generator


Controlling the PSG

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:

Name           Register Meaning

PSG_APITCHLOW     0     Set the pitch of the PSG's channel A to the value
PSG_APITCHHIGH    1     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     2     Set the pitch of the PSG's channel B to the value
PSG_BPITCHHIGH    3     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     4     Set the pitch of the PSG's channel C to the value
PSG_CPITCHHIGH    5     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    6     The lower five bits of this register set the pitch
                        of white noise. The lower the value, the higher
                        the pitch.

PSG_MODE          7     This register contains an eight bit map which
                        determines various aspects of sound generation.
                        Setting each bit on causes the following
                        actions:

                        Name         Mask  Meaning
                        PSG_ENABLEA  0x01  Chnl A tone enable
                        PSG_ENABLEB  0x02  Chnl B tone enable
                        PSG_ENABLEC  0x04  Chnl C tone enable
                        PSG_NOISEA   0x08  Chnl A white noise on
                        PSG_NOISEB   0x10  Chnl B white noise on
                        PSG_NOISEC   0x20  Chnl C white noise on
                        PSG_PRTAOUT  0x40  Port A:  0 = input  1 = output
                        PSG_PRTBOUT  0x80  Port B:  0 = input  1 = output

PSG_AVOLUME       8     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       9     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       10    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       11    Register 11 contains the low byte and register 12
PSG_FREQHIGH      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      13    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         14    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         15    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.

Sound Envelopes

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):


            Value    Vaweform Shape

index=1106
%00xx
index=1107
%01xx
index=1108
%1000
index=1106
%1001
index=1109
%1010
index=1110
%1011
index=1111
%1100
index=1112
%1101
index=1113
%1110
index=1112
%1111