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

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

<b>world of sound Spectrum</b> - Chapter 4.4: Programming sound effects - music programming.
       4.4. Programming Music


   Programming music codes - a thankless task. It is better to 
do with any musical editor. But the editor can not satisfy all 
Your needs, so that the master programming code is still 
desirable. 

   The principle is the same - consistent read data and the 
procedure is called play. It is necessary to provide for 
termination of execution (often for these purposes is 
controlled by pressing any key). For example: 1415.

 10 START LD HL, 60000; HL = address of data
 20 NEXT LD E, (HL); DE =
 30 INC HL; length 40 LD D, (HL); Tel
 50 INC HL; sequence
 60 LD A, D; DE
 1970 CP 255 =
 80 JR NZ, CONT; 65535
 90 LD A, E;?
100 CP 255, if so,
110 JR Z, START; a melody first
120 CONT LD A, D; DE =
130 OR E; 0?
140 JR NZ, BEEP; if not, go to BEEP
150 LD E, (HL); DE =
160 INC HL; dlitel170 LD D, (HL); sequence
180 INC HL; pause
190 PAUSE HALT; interrupt latency
200 DEC DE; DE = DE-1
210 LD A, D; DE =
220 OR E; 0?
230 JR NZ, PAUSE; if not then loop
240 JR NEXT; the transition to the processing of the trace.

                                    Data
250 BEEP LD C, (HL); BC =
260 INC HL; chas270 LD B, (HL); to280 INC HL; that
290 PUSH HL; conservation HL
300 PUSH BC; put BC on the stack
310 POP HL; put the value from the stack

                                    in HL
320 CALL 949, a subroutine call

                                    play
330 CALL 654, control keyboard
340 POP HL; recovery HL
350 LD A, E; A = E
360 CP 255, if pressed,
370 RET NZ; then return to BASIC
380 JR NEXT; the transition to the processing of the trace.

                                    Data
2

   When you call this subroutine from the machine code, note 
that interrupts must be enabled! Otherwise, if data from the 
first will be a pause, the computer hangs. 

   Before using this rather
ugly routines necessary to create for her an array of data 
(this is the most fun). In this case, it should located at 
address 60000 (# EA60), but You can easily change its location, 
changing the number in the first row of this subroutine.


   Data for each note should be as follows: first two bytes of 
length (First - the younger), then two bytes of the frequency. 
If, instead of the duration to put two zero, then the next pair 
of bytes will be regarded as the length of the pause. To mark 
the end of the melody, insert the data instead of the regular 
length of two bytes 255. 

   Pause duration is measured in the fiftieth of a second, and 
what is measured duration of a note - do not know, probably,

No one, though to calculate the required value is still 
possible (see Chapter 4). 

   Now for the drawbacks, which, honestly
speaking, more than enough. Two of them were already mentioned 
above: the difficulty of drawing melodies and strange enough 
measurement duration of notes. In addition, the duration 
frequency-dependent. For example, if you enter the following 
data: 0,1,100,0,0,1,0,5,255, 255, then you hear two different 
notes of the same length as expected. 

   Another drawback - the opportunity to abort execution only 
in the interval between notes. However, it can easily be 
corrected: 1415.

 10 START LD HL, 60000; HL = address of data
 20 NEXT LD E, (HL); DE =
 30 INC HL; length 40 LD D, (HL); Tel
 50 INC HL; sequence
 60 LD A, D; DE
 1970 CP 255 =
 80 JR NZ, CONT; 65535
 90 LD A, E;?
100 CP 255, if so,
110 JR Z, START; a melody first
120 CONT LD A, D; DE =
130 OR E; 0?
140 JR NZ, BEEP; if not, go to BEEP
150 LD E, (HL); DE =
160 INC HL; dlitel170 LD D, (HL); sequence
180 INC HL; pause
190 PAUSE XOR A; A = 0 (control across the keyboard
                                    tours)
200 IN A, (254); poll Keys
210 CPL; inverting A
220 AND 31; dumping excess bit
230 RET NZ; if a key is pressed, the WHO
                                    Gates
240 HALT; interrupt latency
250 DEC DE; DE = DE-1
260 LD A, D; DE =
270 OR E; 0?
280 JR NZ, PAUSE; if not, then the cycle
290 JR NEXT; the transition to the processing of the trace.

                                    Data
300 BEEP LD C, (HL); BC =
310 INC HL; chas320 LD B, (HL); to330 INC HL; that
340 PUSH HL; conservation HL
350 PUSH BC; put BC on the stack
360 POP HL; put the value from the stack

                                    in HL
370 CALL PLAY; subroutine call

                                    play
380 POP HL; recovery HL
390 RET NZ; then return to BASIC
400 JR NEXT; the transition to the processing of the trace.

                                    Data
410 PLAY DI; ban interrupt
420 LD A, (23624); A =
430 SRL A; color
440 SRL A; bor450 SRL A; Duras
460 LOOP1 XOR 16; inverting bits D4
470 OUT (254), A; output to port A 254
480 LD C, A; preservation A
490 PUSH HL; conservation HL
500 LOOP2 XOR A; A = 0 (control across the keyboard
                                    tours)
510 IN A, (254); poll Keys
520 CPL; inverting A
530 AND 31; dumping excess bit
540 JR Z, CONT2; if no key is pressed, the

                                    continue
550 POP HL; off the value of the stack
560 EI; permission to interrupt
570 RET; Returns
580 CONT2 DEC HL; HL = HL-1
590 LD A, H; HL =
600 OR L; 0?
610 JR NZ, LOOP2; if not, then the cycle
620 POP HL; recovery HL
630 DEC DE; DE = DE-1
640 LD A, D; DE =
650 OR E; 0?
660 LD A, C; A recovery
670 JR NZ, LOOP1; if DE <> 0 then loop
680 EI; permission to interrupt
690 RET; Returns
2

   Note that the same
Data will be played in different ways
this and the previous routines.

   And finally, the most obvious drawback - the music, which is 
obtained by These routines are too primitive. On

assembler can do anything and more serious.

   I hope that convinced you not to try
program music directly to the codes and
instead buy a good music editor.

   All routines listed in this
chapter can be used to create
effects. It's enough to place notes
encode the individual level effect.
It is desirable that each step was as
can be shorter, then the effect will be heard
smoothly.







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:
Stuck? - Description of the game "The Last Ninja 2."
News - Work on the CSC Deja VU completed. Emulator Pentagon-128 for the platform Amigo. Level editor for the FT.

В этот день...   21 November