Go to the first, previous, next, last section, table of contents.


Writing To The Device

You write to the device by passing an AHIRequest to the device with CMD_WRITE set in io_Command, the precedence in io_Message.mn_Node.ln_Pri, the number of bytes to be written in io_Length, the address of the write buffer set in io_Data, the sample format set in ahir_Type, the desired sample frequency set in ahir_Frequency, the desired volume set in ahir_Volume and the desired stereo position set in ahir_Position. Unless you are doing double buffering, ahir_Link should be set to NULL. io_Length must be an even multiple of the sample frame size.

Double Buffering

To do double buffering, you need two I/O requests. Create the second one by making a copy of the request you used in OpenDevice(). Start the first with SendIO(). Set ahir_Link in the second request to the address of the first request, and SendIO() it. Wait on the first, fill the first buffer again and repeat, this time with ahir_Link of the first buffer set to the address of the second I/O request.

Distortion

The problems with aliasing are present but not as obvious as with reading. Just make sure your source data is bandlimited correctly, and do not play samples at a lower frequency than they were recorded.

Playing multiple sounds at the same time

If you want to play several sounds at the same time, just make a new copy of the I/O request you used in OpenDevice(), and CMD_WRITE it. The user has set the number of channels available in the preference tool, and if too many requests are sent to the device the one with lowest precedence will be muted. When a request is finished, the muted request with the highest precedence will be played. Note that all muted requests continue to play silently, so the programmer will not have to worry if there are enough channels or not.

Suggested precedences

The precedences to use depend on what kind of sound you are playing. The recommended precedences are the same as for audio.device, listed in AMIGA ROM Kernel Reference manual -- Devices. Reprinted without permission. So sue me.

 Precedences  | Type of sound
 -------------+----------------------------------------------------------
    127       |  Unstoppable.  Sounds first allocated at lower
              | precedencies, then set to this highest level.
    90 - 100  |  Emergencies.  Alert, urgent situation that requires
              | immediate action.
    80 - 90   |  Annunciators.  Attention, bell (CTRL-G).
    75        |  Speech.  Synthesized or recorded speech
              | (narrator.device).
    50 - 70   |  Sonic cues.  Sounds that provide information that is not
              | provided by graphics.  Only the beginning of of each sound
              | should be at this level; the rest should ne set to sound
              | effects level.
   -50 - 50   |  Music program.  Musical notes in a music-oriented program.
              | The higher levels should be used for the attack portions
              | of each note.
   -70 - -50  |  Sound effects.  Sounds used in conjunction with graphics.
              | More important sounds should use higher levels.
   -100 - -80 |  Background.  Theme music and restartable background sounds.
   -128       |  Silence.  Lowest level (freeing the channel completely is
              | preferred).

Right. As you can see, some things do not apply to ahi.device. First, there is no way to change the precedence of a playing sound, so the precedences should be set from the beginning. Second, it is not recommended to use the device interface to play music. However, playing an audio stream from CD or disk comes very close. Third, there are no channels to free in AHI since they are dynamically allocated by the device.


Go to the first, previous, next, last section, table of contents.