Skip to content

Commit 81aed7b

Browse files
committed
corr, getInBufferSize(), setInBufferSize()
1 parent 3626787 commit 81aed7b

File tree

2 files changed

+31
-19
lines changed

2 files changed

+31
-19
lines changed

src/Audio.cpp

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,17 +102,20 @@ AudioBuffer::~AudioBuffer() {
102102

103103
int32_t AudioBuffer::getBufsize() { return m_buffSize; }
104104

105-
void AudioBuffer::setBufsize(size_t mbs) {
106-
if(mbs < 2 * m_resBuffSize) AUDIO_ERROR("not allowed buffer size must be greater than %i", 2 * m_resBuffSize);
105+
bool AudioBuffer::setBufsize(size_t mbs) {
106+
if(mbs < 2 * m_resBuffSize) {
107+
AUDIO_ERROR("not allowed buffer size must be greater than %i", 2 * m_resBuffSize);
108+
return false;
109+
}
107110
m_buffSize = mbs;
108-
return;
111+
if(!init()) return false;
112+
return true;
109113
}
110114

111115
size_t AudioBuffer::init() {
112116
if(m_buffer) free(m_buffer);
113117
m_buffer = NULL;
114-
m_buffer = (uint8_t*)ps_calloc(m_buffSize, sizeof(uint8_t));
115-
m_buffSize = m_buffSize - m_resBuffSize;
118+
m_buffer = (uint8_t*)ps_malloc(m_buffSize + m_resBuffSize);
116119

117120
if(!m_buffer) return 0;
118121
m_f_init = true;
@@ -288,7 +291,7 @@ void Audio::initInBuff() {
288291
AUDIO_INFO("inputBufferSize: %u bytes", size - 1);
289292
}
290293
}
291-
changeMaxBlockSize(1600); // default size mp3 or aac
294+
InBuff.changeMaxBlockSize(1600); // default size mp3 or aac
292295
}
293296

294297
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
@@ -5262,11 +5265,20 @@ uint32_t Audio::inBufferFree() {
52625265
return InBuff.freeSpace();
52635266
}
52645267
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
5265-
uint32_t Audio::inBufferSize() {
5268+
uint32_t Audio::getInBufferSize() {
52665269
// current audio input buffer size in bytes
52675270
return InBuff.getBufsize();
52685271
}
52695272
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
5273+
bool Audio::setInBufferSize(size_t mbs){
5274+
size_t oldBuffSize = InBuff.getBufsize();
5275+
stopSong();
5276+
bool res = InBuff.setBufsize(mbs);
5277+
if(res == false) InBuff.setBufsize(oldBuffSize);
5278+
InBuff.init();
5279+
return res;
5280+
}
5281+
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
52705282
// *** D i g i t a l b i q u a d r a t i c f i l t e r ***
52715283
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
52725284
void Audio::IIR_calculateCoefficients(int8_t G0, int8_t G1, int8_t G2) { // Infinite Impulse Response (IIR) filters

src/Audio.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class AudioBuffer {
8484
size_t init(); // set default values
8585
bool isInitialized() { return m_f_init; };
8686
int32_t getBufsize();
87-
void setBufsize(size_t mbs); // default is m_buffSizePSRAM for psram, and m_buffSizeRAM without psram
87+
bool setBufsize(size_t mbs); // default is m_buffSizePSRAM for psram, and m_buffSizeRAM without psram
8888
void changeMaxBlockSize(uint16_t mbs); // is default 1600 for mp3 and aac, set 16384 for FLAC
8989
uint16_t getMaxBlockSize(); // returns maxBlockSize
9090
size_t freeSpace(); // number of free bytes to overwrite
@@ -120,7 +120,7 @@ static StaticTask_t __attribute__((unused)) xAudioTaskBuffer;
120120
static StackType_t __attribute__((unused)) xAudioStack[AUDIO_STACK_SIZE];
121121
extern char audioI2SVers[];
122122

123-
class Audio : private AudioBuffer{
123+
class Audio{
124124

125125
AudioBuffer InBuff; // instance of input buffer
126126

@@ -399,17 +399,17 @@ class Audio : private AudioBuffer{
399399
uint32_t getTotalPlayingTime();
400400
uint16_t getVUlevel();
401401

402-
uint32_t inBufferFilled(); // returns the number of stored bytes in the inputbuffer
403-
uint32_t inBufferFree(); // returns the number of free bytes in the inputbuffer
404-
uint32_t inBufferSize(); // returns the size of the inputbuffer in bytes
405-
void setBufsize(size_t mbs); // sets the size of the inputbuffer in bytes
406-
void setTone(int8_t gainLowPass, int8_t gainBandPass, int8_t gainHighPass);
407-
void setI2SCommFMT_LSB(bool commFMT);
408-
int getCodec() {return m_codec;}
409-
const char *getCodecname() {return codecname[m_codec];}
410-
const char *getVersion() {return audioI2SVers;}
402+
uint32_t inBufferFilled(); // returns the number of stored bytes in the inputbuffer
403+
uint32_t inBufferFree(); // returns the number of free bytes in the inputbuffer
404+
uint32_t getInBufferSize(); // returns the size of the inputbuffer in bytes
405+
bool setInBufferSize(size_t mbs); // sets the size of the inputbuffer in bytes
406+
void setTone(int8_t gainLowPass, int8_t gainBandPass, int8_t gainHighPass);
407+
void setI2SCommFMT_LSB(bool commFMT);
408+
int getCodec() { return m_codec; }
409+
const char* getCodecname() { return codecname[m_codec]; }
410+
const char* getVersion() { return audioI2SVers; }
411411

412-
private:
412+
private:
413413
// ------- PRIVATE MEMBERS ----------------------------------------
414414

415415
void latinToUTF8(ps_ptr<char>& buff, bool UTF8check = true);

0 commit comments

Comments
 (0)