Changeset bdb249b


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:
4559863
Parents:
8856791
git-author:
Paul Brossier <piem@piem.org> (09/30/16 11:33:16)
git-committer:
Paul Brossier <piem@piem.org> (12/07/18 01:28:55)
Message:

src/effects/timestretch_rubberband.c: do not reopen thread in _seek, add flags to mark warmed-up and finished states

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/effects/timestretch_rubberband.c

    r8856791 rbdb249b  
    6565  pthread_cond_t read_request;
    6666  sint_t available;
     67  uint_t started;
     68  uint_t finish;
    6769#endif
    6870};
     
    113115
    114116#ifdef HAVE_THREADS
     117  p->started = 0;
     118  p->finish = 0;
    115119  pthread_mutex_init(&p->read_mutex, 0);
    116120  pthread_cond_init (&p->read_avail, 0);
    117121  pthread_cond_init (&p->read_request, 0);
     122  //AUBIO_WRN("timestretch: creating thread\n");
    118123  pthread_create(&p->read_thread, 0, aubio_timestretch_readfn, p);
    119124  //AUBIO_DBG("timestretch: new_ waiting for warmup, got %d available\n", p->available);
     
    138143{
    139144  aubio_timestretch_t *p = z;
    140   // signal main-thread when we are done
    141   //AUBIO_WRN("timestretch: read_thread locking, got %d available\n", p->available);
    142   pthread_mutex_lock(&p->read_mutex);
    143   aubio_timestretch_warmup(p);
    144   //AUBIO_WRN("timestretch: signaling warmup\n");
    145   pthread_cond_signal(&p->read_avail);
    146   //AUBIO_WRN("timestretch: unlocking in readfn\n");
    147   pthread_mutex_unlock(&p->read_mutex);
    148   AUBIO_WRN("timestretch: entering readfn loop\n");
    149145  while(1) { //p->available < (int)p->hopsize && p->eof != 1) {
    150146    //AUBIO_WRN("timestretch: locking in readfn\n");
    151147    pthread_mutex_lock(&p->read_mutex);
    152     p->available = aubio_timestretch_fetch(p, p->hopsize);
    153     //AUBIO_WRN("timestretch: read_thread read %d\n", p->available);
    154     // signal main-thread when we are done
    155     //AUBIO_WRN("timestretch: signaling new read\n");
    156     pthread_cond_signal(&p->read_avail);
    157     if (p->eof != 1) {
     148    if (!p->started && !p->eof) {
     149      // fetch the first few samples and mark as started
     150      //AUBIO_WRN("timestretch: fetching first samples\n");
     151      aubio_timestretch_warmup(p);
     152      p->started = 1;
     153    } else if (!p->eof) {
     154      // fetch at least p->hopsize stretched samples
     155      p->available = aubio_timestretch_fetch(p, p->hopsize);
     156      // signal available frames
     157      pthread_cond_signal(&p->read_avail);
     158      if (p->eof != 1) {
     159        // the end of file was not reached yet, wait for the next read_request
     160        pthread_cond_wait(&p->read_request, &p->read_mutex);
     161      } else {
     162        // eof was reached, do not wait for a read request and mark as stopped
     163        p->started = 0;
     164      }
     165    } else {
     166      //pthread_cond_signal(&p->read_avail);
    158167      pthread_cond_wait(&p->read_request, &p->read_mutex);
    159     }
    160     if (p->eof == 1) {
    161       AUBIO_WRN("timestretch: read_thread eof reached %d, %d/%d\n", p->available,
    162         p->hopsize, p->source_hopsize);
    163       pthread_mutex_unlock(&p->read_mutex);
    164       break;
     168      //AUBIO_WRN("timestretch: finished idle in readfn\n");
     169      if (p->finish) pthread_exit(NULL);
    165170    }
    166171    //AUBIO_WRN("timestretch: unlocking in readfn\n");
    167172    pthread_mutex_unlock(&p->read_mutex);
    168173  }
    169 #if 1
    170   pthread_mutex_lock(&p->read_mutex);
    171   //AUBIO_WRN("timestretch: signaling end\n");
    172   pthread_cond_signal(&p->read_avail);
    173   pthread_mutex_unlock(&p->read_mutex);
    174 #endif
    175174  //AUBIO_WRN("timestretch: exiting readfn\n");
    176175  pthread_exit(NULL);
     
    194193{
    195194#ifdef HAVE_THREADS
     195  void *threadfn;
     196  //AUBIO_WRN("timestretch: entering delete\n");
    196197  pthread_mutex_lock(&p->read_mutex);
     198  p->finish = 1;
    197199  pthread_cond_signal(&p->read_request);
    198200  //pthread_cond_wait(&p->read_avail, &p->read_mutex);
    199201  pthread_mutex_unlock(&p->read_mutex);
    200 #if 1
    201   void *threadfn;
    202202  if ((p->eof == 0) && (pthread_cancel(p->read_thread))) {
    203203      AUBIO_WRN("timestretch: cancelling thread failed\n");
     
    206206      AUBIO_WRN("timestretch: joining thread failed\n");
    207207  }
    208 #endif
    209208  pthread_mutex_destroy(&p->read_mutex);
    210209  pthread_cond_destroy(&p->read_avail);
     
    340339  uint_t err = AUBIO_OK;
    341340#if HAVE_THREADS
    342   AUBIO_WRN("timestretch: seek_ waiting for warmup, got %d available\n", p->available);
    343341  pthread_mutex_lock(&p->read_mutex);
    344342#endif
     
    348346#if HAVE_THREADS
    349347  p->available = 0;
    350   void *threadfn;
    351   if ((p->eof == 0) && (pthread_cancel(p->read_thread) == 0)) {
    352       AUBIO_WRN("timestretch: cancelling thread failed\n");
    353   }
    354   if (pthread_join(p->read_thread, &threadfn)) {
    355       AUBIO_WRN("timestretch: joining thread failed\n");
    356   }
    357   pthread_create(&p->read_thread, 0, aubio_timestretch_readfn, p);
    358   pthread_cond_wait(&p->read_avail, &p->read_mutex);
     348  p->started = 1;
    359349  pthread_mutex_unlock(&p->read_mutex);
    360   //AUBIO_WRN("timestretch: seek_ warm up success, got %d available\n", p->available);
    361350#endif
    362351  return err;
Note: See TracChangeset for help on using the changeset viewer.