[PD-cvs] pd/src s_audio_alsa.c, 1.5.4.5.2.2.2.8, 1.5.4.5.2.2.2.9 s_audio_jack.c, 1.5.4.8.2.7.2.6, 1.5.4.8.2.7.2.7 s_audio_oss.c, 1.6.4.2.2.2.2.4, 1.6.4.2.2.2.2.5 s_audio_portaudio.c, 1.1.2.21.2.4, 1.1.2.21.2.5

Mathieu Bouchard matju at users.sourceforge.net
Mon Jul 9 21:59:44 CEST 2007


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

Modified Files:
      Tag: desiredata
	s_audio_alsa.c s_audio_jack.c s_audio_oss.c 
	s_audio_portaudio.c 
Log Message:
cleanup


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.8
retrieving revision 1.5.4.5.2.2.2.9
diff -C2 -d -r1.5.4.5.2.2.2.8 -r1.5.4.5.2.2.2.9
*** s_audio_alsa.c	9 Jul 2007 18:16:13 -0000	1.5.4.5.2.2.2.8
--- s_audio_alsa.c	9 Jul 2007 19:59:42 -0000	1.5.4.5.2.2.2.9
***************
*** 71,84 ****
        return 0;
      }
!     err1 = snd_pcm_hw_params_set_access(dev->a_handle,
!         hw_params, SND_PCM_ACCESS_RW_INTERLEAVED);
      if (err1 < 0) {
!         err2 = snd_pcm_hw_params_set_access(dev->a_handle,
!             hw_params, SND_PCM_ACCESS_MMAP_NONINTERLEAVED);
!     }
!     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;
--- 71,80 ----
        return 0;
      }
!     err1 =     snd_pcm_hw_params_set_access(dev->a_handle, hw_params, SND_PCM_ACCESS_RW_INTERLEAVED);
      if (err1 < 0) {
!         err2 = snd_pcm_hw_params_set_access(dev->a_handle, hw_params, SND_PCM_ACCESS_MMAP_NONINTERLEAVED);
!     } 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;
***************
*** 92,96 ****
      if (sys_verbose) {
  	if (out) post("configuring sound output...");
!         else post("configuring sound input...");
      }
      /* set hardware parameters... */
--- 88,92 ----
      if (sys_verbose) {
  	if (out) post("configuring sound output...");
!         else     post("configuring sound input...");
      }
      /* set hardware parameters... */
***************
*** 113,118 ****
      if (sys_verbose) post("Sample width set to %d bytes", dev->a_sampwidth);
      /* set the subformat */
!     err = snd_pcm_hw_params_set_subformat(dev->a_handle,
!         hw_params, SND_PCM_SUBFORMAT_STD);
      check_error(err, "snd_pcm_hw_params_set_subformat");
      /* set the number of channels */
--- 109,113 ----
      if (sys_verbose) post("Sample width set to %d bytes", dev->a_sampwidth);
      /* set the subformat */
!     err = snd_pcm_hw_params_set_subformat(dev->a_handle, hw_params, SND_PCM_SUBFORMAT_STD);
      check_error(err, "snd_pcm_hw_params_set_subformat");
      /* set the number of channels */
***************
*** 125,130 ****
      dev->a_channels = *channels;
      /* set the sampling rate */
!     err = snd_pcm_hw_params_set_rate_min(dev->a_handle, hw_params, 
!     	(unsigned int *)rate, 0);
      check_error(err, "snd_pcm_hw_params_set_rate_min (input)");
  #if 0
--- 120,124 ----
      dev->a_channels = *channels;
      /* set the sampling rate */
!     err = snd_pcm_hw_params_set_rate_min(dev->a_handle, hw_params, (unsigned int *)rate, 0);
      check_error(err, "snd_pcm_hw_params_set_rate_min (input)");
  #if 0
***************
*** 136,145 ****
         right now, it trips an assertion failure in ALSA lib */
  #ifdef ALSAAPI9
!     err = snd_pcm_hw_params_set_period_size_near(dev->a_handle,
!         hw_params, (snd_pcm_uframes_t)frag_size, 0);
  #else
      tmp_snd_pcm_uframes = frag_size;
!     err = snd_pcm_hw_params_set_period_size_near(dev->a_handle,
!         hw_params, &tmp_snd_pcm_uframes, 0);
  #endif
      check_error(err, "snd_pcm_hw_params_set_period_size_near (input)");
--- 130,137 ----
         right now, it trips an assertion failure in ALSA lib */
  #ifdef ALSAAPI9
!     err = snd_pcm_hw_params_set_period_size_near(dev->a_handle, hw_params, (snd_pcm_uframes_t)frag_size, 0);
  #else
      tmp_snd_pcm_uframes = frag_size;
!     err = snd_pcm_hw_params_set_period_size_near(dev->a_handle, hw_params, &tmp_snd_pcm_uframes, 0);
  #endif
      check_error(err, "snd_pcm_hw_params_set_period_size_near (input)");
***************
*** 203,208 ****
      for (iodev = 0; iodev < naudioindev; iodev++) {
          alsa_numbertoname(audioindev[iodev], devname, 512);
!         err = snd_pcm_open(&alsa_indev[alsa_nindev].a_handle, devname,
!             SND_PCM_STREAM_CAPTURE, SND_PCM_NONBLOCK);
          check_error(err, "snd_pcm_open (input)");
          if (err < 0)
--- 195,199 ----
      for (iodev = 0; iodev < naudioindev; iodev++) {
          alsa_numbertoname(audioindev[iodev], devname, 512);
!         err = snd_pcm_open(&alsa_indev[alsa_nindev].a_handle, devname, SND_PCM_STREAM_CAPTURE, SND_PCM_NONBLOCK);
          check_error(err, "snd_pcm_open (input)");
          if (err < 0)
***************
*** 216,221 ****
      for (iodev = 0; iodev < naudiooutdev; iodev++) {
          alsa_numbertoname(audiooutdev[iodev], devname, 512);
!         err = snd_pcm_open(&alsa_outdev[alsa_noutdev].a_handle, devname,
!             SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK);
          check_error(err, "snd_pcm_open (output)");
          if (err < 0)
--- 207,211 ----
      for (iodev = 0; iodev < naudiooutdev; iodev++) {
          alsa_numbertoname(audiooutdev[iodev], devname, 512);
!         err = snd_pcm_open(&alsa_outdev[alsa_noutdev].a_handle, devname, SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK);
          check_error(err, "snd_pcm_open (output)");
          if (err < 0)
***************
*** 230,257 ****
         Wini's code in s_audio_alsamm.c */
      alsa_usemmap = 1;
!     for (iodev = 0; iodev < alsa_nindev; iodev++)
!         if (!alsaio_canmmap(&alsa_indev[iodev]))
!             alsa_usemmap = 0;
!     for (iodev = 0; iodev < alsa_noutdev; iodev++)
!         if (!alsaio_canmmap(&alsa_outdev[iodev]))
!             alsa_usemmap = 0;
      if (alsa_usemmap) {
          post("using mmap audio interface");
!         if (alsamm_open_audio(rate))
!             goto blewit;
!         else return 0;
      }
      for (iodev = 0; iodev < alsa_nindev; iodev++) {
          int channels = chindev[iodev];
!         if (alsaio_setup(&alsa_indev[iodev], 0, &channels, &rate,
!             nfrags, frag_size) < 0)
!                 goto blewit;
          inchans += channels;
      }
      for (iodev = 0; iodev < alsa_noutdev; iodev++) {
          int channels = choutdev[iodev];
!         if (alsaio_setup(&alsa_outdev[iodev], 1, &channels, &rate,
!             nfrags, frag_size) < 0)
!                 goto blewit;
          outchans += channels;
      }
--- 220,237 ----
         Wini's code in s_audio_alsamm.c */
      alsa_usemmap = 1;
!     for (iodev = 0; iodev < alsa_nindev ; iodev++) if (!alsaio_canmmap(&alsa_indev [iodev])) alsa_usemmap = 0;
!     for (iodev = 0; iodev < alsa_noutdev; iodev++) if (!alsaio_canmmap(&alsa_outdev[iodev])) alsa_usemmap = 0;
      if (alsa_usemmap) {
          post("using mmap audio interface");
!         if (alsamm_open_audio(rate)) goto blewit; else return 0;
      }
      for (iodev = 0; iodev < alsa_nindev; iodev++) {
          int channels = chindev[iodev];
!         if (alsaio_setup(&alsa_indev[iodev], 0, &channels, &rate, nfrags, frag_size) < 0) goto blewit;
          inchans += channels;
      }
      for (iodev = 0; iodev < alsa_noutdev; iodev++) {
          int channels = choutdev[iodev];
!         if (alsaio_setup(&alsa_outdev[iodev], 1, &channels, &rate, nfrags, frag_size) < 0) goto blewit;
          outchans += channels;
      }
***************
*** 284,289 ****
          while (i--) {
              for (iodev = 0; iodev < alsa_noutdev; iodev++)
!                 snd_pcm_writei(alsa_outdev[iodev].a_handle, alsa_snd_buf,
!                     sys_dacblocksize);
          }
      } else if (inchans) {
--- 264,268 ----
          while (i--) {
              for (iodev = 0; iodev < alsa_noutdev; iodev++)
!                 snd_pcm_writei(alsa_outdev[iodev].a_handle, alsa_snd_buf, sys_dacblocksize);
          }
      } else if (inchans) {
***************
*** 325,349 ****
      double timelast;
      t_sample *fp1, *fp2;
!     int i, j, k, iodev, result, ch; 
      int chansintogo, chansouttogo;
      unsigned int transfersize;
  
!     if (alsa_usemmap)
!         return alsamm_send_dacs();
! 
!     if (!alsa_nindev && !alsa_noutdev)
!         return SENDDACS_NO;
! 
      chansintogo = sys_inchannels;
      chansouttogo = sys_outchannels;
      transfersize = sys_dacblocksize;
- 
      timelast = timenow;
      timenow = sys_getrealtime();
  
  #ifdef DEBUG_ALSA_XFER
!     if (timenow - timelast > 0.050)
!         fprintf(stderr, "(%d)",
!             (int)(1000 * (timenow - timelast))), fflush(stderr);
      callno++;
  #endif
--- 304,321 ----
      double timelast;
      t_sample *fp1, *fp2;
!     int i, j, k, iodev, result, ch;
      int chansintogo, chansouttogo;
      unsigned int transfersize;
  
!     if (alsa_usemmap) return alsamm_send_dacs();
!     if (!alsa_nindev && !alsa_noutdev) return SENDDACS_NO;
      chansintogo = sys_inchannels;
      chansouttogo = sys_outchannels;
      transfersize = sys_dacblocksize;
      timelast = timenow;
      timenow = sys_getrealtime();
  
  #ifdef DEBUG_ALSA_XFER
!     if (timenow - timelast > 0.050) fprintf(stderr, "(%d)", int(1000 * (timenow - timelast))), fflush(stderr);
      callno++;
  #endif
***************
*** 374,378 ****
                  float s1 = *fp2 * INT32_MAX;
                  ((t_alsa_sample32 *)alsa_snd_buf)[j] = CLIP32(int(s1));
!             } 
              for (; i < thisdevchans; i++, ch++)
                  for (j = ch, k = sys_dacblocksize; k--; j += thisdevchans)
--- 346,350 ----
                  float s1 = *fp2 * INT32_MAX;
                  ((t_alsa_sample32 *)alsa_snd_buf)[j] = CLIP32(int(s1));
!             }
              for (; i < thisdevchans; i++, ch++)
                  for (j = ch, k = sys_dacblocksize; k--; j += thisdevchans)
***************
*** 383,390 ****
                       j += thisdevchans, fp2++) {
                  int s = int(*fp2 * 32767.);
!                 if (s > 32767)
!                     s = 32767;
!                 else if (s < -32767)
!                     s = -32767;
                  ((t_alsa_sample16 *)alsa_snd_buf)[j] = s;
              }
--- 355,359 ----
                       j += thisdevchans, fp2++) {
                  int s = int(*fp2 * 32767.);
!                 if (s > 32767) s = 32767; else if (s < -32767) s = -32767;
                  ((t_alsa_sample16 *)alsa_snd_buf)[j] = s;
              }
