rem: context.Playing = TRUE; AHI_Play( context.AudioCtrl, AHIP_BeginChannel, 0, AHIP_Freq,         sample_freq, AHIP_Vol,          0x10000, AHIP_Pan,          0x8000, AHIP_Sound,        0, AHIP_EndChannel,   0, TAG_DONE );  kprintf( "AHI_ControlAudio(play)\n" ); if( AHI_ControlAudio( context.AudioCtrl, AHIC_Play, TRUE, TAG_DONE ) != AHIE_OK ) { context.Playing = FALSE; pEIOsg->lError  = EIO_ERR_HARDFAIL; } }  break; }  case EIO_CMD_REC: { ULONG sample_type = -1; ULONG sample_freq = -1;
add: context.Playing = TRUE; AHI_Play( context.AudioCtrl, AHIP_BeginChannel, 0, AHIP_Freq,         sample_freq, AHIP_Vol,          0x10000, AHIP_Pan,          0x8000, AHIP_Sound,        0, AHIP_EndChannel,   0, TAG_DONE ); } }    if( command & COMMANDF_RECORD ) {
context: main( void ){  ExternalIOMessage *pEIOsg;  struct MsgPort* port;  ULONG           ulSignal;  ULONG           ulPortSignal;  struct Context context;    /* Open 'ahi.device'. */  if( !Init() )  {    return RETURN_FAIL;  }  /* Init the hardware. If there is any problem quit without setting up     the message port */  if( !Construct( &context ) )  {    ShutDown();    return RETURN_FAIL;  }  /* Set up the message port */  port = CreatePort( PORTNAME, 0 );  if( port != NULL )  {    BOOL fQuit      = FALSE;    ulPortSignal = 1 << port->mp_SigBit;    while (!fQuit)    {      /* Wait for messages from AL16 (commands) and for signals from         your board (the board must signal your driver each time a         buffer has been completed).         In this demo the timer.device signals us every DELAY seconds */kprintf( "Waiting for signals: %08lx.\n", ulPortSignal | SIGBREAKF_CTRL_C );      ulSignal = Wait(ulPortSignal | SIGBREAKF_CTRL_C );kprintf( "Got signal: %08lx\n", ulSignal );      if( ulSignal & SIGBREAKF_CTRL_C )      {        fQuit = TRUE;      }      else if(ulSignal & ulPortSignal) /* Command from AL16... */      {kprintf( "PSA signal\n" );        while( (pEIOsg = (ExternalIOMessage *) GetMsg(port)) )        {kprintf( "Got message!\n" );          switch(pEIOsg->lCommand)          {            case EIO_CMD_INFO:              /* Tell AL16 your name (please center the name                 into an 11 char string). Fill free to choose                 a name for your driver. */              strncpy(pEIOsg->mpchDrvName,"AHI I/O 1.0",12);              pEIOsg->lError = EIO_ERR_NOERROR;kprintf("EIO_CMD_INFO received\n");               break;            case EIO_CMD_PLAY:            {              ULONG sample_type = -1;              ULONG sample_freq = -1;kprintf( "EIO_CMD_PLAY\n" );              pEIOsg->lError         = EIO_ERR_NOERROR;              context.PlayTask       = pEIOsg->ptaskSwapper;              context.PlaySignalMask = pEIOsg->ulSignalMask;              sample_freq            = pEIOsg->ulClock;              if( pEIOsg->wDataType == EIO_DAT_16LS )              {                if( pEIOsg->wChannels == 1 )                {                  sample_type = AHIST_M16S;                }                else if( pEIOsg->wChannels == 2)                {                  sample_type = AHIST_S16S;                }                else                {                  pEIOsg->lError = EIO_ERR_CHANNELS;                }              }              else              {                pEIOsg->lError = EIO_ERR_DATATYPE;              }              /* Re-allocate audio using new frequency if it has changed. */              if( pEIOsg->lError == EIO_ERR_NOERROR                   && context.Frequency != sample_freq )              {                if( !AllocAudio( context.Mode,                                 sample_freq,                                  &context ) )                {                  pEIOsg->lError = EIO_ERR_HARDFAIL;                }              }              if( pEIOsg->lError == EIO_ERR_NOERROR )              {                AHI_UnloadSound( 0, context.AudioCtrl );                AHI_UnloadSound( 1, context.AudioCtrl );                context.Sound0Loaded = FALSE;                context.Sound1Loaded = FALSE;                if( pEIOsg->fOnePage )                {                  struct AHISampleInfo si;                                  si.ahisi_Type    = sample_type;                  si.ahisi_Address = pEIOsg->pbBuffer1;                  si.ahisi_Length  = pEIOsg->lBufferSize                                      / AHI_SampleFrameSize( sample_type );kprintf( "Loadsound 0: %lx, %ld\n", si.ahisi_Address, si.ahisi_Length );                  if( AHI_LoadSound( 0,                                     AHIST_DYNAMICSAMPLE,                                     &si,                                     context.AudioCtrl ) != AHIE_OK )                  {                    pEIOsg->lError = EIO_ERR_HARDFAIL;                  }                  else                  {                    context.Sound0Loaded = TRUE;                  }                                  context.CurrentSound = 0;                  context.NextSound    = 0;                }                else                {                  struct AHISampleInfo si;                    si.ahisi_Type    = sample_type;                  si.ahisi_Address = pEIOsg->pbBuffer1;                  si.ahisi_Length  = pEIOsg->lBufferSize                                      / AHI_SampleFrameSize( sample_type );kprintf( "Loadsound 0: %lx, %ld\n", si.ahisi_Address, si.ahisi_Length );                  if( AHI_LoadSound( 0,                                     AHIST_DYNAMICSAMPLE,                                     &si,                                     context.AudioCtrl ) != AHIE_OK )                  {                    pEIOsg->lError = EIO_ERR_HARDFAIL;                  }                  else                  {                    context.Sound0Loaded = TRUE;                                      si.ahisi_Address = pEIOsg->pbBuffer2;kprintf( "Loadsound 1: %lx, %ld\n", si.ahisi_Address, si.ahisi_Length );                    if( AHI_LoadSound( 1,                                       AHIST_DYNAMICSAMPLE,                                       &si,                                       context.AudioCtrl ) != AHIE_OK )                    {                      pEIOsg->lError = EIO_ERR_HARDFAIL;                    }                    else                    {                      context.Sound1Loaded = TRUE;                    }                    }                  context.CurrentSound = 1;                  context.NextSound    = 0;                }              }                            if( pEIOsg->lError == EIO_ERR_NOERROR )              {kprintf( "AHI_Play\n" );                context.Playing = TRUE;                AHI_Play( context.AudioCtrl,                          AHIP_BeginChannel, 0,                          AHIP_Freq,         sample_freq,                          AHIP_Vol,          0x10000,                          AHIP_Pan,          0x8000,                          AHIP_Sound,        0,                          AHIP_EndChannel,   0,                          TAG_DONE );kprintf( "AHI_ControlAudio(play)\n" );                if( AHI_ControlAudio( context.AudioCtrl,                                      AHIC_Play, TRUE,                                      TAG_DONE ) != AHIE_OK )                {                  context.Playing = FALSE;                  pEIOsg->lError  = EIO_ERR_HARDFAIL;                }              }              break;            }            case EIO_CMD_REC:            {              ULONG sample_type = -1;              ULONG sample_freq = -1;kprintf( "EIO_CMD_REC\n" );              pEIOsg->lError           = EIO_ERR_NOERROR;              context.RecordTask       = pEIOsg->ptaskSwapper;              context.RecordSignalMask = pEIOsg->ulSignalMask;              sample_freq              = pEIOsg->ulClock;              if( pEIOsg->wDataType == EIO_DAT_16LS )              {                if( pEIOsg->wChannels == 1 )                {                  sample_type = AHIST_M16S;                }                else if( pEIOsg->wChannels == 2)                {                  sample_type = AHIST_S16S;                }                else                {                  pEIOsg->lError = EIO_ERR_CHANNELS;                }              }              else              {                pEIOsg->lError = EIO_ERR_DATATYPE;              }              /* Re-allocate audio using new frequency if it has changed. */              if( pEIOsg->lError == EIO_ERR_NOERROR                   && context.Frequency != sample_freq )              {                if( !AllocAudio( context.Mode,                                  sample_freq,                                  &context ) )                {                  pEIOsg->lError = EIO_ERR_HARDFAIL;                }              }              /* Make sure the mode is fit for recording */              if( pEIOsg->lError == EIO_ERR_NOERROR && !context.CanRecord )              {                pEIOsg->lError = EIO_ERR_HARDFAIL;              }              if( pEIOsg->lError == EIO_ERR_NOERROR )              {                context.RecordBuffer1      = (WORD*) pEIOsg->pbBuffer3;                context.RecordBuffer2      = (WORD*) pEIOsg->pbBuffer4;                context.RecordBufferType   = sample_type;                context.RecordBufferLength = pEIOsg->lBufferSize                                           / AHI_SampleFrameSize( sample_type );                context.RecordBufferOffset = 0;                if( context.RecordSamples > context.RecordBufferLength )                {                  pEIOsg->lError = EIO_ERR_BUFFERSIZE;                }                context.Recording = TRUE;                if( AHI_ControlAudio( context.AudioCtrl,                                      AHIC_Record, TRUE,                                      TAG_DONE ) != AHIE_OK )                {                  context.Recording = FALSE;                  pEIOsg->lError    = EIO_ERR_HARDFAIL;                }              }              break;            }            case EIO_CMD_STOP:              pEIOsg->lError = EIO_ERR_NOERROR;kprintf("EIO_CMD_STOP  received\n");              AHI_ControlAudio( context.AudioCtrl,                                AHIC_Play,   FALSE,                                AHIC_Record, FALSE,                                TAG_DONE );              context.Playing   = FALSE;              context.Recording = FALSE;              AHI_UnloadSound( 0, context.AudioCtrl );              AHI_UnloadSound( 1, context.AudioCtrl );              context.Sound0Loaded = FALSE;              context.Sound1Loaded = FALSE;              break;            case EIO_CMD_SETPARAMS:              pEIOsg->lError = EIO_ERR_NOERROR;              /* Parameters passing removed. Doesn't                 apply to generic boards and AHI as                 well */              break;            case EIO_CMD_QUIT:              pEIOsg->lError = EIO_ERR_NOERROR;              fQuit = TRUE;              break;            default:              pEIOsg->lError = EIO_ERR_UNKNOWNCMD;              break;          }kprintf( "Replying message (%ld)\n", pEIOsg->lError );          ReplyMsg((struct Message *)pEIOsg);        }      }    }  }kprintf( "Exiting... " );  if( port != NULL )  {    DeletePort( port );  }kprintf( "e1\n" );  Destruct( &context );kprintf( "e2\n" );  ShutDown();kprintf( "e3\n" );  return 0;}