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

Modified Files:
        biquadfilt.alg biquadfilt.h ifft.alg ifft.c translate.lsp 
Log Message:
Updating to Nyquist v3.03.


Index: ifft.alg
===================================================================
RCS file: /cvsroot/audacity/lib-src/libnyquist/nyquist/tran/ifft.alg,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- ifft.alg    29 Jan 2009 18:04:24 -0000      1.1
+++ ifft.alg    5 Mar 2009 16:34:00 -0000       1.2
@@ -39,7 +39,7 @@
  */
 
 #include \"samples.h\"
-#include \"fftn.h\"
+#include \"fftext.h\"
 
 #define MUST_BE_FLONUM(e) \\
     if (!(e) || ntype(e) != FLONUM) { xlerror(\"flonum expected\", (e)); }
@@ -80,8 +80,7 @@
         }
         if (susp->index >= susp->stepsize) {
             long i;
-            long half_i;
-            long n;
+            long m, n;
             LVAL elem;
             susp->index = 0;
             susp->array = 
@@ -102,47 +101,49 @@
                 if (susp->window && (susp->window_len != susp->length))
                     xlerror(\"window size and spectrum size differ\", 
                             susp->array);
-                susp->samples = 
-                    (sample_type *) calloc(susp->length * 2,
-                                           sizeof(sample_type));
+                /* tricky non-power of 2 detector: only if this is a
+                 * power of 2 will the highest 1 bit be cleared when
+                 * we subtract 1 ...
+                 */
+                if (susp->length & (susp->length - 1))
+                    xlfail(\"spectrum size must be a power of 2\");
+                susp->samples = (sample_type *) calloc(susp->length,
+                                                       sizeof(sample_type));
                 susp->outbuf = (sample_type *) calloc(susp->length, 
-                    sizeof(sample_type));
+                                                      sizeof(sample_type));
             } else if (getsize(susp->array) != susp->length) {
                 xlerror(\"arrays must all be the same length\", susp->array);
             }
 
             /* at this point, we have a new array to put samples */
-            /* real part will be susp->samples[0:n-1], */
-            /* im part in samples[n:2*n-1] */
+            /* the incoming array format is [DC, R1, I1, R2, I2, ... RN]
+             * where RN is the real coef at the Nyquist frequency
+             * but susp->samples should be organized as [DC, RN, R1, I1, ...]
+             */
             n = susp->length;
+            /* get the DC (real) coef */
             elem = getelement(susp->array, 0);
             MUST_BE_FLONUM(elem)
             susp->samples[0] = (sample_type) getflonum(elem);
-            susp->samples[n] = 0;
-            half_i = 0;
-            for (i = 1; i < n - 1; i += 2) {
-                half_i++;
-                elem = getelement(susp->array, i);
-                MUST_BE_FLONUM(elem)
-                susp->samples[half_i] = susp->samples[n - half_i] = 
-                    (sample_type) (getflonum(elem) / 2.0);
 
-                elem = getelement(susp->array, i + 1);
-                MUST_BE_FLONUM(elem)
-                susp->samples[n + half_i] =
-                    -(susp->samples[2*n - half_i] =
-                          (sample_type) (getflonum(elem) / 2.0));
-            }
-            if (n % 2 == 0) {
-                elem = getelement(susp->array, n - 1);
+            /* get the Nyquist (real) coef */
+            elem = getelement(susp->array, n - 1);
+            MUST_BE_FLONUM(elem);
+            susp->samples[1] = (sample_type) getflonum(elem);
+
+            /* get the remaining coef */
+            for (i = 1; i < n - 1; i++) {
+                elem = getelement(susp->array, i);
                 MUST_BE_FLONUM(elem)
-                susp->samples[n / 2] = (sample_type) getflonum(elem);
-                susp->samples[n + (n / 2)] = 0;
+                susp->samples[i + 1] = (sample_type) getflonum(elem);
             }
             susp->array = NULL; /* free the array */
 
             /* here is where the IFFT and windowing should take place */
-            fftnf(1, &n, susp->samples, susp->samples + n, -1, 1.0);
+            //fftnf(1, &n, susp->samples, susp->samples + n, -1, 1.0);
+            m = round(log2(n));
+            if (!fftInit(m)) riffts(susp->samples, m, 1);
+            else xlfail(\"FFT initialization error\");
             if (susp->window) {
                 n = susp->length;
                 for (i = 0; i < n; i++) {
@@ -166,23 +167,6 @@
             for (i = 0; i < n; i++) {
                 susp->outbuf[i] += susp->samples[i];
             }
-/*
-            temp_fft = (double *) malloc (susp->length * sizeof(double));
-            if (temp_fft == 0) return;
-            big_samples = (double *) malloc (susp->length * sizeof(double));
-            if (big_samples == 0) return;
-            for (i = 0; i < susp->length; i++) {
-                big_samples[i] = (double) susp->samples[i];
-            }
-            rp = rfftw_create_plan(susp->length, FFTW_COMPLEX_TO_REAL, 
FFTW_ESTIMATE);
-            rfftw_one(rp, big_samples, temp_fft);
-            rfftw_destroy_plan(rp);
-            free(big_samples);
-            for (i = 0; i < susp->length; i++) {
-                setelement(result, i, cvflonum(temp_fft[i]));
-            }
-            free (temp_fft);
-*/
         }
         togo = min(togo, susp->stepsize - susp->index);
 ")

Index: ifft.c
===================================================================
RCS file: /cvsroot/audacity/lib-src/libnyquist/nyquist/tran/ifft.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- ifft.c      29 Jan 2009 18:04:24 -0000      1.1
+++ ifft.c      5 Mar 2009 16:34:00 -0000       1.2
@@ -1,4 +1,6 @@
 #include "stdio.h"
+#define _USE_MATH_DEFINES 1 /* for Visual C++ to get M_LN2 */
+#include <math.h>
 #ifndef mips
 #include "stdlib.h"
 #endif
@@ -63,7 +65,7 @@
  */
 
 #include "samples.h"
-#include "fftn.h"
+#include "fftext.h"
 
 #define MUST_BE_FLONUM(e) \
     if (!(e) || ntype(e) != FLONUM) { xlerror("flonum expected", (e)); }
@@ -111,8 +113,7 @@
         }
         if (susp->index >= susp->stepsize) {
             long i;
-            long half_i;
-            int n;
+            long m, n;
             LVAL elem;
             susp->index = 0;
             susp->array = 
@@ -133,47 +134,49 @@
                 if (susp->window && (susp->window_len != susp->length))
                     xlerror("window size and spectrum size differ", 
                             susp->array);
-                susp->samples = 
-                    (sample_type *) calloc(susp->length * 2,
-                                           sizeof(sample_type));
+                /* tricky non-power of 2 detector: only if this is a
+                 * power of 2 will the highest 1 bit be cleared when
+                 * we subtract 1 ...
+                 */
+                if (susp->length & (susp->length - 1))
+                    xlfail("spectrum size must be a power of 2");
+                susp->samples = (sample_type *) calloc(susp->length,
+                                                       sizeof(sample_type));
                 susp->outbuf = (sample_type *) calloc(susp->length, 
-                    sizeof(sample_type));
+                                                      sizeof(sample_type));
             } else if (getsize(susp->array) != susp->length) {
                 xlerror("arrays must all be the same length", susp->array);
             }
 
             /* at this point, we have a new array to put samples */
-            /* real part will be susp->samples[0:n-1], */
-            /* im part in samples[n:2*n-1] */
+            /* the incoming array format is [DC, R1, I1, R2, I2, ... RN]
+             * where RN is the real coef at the Nyquist frequency
+             * but susp->samples should be organized as [DC, RN, R1, I1, ...]
+             */
             n = susp->length;
+            /* get the DC (real) coef */
             elem = getelement(susp->array, 0);
             MUST_BE_FLONUM(elem)
             susp->samples[0] = (sample_type) getflonum(elem);
-            susp->samples[n] = 0;
-            half_i = 0;
-            for (i = 1; i < n - 1; i += 2) {
-                half_i++;
-                elem = getelement(susp->array, i);
-                MUST_BE_FLONUM(elem)
-                susp->samples[half_i] = susp->samples[n - half_i] = 
-                    (sample_type) (getflonum(elem) / 2.0);
 
-                elem = getelement(susp->array, i + 1);
-                MUST_BE_FLONUM(elem)
-                susp->samples[n + half_i] =
-                    -(susp->samples[2*n - half_i] =
-                          (sample_type) (getflonum(elem) / 2.0));
-            }
-            if (n % 2 == 0) {
-                elem = getelement(susp->array, n - 1);
+            /* get the Nyquist (real) coef */
+            elem = getelement(susp->array, n - 1);
+            MUST_BE_FLONUM(elem);
+            susp->samples[1] = (sample_type) getflonum(elem);
+
+            /* get the remaining coef */
+            for (i = 1; i < n - 1; i++) {
+                elem = getelement(susp->array, i);
                 MUST_BE_FLONUM(elem)
-                susp->samples[n / 2] = (sample_type) getflonum(elem);
-                susp->samples[n + (n / 2)] = 0;
+                susp->samples[i + 1] = (sample_type) getflonum(elem);
             }
             susp->array = NULL; /* free the array */
 
             /* here is where the IFFT and windowing should take place */
-            fftnf(1, &n, susp->samples, susp->samples + n, -1, 1.0);
+            //fftnf(1, &n, susp->samples, susp->samples + n, -1, 1.0);
+            m = round(log(n) / M_LN2);
+            if (!fftInit(m)) riffts(susp->samples, m, 1);
+            else xlfail("FFT initialization error");
             if (susp->window) {
                 n = susp->length;
                 for (i = 0; i < n; i++) {
@@ -197,23 +200,6 @@
             for (i = 0; i < n; i++) {
                 susp->outbuf[i] += susp->samples[i];
             }
-/*
-            temp_fft = (double *) malloc (susp->length * sizeof(double));
-            if (temp_fft == 0) return;
-            big_samples = (double *) malloc (susp->length * sizeof(double));
-            if (big_samples == 0) return;
-            for (i = 0; i < susp->length; i++) {
-                big_samples[i] = (double) susp->samples[i];
-            }
-            rp = rfftw_create_plan(susp->length, FFTW_COMPLEX_TO_REAL, 
FFTW_ESTIMATE);
-            rfftw_one(rp, big_samples, temp_fft);
-            rfftw_destroy_plan(rp);
-            free(big_samples);
-            for (i = 0; i < susp->length; i++) {
-                setelement(result, i, cvflonum(temp_fft[i]));
-            }
-            free (temp_fft);
-*/
         }
         togo = min(togo, susp->stepsize - susp->index);
 

Index: biquadfilt.alg
===================================================================
RCS file: /cvsroot/audacity/lib-src/libnyquist/nyquist/tran/biquadfilt.alg,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- biquadfilt.alg      29 Jan 2009 18:04:23 -0000      1.1
+++ biquadfilt.alg      5 Mar 2009 16:34:00 -0000       1.2
@@ -4,6 +4,7 @@
 
 (SNDBIQUAD-ALG
 (NAME "biquadfilt")
+(LISPNAME "biquad")
 (ARGUMENTS ("sound_type" "s") 
         ("double" "b0") ("double" "b1") ("double" "b2") 
                          ("double" "a1") ("double" "a2")

Index: biquadfilt.h
===================================================================
RCS file: /cvsroot/audacity/lib-src/libnyquist/nyquist/tran/biquadfilt.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- biquadfilt.h        29 Jan 2009 18:04:23 -0000      1.1
+++ biquadfilt.h        5 Mar 2009 16:34:00 -0000       1.2
@@ -1,6 +1,3 @@
 sound_type snd_make_biquadfilt(sound_type s, double b0, double b1, double b2, 
double a1, double a2, double z1init, double z2init);
 sound_type snd_biquadfilt(sound_type s, double b0, double b1, double b2, 
double a1, double a2, double z1init, double z2init);
     /* LISP: (snd-biquad SOUND ANYNUM ANYNUM ANYNUM ANYNUM ANYNUM ANYNUM 
ANYNUM) */
-    /* note: snd_biquadfilt is used to avoid naming conflict with STK's BiQuad 
-     *       class, but the Lisp function name is SND-BIQUAD.
-     */

Index: translate.lsp
===================================================================
RCS file: /cvsroot/audacity/lib-src/libnyquist/nyquist/tran/translate.lsp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- translate.lsp       29 Jan 2009 18:04:26 -0000      1.1
+++ translate.lsp       5 Mar 2009 16:34:00 -0000       1.2
@@ -770,7 +770,7 @@
 
   (dolist 
        (slot 
-     '(name inner-loop sample-rate support-functions inline-interpolation delay
+     '(name lispname inner-loop sample-rate support-functions 
inline-interpolation delay
        )) 
        (put-slot alg (car (get-slot alg slot)) slot))
 
@@ -850,7 +850,9 @@
 (defun write-header (alg stream)
 ;;  (format stream "sound_type snd_make_~A();~%" (get-slot alg 'name))
     (let ((arguments (get-slot alg 'arguments))
-      (name (get-slot alg 'name)))
+      (name (get-slot alg 'name))
+      (lisp-name (get-slot alg 'lispname)))
+       (cond ((null lisp-name) (setf lisp-name name)))
        (format stream "sound_type snd_make_~A" name)
        (write-ansi-prototype-list stream "" arguments)
        (format stream ";~%")
@@ -861,7 +863,7 @@
        (format stream ";~%")
 
        ; write the type specification for intgen
-       (format stream "    /* LISP: (snd-~A" name)
+       (format stream "    /* LISP: (snd-~A" lisp-name)
        (dolist (arg arguments)
      (let ((xltype (assoc (car arg) c-to-xlisp-type :test #'equal)))
        (cond ((null xltype)


------------------------------------------------------------------------------
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