APPLICATIONSCREATION MUSICAL ★ MOZART: Part 1 (1 of 3) of m/c use of the AY-3-8912 chip ★

Mozart (Amstrad Computer User)Applications Creation Musical
★ Ce texte vous est présenté dans sa version originale ★ 
 ★ This text is presented to you in its original version ★ 
 ★ Este texto se presenta en su versión original ★ 
 ★ Dieser Text wird in seiner Originalfassung präsentiert ★ 

If you've been following the articles on the Muscial Amstrad published in these pages recently, you will already know that the CPC has stereo sound in three channels, and that a comprehensive set of BASIC commands allow sound the music creations to be added to any program. There are, however, occasions when the CPC's sound chip needs to be run from machine code, and to do so requires rather more information than the standard CPC handbook contains. The purpose of this article is to provide the extra information. By way of illustration, this month's offering describes how your computer can be persuaded to play unlimited quantities of Mozart-minuets. Each minuet is different and you won't hear one repeated in a lifetime. This program, which requires no musical skill whatsoever on the party of the user, will be discussed in some detail later.

The sound chip used inside the CPC464 is the AY-3-8912 from General Instruments and it's generally referred to as a PSG (Programmable Sound Generator). If you have the Amstrad Firmware Manual SOFT 158, then you might already know that this IC has fifteen internal registers (see Appendix 9). This is an early indication of the complexity of the chip and, as the firmware manual suggests for detailed machine code work involving this chip you should get a copy of the manufacturer's chip-specification, which is a 60-page booklet rejoicing in the name "AY-3-8910 /8912 PROGRAMMABLE SOUND GENERATOR DATA MANUAL". It costs about £3.

The registers set is shown in figure 1. For the Mozart program, registers 8,9 and 10 can be set to full volume and then safely forgotten, since the Amstrad has its own volume control. Register 7 is set for TONE output rather than NOISE output, and it is the FREQUENCY registers, 0 to 5 which contrive the hard work of actually sounding the notes. The other registers are not used in this month's application, but I shall be return to them in Part Two.

The Amplitude Registers

There are three identical 5-bit registers, one for each sound channel. Bit 4 is used in conjunction with the envelope facilities which the chip offers. These are unused and so bit 4 should be set to zero. Bits 0 to 3 hold a 15-scale amplitude level. 0 turns a channel off, while 15 is full volume. Control Register Seven

