ZX Forum #04
19 ноября 1997

world of sound Spectrum - Chapter 2: Operator BEEP, Creating effects on BEEPe, Making Music on BEEPe.

<b>world of sound Spectrum</b> - Chapter 2: Operator BEEP, Creating effects on BEEPe, Making Music on BEEPe.
            2. Operator BEEP


   The only possibility of capturing the sound, which provides 
Spectrum-BASIC - is the operator of BEEP. Its format is: 


                 BEEP t, f

where t - the duration of the sound in seconds, and
f - height in semitones. To raise or lower the note one octave, 
it is necessary its value is accordingly increased or

reduced by 12.

   So, BEEP 0.5, 0 plays the note BEFORE
the first octave within half a second, and BEEP
0.5, 12 - the same note before, but the second octave.

   Specified notoischislenie not very accurate, so take a look 
at Figure 3. There's a top line shows the approximate,

and at the bottom - the exact parameters of the operator
BEEP for the first octave.

   Musical range BEERa enough
wide - from -60 to 69. It covers 18.5
octaves, but the lowest and the highest of
are of no practical interest for music creation, although it may
used sound effects.

   Finally, you can add the convenience that Spectrum-BASIC 
provides us with a record of decimal fractions. If a fraction 
less than unity, then the zero before point can be left out. 
Thus, 


              BEEP 0.125,11

can be written as


              BEEP .125,11.


   Further down the text of the book I was so
I will do.


     2.1. Creating effects on BEERe


   In order to do something more interesting simple beeps, the 
operator BEEP usually included in any cycle where

change one or both of its parameters.
The simplest example might look like:


   10 FOR A = 0 TO 60

   20 BEEP .01, A

   30 NEXT A

This small program can be long and
resistant to change, getting more and more
effects. Try to modify the limits, step, direction, cycle 
duration in operator BEEP. How to do it, I think

understandable for everyone, so give examples
I will not. During your experiment, remember that with small 
durations of the low notes will not play, and the note below, 
the greater should be the duration. 

   When you get tired of occupation, the proposed
in the previous paragraph, you can proceed to
the next step - change the "innards" of the cycle ...

   You can increase the number of operators BEEP.
And they can be configured as
the same frequency and duration, and
for different:


   10 FOR A = 0 TO 20

   20 BEEP .007, A +7: BEEP .003, A

   30 NEXT A


   The sound range of additional BEERov
You can limit:


   10 FOR A = 0 TO 69

   20 BEEP .01, A

   30 IF A> 20 AND A <40 THEN BEEP .01, A +8

   40 NEXT A

or so:


   10 FOR A = 0 TO 69

   20 BEEP .0003, A-6: BEEP .001, A-3: BEEP

      .01, A

   30 NEXT A

The latter effect is interesting because it
second and third BEERy come gradually
(See footnote on previous page).

   The effect can be slowed down by the operator PAUSE:


   10 FOR A = 10 TO 40 STEP 2

   20 BEEP .01, A: PAUSE 2

   30 NEXT A


   You can play for a change
Duration:


   10 LET T =. 01

   20 FOR A = 10 TO 60: BEEP T, A

   30 LET T = T-.0002: NEXT A

   10 FOR A = 0 TO 60

   20 BEEP A/500 ,60-A

   30 NEXT A

The first of these examples, try to change the pace or 
direction of change in duration, and its initial value. 

   The next option - nested loops,
which can be any number. BEERy
can occur in any of them:


   10 FOR A = 2 TO 5: BEEP .01, A

   20 FOR B = 20 TO 30: BEEP .01, B

   1930 NEXT B: NEXT A


   10 FOR A = 1 TO 40 STEP 10

   20 FOR B = A TO A +20

   30 BEEP .03, B

   1940 NEXT B: NEXT A


   Try to combine several cycles.
For example:


   10 FOR A = 12 TO 69: BEEP .001, A

   20 NEXT A

   30 FOR A = 69 TO 12 STEP -1

   40 BEEP .001, A: NEXT A


   And finally, in all this collection can be
add an element of randomness:


   10 FOR A = 1 TO 10: LET F = RND * 50

   20 BEEP .1, F: BEEP .1, F +7: BEEP .1, F +4

   30 NEXT A


   10 FOR A = 1 TO 20

   20 BEEP .1, RND * 20 40

   30 NEXT A


   10 FOR A = 1 TO 20

   20 BEEP RND / 6, RND * 60

   30 NEXT A


   All of the above methods to create
effects can be used together,
any combination.

   Look, try and you will find among
sets a couple suitable for your
program effects.


       2.2. Making Music on BEERe


   Unfortunately, the operator of BEEP is impossible to create 
complex music, but Online Time unpretentious melody on it can 
be. 

   The first thing that comes to mind when trying to create a 
