Changeset a47cd35 for src


Ignore:
Timestamp:
Nov 3, 2007, 2:52:34 PM (17 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/pydocstrings, feature/timestretch, fix/ffmpeg5, master, pitchshift, sampler, timestretch, yinfft+
Children:
398c1c5
Parents:
01af943
Message:

fft.{c,h}: remove tabs

Location:
src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/fft.c

    r01af943 ra47cd35  
    2424
    2525#if FFTW3F_SUPPORT
    26 #define fftw_malloc             fftwf_malloc
    27 #define fftw_free               fftwf_free
    28 #define fftw_execute            fftwf_execute
    29 #define fftw_plan_dft_r2c_1d    fftwf_plan_dft_r2c_1d
    30 #define fftw_plan_dft_c2r_1d    fftwf_plan_dft_c2r_1d
    31 #define fftw_plan_r2r_1d      fftwf_plan_r2r_1d
    32 #define fftw_plan               fftwf_plan
    33 #define fftw_destroy_plan       fftwf_destroy_plan
     26#define fftw_malloc            fftwf_malloc
     27#define fftw_free              fftwf_free
     28#define fftw_execute           fftwf_execute
     29#define fftw_plan_dft_r2c_1d   fftwf_plan_dft_r2c_1d
     30#define fftw_plan_dft_c2r_1d   fftwf_plan_dft_c2r_1d
     31#define fftw_plan_r2r_1d       fftwf_plan_r2r_1d
     32#define fftw_plan              fftwf_plan
     33#define fftw_destroy_plan      fftwf_destroy_plan
    3434#endif
    3535
     
    4141
    4242struct _aubio_fft_t {
    43         uint_t fft_size;
    44         uint_t channels;
    45         real_t          *in, *out;
    46         fft_data_t      *specdata;
    47         fftw_plan       pfw, pbw;
     43  uint_t fft_size;
     44  uint_t channels;
     45  real_t    *in, *out;
     46  fft_data_t   *specdata;
     47  fftw_plan   pfw, pbw;
    4848};
    4949
     
    5151
    5252aubio_fft_t * new_aubio_fft(uint_t size) {
    53         aubio_fft_t * s = AUBIO_NEW(aubio_fft_t);
    54         /* allocate memory */
    55         s->in       = AUBIO_ARRAY(real_t,size);
    56         s->out      = AUBIO_ARRAY(real_t,size);
    57         /* create plans */
     53  aubio_fft_t * s = AUBIO_NEW(aubio_fft_t);
     54  /* allocate memory */
     55  s->in       = AUBIO_ARRAY(real_t,size);
     56  s->out      = AUBIO_ARRAY(real_t,size);
     57  /* create plans */
    5858#ifdef HAVE_COMPLEX_H
    5959  s->fft_size = size/2+1;
    60         s->specdata = (fft_data_t*)fftw_malloc(sizeof(fft_data_t)*s->fft_size);
    61         s->pfw = fftw_plan_dft_r2c_1d(size, s->in,  s->specdata, FFTW_ESTIMATE);
    62         s->pbw = fftw_plan_dft_c2r_1d(size, s->specdata, s->out, FFTW_ESTIMATE);
     60  s->specdata = (fft_data_t*)fftw_malloc(sizeof(fft_data_t)*s->fft_size);
     61  s->pfw = fftw_plan_dft_r2c_1d(size, s->in,  s->specdata, FFTW_ESTIMATE);
     62  s->pbw = fftw_plan_dft_c2r_1d(size, s->specdata, s->out, FFTW_ESTIMATE);
    6363#else
    6464  s->fft_size = size;
    65         s->specdata = (fft_data_t*)fftw_malloc(sizeof(fft_data_t)*s->fft_size);
    66         s->pfw = fftw_plan_r2r_1d(size, s->in,  s->specdata, FFTW_R2HC, FFTW_ESTIMATE);
    67         s->pbw = fftw_plan_r2r_1d(size, s->specdata, s->out, FFTW_HC2R, FFTW_ESTIMATE);
     65  s->specdata = (fft_data_t*)fftw_malloc(sizeof(fft_data_t)*s->fft_size);
     66  s->pfw = fftw_plan_r2r_1d(size, s->in,  s->specdata, FFTW_R2HC, FFTW_ESTIMATE);
     67  s->pbw = fftw_plan_r2r_1d(size, s->specdata, s->out, FFTW_HC2R, FFTW_ESTIMATE);
    6868#endif
    69         return s;
     69  return s;
    7070}
    7171
    7272void del_aubio_fft(aubio_fft_t * s) {
    73         /* destroy data */
    74         fftw_destroy_plan(s->pfw);
    75         fftw_destroy_plan(s->pbw);
    76         fftw_free(s->specdata);
    77         AUBIO_FREE(s->out);
    78         AUBIO_FREE(s->in );
    79         AUBIO_FREE(s);
     73  /* destroy data */
     74  fftw_destroy_plan(s->pfw);
     75  fftw_destroy_plan(s->pbw);
     76  fftw_free(s->specdata);
     77  AUBIO_FREE(s->out);
     78  AUBIO_FREE(s->in );
     79  AUBIO_FREE(s);
    8080}
    8181
    8282void aubio_fft_do(const aubio_fft_t * s,
    83                 const smpl_t * data, fft_data_t * spectrum,
    84                 const uint_t size) {
    85         uint_t i;
    86         for (i=0;i<size;i++) s->in[i] = data[i];
    87         fftw_execute(s->pfw);
    88         for (i=0; i < s->fft_size; i++) spectrum[i] = s->specdata[i];
     83    const smpl_t * data, fft_data_t * spectrum, const uint_t size) {
     84  uint_t i;
     85  for (i=0;i<size;i++) s->in[i] = data[i];
     86  fftw_execute(s->pfw);
     87  for (i=0; i < s->fft_size; i++) spectrum[i] = s->specdata[i];
    8988}
    9089
    9190void aubio_fft_rdo(const aubio_fft_t * s,
    92                 const fft_data_t * spectrum,
    93                 smpl_t * data,
    94                 const uint_t size) {
    95         uint_t i;
    96         const smpl_t renorm = 1./(smpl_t)size;
    97         for (i=0; i < s->fft_size; i++) s->specdata[i] = spectrum[i];
    98         fftw_execute(s->pbw);
    99         for (i=0;i<size;i++) data[i] = s->out[i]*renorm;
     91    const fft_data_t * spectrum, smpl_t * data, const uint_t size) {
     92  uint_t i;
     93  const smpl_t renorm = 1./(smpl_t)size;
     94  for (i=0; i < s->fft_size; i++) s->specdata[i] = spectrum[i];
     95  fftw_execute(s->pbw);
     96  for (i=0;i<size;i++) data[i] = s->out[i]*renorm;
    10097}
    10198
     
    103100
    104101void aubio_fft_getnorm(smpl_t * norm, fft_data_t * spectrum, uint_t size) {
    105         uint_t i;
    106         for (i=0;i<size/2+1;i++) norm[i] = ABSC(spectrum[i]);
    107         //for (i=0;i<size/2+1;i++) AUBIO_DBG("%f\n", norm[i]);
     102  uint_t i;
     103  for (i=0;i<size/2+1;i++) norm[i] = ABSC(spectrum[i]);
    108104}
    109105
    110106void aubio_fft_getphas(smpl_t * phas, fft_data_t * spectrum, uint_t size) {
    111         uint_t i;
    112         for (i=0;i<size/2+1;i++) phas[i] = ARGC(spectrum[i]);
    113         //for (i=0;i<size/2+1;i++) AUBIO_DBG("%f\n", phas[i]);
     107  uint_t i;
     108  for (i=0;i<size/2+1;i++) phas[i] = ARGC(spectrum[i]);
    114109}
    115110
     
    125120
    126121void aubio_fft_getnorm(smpl_t * norm, fft_data_t * spectrum, uint_t size) {
    127         uint_t i;
     122  uint_t i;
    128123  norm[0] = SQR(spectrum[0]);
    129         for (i=1;i<size/2;i++) norm[i] = (SQR(spectrum[i]) + SQR(spectrum[size-i]));
    130         norm[size/2] = SQR(spectrum[size/2]);
    131         //for (i=0;i<size/2+1;i++) AUBIO_DBG("%f\n", norm[i]);
     124  for (i=1;i<size/2;i++) norm[i] = (SQR(spectrum[i]) + SQR(spectrum[size-i]));
     125  norm[size/2] = SQR(spectrum[size/2]);
    132126}
    133127
    134128void aubio_fft_getphas(smpl_t * phas, fft_data_t * spectrum, uint_t size) {
    135         uint_t i;
     129  uint_t i;
    136130  phas[0] = 0;
    137         for (i=1;i<size/2+1;i++) phas[i] = atan2f(spectrum[size-i] , spectrum[i]);
     131  for (i=1;i<size/2+1;i++) phas[i] = atan2f(spectrum[size-i] , spectrum[i]);
    138132  phas[size/2] = 0;
    139         //for (i=0;i<size/2+1;i++) AUBIO_DBG("%f\n", phas[i]);
    140133}
    141134
     
    161154
    162155aubio_mfft_t * new_aubio_mfft(uint_t winsize, uint_t channels){
    163         uint_t i;
    164         aubio_mfft_t * fft = AUBIO_NEW(aubio_mfft_t);
    165         fft->winsize       = winsize;
    166         fft->channels      = channels;
    167         fft->fft           = new_aubio_fft(winsize);
    168         fft->spec          = AUBIO_ARRAY(fft_data_t*,channels);
    169         for (i=0; i < channels; i++)
    170                 fft->spec[i] = AUBIO_ARRAY(fft_data_t,winsize);
    171         return fft;
     156  uint_t i;
     157  aubio_mfft_t * fft = AUBIO_NEW(aubio_mfft_t);
     158  fft->winsize       = winsize;
     159  fft->channels      = channels;
     160  fft->fft           = new_aubio_fft(winsize);
     161  fft->spec          = AUBIO_ARRAY(fft_data_t*,channels);
     162  for (i=0; i < channels; i++)
     163    fft->spec[i] = AUBIO_ARRAY(fft_data_t,winsize);
     164  return fft;
    172165}
    173166
    174167/* execute stft */
    175168void aubio_mfft_do (aubio_mfft_t * fft,fvec_t * in,cvec_t * fftgrain){
    176         uint_t i=0;
    177         /* execute stft */
    178         for (i=0; i < fft->channels; i++) {
    179                 aubio_fft_do (fft->fft,in->data[i],fft->spec[i],fft->winsize);
    180                 /* put norm and phase into fftgrain */
    181                 aubio_fft_getnorm(fftgrain->norm[i], fft->spec[i], fft->winsize);
    182                 aubio_fft_getphas(fftgrain->phas[i], fft->spec[i], fft->winsize);
    183         }
     169  uint_t i=0;
     170  /* execute stft */
     171  for (i=0; i < fft->channels; i++) {
     172    aubio_fft_do (fft->fft,in->data[i],fft->spec[i],fft->winsize);
     173    /* put norm and phase into fftgrain */
     174    aubio_fft_getnorm(fftgrain->norm[i], fft->spec[i], fft->winsize);
     175    aubio_fft_getphas(fftgrain->phas[i], fft->spec[i], fft->winsize);
     176  }
    184177}
    185178
    186179/* execute inverse fourier transform */
    187180void aubio_mfft_rdo(aubio_mfft_t * fft,cvec_t * fftgrain, fvec_t * out){
    188         uint_t i=0;
    189         for (i=0; i < fft->channels; i++) {
    190                 aubio_fft_getspectrum(fft->spec[i],fftgrain->norm[i],fftgrain->phas[i],fft->winsize);
    191                 aubio_fft_rdo(fft->fft,fft->spec[i],out->data[i],fft->winsize);
    192         }
     181  uint_t i=0;
     182  for (i=0; i < fft->channels; i++) {
     183    aubio_fft_getspectrum(fft->spec[i],fftgrain->norm[i],fftgrain->phas[i],fft->winsize);
     184    aubio_fft_rdo(fft->fft,fft->spec[i],out->data[i],fft->winsize);
     185  }
    193186}
    194187
    195188void del_aubio_mfft(aubio_mfft_t * fft) {
    196         uint_t i;
    197         for (i=0; i < fft->channels; i++)
    198                 AUBIO_FREE(fft->spec[i]);
    199         AUBIO_FREE(fft->spec);
    200         del_aubio_fft(fft->fft);
    201         AUBIO_FREE(fft);       
     189  uint_t i;
     190  for (i=0; i < fft->channels; i++)
     191    AUBIO_FREE(fft->spec[i]);
     192  AUBIO_FREE(fft->spec);
     193  del_aubio_fft(fft->fft);
     194  AUBIO_FREE(fft);       
    202195}
  • src/fft.h

    r01af943 ra47cd35  
    11/*
    2         Copyright (C) 2003 Paul Brossier
     2  Copyright (C) 2003 Paul Brossier
    33
    4         This program is free software; you can redistribute it and/or modify
    5         it under the terms of the GNU General Public License as published by
    6         the Free Software Foundation; either version 2 of the License, or
    7         (at your option) any later version.
     4  This program is free software; you can redistribute it and/or modify
     5  it under the terms of the GNU General Public License as published by
     6  the Free Software Foundation; either version 2 of the License, or
     7  (at your option) any later version.
    88
    9         This program is distributed in the hope that it will be useful,
    10         but WITHOUT ANY WARRANTY; without even the implied warranty of
    11         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    12         GNU General Public License for more details.
     9  This program is distributed in the hope that it will be useful,
     10  but WITHOUT ANY WARRANTY; without even the implied warranty of
     11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     12  GNU General Public License for more details.
    1313
    14         You should have received a copy of the GNU General Public License
    15         along with this program; if not, write to the Free Software
    16         Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
    17        
     14  You should have received a copy of the GNU General Public License
     15  along with this program; if not, write to the Free Software
     16  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
     17 
    1818*/
    1919
Note: See TracChangeset for help on using the changeset viewer.