Ignore:
Timestamp:
Oct 28, 2013, 12:16:11 AM (11 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:
509e8f9
Parents:
650cae3
Message:

src/synth/wavetable.c: use parameters for frequency and amplitude

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/synth/wavetable.c

    r650cae3 rc2e0aef  
    2424#include "fvec.h"
    2525#include "fmat.h"
    26 #include "io/source.h"
     26#include "utils/parameter.h"
    2727#include "synth/wavetable.h"
    2828
     
    3737  smpl_t last_pos;
    3838
    39   smpl_t target_freq;
    40   smpl_t freq;
    41   smpl_t inc_freq;
    42 
    43   smpl_t target_amp;
    44   smpl_t amp;
    45   smpl_t inc_amp;
     39  aubio_parameter_t *freq;
     40  aubio_parameter_t *amp;
    4641};
    4742
     
    6257  s->playing = 0;
    6358  s->last_pos = 0.;
    64   s->freq = 0.;
    65   s->target_freq = 0.;
    66   s->inc_freq = 0.;
    67 
    68   s->amp = 0.;
    69   s->target_amp = 0.;
    70   s->inc_amp = 0.;
     59  s->freq = new_aubio_parameter( 0., s->samplerate / 2., 10 );
     60  s->amp = new_aubio_parameter( 0., 1., 100 );
    7161  return s;
    7262}
     
    8676    smpl_t pos = s->last_pos;
    8777    for (i = 0; i < output->length; i++) {
    88       if ( ABS(s->freq - s->target_freq) > ABS(s->inc_freq) )
    89         s->freq += s->inc_freq;
    90       else
    91         s->freq = s->target_freq;
    92       smpl_t inc = s->freq * (smpl_t)(s->wavetable_length) / (smpl_t) (s->samplerate);
     78      smpl_t inc = aubio_parameter_get_next_value( s->freq );
     79      inc *= (smpl_t)(s->wavetable_length) / (smpl_t) (s->samplerate);
    9380      pos += inc;
    9481      while (pos > s->wavetable_length) {
    9582        pos -= s->wavetable_length;
    9683      }
    97       if ( ABS(s->amp - s->target_amp) > ABS(s->inc_amp) )
    98         s->amp += s->inc_amp;
    99       else
    100         s->amp = s->target_amp;
    101       output->data[i] = s->amp * interp_2(s->wavetable, pos);
     84      output->data[i] = aubio_parameter_get_next_value ( s->amp );
     85      output->data[i] *= interp_2(s->wavetable, pos);
    10286    }
    10387    s->last_pos = pos;
    10488  } else {
     89    for (i = 0; i < output->length; i++) {
     90      aubio_parameter_get_next_value ( s->freq );
     91      aubio_parameter_get_next_value ( s->amp );
     92    }
    10593    fvec_set(output, 0.);
    10694  }
     
    119107    smpl_t pos = s->last_pos;
    120108    for (j = 0; j < output->length; j++) {
    121       if ( ABS(s->freq - s->target_freq) > ABS(s->inc_freq) )
    122         s->freq += s->inc_freq;
    123       else
    124         s->freq = s->target_freq;
    125       smpl_t inc = s->freq * (smpl_t)(s->wavetable_length) / (smpl_t) (s->samplerate);
     109      smpl_t inc = aubio_parameter_get_next_value( s->freq );
     110      inc *= (smpl_t)(s->wavetable_length) / (smpl_t) (s->samplerate);
    126111      pos += inc;
    127112      while (pos > s->wavetable_length) {
    128113        pos -= s->wavetable_length;
    129114      }
    130       if ( ABS(s->amp - s->target_amp) > ABS(s->inc_amp) )
    131         s->amp += s->inc_amp;
    132       else
    133         s->amp = s->target_amp;
     115      smpl_t amp = aubio_parameter_get_next_value ( s->amp );
    134116      for (i = 0; i < output->height; i++) {
    135         output->data[i][j] = s->amp * interp_2(s->wavetable, pos);
     117        output->data[i][j] = amp * interp_2(s->wavetable, pos);
    136118      }
    137119    }
     
    139121  } else {
    140122    for (j = 0; j < output->length; j++) {
    141       if (s->freq != s->target_freq)
    142         s->freq += s->inc_freq;
     123      aubio_parameter_get_next_value ( s->freq );
     124      aubio_parameter_get_next_value ( s->amp );
    143125    }
    144126    fmat_set(output, 0.);
     
    181163uint_t aubio_wavetable_set_freq ( aubio_wavetable_t * s, smpl_t freq )
    182164{
    183   if (freq >= 0 && freq < s->samplerate / 2.) {
    184     uint_t steps = 10;
    185     s->inc_freq = (freq - s->freq) / steps;
    186     s->target_freq = freq;
    187     return 0;
    188   } else {
    189     return 1;
    190   }
     165  return aubio_parameter_set_target_value ( s->freq, freq );
    191166}
    192167
    193168smpl_t aubio_wavetable_get_freq ( aubio_wavetable_t * s) {
    194   return s->freq;
     169  return aubio_parameter_get_current_value ( s->freq);
    195170}
    196171
    197172uint_t aubio_wavetable_set_amp ( aubio_wavetable_t * s, smpl_t amp )
    198173{
    199   AUBIO_MSG("amp: %f, s->amp: %f, target_amp: %f, inc_amp: %f\n",
    200       amp, s->amp, s->target_amp, s->inc_amp);
    201   if (amp >= 0. && amp < 1.) {
    202     uint_t steps = 100;
    203     s->inc_amp = (amp - s->amp) / steps;
    204     s->target_amp = amp;
    205     AUBIO_ERR("amp: %f, s->amp: %f, target_amp: %f, inc_amp: %f\n",
    206         amp, s->amp, s->target_amp, s->inc_amp);
    207     return 0;
    208   } else {
    209     return 1;
    210   }
     174  return aubio_parameter_set_target_value ( s->amp, amp );
    211175}
    212176
    213177smpl_t aubio_wavetable_get_amp ( aubio_wavetable_t * s) {
    214   return s->amp;
     178  return aubio_parameter_get_current_value ( s->amp );
    215179}
    216180
Note: See TracChangeset for help on using the changeset viewer.