PROGRAM Audio
?
?
? Program Which Directly Accesses Amiga's Sound Library Functions And
? Audio.Device Using F-Basic's SYSLIB Interface. Plays A Sine Wave With A
? Variable Number Of Points A Variable Number Of Times.
? Example Input : 1000,150,20
?
?
APPEND  finclude/AmigaExecSubs
INCLUDE finclude/AmigaExecTypes
INCLUDE finclude/AmigaAudioTypes
GLOBAL
   PTR_TO Library ExecBase
LOCAL
   INTEGER I,J,K,L,HOLD,MemArray
   BYTE    sunit,i
   WORD    error,cycles,period,length
   IOAudio sound
   PTR_TO MsgPort port
   DATA (sunit,15),(port,0),(ExecBase,0),(error,0)
SUBPROGRAM
   INCLUDE finclude/AmigaSubNames

&SYSLIB 1
PRINT "Input Number of Wave Cycles To Play, Period ( >120 ), # Of Pts In Wave"
INPUT "Enter cycles,period,length" cycles,period,length
MemArray=ALLOCATE_WITH(270,MEMF_CLEAR OR MEMF_CHIP)
IF NOT MemArray THEN
   PRINT "Unable To Get Memory For Array"
   GOTO Enda
ENDIF
ExecBase=#4
port=CreatePort(0,0)
IF port=NIL THEN
   PRINT "Unable To Create Port"
   GOTO End1
ENDIF
sound.ioa_Request.io_Message.mn_ReplyPort=port
sound.ioa_Request.io_Message.mn_Node.ln_Pri=10
sound.ioa_Data=@sunit
sound.ioa_Length=SIZEOF(sunit)
error=OpenDevice(ExecBase,@"audio.device",0,@sound,0)
IF error THEN
   PRINT "Unable To Open Audio Device"
   GOTO End2
ENDIF

HOLD=MemArray
FOR I=1 TO length

   ? NOTE: PI Is An F-Basic System CONSTANT-Value Is 3.1415925 (Of Course)

   i=INT(127*SIN(I*2*PI/length))
   ^HOLD=i
   INC(HOLD)
NEXT I

sound.ioa_Request.io_Command=CMD_WRITE
sound.ioa_Request.io_Flags=ADIOF_PERVOL OR IOF_QUICK

sound.ioa_Data=MemArray
sound.ioa_Cycles=cycles
sound.ioa_Length=length
sound.ioa_Period=period
sound.ioa_Volume=64
SAVE_A_REG
   :A1=@sound
   :A6=sound.ioa_Request.io_Device
   ? JSR BeginIO(A6)
   INSERT "4EAEFFE2"
RESTORE_A_REG
WaitIO(ExecBase,@sound)

CloseDevice(ExecBase,@sound)

{End2}
IF sound.ioa_Request.io_Message.mn_ReplyPort THEN DeletePort(sound.ioa_Request.io_Message.mn_ReplyPort)
{End1}
IF MemArray THEN I=DEALLOCATE(270,MemArray)
{Enda}
END
