Skip to content

Commit 4599bfa

Browse files
committed
Maximilian use Vector instead of array
1 parent 2f35a96 commit 4599bfa

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/AudioLibs/MaximilianDSP.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
#include "AudioConfig.h"
33
#include "maximilian.h"
44
#include "libs/maxiClock.h"
5+
#ifdef ESP32
6+
#include "esp_heap_caps.h"
7+
#endif
58

69
// Maximilian play function - return an array of 2 channels
710
void play(maxi_float_t *channels);//run dac!
@@ -19,18 +22,17 @@ class Maximilian : public VolumeSupport {
1922

2023
Maximilian(Print &out, int bufferSize=DEFAULT_BUFFER_SIZE, void (*callback)(maxi_float_t *channels)=play){
2124
buffer_size = bufferSize;
22-
p_buffer = new uint8_t[bufferSize];
2325
p_sink = &out;
2426
this->callback = callback;
2527
}
2628

2729
~Maximilian() {
28-
delete[] p_buffer;
2930
}
3031

3132
/// Setup Maximilian with audio parameters
3233
void begin(AudioInfo cfg){
3334
this->cfg = cfg;
35+
buffer.resize(buffer_size);
3436
maxiSettings::setup(cfg.sample_rate, cfg.channels, DEFAULT_BUFFER_SIZE);
3537
}
3638

@@ -53,7 +55,7 @@ class Maximilian : public VolumeSupport {
5355
// fill buffer with data
5456
maxi_float_t out[cfg.channels];
5557
uint16_t samples = buffer_size / sizeof(uint16_t);
56-
int16_t *p_samples = (int16_t *)p_buffer;
58+
int16_t *p_samples = (int16_t *) buffer.data();
5759
for (uint16_t j=0;j<samples;j+=cfg.channels){
5860
callback(out);
5961
// convert all channels to int16
@@ -62,12 +64,12 @@ class Maximilian : public VolumeSupport {
6264
}
6365
}
6466
// write buffer to audio sink
65-
unsigned int result = p_sink->write(p_buffer, buffer_size);
67+
unsigned int result = p_sink->write(buffer.data(), buffer_size);
6668
LOGI("bytes written %u", result)
6769
}
6870

6971
protected:
70-
uint8_t *p_buffer=nullptr;
72+
Vector<uint8_t> buffer;
7173
int buffer_size=256;
7274
Print *p_sink=nullptr;
7375
AudioInfo cfg;

0 commit comments

Comments
 (0)