Update of /cvsroot/audacity/lib-src/libnyquist/nyquist/nyqsrc
In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv8506/nyqsrc

Modified Files:
        fft.c fftw.h nyx.c sndfnint.c sndfnint.lsp sndread.c 
        sndwritepa.c sound.c sound.h 
Log Message:
Updating to Nyquist v3.03.


Index: nyx.c
===================================================================
RCS file: /cvsroot/audacity/lib-src/libnyquist/nyquist/nyqsrc/nyx.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- nyx.c       29 Jan 2009 18:04:21 -0000      1.1
+++ nyx.c       5 Mar 2009 16:34:00 -0000       1.2
@@ -25,90 +25,480 @@
 /* xlisp includes */
 #include "switches.h"
 #include "xlisp.h"
-#include "term.h"
 #include "cext.h"
 
 /* nyquist includes */
 #include "sound.h"
+#include "samples.h"
 #include "falloc.h"
 
[...1202 lines suppressed...]
+   }
+   return cvstring(tmp);
+}
+#endif
+
+#ifndef WIN32
+/* xget_user -- get a string identifying the user, for use in file names */
+LVAL xget_user()
+{
+   char *user = getenv("USER");
+   if (!user || !*user) {
+      user = getenv("USERNAME");
+      if (!user || !*user) {
+         errputstr("Warning: could not get user ID, using 'nyquist'\n");
+         user = "nyquist";
+      }
+   }
+   return cvstring(user);
+}
+#endif

Index: fft.c
===================================================================
RCS file: /cvsroot/audacity/lib-src/libnyquist/nyquist/nyqsrc/fft.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- fft.c       29 Jan 2009 18:04:21 -0000      1.1
+++ fft.c       5 Mar 2009 16:34:00 -0000       1.2
@@ -1,5 +1,6 @@
 /* fft.c -- implement snd_fft */
 
+#define _USE_MATH_DEFINES 1 /* for Visual C++ to get M_LN2 */
 #include <math.h>
 #include <stdio.h>
 #ifndef mips
@@ -9,7 +10,7 @@
 #include "sound.h"
 #include "falloc.h"
 #include "fft.h"
-#include "fftn.h"
+#include "fftext.h"
 
 /* CHANGE LOG
  * --------------------------------------------------------------------
@@ -31,8 +32,8 @@
  * extra[3] -> FILLCNT (how many samples in buffer)
  * extra[4] -> TERMCNT (how many samples until termination)
  * extra[5 .. 5+len-1] -> samples (stored as floats)
- * extra[5+len .. 5+3*len-1] -> real and imag. arrays for fft
- * extra[5+3*len ... 5+4*len-1] -> window coefficients
+ * extra[5+len .. 5+2*len-1] -> array of samples to fft
+ * extra[5+2*len ... 5+3*len-1] -> window coefficients
  * 
  * Termination details:
  *   Return NIL when the sound terminates.
@@ -87,7 +88,7 @@
 
 LVAL snd_fft(sound_type s, long len, long step, LVAL winval)
 {
-    long i, maxlen, skip, fillptr;
+    long i, m, maxlen, skip, fillptr;
     float *samples;
     float *temp_fft;
     float *window;
@@ -107,12 +108,12 @@
         /* note: any storage required by fft must be allocated here in a 
          * contiguous block of memory who's size is given by the first long
          * in the block. Here, there are 4 more longs after the size, and 
-         * then room for 4*len floats (assumes that floats and longs take 
+         * then room for 3*len floats (assumes that floats and longs take 
          * equal space).
          *
-         * The reason for 4*len floats is to provide space for:
+         * The reason for 3*len floats is to provide space for:
          *    the samples to be transformed (len)
-         *    the complex FFT result (2*len)
+         *    the complex FFT result (len)
          *    the window coefficients (len)
          *
          * The reason for this storage restriction is that when a sound is 
@@ -121,12 +122,12 @@
          * structure (this could be added in sound.c, however, if it's 
          * really necessary).
          */
