Users - programming sound effects.

Faultless #03
 ╔═══════════════════ ═══════════════════╗
  ║Section: Users;                ║
  ║Article: Creating sound effects;   ║
  ║Text: Vorozhkin Alexander.           ║
  ╚═══════════════════ ═══════════════════╝

 Various sound and noise effects,
  which abound in computer games,
  are achieved through a change in one way or another
  a different law for the frequency of the output sound.
   You already know the sound output technique,
  so without further ado, let's move straight to
  case and demonstrate some of the most
  more commonly used effects in games
  comrade. The first of them most closely resembles
  hears the chirping of birds, especially if it is caused by
  with small and unequal intervals
  kami of time:

   TWEET LD A,(23624) ;Color detection
          AND #38 curb
          RRA
          RRA
          RRA
          D.I.
   TWEET1 XOR 16 ;Switching 4th
          OUT (254),A bits
          PUSH BC
          DJNZ$ ;delay cycle
          POP B.C.
          DJNZ TWEET1
          EI
          RET

   Duration of effect before contacting
  the TWEET procedure is specified in register B,
  for example:

          LD B,200
          CALL TWEET
          RET

   Before giving the next example,
  let's say a few words related not to
  only to this subroutine, but to all
  to the rest. Because in realprogram
  the color of the border usually does not change and
  is determined in advance, then it is usually not
  is calculated in the program and specified in
  explicitly loading code into the accumulator
  desired color.You can also instead
  first lines from the TWEET mark to the command
  DI just write XOR A to get
  black border or, for example, LD A,4 -
  for green.
   Another interesting point concerns already
  the program itself, but the assembler itself.
  You probably noticed the post

          DJNZ$

   As you know, the dollar symbol when trans-
  lation takes the value of the current address
  placement of machine code, or rather ad-
  res of the beginning of a line of assembly text.
  Therefore, such a record is completely equivalent
  on the recording:

   LOOP DJNZ LOOP

  but allows you to do without additional
  marks.
   After such a small lyrical
  digressions let's continue  sound effects.
   Especially often in game programs you can
  hear many varieties of vibrations
  chanting sounds.Get this effect
  you can periodically increase and decrease
  frequency (i.e. the number of delay cycles
  ki). Vibration is characterized by two pa-
  parameters: natural frequency and depth
  noy (amplitude), therefore for such a pro-
  procedures will be required, except for the duration
  sounds, set and some others
  input data.Firsttext provided
  routines for obtaining vibrating
  sound, and then we will explain what values in
  which registers should be replaced before
  addressing her.

   VIBR LD A,(23624)
          AND #38
          RRA
          RRA
          RRA
          LD C,A
          D.I.
   VIBR1 LD D,E ;Duration
   VIBR2 LD A,C fall cycle (rise-
          XOR 16 em)
          LD C,A
          OUT(254),A
          LD A,H ;Frequency change
          ADD A,L sound
          LD H,A
   VIBR3 DEC A ;delay cycle
          JR NZ,VIBR3
          DEC D
          JR NZ,VIBR2
          LD A,L ;change direction
          NEG frequency change
          LD L,A
          DJNZ VIBR1
          EI
          RET

   In register H you need to enter the initial
  sound frequency (meaning, of course,
  frequency is not in hertz, but in relative
  units).The contents of register E affects
  to the vibration frequency: the less its value
  tion, the faster the decline will give way
  rise and vice versa. In register B sets -
  This is the number of vibration cycles, i.e. in
  ultimately - the duration of the sound, and
  in L the value is entered that determines
  the depth of vibration, or otherwise, the speed of
  changes in pitch. We offer such
  register values:

          LD H,100
          LD E,120
          LD B,4
          LD L,1
          CALL VIBRRET

  however, this is only one of many possibilities
  new options. Try experimenting
  Rate and select the most interesting
  sound options that are subsequently
  you can use in your own
  developments.

Share your thoughts about the article