Better Programming!

Pub Details

Date

Pages

See all articles from Byte Power Dec 86/Jan 87

This month I will talk about the ‘REAL ECHO’. This one is a little more complicated than the ‘FALSE ECHO’ (NOV ’86).

To create a real echo means playing two notes but one slightly off! To create this effect we’ll need a counter.

It’s quite easy, don’t worry! First, you’ll have to either put the codes in a NUMBER ARRAY or in CODES, DATA statements won’t work. If you did it in DATA statements, you would need as much DATA statements as you have notes!

Let’s see how it would be done:

5 LET v1=60003: LET v2=60000
10 POKE v2,254: POKE v2+2,1
15 GOSUB 100: GOSUB 200
35 IF a1=255 AND b1=255 THEN STOP
40 LET a4=15: IF a1>=254 THEN LET a4=0
45 LET b4=12: IF b1>=254 THEN LET b1=0
50 SOUND 8,a4; 9,b4; 7,60; 0,a1; 1,a2; 2,b1; 3,b2
55 PAUSE 4
60 LET a3=a3-1: IF a3=0 THEN GOSUB 100
65 LET b3=b3-1: IF b3=0 THEN GOSUB 200
70 GOTO 35
100 LET a1=PEEK v1: LET a2=PEEK (v1+1): LET a3=PEEK (v1+2): LET v1=v1+3
110 IF a1<254 THEN SOUND 8,14
120 RETURN
200 LET b1=PEEK v2: LET b2=PEEK (v2+1): LET b3=PEEK (v2+2): LET v2=v2+3
210 IF b1<254 THEN SOUND 9,11
220 RETURN

NOW, let me explain in details:

LINE 5:v1 is the address of the MAIN MUSIC and v2 is the address of the ECHO. NOTE: they are 3 bytes apart since the MAIN MUSIC starts first. The ECHO starts with a PAUSE (254, MUSIcomp data)

LINE 10:This is to insure that the ECHO starts with a PAUSE (254). The second POKE can be altered (don’t use 0 or it’ll never stop!!!) v2 SHOULD ALWAYS BE 3 BYTES LESS THAN v1!

LINE 15:This will get the first notes of MAIN MUSIC and ECHO.

LINE 35:If a1 and b1 are both equal to 255 then it means that the music is over. (255 is, again, MUSIcomp data and can be changed for your own data)… a1 and b1 are defined in lines 100 to 200.

LINE 40:a4 is the volume of MAIN MUSIC. If the value of a1 equal to a PAUSE (254) or END OF MUSIC (255) then the volume is completely cut off.

LINE 45:Same as line 40 but the volume of the ECHO is much lower than the one for MAIN MUSIC. (The echo is never as loud, RIGHT?!?)

LINE 50:This will play the notes!

INE 55:This is the TEMPO, alter the value to suit your needs.

LINE 60:This is the COUNTER! You decrement by one until it equals 0 then you get the next note.

LINE 65:Exactly the same as line 60 but for the ECHO.

LINE 70:Completes the loop!

LINE 100:Get the next note and increment v1 by 3.

LINE 110:Lowers the volume between two notes so that you can hear the separation. NOTE: I didn’t put 0 because it wouldn’t be as smooth!

LINE 120:Returns from subroutine.

LINE 200 to 220 are the same as 100 to 120 except that it is for the ECHO.

What the program does is that it will play the note and decrement the counter by one until 0. Then the computer will get the next note to be played. It does this to both ‘voices’ at the same time until the music ends (255).

It is the same principle for DUETS or TRIOS! You just have to change the addresses for the beginning of the ‘voices’. Ex:45000 could be voice 1 and 55000 could be voice 2. It would play two different notes of different duration at the same time as opposed to the ECHO which plays the same two notes of both the same duration but the ECHO being slightly off and not as loud!

When a DUET or TRIO, what you should do is to put the CODES one after the other. First ‘voice 1’ (the whole data!) and then ‘voice 2’ and then ‘voice 3’ if you have one.

You will find on the cassette two programs: the first one is called “REAL ECHO” and the second one “EXAMPLE 2”. The first one will play a music with the ECHO and the second one will play a DUET.

To fully understand this technique, I suggest you study carefully these BASIC programs. The CODES were generated using MUSIcomp (NOV’86).

Oh! I almost forgot! Try changing the values 15 and 12 in lines 40-45 to 9 and 6. You might like it!

Well that’s it for this month!

See you next time for CHAPTER 6 OF SOUND EFFECTS! Eric will talk about a 2 voice BEEP using a special routine.’Til then… If you have tips or questions send them to…

Products

 

Downloadable Media

 

Image Gallery

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

Scroll to Top