Skip to content

Commit a217b1a

Browse files
committed
OutputMixer: availableSamples()
1 parent f6acdb0 commit a217b1a

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

src/AudioTools/AudioOutput.h

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -420,14 +420,8 @@ class OutputMixer : public Print {
420420
bool result = false;
421421

422422
// determine ringbuffer with mininum available data
423-
size_t samples = 0;
424-
for (int j = 0; j < output_count; j++) {
425-
int available_samples = buffers[j]->available();
426-
if (available_samples > 0){
427-
samples = MIN(size_bytes / sizeof(T), (size_t)available_samples);
428-
}
429-
}
430-
423+
size_t samples = availableSamples();
424+
// sum up samples
431425
if (samples > 0) {
432426
result = true;
433427
// mix data from ringbuffers to output
@@ -449,6 +443,17 @@ class OutputMixer : public Print {
449443
return;
450444
}
451445

446+
int availableSamples() {
447+
size_t samples = 0;
448+
for (int j = 0; j < output_count; j++) {
449+
int available_samples = buffers[j]->available();
450+
if (available_samples > 0){
451+
samples = MIN(size_bytes / sizeof(T), (size_t)available_samples);
452+
}
453+
}
454+
return samples;
455+
}
456+
452457
/// Resizes the buffer to the indicated number of bytes
453458
void resize(int size) {
454459
if (size != size_bytes) {
@@ -493,8 +498,8 @@ class OutputMixer : public Print {
493498
float total_weights = 0.0;
494499
bool is_active = false;
495500
int stream_idx = 0;
496-
int size_bytes;
497-
int output_count;
501+
int size_bytes = 0;
502+
int output_count = 0;
498503
MemoryType memory_type;
499504
void *p_memory = nullptr;
500505
bool is_auto_index = true;

0 commit comments

Comments
 (0)