Changeset 30efdd0


Ignore:
Timestamp:
Sep 29, 2016, 4:31:10 PM (8 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
sampler, timestretch
Children:
4acee97
Parents:
1e4b7f6
Message:

src/effects/timestretch_rubberband.c: factorise into aubio_timestretch_fetch

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/effects/timestretch_rubberband.c

    r1e4b7f6 r30efdd0  
    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.