home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / cdrom / cd32goodies / cdaudio.c < prev    next >
C/C++ Source or Header  |  1977-12-31  |  3KB  |  132 lines

  1. /*
  2.     nothing changed between the uploads, just included for completeness.
  3.     use this crap if you like; i actually prefer the builtin one of the
  4.     CD32...
  5. */
  6.  
  7. #include <exec/exec.h>
  8. #include <dos/dos.h>
  9. #include <devices/cd.h>
  10. #include <proto/exec.h>
  11. #include <proto/dos.h>
  12.  
  13. #define TEMPLATE "PAUSE/S,PLAY/S,TRACK/N/K,LENGTH/N/K,FADE/N/K,VOLUME/N/K,MOTOR/N/K,SEARCH/N/K"
  14.  
  15. /*
  16.     PAUSE    -> drive is in PAUSE mode (laser beam locks)
  17.     
  18.     PLAY    -> drive is in PLAY mode (laser beam unlocks)
  19.  
  20.     TRACK    -> track to play. default is first track
  21.     
  22.     LENGTH    -> how many tracks to play. default is 1000 tracks (only used in conjunction with TRACK)
  23.     
  24.     FADE    -> duration of volume fade. default is 0 (only used in conjunction with VOLUME)
  25.     
  26.     VOLUME    -> volume from 0..16383. default is maximum volume. <2048 == mute audio
  27.     
  28.     MOTOR    -> 0 to stop drive motor, 1 to restart drive motor.
  29.     
  30.     SEARCH    -> play mode: 0 is normal mode (default), 1 is fast forward and 2 is fast reverse mode
  31.  
  32. */
  33.  
  34. struct {
  35.     ULONG    pause,play,track,length,fade,volume,motor,search;
  36.     BOOL    quiet;
  37.     ULONG    pads[7];
  38. } args = {0};
  39.  
  40. void pause (struct IOStdReq *ior, int pausemode)
  41. {
  42.     ior->io_Command    = CD_PAUSE;
  43.     ior->io_Data    = NULL;
  44.     ior->io_Length    = pausemode;
  45.     ior->io_Offset    = 0;
  46.     DoIO(ior);
  47. }
  48.  
  49. void motor (struct IOStdReq *ior, int state)
  50. {
  51.     ior->io_Command    = CD_MOTOR;
  52.     ior->io_Data    = NULL;
  53.     ior->io_Length    = state;
  54.     ior->io_Offset    = 0;
  55.     DoIO(ior);
  56. }
  57.  
  58. void playtrack (struct IOStdReq *ior, int numtracks, int firsttrack)
  59. {
  60.     ior->io_Command    = CD_PLAYTRACK;
  61.     ior->io_Data    = NULL;
  62.     ior->io_Length    = numtracks;
  63.     ior->io_Offset    = firsttrack;
  64.     SendIO(ior);
  65. }
  66.  
  67. void playmode (struct IOStdReq *ior, int playmode)
  68. {
  69.     ior->io_Command    = CD_SEARCH;
  70.     ior->io_Data    = NULL;
  71.     ior->io_Length    = playmode;
  72.     ior->io_Offset    = 0;
  73.     DoIO(ior);
  74. }
  75.  
  76. void attenuate (struct IOStdReq *ior, int duration, int volume)
  77. {
  78.     ior->io_Command    = CD_ATTENUATE;
  79.     ior->io_Data    = NULL;
  80.     ior->io_Length    = duration;
  81.     ior->io_Offset    = volume;
  82.     DoIO(ior);
  83. }
  84.  
  85. int main (void)
  86. {
  87.     struct RDArgs *rdargs;
  88.     struct MsgPort *mp;
  89.     struct IOStdReq *ior;
  90.     int length=1, fade=0;
  91.     
  92.     if (rdargs=ReadArgs(TEMPLATE,(LONG*)&(args),NULL))
  93.     {
  94.         if(!args.quiet) PutStr("*** CD Audio v1.0.0 *** by Daniel Balster\n");
  95.  
  96.         if(mp=CreateMsgPort())
  97.         {
  98.             if(ior=(struct IOStdReq*)CreateIORequest(mp,sizeof(struct IOStdReq)))
  99.             {
  100.                 if(!OpenDevice("cd.device",0,ior,0))
  101.                 {
  102.                     if (args.pause)    pause(ior,1);
  103.                     if (args.play)    pause(ior,0);
  104.                     
  105.                     if (args.length) length = *(ULONG*)args.length;
  106.                     if (args.track) playtrack(ior,length,*(ULONG*)args.track);
  107.             
  108.                     if (args.fade) fade = *(ULONG*)args.fade;
  109.                     if (args.volume) attenuate(ior,fade,*(ULONG*)args.volume);
  110.  
  111.                     if (args.motor) motor(ior,*(ULONG*)args.motor);
  112.  
  113.                     if (args.search) playmode(ior,*(ULONG*)args.search);
  114.  
  115.                     CloseDevice((struct IORequest*)ior);
  116.                 }
  117.                 else PutStr("cannot access cd.device?\n");
  118.                 
  119.                 DeleteIORequest((struct IORequest*)ior);
  120.             }
  121.             else PutStr("cannot create ioreq?\n");
  122.  
  123.             DeleteMsgPort(mp);
  124.         }
  125.         else PutStr("cannot create msgport?\n");
  126.  
  127.         FreeArgs(rdargs);
  128.     }
  129.     else PrintFault(IoErr(),0);
  130.  
  131.     return RETURN_OK;
  132. }