melody - it's up the chain of BEERov, which promises to be very 
uncertain dimensions. This method primitive, cumbersome, takes 
up space and generally not very handsome. Him, there are 
several worthy replacements. For example, You can use this loop:



   10 FOR A = 1 TO 10

   20 READ T, F: BEEP T, F

   30 NEXT A

And somewhere in the program to insert a row,
beginning with the DATA statement, which contains the length 
and height of the music tunes. In this example, there should be 
ten. 

   In some musical works
There are pauses. To perform such tunes, the above cycle will 
have little modified: 


   10 FOR A = 1 TO 10: READ T, F

   1920 IF T = 0 THEN PAUSE F * 50: NEXT A

   30 BEEP T, F: NEXT A

Now it suffices to insert the data 0 and
followed by the pause in seconds.

   You may have noticed that the value
pause is multiplied by 50. This is because the operator PAUSE 
option is calculated in the fiftieth of a second. Table 1 shows 
the corresponding notes of the durations of the operators BEEP 
and PAUSE. In this table lists the default values ​​of notes and

pauses, but you can use any number.

   Here, for example, a program that executes
verse children's song "Born in the Woods
herringbone:


     10 FOR A = 1 TO 29: READ T, F

     1920 IF T = 0 THEN PAUSE F * 50: NEXT A

     30 BEEP T, F: NEXT A

   9000 DATA .25,7.02, .25,15.86, .25,

        15.86, .25,14.039, .25,15.86

   9010 DATA .25,12, .25,7.02, .25,7.02,

        .25,7.02, .25,15.86, .25,15.86

   9020 DATA .25,14.039, .25,20.84, .5,

        19.02,0, .5, .25,19.02, .25,8.84

   9030 DATA .25,8.84, .25,16.98, .25,

        16.98, .25,15.86, .25,14.039, .25,

        12

   9040 DATA .25,7.02, .25,15.86, .25,

        15.86, .25,14.039, .25,15.86, .5,

        12


   In this program we can introduce the possibility of a change 
of pace. To do this, the first three lines replaced by the 
following: 


    5 LET N =. 5

   10 FOR A = 1 TO 29: READ T, F

   1920 IF T = 0 THEN PAUSE F * N * 50: NEXT A

   30 BEEP T * N, F: NEXT A


   Now you can achieve the desired
rate performance tunes, substituting different values ​​in the 
fifth row. However, not I advise you to insert 0 and there are 
very large numbers. 

   You can still improve this program from. For example, to 
insert the control of keystrokes, making it more flexible in 
terms of the length melodies draw as a subroutine, etc. The 
final version may look like this:



   9090 DATA 100

   9100 LET N =. 5: RESTORE 9000

   9110 READ T, F

   9120 IF T = 100 OR INKEY $<>"" THEN RETURN

   9130 IF T = 0 THEN PAUSE F * N * 50: GO TO

        9110

   9140 BEEP T * N, F: GO TO 9110

Remove all rows from 5 to 30 previous
program and enter these. Now you can
cause ringing in response to operator
GO SUB 9100. Also, now is not necessary
carefully calculate the number of notes in the melody: it is 
enough to insert the end of the 100 (which is, in fact, taken 
on line 9090). Also, you can at any time stop execution by 
pressing any key. If the melody is going to end - subroutine 
also completed its work. When you restart, the melody will 
start at first, but if remove operator RESTORE 9000, it will 
continue from the place where it was interrupted (Unless, of 
course, you do not use the operator READ or RESTORE after the 
call). 

   You can make a play round-robin. It will have to change a 
couple of Lines:



   9120 IF INKEY $<>"" THEN RETURN

   9125 IF T = 100 THEN GO TO 9100


   Now back from the subroutine can
just by pressing keys. But the melody
will sound until someone does not
bored.

   Programs of this type are ideal for
simple execution, without replacement, and save the ringing 
tone, but if you want to write his work on tape and download it 
directly from a running program, You fit the following snippet:



   10 FOR A = 3 TO D (1) * 2 +2 STEP 2

   20 IF D (A) = 0 THEN PAUSE D (A +1) * D (2) * 50:

      NEXT A

   30 BEEP D (A) * D (2), D (A +1)

   40 NEXT A

In order to make it work, before it
run must declare and complete the
array D, containing such information
Store:


   D (1) - the number of notes

   D (2) - the rate of execution

   D (3) - duration 1

   D (4) - note 1

    .

    .

    .

   D (N) - the duration of N

   D (N +1) - note N

You can download it from cassette filing direct command


    LOAD "name" DATA D ()

or fill out the following lines DATA
applets:


   10 DIM D (1920): RESTORE

   20 FOR A = 1 TO 20: READ D (A)

   30 NEXT A

Please note that the first two digits
Data should be the amount of notes and tempo.

   Thus created an array of possible
keep the tape team


   SAVE "name" DATA D ()


   Here is another example of such a program, designed by the 
