[PD-cvs] pd/src s_audio_sgi.c,1.1.4.1.4.1,1.1.4.1.4.2

Mathieu Bouchard matju at users.sourceforge.net
Tue Jul 31 00:32:05 CEST 2007


Update of /cvsroot/pure-data/pd/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6969

Modified Files:
      Tag: desiredata
	s_audio_sgi.c 
Log Message:
cleanup


Index: s_audio_sgi.c
===================================================================
RCS file: /cvsroot/pure-data/pd/src/Attic/s_audio_sgi.c,v
retrieving revision 1.1.4.1.4.1
retrieving revision 1.1.4.1.4.2
diff -C2 -d -r1.1.4.1.4.1 -r1.1.4.1.4.2
*** s_audio_sgi.c	30 Jun 2007 20:30:19 -0000	1.1.4.1.4.1
--- s_audio_sgi.c	30 Jul 2007 22:32:02 -0000	1.1.4.1.4.2
***************
*** 1,5 ****
- 
  /* ----------------------- Experimental routines for SGI -------------- */
- 
  /* written by Olaf Matthes <olaf.matthes at gmx.de> */
  
--- 1,3 ----
***************
*** 26,42 ****
  static int sgi_ninchans[SGI_MAXDEV], sgi_noutchans[SGI_MAXDEV];
  
