Changeset b21c751
- Timestamp:
- Sep 30, 2016, 11:33:16 AM (8 years ago)
- Branches:
- sampler
- Children:
- 61abfa4
- Parents:
- 0202028
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/effects/timestretch_rubberband.c
r0202028 rb21c751 65 65 pthread_cond_t read_request; 66 66 sint_t available; 67 uint_t started; 68 uint_t finish; 67 69 #endif 68 70 }; … … 113 115 114 116 #ifdef HAVE_THREADS 117 p->started = 0; 118 p->finish = 0; 115 119 pthread_mutex_init(&p->read_mutex, 0); 116 120 pthread_cond_init (&p->read_avail, 0); 117 121 pthread_cond_init (&p->read_request, 0); 122 //AUBIO_WRN("timestretch: creating thread\n"); 118 123 pthread_create(&p->read_thread, 0, aubio_timestretch_readfn, p); 119 124 //AUBIO_DBG("timestretch: new_ waiting for warmup, got %d available\n", p->available); … … 138 143 { 139 144 aubio_timestretch_t *p = z; 140 // signal main-thread when we are done141 //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");149 145 while(1) { //p->available < (int)p->hopsize && p->eof != 1) { 150 146 //AUBIO_WRN("timestretch: locking in readfn\n"); 151 147 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); 158 167 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); 165 170 } 166 171 //AUBIO_WRN("timestretch: unlocking in readfn\n"); 167 172 pthread_mutex_unlock(&p->read_mutex); 168 173 } 169 #if 1170 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 #endif175 174 //AUBIO_WRN("timestretch: exiting readfn\n"); 176 175 pthread_exit(NULL); … … 194 193 { 195 194 #ifdef HAVE_THREADS 195 void *threadfn; 196 //AUBIO_WRN("timestretch: entering delete\n"); 196 197 pthread_mutex_lock(&p->read_mutex); 198 p->finish = 1; 197 199 pthread_cond_signal(&p->read_request); 198 200 //pthread_cond_wait(&p->read_avail, &p->read_mutex); 199 201 pthread_mutex_unlock(&p->read_mutex); 200 #if 1201 void *threadfn;202 202 if ((p->eof == 0) && (pthread_cancel(p->read_thread))) { 203 203 AUBIO_WRN("timestretch: cancelling thread failed\n"); … … 206 206 AUBIO_WRN("timestretch: joining thread failed\n"); 207 207 } 208 #endif209 208 pthread_mutex_destroy(&p->read_mutex); 210 209 pthread_cond_destroy(&p->read_avail); … … 340 339 uint_t err = AUBIO_OK; 341 340 #if HAVE_THREADS 342 AUBIO_WRN("timestretch: seek_ waiting for warmup, got %d available\n", p->available);343 341 pthread_mutex_lock(&p->read_mutex); 344 342 #endif … … 348 346 #if HAVE_THREADS 349 347 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; 359 349 pthread_mutex_unlock(&p->read_mutex); 360 //AUBIO_WRN("timestretch: seek_ warm up success, got %d available\n", p->available);361 350 #endif 362 351 return err;
Note: See TracChangeset
for help on using the changeset viewer.