Changeset a4364b8 for src/temporal


Ignore:
Timestamp:
Sep 29, 2009, 7:43:12 AM (15 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:
c159aeb
Parents:
d9c45df
Message:

src/temporal: revamp filter object, clarify API for A- and C-weighting filters,
add coefficients for 8000 16000 22050 44100 96000 192000, improve documentation,
remove unneeded filter_priv.h, add A and C weighting tests.

Location:
src/temporal
Files:
1 deleted
6 edited

Legend:

Unmodified
Added
Removed
  • src/temporal/adesign.c

    rd9c45df ra4364b8  
    11/*
    2    Copyright (C) 2003-2007 Paul Brossier
    32
    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.
     3  Copyright (C) 2003-2009 Paul Brossier <piem@aubio.org>
    84
    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.
     5  This file is part of aubio.
    136
    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.
     7  aubio is free software: you can redistribute it and/or modify
     8  it under the terms of the GNU General Public License as published by
     9  the Free Software Foundation, either version 3 of the License, or
     10  (at your option) any later version.
     11
     12  aubio 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 for more details.
     16
     17  You should have received a copy of the GNU General Public License
     18  along with aubio.  If not, see <http://www.gnu.org/licenses/>.
    1719
    1820*/
    19 
    2021
    2122#include "aubio_priv.h"
    2223#include "types.h"
    2324#include "fvec.h"
     25#include "lvec.h"
    2426#include "temporal/filter.h"
    25 #include "temporal/filter_priv.h"
    2627#include "temporal/adesign.h"
    2728
    28 aubio_filter_t * new_aubio_adsgn_filter(uint_t samplerate, uint_t channels) {
    29   aubio_filter_t * f = new_aubio_filter(samplerate, 7, channels);
    30   lsmp_t * a = f->a->data[0];
    31   lsmp_t * b = f->b->data[0];
    32   /* uint_t l; */
    33   /* for now, 44100, adsgn */
    34   a[0] =  1.00000000000000000000000000000000000000000000000000000;
    35   a[1] = -4.01957618111583236952810693765059113502502441406250000;
    36   a[2] =  6.18940644292069386267485242569819092750549316406250000;
    37   a[3] = -4.45319890354411640487342083360999822616577148437500000;
    38   a[4] =  1.42084294962187751565352300531230866909027099609375000;
    39   a[5] = -0.14182547383030480458998567883099894970655441284179688;
    40   a[6] =  0.00435117723349511334451911181986361043527722358703613;
    41   b[0] =  0.25574112520425740235907596797915175557136535644531250;
    42   b[1] = -0.51148225040851391653973223583307117223739624023437500;
    43   b[2] = -0.25574112520426162120656954357400536537170410156250000;
    44   b[3] =  1.02296450081703405032840237254276871681213378906250000;
    45   b[4] = -0.25574112520426051098354491841746494174003601074218750;
    46   b[5] = -0.51148225040851369449512731080176308751106262207031250;
    47   b[6] =  0.25574112520425729133677350546349771320819854736328125;
    48   /* DBG: filter coeffs at creation time */
    49   /*
    50   for (l=0; l<f->order; l++){
    51     AUBIO_DBG("a[%d]=\t%1.16f\tb[%d]=\t%1.16f\n",l,a[l],l,b[l]);
     29void aubio_filter_set_adsgn (aubio_filter_t * f) {
     30
     31  uint_t samplerate = aubio_filter_get_samplerate (f);
     32  lvec_t *bs = aubio_filter_get_feedforward (f);
     33  lvec_t *as = aubio_filter_get_feedback (f);
     34  lsmp_t *b = bs->data[0], *a = as->data[0];
     35  uint_t order = aubio_filter_get_order (f);
     36
     37  if ( order != 7 ) {
     38    AUBIO_ERROR ( "order of A-weighting filter must be 7, not %d\n", order );
     39    return;
    5240  }
    53   */
    54   f->a->data[0] = a;
    55   f->b->data[0] = b;
     41
     42  /* select coefficients according to sampling frequency */
     43  switch ( samplerate ) {
     44
     45    case 8000:
     46      b[0] =  6.306209468238731519207362907764036208391189575195312500e-01;
     47      b[1] = -1.261241893647746525886077506584115326404571533203125000e+00;
     48      b[2] = -6.306209468238730408984338282607495784759521484375000000e-01;
     49      b[3] =  2.522483787295493051772155013168230652809143066406250000e+00;
     50      b[4] = -6.306209468238730408984338282607495784759521484375000000e-01;
     51      b[5] = -1.261241893647746525886077506584115326404571533203125000e+00;
     52      b[6] =  6.306209468238731519207362907764036208391189575195312500e-01;
     53      a[0] =  1.000000000000000000000000000000000000000000000000000000e+00;
     54      a[1] = -2.128467193009123015201566886389628052711486816406250000e+00;
     55      a[2] =  2.948668980101234460278192273108288645744323730468750000e-01;
     56      a[3] =  1.824183830735050637628091863007284700870513916015625000e+00;
     57      a[4] = -8.056628943119792385374466903158463537693023681640625000e-01;
     58      a[5] = -3.947497982842933517133587884018197655677795410156250000e-01;
     59      a[6] =  2.098548546080332977137317129745497368276119232177734375e-01;
     60      break;
     61
     62    case 16000:
     63      b[0] =  5.314898298235570806014038680586963891983032226562500000e-01;
     64      b[1] = -1.062979659647114161202807736117392778396606445312500000e+00;
     65      b[2] = -5.314898298235570806014038680586963891983032226562500000e-01;
     66      b[3] =  2.125959319294228322405615472234785556793212890625000000e+00;
     67      b[4] = -5.314898298235570806014038680586963891983032226562500000e-01;
     68      b[5] = -1.062979659647114161202807736117392778396606445312500000e+00;
     69      b[6] =  5.314898298235570806014038680586963891983032226562500000e-01;
     70      a[0] =  1.000000000000000000000000000000000000000000000000000000e+00;
     71      a[1] = -2.867832572992162987191022693878039717674255371093750000e+00;
     72      a[2] =  2.221144410202312347024644623161293566226959228515625000e+00;
     73      a[3] =  4.552683347886614662058946123579517006874084472656250000e-01;
     74      a[4] = -9.833868636162828025248927588108927011489868164062500000e-01;
     75      a[5] =  5.592994142413361402521587706360151059925556182861328125e-02;
     76      a[6] =  1.188781038285612462468421313133148942142724990844726562e-01;
     77      break;
     78
     79    case 22050:
     80      b[0] =  4.492998504299193784916610638902056962251663208007812500e-01;
     81      b[1] = -8.985997008598388680056245902960654348134994506835937500e-01;
     82      b[2] = -4.492998504299192674693586013745516538619995117187500000e-01;
     83      b[3] =  1.797199401719677958055854105623438954353332519531250000e+00;
     84      b[4] = -4.492998504299192674693586013745516538619995117187500000e-01;
     85      b[5] = -8.985997008598388680056245902960654348134994506835937500e-01;
     86      b[6] =  4.492998504299193784916610638902056962251663208007812500e-01;
     87      a[0] =  1.000000000000000000000000000000000000000000000000000000e+00;
     88      a[1] = -3.229078805225074955131958631682209670543670654296875000e+00;
     89      a[2] =  3.354494881236033787530459449044428765773773193359375000e+00;
     90      a[3] = -7.317843680657351024265722116979304701089859008789062500e-01;
     91      a[4] = -6.271627581807257545420952737913466989994049072265625000e-01;
     92      a[5] =  1.772142005020879151899748649157118052244186401367187500e-01;
     93      a[6] =  5.631716697383508385410522123493137769401073455810546875e-02;
     94      break;
     95
     96    case 44100:
     97      b[0] =  2.55741125204257513381378430494805797934532165527343750e-01;
     98      b[1] = -5.114822504085150267627568609896115958690643310546875000e-01;
     99      b[2] = -2.557411252042575133813784304948057979345321655273437500e-01;
     100      b[3] =  1.022964500817030053525513721979223191738128662109375000e+00;
     101      b[4] = -2.557411252042575133813784304948057979345321655273437500e-01;
     102      b[5] = -5.114822504085150267627568609896115958690643310546875000e-01;
     103      b[6] =  2.557411252042575133813784304948057979345321655273437500e-01;
     104      a[0] =  1.000000000000000000000000000000000000000000000000000000e+00;
     105      a[1] = -4.019576181115832369528106937650591135025024414062500000e+00;
     106      a[2] =  6.189406442920693862674852425698190927505493164062500000e+00;
     107      a[3] = -4.453198903544116404873420833609998226165771484375000000e+00;
     108      a[4] =  1.420842949621876627475103305187076330184936523437500000e+00;
     109      a[5] = -1.418254738303044160119270600262098014354705810546875000e-01;
     110      a[6] =  4.351177233495117681327801761881346465088427066802978516e-03;
     111
     112    case 96000:
     113      b[0] =  9.951898975972744976203898659150581806898117065429687500e-02;
     114      b[1] = -1.990379795194548995240779731830116361379623413085937500e-01;
     115      b[2] = -9.951898975972744976203898659150581806898117065429687500e-02;
     116      b[3] =  3.980759590389097990481559463660232722759246826171875000e-01;
     117      b[4] = -9.951898975972744976203898659150581806898117065429687500e-02;
     118      b[5] = -1.990379795194548995240779731830116361379623413085937500e-01;
     119      b[6] =  9.951898975972744976203898659150581806898117065429687500e-02;
     120      a[0] =  1.000000000000000000000000000000000000000000000000000000e+00;
     121      a[1] = -4.802203044225376693532325589330866932868957519531250000e+00;
     122      a[2] =  9.401807218627226347962277941405773162841796875000000000e+00;
     123      a[3] = -9.566143943569164420637207513209432363510131835937500000e+00;
     124      a[4] =  5.309775930392619081032989925006404519081115722656250000e+00;
     125      a[5] = -1.517333360452622237346531619550660252571105957031250000e+00;
     126      a[6] =  1.740971994228911745583587844521389342844486236572265625e-01;
     127      break;
     128
     129    case 192000:
     130      b[0] =  3.433213424548713782469278044118254911154508590698242188e-02;
     131      b[1] = -6.866426849097426177159775306790834292769432067871093750e-02;
     132      b[2] = -3.433213424548714476358668434841092675924301147460937500e-02;
     133      b[3] =  1.373285369819485235431955061358166858553886413574218750e-01;
     134      b[4] = -3.433213424548714476358668434841092675924301147460937500e-02;
     135      b[5] = -6.866426849097426177159775306790834292769432067871093750e-02;
     136      b[6] =  3.433213424548713782469278044118254911154508590698242188e-02;
     137      a[0] =  1.000000000000000000000000000000000000000000000000000000e+00;
     138      a[1] = -5.305923689674640009172890131594613194465637207031250000e+00;
     139      a[2] =  1.165952437466175695135461864992976188659667968750000000e+01;
     140      a[3] = -1.357560092700591525272102444432675838470458984375000000e+01;
     141      a[4] =  8.828906932824192921316353022120893001556396484375000000e+00;
     142      a[5] = -3.039490120988216581565666274400427937507629394531250000e+00;
     143      a[6] =  4.325834301870381537469256727490574121475219726562500000e-01;
     144      break;
     145
     146    default:
     147      AUBIO_ERROR ( "sampling rate of A-weighting filter is %d, should be one of\
     148 8000, 16000, 22050, 44100, 96000, 192000.\n",  samplerate );
     149      break;
     150
     151  }
     152
     153}
     154
     155aubio_filter_t * new_aubio_filter_adsgn (uint_t samplerate, uint_t channels) {
     156  aubio_filter_t * f = new_aubio_filter (samplerate, 7, channels);
     157  aubio_filter_set_adsgn (f);
    56158  return f;
    57159}
  • src/temporal/adesign.h

    rd9c45df ra4364b8  
    11/*
    2    Copyright (C) 2003-2007 Paul Brossier
     2  Copyright (C) 2003-2009 Paul Brossier <piem@aubio.org>
    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 file is part of aubio.
    85
    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.
     6  aubio is free software: you can redistribute it and/or modify
     7  it under the terms of the GNU General Public License as published by
     8  the Free Software Foundation, either version 3 of the License, or
     9  (at your option) any later version.
    1310
    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.
     11  aubio is distributed in the hope that it will be useful,
     12  but WITHOUT ANY WARRANTY; without even the implied warranty of
     13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     14  GNU General Public License for more details.
     15
     16  You should have received a copy of the GNU General Public License
     17  along with aubio.  If not, see <http://www.gnu.org/licenses/>.
    1718
    1819*/
     
    2324/** \file
    2425
    25   Create a new A-design filter
     26  Create an A-weighting filter
     27 
     28  This file creates an A-weighting digital filter, which reduces low and high
     29  frequencies and enhance the middle ones to reflect the ability of the human
     30  hearing.
     31 
     32  The implementation is based on the following standard:
    2633
    27   This file creates an IIR filter object with A-design coefficients.
     34    - IEC/CD 1672: Electroacoustics-Sound Level Meters, IEC, Geneva, Nov.  1996,
     35  for A- and C-weighting filters.
     36 
     37  See also:
     38 
     39    - <a href="http://en.wikipedia.org/wiki/A-weighting">A-Weighting on
     40  Wikipedia</a>
     41    - <a href="http://en.wikipedia.org/wiki/Weighting_filter">Weighting filter on
     42  Wikipedia</a>
     43    - <a href="http://www.mathworks.com/matlabcentral/fileexchange/69">Christophe
     44  Couvreur's 'octave' toolbox</a>
     45 
     46  The coefficients in this file have been computed using Christophe Couvreur's
     47  scripts in octave 3.0 (debian package 1:3.0.5-6+b2 with octave-signal
     48  1.0.9-1+b1 on i386), with <pre> [b, a] = adsign(1/Fs) </pre> for various
     49  sampling frequencies.
    2850
    2951*/
     
    3557/** create new A-design filter
    3658
    37   \param samplerate sampling-rate of the signal to filter
     59  \param samplerate sampling frequency of the signal to filter. Should be one of
     60  8000, 16000, 22050, 44100, 96000, 192000.
    3861  \param channels number of channels to allocate
    3962
     63  \return a new filter object
     64
    4065*/
    41 aubio_filter_t * new_aubio_adsgn_filter(uint_t samplerate, uint_t channels);
     66aubio_filter_t * new_aubio_filter_adsgn (uint_t samplerate, uint_t channels);
    4267
    43 /** filter input vector (in-place) */
    44 #define aubio_adsgn_filter_do aubio_filter_do
    45 /** delete a-design filter object */
    46 #define del_aubio_adsgn_filter del_aubio_filter
     68/** set feedback and feedforward coefficients of a A-weighting filter
     69
     70  \param f filter object to get coefficients from
     71
     72*/
     73void aubio_filter_set_adsgn (aubio_filter_t *f);
    4774
    4875#ifdef __cplusplus
  • src/temporal/cdesign.c

    rd9c45df ra4364b8  
    11/*
    2    Copyright (C) 2003-2007 Paul Brossier
     2  Copyright (C) 2003-2009 Paul Brossier <piem@aubio.org>
    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 file is part of aubio.
    85
    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.
     6  aubio is free software: you can redistribute it and/or modify
     7  it under the terms of the GNU General Public License as published by
     8  the Free Software Foundation, either version 3 of the License, or
     9  (at your option) any later version.
    1310
    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.
     11  aubio is distributed in the hope that it will be useful,
     12  but WITHOUT ANY WARRANTY; without even the implied warranty of
     13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     14  GNU General Public License for more details.
     15
     16  You should have received a copy of the GNU General Public License
     17  along with aubio.  If not, see <http://www.gnu.org/licenses/>.
    1718
    1819*/
    19 
    2020
    2121#include "aubio_priv.h"
    2222#include "types.h"
    2323#include "fvec.h"
     24#include "lvec.h"
    2425#include "temporal/filter.h"
    25 #include "temporal/filter_priv.h"
    26 #include "temporal/adesign.h"
     26#include "temporal/cdesign.h"
    2727
    28 aubio_filter_t * new_aubio_cdsgn_filter(uint_t samplerate, uint_t channels) {
     28void aubio_filter_set_cdsgn (aubio_filter_t * f) {
     29
     30  uint_t samplerate = aubio_filter_get_samplerate (f);
     31  lvec_t * bs = aubio_filter_get_feedforward (f);
     32  lvec_t * as = aubio_filter_get_feedback (f);
     33  lsmp_t *b = bs->data[0], *a = as->data[0];
     34  uint_t order = aubio_filter_get_order (f);
     35
     36  if ( order != 5 ) {
     37    AUBIO_ERROR ( "order of C-weighting filter must be 5, not %d\n", order );
     38    return;
     39  }
     40
     41  /* select coefficients according to sampling frequency */
     42  switch ( samplerate ) {
     43
     44    case 8000:
     45      b[0] =  6.782173932405135552414776611840352416038513183593750000e-01;
     46      b[1] =  0.000000000000000000000000000000000000000000000000000000e+00;
     47      b[2] = -1.356434786481027110482955322368070483207702636718750000e+00;
     48      b[3] =  0.000000000000000000000000000000000000000000000000000000e+00;
     49      b[4] =  6.782173932405135552414776611840352416038513183593750000e-01;
     50      a[0] =  1.000000000000000000000000000000000000000000000000000000e+00;
     51      a[1] = -6.589092811505605773447769024642184376716613769531250000e-01;
     52      a[2] = -1.179445664897062595599663836765103042125701904296875000e+00;
     53      a[3] =  4.243329729632123736848825501510873436927795410156250000e-01;
     54      a[4] =  4.147270002091348328754349950031610205769538879394531250e-01;
     55      break;
     56
     57    case 16000:
     58      b[0] =  4.971057193673903418229542694461997598409652709960937500e-01;
     59      b[1] =  0.000000000000000000000000000000000000000000000000000000e+00;
     60      b[2] = -9.942114387347806836459085388923995196819305419921875000e-01;
     61      b[3] =  0.000000000000000000000000000000000000000000000000000000e+00;
     62      b[4] =  4.971057193673903418229542694461997598409652709960937500e-01;
     63      a[0] =  1.000000000000000000000000000000000000000000000000000000e+00;
     64      a[1] = -1.162322939286873690889478893950581550598144531250000000e+00;
     65      a[2] = -4.771961355734982701548574368644040077924728393554687500e-01;
     66      a[3] =  4.736145114694704227886745684372726827859878540039062500e-01;
     67      a[4] =  1.660337524309875301131711466950946487486362457275390625e-01;
     68      break;
     69
     70    case 22050:
     71      b[0] =  4.033381299002754549754001800465630367398262023925781250e-01;
     72      b[1] =  0.000000000000000000000000000000000000000000000000000000e+00;
     73      b[2] = -8.066762598005509099508003600931260734796524047851562500e-01;
     74      b[3] =  0.000000000000000000000000000000000000000000000000000000e+00;
     75      b[4] =  4.033381299002754549754001800465630367398262023925781250e-01;
     76      a[0] =  1.000000000000000000000000000000000000000000000000000000e+00;
     77      a[1] = -1.449545371157945350404361306573264300823211669921875000e+00;
     78      a[2] = -1.030104190885922088583015465701464563608169555664062500e-02;
     79      a[3] =  3.881857047554073680828423675848171114921569824218750000e-01;
     80      a[4] =  7.171589940116777917022972133054281584918498992919921875e-02;
     81      break;
     82
     83    case 44100:
     84      b[0] =  2.170085619492190254220531642204150557518005371093750000e-01;
     85      b[1] =  0.000000000000000000000000000000000000000000000000000000e+00;
     86      b[2] = -4.340171238984380508441063284408301115036010742187500000e-01;
     87      b[3] =  0.000000000000000000000000000000000000000000000000000000e+00;
     88      b[4] =  2.170085619492190254220531642204150557518005371093750000e-01;
     89      a[0] =  1.000000000000000000000000000000000000000000000000000000e+00;
     90      a[1] = -2.134674963687040794013682898366823792457580566406250000e+00;
     91      a[2] =  1.279333533236062692139967111870646476745605468750000000e+00;
     92      a[3] = -1.495598460893957093453821016737492755055427551269531250e-01;
     93      a[4] =  4.908700174624683852664386307651511742733418941497802734e-03;
     94      break;
     95
     96    case 96000:
     97      b[0] =  8.182864044979756834585771230194950476288795471191406250e-02;
     98      b[1] =  0.000000000000000000000000000000000000000000000000000000e+00;
     99      b[2] = -1.636572808995951366917154246038990095257759094238281250e-01;
     100      b[3] =  0.000000000000000000000000000000000000000000000000000000e+00;
     101      b[4] =  8.182864044979756834585771230194950476288795471191406250e-02;
     102      a[0] =  1.000000000000000000000000000000000000000000000000000000e+00;
     103      a[1] = -2.856378516857566829401093855267390608787536621093750000e+00;
     104      a[2] =  2.897640237559524045707348705036565661430358886718750000e+00;
     105      a[3] = -1.225265958339703198376469117647502571344375610351562500e+00;
     106      a[4] =  1.840048283551226071530493300087982788681983947753906250e-01;
     107      break;
     108
     109    case 192000:
     110      b[0] =  2.784755468532278815940728122768632601946592330932617188e-02;
     111      b[1] =  0.000000000000000000000000000000000000000000000000000000e+00;
     112      b[2] = -5.569510937064557631881456245537265203893184661865234375e-02;
     113      b[3] =  0.000000000000000000000000000000000000000000000000000000e+00;
     114      b[4] =  2.784755468532278815940728122768632601946592330932617188e-02;
     115      a[0] =  1.000000000000000000000000000000000000000000000000000000e+00;
     116      a[1] = -3.333298856144166322224009491037577390670776367187500000e+00;
     117      a[2] =  4.111467536240339448738723149290308356285095214843750000e+00;
     118      a[3] = -2.222889041651291641699117462849244475364685058593750000e+00;
     119      a[4] =  4.447204118126878991112960193277103826403617858886718750e-01;
     120      break;
     121
     122    default:
     123      AUBIO_ERROR ( "sampling rate of C-weighting filter is %d, should be one of\
     124 8000, 16000, 22050, 44100, 96000, 192000.\n",  samplerate );
     125      break;
     126
     127  }
     128
     129}
     130
     131aubio_filter_t * new_aubio_filter_cdsgn (uint_t samplerate, uint_t channels) {
    29132  aubio_filter_t * f = new_aubio_filter(samplerate, 5, channels);
    30   lsmp_t * a = f->a->data[0];
    31   lsmp_t * b = f->b->data[0];
    32   /* uint_t l; */
    33   /* for now, 44100, cdsgn */
    34   a[0] =  1.000000000000000000000000000000000000000000000000000000000000;
    35   a[1] = -2.134674963687040794013682898366823792457580566406250000000000;
    36   a[2] =  1.279333533236063358273781886964570730924606323242187500000000;
    37   a[3] = -0.149559846089396208945743182994192466139793395996093750000000;
    38   a[4] =  0.004908700174624848651394604104325480875559151172637939453125;
    39   b[0] =  0.217008561949218803377448239189106971025466918945312500000000;
    40   b[1] = -0.000000000000000222044604925031308084726333618164062500000000;
    41   b[2] = -0.434017123898438272888711253472138196229934692382812500000000;
    42   b[3] =  0.000000000000000402455846426619245903566479682922363281250000;
    43   b[4] =  0.217008561949218969910901932962588034570217132568359375000000;
    44   /* DBG: filter coeffs at creation time */
    45   /*
    46   for (l=0; l<f->order; l++){
    47     AUBIO_DBG("a[%d]=\t%1.16f\tb[%d]=\t%1.16f\n",l,a[l],l,b[l]);
    48   }
    49   */
    50   f->a->data[0] = a;
    51   f->b->data[0] = b;
     133  aubio_filter_set_cdsgn (f);
    52134  return f;
    53135}
  • src/temporal/cdesign.h

    rd9c45df ra4364b8  
    11/*
    2    Copyright (C) 2003-2007 Paul Brossier
     2  Copyright (C) 2003-2009 Paul Brossier <piem@aubio.org>
    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 file is part of aubio.
    85
    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.
     6  aubio is free software: you can redistribute it and/or modify
     7  it under the terms of the GNU General Public License as published by
     8  the Free Software Foundation, either version 3 of the License, or
     9  (at your option) any later version.
    1310
    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.
     11  aubio is distributed in the hope that it will be useful,
     12  but WITHOUT ANY WARRANTY; without even the implied warranty of
     13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     14  GNU General Public License for more details.
     15
     16  You should have received a copy of the GNU General Public License
     17  along with aubio.  If not, see <http://www.gnu.org/licenses/>.
    1718
    1819*/
     
    2324/** \file
    2425
    25   Create a new C-design filter
     26  Create a C-weighting filter
     27 
     28  This file creates a C-weighting digital filter, which reduces low and high
     29  frequencies and enhance the middle ones to reflect the ability of the human
     30  hearing.
     31 
     32  The implementation is based on the following standard:
    2633
    27   This file creates an IIR filter object with A-design coefficients.
     34    - IEC/CD 1672: Electroacoustics-Sound Level Meters, IEC, Geneva, Nov.  1996,
     35  for A- and C-weighting filters.
     36 
     37  See also:
     38 
     39    - <a href="http://en.wikipedia.org/wiki/A-weighting">A-Weighting on
     40  Wikipedia</a>
     41    - <a href="http://en.wikipedia.org/wiki/Weighting_filter">Weighting filter on
     42  Wikipedia</a>
     43    - <a href="http://www.mathworks.com/matlabcentral/fileexchange/69">Christophe
     44  Couvreur's 'octave' toolbox</a>
     45 
     46  The coefficients in this file have been computed using Christophe Couvreur's
     47  scripts in octave 3.0 (debian package 1:3.0.5-6+b2 with octave-signal
     48  1.0.9-1+b1 on i386), with <pre> [b, a] = cdsign(1/Fs) </pre> for various
     49  sampling frequencies.
    2850
    2951*/
     
    3557/** create new C-design filter
    3658
    37   \param samplerate sampling-rate of the signal to filter
     59  \param samplerate sampling frequency of the signal to filter. Should be one of
     60  8000, 16000, 22050, 44100, 96000, 192000.
    3861  \param channels number of channels to allocate
    3962
     63  \return a new filter object
     64
    4065*/
    41 aubio_filter_t * new_aubio_cdsgn_filter(uint_t samplerate, uint_t channels);
     66aubio_filter_t * new_aubio_filter_cdsgn (uint_t samplerate, uint_t channels);
    4267
    43 /** filter input vector (in-place) */
    44 #define aubio_cdsgn_filter_do aubio_filter_do
    45 /** delete c-design filter object */
    46 #define del_aubio_cdsgn_filter del_aubio_filter
     68/** set feedback and feedforward coefficients of a C-weighting filter
     69
     70  \param f filter object to get coefficients from
     71
     72*/
     73void aubio_filter_set_cdsgn (aubio_filter_t *f);
    4774
    4875#ifdef __cplusplus
  • src/temporal/filter.c

    rd9c45df ra4364b8  
    2727#include "mathutils.h"
    2828#include "temporal/filter.h"
    29 #include "temporal/filter_priv.h"
     29
     30struct _aubio_filter_t {
     31  uint_t order;
     32  uint_t samplerate;
     33  lvec_t * a;
     34  lvec_t * b;
     35  lvec_t * y;
     36  lvec_t * x;
     37};
    3038
    3139void aubio_filter_do(aubio_filter_t * f, fvec_t * in) {
     
    103111}
    104112
    105 aubio_filter_t * new_aubio_filter(uint_t samplerate UNUSED, uint_t order, uint_t channels) {
     113lvec_t * aubio_filter_get_feedback ( aubio_filter_t *f ) {
     114  return f->a;
     115}
     116
     117lvec_t * aubio_filter_get_feedforward ( aubio_filter_t *f ) {
     118  return f->b;
     119}
     120
     121uint_t aubio_filter_get_order ( aubio_filter_t *f ) {
     122  return f->order;
     123}
     124
     125uint_t aubio_filter_get_samplerate ( aubio_filter_t *f ) {
     126  return f->samplerate;
     127}
     128
     129aubio_filter_t * new_aubio_filter(uint_t samplerate,
     130    uint_t order, uint_t channels) {
    106131  aubio_filter_t * f = AUBIO_NEW(aubio_filter_t);
    107132  f->x = new_lvec(order, channels);
     
    109134  f->a = new_lvec(order, 1);
    110135  f->b = new_lvec(order, 1);
     136  f->samplerate = samplerate;
     137  f->order = order;
     138  /* set default to identity */
    111139  f->a->data[0][1] = 1.;
    112   f->order = order;
    113140  return f;
    114141}
    115142
    116143void del_aubio_filter(aubio_filter_t * f) {
    117   AUBIO_FREE(f->a);
    118   AUBIO_FREE(f->b);
    119   AUBIO_FREE(f->x);
    120   AUBIO_FREE(f->y);
     144  del_lvec(f->a);
     145  del_lvec(f->b);
     146  del_lvec(f->x);
     147  del_lvec(f->y);
    121148  AUBIO_FREE(f);
    122149  return;
  • src/temporal/filter.h

    rd9c45df ra4364b8  
    2323/** \file
    2424
    25   Infinite Impulse Response filter
     25  Digital filter
    2626
    27   This file implements IIR filters of any order:
     27  This object stores a digital filter of order \f$n\f$ for \f$c\f$ channels.
     28  It contains the following data:
     29    - \f$ n*1 b_i \f$ feedforward coefficients
     30    - \f$ n*1 a_i \f$ feedback coefficients
     31    - \f$ n*c x_i \f$ input signal
     32    - \f$ n*c y_i \f$ output signal
     33
     34  For convenience, the samplerate of the input signal is also stored in the object.
     35
     36  Feedforward and feedback parameters can be modified using
     37  aubio_filter_get_feedback() and aubio_filter_get_feedforward().
     38
     39  The function aubio_filter_do_outplace() computes the following output signal
     40  \f$ y[n] \f$ from the input signal \f$ x[n] \f$:
    2841 
    29   \f$ y[n] = b_1 x[n] + ... + b_{order} x[n-order] -
    30        a_2 y[n-1] - ... - a_{order} y[n-order]\f$
     42  \f{eqnarray*}{
     43     y[n] = b_0 x[n] & + & b_1 x[n-1] + b_2 x[n-2] + ... + b_P x[n-P] \\
     44                     & - & a_1 y[n-1] - a_2 y[n-2] - ... - a_P y[n-P] \\
     45  \f}
    3146
    32   The filtfilt version runs the filter twice, forward and backward, to
    33   compensate the phase shifting of the forward operation.
     47  The function aubio_filter_do() executes the same computation but modifies
     48  directly the input signal (in-place).
    3449
     50  The function aubio_filter_do_filtfilt() version runs the filter twice, first
     51  forward then backward, to compensate with the phase shifting of the forward
     52  operation.
     53
     54  Some convenience functions are provided:
     55    - new_aubio_filter_adsgn() and aubio_filter_set_adsgn(),
     56    - new_aubio_filter_cdsgn() and aubio_filter_set_cdsgn().
     57 
    3558*/
    3659
     
    3962#endif
    4063
    41 /** IIR filter object */
     64/** Digital filter
     65
     66*/
    4267typedef struct _aubio_filter_t aubio_filter_t;
    4368
    4469/** filter input vector (in-place)
    4570
    46   \param b biquad object as returned by new_aubio_biquad
     71  \param f filter object as returned by new_aubio_filter()
    4772  \param in input vector to filter
    4873
    4974*/
    50 void aubio_filter_do(aubio_filter_t * b, fvec_t * in);
     75void aubio_filter_do(aubio_filter_t * f, fvec_t * in);
     76
    5177/** filter input vector (out-of-place)
    5278
    53   \param b biquad object as returned by new_aubio_biquad
     79  \param f filter object as returned by new_aubio_filter()
    5480  \param in input vector to filter
    5581  \param out output vector to store filtered input
    5682
    5783*/
    58 void aubio_filter_do_outplace(aubio_filter_t * b, fvec_t * in, fvec_t * out);
     84void aubio_filter_do_outplace(aubio_filter_t * f, fvec_t * in, fvec_t * out);
     85
    5986/** filter input vector forward and backward
    6087
    61   \param b biquad object as returned by new_aubio_biquad
    62   \param in input vector to filter
     88  \param f ::aubio_filter_t object as returned by new_aubio_filter()
     89  \param in ::fvec_t input vector to filter
    6390  \param tmp memory space to use for computation
    6491
    6592*/
    66 void aubio_filter_do_filtfilt(aubio_filter_t * b, fvec_t * in, fvec_t * tmp);
    67 /** create new IIR filter
     93void aubio_filter_do_filtfilt(aubio_filter_t * f, fvec_t * in, fvec_t * tmp);
     94
     95/** returns a pointer to feedback coefficients \f$ a_i \f$
     96
     97  \param f filter object to get parameters from
     98
     99  \return a pointer to the \f$ a_0 ... a_i ... a_P \f$ coefficients
     100
     101*/
     102lvec_t * aubio_filter_get_feedback ( aubio_filter_t *f );
     103
     104/** returns a pointer to feedforward coefficients \f$ b_i \f$
     105
     106  \param f filter object to get coefficients from
     107
     108  \return a pointer to the \f$ b_0 ... b_i ... b_P \f$ coefficients
     109
     110*/
     111lvec_t * aubio_filter_get_feedforward ( aubio_filter_t *f );
     112
     113/** get order of the filter
     114
     115  \param f filter to get order from
     116
     117  \return the order of the filter
     118
     119*/
     120uint_t aubio_filter_get_order ( aubio_filter_t *f );
     121
     122/** get sampling rate of the filter
     123
     124  \param f filter to get sampling rate from
     125
     126  \return the sampling rate of the filter, in Hz
     127
     128*/
     129uint_t aubio_filter_get_samplerate ( aubio_filter_t *f );
     130
     131/** create new filter object
     132
     133  This function creates a new ::aubio_filter_t object, given an order
     134  and a specific number of channels.
    68135
    69136  \param samplerate signal sampling rate
     
    71138  \param channels number of channels to allocate
    72139
     140  \return the newly created filter object
     141
    73142*/
    74143aubio_filter_t * new_aubio_filter(uint_t samplerate, uint_t order, uint_t channels);
     144
    75145/** delete a filter object
    76146 
Note: See TracChangeset for help on using the changeset viewer.