home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 November / CMCD1104.ISO / Software / Complet / ZynAddFX / Setup_ZynAddSubFX-2.1.1.exe / FFTwrapper.C < prev    next >
Encoding:
C/C++ Source or Header  |  2004-03-05  |  3.0 KB  |  98 lines

  1. /*
  2.   ZynAddSubFX - a software synthesizer
  3.  
  4.   FFTwrapper.c  -  A wrapper for Fast Fourier Transforms
  5.   Copyright (C) 2002-2004 Nasca Octavian Paul
  6.   Author: Nasca Octavian Paul
  7.  
  8.   This program is free software; you can redistribute it and/or modify
  9.   it under the terms of version 2 of the GNU General Public License 
  10.   as published by the Free Software Foundation.
  11.  
  12.   This program is distributed in the hope that it will be useful,
  13.   but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.   GNU General Public License (version 2) for more details.
  16.  
  17.   You should have received a copy of the GNU General Public License (version 2)
  18.   along with this program; if not, write to the Free Software Foundation,
  19.   Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
  20.  
  21. */
  22.  
  23. #include <math.h>
  24. #include "FFTwrapper.h"
  25.  
  26. FFTwrapper::FFTwrapper(int fftsize_){
  27.     fftsize=fftsize_;
  28.     tmpfftdata1=new fftw_real[fftsize];
  29.     tmpfftdata2=new fftw_real[fftsize];
  30. #ifdef FFTW_VERSION_2
  31.     planfftw=rfftw_create_plan(fftsize,FFTW_REAL_TO_COMPLEX,FFTW_ESTIMATE|FFTW_IN_PLACE);
  32.     planfftw_inv=rfftw_create_plan(fftsize,FFTW_COMPLEX_TO_REAL,FFTW_ESTIMATE|FFTW_IN_PLACE);
  33. #else
  34.     planfftw=fftw_plan_r2r_1d(fftsize,tmpfftdata1,tmpfftdata1,FFTW_R2HC,FFTW_ESTIMATE);
  35.     planfftw_inv=fftw_plan_r2r_1d(fftsize,tmpfftdata2,tmpfftdata2,FFTW_HC2R,FFTW_ESTIMATE);
  36. #endif
  37. };
  38.  
  39. FFTwrapper::~FFTwrapper(){
  40. #ifdef FFTW_VERSION_2
  41.     rfftw_destroy_plan(planfftw);
  42.     rfftw_destroy_plan(planfftw_inv);
  43. #else 
  44.     fftw_destroy_plan(planfftw);
  45.     fftw_destroy_plan(planfftw_inv);
  46. #endif
  47.  
  48.     delete (tmpfftdata1);
  49.     delete (tmpfftdata2);
  50. };
  51.  
  52. /*
  53.  * do the Fast Fourier Transform
  54.  */
  55. void FFTwrapper::smps2freqs(REALTYPE *smps,REALTYPE *freqs){
  56. #ifdef FFTW_VERSION_2
  57.     for (int i=0;i<fftsize;i++) tmpfftdata1[i]=smps[i];
  58.     if (freqs==NULL) {
  59.         rfftw_one(planfftw,tmpfftdata1,NULL);
  60.             for (int i=0;i<fftsize;i++) smps[i]=tmpfftdata1[i];
  61.     } else { 
  62.         rfftw_one(planfftw,tmpfftdata1,tmpfftdata2);
  63.         for (int i=0;i<fftsize;i++) freqs[i]=tmpfftdata2[i];
  64.     };
  65. #else
  66.     for (int i=0;i<fftsize;i++) tmpfftdata1[i]=smps[i];
  67.     fftw_execute(planfftw);
  68.     if (freqs==NULL) for (int i=0;i<fftsize;i++) smps[i]=tmpfftdata1[i];
  69.     else for (int i=0;i<fftsize;i++) freqs[i]=tmpfftdata1[i];
  70. #endif
  71. };
  72.  
  73. /*
  74.  * do the Inverse Fast Fourier Transform
  75.  */
  76. void FFTwrapper::freqs2smps(REALTYPE *freqs,REALTYPE *smps){
  77. #ifdef FFTW_VERSION_2
  78.     for (int i=0;i<fftsize;i++) tmpfftdata1[i]=freqs[i];
  79.     if (smps==NULL) {
  80.         rfftw_one(planfftw_inv,tmpfftdata1,NULL);
  81.         for (int i=0;i<fftsize;i++) freqs[i]=tmpfftdata1[i];
  82.     } else {
  83.         rfftw_one(planfftw_inv,tmpfftdata1,tmpfftdata2);
  84.         for (int i=0;i<fftsize;i++) smps[i]=tmpfftdata2[i];
  85.     };
  86. #else
  87.     for (int i=0;i<fftsize;i++) tmpfftdata2[i]=freqs[i];
  88.     fftw_execute(planfftw_inv);
  89.     if (smps==NULL) for (int i=0;i<fftsize;i++) freqs[i]=tmpfftdata2[i];
  90.     else for (int i=0;i<fftsize;i++) smps[i]=tmpfftdata2[i];
  91. #endif
  92.  
  93. };
  94.  
  95.  
  96.  
  97.  
  98.