@@ -323,7 +323,7 @@ template <typename T> class OutputMixer : public Print {
323
323
size_bytes = copy_buffer_size_bytes;
324
324
stream_idx = 0 ;
325
325
memory_type = memoryType;
326
- allocate_buffers ();
326
+ allocate_buffers (size_bytes );
327
327
return true ;
328
328
}
329
329
@@ -414,6 +414,14 @@ template <typename T> class OutputMixer : public Print {
414
414
return ;
415
415
}
416
416
417
+ // / Resizes the buffer to the indicated number of bytes
418
+ void resize (int size){
419
+ if (size != size_bytes){
420
+ allocate_buffers (size);
421
+ }
422
+ size_bytes = size;
423
+ }
424
+
417
425
protected:
418
426
Vector<RingBuffer<T> *> buffers{0 };
419
427
Vector<T> output{0 };
@@ -434,27 +442,27 @@ template <typename T> class OutputMixer : public Print {
434
442
}
435
443
}
436
444
437
- void allocate_buffers () {
445
+ void allocate_buffers (int size ) {
438
446
// allocate ringbuffers for each output
439
447
for (int j = 0 ; j < output_count; j++) {
440
448
if (buffers[j] != nullptr ) {
441
449
delete buffers[j];
442
450
}
443
451
#if defined(ESP32) && defined(ARDUINO)
444
- if (memory_type == PS_RAM && ESP.getFreePsram () >= size_bytes ) {
445
- p_memory = ps_malloc (size_bytes );
446
- LOGI (" Buffer %d allocated %d bytes in PS_RAM" , j, size_bytes );
452
+ if (memory_type == PS_RAM && ESP.getFreePsram () >= size ) {
453
+ p_memory = ps_malloc (size );
454
+ LOGI (" Buffer %d allocated %d bytes in PS_RAM" , j, size );
447
455
} else {
448
- p_memory = malloc (size_bytes );
449
- LOGI (" Buffer %d allocated %d bytes in RAM" , j, size_bytes );
456
+ p_memory = malloc (size );
457
+ LOGI (" Buffer %d allocated %d bytes in RAM" , j, size );
450
458
}
451
459
if (p_memory != nullptr ) {
452
- buffers[j] = new (p_memory) RingBuffer<T>(size_bytes / sizeof (T));
460
+ buffers[j] = new (p_memory) RingBuffer<T>(size / sizeof (T));
453
461
} else {
454
- LOGE (" Not enough memory to allocate %d bytes" , size_bytes );
462
+ LOGE (" Not enough memory to allocate %d bytes" , size );
455
463
}
456
464
#else
457
- buffers[j] = new RingBuffer<T>(size_bytes / sizeof (T));
465
+ buffers[j] = new RingBuffer<T>(size / sizeof (T));
458
466
#endif
459
467
}
460
468
}
0 commit comments