[PD-cvs] pd/src s_audio_alsa.c,1.5.4.5.2.2.2.10,1.5.4.5.2.2.2.11

Mathieu Bouchard matju at users.sourceforge.net
Tue Jul 31 01:48:36 CEST 2007


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

Modified Files:
      Tag: desiredata
	s_audio_alsa.c 
Log Message:
remove fprintf


Index: s_audio_alsa.c
===================================================================
RCS file: /cvsroot/pure-data/pd/src/s_audio_alsa.c,v
retrieving revision 1.5.4.5.2.2.2.10
retrieving revision 1.5.4.5.2.2.2.11
diff -C2 -d -r1.5.4.5.2.2.2.10 -r1.5.4.5.2.2.2.11
*** s_audio_alsa.c	10 Jul 2007 16:15:00 -0000	1.5.4.5.2.2.2.10
--- s_audio_alsa.c	30 Jul 2007 23:48:34 -0000	1.5.4.5.2.2.2.11
***************
*** 1,4 ****
! /* Copyright (c) 1997-2003 Guenter Geiger, Miller Puckette, Larry Troxler,
! * Winfried Ritsch, Karl MacMillan, and others.
  * For information on usage and redistribution, and for a DISCLAIMER OF ALL
  * WARRANTIES, see the file, "LICENSE.txt," in this distribution.  */
--- 1,3 ----
! /* Copyright (c) 1997-2003 Guenter Geiger, Miller Puckette, Larry Troxler, Winfried Ritsch, Karl MacMillan, and others.
  * For information on usage and redistribution, and for a DISCLAIMER OF ALL
  * WARRANTIES, see the file, "LICENSE.txt," in this distribution.  */
***************
*** 59,65 ****
  int alsa_noutdev;
  
! static void check_error(int err, const char *why) {
!     if (err < 0) fprintf(stderr, "%s: %s\n", why, snd_strerror(err));
! }
  
  static int alsaio_canmmap(t_alsa_dev *dev) {
--- 58,62 ----
  int alsa_noutdev;
  
! static void check_error(int err, const char *why) {if (err<0) error("%s: %s", why, snd_strerror(err));}
  
  static int alsaio_canmmap(t_alsa_dev *dev) {
***************
*** 77,81 ****
      } else err2 = -1;
  #if 0
!     post("err 1 %d (%s), err2 %d (%s)", err1, snd_strerror(err1), err2, snd_strerror(err2));
  #endif
      return err1<0 && err2>=0;
--- 74,78 ----
      } else err2 = -1;
  #if 0
!     error("err 1 %d (%s), err2 %d (%s)", err1, snd_strerror(err1), err2, snd_strerror(err2));
  #endif
      return err1<0 && err2>=0;
***************
*** 102,107 ****
      /* Try to set 32 bit format first */
      err = snd_pcm_hw_params_set_format(dev->a_handle, hw_params, SND_PCM_FORMAT_S32);
