AHI

From Amiga Development Wiki
Revision as of 17:06, 22 August 2015 by AmigaDeveloper (Talk | contribs) (Example: Improved example code with example code how to send sample data to AHI)

Jump to: navigation, search

Introduction

AHI is an audio system for Amiga created by Martin Blom. It replaces the original audio.device developed by Commodore-Amiga, however, AHI is not suitable for low end Amigas.

Since developing audio applications using audio.device need careful coding and understanding the original Amiga audio hardware (Paula) it is not covered here.

AHI has both device and library interfaces to play sound but using library interface is not recommended. You should always use low level interface (also known as device interface) only.

Example

#include <devices/ahi.h>
#include <proto/exec.h>
 
int main()
{
   struct MsgPort *port = CreateMsgPort();
 
   if (port)
   {
      struct AHIRequest req;
 
      req.ahir_Std.io_Message.mn_Node.ln_Type = NT_REPLYMSG;
      req.ahir_Std.io_Message.mn_ReplyPort = port;
      req.ahir_Std.io_Message.mn_Length = sizeof(struct AHIRequest);
      req.ahir_Version = 2;
 
      if (OpenDevice("ahi.device", AHI_DEFAULT_UNIT, (struct IORequest *)&req, 0) == 0)
      {
         /* call player routine to get sample data */
         req.ahir_Std.io_Command = CMD_WRITE;
         req.ahir_Std.io_Data = playback_buffer; /* Sample data to play */
         req.ahir_Std.io_Length = playback_buffer_length; /* Length of sample data in bytes */
         req.ahir_Type = AHIST_S16S; /* 16-bit, stereo */
         req.ahir_Frequency = 44100; /* Frequency in Hz */
         req.ahir_Volume = 0x10000; /* Volume to max */
         req.ahir_Position = 0x8000; /* Stereo position (this is in the middle) */
         SendIO((struct IORequest *)&req);
 
         /* now we have finished and can quit... */
 
         /* Abort all pending request */
         AbortIO((struct IORequest *)&req);
         WaitIO((struct IORequest *)&req);
 
         CloseDevice((struct IORequest *)&req);
      }
 
      DeleteMsgPort(port);
   }
 
   return 0;
}

Links

AHI developer archive for AmigaOS