Changeset 59c046d


Ignore:
Timestamp:
Oct 19, 2009, 1:52:04 PM (10 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/autosink, feature/constantq, feature/pitchshift, feature/pydocstrings, feature/timestretch, master, pitchshift, sampler, timestretch, yinfft+
Children:
b01bd4a
Parents:
b14107f
Message:

src/spectral/filter.c, src/temporal/filterbank_mel.c: move samplerate to the end

Files:
12 edited

Legend:

Unmodified
Added
Removed
  • src/spectral/filterbank_mel.c

    rb14107f r59c046d  
    2828uint_t
    2929aubio_filterbank_set_triangle_bands (aubio_filterbank_t * fb,
    30     smpl_t samplerate, fvec_t * freqs)
     30    fvec_t * freqs, smpl_t samplerate)
    3131{
    3232
     
    191191
    192192  /* now compute the actual coefficients */
    193   retval = aubio_filterbank_set_triangle_bands (fb, samplerate, freqs);
     193  retval = aubio_filterbank_set_triangle_bands (fb, freqs, samplerate);
    194194
    195195  /* destroy vector used to store frequency limits */
  • src/spectral/filterbank_mel.h

    rb14107f r59c046d  
    5151*/
    5252uint_t aubio_filterbank_set_triangle_bands (aubio_filterbank_t * fb,
    53     smpl_t samplerate, fvec_t * freqs);
     53    fvec_t * freqs, smpl_t samplerate);
    5454
    5555/** filterbank initialization for Mel filters using Slaney's coefficients
  • src/temporal/a_weighting.c

    rb14107f r59c046d  
    11/*
    2 
    32  Copyright (C) 2003-2009 Paul Brossier <piem@aubio.org>
    43
     
    2726#include "temporal/a_weighting.h"
    2827
    29 uint_t aubio_filter_set_a_weighting (aubio_filter_t * f) {
    30 
    31   uint_t samplerate = aubio_filter_get_samplerate (f);
     28uint_t
     29aubio_filter_set_a_weighting (aubio_filter_t * f, uint_t samplerate)
     30{
     31  aubio_filter_set_samplerate (f, samplerate);
    3232  lvec_t *bs = aubio_filter_get_feedforward (f);
    3333  lvec_t *as = aubio_filter_get_feedback (f);
     
    3535  uint_t order = aubio_filter_get_order (f);
    3636
    37   if ( order != 7 ) {
    38     AUBIO_ERROR ( "order of A-weighting filter must be 7, not %d\n", order );
     37  if (order != 7) {
     38    AUBIO_ERROR ("order of A-weighting filter must be 7, not %d\n", order);
    3939    return 1;
    4040  }
    4141
    4242  /* select coefficients according to sampling frequency */
    43   switch ( samplerate ) {
    44 
    45     // adsgn 8000
     43  switch (samplerate) {
     44
    4645    case 8000:
    4746      b[0] =  6.306209468238731519207362907764036208391189575195312500e-01;
     
    6160      break;
    6261
    63     // adsgn 11025
    6462    case 11025:
    6563      b[0] =  6.014684165832374640459079273568931967020034790039062500e-01;
     
    7977      break;
    8078
    81     // adsgn 16000
    8279    case 16000:
    8380      b[0] =  5.314898298235570806014038680586963891983032226562500000e-01;
     
    9794      break;
    9895
    99     // adsgn 22050
    10096    case 22050:
    10197      b[0] =  4.492998504299193784916610638902056962251663208007812500e-01;
     
    115111      break;
    116112
    117     // adsgn 24000
    118113    case 24000:
    119114      b[0] =  4.256263892891054001488271296693710610270500183105468750e-01;
     
    133128      break;
    134129
    135     // adsgn 32000
    136130    case 32000:
    137131      b[0] =  3.434583386824304196416335344110848382115364074707031250e-01;
     
    151145      break;
    152146
    153     // adsgn 44100
    154147    case 44100:
    155148      b[0] =  2.557411252042575133813784304948057979345321655273437500e-01;
     
    169162      break;
    170163
    171     // adsgn 48000
    172164    case 48000:
    173165      b[0] =  2.343017922995132285013397677175817079842090606689453125e-01;
     
    187179      break;
    188180
    189     // adsgn 88200
    190181    case 88200:
    191182      b[0] =  1.118876366882113199130444058937428053468465805053710938e-01;
     
    205196      break;
    206197
    207     // adsgn 96000
    208198    case 96000:
    209199      b[0] =  9.951898975972744976203898659150581806898117065429687500e-02;
     
    223213      break;
    224214
    225     // adsgn 192000
    226215    case 192000:
    227216      b[0] =  3.433213424548713782469278044118254911154508590698242188e-02;
     
    241230      break;
    242231
    243     default:
    244       AUBIO_ERROR ( "sampling rate of A-weighting filter is %d, should be one of\
    245  8000, 11025, 16000, 22050, 24000, 32000, 44100, 48000, 88200, 96000, 192000.\n",
    246  samplerate );
     232    default:
     233      AUBIO_ERROR ("sampling rate of A-weighting filter is %d, should be one of\
     234 8000, 11025, 16000, 22050, 24000, 32000, 44100, 48000, 88200, 96000, 192000.\n", samplerate);
    247235      return 1;
    248236
     
    252240}
    253241
    254 aubio_filter_t * new_aubio_filter_a_weighting (uint_t samplerate, uint_t channels) {
    255   aubio_filter_t * f = new_aubio_filter (samplerate, 7, channels);
    256   aubio_filter_set_a_weighting (f);
     242aubio_filter_t *
     243new_aubio_filter_a_weighting (uint_t channels, uint_t samplerate)
     244{
     245  aubio_filter_t *f = new_aubio_filter (7, channels);
     246  aubio_filter_set_a_weighting (f, samplerate);
    257247  return f;
    258248}
    259 
  • src/temporal/a_weighting.h

    rb14107f r59c046d  
    6969
    7070*/
    71 aubio_filter_t * new_aubio_filter_a_weighting (uint_t samplerate, uint_t channels);
     71aubio_filter_t *new_aubio_filter_a_weighting (uint_t channels,
     72    uint_t samplerate);
    7273
    7374/** set feedback and feedforward coefficients of a A-weighting filter
     
    7677
    7778*/
    78 uint_t aubio_filter_set_a_weighting (aubio_filter_t *f);
     79uint_t aubio_filter_set_a_weighting (aubio_filter_t *f, uint_t samplerate);
    7980
    8081#ifdef __cplusplus
  • src/temporal/c_weighting.c

    rb14107f r59c046d  
    2626#include "temporal/c_weighting.h"
    2727
    28 uint_t aubio_filter_set_c_weighting (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);
     28uint_t
     29aubio_filter_set_c_weighting (aubio_filter_t * f, uint_t samplerate)
     30{
     31  aubio_filter_set_samplerate (f, samplerate);
     32  lvec_t *bs = aubio_filter_get_feedforward (f);
     33  lvec_t *as = aubio_filter_get_feedback (f);
    3334  lsmp_t *b = bs->data[0], *a = as->data[0];
    3435  uint_t order = aubio_filter_get_order (f);
    3536
    3637  if ( order != 5 ) {
    37     AUBIO_ERROR ( "order of C-weighting filter must be 5, not %d\n", order );
     38    AUBIO_ERROR ("order of C-weighting filter must be 5, not %d\n", order);
    3839    return 1;
    3940  }
    4041
    4142  /* select coefficients according to sampling frequency */
    42   switch ( samplerate ) {
    43 
    44     // cdsgn 8000
     43  switch (samplerate) {
     44
    4545    case 8000:
    4646      b[0] =  6.782173932405135552414776611840352416038513183593750000e-01;
     
    5656      break;
    5757
    58     // cdsgn 11025
    5958    case 11025:
    6059      b[0] =  6.002357155402652244546857218665536493062973022460937500e-01;
     
    7069      break;
    7170
    72     // cdsgn 16000
    7371    case 16000:
    7472      b[0] =  4.971057193673903418229542694461997598409652709960937500e-01;
     
    8482      break;
    8583
    86     // cdsgn 22050
    8784    case 22050:
    8885      b[0] =  4.033381299002754549754001800465630367398262023925781250e-01;
     
    9895      break;
    9996
    100     // cdsgn 24000
    10197    case 24000:
    10298      b[0] =  3.786678621924967069745093795063439756631851196289062500e-01;
     
    112108      break;
    113109
    114     // cdsgn 32000
    115110    case 32000:
    116111      b[0] =  2.977986488230693340462096330156782642006874084472656250e-01;
     
    126121      break;
    127122
    128     // cdsgn 44100
    129123    case 44100:
    130124      b[0] =  2.170085619492190254220531642204150557518005371093750000e-01;
     
    140134      break;
    141135
    142     // cdsgn 48000
    143136    case 48000:
    144137      b[0] =  1.978871200263932761398422144338837824761867523193359375e-01;
     
    154147      break;
    155148
    156     // cdsgn 88200
    157149    case 88200:
    158150      b[0] =  9.221909851156021020734954163344809785485267639160156250e-02;
     
    168160      break;
    169161
    170     // cdsgn 96000
    171162    case 96000:
    172163      b[0] =  8.182864044979756834585771230194950476288795471191406250e-02;
     
    182173      break;
    183174
    184     // cdsgn 192000
    185175    case 192000:
    186176      b[0] =  2.784755468532278815940728122768632601946592330932617188e-02;
     
    207197}
    208198
    209 aubio_filter_t * new_aubio_filter_c_weighting (uint_t samplerate, uint_t channels) {
    210   aubio_filter_t * f = new_aubio_filter(samplerate, 5, channels);
    211   aubio_filter_set_c_weighting (f);
     199aubio_filter_t * new_aubio_filter_c_weighting (uint_t channels, uint_t samplerate) {
     200  aubio_filter_t * f = new_aubio_filter(5, channels);
     201  aubio_filter_set_c_weighting (f, samplerate);
    212202  return f;
    213203}
  • src/temporal/c_weighting.h

    rb14107f r59c046d  
    6969
    7070*/
    71 aubio_filter_t * new_aubio_filter_c_weighting (uint_t samplerate, uint_t channels);
     71aubio_filter_t * new_aubio_filter_c_weighting (uint_t channels, uint_t samplerate);
    7272
    7373/** set feedback and feedforward coefficients of a C-weighting filter
     
    7676
    7777*/
    78 uint_t aubio_filter_set_c_weighting (aubio_filter_t *f);
     78uint_t aubio_filter_set_c_weighting (aubio_filter_t *f, uint_t samplerate);
    7979
    8080#ifdef __cplusplus
  • src/temporal/filter.c

    rb14107f r59c046d  
    138138}
    139139
     140uint_t
     141aubio_filter_set_samplerate (aubio_filter_t * f, uint_t samplerate)
     142{
     143  f->samplerate = samplerate;
     144  return AUBIO_OK;
     145}
     146
    140147aubio_filter_t *
    141 new_aubio_filter (uint_t samplerate, uint_t order, uint_t channels)
     148new_aubio_filter (uint_t order, uint_t channels)
    142149{
    143150  aubio_filter_t *f = AUBIO_NEW (aubio_filter_t);
     
    146153  f->a = new_lvec (order, 1);
    147154  f->b = new_lvec (order, 1);
    148   f->samplerate = samplerate;
     155  /* by default, samplerate is not set */
     156  f->samplerate = 0;
    149157  f->order = order;
    150158  /* set default to identity */
  • src/temporal/filter.h

    rb14107f r59c046d  
    131131uint_t aubio_filter_get_samplerate (aubio_filter_t * f);
    132132
     133/** get sampling rate of the filter
     134
     135  \param f filter to get sampling rate from
     136  \param samplerate sample rate to set the filter to
     137
     138  \return the sampling rate of the filter, in Hz
     139
     140*/
     141uint_t aubio_filter_set_samplerate (aubio_filter_t * f, uint_t samplerate);
     142
    133143/** create new filter object
    134144
     
    143153
    144154*/
    145 aubio_filter_t *new_aubio_filter (uint_t samplerate, uint_t order,
    146     uint_t channels);
     155aubio_filter_t *new_aubio_filter (uint_t order, uint_t channels);
    147156
    148157/** delete a filter object
  • swig/aubio.i

    rb14107f r59c046d  
    7272
    7373/* filter */
    74 aubio_filter_t * new_aubio_filter(uint_t samplerate, uint_t order, uint_t channels);
     74aubio_filter_t * new_aubio_filter(uint_t order, uint_t channels);
    7575void aubio_filter_do(aubio_filter_t * b, fvec_t * in);
    7676void aubio_filter_do_outplace(aubio_filter_t * b, fvec_t * in, fvec_t * out);
     
    7878void del_aubio_filter(aubio_filter_t * b);
    7979
    80 aubio_filter_t * new_aubio_filter_a_weighting (uint_t samplerate, uint_t channels);
    81 uint_t aubio_filter_set_a_weighting (aubio_filter_t * b);
    82 
    83 aubio_filter_t * new_aubio_filter_c_weighting (uint_t samplerate, uint_t channels);
    84 uint_t aubio_filter_set_c_weighting (aubio_filter_t * b);
     80aubio_filter_t * new_aubio_filter_a_weighting (uint_t channels, uint_t samplerate);
     81uint_t aubio_filter_set_a_weighting (aubio_filter_t * b, uint_t samplerate);
     82
     83aubio_filter_t * new_aubio_filter_c_weighting (uint_t channels, uint_t samplerate);
     84uint_t aubio_filter_set_c_weighting (aubio_filter_t * b, uint_t samplerate);
    8585
    8686/* biquad */
     
    135135/* filterbank */
    136136aubio_filterbank_t * new_aubio_filterbank(uint_t win_s, uint_t channels);
    137 void aubio_filterbank_set_triangle_bands (aubio_filterbank_t *fb, uint_t samplerate, fvec_t *freqs);
     137void aubio_filterbank_set_triangle_bands (aubio_filterbank_t *fb, fvec_t *freqs, uint_t samplerate);
    138138void aubio_filterbank_set_mel_coeffs_slaney(aubio_filterbank_t *fb, uint_t samplerate);
    139139void del_aubio_filterbank(aubio_filterbank_t * fb);
  • tests/src/temporal/test-aweighting.c

    rb14107f r59c046d  
    1111
    1212  for ( samplerate = rates[i]; i < nrates ; i++ ) {
    13     f = new_aubio_filter_a_weighting (samplerate, channels);
     13    f = new_aubio_filter_a_weighting (channels, samplerate);
    1414    del_aubio_filter (f);
    1515
    16     f = new_aubio_filter (samplerate, 7, channels*2);
    17     aubio_filter_set_a_weighting (f);
     16    f = new_aubio_filter (7, channels*2);
     17    aubio_filter_set_a_weighting (f, samplerate);
    1818    del_aubio_filter (f);
    1919  }
    2020
    2121  // samplerate unknown
    22   f = new_aubio_filter_a_weighting (12089, channels);
     22  f = new_aubio_filter_a_weighting (channels, 4200);
    2323  del_aubio_filter (f);
    2424
    2525  // order to small
    26   f = new_aubio_filter (samplerate, 2, channels*2);
    27   aubio_filter_set_a_weighting (f);
     26  f = new_aubio_filter (2, channels*2);
     27  aubio_filter_set_a_weighting (f, samplerate);
    2828  del_aubio_filter (f);
    2929
    3030  // order to big
    31   f = new_aubio_filter (samplerate, 12, channels*2);
    32   aubio_filter_set_a_weighting (f);
     31  f = new_aubio_filter (12, channels*2);
     32  aubio_filter_set_a_weighting (f, samplerate);
    3333  del_aubio_filter (f);
    3434
  • tests/src/temporal/test-cweighting.c

    rb14107f r59c046d  
    1111
    1212  for ( samplerate = rates[i]; i < nrates ; i++ ) {
    13     f = new_aubio_filter_c_weighting (samplerate, channels);
     13    f = new_aubio_filter_c_weighting (channels, samplerate);
    1414    del_aubio_filter (f);
    1515
    16     f = new_aubio_filter (samplerate, 5, channels*2);
    17     aubio_filter_set_c_weighting (f);
     16    f = new_aubio_filter (5, channels*2);
     17    aubio_filter_set_c_weighting (f, samplerate);
    1818    del_aubio_filter (f);
    1919  }
    2020
    2121  // samplerate unknown
    22   f = new_aubio_filter_c_weighting (12089, channels);
     22  f = new_aubio_filter_c_weighting (channels, 4200);
    2323  del_aubio_filter (f);
    2424
    2525  // order to small
    26   f = new_aubio_filter (samplerate, 2, channels*2);
    27   aubio_filter_set_c_weighting (f);
     26  f = new_aubio_filter (2, channels*2);
     27  aubio_filter_set_c_weighting (f, samplerate);
    2828  del_aubio_filter (f);
    2929
    3030  // order to big
    31   f = new_aubio_filter (samplerate, 12, channels*2);
    32   aubio_filter_set_c_weighting (f);
     31  f = new_aubio_filter (12, channels*2);
     32  aubio_filter_set_c_weighting (f, samplerate);
    3333  del_aubio_filter (f);
    3434
  • tests/src/test-filter.c

    rb14107f r59c046d  
    1111
    1212
    13   aubio_filter_t *o = new_aubio_filter_c_weighting (44100, channels);
     13  aubio_filter_t *o = new_aubio_filter_c_weighting (channels, 44100);
    1414  in->data[0][12] = 0.5;
    1515  fvec_print (in);
     
    1818  del_aubio_filter (o);
    1919
    20   o = new_aubio_filter_c_weighting (44100, channels);
     20  o = new_aubio_filter_c_weighting (channels, 44100);
    2121  in->data[0][12] = 0.5;
    2222  fvec_print (in);
     
    2525  del_aubio_filter (o);
    2626
    27   o = new_aubio_filter_c_weighting (44100, channels);
     27  o = new_aubio_filter_c_weighting (channels, 44100);
    2828  in->data[0][12] = 0.5;
    2929  fvec_print (in);
Note: See TracChangeset for help on using the changeset viewer.