AMOS study #01 - Graphic equalizers In this study I have decided to explore the various ways of creating an intresting type of equalizer, starting with extremely simple methods to rather long programs. The document is split up into various chapters : CHAPTER 1 _ How to obtain a reading. CHAPTER 2 - Using DRAW statements. CHAPTER 3 - Using sprites. The following documentation has been typed by ANDREW KELLETT, and all programs used (unless stated) have been written by ANDREW KELLETT of KELLETT PRODUCTIONS LIMITED © september 1994. All rights reserved by the owner of the work. The programs featured can be used in your own programs as long as the following rules are applied : 1) My name and © KELLETT PRODUCTIONS LTD sept 1994 are placed in your program where they can be seen, such as in a scroller under "Equalizer coding by Andrew Kellett of KELLETT PRODUCTIONS LTD © SEPT 1994", or a a credits/title screen. 2) (THIS ONLY APPLIES IF YOU INTEND TO SELL THE PROGRAM WITH ONE OF MY ROUTINES INCLUDED) I must be told in writing that you will be using one of my routines. I would also like a copy of the program to see how you have used the routine. The address to write to is: Andrew Kellett Mushroom PD 32 Castleton Crescent Gamesley Glossop Derbyshire SK13 9TH I would also gratefully reicieve listings of your own programming that update my routines. I have to go now, but I hope that some of these listings help you with some of your AMOS programming problems. Thank-you for your co-operation ! ************************************ * CHAPTER 1 - HOW TO GET A READING * * ----------------------* ************************************ Every time AMOS generates a sound, there is a note made in the memory of its intensity value. The numbers are not displayed directly on the screen but can be seen by using the VUMETER (channel) command. The channel number can be anything from 0 to 3, and the value returned is between 0 and 63. With a bit of altering, these numbers can be incorporated into programs to produce graphic images representing a graphic equalizer which animate in time to the music. The following program demonstrates the number effect by displaying the 4 channel intensities as a piece of music of your choice is being played : Close Editor : Curs Off Rem load and play a tune T$=Fsel$("","","Load an AMOS music bank") If T$="" Then Edit Load T$ : Music 1 : Paper 0 : Cls : Volume 63 : Led Off : Hide On Do Proc DISPLAY Loop Procedure DISPLAY For N=0 To 3 Locate 0,N : Print N;" ";Vumeter(N);" " Next N : Wait 3 End Proc There are a few commands in AMOS that can alter the way a piece of music sounds. The first command is MVOLUME [value]. This can be anything between 0 and 64 (0 being silent and 63 being the loudest setting). The volume command can be very useful at times, as it can be used in a way to make your tunes fade into silence slowly, rather than a sudden halt of playing. Try out this listing to see what I mean : Rem music fader Paper 0 : Cls F$=Fsel$("*.abk","","Select an AMOS music bank") If F$="" Then Edit Load F$ : Music 1 : Led Off : Volume 63 Rem wait for keypress Do Centre "Press a key to fade" Wait Key : Print : Print : Print "Fading ..." For N=63 To 0 Step -1 Mvolume N For G=1 To 1000 : Next G Next N For G=1 To 60000 : Next G Rem bring back Print "Fading back ..." For N=0 To 63 Mvolume N For G=1 To 1000 : Next G Next N Loop Next on the list is the TEMPO command. This one alters the speed of the piece of music and can range between 0 for very slow, and 99 for a very rapid tune. Note that different pieces of music play correctly at different speeds than other tunes do, so make a note of the tempo if you alter it. The average tempo rating is between 10 and 17. It is advisable to play around with this command in direct mode to get to grips with it. Some pieces of music however, leave the TEMPO command in-effective, as some tunes have a tempo setting programmed into them which overrides the AMOS command. It does this by playing the tune at the tempo you have set, and then resets back to the default value. Last up is the FILTER command. This command has two totally different functions, and is used by stating ON or OFF after the command. The responses are shown below : 1) the command alters the sound filter, and restricts the bass of the tune. If you turn it ON for example during a piece of music and then turn it OFF, you will notice the difference. Some tunes sound better with the command on, and others off. Personally I think the command is best turned off as it plays the finer notes better. The default value for the command is ON. 2) When the command is switched ON or OFF, the power light will dim or brighten, depending on what setting you choose. It can be handy sometimes to make the power light flash or dim, as seen in games you can buy. The best way really with any of these music commands, is to experiment all the different possibilities and learn the different values in order to obtain the best sounds you can possibly get. /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ ************************************* *CHAPTER 2 - USING DRAW STATEMENTS * * ----------------------- * ************************************* In the last chapter, I showed how we can obtain a number in proportion to the sound that AMOS is currently making. In this chapter I now show you how that number can be transformed into a graphic representation. With the numbers retrieved from VUMETER, I can now create a variable for drawing lines which when ran, creates an "animation" effect to the timing of the music. There are thousands of different ways of doing this. The following routines draws 4 bars on the screen, that go across 5 pixels and have a 1 line gap in-between each one, as this method only has to draw half of a bar in order to create the illusion of a full bar. When run you will see what I mean Rem 4 band graphic equalizer Rem by Andrew Kellett Paper 0 : Cls : Box 5,95 To 53,165 F$=Fsel$("*.ABK","","Select an AMOS music bank.") If F$="" Then Edit Load F$ : Volume 63 : Led Off : Music 1 Do X=10 : A=0 Repeat For N=0 To 3 : H=1 : Z=Vumeter(N) For G=0 To Z Step 2 : If Z=A H=0 Else H=1 If H Draw X,G+100 To X+5,G+100 End If End If Next G X=X+10 Next N Until X=50 Cls 0,10,100 To 47,165 Loop Although when run, the image produced is flickery as the area inside is cleared lots of times. The image is displayed upside-down as it looks better this way than the other way. As you can see, the animation effect moves the bars in time with the music. For a totally smooth version of this program, refer to the last chapter for the updated listing. Another way of displaying an equalizer bar, is to use peaks instead of the old-fashioned bars going across. I have managed to acheive this by linking all 4 points together in one complete line across the screen, and each of the bars, or "peaks" is totally free to choose any value it wishes, and not effect the bar next to this. The effect is created using the DRAW x,y TO x2,y2. I drew from the edge of the screen to the first peak, which then returns to a fixed point. I did the same with the other 2, and for the last peak the fixed point was the right hand edge of the screen. The entire process is much more simplistic, not to mention more effective to the other equalizer, as it can update a lot faster, and there is not as much flickering to worry about. Because of the sheer speed of the routine, I have had to put a FOR ... NEXT ... loop in order to slow it down, otherwise the line flickers so much, it is hard to work out. The loop can be reduced to a lower value if you want to see what I mean, But erase the line altogether if you want to see the real ned for it. The following is the listing, and the line that is starred is the line with the delay in it : Rem equalizer 2 DRAW statement FULL SCREEN SIZE Rem Programmed by ANDREW KELLETT Rem Copyright KELLETT PRODUCTIONS LIMITED SEPTEMBER 1994 Paper 0 : Cls : Colour 1,$F00 : Colour 2,$0 : Colour 3,$666 : Curs Off Ink 3 : Box 0,0 To 319,199 Rem zero values : Rem Plot 5,194 : Plot 15,194 : Plot 25,194 : Plot 35,194 F$=Fsel$("*.abk","","Choose a Music bank.") If F$="" Then Edit Load F$ : Music 1 : Led Off : Volume 63 : Hide On Rem animate 4 voices Do A=Vumeter(0) B=Vumeter(1) C=Vumeter(2) D=Vumeter(3) For N=1 To 2 : Ink N Draw 0,199 To 40,194-A*3 Draw 40,194-A*3 To 79,194 Draw 79,194 To 119,194-B*3 Draw 119,194-B*3 To 149,194 Draw 149,194 To 198,194-C*3 Draw 198,194-C*3 To 237,194 Draw 237,194 To 277,194-D*3 Draw 277,194-D*3 To 319,199 * If N=1 Then For Z=1 To 1900 : Next Z Next N Loop As you can clearly see, with the flashing border, the effect is much better than the other equalizer due to more speed, and greater in size. If the peaks look the same to you and you want to try and make lots of different results, then change the following lines : A=Int(Rnd(64)) B=Int(Rnd(64)) C=Int(Rnd(64)) D=Int(Rnd(64)) Now whilst the tune is playing, the equalizer peaks will not be in time to the music, but will simply display different peaks all the time. Also you can change the loop to a low value now and the many peaks will be changed faster, yet a bit more flickery. So far, the programs have just been drawn from 0 to the current VUMETER reading, and if this is a lot lower than the last time, then there is a massive drop in the line, and makes the equalizer look nothing like one that you might find on the front of the stereos you buy today. There now follows an update of the two above programs, to make the downward fall of each bar a lot smoother. First of all, we will tackle the second program, as the sudden changes to the equalizer make the line look a little odd as they constantly change. Firstly, we have to create some variables to keep check of the value in VUMETER (channel) for each of the four channels. A1, B1, C1, & D1 are set at zero, and are only changed if VUMETER (channel) is higher than its current value. A1 represents channel 0, B1 represents channel 1 etc. Next, for every loop we have to create a variable for each of the channels, CH1, CH2, CH3, and CH4. These are then linked in A1, B1, C1, and D1 by the following rule. If the value of VUMETER (channel) is greater than the value of A1 then A1 is set to that value, and CH1 is set to 1. If the value of A1 is greater than VUMETER (channel) then CH1 is set to 0, so that when it comes to decreasing 1, the routine subtracts 5 off the value of A1 which gives the effect of a steady decline when constantly updated. The same go`s for B1 and CH2, C1 and CH3 etc. Here is the new, complete listing for you to try, and to compare to the previous listing : Rem equalizer 2 DRAW statement FULL SCREEN SIZE Rem Programmed by ANDREW KELLETT Rem Copyright KELLETT PRODUCTIONS LIMITED SEPTEMBER 1994 Rem version 2 - Smoother downward scroll Paper 0 : Cls : Curs Off Colour 1,$F00 : Colour 2,$0 : Colour 3,$666 Ink 3 : Box 0,0 To 319,199 F$=Fsel$("*.abk","","Choose a Music bank.") If F$="" Then Edit Load F$ : Music 1 Led Off : Volume 63 : Hide On A1=0 : B1=0 : C1=0 : D1=0 Rem animate 4 voices Do A=Vumeter(0) : CH1=0 B=Vumeter(1) : CH2=0 C=Vumeter(2) : CH3=0 D=Vumeter(3) : CH4=0 Rem check to see if equalizer is lower than graphics bar If A>A1 Then A1=A : CH1=1 If B>B1 Then B1=B : CH2=1 If C>C1 Then C1=C : CH3=1 If D>D1 Then D1=D : CH4=1 Rem alter lower values downwards If CH1=0 and A1>0 Then A1=A1-5 If CH2=0 and B1>0 Then B1=B1-5 If CH3=0 and C1>0 Then C1=C1-5 If CH4=0 and D1>0 Then D1=D1-5 Rem Check to see that none have fallen below 0 If A1<0 Then A1=0 If B1<0 Then B1=0 If C1<0 Then C1=0 If D1<0 Then D1=0 Rem Draw line across 4 points of equalizer For N=1 To 2 Ink N Draw 0,199 To 40,194-A1*3 Draw 40,194-A1*3 To 79,194 Draw 79,194 To 119,194-B1*3 Draw 119,194-B1*3 To 149,194 Draw 149,194 To 198,194-C1*3 Draw 198,194-C1*3 To 237,194 Draw 237,194 To 277,194-D1*3 Draw 277,194-D1*3 To 319,199 If N=1 Then For G=1 To 700 : Next G Wait Vbl Next N Loop As you can see, the overall effect is much better than the previous program. The first program update is very long, slow and very memory-consuming and not to mention very difficult to update with great speed, so I have decided to leave it out. However, I have designed another program that instead of using the DRAW command, it uses the BOX command, which draws a hollow box between two sets of X and Y co-ordinates. It is faster and smoother than the draw commands, although it does flicker a tiny bit. The program uses exactly the same kind of decreasing to make the bars drop smoother, and the program has rather a good overall effect. Try it and see : Rem 4 band equalizer - BOX command Rem Written by ANDREW KELLETT (C) SEPT 1994 Cls 0 Load "df0:tune.abk" : Music 1 Hide On : Curs Off : Flash Off Volume 63 : Led Off : Colour 1,$FFF : Colour 2,$0 A1=0 : B1=0 : C1=0 : D1=0 Do A=Vumeter(0) : CH1=0 B=Vumeter(1) : CH2=0 C=Vumeter(2) : CH3=0 D=Vumeter(3) : CH4=0 If A>A1 Then A1=A : CH1=0 If B>B1 Then B1=B : CH2=0 If C>C1 Then C1=C : CH3=0 If D>D1 Then D1=D : CH4=0 Rem Decrease 1 from main value If A1>0 and CH1=0 Then A1=A1-2 If B1>0 and CH2=0 Then B1=B1-2 If C1>0 and CH3=0 Then C1=C1-2 If D1>0 and CH4=0 Then D1=D1-2 Rem Check for below 0 If A1<0 Then A1=0 If B1<0 Then B1=0 If C1<0 Then C1=0 If D1<0 Then D1=0 Rem Draw 4 bars For N=1 To 2 Ink N Box 5,194 To 15,194-A1 Box 20,194 To 30,194-B1 Box 35,194 To 45,194-C1 Box 50,194 To 60,194-D1 If N=1 Then Wait Vbl Next N Loop As you can see, the flicker is very slight, and still produces a very good equalizer effect. /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ ***************************** * Chapter 3 - USING SPRITES * * ---------------* ***************************** Using sprites in AMOS is very simple, and is much faster than any DRAW command, and can produce colours in just the same speed. In order to acheive this, you must first draw out all of the possible sprite positions, and turn them into sprites using the AMOS Sprite editor, or some other sprite program. The design I have used is just a plain line going straight across, with the pattern of 1 line, blank line, 1 line etc. all the way to the top. The sprites are designed on the size of 32 across and 64 up. I only needed 32 sprites, as for every time I drew one I just drew the line going across, therefore I would not have 2 sprites the same as if I had drew in the blank as well. Once you have drew in the sprite bank, The program can be altered if you have more or less sprites. The current settings are for 32 sprites but I will show you how to alter it later on. The program can be used over and over again with hundreds of possible sprites, as the listing only draws what is in the sprite bank. One of the many problems that I encountered in de-bugging this program was the delay. When there is no delay, you cannot see anything on the screen as the sprite positions update too fast for the human eye to see. Secondly, I had major problems with the fourth bar in the sequence, as it kept "Half disappearing" when the other three bars became rather cluttered. I have managed to eradicate the worst part of it, but sometimes it does rear it's ugly head. The following program when typed in will run only when a bank of 32 sprite characters is created. There is actually a listing to create the ones I used in BASIC at the end of the chapter : ' Equalizer coded by Andrew Kellett ' September 22nd 1994 ' Set up title screen and loader tune Screen Open 0,320,256,16,Lowres Load "amos_listings/data_files/4_1.abk" A1=0 : B1=0 : C1=0 : D1=0 : MA=9 Goto S : EQUALIZER: Goto AGAIN : AGAIN: A=(Vumeter(0)/2)+1 : CH1=0 B=(Vumeter(1)/2)+1 : CH2=0 C=(Vumeter(2)/2)+1 : CH3=0 D=(Vumeter(3)/2)+1 : CH4=0 Rem check if value is higher than equalizer bar If A>A1 Then A1=A If A>A1 Then CH1=1 If B>B1 Then B1=B If B>B1 Then CH2=1 If C>C1 Then C1=C If C>C1 Then CH3=1 If D>D1 Then D1=D If D>D1 Then CH4=1 ' alter lower values downwards If CH1=0 and A1>0 Then A1=A1-2 If CH2=0 and B1>0 Then B1=B1-2 If CH3=0 and C1>0 Then C1=C1-2 If CH4=0 and D1>0 Then D1=D1-2 Rem Draw bobs on screen Bob 1,10,246,A1 Bob 2,30,246,B1 Bob 3,50,246,C1 Bob 4,70,246,D1 : Wait Vbl Wait Vbl T=0 Gosub KEY_RESPOND If I$<>"" Then Gosub FIZZ : If I$<>"" Then Goto S : Goto AGAIN : KEY_RESPOND: I$=Inkey$ Return FIZZ: Bob Off For N=63 To 0 Step -1 Mvolume N For X=1 To 1000 : Next X Next N Music Off Return S: Screen Open 0,640,320,16,Lowres Paper 0 : Cls Get Sprite Palette Mvolume 63 F$=Fsel$("","*.abk","Load an AMOS Music Bank") If F$="" Then Edit Load F$ Led Off : Music 1 Goto EQUALIZER : As you can see, the effect looks like a true graphic equalizer. There is not much you can do to improve this program really, except to alter the sprites in the sprite bank. If you are using 64 sprites instead of 32, then remove the brackets and contents after the VUMETER (CHANNEL), and replace them if you want to use 32 sprites. Next is a program which draws all of the default 32 sprites that I have used. If you want to use it then insert the lines before entering the program lines. You will also have to delete line 6, as you will not need to load a sprite bank. Also note that the bars tend to flash red at some points. This problem is eradicated when the sprites are created into a sprite bank and loaded in : Screen Open 0,640,320,16,Lowres Paper 0 : Cls : Curs Off Ink 9 CUR=1 For N=63 To 0 Step -2 Draw 0,N To 17,N Get Bob CUR,0,0 To 16,63 CUR=CUR+1 Next N For N=1 To 32 Hot Spot N,0,64 Next N However, If you are so lucky to own a copy of this disk, then you will reicieve a copy of the sprite bank absolutely free. It is stored in the DATA_FILES directory under the name "4_1.abk" so the last little program is not needed at all. Well, that is really all I can tell you about this subject, so I will now wish you happy AMOS programming. Byeee !