rage: 


   9100 LET A = 2

   9110 IF D (A) = 100 THEN GO TO 9100

   9120 IF INKEY $<>"" THEN RETURN

   9130 IF D (A) = 0 THEN PAUSE D (A +1) * D (1) *

        50: GO TO 9150

   9140 BEEP D (A) * D (1), D (A +1)

   9150 LET A = A +2: GO TO 9110

Array for this sub should be
as follows:


   D (1) - the rate of execution

   D (2) - duration 1

   D (3) - note 1

    .

    .

    .

   D (N) - the duration of N

   D (N +1) - note N

   D (N +2) - 100


   Note that the number of notes to indicate
not necessary. Based on this example can be
make even a music editor.

   Now back to the drawing up of chains
data.

   Suppose, on the stave you see
note to a hair's breadth, as in Figure 4. This is LA
the first octave. Figure 1 shows that it
frequency can be written as 8.84.

   Is one-fourth, and, looking at Table 1, we can determine 
that its duration would be .25. Thus, a pair of data for this 
note will .25,8.84. For all further notes the calculation will 
be the same.







Other articles:

Help - Description of the shell of an electronic book "ZX-FORUM 4.

Secrets of Successful Design - Head for the book "Design your Programs

screen effects - Running a string of R-Type.

screen effects - clearing the screen of Zynaps.

screen effects - "minimize" the screen from Comando Tracer.

screen effects - smooth "decay" of the screen Sommando Tracer.

screen effects - changed the character set for the original stylized font from the game Rockstar.

screen effects - "running out the string" out of the game Rockstar.

screen effects - "pouring" the screen of the game Rockstar.

screen effects - a complex multi-effects from the game Bubbler.

New top 40 procedures - scrolling display, a fusion of two images, inverting screen, rotate characters, replacement of attributes, fill a closed loop, the calculation of addresses in the screen, copy of the screen, etc.

Technology sprites - Part 1: Introduction.

Technology sprites - Part 2: The hunt for sprites (search and pulling).

Technology sprites - Part 3: Format of sprites.

Technology sprites - Part 4: Format of sprites with a mask.

Technology sprites - Part 5: Structure sprite blocks (both co-exist in memory sprite and mask, what data to help us quickly find the address of the sprite in memory, and much more.)

Technology sprites - Part 6: preparation of data for publication.

Technology sprites - Part 8: Printing sprites (coordinates are given in familiarity).

Technology sprites - Part 9: Printing sprites (coordinates given in pixels).

Technology sprites - Part 10: a review of programs to work with sprites and graphics.

world of sound Spectrum - Chapter 1: The Physics of Sound.

world of sound Spectrum - Chapter 2: Operator BEEP, Creating effects on BEEPe, Making Music on BEEPe.

world of sound Spectrum - Chapter 3: How is the sound device (BEEP'ra and methods of sound production).

world of sound Spectrum - Chapter 4: Programming sound in assembler.

world of sound Spectrum - Chapter 4.1: Programming sound effects - Tone, Noise, Complexes effects.

world of sound Spectrum - Chapter 4.2: Programming Sound Effects - Volume Control.

world of sound Spectrum - chapter 4.3: Sound Effects - Management timbre.

world of sound Spectrum - Chapter 4.4: Programming sound effects - music programming.

world of sound Spectrum - Chapter 4.5: Programming sound effects - Polyphonic ringtones (polyphonic).

world of sound Spectrum - chapter 4.6: Treatment of external signals - digitization.

world of sound Spectrum - Chapter 4.7: Handling of external signals - Reverberation.

world of sound Spectrum - chapter 4.8: Synthesis of speech.

world of sound Spectrum - Chapter 4.9: audio playback interrupt.

world of sound Spectrum - Chapter 5: The operator PLAY for music coprocessor AY- 3-8910 (AY-3-8912).

world of sound Spectrum - Chapter 5.1: Creating effects operator PLAY.

world of sound Spectrum - Chapter 5.2: Making Music on PLAYe.

world of sound Spectrum - Chapter 6.1: Description of the coprocessor registers of the musical AY- 3-8910 (AY-3-8912).

world of sound Spectrum - Chapter 6.2: Programming effects and music under the musical coprocessor AY- 3-8910 (AY-3-8912).

world of sound Spectrum - Chapter 7: Software Review ZX-Spectrum to create sounds and music.

world of sound Spectrum - chapter 7.1: Editor, Sound Effects SUPER SOUND.

world of sound Spectrum - Chapter 7.2: Music Editor Wham the Music Box.

world of sound Spectrum - Annex 1, 2: Listings sound effects SUPER SOUND'a, tips assembler.


Темы: Игры, Программное обеспечение, Пресса, Аппаратное обеспечение, Сеть, Демосцена, Люди, Программирование

Similar articles:
Games - The demo version of the game Wolfenstein 3D.
Schedule BBS - schedule Grodno BBS.
Premiere - The Adventures of Winnie the Pooh.

В этот день...   28 April