home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 3 / goldfish_volume_3.bin / files / dev / e / amigae / src / tools / async / playsamp.e < prev    next >
Text File  |  1992-09-02  |  5KB  |  153 lines

  1. /*
  2.  
  3.    PlaySamp.e               Michael Zucchi 1993
  4.  
  5.    A disk based raw sample player, written in AmigaE.
  6.  
  7.  */
  8.  
  9. MODULE  'tools/async',
  10.     'dos/dos',
  11.     'exec/io', 'exec/memory', 'exec/ports',
  12.     'devices/audio'
  13.  
  14. CONST BUFFSIZE = 5120,
  15.     BUFFCOUNT = 3
  16.  
  17. PROC main()
  18.  
  19. DEF args:PTR TO LONG,rdargs,rate,names:PTR TO LONG
  20.  
  21. args:=[0,0]
  22. IF rdargs:=ReadArgs('Name/A/M,Rate/N',args,0)
  23.  
  24.    -> is there an easier way to do this crap?
  25.     MOVE.L  args,A0
  26.     MOVE.L  4(A0),D0
  27.     BEQ.S   rate_def
  28.     MOVE.L  D0,A0
  29.     MOVE.L  (A0),D0
  30.     CMP.L   #999,D0
  31.     BLT.S   rate_def
  32.     CMP.L   #60001,D0
  33.     BLT.S   rate_ok
  34. rate_def:
  35.     MOVE.L  #10000,D0
  36. rate_ok:
  37.     MOVE.L  D0,rate
  38.  
  39.     names:=args[0];
  40.     WHILE (names[0])
  41.         play(names[]++,rate)
  42.     ENDWHILE
  43.     FreeArgs(rdargs)
  44. ENDIF
  45.  
  46. ENDPROC
  47.  
  48. PROC play(filename,rate)
  49.  
  50. DEF arequest1:PTR TO ioaudio,
  51.     arequest2:ioaudio,
  52.     reply1,reply2,
  53.     ior:PTR TO io,
  54.     ioa:PTR TO ioaudio,
  55.     mnode:PTR TO mn,
  56.     buffer1,buffer2,
  57.     file,
  58.     len,
  59.     go
  60.  
  61. WriteF('playing "\s"\n',filename)
  62.  
  63. IF file:=as_Open(filename,MODE_OLDFILE,BUFFCOUNT,BUFFSIZE)
  64.     IF buffer1:=AllocVec(BUFFSIZE,MEMF_CHIP)
  65.         IF buffer2:=AllocVec(BUFFSIZE,MEMF_CHIP)
  66.             IF reply1:=CreateMsgPort()
  67.                 IF reply2:=CreateMsgPort()
  68.                     IF arequest1:=CreateIORequest(reply1, SIZEOF ioaudio)
  69.  
  70.                         /* want to allocate and use any channel with OpenDev() */
  71.                         arequest1.data:=[1,2,4,8]:CHAR
  72.                         arequest1.length:=4;
  73.                         ior:=arequest1
  74.                         ior.command:=ADCMD_ALLOCATE
  75.                         IF (0=OpenDevice('audio.device', 0, arequest1, 0))
  76.  
  77.                             /* copy iorequest for double buffered operation */
  78.                             ior.flags:=ADIOF_PERVOL
  79.                             arequest1.volume:=64            /* volume = MAX */
  80.                             arequest1.period:=Div(3546895,rate)/* set frequency */
  81.                             arequest1.cycles:=1             /* 1 cycle only */
  82.                             ior.command:=CMD_WRITE
  83.                             CopyMem(arequest1,arequest2,SIZEOF ioaudio)
  84.                             mnode:=arequest2
  85.                             mnode.replyport:=reply2
  86.  
  87.                             /* send first two buffer's full to device */
  88.                             len:=as_Read(file,buffer1,BUFFSIZE)
  89.                             arequest1.data:=buffer1
  90.                             arequest1.length:=len
  91.                             beginio(arequest1)
  92.                             len:=as_Read(file,buffer2,BUFFSIZE)
  93.                             arequest2.data:=buffer2
  94.                             arequest2.length:=len
  95.                             beginio(arequest2)
  96.  
  97.                             /* wait on request1 first time around */
  98.                             mnode:=arequest1
  99.                             go:=1
  100.  
  101.                             /* until done, keep feeding data to device */
  102.                             WHILE (go)
  103.                                 WaitPort(mnode.replyport)
  104.                                 VOID GetMsg(mnode.replyport)
  105.                                 ioa:=mnode
  106.                                 IF ioa=arequest1
  107.                                     mnode:=arequest2
  108.                                 ELSE
  109.                                     mnode:=arequest1
  110.                                 ENDIF
  111.                                 IF ((len:=as_Read(file, ioa.data, BUFFSIZE))>0) AND (CheckSignal(SIGBREAKF_CTRL_C)=0)
  112.                                     ioa.length:=len
  113.                                     beginio(ioa)
  114.                                 ELSE
  115.                                     go:=0
  116.                                 ENDIF
  117.                             ENDWHILE
  118.  
  119.                             /* clean up */
  120.                             WaitPort(mnode.replyport)
  121.                             GetMsg(mnode.replyport)
  122.  
  123.                             CloseDevice(arequest1)
  124.                         ENDIF
  125.                         DeleteIORequest(arequest1)
  126.                     ENDIF
  127.                     DeleteMsgPort(reply2)
  128.                 ENDIF
  129.                 DeleteMsgPort(reply1)
  130.             ENDIF
  131.             FreeVec(buffer2)
  132.         ENDIF
  133.         FreeVec(buffer1)
  134.     ENDIF
  135.     as_Close(file)
  136. ENDIF
  137.  
  138. ENDPROC
  139.  
  140.  
  141. /* from amiga.lib */
  142. PROC beginio(arequest)
  143.     MOVE.L  arequest,A1
  144.     MOVE.L  A6,-(A7)
  145.     MOVE.L  $14(A1),A6
  146.     JSR -$1E(A6)
  147.     MOVE.L  (A7)+,A6
  148. ENDPROC
  149.  
  150.  
  151.  
  152.  
  153.