Sound: Exploring the PSG

Authors

Publication

Date

Pages

BASIC Terms

One of the things that caught my attention when I was deciding on which computer to buy three years ago was the fact that the 2068 had not one, but two means of producing sound. The “Spectrum Beep” and the sophisticated General Instrument PSG. Being that I am a musician of eight years, I wanted to make sure that the computer would be capable of offering high quality sound along with exceptional computational performance. Needless to say, I’m sold on the 2068.

The PSG is so complex that it offers many ways to create sound. Here are the choices: Computer regulated Amplitude and Frequency modulation (like the Atari) using the Beep to provide extra distortions with or without the noise source, using the envelope generator to control Amplitude modulation and frequency, modulation along with tone generation using the envelope generator without the tone generators and with or without the noise source, and lastly, any of the combinations from above. The major advantage that our chip has over the Atari and Commodore’s 8 bit series of computers is the ability to create complex waveforms with less effort on the part of the CPU. Remember this, Atari-Tramiel decided to use the chip in their new 16 bit machines too.

Before we can efficiently use the chip we must gain an understanding of the relationship of time and the various elements of sound. For example, if we were to generate a ADSR waveform using the envelope generator we would have to know how long it takes for each phase to be completed so that we could set up the delay using the PAUSE command or (more protected) a FOR-NEXT loop.

We must gain an understanding of the various components of sound and how we can represent these components using the control registers of the sound chip.

One of the most important aspects of sound is frequency. In order to create music using the equally tempered scale, a table of values must be constructed to represent each semitone, as is with the BEEP facility. From the TIMEX technical manual, we can see that the frequency for the tone generator can be derived using the equation:

frequency = 1.764 / (16(256×CT + FT))

CT = decimal val coarse tune
FT = decimal val fine tune

* The number in parens represents the Tone Period. This is not the same as the period of a waveform, which is the inverse of the frequency.

By using this equation we can create an array to hold the coarse and Fine Tune Register values for the equally tempered scale.

BASIC Listing — PROG: AY_ets!

1 PAPER 6: INK 0: BORDER 6: BRIGHT 0: FLASH 0: CLS : DIM v(96): DIM u(96): LET z=-40: DIM n(96)
10 LET x=1764000/16
20 LET b=27.5: LET s=2↑(1/12)
30 FOR i=3 TO 98
40 LET a=(b*s↑i)
70 LET a=x/a: LET c=INT (a/256)
80 LET f=INT (a-(c*256)+.5)
90 LET a=x/(c*256+f)
95 LET z=z+1: LET n(i-2)=z: LET u(i-2)=f: LET v(i-2)=c
100 PRINT AT 0,5;"EQUALLY TEMPERED SCALE";AT 11,11; INK 2; BRIGHT 1; FLASH 1;"PLEASE WAIT": NEXT i
105 RESTORE : LET Z=1: CLS : PRINT AT 0,0; BRIGHT 1; PAPER 7;"OCTVE NOTE FINE CRSE VAL#": LET L=0: FOR f=1 TO 96: LET L=L+1: FOR n=15 TO 0 STEP -2: SOUND 8,n;9,n;10,n: NEXT n: PAUSE 5: SOUND 8,15;9,15;10,15;7,56;2,u(f);3,v(f);4,u(f);5,v(f);1,v(f);0,u(f)
110 IF L>12 THEN LET Z=Z+1: LET L=1: RESTORE 180
115 READ N$: PRINT AT 1,3;" ";AT 1,3;Z;AT 1,9;" ";AT 1,9;N$;AT 1,15;" ";AT 1,15;U(F);AT 1,22;" ";AT 1,22;V(F);AT 1,28;" ";AT 1,28;F
120 PAUSE 5: NEXT F
180 DATA "C","C#","D","D#","E","F","F#","G","G#","A","A#","B"
199 PAPER 6: INK 0: BORDER 6: CLS : PRINT AT 2,1;"This program sets up two arrays to hold the coarse and fine tune values for the equally tempered scale."'"Array-u holds the value for the fine tune register."'"Array-v holds values for coarse tune reg.''
200 PRINT " The complete 8-octave range is set. This will allow the programmer to easily create music programs in a similer fashion to using the British BEEP but with the sophistication of our PSG."
201 PRINT '" Simply GOTO 9999 to save the arrays";AT 20,0; BRIGHT 1; INK 4;"PSG ARRAY VAL OF 37=mid C = BEEP VAL OF 0"
300 STOP
9999 SAVE "PSG_ets" DATA v(): SAVE "PSG_ets#2" DATA u()

Products

 

Media

 

Image Gallery

Source Code

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.

Scroll to Top