!     if (err < 0) {
!         /* fprintf(stderr,"PD-ALSA: 32 bit format not available - using 16\n"); */
          err = snd_pcm_hw_params_set_format(dev->a_handle, hw_params,SND_PCM_FORMAT_S16);
          check_error(err, "snd_pcm_hw_params_set_format");
--- 99,104 ----
      /* Try to set 32 bit format first */
      err = snd_pcm_hw_params_set_format(dev->a_handle, hw_params, SND_PCM_FORMAT_S32);
!     if (err<0) {
!         error("PD-ALSA: 32 bit format not available - using 16");
          err = snd_pcm_hw_params_set_format(dev->a_handle, hw_params,SND_PCM_FORMAT_S16);
          check_error(err, "snd_pcm_hw_params_set_format");
***************
*** 116,121 ****
      err = snd_pcm_hw_params_set_channels_min(dev->a_handle, hw_params, &tmp_uint);
      check_error(err, "snd_pcm_hw_params_set_channels");
!     if (tmp_uint != (unsigned)*channels)
!         post("ALSA: set input channels to %d", tmp_uint);
      *channels = tmp_uint;
      dev->a_channels = *channels;
--- 113,117 ----
      err = snd_pcm_hw_params_set_channels_min(dev->a_handle, hw_params, &tmp_uint);
      check_error(err, "snd_pcm_hw_params_set_channels");
!     if (tmp_uint != (unsigned)*channels) post("ALSA: set input channels to %d", tmp_uint);
      *channels = tmp_uint;
      dev->a_channels = *channels;
***************
*** 159,174 ****
      if (alsa_snd_buf) {
          if (alsa_snd_bufsize < bufsizeforthis) {
!             if (!(alsa_snd_buf = (char *)realloc(alsa_snd_buf, bufsizeforthis))) {
!                 post("out of memory");
!                 return 0;
!             }
              memset(alsa_snd_buf, 0, bufsizeforthis);
              alsa_snd_bufsize = bufsizeforthis;
          }
      } else {
!         if (!(alsa_snd_buf = (char *)malloc(bufsizeforthis))) {
!             post("out of memory");
!             return 0;
!         }
          memset(alsa_snd_buf, 0, bufsizeforthis);
          alsa_snd_bufsize = bufsizeforthis;
--- 155,164 ----
      if (alsa_snd_buf) {
          if (alsa_snd_bufsize < bufsizeforthis) {
!             if (!(alsa_snd_buf = (char *)realloc(alsa_snd_buf, bufsizeforthis))) {error("out of memory"); return 0;}
              memset(alsa_snd_buf, 0, bufsizeforthis);
              alsa_snd_bufsize = bufsizeforthis;
          }
      } else {
!         if (!(alsa_snd_buf = (char *)malloc(bufsizeforthis))) {error("out of memory"); return 0;}
          memset(alsa_snd_buf, 0, bufsizeforthis);
          alsa_snd_bufsize = bufsizeforthis;
***************
*** 305,309 ****
      timenow = sys_getrealtime();
  #ifdef DEBUG_ALSA_XFER
!     if (timenow - timelast > 0.050) fprintf(stderr, "(%d)", int(1000 * (timenow - timelast))), fflush(stderr);
      callno++;
  #endif
--- 295,299 ----
      timenow = sys_getrealtime();
  #ifdef DEBUG_ALSA_XFER
!     if (timenow - timelast > 0.050) post("(%d)", int(1000 * (timenow - timelast))), fflush(stderr);
      callno++;
  #endif
***************
*** 343,350 ****
          if (result != (int)transfersize) {
      #ifdef DEBUG_ALSA_XFER
!             if (result >= 0 || errno == EAGAIN)
!                 fprintf(stderr, "ALSA: write returned %d of %d\n", result, transfersize);
!             else fprintf(stderr, "ALSA: write: %s\n", snd_strerror(errno));
!             fprintf(stderr, "inputcount %d, outputcount %d, outbufsize %d\n",
                      inputcount, outputcount, (ALSA_EXTRABUFFER + sys_advance_samples) * alsa_outdev[iodev].a_sampwidth * outchannels);
      #endif
--- 333,339 ----
          if (result != (int)transfersize) {
      #ifdef DEBUG_ALSA_XFER
!             if (result >= 0 || errno == EAGAIN) post("ALSA: write returned %d of %d\n", result, transfersize);
!             else error("ALSA: write: %s", snd_strerror(errno));
!             post("inputcount %d, outputcount %d, outbufsize %d",
                      inputcount, outputcount, (ALSA_EXTRABUFFER + sys_advance_samples) * alsa_outdev[iodev].a_sampwidth * outchannels);
      #endif
***************
*** 358,362 ****
          if (sys_getrealtime() - timenow > 0.002) {
      #ifdef DEBUG_ALSA_XFER
!             fprintf(stderr, "output %d took %d msec\n", callno, int(1000 * (timenow - timelast))), fflush(stderr);
      #endif
              timenow = sys_getrealtime();
--- 347,351 ----
          if (sys_getrealtime() - timenow > 0.002) {
      #ifdef DEBUG_ALSA_XFER
!             post("output %d took %d msec", callno, int(1000 * (timenow - timelast))), fflush(stderr);
      #endif
              timenow = sys_getrealtime();
***************
*** 372,379 ****
          if (result < (int)transfersize) {
  #ifdef DEBUG_ALSA_XFER
!             if (result < 0)
!                 fprintf(stderr, "snd_pcm_read %d %d: %s\n", callno, xferno, snd_strerror(errno));
!             else fprintf(stderr, "snd_pcm_read %d %d returned only %d\n", callno, xferno, result);
!             fprintf(stderr, "inputcount %d, outputcount %d, inbufsize %d\n",
                      inputcount, outputcount, (ALSA_EXTRABUFFER + sys_advance_samples) * alsa_indev[iodev].a_sampwidth * inchannels);
  #endif
--- 361,367 ----
          if (result < (int)transfersize) {
  #ifdef DEBUG_ALSA_XFER
!             if (result<0) error("snd_pcm_read %d %d: %s", callno, xferno, snd_strerror(errno));
!             else post("snd_pcm_read %d %d returned only %d", callno, xferno, result);
!             post("inputcount %d, outputcount %d, inbufsize %d",
                      inputcount, outputcount, (ALSA_EXTRABUFFER + sys_advance_samples) * alsa_indev[iodev].a_sampwidth * inchannels);
  #endif
***************
*** 382,391 ****
          }
          if (alsa_indev[iodev].a_sampwidth == 4) {
!             for (i = 0; i < chans; i++, ch++, fp1 += sys_dacblocksize) {
                  for (j = ch, k = sys_dacblocksize, fp2 = fp1; k--; j += thisdevchans, fp2++)
                      *fp2 = (float) ((t_alsa_sample32 *)alsa_snd_buf)[j] * (1./ INT32_MAX);
              }
          } else {
!             for (i = 0; i < chans; i++, ch++, fp1 += sys_dacblocksize) {
                  for (j = ch, k = sys_dacblocksize, fp2 = fp1; k--; j += thisdevchans, fp2++)
                      *fp2 = (float) ((t_alsa_sample16 *)alsa_snd_buf)[j] * 3.051850e-05;
--- 370,379 ----
          }
          if (alsa_indev[iodev].a_sampwidth == 4) {
!             for (int i=0; i<chans; i++, ch++, fp1 += sys_dacblocksize) {
                  for (j = ch, k = sys_dacblocksize, fp2 = fp1; k--; j += thisdevchans, fp2++)
                      *fp2 = (float) ((t_alsa_sample32 *)alsa_snd_buf)[j] * (1./ INT32_MAX);
              }
          } else {
!             for (int i=0; i<chans; i++, ch++, fp1 += sys_dacblocksize) {
                  for (j = ch, k = sys_dacblocksize, fp2 = fp1; k--; j += thisdevchans, fp2++)
                      *fp2 = (float) ((t_alsa_sample16 *)alsa_snd_buf)[j] * 3.051850e-05;
***************
*** 398,402 ****
      if (sys_getrealtime() - timenow > 0.002) {
  #ifdef DEBUG_ALSA_XFER
!         fprintf(stderr, "routine took %d msec\n", int(1000 * (sys_getrealtime() - timenow)));
  #endif
          sys_log_error(ERR_ADCSLEPT);
--- 386,390 ----
      if (sys_getrealtime() - timenow > 0.002) {
  #ifdef DEBUG_ALSA_XFER
!         post("routine took %d msec", int(1000 * (sys_getrealtime() - timenow)));
  #endif
          sys_log_error(ERR_ADCSLEPT);
***************
*** 414,422 ****
      if (sys_inchannels) {
          result = snd_pcm_delay(alsa_indev[iodev].a_handle, &indelay);
!         if (result < 0) post("snd_pcm_delay 1 failed"); else post("in delay %d", indelay);
      }
      if (sys_outchannels) {
          result = snd_pcm_delay(alsa_outdev[iodev].a_handle, &outdelay);
!         if (result < 0) post("snd_pcm_delay 2 failed"); else post("out delay %d", outdelay);
      }
      post("sum %d (%d mod 64)\n", indelay + outdelay, (indelay+outdelay)%64);
--- 402,410 ----
      if (sys_inchannels) {
          result = snd_pcm_delay(alsa_indev[iodev].a_handle, &indelay);
!         if (result<0) error("snd_pcm_delay 1 failed"); else post( "in delay %d",  indelay);
      }
      if (sys_outchannels) {
          result = snd_pcm_delay(alsa_outdev[iodev].a_handle, &outdelay);
!         if (result<0) error("snd_pcm_delay 2 failed"); else post("out delay %d", outdelay);
      }
      post("sum %d (%d mod 64)\n", indelay + outdelay, (indelay+outdelay)%64);
***************
*** 465,469 ****
  /* call this only if both input and output are open */
  static void alsa_checkiosync() {
!     int result, giveup = 1000, alreadylogged = 0, iodev = 0;
      snd_pcm_sframes_t minphase, maxphase, thisphase, outdelay;
      while (1) {
--- 453,457 ----
  /* call this only if both input and output are open */
  static void alsa_checkiosync() {
!     int result, giveup = 1000, alreadylogged = 0;
      snd_pcm_sframes_t minphase, maxphase, thisphase, outdelay;
      while (1) {
***************
*** 475,487 ****
          minphase = 0x7fffffff;
          maxphase = -0x7fffffff;
!         for (iodev=0; iodev<alsa_noutdev; iodev++) {
!             result = snd_pcm_delay(alsa_outdev[iodev].a_handle, &outdelay);
              if (result < 0) {
                  snd_pcm_prepare(alsa_outdev[iodev].a_handle);
                  result = snd_pcm_delay(alsa_outdev[iodev].a_handle, &outdelay);
              }
!             if (result < 0) {
!                 post("output snd_pcm_delay failed: %s", snd_strerror(result));
!                 if (snd_pcm_status(alsa_outdev[iodev].a_handle, alsa_status) < 0) post("output snd_pcm_status failed");
                  else post("astate %d", snd_pcm_status_get_state(alsa_status));
                  return;
--- 463,475 ----
          minphase = 0x7fffffff;
          maxphase = -0x7fffffff;
!         for (int iodev=0; iodev<alsa_noutdev; iodev++) {
!             result     = snd_pcm_delay(alsa_outdev[iodev].a_handle, &outdelay);
              if (result < 0) {
                  snd_pcm_prepare(alsa_outdev[iodev].a_handle);
                  result = snd_pcm_delay(alsa_outdev[iodev].a_handle, &outdelay);
              }
!             if (result<0) {
!                 error("output snd_pcm_delay failed: %s", snd_strerror(result));
!                 if (snd_pcm_status(alsa_outdev[iodev].a_handle, alsa_status)<0) error("output snd_pcm_status failed");
                  else post("astate %d", snd_pcm_status_get_state(alsa_status));
                  return;
***************
*** 493,497 ****
                  sys_log_error(ERR_DATALATE), alreadylogged = 1;
          }
!         for (iodev=0; iodev<alsa_nindev; iodev++) {
              result =     snd_pcm_delay(alsa_indev[iodev].a_handle, &thisphase);
              if (result < 0) {
--- 481,485 ----
                  sys_log_error(ERR_DATALATE), alreadylogged = 1;
          }
!         for (int iodev=0; iodev<alsa_nindev; iodev++) {
              result =     snd_pcm_delay(alsa_indev[iodev].a_handle, &thisphase);
              if (result < 0) {
***************
*** 500,506 ****
              }
              if (result < 0) {
!                 post("output snd_pcm_delay failed: %s", snd_strerror(result));
!                 if (snd_pcm_status(alsa_outdev[iodev].a_handle, alsa_status) < 0)
!                     post("output snd_pcm_status failed");
                  else post("astate %d", snd_pcm_status_get_state(alsa_status));
                  return;
--- 488,493 ----
              }
              if (result < 0) {
!                 error("output snd_pcm_delay failed: %s", snd_strerror(result));
!                 if (snd_pcm_status(alsa_outdev[iodev].a_handle, alsa_status) < 0) error("output snd_pcm_status failed");
                  else post("astate %d", snd_pcm_status_get_state(alsa_status));
                  return;
***************
*** 509,519 ****
              if (thisphase > maxphase) maxphase = thisphase;
          }
!         /* the "correct" position is for all the phases to be exactly
!            equal; but since we only make corrections sys_dacblocksize samples
!            at a time, we just ask that the spread be not more than 3/4 of a block.  */
          if (maxphase <= minphase + (alsa_jittermax * (sys_dacblocksize / 4))) break;
!         if (!alreadylogged)
!             sys_log_error(ERR_RESYNC), alreadylogged = 1;
!         for (iodev = 0; iodev < alsa_noutdev; iodev++) {
              result = snd_pcm_delay(alsa_outdev[iodev].a_handle, &outdelay);
              if (result < 0) break;
--- 496,505 ----
              if (thisphase > maxphase) maxphase = thisphase;
          }
!         /* the "correct" position is for all the phases to be exactly equal;
!            but since we only make corrections sys_dacblocksize samples at a time,
!            we just ask that the spread be not more than 3/4 of a block.  */
          if (maxphase <= minphase + (alsa_jittermax * (sys_dacblocksize / 4))) break;
!         if (!alreadylogged) sys_log_error(ERR_RESYNC), alreadylogged = 1;
!         for (int iodev=0; iodev<alsa_noutdev; iodev++) {
              result = snd_pcm_delay(alsa_outdev[iodev].a_handle, &outdelay);
              if (result < 0) break;
***************
*** 522,530 ****
                  alsa_putzeros(iodev, 1);
  #if DEBUGSYNC
!                 fprintf(stderr, "putz %d %d\n", (int)thisphase, (int)minphase);
  #endif
              }
          }
!         for (iodev = 0; iodev < alsa_nindev; iodev++) {
              result = snd_pcm_delay(alsa_indev[iodev].a_handle, &thisphase);
              if (result < 0) break;
--- 508,516 ----
                  alsa_putzeros(iodev, 1);
  #if DEBUGSYNC
!                 post("putz %d %d", (int)thisphase, (int)minphase);
  #endif
              }
          }
!         for (int iodev=0; iodev<alsa_nindev; iodev++) {
              result = snd_pcm_delay(alsa_indev[iodev].a_handle, &thisphase);
              if (result < 0) break;
***************
*** 532,536 ****
                  alsa_getzeros(iodev, 1);
  #if DEBUGSYNC
!                 fprintf(stderr, "getz %d %d\n", (int)thisphase, (int)minphase);
  #endif
              }
--- 518,522 ----
                  alsa_getzeros(iodev, 1);
  #if DEBUGSYNC
!                 post("getz %d %d", (int)thisphase, (int)minphase);
  #endif
              }
***************
*** 538,543 ****
      }
  #if DEBUGSYNC
!     if (alreadylogged)
!         fprintf(stderr, "done\n");
  #endif
  }
--- 524,528 ----
      }
  #if DEBUGSYNC
!     if (alreadylogged) post("done");
  #endif
  }
***************
*** 576,582 ****
          if (2 * ndev + 2  > maxndev) break;
          /* apparently, "cardno" is just a counter; but check that here */
!         if (ndev != cardno) fprintf(stderr, "oops: ALSA cards not reported in order?\n");
          sprintf(devname, "hw:%d", cardno);
!         /* fprintf(stderr, "\ntry %s...\n", devname); */
          if (snd_ctl_open(&ctl, devname, 0) >= 0) {
              snd_ctl_card_info_malloc(&info);
--- 561,567 ----
          if (2 * ndev + 2  > maxndev) break;
          /* apparently, "cardno" is just a counter; but check that here */
!         if (ndev != cardno) post("oops: ALSA cards not reported in order?");
          sprintf(devname, "hw:%d", cardno);
!         /* post("try %s..", devname); */
          if (snd_ctl_open(&ctl, devname, 0) >= 0) {
              snd_ctl_card_info_malloc(&info);
***************
*** 585,589 ****
              snd_ctl_card_info_free(info);
          } else {
!             fprintf(stderr, "ALSA card scan error\n");
              desc = strdup("???");
          }
--- 570,574 ----
              snd_ctl_card_info_free(info);
          } else {
!             error("ALSA card scan error");
              desc = strdup("???");
          }





More information about the Pd-cvs mailing list