This is an 8-bit register which has the job of mixing sound and also setting the peripheral port which the PSG possesses. A zero bit is taken to mean ON, and the bits are used as switches, BO for channel one tone, B1 for channel two tone and 90 on. Channel noise is switched, the noise is mixed with it. Note that there is only one noise source (register 6), but that it can be sent to any of the channels. Bit 6 sets the peripheral port as an input (B6=0l otherwise the keyboard stops working. This will not harm the machine, but a total RESET will have to be made to unlock the system.

Fig. 1
The sound chip data registers arc at follow:
Register 0: Channel A tone period fine tune.
Register 1. Channel A tone period coarse tune
Register 2: Channel B tone period fine tune
Register 3: Channel B tone period coaree tune.
Register 4: Channel C tone period fine tune
Register f: Channel C tone period coarse tune.
Register 6: Noise penod
Register 7: Enables and I/O direction
Register 8: Channel A amplitude and envelope enable
Register 9: Channel B amplitude and envelope enable.
Register 10. Channel C amplitude and envelope enable.
Register 11: Envelope period fine tune.
Register 12: Envelope period coarse tune.
Register 13: Envelope shape
Register 14: Input from or output to port A.
Register 15: Not used

The Frequency Registers

Each sound channel has a double register allocated to it since a 12-bit number is required to set the TONE PERIOD. A high number sets a long period and long periods produce low notes, so the higher the number, the lower the frequency of the note. There is an equation which creates a number between 0 and 4095 which, when loaded into the registers, produces the desired frequency.

;PSGCLOCK
NUMBER = ----------------------
FREQUENCY*16

It is convenient to let a BASIC program do the maths involved, which includes splitting the 12-bit number produced into a least-signficant byte and a most-significant byte ready for loading into the appropriate PSG register pair.

10 INPUT "FREQUENCY ";F
20 N=125000/F
30 PRINT "LSB ";N-256*INT (N/256)
40 PRINT "HSB ";INT (N/256) :G0T0 10

Alternatively N may be taken from the TONE PERIOD table in the CPC464 manuals. Thus, in the user instructions booklet (Appendix VII), International A is listed as having a frequency of 440Hz and a tone period of 284. The firmware manual takes us a little further by listing the period number in hex : it's 011C. Hex numbers split naturally into bytes, so to load channel one with a frequency of440Hz, 10 is loaded into register one and 01 into register two. This brings us to the problem of how to load a PSG register.

Hard and Soft Sounds

The PSG is a programmable hardware device, and as such it is capable of producing a wealth of sound just by changing the information in some of its registers. Some software is required to do this, but it is essentially a hardware sound-production unit. What Locomotive BASIC provides is an added dimension of control based on complicated routines and interrupt -handling in the SOUND MANAGER part of the ROM. Thus software considerably enhances the PSG hardware and the end resultisverygood.lt is possible to access the PSG and all its registers directly, but there is little point in doing so since the ROM routine MC SOUND REGISTER at &BD34 provides the necessary software interface. The number of the register you want to access is placed in the A register and the data you wish to load is put in the C register. A CALL &BD34 then performs the load. Registers AF and BC are corrupted but the contents of the others are preserved. The routine also enables interrupts which might be undesirable in certain circumstances. The Mozart program runs with interrupts switched off for most of the time, but in fact the quality of sound with interrupts, enabled seemed little the worse for all that — the PSG carries on regardless, and timing between notes is hardly affected.

Enter Mozart

Sometime in the 18th century, Mozart indulged in a piece of musical fun which was of little significance before the advent of the computer. He wrote 176 carefully constructed bars of music, each bar on a separate manuscript, in such a way that when 16 bars were randomly selected from the "bar bank" and played in sequence, a pleasant sounding minuet would result. In pre-Amstrad days the selection of the 16 bars was determined by two dice and a look-up table. The manuscipts were then placed on a harpsichord, secured by wooden clips. Since each minuet takes only 60 seconds to play, the musical evening must have been somewhat fragmented. Computers like dealing with dice (random numbers), and look-up tables are the programmer's stock-in-trade. Not surprisingly therefore, Mozart's Dice Waltz was computerised as soon as home-micros became anywhere near affordable, and honours go to the Apple which had Mozart playing away merrily on TV's Tomorrow's World at a time when there were no British home computers to be bought for either love or money. The CPC464 can be set to play the Dice Waltz for ever, since there are literally thousands of millions of combinations of the 176 musical bars... Fortunately ESCape will terminate the computer's efforts.

Think of Number...

Each of Mozart's manuscipt-bars had a reference number attached to it, and these numbers were arranged in a table 11 rows deep and 16 columns wide. 16 throws of the dice were made, one throw for each column, and the number thrown indicated which row (for the current column) should produce the manuscript reference number. Mozart had, of course, arranged the table so that the 16 bars selected would conform to certain accepted rules pertaining to the particular style of music. The last 8 columns of music, 88 bars in all, were arranged to complement the first 88 bars and special attention was given to the notes in columns 1 and 16, the first and the last bars. A dice-throwing session thus provided a unique 16-bar piece of music. The first 8 bars were always repeated, as were the last 8 bars, giving a 32-bar minuet. The minuets should be played in three-eight time. As far as the computer is concerned there are 6 beats in the bar. At every beat 3 bytes of information must be supplied -- one byte for each channel of the PSG. A bar uses 18 bytes, so the table of 176 bars is nearly 3K in length. Each byte represents one of 51 notes, or a rest (silence), and there are shorter look-up tables which translate the bar-byte into the double-byte period-value destined for the PSG register.

Getting Running.Next month we will print the source code so that you can see how the machine code works. Since not everyone has an assembler we have printed the program "Listing 1" this generates the machine code which is used by the Basic program. If you have a disc system then using the two programs is nice and simple. Type in the long listing 1, save it and then run it. Reset the computer, type in the shorter Basic program and save it. Finally run the short Basic program which will then load a file which was put onto the disc by the long Basic program. For tape users it is even more complicated. Type in both programs and save them on seperate tapes. Wind the tape with the short program to the end of the program. Then take the tape with the long program. Load it but don't run it yet. Swap the tape for the one with the short program on the beginning. Then run the program you have in memory. This will create the machine code in the right place on the tape. If you make any typing mistakes the long program should tell you about them and give an indication as to which line the mistake is in or close to.

Basic program. This loads the machine code file 'CODEP1' which must be saved on the same tape or disc.

ACU #8508

★ PUBLISHER: Amstrad Computer User
★ YEAR: 1985
★ CONFIG: 64K + AMSDOS
★ LANGUAGE:
★ LiCENCE: LISTING
★ AUTHOR: Richard SARGENT

★ AMSTRAD CPC ★ DOWNLOAD ★

Aucun fichier de disponible:
» Vous avez des fichiers que nous ne possédons pas concernent cette page ?
★ AMSTRAD CPC ★ A voir aussi sur CPCrulez , les sujets suivants pourront vous intéresser...

Lien(s):
Je participe au site:
» Vous avez des infos personnel, des fichiers que nous ne possédons pas concernent ce programme ?
» Vous avez remarqué une erreur dans ce texte ?
» Aidez-nous à améliorer cette page : en nous contactant via le forum ou par email.

CPCrulez[Content Management System] v8.7-desktop
Page créée en 006 millisecondes et consultée 2273 fois

L'Amstrad CPC est une machine 8 bits à base d'un Z80 à 4MHz. Le premier de la gamme fut le CPC 464 en 1984, équipé d'un lecteur de cassettes intégré il se plaçait en concurrent  du Commodore C64 beaucoup plus compliqué à utiliser et plus cher. Ce fut un réel succès et sorti cette même années le CPC 664 équipé d'un lecteur de disquettes trois pouces intégré. Sa vie fut de courte durée puisqu'en 1985 il fut remplacé par le CPC 6128 qui était plus compact, plus soigné et surtout qui avait 128Ko de RAM au lieu de 64Ko.