Changeset f88a326 for src


Ignore:
Timestamp:
May 28, 2005, 2:53:13 AM (19 years ago)
Author:
Paul Brossier <piem@altern.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:
946cad3
Parents:
f8714ee
Message:

added simplified mfft interface

Location:
src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/fft.c

    rf8714ee rf88a326  
    7878void del_aubio_fft(aubio_fft_t * s) {
    7979        aubio_fft_free(s);
     80        AUBIO_FREE(s);
    8081}
    8182
     
    111112}
    112113
     114
     115/* new interface aubio_mfft */
     116struct _aubio_mfft_t {
     117        aubio_fft_t * fft;      /* fftw interface */
     118        fft_data_t ** spec;     /* complex spectral data */
     119        uint_t winsize;
     120        uint_t channels;
     121};
     122
     123aubio_mfft_t * new_aubio_mfft(uint_t winsize, uint_t channels){
     124        uint_t i;
     125        aubio_mfft_t * fft = AUBIO_NEW(aubio_mfft_t);
     126        fft->winsize       = winsize;
     127        fft->channels      = channels;
     128        fft->fft           = new_aubio_fft(winsize);
     129        fft->spec          = AUBIO_ARRAY(fft_data_t*,channels);
     130        for (i=0; i < channels; i++)
     131                fft->spec[i] = AUBIO_ARRAY(fft_data_t,winsize);
     132        return fft;
     133}
     134
     135/* execute stft */
     136void aubio_mfft_do (aubio_mfft_t * fft,fvec_t * in,cvec_t * fftgrain){
     137        uint_t i=0;
     138        /* execute stft */
     139        for (i=0; i < fft->channels; i++) {
     140                aubio_fft_do (fft->fft,in->data[i],fft->spec[i],fft->winsize);
     141                /* put norm and phase into fftgrain */
     142                aubio_fft_getnorm(fftgrain->norm[i], fft->spec[i], fft->winsize/2+1);
     143                aubio_fft_getphas(fftgrain->phas[i], fft->spec[i], fft->winsize/2+1);
     144        }
     145}
     146
     147/* execute inverse fourier transform */
     148void aubio_mfft_rdo(aubio_mfft_t * fft,cvec_t * fftgrain, fvec_t * out){
     149        uint_t i=0,j;
     150        for (i=0; i < fft->channels; i++) {
     151                for (j=0; j<fft->winsize/2+1; j++) {
     152                        fft->spec[i][j]  = CEXPC(I*unwrap2pi(fftgrain->phas[i][j]));
     153                        fft->spec[i][j] *= fftgrain->norm[i][j];
     154                }
     155                aubio_fft_rdo(fft->fft,fft->spec[i],out->data[i],fft->winsize);
     156        }
     157}
     158
     159void del_aubio_mfft(aubio_mfft_t * fft) {
     160        uint_t i;
     161        for (i=0; i < fft->channels; i++)
     162                AUBIO_FREE(fft->spec[i]);
     163        AUBIO_FREE(fft->spec);
     164        aubio_fft_free(fft->fft);
     165        AUBIO_FREE(fft);       
     166}
  • src/fft.h

    rf8714ee rf88a326  
    5656void aubio_fft_getphas(smpl_t * phase, fft_data_t * spectrum, uint_t size);
    5757
     58
     59typedef struct _aubio_mfft_t aubio_mfft_t;
     60aubio_mfft_t * new_aubio_mfft(uint_t winsize, uint_t channels);
     61void aubio_mfft_do (aubio_mfft_t * fft,fvec_t * in,cvec_t * fftgrain);
     62void aubio_mfft_rdo(aubio_mfft_t * fft,cvec_t * fftgrain, fvec_t * out);
     63void del_aubio_mfft(aubio_mfft_t * fft);
     64
     65
    5866#ifdef __cplusplus
    5967}
  • src/phasevoc.c

    rf8714ee rf88a326  
    3333        uint_t channels;
    3434        /** spectral data */
    35         aubio_fft_t * spectrum;
     35        aubio_mfft_t * fft;
    3636        /**cur output grain             [win_s] */
    3737        fvec_t * synth;         
    3838        /**last input frame             [win_s-hop_s] */
    3939        fvec_t * synthold;
    40         /**current spectrum             [win_s] */
    41         fft_data_t ** spec;
    4240        /**current input grain          [win_s] */
    4341        fvec_t * data;           
     
    4947
    5048
    51 /** memory allocation */
    52 static aubio_pvoc_t * aubio_pvoc_malloc (uint_t win_s, uint_t hop_s, uint_t channels);
    53 /** object deletion */
    54 static void aubio_pvoc_free (aubio_pvoc_t *pv);
    5549/** returns data and dataold slided by hop_s */
    5650static void aubio_pvoc_swapbuffers(
     
    7569                /* windowing */
    7670                for (j=0; j<pv->win_s; j++) pv->data->data[i][j] *= pv->w[j];
    77                 /* fftshift */
    78                 vec_shift(pv->data);
    79                 /* calculate fft */
    80                 aubio_fft_do(pv->spectrum,pv->data->data[i],pv->spec[i],pv->win_s);
    81                 /* put norm and phase to fftgrain */
    82                 aubio_fft_getnorm(fftgrain->norm[i], pv->spec[i], pv->win_s/2+1);
    83                 aubio_fft_getphas(fftgrain->phas[i], pv->spec[i], pv->win_s/2+1);
    84         }
     71        }
     72        /* shift */
     73        vec_shift(pv->data);
     74        /* calculate fft */
     75        aubio_mfft_do (pv->fft,pv->data,fftgrain);
    8576}
    8677
    8778void aubio_pvoc_rdo(aubio_pvoc_t *pv,cvec_t * fftgrain, fvec_t * synthnew) {
    8879        uint_t i,j;
     80        /* calculate rfft */
     81        aubio_mfft_rdo(pv->fft,fftgrain,pv->synth);
     82        /* unshift */
     83        vec_shift(pv->synth);
    8984        for (i=0; i<pv->channels; i++) {
    90                 for (j=0; j<pv->win_s/2+1; j++) {
    91                         pv->spec[i][j]  = CEXPC(I*unwrap2pi(fftgrain->phas[i][j]));
    92                         pv->spec[i][j] *= fftgrain->norm[i][j];
    93                 }
    94                 aubio_fft_rdo(pv->spectrum,pv->spec[i],pv->synth->data[i],pv->win_s);
    95                 vec_shift(pv->synth);
    9685                for (j=0; j<pv->win_s; j++) pv->synth->data[i][j] *= pv->w[j];
    9786                aubio_pvoc_addsynth(pv->synth->data[i],pv->synthold->data[i],
     
    10089}
    10190
    102 void del_aubio_pvoc(aubio_pvoc_t *pv) {
    103         aubio_pvoc_free(pv);
    104 }
    105 
    10691aubio_pvoc_t * new_aubio_pvoc (uint_t win_s, uint_t hop_s, uint_t channels) {
    107         aubio_pvoc_t * pv = aubio_pvoc_malloc(win_s, hop_s, channels);
    108         window(pv->w,pv->win_s,hanningz);
    109         return pv;
    110 }
    111 
    112 static aubio_pvoc_t * aubio_pvoc_malloc (uint_t win_s, uint_t hop_s, uint_t channels) {
    113         uint_t i;
    114 
    11592        aubio_pvoc_t * pv = AUBIO_NEW(aubio_pvoc_t);
    11693
    11794        if (win_s < 2*hop_s) {
    118                 AUBIO_ERR("Window size is smaller than twice the hop size!\n");
    119                 return 0;
     95                AUBIO_ERR("Hop size bigger than half the window size!\n");
     96                AUBIO_ERR("Resetting hop size to half the window size.\n");
     97                hop_s = win_s / 2;
    12098        }
    12199
    122100        if (hop_s < 1) {
    123101                AUBIO_ERR("Hop size is smaller than 1!\n");
    124                 return 0;
     102                AUBIO_ERR("Resetting hop size to half the window size.\n");
     103                hop_s = win_s / 2;
    125104        }
    126105       
    127         pv->spectrum = new_aubio_fft(win_s);
     106        pv->fft      = new_aubio_mfft(win_s,channels);
    128107
    129108        /* remember old */
     
    135114        pv->synthold = new_fvec (win_s-hop_s, channels);
    136115        pv->w        = AUBIO_ARRAY(smpl_t,win_s);
    137 
    138         pv->spec     = AUBIO_ARRAY(fft_data_t*,channels);
    139         for (i=0; i<channels; i++)
    140                 pv->spec[i] = AUBIO_ARRAY(fft_data_t,win_s);
     116        window(pv->w,win_s,hanningz);
    141117
    142118        pv->channels = channels;
     
    147123}
    148124
    149 static void aubio_pvoc_free (aubio_pvoc_t *pv) {
    150         uint_t i;
    151         del_aubio_fft(pv->spectrum);
     125void del_aubio_pvoc(aubio_pvoc_t *pv) {
    152126        del_fvec(pv->data);
    153127        del_fvec(pv->synth);
     
    155129        del_fvec(pv->synthold);
    156130        AUBIO_FREE(pv->w);
    157         for (i=0; i< pv->channels; i++) {
    158                 AUBIO_FREE(pv->spec[i]);
    159         }
    160         AUBIO_FREE(pv->spec);
    161131        AUBIO_FREE(pv);
    162132}
    163133
    164 static void aubio_pvoc_swapbuffers(smpl_t * data, smpl_t * dataold, const smpl_t * datanew,
    165                 uint_t win_s, uint_t hop_s)
     134static void aubio_pvoc_swapbuffers(smpl_t * data, smpl_t * dataold,
     135                const smpl_t * datanew, uint_t win_s, uint_t hop_s)
    166136{
    167137        uint_t i;
     
    174144}
    175145
    176 static void aubio_pvoc_addsynth(const smpl_t * synth, smpl_t * synthold, smpl_t * synthnew,
    177                 uint_t win_s, uint_t hop_s)
     146static void aubio_pvoc_addsynth(const smpl_t * synth, smpl_t * synthold,
     147                smpl_t * synthnew, uint_t win_s, uint_t hop_s)
    178148{
    179149        uint_t i;
Note: See TracChangeset for help on using the changeset viewer.