/* Copyright (C) 2003-2009 Paul Brossier This file is part of aubio. aubio is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. aubio is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with aubio. If not, see . */ #include "aubio_priv.h" #include "types.h" #include "fvec.h" #include "lvec.h" #include "temporal/filter.h" #include "temporal/c_weighting.h" void aubio_filter_set_c_weighting (aubio_filter_t * f) { uint_t samplerate = aubio_filter_get_samplerate (f); lvec_t * bs = aubio_filter_get_feedforward (f); lvec_t * as = aubio_filter_get_feedback (f); lsmp_t *b = bs->data[0], *a = as->data[0]; uint_t order = aubio_filter_get_order (f); if ( order != 5 ) { AUBIO_ERROR ( "order of C-weighting filter must be 5, not %d\n", order ); return; } /* select coefficients according to sampling frequency */ switch ( samplerate ) { case 8000: b[0] = 6.782173932405135552414776611840352416038513183593750000e-01; b[1] = 0.000000000000000000000000000000000000000000000000000000e+00; b[2] = -1.356434786481027110482955322368070483207702636718750000e+00; b[3] = 0.000000000000000000000000000000000000000000000000000000e+00; b[4] = 6.782173932405135552414776611840352416038513183593750000e-01; a[0] = 1.000000000000000000000000000000000000000000000000000000e+00; a[1] = -6.589092811505605773447769024642184376716613769531250000e-01; a[2] = -1.179445664897062595599663836765103042125701904296875000e+00; a[3] = 4.243329729632123736848825501510873436927795410156250000e-01; a[4] = 4.147270002091348328754349950031610205769538879394531250e-01; break; case 16000: b[0] = 4.971057193673903418229542694461997598409652709960937500e-01; b[1] = 0.000000000000000000000000000000000000000000000000000000e+00; b[2] = -9.942114387347806836459085388923995196819305419921875000e-01; b[3] = 0.000000000000000000000000000000000000000000000000000000e+00; b[4] = 4.971057193673903418229542694461997598409652709960937500e-01; a[0] = 1.000000000000000000000000000000000000000000000000000000e+00; a[1] = -1.162322939286873690889478893950581550598144531250000000e+00; a[2] = -4.771961355734982701548574368644040077924728393554687500e-01; a[3] = 4.736145114694704227886745684372726827859878540039062500e-01; a[4] = 1.660337524309875301131711466950946487486362457275390625e-01; break; case 22050: b[0] = 4.033381299002754549754001800465630367398262023925781250e-01; b[1] = 0.000000000000000000000000000000000000000000000000000000e+00; b[2] = -8.066762598005509099508003600931260734796524047851562500e-01; b[3] = 0.000000000000000000000000000000000000000000000000000000e+00; b[4] = 4.033381299002754549754001800465630367398262023925781250e-01; a[0] = 1.000000000000000000000000000000000000000000000000000000e+00; a[1] = -1.449545371157945350404361306573264300823211669921875000e+00; a[2] = -1.030104190885922088583015465701464563608169555664062500e-02; a[3] = 3.881857047554073680828423675848171114921569824218750000e-01; a[4] = 7.171589940116777917022972133054281584918498992919921875e-02; break; case 44100: b[0] = 2.170085619492190254220531642204150557518005371093750000e-01; b[1] = 0.000000000000000000000000000000000000000000000000000000e+00; b[2] = -4.340171238984380508441063284408301115036010742187500000e-01; b[3] = 0.000000000000000000000000000000000000000000000000000000e+00; b[4] = 2.170085619492190254220531642204150557518005371093750000e-01; a[0] = 1.000000000000000000000000000000000000000000000000000000e+00; a[1] = -2.134674963687040794013682898366823792457580566406250000e+00; a[2] = 1.279333533236062692139967111870646476745605468750000000e+00; a[3] = -1.495598460893957093453821016737492755055427551269531250e-01; a[4] = 4.908700174624683852664386307651511742733418941497802734e-03; break; case 96000: b[0] = 8.182864044979756834585771230194950476288795471191406250e-02; b[1] = 0.000000000000000000000000000000000000000000000000000000e+00; b[2] = -1.636572808995951366917154246038990095257759094238281250e-01; b[3] = 0.000000000000000000000000000000000000000000000000000000e+00; b[4] = 8.182864044979756834585771230194950476288795471191406250e-02; a[0] = 1.000000000000000000000000000000000000000000000000000000e+00; a[1] = -2.856378516857566829401093855267390608787536621093750000e+00; a[2] = 2.897640237559524045707348705036565661430358886718750000e+00; a[3] = -1.225265958339703198376469117647502571344375610351562500e+00; a[4] = 1.840048283551226071530493300087982788681983947753906250e-01; break; case 192000: b[0] = 2.784755468532278815940728122768632601946592330932617188e-02; b[1] = 0.000000000000000000000000000000000000000000000000000000e+00; b[2] = -5.569510937064557631881456245537265203893184661865234375e-02; b[3] = 0.000000000000000000000000000000000000000000000000000000e+00; b[4] = 2.784755468532278815940728122768632601946592330932617188e-02; a[0] = 1.000000000000000000000000000000000000000000000000000000e+00; a[1] = -3.333298856144166322224009491037577390670776367187500000e+00; a[2] = 4.111467536240339448738723149290308356285095214843750000e+00; a[3] = -2.222889041651291641699117462849244475364685058593750000e+00; a[4] = 4.447204118126878991112960193277103826403617858886718750e-01; break; default: AUBIO_ERROR ( "sampling rate of C-weighting filter is %d, should be one of\ 8000, 16000, 22050, 44100, 96000, 192000.\n", samplerate ); break; } } aubio_filter_t * new_aubio_filter_c_weighting (uint_t samplerate, uint_t channels) { aubio_filter_t * f = new_aubio_filter(samplerate, 5, channels); aubio_filter_set_c_weighting (f); return f; }