***************
*** 393,411 ****
                      ((t_alsa_sample16 *)alsa_snd_buf)[j] = 0;
          }
!         result = snd_pcm_writei(alsa_outdev[iodev].a_handle, alsa_snd_buf,
!             transfersize);
  
          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
              sys_log_error(ERR_DACSLEPT);
--- 362,374 ----
                      ((t_alsa_sample16 *)alsa_snd_buf)[j] = 0;
          }
!         result = snd_pcm_writei(alsa_outdev[iodev].a_handle, alsa_snd_buf, transfersize);
  
          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
              sys_log_error(ERR_DACSLEPT);
***************
*** 418,423 ****
          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();
--- 381,385 ----
          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();
***************
*** 431,450 ****
          int chans = (chansintogo < thisdevchans ? chansintogo : thisdevchans);
          chansouttogo -= chans;
!         result = snd_pcm_readi(alsa_indev[iodev].a_handle, alsa_snd_buf,
!             transfersize);
          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
              sys_log_error(ERR_ADCSLEPT);
--- 393,404 ----
          int chans = (chansintogo < thisdevchans ? chansintogo : thisdevchans);
          chansouttogo -= chans;
!         result = snd_pcm_readi(alsa_indev[iodev].a_handle, alsa_snd_buf, transfersize);
          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
              sys_log_error(ERR_ADCSLEPT);
***************
*** 453,467 ****
          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;
              }
          }
--- 407,417 ----
          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;
              }
          }
***************
*** 472,477 ****
      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);
--- 422,426 ----
      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);
***************
*** 489,504 ****
      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);
- 
      post("buf samples %d", alsa_buf_samps);
  }
--- 438,448 ----
      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);
      post("buf samples %d", alsa_buf_samps);
  }
***************
*** 511,522 ****
          return;
      }
!     memset(alsa_snd_buf, 0,
!         alsa_indev[iodev].a_sampwidth *
!             sys_dacblocksize * sys_outchannels);
      for (i = 0; i < 1000000; i++) {
!         result = snd_pcm_writei(alsa_outdev[iodev].a_handle, alsa_snd_buf,
!             sys_dacblocksize);
!         if (result != (int)sys_dacblocksize)
!             break;
      }
      post("%d written", i);
--- 455,462 ----
          return;
      }
!     memset(alsa_snd_buf, 0, alsa_indev[iodev].a_sampwidth * sys_dacblocksize * sys_outchannels);
      for (i = 0; i < 1000000; i++) {
!         result = snd_pcm_writei(alsa_outdev[iodev].a_handle, alsa_snd_buf, sys_dacblocksize);
!         if (result != (int)sys_dacblocksize) break;
      }
      post("%d written", i);
***************
*** 538,543 ****
      int i, result;
      for (i = 0; i < n; i++) {
!         result = snd_pcm_readi(alsa_indev[iodev].a_handle, alsa_snd_buf,
!             sys_dacblocksize);
  #if 0
          if (result != sys_dacblocksize)
--- 478,482 ----
      int i, result;
      for (i = 0; i < n; i++) {
!         result = snd_pcm_readi(alsa_indev[iodev].a_handle, alsa_snd_buf, sys_dacblocksize);
  #if 0
          if (result != sys_dacblocksize)
***************
*** 548,552 ****
  }
  
!     /* call this only if both input and output are open */
  static void alsa_checkiosync() {
      int result, giveup = 1000, alreadylogged = 0, iodev = 0;
--- 487,491 ----
  }
  
! /* call this only if both input and output are open */
  static void alsa_checkiosync() {
      int result, giveup = 1000, alreadylogged = 0, iodev = 0;
***************
*** 568,573 ****
              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;
--- 507,511 ----
              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;
***************
*** 580,584 ****
          }
          for (iodev=0; iodev<alsa_nindev; iodev++) {
!             result = snd_pcm_delay(alsa_indev[iodev].a_handle, &thisphase);
              if (result < 0) {
                  snd_pcm_prepare(alsa_indev[iodev].a_handle);
--- 518,522 ----
          }
          for (iodev=0; iodev<alsa_nindev; iodev++) {
!             result =     snd_pcm_delay(alsa_indev[iodev].a_handle, &thisphase);
              if (result < 0) {
                  snd_pcm_prepare(alsa_indev[iodev].a_handle);
***************
*** 587,595 ****
              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;
              }
--- 525,531 ----
              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;
              }
***************
*** 597,606 ****
              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)
--- 533,540 ----
              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)
