MCPcopy Create free account
hub / github.com/BatchDrake/SigDigger / write

Method write

Audio/AudioPlayback.cpp:534–580  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

532}
533
534void
535AudioPlayback::write(const SUCOMPLEX *samples, SUSCOUNT size)
536{
537 unsigned int bufferSize = this->bufferSize;
538
539 while (size > 0 && this->running && this->ready) {
540 SUSCOUNT chunk = size;
541 SUSCOUNT remaining;
542 float *start;
543
544 // No current buffer, try to allocate
545 if (this->current_buffer == nullptr) {
546 this->ptr = 0;
547 if ((this->current_buffer = this->bufferList.reserve()) == nullptr) {
548 // Somehow the playback thread is slow...
549 return;
550 }
551 }
552
553 start = this->current_buffer + this->ptr;
554
555 if (chunk > bufferSize - this->ptr)
556 chunk = bufferSize - this->ptr;
557 remaining = chunk;
558
559 while (remaining-- > 0)
560 *start++ = SU_C_REAL(*samples++);
561
562 this->ptr += chunk;
563 size -= chunk;
564
565 // Buffer full, send to playback thread.
566 if (this->ptr == bufferSize) {
567 this->current_buffer = nullptr;
568 this->bufferList.commit();
569
570 // If buffering, we wait until we have SIGDIGGER_AUDIO_BUFFER_MIN
571 // buffers full. When that happens, we restart the thread.
572 if (this->buffering) {
573 if (++this->completed == SIGDIGGER_AUDIO_BUFFER_MIN) {
574 emit restart();
575 this->buffering = false;
576 }
577 }
578 }
579 }
580}
581
582void
583AudioPlayback::onReady(void)

Callers 1

playMethod · 0.45

Calls 2

reserveMethod · 0.80
commitMethod · 0.80

Tested by

no test coverage detected