Changeset f253b03 for src/synth/sampler.c
- Timestamp:
- Oct 9, 2016, 8:04:35 PM (8 years ago)
- Branches:
- sampler
- Children:
- a006c5f
- Parents:
- 128589e
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/synth/sampler.c
r128589e rf253b03 65 65 aubio_ringbuffer_t *ring; 66 66 uint_t perfectloop; 67 uint_t eof_remaining; 67 68 fvec_t *samples; 68 69 fmat_t *msamples; … … 151 152 //s->source_blocksize = 8192; 152 153 154 if (s->threaded_read || s->perfectloop) 155 s->source_output = new_fvec(s->source_blocksize); 153 156 if (s->perfectloop || s->source_blocksize != s->blocksize) { 154 s->source_output = new_fvec(s->source_blocksize); 155 s->ring = new_aubio_ringbuffer(s->source_blocksize, s->blocksize); 157 s->ring = new_aubio_ringbuffer(s->source_blocksize * 2, s->blocksize); 156 158 } 157 159 //s->channels = 1; … … 236 238 o->finished = 0; 237 239 o->eof = 0; 240 o->eof_remaining = 0; 238 241 o->opened = 1; 239 242 ret = AUBIO_OK; … … 250 253 o->finished = 1; 251 254 o->eof = 0; 255 o->eof_remaining = 0; 252 256 o->opened = 0; 253 257 AUBIO_WRN("sampler: failed loading %s\n", uri); 254 258 } 255 259 if (o->ring) { 256 AUBIO_WRN("sampler: resetting ringbuffer\n");260 //AUBIO_WRN("sampler: resetting ringbuffer\n"); 257 261 aubio_ringbuffer_reset(o->ring); 258 262 } … … 369 373 pthread_exit(NULL); 370 374 } 371 372 void *aubio_sampler_readfn_ring(void *z) {373 aubio_sampler_t *p = z;374 while(1) {375 pthread_mutex_lock(&p->read_mutex);376 if (p->open_thread_running) {377 //AUBIO_WRN("sampler: readfn(): file is being opened\n");378 pthread_cond_signal(&p->read_avail);379 //pthread_cond_wait(&p->read_request, &p->read_mutex);380 } else if (p->opened && !p->started && !p->finished) {381 //AUBIO_WRN("sampler: readfn(): file started\n");382 p->available = aubio_sampler_pull_from_source(p);383 if (p->available < (sint_t)p->source_blocksize)384 aubio_sampler_do_eof(p);385 pthread_cond_signal(&p->read_avail);386 if (!p->finished) {387 pthread_cond_wait(&p->read_request, &p->read_mutex);388 }389 } else {390 //AUBIO_WRN("sampler: readfn(): idle?\n");391 //pthread_cond_signal(&p->read_avail);392 pthread_cond_wait(&p->read_request, &p->read_mutex);393 if (p->read_thread_finish) {394 goto done;395 }396 }397 pthread_mutex_unlock(&p->read_mutex);398 }399 done:400 //AUBIO_WRN("sampler: exiting reading thread\n");401 pthread_mutex_unlock(&p->read_mutex);402 pthread_exit(NULL);403 }404 375 #endif 405 376 … … 412 383 } 413 384 } 414 415 static void aubio_sampler_do_perfectloop(aubio_sampler_t *s);416 385 417 386 static void … … 438 407 if (ring_avail < (sint_t)s->blocksize) { 439 408 available = aubio_sampler_pull_from_source(s); 440 #if 0441 //AUBIO_MSG("sampler: got %d / %d fetching from source\n", s->available,442 // s->source_blocksize);443 if (s->available == 0) {444 //aubio_sampler_do_eof(s);445 //aubio_sampler_do_perfectloop(s, output);446 }447 if (s->available < s->source_blocksize) {448 AUBIO_ERR("sampler: short read from source"449 " s->available %d, ring_avail %d \n", s->available, ring_avail);450 //s->eof = 0;451 //abort();452 }453 #endif454 409 if (available > 0) { 455 410 aubio_ringbuffer_push(s->ring, s->source_output, available); 456 } else { 457 //if (s->playing && !s->finished) 458 //AUBIO_WRN("sampler: not reading anymore should do eof now %d\n", check_wrote); 459 // TODO: move eof fetch now 411 } 412 if (available < s->source_blocksize) { 413 if (ring_avail + available <= s->blocksize) { 414 s->eof_remaining = available + ring_avail; 415 if (s->eof_remaining == 0) s->eof_remaining = s->blocksize; 416 //AUBIO_ERR("sampler: marking special eof got: %d, in ring: %d, %d, eof remaining %d\n", 417 // available, ring_avail, s->blocksize, s->eof_remaining); 418 if (s->loop) { 419 aubio_sampler_seek(s,0); 420 // read some frames from beginning of source for perfect looping 421 if (s->perfectloop) { 422 available = aubio_sampler_pull_from_source(s); 423 if (available <= 0) { 424 AUBIO_ERR("sampler: perfectloop but s->available = 0 !\n"); 425 } else { 426 aubio_ringbuffer_push(s->ring, s->source_output, available); 427 } 428 } 429 } 430 } 460 431 } 461 432 } 462 433 return available; 463 434 } 464 465 uint_t466 aubio_sampler_write_remaining_ring(aubio_sampler_t *s, fvec_t *output, uint_t wrote);467 435 468 436 static void … … 477 445 check_wrote += s->blocksize; 478 446 *read = s->blocksize; 447 if (s->eof_remaining > 0) { 448 if (s->eof_remaining <= s->blocksize) { 449 s->eof = 1; 450 s->eof_remaining = 0; 451 } else if (s->eof_remaining <= s->source_blocksize) { 452 s->eof_remaining -= s->blocksize; 453 } 454 } 479 455 } else { 480 //AUBIO_MSG("sampler: last frame, pulling remaining %d left\n", ring_avail);456 AUBIO_MSG("sampler: last frame, pulling remaining %d left\n", ring_avail); 481 457 *read = 0; 482 458 if (ring_avail > 0) { … … 486 462 *read += ring_avail; 487 463 } 488 // signal eof , seek to 0 if looping464 // signal eof 489 465 aubio_sampler_do_eof(s); 490 // read new frames from source early if needed 491 aubio_sampler_do_perfectloop(s); 492 // write the remaining frames 493 *read += aubio_sampler_write_remaining_ring(s, output, ring_avail); 466 // finished playing, reset ringbuffer for next read 467 if (!s->playing) 468 aubio_ringbuffer_reset(s->ring); 494 469 } 495 470 } … … 571 546 } 572 547 573 uint_t574 aubio_sampler_write_remaining_ring(aubio_sampler_t *s, fvec_t *output, uint_t wrote){575 if (s->perfectloop && s->loop) {576 fvec_t tmpout;577 tmpout.data = output->data + wrote;578 tmpout.length = s->blocksize - wrote;579 aubio_ringbuffer_pull(s->ring, &tmpout, tmpout.length);580 check_wrote += tmpout.length;581 return tmpout.length;582 }583 return 0;584 }585 586 void587 aubio_sampler_do_perfectloop(aubio_sampler_t *s) {588 // perfectloop fetched new samples from start of source to ringbuffer589 if (s->perfectloop && s->loop) {590 s->available = aubio_sampler_pull_from_source(s);591 if (s->available <= 0) {592 AUBIO_ERR("sampler: perfectloop but s->available = 0 !\n");593 } else {594 aubio_ringbuffer_push(s->ring, s->source_output, s->available);595 }596 }597 }598 599 548 void 600 549 aubio_sampler_read_from_table(aubio_sampler_t *o, fvec_t *output, uint_t *read) { … … 778 727 #endif 779 728 //if (o->source_output) { 780 if (o-> perfectloop || o->ring) {729 if (o->source_output && (o->threaded_read || o->perfectloop)) { 781 730 del_fvec(o->source_output); 782 731 }
Note: See TracChangeset
for help on using the changeset viewer.