Skip to content

Commit 09f1538

Browse files
committed
QueueStream: activation counting bytes
1 parent bd7f244 commit 09f1538

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/AudioTools/CoreAudio/BaseStream.h

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -321,16 +321,19 @@ class QueueStream : public BaseStream {
321321
/// Activates the output
322322
virtual bool begin() {
323323
TRACED();
324+
total_written = 0;
324325
active = true;
325326
return true;
326327
}
327328

328329
/// Activate only when filled buffer reached %
329330
virtual bool begin(size_t activeWhenPercentFilled) {
331+
total_written = 0;
330332
// determine total buffer size in bytes
331333
size_t size = callback_buffer_ptr->size() * sizeof(T);
332334
// calculate limit
333335
active_limit = size * activeWhenPercentFilled / 100;
336+
LOGI("activate after: %d bytes", active_limit);
334337
return true;
335338
}
336339

@@ -345,15 +348,19 @@ class QueueStream : public BaseStream {
345348
}
346349

347350
int availableForWrite() override {
351+
if (!active && active_limit > 0) return DEFAULT_BUFFER_SIZE;
348352
return callback_buffer_ptr->availableForWrite() * sizeof(T);
349353
}
350354

351355
virtual size_t write(const uint8_t *data, size_t len) override {
356+
if (len == 0) return 0;
352357
if (active_limit == 0 && !active) return 0;
353358

354359
// activate automaticaly when limit has been reached
355-
if (active_limit > 0 && !active && available() >= active_limit) {
360+
total_written += len;
361+
if (!active && active_limit > 0 && total_written >= active_limit) {
356362
this->active = true;
363+
LOGI("setting active");
357364
}
358365

359366
// make space by deleting oldest entries
@@ -388,9 +395,10 @@ class QueueStream : public BaseStream {
388395
protected:
389396
BaseBuffer<T> *callback_buffer_ptr;
390397
size_t active_limit = 0;
391-
bool active;
392-
bool remove_oldest_data;
393-
bool owns_buffer;
398+
size_t total_written = 0;
399+
bool active = false;
400+
bool remove_oldest_data = false;
401+
bool owns_buffer = false;
394402
};
395403

396404
#if USE_OBSOLETE

0 commit comments

Comments
 (0)