Commit 0a415271 authored by Stefan Seyfried's avatar Stefan Seyfried

AudioBuffer: manage initialization on its own

if InBuff is initialized should be a property of the AudioBuffer, the
calling code should not keep track of that.
parent 8d62cd85
...@@ -57,6 +57,7 @@ size_t AudioBuffer::init() { ...@@ -57,6 +57,7 @@ size_t AudioBuffer::init() {
} }
if(!m_buffer) if(!m_buffer)
return 0; return 0;
m_f_init = true;
resetBuffer(); resetBuffer();
return m_buffSize; return m_buffSize;
} }
...@@ -205,17 +206,15 @@ Audio::Audio(bool internalDAC /* = false */, i2s_dac_mode_t channelEnabled /* = ...@@ -205,17 +206,15 @@ Audio::Audio(bool internalDAC /* = false */, i2s_dac_mode_t channelEnabled /* =
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void Audio::initInBuff() { void Audio::initInBuff() {
if(!m_f_initInbuffOnce) { if(!InBuff.isInitialized()) {
size_t size = InBuff.init(); size_t size = InBuff.init();
if(size == m_buffSizeRAM - m_resBuffSizeRAM) { if(size == m_buffSizeRAM - m_resBuffSizeRAM) {
AUDIO_INFO(sprintf(chbuf, "PSRAM not found, inputBufferSize: %u bytes", size - 1);) AUDIO_INFO(sprintf(chbuf, "PSRAM not found, inputBufferSize: %u bytes", size - 1);)
m_f_psram = false; m_f_psram = false;
m_f_initInbuffOnce = true;
} }
if(size == m_buffSizePSRAM - m_resBuffSizePSRAM) { if(size == m_buffSizePSRAM - m_resBuffSizePSRAM) {
AUDIO_INFO(sprintf(chbuf, "PSRAM found, inputBufferSize: %u bytes", size - 1);) AUDIO_INFO(sprintf(chbuf, "PSRAM found, inputBufferSize: %u bytes", size - 1);)
m_f_psram = true; m_f_psram = true;
m_f_initInbuffOnce = true;
} }
} }
changeMaxBlockSize(1600); // default size mp3 or aac changeMaxBlockSize(1600); // default size mp3 or aac
...@@ -258,7 +257,6 @@ esp_err_t Audio::i2s_mclk_pin_select(const uint8_t pin) { ...@@ -258,7 +257,6 @@ esp_err_t Audio::i2s_mclk_pin_select(const uint8_t pin) {
Audio::~Audio() { Audio::~Audio() {
//I2Sstop(m_i2s_num); //I2Sstop(m_i2s_num);
//InBuff.~AudioBuffer(); #215 the AudioBuffer is automatically destroyed by the destructor //InBuff.~AudioBuffer(); #215 the AudioBuffer is automatically destroyed by the destructor
m_f_initInbuffOnce = false;
setDefaults(); setDefaults();
if(m_playlistBuff) {free(m_playlistBuff); m_playlistBuff = NULL;} if(m_playlistBuff) {free(m_playlistBuff); m_playlistBuff = NULL;}
i2s_driver_uninstall((i2s_port_t)m_i2s_num); // #215 free I2S buffer i2s_driver_uninstall((i2s_port_t)m_i2s_num); // #215 free I2S buffer
......
...@@ -113,6 +113,7 @@ public: ...@@ -113,6 +113,7 @@ public:
AudioBuffer(size_t maxBlockSize = 0); // constructor AudioBuffer(size_t maxBlockSize = 0); // constructor
~AudioBuffer(); // frees the buffer ~AudioBuffer(); // frees the buffer
size_t init(); // set default values size_t init(); // set default values
bool isInitialized() { return m_f_init; };
void changeMaxBlockSize(uint16_t mbs); // is default 1600 for mp3 and aac, set 16384 for FLAC void changeMaxBlockSize(uint16_t mbs); // is default 1600 for mp3 and aac, set 16384 for FLAC
uint16_t getMaxBlockSize(); // returns maxBlockSize uint16_t getMaxBlockSize(); // returns maxBlockSize
size_t freeSpace(); // number of free bytes to overwrite size_t freeSpace(); // number of free bytes to overwrite
...@@ -141,6 +142,7 @@ protected: ...@@ -141,6 +142,7 @@ protected:
uint8_t* m_readPtr = NULL; uint8_t* m_readPtr = NULL;
uint8_t* m_endPtr = NULL; uint8_t* m_endPtr = NULL;
bool m_f_start = true; bool m_f_start = true;
bool m_f_init = false;
}; };
//---------------------------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------------------------
...@@ -460,7 +462,6 @@ private: ...@@ -460,7 +462,6 @@ private:
bool m_f_m3u8data = false; // used in processM3U8entries bool m_f_m3u8data = false; // used in processM3U8entries
bool m_f_Log = true; // if m3u8: log is cancelled bool m_f_Log = true; // if m3u8: log is cancelled
bool m_f_continue = false; // next m3u8 chunk is available bool m_f_continue = false; // next m3u8 chunk is available
bool m_f_initInbuffOnce = false; // init InBuff only once
i2s_dac_mode_t m_f_channelEnabled = I2S_DAC_CHANNEL_LEFT_EN; // internal DAC on GPIO26 for M5StickC/Plus i2s_dac_mode_t m_f_channelEnabled = I2S_DAC_CHANNEL_LEFT_EN; // internal DAC on GPIO26 for M5StickC/Plus
uint32_t m_audioFileDuration = 0; uint32_t m_audioFileDuration = 0;
float m_audioCurrentTime = 0; float m_audioCurrentTime = 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment