Essential Notes From The Amiga Metal Bashers Bunker --------------------------------------------------- 3. Sound -------- It's time once again for all you amateur metal bashers out there to hit metal again. In this article, I will try and explain the fundamentals of producing sound and music on the amiga. Before this, we must understand exactly what sound is, so that we understand exactly what we are trying to reproduce. Sound is basically a movement or vibration of the air which our detectors, (known as EARS!), can register. The amiga produces sound by making a speaker vibrate, which causes the air to vibrate and produce audible sound. Figure 1 shows how this occurs. An electrical signal is fed into the speaker, which is displaced back and forth according to the signal. This compresses and decompresses the air molecules which pass this outwards though each other. If we consider one spot in the air, the molecules at that spot are alternately compressed and decompressed. This is know as a PRESSURE VARIATION. The variation of pressure at one point as time progresses is shown in figure 2. This is the way we usually look at sound, and is the display you will see in many of the sound software packages available. The physical characteristics of the sound we hear can be determined from this graph. The volume, for instance, is closely related to the amplitude. The larger the amplitude, the larger the volume. The pitch of the sound is closely related to the frequency. Some definitions are useful: FREQUENCY: The number of waves/second PERIOD: The time for one complete wave to pass Hence, FREQUENCY = __1___ PERIOD The sound wave shown in figure 2 is a very simple 'SINE WAVE' and would be a very pure note if played through a speaker. A 'real' sound, such as a spoken word, is very complicated. Now, we have a sound which we want to be able to record on our amiga, and then play back. How do we do it ? The first step is to convert the sound into an analogue electrical signal. This is usually done by playing the sound through a microphone. Note that this electrical signal would look exactly the same as our pressure/time graph. For pressure, now read voltage. Now we have an ANALOGUE signal, that is, and infinitely and smoothly varying signal. This is a problem, because our Amiga is DIGITAL and can only store discrete values. To change the signal into a form the computer can understand, we use a piece of hardware known as an ANALOGUE TO DIGITAL CONVERTER. This is also known as a SAMPLER because of what it does. The sampler takes voltage measurements at regular intervals of time while the sound signal is played into it, and sends the results to the amiga. We end up with a table of voltages as shown in figure 3. These are values of -127 to +127 so that we only need one byte per sample. Now we have the sound stored in the amiga's memory, although not quite as good as the original due to our DIGITISATION of the signal. Note that the faster we collect samples, the nearer our digitised version will be to the original sound. The sinal that will be reproduced from our table of samples is shown in figure 4. The amiga uses the opposite of a sampler to reproduce sound from these samples. This is called a DIGITAL TO ANALOGUE CONVERTER. The amiga actually has four of these, two connected to the left audio channel and two to the right. This means that we can play four different samples all at the same time. Even better, each of these D to A converters can collect its own samples automatically from chip memory, so the processor is free to do other things once the sound has been setup. The registers required to setup the sound hardware will now be explained. There are four of each types of register, one for each channel. Channels 0 and 3 are the connected to the left side stereo jack, 1 and 2 are connected to the right side stereo jack. AUDxLC where x=0,1,2,3 ------ This is the location register. It tells the hardware where in memory the sample to be played is stored. As soon as a sample starts playing, this can be reloaded with a new value, which will start playing as soon as the current sample ends. This register is 4 bytes wide. AUDxLEN where x=0,1,2,3 ------- This register is two bytes wide and tells the harwdare the length of the sample to be played DIVIDED BY TWO. This is because the hardware actually fetches two bytes at a time from memory to speed things up a bit. This register can also be reloaded as soon as the current sample has started playing. AUDxVOL where x=0,1,2,3 ------- This is the volume register, and is two bytes wide. It must be loaded with a value between 0 (min volume) and 64 (max volume). Loading this register with a new value affects the current sample being played. AUDxPER where x=0,1,2,3 ------- This register selects the period value for the sample, ie the playback speed or frequency. It is 2 bytes wide and must be loaded with a value between 124 (max frequency) and 65535 (min frequency). Loading this register with a new value affects the current sample being played. After the location,length,volume and period for the sample have been set, the sound can be started by switching on DMA for the required audio channel in register DMACON. Note that to set a bit in this register, bit 15 must also be set and to clear a bit, bit 15 must be set along with the bit to be cleared. Figure 5 shows the relevant bits in this register, and figure 6 shows the addresses of all the registers described in this article. There is an small example program on the cover disk which demonstrates the process of playing a sample. The source is also included to aid the understanding of this article. Music is produced basically by playing samples one after the other at varying frequencies to produce notes. For instance, to reproduce a trumpet solo might only require one sample. This sample could then be played back at many different frequencies to produce the whole range of musical notes. The amiga has four sound channels, so it can play four instruments all at the same time. This is how amiga musicians produce the very high quality music associated with todays games software. There are problems though which can limit the use of the sound capabilities of the amiga. A short sound sample, lasting only a few seconds can be many kilobytes long. A typical musical score as used in a game uses many different samples and can be two to three hundred kilobytes in length. Add to this the fact that samples are not easily compressed for storage on disk. After compression, the sample will still be about 90% of its original length, as compared with graphical data which can easily be halved in size by compression. This is the reason why this months demo program is very simple ! Sound is a very interesting subject which requires alot of experimentation. Try it and see ! Until next time, enjoy your bashing ! Andrew Walrond