Changeset 2ca4b59 for src/synth


Ignore:
Timestamp:
Oct 11, 2016, 2:37:25 AM (7 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
sampler
Children:
a125fb9a
Parents:
a006c5f
Message:

src/synth/sampler.c: add _set_table and allow switching to/from table or source

Location:
src/synth
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/synth/sampler.c

    ra006c5f r2ca4b59  
    6060  // current interpolation mode (can be quadratic, timestretch, ...)
    6161  uint_t interp;
    62   // reading from a table
    6362  aubio_ringbuffer_t *ring;
    6463  uint_t perfectloop;
    6564  uint_t eof_remaining;
    66   fvec_t *samples;
    67   fmat_t *msamples;
     65  // reading from a table
     66  fvec_t *table;
     67  uint_t table_index;
    6868  // reading from a source
    6969  aubio_source_t *source;
     
    171171#endif
    172172
     173#if 0
     174  s->reading_from = aubio_sampler_reading_from_table;
     175  s->perfectloop = 1;
     176  s->threaded_read = 0;
     177  s->opened = 1;
     178  s->finished = 1;
     179  s->table_index = 0;
     180#endif
     181
    173182  return s;
    174183beach:
     
    196205  // clean up opening thread
    197206  void *threadret;
     207  if (!o->open_thread) return;
    198208  pthread_mutex_destroy(&o->open_mutex);
    199209  if (o->open_thread_running) {
     
    206216  }
    207217  pthread_mutex_destroy(&o->open_mutex);
     218  o->open_thread = 0;
    208219}
    209220
     
    223234  pthread_cond_destroy(&o->read_avail);
    224235  pthread_cond_destroy(&o->read_request);
     236  o->read_thread = 0;
    225237}
    226238#endif
     
    293305#ifdef HAVE_THREADS
    294306  uint_t ret = AUBIO_OK;
     307
     308  if (o->reading_from == aubio_sampler_reading_from_table) {
     309    o->reading_from = aubio_sampler_reading_from_source;
     310    o->opened = 0;
     311    o->finished = 1;
     312  }
    295313  /* open uri in open_thread */
    296314  if (o->open_thread_running) {
     
    549567
    550568void
    551 aubio_sampler_read_from_table(aubio_sampler_t *o, fvec_t *output, uint_t *read) {
     569aubio_sampler_read_from_table(aubio_sampler_t *s, fvec_t *output, uint_t *read) {
    552570  *read = 0;
    553   AUBIO_WRN("sampler: _pull_from_table not implemented for %d, %d, %d",
    554       o, output->length, *read);
     571  if (s->table == NULL) {
     572    AUBIO_WRN("sampler: _pull_from_table but table not set %d, %d\n",
     573        output->length, *read);
     574  } else if (s->playing) {
     575    uint_t available = s->table->length - s->table_index;
     576    fvec_t tmp;
     577    tmp.data = s->table->data + s->table_index;
     578    if (available < s->blocksize) {
     579      //AUBIO_WRN("sampler: _pull_from_table: table length %d, index: %d, read %d\n",
     580      //    s->table->length, s->table_index, *read);
     581      tmp.length = available;
     582      fvec_t tmpout; tmpout.data = output->data; tmpout.length = available;
     583      fvec_copy(&tmp, &tmpout);
     584      if (s->loop && s->perfectloop) {
     585        uint_t remaining = s->blocksize - available;
     586        tmpout.data = output->data + available; tmpout.length = remaining;
     587        tmp.data = s->table->data; tmp.length = remaining;
     588        fvec_copy(&tmp, &tmpout);
     589        s->table_index = remaining;
     590        *read = s->blocksize;
     591      } else {
     592        s->table_index = 0;
     593        *read = available;
     594      }
     595      aubio_sampler_do_eof(s);
     596    } else {
     597      tmp.length = s->blocksize;
     598      fvec_copy(&tmp, output);
     599      s->table_index += output->length;
     600      *read = s->blocksize;
     601    }
     602  }
     603}
     604
     605uint_t
     606aubio_sampler_set_table(aubio_sampler_t *s, fvec_t *samples) {
     607  if (!samples || !s) return AUBIO_FAIL;
     608  if (s->reading_from == aubio_sampler_reading_from_source) {
     609    //aubio_sampler_close_reading_thread(s);
     610  }
     611  s->table = samples;
     612  //AUBIO_INF("sampler: setting table (%d long)\n", s->table->length);
     613  s->table_index = 0;
     614  s->reading_from = aubio_sampler_reading_from_table;
     615  //s->threaded_read = 0;
     616  s->opened = 1;
     617  s->finished = 1;
     618  return AUBIO_OK;
    555619}
    556620
     
    620684  if (o->source) {
    621685    ret = aubio_source_seek(o->source, pos);
     686  } else {
     687    o->table_index = pos;
    622688  }
    623689  return ret;
     
    633699    o->playing = 0;
    634700  } else {
    635     aubio_sampler_seek(o, 0);
     701    if (o->reading_from == aubio_sampler_reading_from_source)
     702      aubio_sampler_seek(o, 0);
    636703    //o->finished = 0;
    637704  }
  • src/synth/sampler.h

    ra006c5f r2ca4b59  
    8383uint_t aubio_sampler_queue(aubio_sampler_t * o, const char_t * uri );
    8484
     85/** set array to read from
     86
     87  \param o sampler, created by new_aubio_sampler()
     88  \param samples the vector to set the table to
     89
     90  \return 0 if successfully set, non-zero otherwise
     91
     92*/
     93uint_t aubio_sampler_set_table(aubio_sampler_t *o, fvec_t *samples);
     94
    8595/** process sampler function
    8696
Note: See TracChangeset for help on using the changeset viewer.