Changeset ce3ff2b for src/pitch


Ignore:
Timestamp:
Apr 21, 2016, 7:32:58 PM (9 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:
feb694b
Parents:
eaee767
Message:

src/pitch/: add const qualifiers, filter_do_outplace to avoid modifying input

Location:
src/pitch
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • src/pitch/pitch.c

    reaee767 rce3ff2b  
    6262
    6363/** callback to get pitch candidate, defined below */
    64 typedef void (*aubio_pitch_detect_t) (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * obuf);
     64typedef void (*aubio_pitch_detect_t) (aubio_pitch_t * p, const fvec_t * ibuf, fvec_t * obuf);
    6565
    6666/** callback to convert pitch from one unit to another, defined below */
     
    7979  void *p_object;                 /**< pointer to pitch object */
    8080  aubio_filter_t *filter;         /**< filter */
     81  fvec_t *filtered;               /**< filtered input */
    8182  aubio_pvoc_t *pv;               /**< phase vocoder for mcomb */
    8283  cvec_t *fftgrain;               /**< spectral frame for mcomb */
     
    8990
    9091/* callback functions for pitch detection */
    91 static void aubio_pitch_do_mcomb (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * obuf);
    92 static void aubio_pitch_do_yin (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * obuf);
    93 static void aubio_pitch_do_schmitt (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * obuf);
    94 static void aubio_pitch_do_fcomb (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * obuf);
    95 static void aubio_pitch_do_yinfft (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * obuf);
    96 static void aubio_pitch_do_specacf (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * obuf);
     92static void aubio_pitch_do_mcomb (aubio_pitch_t * p, const fvec_t * ibuf, fvec_t * obuf);
     93static void aubio_pitch_do_yin (aubio_pitch_t * p, const fvec_t * ibuf, fvec_t * obuf);
     94static void aubio_pitch_do_schmitt (aubio_pitch_t * p, const fvec_t * ibuf, fvec_t * obuf);
     95static void aubio_pitch_do_fcomb (aubio_pitch_t * p, const fvec_t * ibuf, fvec_t * obuf);
     96static void aubio_pitch_do_yinfft (aubio_pitch_t * p, const fvec_t * ibuf, fvec_t * obuf);
     97static void aubio_pitch_do_specacf (aubio_pitch_t * p, const fvec_t * ibuf, fvec_t * obuf);
    9798
    9899/* conversion functions for frequency conversions */
     
    102103
    103104/* adapter to stack ibuf new samples at the end of buf, and trim `buf` to `bufsize` */
    104 void aubio_pitch_slideblock (aubio_pitch_t * p, fvec_t * ibuf);
     105void aubio_pitch_slideblock (aubio_pitch_t * p, const fvec_t * ibuf);
    105106
    106107
    107108aubio_pitch_t *
    108 new_aubio_pitch (char_t * pitch_mode,
     109new_aubio_pitch (const char_t * pitch_mode,
    109110    uint_t bufsize, uint_t hopsize, uint_t samplerate)
    110111{
     
    161162      break;
    162163    case aubio_pitcht_mcomb:
     164      p->filtered = new_fvec (hopsize);
    163165      p->pv = new_aubio_pvoc (bufsize, hopsize);
    164166      p->fftgrain = new_cvec (bufsize);
     
    210212      break;
    211213    case aubio_pitcht_mcomb:
     214      del_fvec (p->filtered);
    212215      del_aubio_pvoc (p->pv);
    213216      del_cvec (p->fftgrain);
     
    238241
    239242void
    240 aubio_pitch_slideblock (aubio_pitch_t * p, fvec_t * ibuf)
     243aubio_pitch_slideblock (aubio_pitch_t * p, const fvec_t * ibuf)
    241244{
    242245  uint_t overlap_size = p->buf->length - ibuf->length;
     
    258261
    259262uint_t
    260 aubio_pitch_set_unit (aubio_pitch_t * p, char_t * pitch_unit)
     263aubio_pitch_set_unit (aubio_pitch_t * p, const char_t * pitch_unit)
    261264{
    262265  uint_t err = AUBIO_OK;
     
    343346/* do method, calling the detection callback, then the conversion callback */
    344347void
    345 aubio_pitch_do (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * obuf)
     348aubio_pitch_do (aubio_pitch_t * p, const fvec_t * ibuf, fvec_t * obuf)
    346349{
    347350  p->detect_cb (p, ibuf, obuf);
     
    354357/* do method for each algorithm */
    355358void
    356 aubio_pitch_do_mcomb (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * obuf)
    357 {
    358   aubio_filter_do (p->filter, ibuf);
     359aubio_pitch_do_mcomb (aubio_pitch_t * p, const fvec_t * ibuf, fvec_t * obuf)
     360{
     361  aubio_filter_do_outplace (p->filter, ibuf, p->filtered);
    359362  aubio_pvoc_do (p->pv, ibuf, p->fftgrain);
    360363  aubio_pitchmcomb_do (p->p_object, p->fftgrain, obuf);
     
    363366
    364367void
    365 aubio_pitch_do_yin (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * obuf)
     368aubio_pitch_do_yin (aubio_pitch_t * p, const fvec_t * ibuf, fvec_t * obuf)
    366369{
    367370  smpl_t pitch = 0.;
     
    379382
    380383void
    381 aubio_pitch_do_yinfft (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * obuf)
     384aubio_pitch_do_yinfft (aubio_pitch_t * p, const fvec_t * ibuf, fvec_t * obuf)
    382385{
    383386  smpl_t pitch = 0.;
     
    394397
    395398void
    396 aubio_pitch_do_specacf (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * out)
     399aubio_pitch_do_specacf (aubio_pitch_t * p, const fvec_t * ibuf, fvec_t * out)
    397400{
    398401  smpl_t pitch = 0., period;
     
    410413
    411414void
    412 aubio_pitch_do_fcomb (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * out)
     415aubio_pitch_do_fcomb (aubio_pitch_t * p, const fvec_t * ibuf, fvec_t * out)
    413416{
    414417  aubio_pitch_slideblock (p, ibuf);
     
    418421
    419422void
    420 aubio_pitch_do_schmitt (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * out)
     423aubio_pitch_do_schmitt (aubio_pitch_t * p, const fvec_t * ibuf, fvec_t * out)
    421424{
    422425  smpl_t period, pitch = 0.;
  • src/pitch/pitch.h

    reaee767 rce3ff2b  
    108108
    109109*/
    110 void aubio_pitch_do (aubio_pitch_t * o, fvec_t * in, fvec_t * out);
     110void aubio_pitch_do (aubio_pitch_t * o, const fvec_t * in, fvec_t * out);
    111111
    112112/** change yin or yinfft tolerance threshold
     
    135135
    136136*/
    137 aubio_pitch_t *new_aubio_pitch (char_t * method,
     137aubio_pitch_t *new_aubio_pitch (const char_t * method,
    138138    uint_t buf_size, uint_t hop_size, uint_t samplerate);
    139139
     
    146146
    147147*/
    148 uint_t aubio_pitch_set_unit (aubio_pitch_t * o, char_t * mode);
     148uint_t aubio_pitch_set_unit (aubio_pitch_t * o, const char_t * mode);
    149149
    150150/** set the silence threshold of the pitch detection object
  • src/pitch/pitchfcomb.c

    reaee767 rce3ff2b  
    6464/* input must be stepsize long */
    6565void
    66 aubio_pitchfcomb_do (aubio_pitchfcomb_t * p, fvec_t * input, fvec_t * output)
     66aubio_pitchfcomb_do (aubio_pitchfcomb_t * p, const fvec_t * input, fvec_t * output)
    6767{
    6868  uint_t k, l, maxharm = 0;
  • src/pitch/pitchfcomb.h

    reaee767 rce3ff2b  
    5252
    5353*/
    54 void aubio_pitchfcomb_do (aubio_pitchfcomb_t * p, fvec_t * input,
     54void aubio_pitchfcomb_do (aubio_pitchfcomb_t * p, const fvec_t * input,
    5555    fvec_t * output);
    5656
  • src/pitch/pitchmcomb.c

    reaee767 rce3ff2b  
    3232    uint_t length);
    3333uint_t aubio_pitchmcomb_quadpick (aubio_spectralpeak_t * spectral_peaks,
    34     fvec_t * X);
    35 void aubio_pitchmcomb_spectral_pp (aubio_pitchmcomb_t * p, fvec_t * oldmag);
    36 void aubio_pitchmcomb_combdet (aubio_pitchmcomb_t * p, fvec_t * newmag);
     34    const fvec_t * X);
     35void aubio_pitchmcomb_spectral_pp (aubio_pitchmcomb_t * p, const fvec_t * oldmag);
     36void aubio_pitchmcomb_combdet (aubio_pitchmcomb_t * p, const fvec_t * newmag);
    3737/* not used but useful : sort by amplitudes (or anything else)
    3838 * sort_pitchpeak(peaks, length);
     
    4343void aubio_pitchmcomb_sort_peak (aubio_spectralpeak_t * peaks, uint_t nbins);
    4444/** select the best candidates */
    45 uint_t aubio_pitch_cands (aubio_pitchmcomb_t * p, cvec_t * fftgrain,
     45uint_t aubio_pitch_cands (aubio_pitchmcomb_t * p, const cvec_t * fftgrain,
    4646    smpl_t * cands);
    4747
     
    102102
    103103void
    104 aubio_pitchmcomb_do (aubio_pitchmcomb_t * p, cvec_t * fftgrain, fvec_t * output)
     104aubio_pitchmcomb_do (aubio_pitchmcomb_t * p, const cvec_t * fftgrain, fvec_t * output)
    105105{
    106106  uint_t j;
     
    135135
    136136uint_t
    137 aubio_pitch_cands (aubio_pitchmcomb_t * p, cvec_t * fftgrain, smpl_t * cands)
     137aubio_pitch_cands (aubio_pitchmcomb_t * p, const cvec_t * fftgrain, smpl_t * cands)
    138138{
    139139  uint_t j;
     
    166166
    167167void
    168 aubio_pitchmcomb_spectral_pp (aubio_pitchmcomb_t * p, fvec_t * newmag)
     168aubio_pitchmcomb_spectral_pp (aubio_pitchmcomb_t * p, const fvec_t * newmag)
    169169{
    170170  fvec_t *mag = (fvec_t *) p->scratch;
     
    198198
    199199void
    200 aubio_pitchmcomb_combdet (aubio_pitchmcomb_t * p, fvec_t * newmag)
     200aubio_pitchmcomb_combdet (aubio_pitchmcomb_t * p, const fvec_t * newmag)
    201201{
    202202  aubio_spectralpeak_t *peaks = (aubio_spectralpeak_t *) p->peaks;
     
    286286 */
    287287uint_t
    288 aubio_pitchmcomb_quadpick (aubio_spectralpeak_t * spectral_peaks, fvec_t * X)
     288aubio_pitchmcomb_quadpick (aubio_spectralpeak_t * spectral_peaks, const fvec_t * X)
    289289{
    290290  uint_t j, ispeak, count = 0;
  • src/pitch/pitchmcomb.h

    reaee767 rce3ff2b  
    5353
    5454*/
    55 void aubio_pitchmcomb_do (aubio_pitchmcomb_t * p, cvec_t * in_fftgrain,
     55void aubio_pitchmcomb_do (aubio_pitchmcomb_t * p, const cvec_t * in_fftgrain,
    5656    fvec_t * out_cands);
    5757
  • src/pitch/pitchschmitt.c

    reaee767 rce3ff2b  
    4848
    4949void
    50 aubio_pitchschmitt_do (aubio_pitchschmitt_t * p, fvec_t * input,
     50aubio_pitchschmitt_do (aubio_pitchschmitt_t * p, const fvec_t * input,
    5151    fvec_t * output)
    5252{
  • src/pitch/pitchschmitt.h

    reaee767 rce3ff2b  
    5252
    5353*/
    54 void aubio_pitchschmitt_do (aubio_pitchschmitt_t * p, fvec_t * samples_in,
     54void aubio_pitchschmitt_do (aubio_pitchschmitt_t * p, const fvec_t * samples_in,
    5555    fvec_t * cands_out);
    5656
  • src/pitch/pitchspecacf.c

    reaee767 rce3ff2b  
    5555
    5656void
    57 aubio_pitchspecacf_do (aubio_pitchspecacf_t * p, fvec_t * input, fvec_t * output)
     57aubio_pitchspecacf_do (aubio_pitchspecacf_t * p, const fvec_t * input, fvec_t * output)
    5858{
    5959  uint_t l, tau;
     
    9292
    9393smpl_t
    94 aubio_pitchspecacf_get_confidence (aubio_pitchspecacf_t * o) {
     94aubio_pitchspecacf_get_confidence (const aubio_pitchspecacf_t * o) {
    9595  // no confidence for now
    9696  return o->confidence;
     
    105105
    106106smpl_t
    107 aubio_pitchspecacf_get_tolerance (aubio_pitchspecacf_t * p)
     107aubio_pitchspecacf_get_tolerance (const aubio_pitchspecacf_t * p)
    108108{
    109109  return p->tol;
  • src/pitch/pitchspecacf.h

    reaee767 rce3ff2b  
    5656
    5757*/
    58 void aubio_pitchspecacf_do (aubio_pitchspecacf_t * o, fvec_t * samples_in, fvec_t * cands_out);
     58void aubio_pitchspecacf_do (aubio_pitchspecacf_t * o, const fvec_t * samples_in, fvec_t * cands_out);
    5959/** creation of the pitch detection object
    6060
     
    7777
    7878*/
    79 smpl_t aubio_pitchspecacf_get_tolerance (aubio_pitchspecacf_t * o);
     79smpl_t aubio_pitchspecacf_get_tolerance (const aubio_pitchspecacf_t * o);
    8080
    8181/** set tolerance parameter for `specacf` pitch detection object
     
    9595
    9696*/
    97 smpl_t aubio_pitchspecacf_get_confidence (aubio_pitchspecacf_t * o);
     97smpl_t aubio_pitchspecacf_get_confidence (const aubio_pitchspecacf_t * o);
    9898
    9999#ifdef __cplusplus
  • src/pitch/pitchyin.c

    reaee767 rce3ff2b  
    4141
    4242/** compute difference function
    43  
    44   \param input input signal 
     43
     44  \param input input signal
    4545  \param yinbuf output buffer to store difference function (half shorter than input)
    4646
     
    4848void aubio_pitchyin_diff (fvec_t * input, fvec_t * yinbuf);
    4949
    50 /** in place computation of the YIN cumulative normalised function 
    51  
    52   \param yinbuf input signal (a square difference function), also used to store function 
     50/** in place computation of the YIN cumulative normalised function
     51
     52  \param yinbuf input signal (a square difference function), also used to store function
    5353
    5454*/
     
    5656
    5757/** detect pitch in a YIN function
    58  
     58
    5959  \param yinbuf input buffer as computed by aubio_pitchyin_getcum
    6060
    6161*/
    62 uint_t aubio_pitchyin_getpitch (fvec_t * yinbuf);
     62uint_t aubio_pitchyin_getpitch (const fvec_t * yinbuf);
    6363
    6464aubio_pitchyin_t *
     
    112112
    113113uint_t
    114 aubio_pitchyin_getpitch (fvec_t * yin)
     114aubio_pitchyin_getpitch (const fvec_t * yin)
    115115{
    116116  uint_t tau = 1;
     
    131131/* all the above in one */
    132132void
    133 aubio_pitchyin_do (aubio_pitchyin_t * o, fvec_t * input, fvec_t * out)
     133aubio_pitchyin_do (aubio_pitchyin_t * o, const fvec_t * input, fvec_t * out)
    134134{
    135135  smpl_t tol = o->tol;
  • src/pitch/pitchyin.h

    reaee767 rce3ff2b  
    6767
    6868*/
    69 void aubio_pitchyin_do (aubio_pitchyin_t * o, fvec_t * samples_in, fvec_t * cands_out);
     69void aubio_pitchyin_do (aubio_pitchyin_t * o, const fvec_t * samples_in, fvec_t * cands_out);
    7070
    7171
  • src/pitch/pitchyinfft.c

    reaee767 rce3ff2b  
    9999
    100100void
    101 aubio_pitchyinfft_do (aubio_pitchyinfft_t * p, fvec_t * input, fvec_t * output)
     101aubio_pitchyinfft_do (aubio_pitchyinfft_t * p, const fvec_t * input, fvec_t * output)
    102102{
    103103  uint_t tau, l;
  • src/pitch/pitchyinfft.h

    reaee767 rce3ff2b  
    5353
    5454*/
    55 void aubio_pitchyinfft_do (aubio_pitchyinfft_t * o, fvec_t * samples_in, fvec_t * cands_out);
     55void aubio_pitchyinfft_do (aubio_pitchyinfft_t * o, const fvec_t * samples_in, fvec_t * cands_out);
    5656/** creation of the pitch detection object
    5757
Note: See TracChangeset for help on using the changeset viewer.