***************
*** 608,613 ****
          for (iodev = 0; iodev < alsa_noutdev; iodev++) {
              result = snd_pcm_delay(alsa_outdev[iodev].a_handle, &outdelay);
!             if (result < 0)
!                 break;
              thisphase = alsa_buf_samps - outdelay;
              if (thisphase > minphase + sys_dacblocksize) {
--- 542,546 ----
          for (iodev = 0; iodev < alsa_noutdev; iodev++) {
              result = snd_pcm_delay(alsa_outdev[iodev].a_handle, &outdelay);
!             if (result < 0) break;
              thisphase = alsa_buf_samps - outdelay;
              if (thisphase > minphase + sys_dacblocksize) {
***************
*** 620,625 ****
          for (iodev = 0; iodev < alsa_nindev; iodev++) {
              result = snd_pcm_delay(alsa_indev[iodev].a_handle, &thisphase);
!             if (result < 0)
!                 break;
              if (thisphase > minphase + sys_dacblocksize) {
                  alsa_getzeros(iodev, 1);
--- 553,557 ----
          for (iodev = 0; iodev < alsa_nindev; iodev++) {
              result = snd_pcm_delay(alsa_indev[iodev].a_handle, &thisphase);
!             if (result < 0) break;
              if (thisphase > minphase + sys_dacblocksize) {
                  alsa_getzeros(iodev, 1);
***************
*** 636,647 ****
  }
  
! static int alsa_nnames = 0;
  static char **alsa_names = 0;
  
  void alsa_adddev(char *name) {
!     if (alsa_nnames)
!         alsa_names = (char **)t_resizebytes(alsa_names,
!             alsa_nnames * sizeof(char *),
!             (alsa_nnames+1) * sizeof(char *));
      else alsa_names = (char **)t_getbytes(sizeof(char *));
      alsa_names[alsa_nnames] = gensym(name)->s_name;
--- 568,576 ----
  }
  
! static int   alsa_nnames = 0;
  static char **alsa_names = 0;
  
  void alsa_adddev(char *name) {
!     if (alsa_nnames) alsa_names = (char **)t_resizebytes(alsa_names, alsa_nnames*sizeof(char *), (alsa_nnames+1)*sizeof(char *));
      else alsa_names = (char **)t_getbytes(sizeof(char *));
      alsa_names[alsa_nnames] = gensym(name)->s_name;
***************
*** 654,671 ****
          ndev++;
      if (devno < 2*ndev) {
!         if (devno & 1)
!             snprintf(devname, nchar, "plughw:%d", devno/2);
          else snprintf(devname, nchar, "hw:%d", devno/2);
!     }
!     else if (devno <2*ndev + alsa_nnames)
          snprintf(devname, nchar, "%s", alsa_names[devno - 2*ndev]);
      else snprintf(devname, nchar, "???");
  }
  
!     /* For each hardware card found, we list two devices, the "hard" and
!     "plug" one.  The card scan is derived from portaudio code. */
! void alsa_getdevs(char *indevlist, int *nindevs,
!     char *outdevlist, int *noutdevs, int *canmulti,
!         int maxndev, int devdescsize) {
      int ndev = 0, cardno = -1, i, j;
      *canmulti = 2;  /* supports multiple devices */
--- 583,596 ----
          ndev++;
      if (devno < 2*ndev) {
!         if (devno & 1) snprintf(devname, nchar, "plughw:%d", devno/2);
          else snprintf(devname, nchar, "hw:%d", devno/2);
!     } else if (devno <2*ndev + alsa_nnames)
          snprintf(devname, nchar, "%s", alsa_names[devno - 2*ndev]);
      else snprintf(devname, nchar, "???");
  }
  
! /* For each hardware card found, we list two devices, the "hard" and
!    "plug" one.  The card scan is derived from portaudio code. */
! void alsa_getdevs(char *indevlist, int *nindevs, char *outdevlist, int *noutdevs, int *canmulti, int maxndev, int devdescsize) {
      int ndev = 0, cardno = -1, i, j;
      *canmulti = 2;  /* supports multiple devices */

Index: s_audio_oss.c
===================================================================
RCS file: /cvsroot/pure-data/pd/src/s_audio_oss.c,v
retrieving revision 1.6.4.2.2.2.2.4
retrieving revision 1.6.4.2.2.2.2.5
diff -C2 -d -r1.6.4.2.2.2.2.4 -r1.6.4.2.2.2.2.5
*** s_audio_oss.c	9 Jul 2007 17:51:14 -0000	1.6.4.2.2.2.2.4
--- s_audio_oss.c	9 Jul 2007 19:59:42 -0000	1.6.4.2.2.2.2.5
***************
*** 8,12 ****
  #include <linux/soundcard.h>
  
! #include "m_pd.h"
  #include "s_stuff.h"
  #include <errno.h>
--- 8,13 ----
  #include <linux/soundcard.h>
  
! #define PD_PLUSPLUS_FACE
! #include "desire.h"
  #include "s_stuff.h"
  #include <errno.h>
***************
*** 81,100 ****
      cache the results, which in effect are the number of available
      devices.  */
! void oss_init(void) {
!     int fd, i;
      static int countedthem = 0;
      if (countedthem) return;
!     for (i = 0; i < 10; i++) {
          char devname[100];
          if (i == 0) strcpy(devname, "/dev/dsp"); else sprintf(devname, "/dev/dsp%d", i);
!         if ((fd = open(devname, O_WRONLY|O_NONBLOCK)) != -1) {
!             oss_ndev++;
!             close(fd);
!         } else break;
      }
      countedthem = 1;
  }
  
! void oss_set32bit(void) {oss_32bit=1;}
  
  typedef struct _multidev {
--- 82,100 ----
      cache the results, which in effect are the number of available
      devices.  */
! void oss_init() {
      static int countedthem = 0;
      if (countedthem) return;
!     for (int i=0; i<10; i++) {
          char devname[100];
          if (i == 0) strcpy(devname, "/dev/dsp"); else sprintf(devname, "/dev/dsp%d", i);
!         int fd = open(devname, O_WRONLY|O_NONBLOCK);
!         if (fd<0) break;
!         oss_ndev++;
!         close(fd);
      }
      countedthem = 1;
  }
  
! void oss_set32bit() {oss_32bit=1;}
  
  typedef struct _multidev {
***************
*** 155,160 ****
          if (!linux_fragsize) {
              linux_fragsize = OSS_DEFFRAGSIZE;
!             while (linux_fragsize > sys_dacblocksize
!                 && linux_fragsize * 6 > sys_advance_samples)
                      linux_fragsize = linux_fragsize/2;
          }
--- 155,159 ----
          if (!linux_fragsize) {
              linux_fragsize = OSS_DEFFRAGSIZE;
!             while (linux_fragsize > sys_dacblocksize && linux_fragsize * 6 > sys_advance_samples)
                      linux_fragsize = linux_fragsize/2;
          }
***************
*** 196,201 ****
          if (defect > 0) {
              if (sys_verbose || defect > (dev->d_bufsize >> 2))
!                 fprintf(stderr,
!                     "OSS: requested audio buffer size %d limited to %d\n",
                          sys_advance_samples * (dev->d_bytespersamp * nchannels), dev->d_bufsize);
              sys_advance_samples = (dev->d_bufsize-OSS_XFERSAMPS(nchannels)) / (dev->d_bytespersamp*nchannels);
--- 195,199 ----
          if (defect > 0) {
              if (sys_verbose || defect > (dev->d_bufsize >> 2))
!                 fprintf(stderr, "OSS: requested audio buffer size %d limited to %d\n",
                          sys_advance_samples * (dev->d_bytespersamp * nchannels), dev->d_bufsize);
              sys_advance_samples = (dev->d_bufsize-OSS_XFERSAMPS(nchannels)) / (dev->d_bytespersamp*nchannels);
***************
*** 230,258 ****
  
      linux_nindevs = linux_noutdevs = 0;
!         /* mark devices unopened */
!     for (i = 0; i < OSS_MAXDEV; i++)
!         linux_adcs[i].d_fd = linux_dacs[i].d_fd = -1;
  
      /* open output devices */
      wantmore=0;
!     if (noutdev < 0 || nindev < 0)
!         bug("linux_open_audio");
! 
!     for (n = 0; n < noutdev; n++) {
          int gotchans, j, inindex = -1;
          int thisdevice = (outdev[n] >= 0 ? outdev[n] : 0);
          int wantchannels = (nchout>n) ? chout[n] : wantmore;
          fd = -1;
!         if (!wantchannels)
!             goto end_out_loop;
! 
          if (thisdevice > 0) sprintf(devname, "/dev/dsp%d", thisdevice); else sprintf(devname, "/dev/dsp");
              /* search for input request for same device.  Succeed only
              if the number of channels matches. */
          for (j = 0; j < nindev; j++)
!             if (indev[j] == thisdevice && chin[j] == wantchannels)
!                 inindex = j;
!             /* if the same device is requested for input and output,
!             try to open it read/write */
          if (inindex >= 0) {
              sys_setalarm(1000000);
--- 228,249 ----
  
      linux_nindevs = linux_noutdevs = 0;
!     /* mark devices unopened */
!     for (int i=0; i<OSS_MAXDEV; i++) linux_adcs[i].d_fd = linux_dacs[i].d_fd = -1;
  
      /* open output devices */
      wantmore=0;
!     if (noutdev < 0 || nindev < 0) bug("linux_open_audio");
!     for (int n=0; n<noutdev; n++) {
          int gotchans, j, inindex = -1;
          int thisdevice = (outdev[n] >= 0 ? outdev[n] : 0);
          int wantchannels = (nchout>n) ? chout[n] : wantmore;
          fd = -1;
!         if (!wantchannels) goto end_out_loop;
          if (thisdevice > 0) sprintf(devname, "/dev/dsp%d", thisdevice); else sprintf(devname, "/dev/dsp");
              /* search for input request for same device.  Succeed only
              if the number of channels matches. */
          for (j = 0; j < nindev; j++)
!             if (indev[j] == thisdevice && chin[j] == wantchannels) inindex = j;
!             /* if the same device is requested for input and output, try to open it read/write */
          if (inindex >= 0) {
              sys_setalarm(1000000);
***************
*** 267,272 ****
                  else if (fcntl(fd, F_SETFL, flags & (!O_NDELAY)) < 0)
                      post("couldn't set audio device flags");
!                 if (sys_verbose)
!                     post("opened %s for reading and writing\n", devname);
                  linux_adcs[inindex].d_fd = fd;
              }
--- 258,262 ----
                  else if (fcntl(fd, F_SETFL, flags & (!O_NDELAY)) < 0)
                      post("couldn't set audio device flags");
!                 if (sys_verbose) post("opened %s for reading and writing\n", devname);
                  linux_adcs[inindex].d_fd = fd;
              }
***************
*** 276,281 ****
              sys_setalarm(1000000);
              if ((fd = open(devname, O_WRONLY | O_AUDIOFLAG)) == -1) {
!                 post("%s (writeonly): %s",
!                      devname, strerror(errno));
                  break;
              }
--- 266,270 ----
              sys_setalarm(1000000);
              if ((fd = open(devname, O_WRONLY | O_AUDIOFLAG)) == -1) {
!                 post("%s (writeonly): %s", devname, strerror(errno));
                  break;
              }
***************
*** 292,302 ****
              error("OSS: SNDCTL_DSP_GETCAPS failed %s", devname);
  
!         gotchans = oss_setchannels(fd,
!             (wantchannels>OSS_MAXCHPERDEV)?OSS_MAXCHPERDEV:wantchannels,
!                     devname);
  
!         if (sys_verbose)
!             post("opened audio output on %s; got %d channels",
!                  devname, gotchans);
  
          if (gotchans < 2) {
--- 281,287 ----
              error("OSS: SNDCTL_DSP_GETCAPS failed %s", devname);
  
!         gotchans = oss_setchannels(fd, (wantchannels>OSS_MAXCHPERDEV)?OSS_MAXCHPERDEV:wantchannels, devname);
  
!         if (sys_verbose) post("opened audio output on %s; got %d channels", devname, gotchans);
  
          if (gotchans < 2) {
***************
*** 306,310 ****
              linux_dacs[linux_noutdevs].d_nchannels = gotchans;
              linux_dacs[linux_noutdevs].d_fd = fd;
!             oss_configure(linux_dacs+linux_noutdevs, rate, 1, 0);
  
              linux_noutdevs++;
--- 291,295 ----
              linux_dacs[linux_noutdevs].d_nchannels = gotchans;
              linux_dacs[linux_noutdevs].d_fd = fd;
!             oss_configure(&linux_dacs[linux_noutdevs], rate, 1, 0);
  
              linux_noutdevs++;
***************
*** 373,393 ****
  
      if (linux_nindevs) {
!         if (sys_verbose)
!             fprintf(stderr,("OSS: issuing first ADC 'read' ... "));
!         read(linux_adcs[0].d_fd, buf,
!             linux_adcs[0].d_bytespersamp *
!                 linux_adcs[0].d_nchannels * sys_dacblocksize);
          if (sys_verbose)
              fprintf(stderr, "...done.\n");
      }
!         /* now go and fill all the output buffers. */
      for (i = 0; i < linux_noutdevs; i++) {
!         int j;
!         memset(buf, 0, linux_dacs[i].d_bytespersamp *
!                 linux_dacs[i].d_nchannels * sys_dacblocksize);
!         for (j = 0; j < sys_advance_samples/sys_dacblocksize; j++)
!             write(linux_dacs[i].d_fd, buf,
!                 linux_dacs[i].d_bytespersamp *
!                     linux_dacs[i].d_nchannels * sys_dacblocksize);
      }
      sys_setalarm(0);
--- 358,372 ----
  
      if (linux_nindevs) {
!         if (sys_verbose) fprintf(stderr,("OSS: issuing first ADC 'read' ... "));
!         read(linux_adcs[0].d_fd, buf, linux_adcs[0].d_bytespersamp * linux_adcs[0].d_nchannels * sys_dacblocksize);
          if (sys_verbose)
              fprintf(stderr, "...done.\n");
      }
!     /* now go and fill all the output buffers. */
      for (i = 0; i < linux_noutdevs; i++) {
! 	t_oss_dev &d = linux_dacs[i];
!         memset(buf, 0, d.d_bytespersamp * d.d_nchannels * sys_dacblocksize);
!         for (int j = 0; j < sys_advance_samples/sys_dacblocksize; j++)
!             write(d.d_fd, buf, d.d_bytespersamp * d.d_nchannels * sys_dacblocksize);
      }
      sys_setalarm(0);
***************
*** 397,401 ****
  }
  
! void oss_close_audio( void) {
      int i;
      for (i=0;i<linux_nindevs ;i++) close(linux_adcs[i].d_fd);
--- 376,380 ----
  }
  
! void oss_close_audio() {
      int i;
      for (i=0;i<linux_nindevs ;i++) close(linux_adcs[i].d_fd);
***************
*** 408,416 ****
  
      /* query audio devices for "available" data size. */
! static void oss_calcspace(void) {
      int dev;
      audio_buf_info ainfo;
      for (dev=0; dev < linux_noutdevs; dev++) {
!         if (ioctl(linux_dacs[dev].d_fd, SOUND_PCM_GETOSPACE, &ainfo) < 0)
             fprintf(stderr,"OSS: ioctl on output device %d failed",dev);
          linux_dacs[dev].d_space = ainfo.bytes;
--- 387,395 ----
  
      /* query audio devices for "available" data size. */
! static void oss_calcspace() {
      int dev;
      audio_buf_info ainfo;
      for (dev=0; dev < linux_noutdevs; dev++) {
!         if (ioctl(linux_dacs[dev].d_fd, SOUND_PCM_GETOSPACE,&ainfo) < 0)
             fprintf(stderr,"OSS: ioctl on output device %d failed",dev);
          linux_dacs[dev].d_space = ainfo.bytes;
***************
*** 418,435 ****
      for (dev = 0; dev < linux_nindevs; dev++) {
          if (ioctl(linux_adcs[dev].d_fd, SOUND_PCM_GETISPACE,&ainfo) < 0)
!             fprintf(stderr, "OSS: ioctl on input device %d, fd %d failed",
!                 dev, linux_adcs[dev].d_fd);
          linux_adcs[dev].d_space = ainfo.bytes;
      }
  }
  
! void linux_audiostatus(void) {
!     int dev;
      if (!oss_blockmode) {
          oss_calcspace();
!         for (dev=0; dev < linux_noutdevs; dev++)
!             fprintf(stderr, "dac %d space %d\n", dev, linux_dacs[dev].d_space);
!         for (dev = 0; dev < linux_nindevs; dev++)
!             fprintf(stderr, "adc %d space %d\n", dev, linux_adcs[dev].d_space);
      }
  }
--- 397,410 ----
      for (dev = 0; dev < linux_nindevs; dev++) {
          if (ioctl(linux_adcs[dev].d_fd, SOUND_PCM_GETISPACE,&ainfo) < 0)
!             fprintf(stderr, "OSS: ioctl on input device %d, fd %d failed", dev, linux_adcs[dev].d_fd);
          linux_adcs[dev].d_space = ainfo.bytes;
      }
  }
  
! void linux_audiostatus() {
      if (!oss_blockmode) {
          oss_calcspace();
!         for (int dev=0; dev < linux_noutdevs; dev++) fprintf(stderr, "dac %d space %d\n", dev, linux_dacs[dev].d_space);
!         for (int dev=0; dev < linux_nindevs;  dev++) fprintf(stderr, "adc %d space %d\n", dev, linux_adcs[dev].d_space);
      }
  }
***************
*** 438,489 ****
  in audio output and/or input. */
  
! static void oss_doresync( void) {
      int dev, zeroed = 0;
      char buf[OSS_MAXSAMPLEWIDTH * sys_dacblocksize * OSS_MAXCHPERDEV];
      audio_buf_info ainfo;
  
!         /* 1. if any input devices are ahead (have more than 1 buffer stored),
!             drop one or more buffers worth */
      for (dev = 0; dev < linux_nindevs; dev++) {
!         if (linux_adcs[dev].d_space == 0) {
!             linux_adcs_read(linux_adcs[dev].d_fd, buf,
!                 OSS_XFERSIZE(linux_adcs[dev].d_nchannels,
!                     linux_adcs[dev].d_bytespersamp));
!         }
!         else while (linux_adcs[dev].d_space >
!             OSS_XFERSIZE(linux_adcs[dev].d_nchannels,
!                 linux_adcs[dev].d_bytespersamp))
!         {
!             linux_adcs_read(linux_adcs[dev].d_fd, buf,
!                 OSS_XFERSIZE(linux_adcs[dev].d_nchannels,
!                     linux_adcs[dev].d_bytespersamp));
!             if (ioctl(linux_adcs[dev].d_fd, SOUND_PCM_GETISPACE, &ainfo) < 0) {
!                 fprintf(stderr, "OSS: ioctl on input device %d, fd %d failed", dev, linux_adcs[dev].d_fd);
                  break;
              }
!             linux_adcs[dev].d_space = ainfo.bytes;
          }
      }
  
!         /* 2. if any output devices are behind, feed them zeros to catch them
!             up */
      for (dev = 0; dev < linux_noutdevs; dev++) {
!         while (linux_dacs[dev].d_space > linux_dacs[dev].d_bufsize -
!             sys_advance_samples * (linux_dacs[dev].d_nchannels *
!                 linux_dacs[dev].d_bytespersamp))
!         {
              if (!zeroed) {
!                 unsigned int i;
!                 for (i = 0; i < OSS_XFERSAMPS(linux_dacs[dev].d_nchannels); i++) buf[i] = 0;
                  zeroed = 1;
              }
!             linux_dacs_write(linux_dacs[dev].d_fd, buf,
!                 OSS_XFERSIZE(linux_dacs[dev].d_nchannels,
!                     linux_dacs[dev].d_bytespersamp));
!             if (ioctl(linux_dacs[dev].d_fd, SOUND_PCM_GETOSPACE, &ainfo) < 0) {
!                 fprintf(stderr, "OSS: ioctl on output device %d, fd %d failed", dev, linux_dacs[dev].d_fd);
                  break;
              }
!             linux_dacs[dev].d_space = ainfo.bytes;
          }
      }
--- 413,450 ----
  in audio output and/or input. */
  
! static void oss_doresync() {
      int dev, zeroed = 0;
      char buf[OSS_MAXSAMPLEWIDTH * sys_dacblocksize * OSS_MAXCHPERDEV];
      audio_buf_info ainfo;
  
!     /* 1. if any input devices are ahead (have more than 1 buffer stored), drop one or more buffers worth */
      for (dev = 0; dev < linux_nindevs; dev++) {
! 	t_oss_dev d = linux_adcs[dev];
!         if (d.d_space == 0) {
!             linux_adcs_read(d.d_fd, buf, OSS_XFERSIZE(d.d_nchannels, d.d_bytespersamp));
!         } else while (d.d_space > OSS_XFERSIZE(d.d_nchannels, d.d_bytespersamp)) {
!             linux_adcs_read(d.d_fd, buf, OSS_XFERSIZE(d.d_nchannels, d.d_bytespersamp));
!             if (ioctl(d.d_fd, SOUND_PCM_GETISPACE, &ainfo) < 0) {
!                 fprintf(stderr, "OSS: ioctl on input device %d, fd %d failed", dev, d.d_fd);
                  break;
              }
!             d.d_space = ainfo.bytes;
          }
      }
  
!     /* 2. if any output devices are behind, feed them zeros to catch them up */
      for (dev = 0; dev < linux_noutdevs; dev++) {
! 	t_oss_dev d = linux_dacs[dev];
!         while (d.d_space > d.d_bufsize - sys_advance_samples*d.d_nchannels*d.d_bytespersamp) {
              if (!zeroed) {
!                 for (unsigned int i = 0; i < OSS_XFERSAMPS(d.d_nchannels); i++) buf[i] = 0;
                  zeroed = 1;
              }
!             linux_dacs_write(d.d_fd, buf, OSS_XFERSIZE(d.d_nchannels, d.d_bytespersamp));
!             if (ioctl(d.d_fd, SOUND_PCM_GETOSPACE, &ainfo) < 0) {
!                 fprintf(stderr, "OSS: ioctl on output device %d, fd %d failed", dev, d.d_fd);
                  break;
              }
!             d.d_space = ainfo.bytes;
          }
      }
***************
*** 491,508 ****
              number of frames which will let the others catch up. */
      for (dev = 0; dev < linux_noutdevs; dev++) {
!         if (linux_dacs[dev].d_space > linux_dacs[dev].d_bufsize -
!             (sys_advance_samples - 1) * linux_dacs[dev].d_nchannels *
!                 linux_dacs[dev].d_bytespersamp)
!         {
!             linux_dacs[dev].d_dropcount = sys_advance_samples - 1 -
!                 (linux_dacs[dev].d_space - linux_dacs[dev].d_bufsize) /
!                      (linux_dacs[dev].d_nchannels *
!                         linux_dacs[dev].d_bytespersamp) ;
!         }
!         else linux_dacs[dev].d_dropcount = 0;
      }
  }
  
! int oss_send_dacs(void) {
      float *fp1, *fp2;
      int i, j, dev, rtnval = SENDDACS_YES;
--- 452,463 ----
              number of frames which will let the others catch up. */
      for (dev = 0; dev < linux_noutdevs; dev++) {
! 	t_oss_dev d = linux_dacs[dev];
!         if (d.d_space > d.d_bufsize - (sys_advance_samples - 1) * d.d_nchannels * d.d_bytespersamp) {
!             d.d_dropcount = sys_advance_samples - 1 - (d.d_space - d.d_bufsize) / (d.d_nchannels * d.d_bytespersamp);
!         } else d.d_dropcount = 0;
      }
  }
  
! int oss_send_dacs() {
      float *fp1, *fp2;
      int i, j, dev, rtnval = SENDDACS_YES;
***************
*** 510,546 ****
      t_oss_int16 *sp;
      t_oss_int32 *lp;
!         /* the maximum number of samples we should have in the ADC buffer */
      int idle = 0;
      int thischan;
      double timeref, timenow;
  
!     if (!linux_nindevs && !linux_noutdevs)
!         return SENDDACS_NO;
! 
      if (!oss_blockmode) {
          /* determine whether we're idle.  This is true if either (1)
!         some input device has less than one buffer to read or (2) some
!         output device has fewer than (sys_advance_samples) blocks buffered
!         already. */
          oss_calcspace();
!         for (dev=0; dev < linux_noutdevs; dev++)
!             if (linux_dacs[dev].d_dropcount ||
!                 (linux_dacs[dev].d_bufsize - linux_dacs[dev].d_space >
!                     sys_advance_samples * linux_dacs[dev].d_bytespersamp *
!                         linux_dacs[dev].d_nchannels))
!                             idle = 1;
!         for (dev=0; dev < linux_nindevs; dev++)
!             if (linux_adcs[dev].d_space <
!                 OSS_XFERSIZE(linux_adcs[dev].d_nchannels,
!                     linux_adcs[dev].d_bytespersamp))
!                         idle = 1;
      }
      if (idle && !oss_blockmode) {
!             /* sometimes---rarely---when the ADC available-byte-count is
!             zero, it's genuine, but usually it's because we're so
!             late that the ADC has overrun its entire kernel buffer.  We
!             distinguish between the two by waiting 2 msec and asking again.
!             There should be an error flag we could check instead; look for this
!             someday... */
          for (dev = 0;dev < linux_nindevs; dev++) if (linux_adcs[dev].d_space == 0) {
              sys_microsleep(sys_sleepgrain); /* tb: changed to sys_sleepgrain */
--- 465,494 ----
      t_oss_int16 *sp;
      t_oss_int32 *lp;
!     /* the maximum number of samples we should have in the ADC buffer */
      int idle = 0;
      int thischan;
      double timeref, timenow;
  
!     if (!linux_nindevs && !linux_noutdevs) return SENDDACS_NO;
      if (!oss_blockmode) {
          /* determine whether we're idle.  This is true if either (1)
!            some input device has less than one buffer to read or (2) some
!            output device has fewer than (sys_advance_samples) blocks buffered already. */
          oss_calcspace();
!         for (dev=0; dev < linux_noutdevs; dev++) {
! 	    t_oss_dev d = linux_dacs[dev];
!             if (d.d_dropcount || (d.d_bufsize - d.d_space > sys_advance_samples * d.d_bytespersamp * d.d_nchannels)) idle = 1;
! 	}
!         for (dev=0; dev < linux_nindevs; dev++) {
! 	    t_oss_dev d = linux_adcs[dev];
!             if (d.d_space < OSS_XFERSIZE(d.d_nchannels, d.d_bytespersamp)) idle = 1;
! 	}
      }
      if (idle && !oss_blockmode) {
!         /* sometimes---rarely---when the ADC available-byte-count is
!            zero, it's genuine, but usually it's because we're so
!            late that the ADC has overrun its entire kernel buffer.  We
!            distinguish between the two by waiting 2 msec and asking again.
!            There should be an error flag we could check instead; look for this someday... */
          for (dev = 0;dev < linux_nindevs; dev++) if (linux_adcs[dev].d_space == 0) {
              sys_microsleep(sys_sleepgrain); /* tb: changed to sys_sleepgrain */
***************
*** 557,572 ****
             input device should have more than one buffer readable and
             no output device should have less than sys_advance_samples-1 */
!         for (dev=0; dev < linux_noutdevs; dev++)
!             if (!linux_dacs[dev].d_dropcount &&
!                 (linux_dacs[dev].d_bufsize - linux_dacs[dev].d_space <
!                     (sys_advance_samples - 2) *
!                         (linux_dacs[dev].d_bytespersamp *
!                             linux_dacs[dev].d_nchannels)))
                          goto badsync;
          for (dev=0; dev < linux_nindevs; dev++)
!             if (linux_adcs[dev].d_space > 3 *
!                 OSS_XFERSIZE(linux_adcs[dev].d_nchannels,
!                     linux_adcs[dev].d_bytespersamp))
!                         goto badsync;
  
          /* return zero to tell the scheduler we're idle. */
--- 505,515 ----
             input device should have more than one buffer readable and
             no output device should have less than sys_advance_samples-1 */
!         for (dev=0; dev < linux_noutdevs; dev++) {
! 	    t_oss_dev d = linux_dacs[dev];
!             if (!d.d_dropcount && (d.d_bufsize - d.d_space < (sys_advance_samples - 2)*d.d_bytespersamp*d.d_nchannels))
                          goto badsync;
+ 	}
          for (dev=0; dev < linux_nindevs; dev++)
!             if (linux_adcs[dev].d_space > 3 * OSS_XFERSIZE(linux_adcs[dev].d_nchannels, linux_adcs[dev].d_bytespersamp)) goto badsync;
  
          /* return zero to tell the scheduler we're idle. */
***************
*** 581,600 ****
      timeref = sys_getrealtime();
      for (dev=0, thischan = 0; dev < linux_noutdevs; dev++) {
!         int nchannels = linux_dacs[dev].d_nchannels;
!         if (linux_dacs[dev].d_dropcount)
!             linux_dacs[dev].d_dropcount--;
          else {
!             if (linux_dacs[dev].d_bytespersamp == 4) {
!                 for (i = sys_dacblocksize * nchannels,  fp1 = sys_soundout +
!                     sys_dacblocksize*thischan,
!                     lp = (t_oss_int32 *)buf; i--; fp1++, lp++) {
                      float f = *fp1 * 2147483648.;
                      *lp = int(f >= 2147483647. ? 2147483647. : (f < -2147483648. ? -2147483648. : f));
                  }
              } else {
!                 for (i = sys_dacblocksize,  fp1 = sys_soundout +
!                     sys_dacblocksize*thischan,
!                     sp = (t_oss_int16 *)buf; i--; fp1++, sp += nchannels)
!                 {
                      for (j=0, fp2 = fp1; j<nchannels; j++, fp2 += sys_dacblocksize) {
                          int s = int(*fp2 * 32767.);
--- 524,540 ----
      timeref = sys_getrealtime();
      for (dev=0, thischan = 0; dev < linux_noutdevs; dev++) {
! 	t_oss_dev d = linux_dacs[dev];
!         int nchannels = d.d_nchannels;
!         if (d.d_dropcount) d.d_dropcount--;
          else {
!             if (d.d_bytespersamp == 4) {
! 		fp1 = sys_soundout + sys_dacblocksize*thischan;
!                 for (i = sys_dacblocksize * nchannels, lp = (t_oss_int32 *)buf; i--; fp1++, lp++) {
                      float f = *fp1 * 2147483648.;
                      *lp = int(f >= 2147483647. ? 2147483647. : (f < -2147483648. ? -2147483648. : f));
                  }
              } else {
! 		fp1 = sys_soundout + sys_dacblocksize*thischan;
!                 for (i = sys_dacblocksize, sp = (t_oss_int16 *)buf; i--; fp1++, sp += nchannels) {
                      for (j=0, fp2 = fp1; j<nchannels; j++, fp2 += sys_dacblocksize) {
                          int s = int(*fp2 * 32767.);
***************
*** 605,614 ****
                  }
              }
!             linux_dacs_write(linux_dacs[dev].d_fd, buf,
!                 OSS_XFERSIZE(nchannels, linux_dacs[dev].d_bytespersamp));
              if ((timenow = sys_getrealtime()) - timeref > 0.002) {
!                 if (!oss_blockmode)
!                     sys_log_error(ERR_DACSLEPT);
!                 else rtnval = SENDDACS_SLEPT;
              }
              timeref = timenow;
--- 545,551 ----
                  }
              }
!             linux_dacs_write(d.d_fd, buf, OSS_XFERSIZE(nchannels, d.d_bytespersamp));
              if ((timenow = sys_getrealtime()) - timeref > 0.002) {
!                 if (!oss_blockmode) sys_log_error(ERR_DACSLEPT); else rtnval = SENDDACS_SLEPT;
              }
              timeref = timenow;
***************
*** 616,651 ****
          thischan += nchannels;
      }
!     memset(sys_soundout, 0,
!         sys_outchannels * (sizeof(float) * sys_dacblocksize));
! 
!         /* do input */
  
      for (dev = 0, thischan = 0; dev < linux_nindevs; dev++) {
          int nchannels = linux_adcs[dev].d_nchannels;
!         linux_adcs_read(linux_adcs[dev].d_fd, buf,
!             OSS_XFERSIZE(nchannels, linux_adcs[dev].d_bytespersamp));
! 
          if ((timenow = sys_getrealtime()) - timeref > 0.002) {
!             if (!oss_blockmode)
!                 sys_log_error(ERR_ADCSLEPT);
!             else
!                 rtnval = SENDDACS_SLEPT;
          }
          timeref = timenow;
! 
          if (linux_adcs[dev].d_bytespersamp == 4) {
!             for (i = sys_dacblocksize*nchannels,
!                 fp1 = sys_soundin + thischan*sys_dacblocksize,
!                     lp = (t_oss_int32 *)buf; i--; fp1++, lp++)
!             {
!                 *fp1 = ((float)(*lp))*(float)(1./2147483648.);
!             }
          } else {
!             for (i = sys_dacblocksize,fp1 = sys_soundin + thischan*sys_dacblocksize,
!                 sp = (t_oss_int16 *)buf; i--; fp1++, sp += nchannels)
!             {
!                 for (j=0;j<nchannels;j++)
!                     fp1[j*sys_dacblocksize] = (float)sp[j]*(float)3.051850e-05;
!             }
          }
          thischan += nchannels;
--- 553,572 ----
          thischan += nchannels;
      }
!     memset(sys_soundout, 0, sys_outchannels * (sizeof(float) * sys_dacblocksize));
  
      for (dev = 0, thischan = 0; dev < linux_nindevs; dev++) {
          int nchannels = linux_adcs[dev].d_nchannels;
!         linux_adcs_read(linux_adcs[dev].d_fd, buf, OSS_XFERSIZE(nchannels, linux_adcs[dev].d_bytespersamp));
          if ((timenow = sys_getrealtime()) - timeref > 0.002) {
!             if (!oss_blockmode) sys_log_error(ERR_ADCSLEPT); else rtnval = SENDDACS_SLEPT;
          }
          timeref = timenow;
! 	fp1 = sys_soundin + thischan*sys_dacblocksize;
          if (linux_adcs[dev].d_bytespersamp == 4) {
!             for (i = sys_dacblocksize*nchannels, lp = (t_oss_int32 *)buf; i--; fp1++, lp++)
!                 *fp1 = float(*lp)*float(1./2147483648.);
          } else {
!             for (i = sys_dacblocksize, sp = (t_oss_int16 *)buf; i--; fp1++, sp += nchannels)
!                 for (j=0; j<nchannels; j++) fp1[j*sys_dacblocksize] = (float)sp[j]*(float)3.051850e-05;
          }
          thischan += nchannels;
***************
*** 655,664 ****
  
  void oss_getdevs(char *indevlist, int *nindevs, char *outdevlist, int *noutdevs, int *canmulti, int maxndev, int devdescsize) {
!     int i, ndev;
      *canmulti = 2;  /* supports multiple devices */
!     if ((ndev = oss_ndev) > maxndev) ndev = maxndev;
!     for (i = 0; i < ndev; i++) {
!         sprintf(indevlist + i * devdescsize, "OSS device #%d", i+1);
!         sprintf(outdevlist + i * devdescsize, "OSS device #%d", i+1);
      }
      *nindevs = *noutdevs = ndev;
--- 576,584 ----
  
  void oss_getdevs(char *indevlist, int *nindevs, char *outdevlist, int *noutdevs, int *canmulti, int maxndev, int devdescsize) {
!     int ndev = min(oss_ndev,maxndev);
      *canmulti = 2;  /* supports multiple devices */
!     for (int i=0; i<ndev; i++) {
!         sprintf(indevlist  + i*devdescsize, "OSS device #%d", i+1);
!         sprintf(outdevlist + i*devdescsize, "OSS device #%d", i+1);
      }
      *nindevs = *noutdevs = ndev;

Index: s_audio_jack.c
===================================================================
RCS file: /cvsroot/pure-data/pd/src/s_audio_jack.c,v
retrieving revision 1.5.4.8.2.7.2.6
retrieving revision 1.5.4.8.2.7.2.7
diff -C2 -d -r1.5.4.8.2.7.2.6 -r1.5.4.8.2.7.2.7
*** s_audio_jack.c	9 Jul 2007 17:41:02 -0000	1.5.4.8.2.7.2.6
--- s_audio_jack.c	9 Jul 2007 19:59:42 -0000	1.5.4.8.2.7.2.7
***************
*** 2,5 ****
--- 2,6 ----
  #include <stdlib.h>
  #include <string.h>
+ #define PD_PLUSPLUS_FACE
  #include "desire.h"
  #include "m_simd.h"
***************
*** 26,46 ****
  pthread_cond_t jack_sem;
  t_int jack_save_connection_state(t_int* dummy);
! static void jack_restore_connection_state(void);
! void run_all_idle_callbacks(void);
  
  static int process (jack_nframes_t nframes, void *arg) {
! 	int j;
! 	float *out;
! 	float *in;
! 	if (nframes > JACK_OUT_MAX) jack_out_max = nframes;
! 	else jack_out_max = JACK_OUT_MAX;
  	if (jack_filled >= nframes) {
  		if (jack_filled != nframes) fprintf(stderr,"Partial read");
! 		for (j = 0; j < sys_outchannels;  j++) {
! 			out = (float *)jack_port_get_buffer(output_port[j], nframes);
  			memcpy(out, jack_outbuf + (j * BUF_JACK), sizeof(float)*nframes);
  		}
! 		for (j = 0; j < sys_inchannels; j++) {
! 			in  = (float *)jack_port_get_buffer( input_port[j], nframes);
  			memcpy(jack_inbuf + (j * BUF_JACK), in,   sizeof(float)*nframes);
  		}
--- 27,43 ----
  pthread_cond_t jack_sem;
  t_int jack_save_connection_state(t_int* dummy);
! static void jack_restore_connection_state();
! void run_all_idle_callbacks();
  
  static int process (jack_nframes_t nframes, void *arg) {
! 	jack_out_max = max(int(nframes),JACK_OUT_MAX);
  	if (jack_filled >= nframes) {
  		if (jack_filled != nframes) fprintf(stderr,"Partial read");
! 		for (int j = 0; j < sys_outchannels;  j++) {
! 			float *out = (float *)jack_port_get_buffer(output_port[j], nframes);
  			memcpy(out, jack_outbuf + (j * BUF_JACK), sizeof(float)*nframes);
  		}
! 		for (int j = 0; j < sys_inchannels; j++) {
! 			float *in  = (float *)jack_port_get_buffer( input_port[j], nframes);
  			memcpy(jack_inbuf + (j * BUF_JACK), in,   sizeof(float)*nframes);
  		}
***************
*** 48,53 ****
  	} else { /* PD could not keep up ! */
  		if (jack_started) jack_dio_error = 1;
! 		for (j = 0; j < outport_count;  j++) {
! 			out = (float *)jack_port_get_buffer (output_port[j], nframes);
  			memset(out, 0, sizeof (float) * nframes);
  		}
--- 45,50 ----
  	} else { /* PD could not keep up ! */
  		if (jack_started) jack_dio_error = 1;
! 		for (int j = 0; j < outport_count;  j++) {
! 			float *out = (float *)jack_port_get_buffer (output_port[j], nframes);
  			memset(out, 0, sizeof (float) * nframes);
  		}
***************
*** 55,65 ****
  		jack_filled = 0;
  	}
!     /* tb: wait in the scheduler */
!     /* pthread_cond_broadcast(&jack_sem); */
  	return 0;
  }
  
  
! void sys_peakmeters(void);
  extern int sys_meters;          /* true if we're metering */
  extern float sys_inmax;         /* max input amplitude */
--- 52,62 ----
  		jack_filled = 0;
  	}
!         /* tb: wait in the scheduler */
!         /* pthread_cond_broadcast(&jack_sem); */
  	return 0;
  }
  
  
! void sys_peakmeters();
  extern int sys_meters;          /* true if we're metering */
  extern float sys_inmax;         /* max input amplitude */
***************
*** 73,81 ****
  
  static int cb_process (jack_nframes_t nframes, void *arg) {
- 	int i,j;
  	int timeout = int(nframes * 1e6 / sys_dacsr);
  	if (canvas_dspstate == 0) {
  		/* dsp is switched off, the audio is open ... */
! 		for (j = 0; j < sys_outchannels;  j++) {
  			t_sample *out = (t_sample *)jack_port_get_buffer (output_port[j], nframes);
  			zeroblock(out, dspticks_per_jacktick * sys_dacblocksize);
--- 70,77 ----
  
  static int cb_process (jack_nframes_t nframes, void *arg) {
  	int timeout = int(nframes * 1e6 / sys_dacsr);
  	if (canvas_dspstate == 0) {
  		/* dsp is switched off, the audio is open ... */
! 		for (int j=0; j<sys_outchannels;  j++) {
  			t_sample *out = (t_sample *)jack_port_get_buffer (output_port[j], nframes);
  			zeroblock(out, dspticks_per_jacktick * sys_dacblocksize);
***************
*** 94,109 ****
  			return 0;
  		}
! 	for (i = 0; i != dspticks_per_jacktick; ++i) {
  		/* get sound from the inputs */
! 		for (j = 0; j < sys_inchannels; j++) {
  			t_sample *in = (t_sample *)jack_port_get_buffer(input_port[j], nframes);
! 			copyblock(sys_soundin + j * sys_dacblocksize,
! 				in + i * sys_dacblocksize,
! 				sys_dacblocksize);
  		}
  		/* run dsp */
  		sched_tick(sys_time + sys_time_per_dsp_tick);
  		/* send sound to the output */
! 		for (j = 0; j < sys_outchannels;  j++) {
  			t_sample *out = (t_sample *)jack_port_get_buffer (output_port[j], nframes);
  			copyblock(out + i * sys_dacblocksize, sys_soundout + j * sys_dacblocksize, sys_dacblocksize);
--- 90,104 ----
  			return 0;
  		}
! 	for (int i = 0; i != dspticks_per_jacktick; ++i) {
  		/* get sound from the inputs */
! 		for (int j=0; j<sys_inchannels; j++) {
  			t_sample *in = (t_sample *)jack_port_get_buffer(input_port[j], nframes);
! 			copyblock(sys_soundin + j * sys_dacblocksize, in + i * sys_dacblocksize, sys_dacblocksize);
  		}
  		/* run dsp */
  		sched_tick(sys_time + sys_time_per_dsp_tick);
  		/* send sound to the output */
! 		int j;
! 		for (j=0; j<sys_outchannels;  j++) {
  			t_sample *out = (t_sample *)jack_port_get_buffer (output_port[j], nframes);
  			copyblock(out + i * sys_dacblocksize, sys_soundout + j * sys_dacblocksize, sys_dacblocksize);
***************
*** 138,174 ****
  }
  
! static void jack_shutdown (void *arg) {
! 	/* register idle callback in scheduler */
! 	sys_callback(jack_shutdown_handler, NULL, 0);
! }
! 
! static int jack_graph_order_callback(void* arg) {
! 	sys_callback(jack_save_connection_state, NULL, 0);
! 	return 0;
! }
  
! static char** jack_get_clients(void) {
      const char **jack_ports;
-     int i,j;
      int num_clients = 0;
      regex_t port_regex;
!     jack_ports = jack_get_ports( jack_client, "", "", 0 );
!     regcomp( &port_regex, "^[^:]*", REG_EXTENDED );
      jack_client_names[0] = NULL;
      /* Build a list of clients from the list of ports */
!     for (i=0; jack_ports[i] != NULL; i++) {
          int client_seen;
          regmatch_t match_info;
          char tmp_client_name[100];
          /* extract the client name from the port name, using a regex that parses the clientname:portname syntax */
!         regexec( &port_regex, jack_ports[i], 1, &match_info, 0 );
!         memcpy( tmp_client_name, &jack_ports[i][match_info.rm_so],
!                 match_info.rm_eo - match_info.rm_so );
          tmp_client_name[ match_info.rm_eo - match_info.rm_so ] = '\0';
          /* do we know about this port's client yet? */
          client_seen = 0;
!         for (j = 0; j < num_clients; j++)
!             if( strcmp( tmp_client_name, jack_client_names[j] ) == 0 )
!                 client_seen = 1;
          if (!client_seen) {
              jack_client_names[num_clients] = (char*)getbytes(strlen(tmp_client_name) + 1);
--- 133,159 ----
  }
  
! /* register idle callback in scheduler */
! static void jack_shutdown (void *arg) {sys_callback(jack_shutdown_handler, NULL, 0);}
! static int jack_graph_order_callback(void* arg) {sys_callback(jack_save_connection_state, NULL, 0); return 0;}
  
! static char** jack_get_clients() {
      const char **jack_ports;
      int num_clients = 0;
      regex_t port_regex;
!     jack_ports = jack_get_ports(jack_client, "", "", 0);
!     regcomp(&port_regex, "^[^:]*", REG_EXTENDED);
      jack_client_names[0] = NULL;
      /* Build a list of clients from the list of ports */
!     for (int i=0; jack_ports[i] != NULL; i++) {
          int client_seen;
          regmatch_t match_info;
          char tmp_client_name[100];
          /* extract the client name from the port name, using a regex that parses the clientname:portname syntax */
!         regexec(&port_regex, jack_ports[i], 1, &match_info, 0);
!         memcpy(tmp_client_name, &jack_ports[i][match_info.rm_so], match_info.rm_eo-match_info.rm_so);
          tmp_client_name[ match_info.rm_eo - match_info.rm_so ] = '\0';
          /* do we know about this port's client yet? */
          client_seen = 0;
!         for (int j=0; j<num_clients; j++) if (strcmp(tmp_client_name, jack_client_names[j])==0) client_seen = 1;
          if (!client_seen) {
              jack_client_names[num_clients] = (char*)getbytes(strlen(tmp_client_name) + 1);
***************
*** 177,181 ****
               * it in spot 0 put it in spot 0 and move whatever
               * was already in spot 0 to the end. */
!             if (strcmp( "alsa_pcm", tmp_client_name ) == 0 && num_clients > 0) {
  		char* tmp;
                  /* alsa_pcm goes in spot 0 */
--- 162,166 ----
               * it in spot 0 put it in spot 0 and move whatever
               * was already in spot 0 to the end. */
!             if (strcmp("alsa_pcm",tmp_client_name)==0 && num_clients>0) {
  		char* tmp;
                  /* alsa_pcm goes in spot 0 */
***************
*** 183,195 ****
  		jack_client_names[ num_clients ] = jack_client_names[0];
  		jack_client_names[0] = tmp;
! 		strcpy( jack_client_names[0], tmp_client_name);
              } else {
                  /* put the new client at the end of the client list */
!                 strcpy( jack_client_names[ num_clients ], tmp_client_name );
              }
              num_clients++;
          }
      }
! /* for (i=0;i<num_clients;i++) post("client: %s",jack_client_names[i]); */
      free(jack_ports);
      return jack_client_names;
--- 168,180 ----
  		jack_client_names[ num_clients ] = jack_client_names[0];
  		jack_client_names[0] = tmp;
! 		strcpy(jack_client_names[0], tmp_client_name);
              } else {
                  /* put the new client at the end of the client list */
!                 strcpy(jack_client_names[ num_clients ], tmp_client_name);
              }
              num_clients++;
          }
      }
!     /* for (int i=0; i<num_clients; i++) post("client: %s",jack_client_names[i]); */
      free(jack_ports);
      return jack_client_names;
***************
*** 205,215 ****
  	entered = 1;
  	if (strlen(client) > 96)  return -1;
! 	sprintf( regex_pattern, "%s:.*", client );
! 	jack_ports = jack_get_ports( jack_client, regex_pattern, NULL, JackPortIsOutput);
  	if (jack_ports)
  		for (i=0;jack_ports[i] != NULL && i < sys_inchannels;i++)
  			if (jack_connect (jack_client, jack_ports[i], jack_port_name (input_port[i])))
  				fprintf (stderr, "cannot connect input ports %s -> %s\n", jack_ports[i],jack_port_name (input_port[i]));
! 	jack_ports = jack_get_ports( jack_client, regex_pattern, NULL, JackPortIsInput);
  	if (jack_ports)
  		for (i=0;jack_ports[i] != NULL && i < sys_outchannels;i++)
--- 190,200 ----
  	entered = 1;
  	if (strlen(client) > 96)  return -1;
! 	sprintf(regex_pattern, "%s:.*", client);
! 	jack_ports = jack_get_ports(jack_client, regex_pattern, NULL, JackPortIsOutput);
  	if (jack_ports)
  		for (i=0;jack_ports[i] != NULL && i < sys_inchannels;i++)
  			if (jack_connect (jack_client, jack_ports[i], jack_port_name (input_port[i])))
  				fprintf (stderr, "cannot connect input ports %s -> %s\n", jack_ports[i],jack_port_name (input_port[i]));
! 	jack_ports = jack_get_ports(jack_client, regex_pattern, NULL, JackPortIsInput);
  	if (jack_ports)
  		for (i=0;jack_ports[i] != NULL && i < sys_outchannels;i++)
***************
*** 295,303 ****
      sys_dacsr = srate;
      /* create the ports */
!     for (j = 0; j < inchans; j++) {
  	sprintf(port_name, "input%d", j);
  	if (!input_port[j]) input_port[j] = jack_port_register (jack_client, port_name, JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0);
      }
!     for (j = 0; j < outchans; j++) {
  	sprintf(port_name, "output%d", j);
  	if (!output_port[j]) output_port[j] = jack_port_register (jack_client, port_name, JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0);
--- 280,288 ----
      sys_dacsr = srate;
      /* create the ports */
!     for (int j = 0; j < inchans; j++) {
  	sprintf(port_name, "input%d", j);
  	if (!input_port[j]) input_port[j] = jack_port_register (jack_client, port_name, JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0);
      }
!     for (int j = 0; j < outchans; j++) {
  	sprintf(port_name, "output%d", j);
  	if (!output_port[j]) output_port[j] = jack_port_register (jack_client, port_name, JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0);
***************
*** 326,337 ****
  }
  
! void jack_close_audio(void) {
      if (jack_client) {
- 	int i;
  	jack_deactivate(jack_client);
  	jack_started = 0;
  	jack_client_close(jack_client);
  	jack_client = NULL;
! 	for (i = 0; i <NUM_JACK_PORTS; i++) {
  		input_port[i] = NULL;
  		output_port[i] = NULL;
--- 311,321 ----
  }
  
! void jack_close_audio() {
      if (jack_client) {
  	jack_deactivate(jack_client);
  	jack_started = 0;
  	jack_client_close(jack_client);
  	jack_client = NULL;
! 	for (int i = 0; i <NUM_JACK_PORTS; i++) {
  		input_port[i] = NULL;
  		output_port[i] = NULL;
***************
*** 340,344 ****
  }
  
! int jack_send_dacs(void) {
  	float *fp;
  	int j;
--- 324,328 ----
  }
  
! int jack_send_dacs() {
  	float *fp;
  	int j;
***************
*** 386,392 ****
  }
  
! void jack_listdevs (void) {
!     post("device listing not implemented for jack yet\n");
! }
  
  /* ports connected to the inputs */
--- 370,374 ----
  }
  
! void jack_listdevs () {post("device listing not implemented for jack yet\n");}
  
  /* ports connected to the inputs */
***************
*** 397,403 ****
  /* tb: save the current state of pd's jack connections */
  t_int jack_save_connection_state(t_int* dummy) {
- 	int i;
  	if (jack_ignore_graph_callback) return 0;
! 	for (i = 0; i != NUM_JACK_PORTS; ++i) {
  		/* saving the inputs connections */
  		if (jack_in_connections[i]) free(jack_in_connections[i]);
--- 379,384 ----
  /* tb: save the current state of pd's jack connections */
  t_int jack_save_connection_state(t_int* dummy) {
  	if (jack_ignore_graph_callback) return 0;
! 	for (int i = 0; i != NUM_JACK_PORTS; ++i) {
  		/* saving the inputs connections */
  		if (jack_in_connections[i]) free(jack_in_connections[i]);
***************
*** 413,423 ****
  
  /* todo: don't try to connect twice if we're both input and output host */
! static void jack_restore_connection_state(void) {
! 	int i, j, status;
  	post("restoring connections");
! 	for (i = 0; i != NUM_JACK_PORTS; ++i) {
  		/* restoring the inputs connections */
  		if (jack_in_connections[i]) {
! 			j = 0;
  			while (1) {
  				const char* src_port = jack_in_connections[i][j];
--- 394,404 ----
  
  /* todo: don't try to connect twice if we're both input and output host */
! static void jack_restore_connection_state() {
! 	int status;
  	post("restoring connections");
! 	for (int i = 0; i != NUM_JACK_PORTS; ++i) {
  		/* restoring the inputs connections */
  		if (jack_in_connections[i]) {
! 			int j = 0;
  			while (1) {
  				const char* src_port = jack_in_connections[i][j];
***************
*** 430,434 ****
  		/* restoring the output connections */
  		if (jack_out_connections[i]) {
! 			j = 0;
  			while (1) {
  				const char* dst_port = jack_out_connections[i][j];
--- 411,415 ----
  		/* restoring the output connections */
  		if (jack_out_connections[i]) {
! 			int j = 0;
  			while (1) {
  				const char* dst_port = jack_out_connections[i][j];

Index: s_audio_portaudio.c
===================================================================
RCS file: /cvsroot/pure-data/pd/src/Attic/s_audio_portaudio.c,v
retrieving revision 1.1.2.21.2.4
retrieving revision 1.1.2.21.2.5
diff -C2 -d -r1.1.2.21.2.4 -r1.1.2.21.2.5
*** s_audio_portaudio.c	9 Jul 2007 18:16:13 -0000	1.1.2.21.2.4
--- s_audio_portaudio.c	9 Jul 2007 19:59:42 -0000	1.1.2.21.2.5
***************
*** 65,81 ****
  static int pddev2padev(int pdindev,int isinput);
  static int padev2pddev(int padev,int isinput);
! int process (const void *input, void *output, unsigned long frameCount,
!     const PaStreamCallbackTimeInfo* timeInfo,
      PaStreamCallbackFlags statusFlags, void *userData);
  
- #if 0
- static int patestCallback(const void*                     inputBuffer,
-                           void*                           outputBuffer,
-                           unsigned long                   framesPerBuffer,
-                           const PaStreamCallbackTimeInfo* timeInfo,
-                           PaStreamCallbackFlags           statusFlags,
-                           void*                           userData);
- #endif
- 
  static int pa_indev = -1, pa_outdev = -1;
  
--- 65,71 ----
  static int pddev2padev(int pdindev,int isinput);
  static int padev2pddev(int padev,int isinput);
! int process (const void *input, void *output, unsigned long frameCount, const PaStreamCallbackTimeInfo* timeInfo,
      PaStreamCallbackFlags statusFlags, void *userData);
  
  static int pa_indev = -1, pa_outdev = -1;
  
***************
*** 198,204 ****
          return 1;
      }
- #ifndef DEBUG
      if(sys_verbose)
- #endif
          post("successfully started");
      return 0;
--- 188,192 ----
***************
*** 208,232 ****
  extern int sys_meters;          /* true if we're metering */
  
- #if 0
- static int patestCallback(
- const void *inputBuffer, void *outputBuffer,
- unsigned long framesPerBuffer, const PaStreamCallbackTimeInfo *timeInfo,
- PaStreamCallbackFlags statusFlags, void *userData) {
-     float**     outputs = (float**)outputBuffer;
-     static float phase;
-     for (int frameIndex=0; frameIndex<(int)framesPerBuffer; frameIndex++) {
-         /* Output sine wave on every channel. */
-         outputs[0][frameIndex] = (float) sin(phase);
-         outputs[1][frameIndex] = (float) sin(phase);
-         phase += 0.05;
-         if (phase >= 2*M_PI) phase -= 2*M_PI;
-     }
-     for (int i=0; (unsigned)i != framesPerBuffer / sys_dacblocksize; ++i) {
-         sched_tick(sys_time + sys_time_per_dsp_tick);
-     }
-     return 0;
- }
- #endif
- 
  void run_all_idle_callbacks();
  void sys_xrun_notification(); /* in m_sched.c */
--- 196,199 ----
***************
*** 260,267 ****
  
  void pa_close_audio() {
! #ifndef DEBUG
!     if(sys_verbose)
! #endif
!         post("closing portaudio");
      if (pa_inchans || pa_outchans) {
          if (pa_stream) {
--- 227,231 ----
  
  void pa_close_audio() {
!     if(sys_verbose) post("closing portaudio");
      if (pa_inchans || pa_outchans) {
          if (pa_stream) {
***************
*** 273,280 ****
      }
      sys_setscheduler(0);
! #ifndef DEBUG
!     if(sys_verbose)
! #endif
!         post("portaudio closed");
      pa_inchans = pa_outchans = 0;
      pa_indev = pa_outdev = -1;
--- 237,241 ----
      }
      sys_setscheduler(0);
!     if(sys_verbose) post("portaudio closed");
      pa_inchans = pa_outchans = 0;
      pa_indev = pa_outdev = -1;





More information about the Pd-cvs mailing list