Changeset 992ac88


Ignore:
Timestamp:
Dec 7, 2018, 1:28:55 AM (6 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/cnn, feature/crepe, feature/timestretch, fix/ffmpeg5, master
Children:
9bd769a
Parents:
a874c48
git-author:
Paul Brossier <piem@piem.org> (09/29/16 16:31:10)
git-committer:
Paul Brossier <piem@piem.org> (12/07/18 01:28:55)
Message:

src/effects/timestretch_rubberband.c: factorise into aubio_timestretch_fetch

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/effects/timestretch_rubberband.c

    ra874c48 r992ac88  
    4343
    4444  aubio_source_t *source;
     45  uint_t source_hopsize;          /**< hop size at which the source is read */
    4546  fvec_t *in;
    4647  uint_t eof;
     
    5354
    5455static void aubio_timestretch_warmup (aubio_timestretch_t * p);
    55 static sint_t aubio_timestretch_fetch(aubio_timestretch_t *p);
     56static sint_t aubio_timestretch_fetch(aubio_timestretch_t *p, uint_t fetch);
    5657
    5758aubio_timestretch_t *
     
    6263  p->samplerate = samplerate;
    6364  p->hopsize = hopsize;
     65  p->source_hopsize = hopsize;
    6466  p->pitchscale = 1.;
    6567  p->eof = 0;
    6668
    67   p->source = new_aubio_source(uri, samplerate, hopsize);
     69  p->source = new_aubio_source(uri, samplerate, p->source_hopsize);
    6870  if (!p->source) goto beach;
    6971  if (samplerate == 0 ) p->samplerate = aubio_source_get_samplerate(p->source);
    7072
    71   p->in = new_fvec(hopsize);
     73  p->in = new_fvec(p->source_hopsize);
    7274
    7375  if (stretchratio <= MAX_STRETCH_RATIO && stretchratio >= MIN_STRETCH_RATIO) {
     
    8688
    8789  p->rb = rubberband_new(p->samplerate, 1, p->rboptions, p->stretchratio, p->pitchscale);
    88   rubberband_set_max_process_size(p->rb, p->hopsize);
     90  rubberband_set_max_process_size(p->rb, p->source_hopsize);
    8991  //rubberband_set_debug_level(p->rb, 10);
    9092
     
    102104{
    103105  // warm up rubber band
    104   uint_t source_read = 0;
    105106  unsigned int latency = MAX(p->hopsize, rubberband_get_latency(p->rb));
    106   int available = rubberband_available(p->rb);
    107   while (available <= (int)latency) {
    108     aubio_source_do(p->source, p->in, &source_read);
    109     // for very short samples
    110     if (source_read < p->hopsize) p->eof = 1;
    111     rubberband_process(p->rb, (const float* const*)&(p->in->data), p->hopsize, p->eof);
    112     available = rubberband_available(p->rb);
    113   }
     107  aubio_timestretch_fetch(p, latency);
    114108}
    115109
     
    192186
    193187sint_t
    194 aubio_timestretch_fetch(aubio_timestretch_t *p)
    195 {
    196   uint_t source_read = p->hopsize;
     188aubio_timestretch_fetch(aubio_timestretch_t *p, uint_t length)
     189{
     190  uint_t source_read = p->source_hopsize;
    197191  // read more samples from source until we have enough available or eof is reached
    198192  int available = rubberband_available(p->rb);
    199   while ((available < (int)p->hopsize) && (p->eof == 0)) {
     193  while ((available < (int)length) && (p->eof == 0)) {
    200194    aubio_source_do(p->source, p->in, &source_read);
    201     if (source_read < p->hopsize) {
     195    if (source_read < p->source_hopsize) {
    202196      p->eof = 1;
    203197    }
     
    205199    available = rubberband_available(p->rb);
    206200  }
    207   return source_read;
     201  return available;
    208202}
    209203
     
    211205aubio_timestretch_do (aubio_timestretch_t * p, fvec_t * out, uint_t * read)
    212206{
    213   int available = aubio_timestretch_fetch(p);
     207  int available = aubio_timestretch_fetch(p, p->hopsize);
    214208  // now retrieve the samples and write them into out->data
    215209  if (available >= (int)p->hopsize) {
Note: See TracChangeset for help on using the changeset viewer.