-        s->extra = (long *) malloc(sizeof(long) * (4 * len + OFFSET));
-        s->extra[0] = sizeof(long) * (4 * len + OFFSET);
+        s->extra = (long *) malloc(sizeof(long) * (3 * len + OFFSET));
+        s->extra[0] = sizeof(long) * (3 * len + OFFSET);
         s->CNT = s->INDEX = s->FILLCNT = 0;
         s->TERMCNT = -1;
         maxlen = len;
-        window = (float *) &(s->extra[OFFSET + 3 * len]);
+        window = (float *) &(s->extra[OFFSET + 2 * len]);
         /* fill the window from w */
         if (!w) {
             for (i = 0; i < len; i++) *window++ = 1.0F;
@@ -134,12 +135,12 @@
             n_samples_from_sound(w, len, window);
         }
     } else {
-        maxlen = ((s->extra[0] / sizeof(long)) - OFFSET) / 4;
+        maxlen = ((s->extra[0] / sizeof(long)) - OFFSET) / 3;
         if (maxlen != len) xlfail("len changed from initial value");
     }
     samples = (float *) &(s->extra[OFFSET]);
     temp_fft = samples + len;
-    window = temp_fft + 2 * len;
+    window = temp_fft + len;
     /* step 1: refill buffer with samples */
     fillptr = s->FILLCNT;
     while (fillptr < maxlen) {
@@ -174,17 +175,18 @@
      */
     for (i = 0; i < len; i++) {
         temp_fft[i] = samples[i] * *window++;
-        temp_fft[i + len] = 0.0F;
     }
     /* perform the fft: */
-    fftnf(1, (const int *) &len, temp_fft, temp_fft + len, 1, -1.0);
+    m = round(log(len) / M_LN2); /* compute log-base-2(len) */
+    if (!fftInit(m)) rffts(temp_fft, m, 1);
+    else xlfail("FFT initialization error");
+
+    /* move results to Lisp array */
     setelement(result, 0, cvflonum(temp_fft[0]));
-    for (i = 2; i < len; i += 2) {
-        setelement(result, i - 1, cvflonum(temp_fft[i / 2] * 2));
-        setelement(result, i, cvflonum(temp_fft[len + (i / 2)] * -2));
+    setelement(result, len - 1, cvflonum(temp_fft[1]));
+    for (i = 2; i < len; i++) {
+        setelement(result, i - 1, cvflonum(temp_fft[i]));
     }
-    if (len % 2 == 0)
-        setelement(result, len - 1, cvflonum(temp_fft[len / 2]));
 
     /* step 3: shift samples by step */
     if (step < 0) xlfail("step < 0");

Index: sound.c
===================================================================
RCS file: /cvsroot/audacity/lib-src/libnyquist/nyquist/nyqsrc/sound.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- sound.c     1 Mar 2009 21:09:49 -0000       1.3
+++ sound.c     5 Mar 2009 16:34:00 -0000       1.4
@@ -85,7 +85,7 @@
  *  the nominal pitch (in half steps), the table length, and the sample
  *  rate, compute the sample number corresponding to the phase.  This
  *  routine makes it easy to initialize the table pointer at the beginning
- *  of various oscillator implementations in Fugue.  Note that the table
+ *  of various oscillator implementations in Nyquist.  Note that the table
  *  may represent several periods, in which case phase 360 is not the same
  *  as 0.  Also note that the phase increment is also computed and returned
  *  through incr_ptr.
@@ -332,7 +332,7 @@
     /* compute the true t0 which corresponds to the time of first sample */
     snd->true_t0 -= (n / snd->sr);
     /* make caller happy by claiming the sound now starts at exactly t0;
-     * this is always true within 0.5 samples as allowed by Fugue. */
+     * this is always true within 0.5 samples as allowed by Nyquist. */
     snd->t0 = t0;
 /*    nyquist_printf("sound_prepend_zeros: snd %p true_t0 %g sr %g n %d\n", 
            snd, snd->true_t0, snd->sr, n);*/
@@ -506,39 +506,33 @@
 void snd_list_unref(snd_list_type list)
 {
     void (*freefunc)();
-    snd_list_type next;
 
-    while (list != zero_snd_list) {
-        if (list == NULL) {
+    if (list == NULL || list == zero_snd_list) {
+        if (list == NULL)
            nyquist_printf("why did snd_list_unref get %p?\n", list);
-           return;
+        return;
+    }
+    list->refcnt--;
+/*    nyquist_printf("snd_list_unref "); print_snd_list_type(list); 
stdputstr("\n"); */
+    if (list->refcnt == 0) {
+        if (list->block && list->block != zero_block) {
+            /* there is a next snd_list */
+/*          stdputstr("["); */
+            sample_block_unref(list->block);
+/*          stdputstr("]"); */
+            snd_list_unref(list->u.next);
         }
-        next = zero_snd_list;
-
-        list->refcnt--;
-/*      nyquist_printf("snd_list_unref "); print_snd_list_type(list); 
stdputstr("\n"); */
-        if (list->refcnt == 0) {
-            if (list->block && list->block != zero_block) {
-                /* there is a next snd_list */
-/*              stdputstr("["); */
-                sample_block_unref(list->block);
-/*              stdputstr("]"); */
-                next = list->u.next;
-            }
-            else if (list->block == NULL) { /* the next thing is the susp */
-                /* free suspension structure */
-                /* nyquist_printf("freeing s...@%p\n", list->u.susp); */
-                freefunc = list->u.susp->free;
-                (*freefunc)(list->u.susp);
-            }
-            /* nyquist_printf("freeing snd_l...@%p\n", list); */
-            //DBY
-            if (list == list_watch) printf("freeing watched snd_list %p\n", 
list);
-            //DBY
-            ffree_snd_list(list, "snd_list_unref");
+        else if (list->block == NULL) { /* the next thing is the susp */
+            /* free suspension structure */
+            /* nyquist_printf("freeing s...@%p\n", list->u.susp); */
+            freefunc = list->u.susp->free;
+            (*freefunc)(list->u.susp);
         }
-
-        list = next;
+        /* nyquist_printf("freeing snd_l...@%p\n", list); */
+        //DBY
+        if (list == list_watch) printf("freeing watched snd_list %p\n", list);
+        //DBY
+        ffree_snd_list(list, "snd_list_unref");
     }
 }
 

Index: sound.h
===================================================================
RCS file: /cvsroot/audacity/lib-src/libnyquist/nyquist/nyqsrc/sound.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- sound.h     29 Jan 2009 18:04:22 -0000      1.1
+++ sound.h     5 Mar 2009 16:34:00 -0000       1.2
@@ -131,7 +131,7 @@
 /* used by sndwrite.c for output buffers.  This should be
  * eliminated:
  */
-#define MAX_SND_CHANNELS 8
+#define MAX_SND_CHANNELS 24
 
 #define max_table_len 100000
 /* Set to 4 for debugging block allocation stuff, 1012? for

Index: sndfnint.c
===================================================================
RCS file: /cvsroot/audacity/lib-src/libnyquist/nyquist/nyqsrc/sndfnint.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- sndfnint.c  29 Jan 2009 18:04:21 -0000      1.1
+++ sndfnint.c  5 Mar 2009 16:34:00 -0000       1.2
@@ -1,39 +1,39 @@
-/* nyqsrc/sndfnint.c -- interface to  nylsf/sndfile.h, 
- * nyqsrc/sound.h, nyqsrc/add.h, nyqsrc/avg.h, 
- * nyqsrc/compose.h, nyqsrc/convolve.h, 
+/* nyqsrc/sndfnint.c -- interface to  nyqsrc/sndfmt.h, 
+ * nylsf/sndfile.h, nyqsrc/sound.h, nyqsrc/add.h, 
+ * nyqsrc/avg.h, nyqsrc/compose.h, nyqsrc/convolve.h, 
  * nyqsrc/downsample.h, nyqsrc/fft.h, nyqsrc/inverse.h, 
  * nyqsrc/multiseq.h, nyqsrc/resamp.h, nyqsrc/resampv.h, 
  * nyqsrc/samples.h, nyqsrc/sndmax.h, nyqsrc/sndread.h, 
  * nyqsrc/sndseq.h, nyqsrc/sndsliders.h, nyqsrc/sndwrite.h, 
- * nyqsrc/yin.h, nyqsrc/trigger.h, nyqsrc/lpanal.h, 
- * tran/abs.h, tran/allpoles.h, tran/alpass.h, 
- * tran/alpasscv.h, tran/alpassvv.h, tran/amosc.h, 
- * tran/areson.h, tran/aresonvc.h, tran/aresoncv.h, 
- * tran/aresonvv.h, tran/atone.h, tran/atonev.h, 
- * tran/biquadfilt.h, tran/buzz.h, tran/chase.h, 
- * tran/clip.h, tran/congen.h, tran/const.h, 
- * tran/coterm.h, tran/delaycc.h, tran/delaycv.h, 
- * tran/eqbandvvv.h, tran/exp.h, tran/follow.h, 
- * tran/fmosc.h, tran/fromobject.h, tran/fromarraystream.h, 
- * tran/gate.h, tran/ifft.h, tran/instrclar.h, 
- * tran/instrclarall.h, tran/instrclarfreq.h, 
- * tran/instrsax.h, tran/instrsaxall.h, 
- * tran/instrsaxfreq.h, tran/integrate.h, tran/log.h, 
- * tran/lpreson.h, tran/maxv.h, tran/offset.h, 
- * tran/oneshot.h, tran/osc.h, tran/partial.h, 
- * tran/pluck.h, tran/prod.h, tran/pwl.h, 
- * tran/quantize.h, tran/recip.h, tran/reson.h, 
- * tran/resonvc.h, tran/resoncv.h, tran/resonvv.h, 
- * tran/sampler.h, tran/scale.h, tran/shape.h, 
- * tran/sine.h, tran/siosc.h, tran/slope.h, tran/sqrt.h, 
- * tran/tapf.h, tran/tapv.h, tran/tone.h, tran/tonev.h, 
- * tran/upsample.h, tran/white.h, tran/stkrev.h, 
- * tran/stkpitshift.h, tran/stkchorus.h, tran/instrbow.h, 
- * tran/instrbowedfreq.h, tran/instrbanded.h, 
- * tran/instrmandolin.h, tran/instrsitar.h, 
- * tran/instrmodalbar.h, tran/instrflute.h, 
- * tran/instrflutefreq.h, tran/instrfluteall.h, 
- * tran/fmfb.h, tran/fmfbv.h */
+ * nyqsrc/yin.h, nyqsrc/nyq-osc-server.h, nyqsrc/trigger.h, 
+ * nyqsrc/lpanal.h, tran/abs.h, tran/allpoles.h, 
+ * tran/alpass.h, tran/alpasscv.h, tran/alpassvv.h, 
+ * tran/amosc.h, tran/areson.h, tran/aresonvc.h, 
+ * tran/aresoncv.h, tran/aresonvv.h, tran/atone.h, 
+ * tran/atonev.h, tran/biquadfilt.h, tran/buzz.h, 
+ * tran/chase.h, tran/clip.h, tran/congen.h, 
+ * tran/const.h, tran/coterm.h, tran/delaycc.h, 
+ * tran/delaycv.h, tran/eqbandvvv.h, tran/exp.h, 
+ * tran/follow.h, tran/fmosc.h, tran/fromobject.h, 
+ * tran/fromarraystream.h, tran/gate.h, tran/ifft.h, 
+ * tran/instrclar.h, tran/instrclarall.h, 
+ * tran/instrclarfreq.h, tran/instrsax.h, 
+ * tran/instrsaxall.h, tran/instrsaxfreq.h, 
+ * tran/integrate.h, tran/log.h, tran/lpreson.h, 
+ * tran/maxv.h, tran/offset.h, tran/oneshot.h, 
+ * tran/osc.h, tran/partial.h, tran/pluck.h, tran/prod.h, 
+ * tran/pwl.h, tran/quantize.h, tran/recip.h, 
+ * tran/reson.h, tran/resonvc.h, tran/resoncv.h, 
+ * tran/resonvv.h, tran/sampler.h, tran/scale.h, 
+ * tran/shape.h, tran/sine.h, tran/siosc.h, tran/slope.h, 
+ * tran/sqrt.h, tran/tapf.h, tran/tapv.h, tran/tone.h, 
+ * tran/tonev.h, tran/upsample.h, tran/white.h, 
+ * tran/stkrev.h, tran/stkpitshift.h, tran/stkchorus.h, 
+ * tran/instrbow.h, tran/instrbowedfreq.h, 
+ * tran/instrbanded.h, tran/instrmandolin.h, 
+ * tran/instrsitar.h, tran/instrmodalbar.h, 
+ * tran/instrflute.h, tran/instrflutefreq.h, 
+ * tran/instrfluteall.h, tran/fmfb.h, tran/fmfbv.h */
 
 #ifndef mips
 #include "stdlib.h"
@@ -51,6 +51,8 @@
 extern LVAL RSLT_sym;
 
 
+#include "sndfmt.h"
+
 #include "sndfile.h"
 
 #include "sound.h"
@@ -772,6 +774,8 @@
 }
 
 
+#include "nyq-osc-server.h"
+
 #include "trigger.h"
 
 /* xlc_snd_trigger -- interface to C routine snd_trigger */

Index: sndread.c
===================================================================
RCS file: /cvsroot/audacity/lib-src/libnyquist/nyquist/nyqsrc/sndread.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- sndread.c   29 Jan 2009 18:04:21 -0000      1.1
+++ sndread.c   5 Mar 2009 16:34:00 -0000       1.2
@@ -273,7 +273,11 @@
         nyquist_printf("Warning: more than 24 sound files are now open\n");
     }
 #endif
-    
+    /* report info back to caller */
+    if ((susp->sf_info.format & SF_FORMAT_TYPEMASK) != SF_FORMAT_RAW) {
+        *flags = SND_HEAD_CHANNELS | SND_HEAD_MODE | SND_HEAD_BITS |
+                 SND_HEAD_SRATE | SND_HEAD_LEN | SND_HEAD_TYPE;
+    }    
     if (susp->sf_info.channels == 1) {
         susp->susp.fetch = read__fetch;
         susp->susp.free = read_free;

Index: sndwritepa.c
===================================================================
RCS file: /cvsroot/audacity/lib-src/libnyquist/nyquist/nyqsrc/sndwritepa.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- sndwritepa.c        29 Jan 2009 18:04:22 -0000      1.1
+++ sndwritepa.c        5 Mar 2009 16:34:00 -0000       1.2
@@ -37,6 +37,63 @@
 #endif
 #endif
 
+/* Previously, Nyquist would wrap samples that 
+ * overflowed -- this produces horrible output, 
+ * but makes it really easy to detect clipping,
+ * which I found helpful in my own work and good 
+ * for students too since the effect is impossible
+ * to ignore. Now that Nyquist is doing IO to
+ * libraries that clip, we're going to artificially
+ * generate the wrapping here. This is floating point
+ * wrapping, so +1.0 does not wrap (it would if it
+ * were an integer since the maximum sample value for
+ * 16-bit data is a bit less than 1.) Since this is extra
+ * overhead, I'm trying to be a bit clever by using
+ * the compare to max_sample to eliminate compares
+ * for clipping in the common case.
+ * 
+ * INPUTS: max_sample -- initially 0.0
+ *         threshold -- initially 0.0
+ *         s -- the value of the current sample
+ *         x -- if s has to be wrapped, put the value here
+ */
+#define COMPUTE_MAXIMUM_AND_WRAP(x) \
+    if (s > threshold) { \
+        if (s > max_sample) { \
+            max_sample = s; \
+            threshold = min(1.0, s); \
+        } \
+        if (s > 1.0) { \
+            s = fmod(s + 1.0, 2.0) - 1.0; \
+            (x) = s; \
+        } \
+    } else if (s < -threshold) { \
+        if (s < -max_sample) { \
+            max_sample = -s; \
+            threshold = min(1.0, -s); \
+        } \
+        if (s < -1.0) { \
+            s = -(fmod(-s + 1.0, 2.0) - 1.0); \
+            (x) = s; \
+        } \
+    }
+// the s < -threshold case is tricky: 
+//    flip the signal, do the wrap, flip again
+//    in order to pass positive values to fmod
+
+
+/* When not using PCM encodings, we do not wrap
+ * samples -- therefore float sample formats do 
+ * not wrap or clip when written to sound files
+ */
+#define COMPUTE_MAXIMUM() \
+        if (s > max_sample) { \
+            max_sample = s; \
+        } else if (s < -max_sample) { \
+            max_sample = -s; \
+        }
+
+
 /* jlh Changed these to the <> format, so it will be sought for in the
    include path */
 #include <portaudio.h>
@@ -300,6 +357,10 @@
          */ 
         if (filename[0]) {
             sndfile = sf_open((char *) filename, SFM_WRITE, &sf_info);
+            if (sndfile) {
+                /* use proper scale factor: 8000 vs 7FFF */
+                sf_command(sndfile, SFC_SET_CLIPPING, NULL, SF_TRUE);
+            }
         }
         
         if (play) 
@@ -321,6 +382,10 @@
         *sr = sf_info.samplerate;
         if (filename[0]) {
             sndfile = sf_open((char *) filename, SFM_WRITE, &sf_info);
+            if (sndfile) {
+                /* use proper scale factor: 8000 vs 7FFF */
+                sf_command(sndfile, SFC_SET_CLIPPING, NULL, SF_TRUE);
+            }
         }
         if (play)
             play = prepare_audio(play, &sf_info, &audio_stream);
@@ -345,7 +410,7 @@
 }
 
 
-/* open_for_write -- helper function for sound_save and sound_overwrite */
+/* open_for_write -- helper function for sound_overwrite */
 /*
  * if the format is RAW, then fill in sf_info according to 
  * sound sample rate and channels. Otherwise, open the file
@@ -373,10 +438,13 @@
         sprintf(error, "snd_overwrite: cannot open file %s", filename);
         xlabort(error);
     }
+    /* use proper scale factor: 8000 vs 7FFF */
+    sf_command(sndfile, SFC_SET_CLIPPING, NULL, SF_TRUE);
+    
     frames = round(offset * sf_info->samplerate);
     rslt = sf_seek(sndfile, frames, SEEK_SET);
     if (rslt < 0) {
-        sprintf(error, "snd_overwrite: cannot seek to frame %ld of %s",
+        sprintf(error, "snd_overwrite: cannot seek to frame %lld of %s",
                 frames, filename);
         xlabort(error);
     }
@@ -391,7 +459,7 @@
     }
 
     if (sf_info->samplerate != srate) {
-        sprintf(error, "%s%g%s%g%s",
+        sprintf(error, "%s%g%s%ld%s",
                 "snd_overwrite: sample rate in sound (",
                 srate,
                 ") does not match\n    sample rate in file (",
@@ -480,6 +548,13 @@
     return max_sample;
 }
 
+int is_pcm(SF_INFO *sf_info)
+{
+    long subtype = sf_info->format & SF_FORMAT_SUBMASK;
+    return (subtype == SF_FORMAT_PCM_S8 || subtype == SF_FORMAT_PCM_16 ||
+            subtype == SF_FORMAT_PCM_24 || subtype == SF_FORMAT_PCM_32);
+}
+
 
 sample_type sound_save_sound(LVAL s_as_lval, long n, SF_INFO *sf_info, 
         SNDFILE *sndfile, float *buf, long *ntotal, PaStream *audio_stream)
@@ -491,6 +566,7 @@
     long debug_unit;    /* print messages at intervals of this many samples */
     long debug_count;   /* next point at which to print a message */
     sample_type max_sample = 0.0F;
+    sample_type threshold = 0.0F;
     /* jlh    cvtfn_type cvtfn; */
     *ntotal = 0;
 
@@ -545,12 +621,17 @@
         } else {
             samps = sampblock->samples;
         }
-        for (i = 0; i < togo; i++) {
-            sample_type s = samps[i];
-            if (s > max_sample) max_sample = s;
-            else if (s < -max_sample) max_sample = -s;
+        if (is_pcm(sf_info)) {
+            for (i = 0; i < togo; i++) {
+                sample_type s = samps[i];
+                COMPUTE_MAXIMUM_AND_WRAP(samps[i]);
+            }
+        } else {
+            for (i = 0; i < togo; i++) {
+                sample_type s = samps[i];
+                COMPUTE_MAXIMUM();
+            }
         }
-
         if (sndfile) {
             sf_writef_float(sndfile, samps, togo);
         }
@@ -584,6 +665,7 @@
     long debug_unit;    /* print messages at intervals of this many samples */
     long debug_count;   /* next point at which to print a message */
     sample_type max_sample = 0.0F;
+    sample_type threshold = 0.0F;
     /*    cvtfn_type cvtfn; jlh */
 
     *ntotal = 0;
@@ -684,12 +766,21 @@
         if (terminated) break;
 
         float_bufp = (float *) buf;
-        for (j = 0; j < togo; j++) {
-            for (i = 0; i < chans; i++) {
-                float s = (float) (*(state[i].ptr++) * (float) 
state[i].scale); 
-                *float_bufp++ = s;
-                if (s > max_sample) max_sample = s;
-                else if (s < -max_sample) max_sample = -s;
+        if (is_pcm(sf_info)) {
+            for (j = 0; j < togo; j++) {
+                for (i = 0; i < chans; i++) {
+                    float s = (float) (*(state[i].ptr++) * (float) 
state[i].scale);
+                    COMPUTE_MAXIMUM_AND_WRAP(s);
+                    *float_bufp++ = s;
+                }
+            }
+        } else {
+            for (j = 0; j < togo; j++) {
+                for (i = 0; i < chans; i++) {
+                    float s = (float) (*(state[i].ptr++) * (float) 
state[i].scale);
+                    COMPUTE_MAXIMUM();
+                    *float_bufp++ = s;
+                }
             }
         }
         /* Here we have interleaved floats. Before converting to the sound


Index: sndfnint.lsp
===================================================================
RCS file: /cvsroot/audacity/lib-src/libnyquist/nyquist/nyqsrc/sndfnint.lsp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- sndfnint.lsp        29 Jan 2009 18:04:21 -0000      1.1
+++ sndfnint.lsp        5 Mar 2009 16:34:00 -0000       1.2
@@ -1,3 +1,83 @@
+ (setf snd-head-none 0) 
+
+ (setf snd-head-AIFF 1) 
+
+ (setf snd-head-IRCAM 2) 
+
+ (setf snd-head-NeXT 3) 
+
+ (setf snd-head-Wave 4) 
+
+ (setf snd-head-PAF 5) 
+
+ (setf snd-head-SVX 6) 
+
+ (setf snd-head-NIST 7) 
+
+ (setf snd-head-VOC 8) 
+
+ (setf snd-head-W64 9) 
+
+ (setf snd-head-MAT4 10) 
+
+ (setf snd-head-MAT5 11) 
+
+ (setf snd-head-PVF 12) 
+
+ (setf snd-head-XI 13) 
+
+ (setf snd-head-HTK 14) 
+
+ (setf snd-head-SDS 15) 
+
+ (setf snd-head-AVR 16) 
+
+ (setf snd-head-SD2 17) 
+
+ (setf snd-head-FLAC 18) 
+
+ (setf snd-head-CAF 19) 
+
+ (setf snd-head-raw 20) 
+
+ (setf snd-head-channels 1) 
+
+ (setf snd-head-mode 2) 
+
+ (setf snd-head-bits 4) 
+
+ (setf snd-head-srate 8) 
+
+ (setf snd-head-dur 16) 
+
+ (setf snd-head-latency 32) 
+
+ (setf snd-head-type 64) 
+
+ (setf snd-mode-adpcm 0) 
+
+ (setf snd-mode-pcm 1) 
+
+ (setf snd-mode-ulaw 2) 
+
+ (setf snd-mode-alaw 3) 
+
+ (setf snd-mode-float 4) 
+
+ (setf snd-mode-upcm 5) 
+
+ (setf snd-mode-unknown 6) 
+
+ (setf snd-mode-double 7) 
+
+ (setf snd-mode-GSM610 8) 
+
+ (setf snd-mode-DWVW 9) 
+
+ (setf snd-mode-DPCM 10) 
+
+ (setf snd-mode-msadpcm 11) 
+
  (SETF MAX-STOP-TIME 10E20) 
 
  (SETF MIN-START-TIME -10E20) 


------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
Audacity-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/audacity-cvs

Reply via email to