! 
!   /*
!     set the special "flush zero" but (FS, bit 24) in the
!     Control Status Register of the FPU of R4k and beyond
!     so that the result of any underflowing operation will
!     be clamped to zero, and no exception of any kind will
!     be generated on the CPU.
! 
!     thanks to cpirazzi at cp.esd.sgi.com (Chris Pirazzi).
!   */
! 
! static void sgi_flush_all_underflows_to_zero(void)
! {
      union fpc_csr f;
      f.fc_word = get_fpc_csr();
--- 24,31 ----
  static int sgi_ninchans[SGI_MAXDEV], sgi_noutchans[SGI_MAXDEV];
  
! /* set the special "flush zero" but (FS, bit 24) in the Control Status Register of the FPU of R4k and beyond
!     so that the result of any underflowing operation will be clamped to zero, and no exception of any kind will
!     be generated on the CPU. thanks to cpirazzi at cp.esd.sgi.com (Chris Pirazzi). */
! static void sgi_flush_all_underflows_to_zero () {
      union fpc_csr f;
      f.fc_word = get_fpc_csr();
***************
*** 45,275 ****
  }
  
! 
!         /* convert the most common errors into readable strings */
! static char *sgi_get_error_message(int err)
! {
!         switch (err)
!         {
!                 case AL_BAD_CONFIG:
!                         return "Invalid config";
! 
!                 case AL_BAD_DIRECTION:
!                         return "Invalid direction (neither \"r\" nor \"w\")";
! 
!                 case AL_BAD_OUT_OF_MEM:
!                         return "Not enough memory";
! 
!                 case AL_BAD_DEVICE_ACCESS:
!                         return "Audio hardware is not available or is improperly configured";
! 
!                 case AL_BAD_DEVICE:
!                         return "Invalid device";
! 
!                 case AL_BAD_NO_PORTS:
!                         return "No audio ports available";
! 
!                 case AL_BAD_QSIZE:
!                         return "Invalid fifo size";
! 
!                 case AL_BAD_SAMPFMT:
!                         return "Invalid sample format";
! 
!                 case AL_BAD_FLOATMAX:
!                         return "Invalid float maximum";
! 
!                 case AL_BAD_WIDTH:
!                         return "Invalid sample width";
! 
!                 default:
!                         return "Unknown error";
          }
  }
  
- 
  int sgi_open_audio(int nindev,  int *indev,  int nchin,  int *chin,
!     int noutdev, int *outdev, int nchout, int *chout, int rate/*, int dummy*/)
! {
      ALpv pvbuf[2];
      int num_devs = 0;
      int in_dev = 0;
      int out_dev = 0;
!         int inchans = 0;
!         int outchans = 0;
!         int err, n, gotchannels;
!         char *indevnames[4] = {"DefaultIn", "AnalogIn", "AESIn", "ADATIn"};
!         char *outdevnames[4] = {"DefaultOut", "AnalogOut", "AESOut", "ADATOut"};
! 
!         sgi_flush_all_underflows_to_zero();
! 
!         if (sys_verbose)
!                 post("opening sound input...");
! 
!     for (n = 0; n < nindev; n++)
!     {
!                 int gotchannels = 0;
! 
!                 if (indev[n] >= 0 && indev[n] < SGI_MAXDEV)     /* open specified defice by name */
!                 {
!                         if (sys_verbose)
!                                 post("opening %s", indevnames[indev[n]]);
!                         in_dev = alGetResourceByName(AL_SYSTEM, 
!                                 indevnames[indev[n]], AL_DEVICE_TYPE);
!                 }
!                 else    /* open default device */
!                 {
!                         if(sys_verbose)post("opening %s", indevnames[0]);
!                         in_dev = AL_DEFAULT_INPUT;
!                 }
!                 if (!in_dev)
!                 {
!                         error("%s\n", sgi_get_error_message(in_dev));
!                         continue;       /* try next device, if any */
!                 }
! 
!                 sgi_inconfig = alNewConfig();
!                 alSetSampFmt(sgi_inconfig, AL_SAMPFMT_FLOAT);
!                 alSetFloatMax(sgi_outconfig, 1.1f);
          alSetChannels(sgi_outconfig, chin[n]);
          alSetQueueSize(sgi_inconfig, sys_advance_samples * chin[n]);
          alSetDevice(sgi_inconfig, in_dev);
          sgi_iport[n] = alOpenPort("Pd input port", "r", sgi_inconfig);
!                 if (!sgi_iport[n])
!                     fprintf(stderr,"Pd: failed to open audio read port\n");
! 
!                    /* try to set samplerate */
!                 pvbuf[0].param = AL_RATE;
!                 pvbuf[0].value.ll = alDoubleToFixed(rate);
!                 if ((err = alSetParams(in_dev, pvbuf, 1)) < 0)
!                 {
!                     post("could not set specified sample rate for input (%s)\n",
!                                 sgi_get_error_message(err));
!                     if(pvbuf[0].sizeOut < 0)
!                                 post("rate was invalid\n");
!                 }
!                         /* check how many channels we actually got */
!                 pvbuf[0].param = AL_CHANNELS;
!                 if (alGetParams(in_dev, pvbuf, 1) < 0)
!                 {
!                         post("could not figure out how many input channels we got");
!                         gotchannels = chin[n];  /* assume we got them all */
!                 }
!                 else
!                 {
!                         gotchannels = pvbuf[0].value.i;
!                 }
!                 inchans += gotchannels; /* count total number of channels */
!                 sgi_ninchans[n] = gotchannels;  /* remember channels for this device */
          }
! 
!         if (sys_verbose)
!                 post("opening sound output...");
! 
!         for (n = 0; n < noutdev; n++)
!     {
!                 if (outdev[n] >= 0 && outdev[n] < SGI_MAXDEV)   /* open specified defice by name */
!                 {
!                         if(sys_verbose)post("opening %s", outdevnames[outdev[n]]);
!                         out_dev = alGetResourceByName(AL_SYSTEM, 
!                                 outdevnames[outdev[n]], AL_DEVICE_TYPE);
!                 }
!                 else    /* open default device */
!                 {
!                         if (sys_verbose)
!                                 post("opening %s", outdevnames[0]);
!                         out_dev = AL_DEFAULT_OUTPUT;
!                 }
!                 if (!out_dev)
!                 {
!                         error("%s\n", sgi_get_error_message(out_dev));
!                         continue;       /* try next device, if any */
!                 }
! 
!                         /* configure the port before opening it */
!                 sgi_outconfig = alNewConfig();
!                 alSetSampFmt(sgi_outconfig, AL_SAMPFMT_FLOAT);
!                 alSetFloatMax(sgi_outconfig, 1.1f);
          alSetChannels(sgi_outconfig, chout[n]);
          alSetQueueSize(sgi_outconfig, sys_advance_samples * chout[n]);
          alSetDevice(sgi_outconfig, out_dev);
! 
!                         /* open the port */
          sgi_oport[n] = alOpenPort("Pd ouput port", "w", sgi_outconfig);
!                 if (!sgi_oport[n])
!                     fprintf(stderr,"Pd: failed to open audio write port\n");
! 
!                         /* now try to set sample rate */
!                 pvbuf[0].param = AL_RATE;
!                 pvbuf[0].value.ll = alDoubleToFixed(rate);
!                 if ((err = alSetParams(out_dev, pvbuf, 1)) < 0)
!                 {
!                     post("could not set specified sample rate for output (%s)\n",
!                                 sgi_get_error_message(err));
!                     if(pvbuf[0].sizeOut < 0)
!                                 post("rate was invalid\n");
!                 }
!                         /* check how many channels we actually got */
!                 pvbuf[0].param = AL_CHANNELS;
!                 if (alGetParams(out_dev, pvbuf, 1) < 0)
!                 {
!                         post("could not figure out how many output channels we got");
!                         gotchannels = chout[n];
!                 }
!                 else
!                 {
!                         gotchannels = pvbuf[0].value.i;
!                 }
!                 outchans += gotchannels;
!                 sgi_noutchans[n] = gotchannels;
          }
! 
!         sgi_noutdevs = noutdev;
!         sgi_nindevs = nindev;
! 
!         sgi_inchannels = inchans;
!         sgi_outchannels = outchans;
! 
!     return (!(inchans || outchans));
  }
  
! 
! void sgi_close_audio(void) 
! {
      int err, n;
!         for (n = 0; n < sgi_nindevs; n++)
!         {
!         if (sgi_iport[n])
!                 {
!                         err = alClosePort(sgi_iport[n]);
!                         if (err < 0)
!                                 error("closing input %d: %s (%d)", n + 1, 
!                                                 alGetErrorString(oserror()), err);
!                 }
          }
!         for (n = 0; n < sgi_noutdevs; n++)
!         {
!         if (sgi_oport[n])
!                 {
!                         err = alClosePort(sgi_oport[n]);
!                         if (err < 0)
!                                 error("closing output %d: %s (%d)", n + 1, 
!                                                 alGetErrorString(oserror()), err);
!                 }
          }
  }
  
! 
!     /* call this only if both input and output are open */
! static void sgi_checkiosync(void)
! {
!     int i, result, checkit = 1, giveup = 1000, alreadylogged = 0;
!     long indelay, outdelay, defect;
! 
!     if (!(sgi_outchannels && sgi_inchannels))
!         return;
  }
  
! 
! int sgi_send_dacs(void)
! {
      float buf[SGI_MAXCH * sys_dacblocksize], *fp1, *fp2, *fp3, *fp4;
      static int xferno = 0;
--- 34,178 ----
  }
  
! /* convert the most common errors into readable strings */
! static char *sgi_get_error_message(int err) {
!         switch (err) {
!                 case AL_BAD_CONFIG:        return "Invalid config";
!                 case AL_BAD_DIRECTION:     return "Invalid direction (neither \"r\" nor \"w\")";
!                 case AL_BAD_OUT_OF_MEM:    return "Not enough memory";
!                 case AL_BAD_DEVICE_ACCESS: return "Audio hardware is not available or is improperly configured";
!                 case AL_BAD_DEVICE:        return "Invalid device";
!                 case AL_BAD_NO_PORTS:      return "No audio ports available";
!                 case AL_BAD_QSIZE:         return "Invalid fifo size";
!                 case AL_BAD_SAMPFMT:       return "Invalid sample format";
!                 case AL_BAD_FLOATMAX:      return "Invalid float maximum";
!                 case AL_BAD_WIDTH:         return "Invalid sample width";
!                 default:                   return "Unknown error";
          }
  }
  
  int sgi_open_audio(int nindev,  int *indev,  int nchin,  int *chin,
! int noutdev, int *outdev, int nchout, int *chout, int rate/*, int dummy*/) {
      ALpv pvbuf[2];
      int num_devs = 0;
      int in_dev = 0;
      int out_dev = 0;
!     int inchans = 0;
!     int outchans = 0;
!     int err, n, gotchannels;
!     char *indevnames[4] = {"DefaultIn", "AnalogIn", "AESIn", "ADATIn"};
!     char *outdevnames[4] = {"DefaultOut", "AnalogOut", "AESOut", "ADATOut"};
!     sgi_flush_all_underflows_to_zero();
!     if (sys_verbose) post("opening sound input...");
!     for (n = 0; n < nindev; n++) {
!         int gotchannels = 0;
!         if (indev[n] >= 0 && indev[n] < SGI_MAXDEV) {
!             if (sys_verbose) post("opening %s", indevnames[indev[n]]);
!             in_dev = alGetResourceByName(AL_SYSTEM, indevnames[indev[n]], AL_DEVICE_TYPE);
!         } else {
!             if(sys_verbose)post("opening %s", indevnames[0]);
!             in_dev = AL_DEFAULT_INPUT;
!         }
!         if (!in_dev) {
!             error("%s\n", sgi_get_error_message(in_dev));
!             continue;       /* try next device, if any */
!         }
!         sgi_inconfig = alNewConfig();
!         alSetSampFmt(sgi_inconfig, AL_SAMPFMT_FLOAT);
!         alSetFloatMax(sgi_outconfig, 1.1f);
          alSetChannels(sgi_outconfig, chin[n]);
          alSetQueueSize(sgi_inconfig, sys_advance_samples * chin[n]);
          alSetDevice(sgi_inconfig, in_dev);
          sgi_iport[n] = alOpenPort("Pd input port", "r", sgi_inconfig);
!         if (!sgi_iport[n]) fprintf(stderr,"Pd: failed to open audio read port\n");
!         /* try to set samplerate */
!         pvbuf[0].param = AL_RATE;
!         pvbuf[0].value.ll = alDoubleToFixed(rate);
!         if ((err = alSetParams(in_dev, pvbuf, 1)) < 0) {
!             post("could not set specified sample rate for input (%s)\n", sgi_get_error_message(err));
!             if(pvbuf[0].sizeOut < 0) post("rate was invalid\n");
          }
!         /* check how many channels we actually got */
!         pvbuf[0].param = AL_CHANNELS;
!         if (alGetParams(in_dev, pvbuf, 1) < 0) {
!             post("could not figure out how many input channels we got");
!             gotchannels = chin[n];  /* assume we got them all */
!         } else {
!             gotchannels = pvbuf[0].value.i;
!         }
!         inchans += gotchannels; /* count total number of channels */
!         sgi_ninchans[n] = gotchannels;  /* remember channels for this device */
!     }
!     if (sys_verbose) post("opening sound output...");
!     for (n = 0; n < noutdev; n++) {
!         if (outdev[n] >= 0 && outdev[n] < SGI_MAXDEV) {
!             if(sys_verbose)post("opening %s", outdevnames[outdev[n]]);
!             out_dev = alGetResourceByName(AL_SYSTEM, outdevnames[outdev[n]], AL_DEVICE_TYPE);
!         } else {
!             if (sys_verbose) post("opening %s", outdevnames[0]);
!             out_dev = AL_DEFAULT_OUTPUT;
!         }
!         if (!out_dev) {
!             error("%s\n", sgi_get_error_message(out_dev));
!             continue; /* try next device, if any */
!         }
!         /* configure the port before opening it */
!         sgi_outconfig = alNewConfig();
!         alSetSampFmt(sgi_outconfig, AL_SAMPFMT_FLOAT);
!         alSetFloatMax(sgi_outconfig, 1.1f);
          alSetChannels(sgi_outconfig, chout[n]);
          alSetQueueSize(sgi_outconfig, sys_advance_samples * chout[n]);
          alSetDevice(sgi_outconfig, out_dev);
!         /* open the port */
          sgi_oport[n] = alOpenPort("Pd ouput port", "w", sgi_outconfig);
!         if (!sgi_oport[n]) fprintf(stderr,"Pd: failed to open audio write port\n");
!         /* now try to set sample rate */
!         pvbuf[0].param = AL_RATE;
!         pvbuf[0].value.ll = alDoubleToFixed(rate);
!         if ((err = alSetParams(out_dev, pvbuf, 1)) < 0) {
!             post("could not set specified sample rate for output (%s)\n", sgi_get_error_message(err));
!             if(pvbuf[0].sizeOut < 0) post("rate was invalid\n");
          }
!         /* check how many channels we actually got */
!         pvbuf[0].param = AL_CHANNELS;
!         if (alGetParams(out_dev, pvbuf, 1) < 0) {
!             post("could not figure out how many output channels we got");
!             gotchannels = chout[n];
!         } else {
!             gotchannels = pvbuf[0].value.i;
!         }
!         outchans += gotchannels;
!         sgi_noutchans[n] = gotchannels;
!     }
!     sgi_noutdevs = noutdev;
!     sgi_nindevs = nindev;
!     sgi_inchannels = inchans;
!     sgi_outchannels = outchans;
!     return !(inchans || outchans);
  }
  
! void sgi_close_audio() {
      int err, n;
!     for (n = 0; n < sgi_nindevs; n++) {
!         if (sgi_iport[n]) {
!             err = alClosePort(sgi_iport[n]);
!             if (err < 0) error("closing input %d: %s (%d)", n + 1, alGetErrorString(oserror()), err);
          }
!     }
!     for (n = 0; n < sgi_noutdevs; n++) {
!         if (sgi_oport[n]) {
!             err = alClosePort(sgi_oport[n]);
!             if (err < 0) error("closing output %d: %s (%d)", n + 1, alGetErrorString(oserror()), err);
          }
+     }
  }
  
! /* call this only if both input and output are open */
! static void sgi_checkiosync() {
! //    int i, result, checkit = 1, giveup = 1000, alreadylogged = 0;
! //    long indelay, outdelay, defect;
! //    if (!(sgi_outchannels && sgi_inchannels)) return;
  }
  
! int sgi_send_dacs() {
      float buf[SGI_MAXCH * sys_dacblocksize], *fp1, *fp2, *fp3, *fp4;
      static int xferno = 0;
***************
*** 277,288 ****
      static double timenow;
      double timelast;
!     int inchannels = (sys_inchannels > sgi_inchannels ?
!         sgi_inchannels : sys_inchannels);
!     int outchannels = (sys_outchannels > sgi_outchannels ?
!             sgi_outchannels : sys_outchannels);
      long outfill[SGI_MAXDEV], infill[SGI_MAXDEV];
!         int outdevchannels, indevchannels;
      int i, n, channel;
!         int result;
      unsigned int outtransfersize = sys_dacblocksize;
      unsigned int intransfersize = sys_dacblocksize;
--- 180,189 ----
      static double timenow;
      double timelast;
!     int inchannels =   min(sys_inchannels, sgi_inchannels);
!     int outchannels = min(sys_outchannels,sgi_outchannels);
      long outfill[SGI_MAXDEV], infill[SGI_MAXDEV];
!     int outdevchannels, indevchannels;
      int i, n, channel;
!     int result;
      unsigned int outtransfersize = sys_dacblocksize;
      unsigned int intransfersize = sys_dacblocksize;





More information about the Pd-cvs mailing list