Changeset ef7df76


Ignore:
Timestamp:
Nov 6, 2007, 11:53:50 AM (16 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:
f218f29
Parents:
82c588a (diff), 2b3280a (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

merge from banane

Files:
16 added
1 deleted
12 edited
2 moved

Legend:

Unmodified
Added
Removed
  • .bzrignore

    r82c588a ref7df76  
    1 */Makefile.in
    2 */*/Makefile.in
    3 */*/*/Makefile.in
    4 */Makefile
    5 */*/Makefile
    6 */*/*/Makefile
    7 */.deps
    8 */*/.deps
    9 */*/*/.deps
    10 */.libs
    11 */*/.libs
    12 */*/*/.libs
    13 */*.lo
    14 */*/*.lo
    15 */*/*/*.lo
    16 */*.la
     1**/Makefile.in
     2**/Makefile
     3**/.deps
     4**/.libs
     5**/*.lo
     6**/*.la
     7
     8# ignore compiled examples
     9RE:examples/[a-z]*
     10
     11# ignore compiled test programs
     12RE:tests/src/test-[a-z-]*$
     13
     14# ignore aubio
    1715plugins/puredata/aubio.pd_linux
    18 doc/aubiocut.1
    19 doc/aubionotes.1
    20 doc/aubioonset.1
    21 doc/aubiopitch.1
    22 doc/aubiotrack.1
     16
     17# only sgml manpages count
     18doc/*.1
     19
     20# cachegrind/callgrind stuff
     21**/cachegrind.out.[0-9]*
     22**/callgrind.out.[0-9]*
     23
     24# autoreconf -f -i will create these
     25INSTALL
     26aclocal.m4
     27aubio.pc
     28autom4te.cache/
     29compile
     30config.guess
     31config.log
     32config.status
     33config.sub
     34configure
     35depcomp
     36install-sh
     37libtool
     38ltmain.sh
     39missing
     40py-compile
    2341src/config.h
    2442src/config.h.in
    2543src/stamp-h1
     44
  • python/aubio/aubioclass.py

    r82c588a ref7df76  
    4343        else:
    4444            self.file = new_aubio_sndfile_ro(filename)
     45        if self.file == None: raise(ValueError, "failed opening file")
    4546    def __del__(self):
    46         del_aubio_sndfile(self.file)
     47        if self.file != None: del_aubio_sndfile(self.file)
    4748    def info(self):
    4849        aubio_sndfile_info(self.file)
  • src/Makefile.am

    r82c588a ref7df76  
    66        fft.h \
    77        sample.h \
     8        fvec.h \
     9        cvec.h \
    810        hist.h \
    911        scale.h \
     
    3436        fft.c \
    3537        fft.h \
    36         sample.c \
    37         sample.h \
     38        fvec.c \
     39        fvec.h \
     40        cvec.c \
     41        cvec.h \
    3842        hist.c \
    3943        hist.h \
  • src/aubio_priv.h

    r82c588a ref7df76  
    11/*
    2          Copyright (C) 2003 Paul Brossier
     2   Copyright (C) 2003-2007 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
     
    7171
    7272/* Memory management */
    73 #define AUBIO_MALLOC(_n)                malloc(_n)
    74 #define AUBIO_REALLOC(_p,_n)            realloc(_p,_n)
    75 #define AUBIO_NEW(_t)                   (_t*)malloc(sizeof(_t))
    76 #define AUBIO_ARRAY(_t,_n)              (_t*)malloc((_n)*sizeof(_t))
    77 #define AUBIO_MEMCPY(_dst,_src,_n)      memcpy(_dst,_src,_n)
    78 #define AUBIO_MEMSET(_dst,_src,_t)      memset(_dst,_src,_t)
    79 #define AUBIO_FREE(_p)                  free(_p)       
     73#define AUBIO_MALLOC(_n)             malloc(_n)
     74#define AUBIO_REALLOC(_p,_n)         realloc(_p,_n)
     75#define AUBIO_NEW(_t)                (_t*)malloc(sizeof(_t))
     76#define AUBIO_ARRAY(_t,_n)           (_t*)malloc((_n)*sizeof(_t))
     77#define AUBIO_MEMCPY(_dst,_src,_n)   memcpy(_dst,_src,_n)
     78#define AUBIO_MEMSET(_dst,_src,_t)   memset(_dst,_src,_t)
     79#define AUBIO_FREE(_p)               free(_p)
    8080
    8181
  • src/cvec.c

    r82c588a ref7df76  
    11/*
    2    Copyright (C) 2003 Paul Brossier
     2   Copyright (C) 2003-2007 Paul Brossier <piem@piem.org>
    33
    44   This program is free software; you can redistribute it and/or modify
     
    1919
    2020#include "aubio_priv.h"
    21 #include "sample.h"
    22 
    23 fvec_t * new_fvec( uint_t length, uint_t channels) {
    24   fvec_t * s = AUBIO_NEW(fvec_t);
    25   uint_t i,j;
    26   s->channels = channels;
    27   s->length = length;
    28   s->data = AUBIO_ARRAY(smpl_t*,s->channels);
    29   for (i=0; i< s->channels; i++) {
    30     s->data[i] = AUBIO_ARRAY(smpl_t, s->length);
    31     for (j=0; j< s->length; j++) {
    32       s->data[i][j]=0.;
    33     }
    34   }
    35   return s;
    36 }
    37 
    38 void del_fvec(fvec_t *s) {
    39   uint_t i;
    40   for (i=0; i<s->channels; i++) {
    41     AUBIO_FREE(s->data[i]);
    42   }
    43   AUBIO_FREE(s->data);
    44   AUBIO_FREE(s);
    45 }
    46 
    47 void fvec_write_sample(fvec_t *s, smpl_t data, uint_t channel, uint_t position) {
    48   s->data[channel][position] = data;
    49 }
    50 smpl_t fvec_read_sample(fvec_t *s, uint_t channel, uint_t position) {
    51   return s->data[channel][position];
    52 }
    53 void fvec_put_channel(fvec_t *s, smpl_t * data, uint_t channel) {
    54   s->data[channel] = data;
    55 }
    56 smpl_t * fvec_get_channel(fvec_t *s, uint_t channel) {
    57   return s->data[channel];
    58 }
    59 
    60 smpl_t ** fvec_get_data(fvec_t *s) {
    61   return s->data;
    62 }
     21#include "cvec.h"
    6322
    6423cvec_t * new_cvec( uint_t length, uint_t channels) {
     
    12180  return s->phas;
    12281}
     82
  • src/fft.c

    r82c588a ref7df76  
    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         s->specdata = (fft_data_t*)fftw_malloc(sizeof(fft_data_t)*size);
    58         /* 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 */
    5958#ifdef HAVE_COMPLEX_H
    60         s->pfw = fftw_plan_dft_r2c_1d(size, s->in,  s->specdata, FFTW_ESTIMATE);
    61         s->pbw = fftw_plan_dft_c2r_1d(size, s->specdata, s->out, FFTW_ESTIMATE);
     59  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);
    6263#else
    63         s->pfw = fftw_plan_r2r_1d(size, s->in,  s->specdata, FFTW_R2HC, FFTW_ESTIMATE);
    64         s->pbw = fftw_plan_r2r_1d(size, s->specdata, s->out, FFTW_HC2R, FFTW_ESTIMATE);
     64  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);
    6568#endif
    66         return s;
     69  return s;
    6770}
    6871
    6972void del_aubio_fft(aubio_fft_t * s) {
    70         /* destroy data */
    71         fftw_destroy_plan(s->pfw);
    72         fftw_destroy_plan(s->pbw);
    73         fftw_free(s->specdata);
    74         AUBIO_FREE(s->out);
    75         AUBIO_FREE(s->in );
    76         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);
    7780}
    7881
    7982void aubio_fft_do(const aubio_fft_t * s,
    80                 const smpl_t * data, fft_data_t * spectrum,
    81                 const uint_t size) {
    82         uint_t i;
    83         for (i=0;i<size;i++) s->in[i] = data[i];
    84         fftw_execute(s->pfw);
    85         for (i=0;i<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];
    8688}
    8789
    8890void aubio_fft_rdo(const aubio_fft_t * s,
    89                 const fft_data_t * spectrum,
    90                 smpl_t * data,
    91                 const uint_t size) {
    92         uint_t i;
    93         const smpl_t renorm = 1./(smpl_t)size;
    94         for (i=0;i<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;
     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;
    9797}
    9898
     
    100100
    101101void aubio_fft_getnorm(smpl_t * norm, fft_data_t * spectrum, uint_t size) {
    102         uint_t i;
    103         for (i=0;i<size/2+1;i++) norm[i] = ABSC(spectrum[i]);
    104         //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]);
    105104}
    106105
    107106void aubio_fft_getphas(smpl_t * phas, fft_data_t * spectrum, uint_t size) {
    108         uint_t i;
    109         for (i=0;i<size/2+1;i++) phas[i] = ARGC(spectrum[i]);
    110         //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]);
    111109}
    112110
     
    122120
    123121void aubio_fft_getnorm(smpl_t * norm, fft_data_t * spectrum, uint_t size) {
    124         uint_t i;
    125   norm[0] = -spectrum[0];
    126         for (i=1;i<size/2+1;i++) norm[i] = SQRT(SQR(spectrum[i]) + SQR(spectrum[size-i]));
    127         //for (i=0;i<size/2+1;i++) AUBIO_DBG("%f\n", norm[i]);
     122  uint_t i;
     123  norm[0] = spectrum[0];
     124  for (i=1;i<size/2;i++) norm[i] = SQRT((SQR(spectrum[i]) + SQR(spectrum[size-i])));
     125  norm[size/2] = spectrum[size/2];
    128126}
    129127
    130128void aubio_fft_getphas(smpl_t * phas, fft_data_t * spectrum, uint_t size) {
    131         uint_t i;
    132   phas[0] = PI;
    133         for (i=1;i<size/2+1;i++) phas[i] = atan2f(spectrum[size-i] , spectrum[i]);
    134         //for (i=0;i<size/2+1;i++) AUBIO_DBG("%f\n", phas[i]);
     129  uint_t i;
     130  phas[0] = 0;
     131  for (i=1;i<size/2+1;i++) phas[i] = atan2f(spectrum[size-i] , spectrum[i]);
     132  phas[size/2] = 0;
    135133}
    136134
     
    156154
    157155aubio_mfft_t * new_aubio_mfft(uint_t winsize, uint_t channels){
    158         uint_t i;
    159         aubio_mfft_t * fft = AUBIO_NEW(aubio_mfft_t);
    160         fft->winsize       = winsize;
    161         fft->channels      = channels;
    162         fft->fft           = new_aubio_fft(winsize);
    163         fft->spec          = AUBIO_ARRAY(fft_data_t*,channels);
    164         for (i=0; i < channels; i++)
    165                 fft->spec[i] = AUBIO_ARRAY(fft_data_t,winsize);
    166         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;
    167165}
    168166
    169167/* execute stft */
    170168void aubio_mfft_do (aubio_mfft_t * fft,fvec_t * in,cvec_t * fftgrain){
    171         uint_t i=0;
    172         /* execute stft */
    173         for (i=0; i < fft->channels; i++) {
    174                 aubio_fft_do (fft->fft,in->data[i],fft->spec[i],fft->winsize);
    175                 /* put norm and phase into fftgrain */
    176                 aubio_fft_getnorm(fftgrain->norm[i], fft->spec[i], fft->winsize);
    177                 aubio_fft_getphas(fftgrain->phas[i], fft->spec[i], fft->winsize);
    178         }
     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  }
    179177}
    180178
    181179/* execute inverse fourier transform */
    182180void aubio_mfft_rdo(aubio_mfft_t * fft,cvec_t * fftgrain, fvec_t * out){
    183         uint_t i=0;
    184         for (i=0; i < fft->channels; i++) {
    185                 aubio_fft_getspectrum(fft->spec[i],fftgrain->norm[i],fftgrain->phas[i],fft->winsize);
    186                 aubio_fft_rdo(fft->fft,fft->spec[i],out->data[i],fft->winsize);
    187         }
     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  }
    188186}
    189187
    190188void del_aubio_mfft(aubio_mfft_t * fft) {
    191         uint_t i;
    192         for (i=0; i < fft->channels; i++)
    193                 AUBIO_FREE(fft->spec[i]);
    194         AUBIO_FREE(fft->spec);
    195         del_aubio_fft(fft->fft);
    196         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);       
    197195}
  • src/fft.h

    r82c588a ref7df76  
    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
  • src/phasevoc.c

    r82c588a ref7df76  
    2626/** phasevocoder internal object */
    2727struct _aubio_pvoc_t {
    28         /** grain length */
    29         uint_t win_s;
    30         /** overlap step */
    31         uint_t hop_s;
    32         /** number of channels */
    33         uint_t channels;
    34         /** spectral data */
    35         aubio_mfft_t * fft;
    36         /**cur output grain             [win_s] */
    37         fvec_t * synth;         
    38         /**last input frame             [win_s-hop_s] */
    39         fvec_t * synthold;
    40         /**current input grain          [win_s] */
    41         fvec_t * data;           
    42         /**last input frame             [win_s-hop_s] */
    43         fvec_t * dataold; 
    44         /** grain window                [win_s] */
    45         float * w;
     28  uint_t win_s;       /** grain length */
     29  uint_t hop_s;       /** overlap step */
     30  uint_t channels;    /** number of channels */
     31  aubio_mfft_t * fft; /** spectral data */
     32  fvec_t * synth;     /**cur output grain [win_s] */
     33  fvec_t * synthold;  /**last input frame [win_s-hop_s] */
     34  fvec_t * data;      /**current input grain [win_s] */
     35  fvec_t * dataold;   /**last input frame [win_s-hop_s] */
     36  smpl_t * w;          /** grain window [win_s] */
    4637};
    4738
    4839
    4940/** returns data and dataold slided by hop_s */
    50 static void aubio_pvoc_swapbuffers(
    51                 smpl_t * data,
    52                 smpl_t * dataold,
    53                 const smpl_t * datanew,
    54                 uint_t win_s, uint_t hop_s);
     41static void aubio_pvoc_swapbuffers(smpl_t * data, smpl_t * dataold, const
     42    smpl_t * datanew, uint_t win_s, uint_t hop_s);
     43
    5544/** do additive synthesis from 'old' and 'cur' */
    56 static void aubio_pvoc_addsynth(
    57                 const smpl_t * synth,
    58                 smpl_t * synthold,
    59                 smpl_t * synthnew,
    60                 uint_t win_s, uint_t hop_s);
    61 
     45static void aubio_pvoc_addsynth(const smpl_t * synth, smpl_t * synthold,
     46    smpl_t * synthnew, uint_t win_s, uint_t hop_s);
    6247
    6348void aubio_pvoc_do(aubio_pvoc_t *pv, fvec_t * datanew, cvec_t *fftgrain) {
    64         uint_t i,j;
    65         for (i=0; i<pv->channels; i++) {
    66                 /* slide  */
    67                 aubio_pvoc_swapbuffers(pv->data->data[i],pv->dataold->data[i],
    68                                 datanew->data[i],pv->win_s,pv->hop_s);
    69                 /* windowing */
    70                 for (j=0; j<pv->win_s; j++) pv->data->data[i][j] *= pv->w[j];
    71         }
    72         /* shift */
    73         vec_shift(pv->data);
    74         /* calculate fft */
    75         aubio_mfft_do (pv->fft,pv->data,fftgrain);
     49  uint_t i,j;
     50  for (i=0; i<pv->channels; i++) {
     51    /* slide  */
     52    aubio_pvoc_swapbuffers(pv->data->data[i],pv->dataold->data[i],
     53        datanew->data[i],pv->win_s,pv->hop_s);
     54    /* windowing */
     55    for (j=0; j<pv->win_s; j++) pv->data->data[i][j] *= pv->w[j];
     56  }
     57  /* shift */
     58  vec_shift(pv->data);
     59  /* calculate fft */
     60  aubio_mfft_do (pv->fft,pv->data,fftgrain);
    7661}
    7762
    7863void aubio_pvoc_rdo(aubio_pvoc_t *pv,cvec_t * fftgrain, fvec_t * synthnew) {
    79         uint_t i,j;
    80         /* calculate rfft */
    81         aubio_mfft_rdo(pv->fft,fftgrain,pv->synth);
    82         /* unshift */
    83         vec_shift(pv->synth);
    84         for (i=0; i<pv->channels; i++) {
    85                 for (j=0; j<pv->win_s; j++) pv->synth->data[i][j] *= pv->w[j];
    86                 aubio_pvoc_addsynth(pv->synth->data[i],pv->synthold->data[i],
    87                                 synthnew->data[i],pv->win_s,pv->hop_s);
    88         }
     64  uint_t i;
     65  /* calculate rfft */
     66  aubio_mfft_rdo(pv->fft,fftgrain,pv->synth);
     67  /* unshift */
     68  vec_shift(pv->synth);
     69  for (i=0; i<pv->channels; i++) {
     70    aubio_pvoc_addsynth(pv->synth->data[i],pv->synthold->data[i],
     71        synthnew->data[i],pv->win_s,pv->hop_s);
     72  }
    8973}
    9074
    9175aubio_pvoc_t * new_aubio_pvoc (uint_t win_s, uint_t hop_s, uint_t channels) {
    92         aubio_pvoc_t * pv = AUBIO_NEW(aubio_pvoc_t);
     76  aubio_pvoc_t * pv = AUBIO_NEW(aubio_pvoc_t);
    9377
    94         if (win_s < 2*hop_s) {
    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;
    98         }
     78  if (win_s < 2*hop_s) {
     79    AUBIO_ERR("Hop size bigger than half the window size!\n");
     80    AUBIO_ERR("Resetting hop size to half the window size.\n");
     81    hop_s = win_s / 2;
     82  }
    9983
    100         if (hop_s < 1) {
    101                 AUBIO_ERR("Hop size is smaller than 1!\n");
    102                 AUBIO_ERR("Resetting hop size to half the window size.\n");
    103                 hop_s = win_s / 2;
    104         }
    105        
    106         pv->fft      = new_aubio_mfft(win_s,channels);
     84  if (hop_s < 1) {
     85    AUBIO_ERR("Hop size is smaller than 1!\n");
     86    AUBIO_ERR("Resetting hop size to half the window size.\n");
     87    hop_s = win_s / 2;
     88  }
    10789
    108         /* remember old */
    109         pv->data     = new_fvec (win_s, channels);
    110         pv->synth    = new_fvec (win_s, channels);
     90  pv->fft      = new_aubio_mfft(win_s,channels);
    11191
    112         /* new input output */
    113         pv->dataold  = new_fvec  (win_s-hop_s, channels);
    114         pv->synthold = new_fvec (win_s-hop_s, channels);
    115         pv->w        = AUBIO_ARRAY(smpl_t,win_s);
    116         aubio_window(pv->w,win_s,aubio_win_hanningz);
     92  /* remember old */
     93  pv->data     = new_fvec (win_s, channels);
     94  pv->synth    = new_fvec (win_s, channels);
    11795
    118         pv->channels = channels;
    119         pv->hop_s    = hop_s;
    120         pv->win_s    = win_s;
     96  /* new input output */
     97  pv->dataold  = new_fvec  (win_s-hop_s, channels);
     98  pv->synthold = new_fvec (win_s-hop_s, channels);
     99  pv->w        = AUBIO_ARRAY(smpl_t,win_s);
     100  aubio_window(pv->w,win_s,aubio_win_hanningz);
    121101
    122         return pv;
     102  pv->channels = channels;
     103  pv->hop_s    = hop_s;
     104  pv->win_s    = win_s;
     105
     106  return pv;
    123107}
    124108
    125109void del_aubio_pvoc(aubio_pvoc_t *pv) {
    126         del_fvec(pv->data);
    127         del_fvec(pv->synth);
    128         del_fvec(pv->dataold);
    129         del_fvec(pv->synthold);
    130         del_aubio_mfft(pv->fft);
    131         AUBIO_FREE(pv->w);
    132         AUBIO_FREE(pv);
     110  del_fvec(pv->data);
     111  del_fvec(pv->synth);
     112  del_fvec(pv->dataold);
     113  del_fvec(pv->synthold);
     114  del_aubio_mfft(pv->fft);
     115  AUBIO_FREE(pv->w);
     116  AUBIO_FREE(pv);
    133117}
    134118
    135119static void aubio_pvoc_swapbuffers(smpl_t * data, smpl_t * dataold,
    136                 const smpl_t * datanew, uint_t win_s, uint_t hop_s)
     120    const smpl_t * datanew, uint_t win_s, uint_t hop_s)
    137121{
    138         uint_t i;
    139         for (i=0;i<win_s-hop_s;i++)
    140                 data[i] = dataold[i];
    141         for (i=0;i<hop_s;i++)
    142                 data[win_s-hop_s+i] = datanew[i];
    143         for (i=0;i<win_s-hop_s;i++)
    144                 dataold[i] = data[i+hop_s];
     122  uint_t i;
     123  for (i=0;i<win_s-hop_s;i++)
     124    data[i] = dataold[i];
     125  for (i=0;i<hop_s;i++)
     126    data[win_s-hop_s+i] = datanew[i];
     127  for (i=0;i<win_s-hop_s;i++)
     128    dataold[i] = data[i+hop_s];
    145129}
    146130
     
    148132                smpl_t * synthnew, uint_t win_s, uint_t hop_s)
    149133{
    150         uint_t i;
    151         smpl_t scale = 2*hop_s/(win_s+.0);
    152         /* add new synth to old one and put result in synthnew */
    153         for (i=0;i<hop_s;i++)                                           
    154                 synthnew[i] = synthold[i]+synth[i]*scale;
    155         /* shift synthold */
    156         for (i=0;i<win_s-2*hop_s;i++)   
    157                 synthold[i] = synthold[i+hop_s];
    158         /* erase last frame in synthold */
    159         for (i=win_s-hop_s;i<win_s;i++)
    160                 synthold[i-hop_s]=0.;
    161         /* additive synth */
    162         for (i=0;i<win_s-hop_s;i++)     
    163                 synthold[i] += synth[i+hop_s]*scale;
     134  uint_t i;
     135  smpl_t scale = 2*hop_s/(win_s+.0);
     136  /* add new synth to old one and put result in synthnew */
     137  for (i=0;i<hop_s;i++)
     138    synthnew[i] = synthold[i]+synth[i]*scale;
     139  /* shift synthold */
     140  for (i=0;i<win_s-2*hop_s;i++)
     141    synthold[i] = synthold[i+hop_s];
     142  /* erase last frame in synthold */
     143  for (i=win_s-hop_s;i<win_s;i++)
     144    synthold[i-hop_s]=0.;
     145  /* additive synth */
     146  for (i=0;i<win_s-hop_s;i++)
     147    synthold[i] += synth[i+hop_s]*scale;
    164148}
    165149
  • src/sample.h

    r82c588a ref7df76  
    11/*
    2    Copyright (C) 2003 Paul Brossier
     2   Copyright (C) 2003-2007 Paul Brossier <piem@piem.org>
    33
    44   This program is free software; you can redistribute it and/or modify
     
    2121#define _SAMPLE_H
    2222
    23 #ifdef __cplusplus
    24 extern "C" {
    25 #endif
    26 
    27 /** \file
    28 
    29   Real and complex buffers
    30 
    31   This file specifies fvec_t and cvec_t buffers types, which are used
    32   throughout aubio to store real and complex data. Complex values are stored in
    33   terms of phase and norm.
    34 
    35 */
    36 
    37 /** Sample buffer type */
    38 typedef struct _fvec_t fvec_t;
    39 /** Spectrum buffer type */
    40 typedef struct _cvec_t cvec_t;
    41 /** Buffer for real values */
    42 struct _fvec_t {
    43   uint_t length;   /**< length of buffer */
    44   uint_t channels; /**< number of channels */
    45   smpl_t **data;   /**< data array of size [length] * [channels] */
    46 };
    47 /** Buffer for complex data */
    48 struct _cvec_t {
    49   uint_t length;   /**< length of buffer = (requested length)/2 + 1 */
    50   uint_t channels; /**< number of channels */
    51   smpl_t **norm;   /**< norm array of size [length] * [channels] */
    52   smpl_t **phas;   /**< phase array of size [length] * [channels] */
    53 };
    54 /** fvec_t buffer creation function
    55 
    56   \param length the length of the buffer to create
    57   \param channels the number of channels in the buffer
    58 
    59 */
    60 fvec_t * new_fvec(uint_t length, uint_t channels);
    61 /** fvec_t buffer deletion function
    62 
    63   \param s buffer to delete as returned by new_fvec()
    64 
    65 */
    66 void del_fvec(fvec_t *s);
    67 /** read sample value in a buffer
    68 
    69   Note that this function is not used in the aubio library, since the same
    70   result can be obtained using vec->data[channel][position]. Its purpose is to
    71   access these values from wrappers, as created by swig.
    72 
    73   \param s vector to read from
    74   \param channel channel to read from
    75   \param position sample position to read from
    76 
    77 */
    78 smpl_t fvec_read_sample(fvec_t *s, uint_t channel, uint_t position);
    79 /** write sample value in a buffer
    80 
    81   Note that this function is not used in the aubio library, since the same
    82   result can be obtained by assigning vec->data[channel][position]. Its purpose
    83   is to access these values from wrappers, as created by swig.
    84 
    85   \param s vector to write to
    86   \param data value to write in s->data[channel][position]
    87   \param channel channel to write to
    88   \param position sample position to write to
    89 
    90 */
    91 void  fvec_write_sample(fvec_t *s, smpl_t data, uint_t channel, uint_t position);
    92 /** read channel vector from a buffer
    93 
    94   Note that this function is not used in the aubio library, since the same
    95   result can be obtained with vec->data[channel]. Its purpose is to access
    96   these values from wrappers, as created by swig.
    97 
    98   \param s vector to read from
    99   \param channel channel to read from
    100 
    101 */
    102 smpl_t * fvec_get_channel(fvec_t *s, uint_t channel);
    103 /** write channel vector into a buffer
    104 
    105   Note that this function is not used in the aubio library, since the same
    106   result can be obtained by assigning vec->data[channel]. Its purpose is to
    107   access these values from wrappers, as created by swig.
    108 
    109   \param s vector to write to
    110   \param data vector of [length] values to write
    111   \param channel channel to write to
    112 
    113 */
    114 void fvec_put_channel(fvec_t *s, smpl_t * data, uint_t channel);
    115 /** read data from a buffer
    116 
    117   Note that this function is not used in the aubio library, since the same
    118   result can be obtained with vec->data. Its purpose is to access these values
    119   from wrappers, as created by swig.
    120 
    121   \param s vector to read from
    122 
    123 */
    124 smpl_t ** fvec_get_data(fvec_t *s);
    125 
    126 /** cvec_t buffer creation function
    127 
    128   This function creates a cvec_t structure holding two arrays of size
    129   [length/2+1] * channels, corresponding to the norm and phase values of the
    130   spectral frame. The length stored in the structure is the actual size of both
    131   arrays, not the length of the complex and symetrical vector, specified as
    132   creation argument.
    133 
    134   \param length the length of the buffer to create
    135   \param channels the number of channels in the buffer
    136 
    137 */
    138 cvec_t * new_cvec(uint_t length, uint_t channels);
    139 /** cvec_t buffer deletion function
    140 
    141   \param s buffer to delete as returned by new_cvec()
    142 
    143 */
    144 void del_cvec(cvec_t *s);
    145 /** write norm value in a complex buffer
    146 
    147   Note that this function is not used in the aubio library, since the same
    148   result can be obtained by assigning vec->norm[channel][position]. Its purpose
    149   is to access these values from wrappers, as created by swig.
    150 
    151   \param s vector to write to
    152   \param data norm value to write in s->norm[channel][position]
    153   \param channel channel to write to
    154   \param position sample position to write to
    155 
    156 */
    157 void cvec_write_norm(cvec_t *s, smpl_t data, uint_t channel, uint_t position);
    158 /** write phase value in a complex buffer
    159 
    160   Note that this function is not used in the aubio library, since the same
    161   result can be obtained by assigning vec->phas[channel][position]. Its purpose
    162   is to access these values from wrappers, as created by swig.
    163 
    164   \param s vector to write to
    165   \param data phase value to write in s->phas[channel][position]
    166   \param channel channel to write to
    167   \param position sample position to write to
    168 
    169 */
    170 void cvec_write_phas(cvec_t *s, smpl_t data, uint_t channel, uint_t position);
    171 /** read norm value from a complex buffer
    172 
    173   Note that this function is not used in the aubio library, since the same
    174   result can be obtained with vec->norm[channel][position]. Its purpose is to
    175   access these values from wrappers, as created by swig.
    176 
    177   \param s vector to read from
    178   \param channel channel to read from
    179   \param position sample position to read from
    180 
    181 */
    182 smpl_t cvec_read_norm(cvec_t *s, uint_t channel, uint_t position);
    183 /** read phase value from a complex buffer
    184 
    185   Note that this function is not used in the aubio library, since the same
    186   result can be obtained with vec->phas[channel][position]. Its purpose is to
    187   access these values from wrappers, as created by swig.
    188 
    189   \param s vector to read from
    190   \param channel channel to read from
    191   \param position sample position to read from
    192 
    193 */
    194 smpl_t cvec_read_phas(cvec_t *s, uint_t channel, uint_t position);
    195 /** write norm channel in a complex buffer
    196 
    197   Note that this function is not used in the aubio library, since the same
    198   result can be obtained by assigning vec->norm[channel]. Its purpose is to
    199   access these values from wrappers, as created by swig.
    200 
    201   \param s vector to write to
    202   \param data norm vector of [length] samples to write in s->norm[channel]
    203   \param channel channel to write to
    204 
    205 */
    206 void cvec_put_norm_channel(cvec_t *s, smpl_t * data, uint_t channel);
    207 /** write phase channel in a complex buffer
    208 
    209   Note that this function is not used in the aubio library, since the same
    210   result can be obtained by assigning vec->phas[channel]. Its purpose is to
    211   access these values from wrappers, as created by swig.
    212 
    213   \param s vector to write to
    214   \param data phase vector of [length] samples to write in s->phas[channel]
    215   \param channel channel to write to
    216 
    217 */
    218 void cvec_put_phas_channel(cvec_t *s, smpl_t * data, uint_t channel);
    219 /** read norm channel from a complex buffer
    220 
    221   Note that this function is not used in the aubio library, since the same
    222   result can be obtained with vec->norm[channel]. Its purpose is to access
    223   these values from wrappers, as created by swig.
    224 
    225   \param s vector to read from
    226   \param channel channel to read from
    227 
    228 */
    229 smpl_t * cvec_get_norm_channel(cvec_t *s, uint_t channel);
    230 /** write phase channel in a complex buffer
    231 
    232   Note that this function is not used in the aubio library, since the same
    233   result can be obtained with vec->phas[channel]. Its purpose is to access
    234   these values from wrappers, as created by swig.
    235 
    236   \param s vector to read from
    237   \param channel channel to read from
    238 
    239 */
    240 smpl_t * cvec_get_phas_channel(cvec_t *s, uint_t channel);
    241 /** read norm data from a complex buffer
    242 
    243   Note that this function is not used in the aubio library, since the same
    244   result can be obtained with vec->norm. Its purpose is to access these values
    245   from wrappers, as created by swig.
    246 
    247   \param s vector to read from
    248 
    249 */
    250 smpl_t ** cvec_get_norm(cvec_t *s);
    251 /** read phase data from a complex buffer
    252 
    253   Note that this function is not used in the aubio library, since the same
    254   result can be obtained with vec->phas. Its purpose is to access these values
    255   from wrappers, as created by swig.
    256 
    257   \param s vector to read from
    258 
    259 */
    260 smpl_t ** cvec_get_phas(cvec_t *s);
    261 
    262 #ifdef __cplusplus
    263 }
    264 #endif
     23#include "fvec.h"
     24#include "cvec.h"
    26525
    26626#endif /* _SAMPLE_H */
  • tests/python/fvec.py

    r82c588a ref7df76  
    2222    for index in range(buf_size):
    2323      for channel in range(channels):
    24         self.assertEqual(fvec_read_sample(self.vector,channel,index),0.)
     24        self.assertEqual(0., fvec_read_sample(self.vector,channel,index))
    2525
    2626  def test_fvec_write_sample(self):
     
    3131    for index in range(buf_size):
    3232      for channel in range(channels):
    33         self.assertEqual(fvec_read_sample(self.vector,channel,index),1.)
     33        self.assertEqual(1., fvec_read_sample(self.vector,channel,index))
    3434
    3535if __name__ == '__main__':
  • tests/python/run_all_tests

    r82c588a ref7df76  
    1212
    1313from glob import glob
    14 modules_to_test = [i.split('.')[0] for i in glob('*.py')]
     14def list_of_test_files(path):
     15  return [i.split('.')[0].replace('/','.') for i in glob(path)]
     16
     17modules_to_test  = list_of_test_files('*.py')
     18modules_to_test += list_of_test_files('examples/aubio*.py')
    1519
    1620if __name__ == '__main__':
    1721  for module in modules_to_test:
    18     if module != 'all_tests': # (not actually needed)
     22    if module != 'run_all_tests': # (not actually needed)
    1923      exec('from %s import *' % module)
    2024  unittest.main()
  • tests/src/Makefile.am

    r82c588a ref7df76  
    1010        test-hist \
    1111        test-scale \
    12         test-sample \
     12        test-cvec \
     13        test-fvec \
    1314        test-window \
    1415        test-filter \
  • tests/src/test-cvec.c

    r82c588a ref7df76  
    55        uint_t win_s      = 1024;                       /* window size */
    66        uint_t channels   = 1;                          /* number of channel */
    7         fvec_t * in       = new_fvec (win_s, channels); /* input buffer */
    87        cvec_t * sp       = new_cvec (win_s, channels); /* input buffer */
    9         del_fvec(in);
    108        del_cvec(sp);
    119
  • tests/src/test-fft.c

    r82c588a ref7df76  
    99int main(){
    1010        uint_t i,j;
    11         /* allocate some memory */
    12         uint_t win_s      = 1024;                       /* window size */
    13         uint_t channels   = 1;                          /* number of channel */
    14         fvec_t * in       = new_fvec (win_s, channels); /* input buffer */
    15         cvec_t * fftgrain = new_cvec (win_s, channels); /* fft norm and phase */
    16         fvec_t * out      = new_fvec (win_s, channels); /* output buffer */
     11        uint_t win_s      = 1024;                       // window size
     12        uint_t channels   = 1;                          // number of channel
     13        fvec_t * in       = new_fvec (win_s, channels); // input buffer
     14        cvec_t * fftgrain = new_cvec (win_s, channels); // fft norm and phase
     15        fvec_t * out      = new_fvec (win_s, channels); // output buffer
    1716 
    18         /* allocate fft and other memory space */
    19         aubio_fft_t * fft      = new_aubio_fft(win_s);      /* fft interface */
    20         smpl_t * w             = NEW_ARRAY(smpl_t,win_s); /* window */
    21         /* complex spectral data */
     17        // allocate fft and other memory space
     18        aubio_fft_t * fft      = new_aubio_fft(win_s);    // fft interface
     19        smpl_t * w             = NEW_ARRAY(smpl_t,win_s); // window
     20        // complex spectral data
    2221        fft_data_t ** spec     = NEW_ARRAY(fft_data_t*,channels);
    2322        for (i=0; i < channels; i++)
    2423                spec[i] = NEW_ARRAY(fft_data_t,win_s);
    25         /* initialize the window (see mathutils.c) */
     24        // initialize the window (see mathutils.c)
    2625        aubio_window(w,win_s,aubio_win_hanningz);
    2726 
    28         /* fill input with some data */
     27        // fill input with some data
    2928        in->data[0][win_s/2] = 1;
    3029 
    31         /* execute stft */
     30        // execute stft
    3231        for (i=0; i < channels; i++) {
    3332                aubio_fft_do (fft,in->data[i],spec[i],win_s);
    34                 /* put norm and phase into fftgrain */
     33                // put norm and phase into fftgrain
    3534                aubio_fft_getnorm(fftgrain->norm[i], spec[i], win_s/2+1);
    3635                aubio_fft_getphas(fftgrain->phas[i], spec[i], win_s/2+1);
    3736        }
    3837 
    39         /* execute inverse fourier transform */
     38        // execute inverse fourier transform
    4039        for (i=0; i < channels; i++) {
    4140                for (j=0; j<win_s/2+1; j++) {
Note: See TracChangeset for help on using the changeset viewer.