v0.9.337b
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
#include "../core/options.h"
|
||||
#include "../core/spidog.h"
|
||||
#if VS1053_CS==255
|
||||
/*
|
||||
* Audio.cpp
|
||||
@@ -26,6 +25,9 @@ fs::SDFATFS SD_SDFAT;
|
||||
#ifndef DMA_BUFLEN
|
||||
#define DMA_BUFLEN 512 // (512)
|
||||
#endif
|
||||
#if defined(ESP_ARDUINO_3)
|
||||
#include "soc/io_mux_reg.h"
|
||||
#endif
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
AudioBuffer::AudioBuffer(size_t maxBlockSize) {
|
||||
// if maxBlockSize isn't set use defaultspace (1600 bytes) is enough for aac and mp3 player
|
||||
@@ -688,7 +690,6 @@ bool Audio::connecttoFS(fs::FS &fs, const char* path, uint32_t resumeFilePos) {
|
||||
|
||||
AUDIO_INFO("Reading file: \"%s\"", audioName); vTaskDelay(2);
|
||||
if(audio_beginSDread) audio_beginSDread();
|
||||
cardLock(true);
|
||||
if(fs.exists(audioName)) {
|
||||
audiofile = fs.open(audioName); // #86
|
||||
}
|
||||
@@ -698,24 +699,19 @@ bool Audio::connecttoFS(fs::FS &fs, const char* path, uint32_t resumeFilePos) {
|
||||
audiofile = fs.open(audioName);
|
||||
}
|
||||
}
|
||||
cardLock(false);
|
||||
if(!audiofile) {
|
||||
if(audio_info) {vTaskDelay(2); audio_info("Failed to open file for reading");}
|
||||
return false;
|
||||
}
|
||||
cardLock(true);
|
||||
setDatamode(AUDIO_LOCALFILE);
|
||||
m_file_size = audiofile.size();//TEST loop
|
||||
cardLock(false);
|
||||
char* afn = NULL; // audioFileName
|
||||
cardLock(true);
|
||||
#ifdef SDFATFS_USED
|
||||
audiofile.getName(chbuf, sizeof(chbuf));
|
||||
afn = strdup(chbuf);
|
||||
#else
|
||||
afn = strdup(audiofile.name());
|
||||
#endif
|
||||
cardLock(false);
|
||||
uint8_t dotPos = lastIndexOf(afn, ".");
|
||||
for(uint8_t i = dotPos + 1; i < strlen(afn); i++){
|
||||
afn[i] = toLowerCase(afn[i]);
|
||||
@@ -751,7 +747,7 @@ cardLock(false);
|
||||
bool ret = initializeDecoder();
|
||||
if(ret) m_f_running = true;
|
||||
else {
|
||||
cardLock(true);audiofile.close();cardLock(false);
|
||||
audiofile.close();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@@ -1769,11 +1765,9 @@ int Audio::read_ID3_Header(uint8_t *data, size_t len) {
|
||||
AUDIO_INFO("Audio-Length: %u", m_audioDataSize);
|
||||
if(audio_progress) audio_progress(m_audioDataStart, m_audioDataSize);
|
||||
if(APIC_seen && audio_id3image){
|
||||
cardLock(true);
|
||||
size_t pos = audiofile.position();
|
||||
audio_id3image(audiofile, APIC_pos, APIC_size);
|
||||
audiofile.seek(pos); // the filepointer could have been changed by the user, set it back
|
||||
cardLock(false);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -2297,13 +2291,13 @@ uint32_t Audio::stopSong() {
|
||||
if(getDatamode() == AUDIO_LOCALFILE){
|
||||
m_streamType = ST_NONE;
|
||||
pos = getFilePos() - inBufferFilled();
|
||||
cardLock(true);audiofile.close();cardLock(false);
|
||||
audiofile.close();
|
||||
AUDIO_INFO("Closing audio file");
|
||||
}
|
||||
}
|
||||
if(audiofile){
|
||||
// added this before putting 'm_f_localfile = false' in stopSong(); shoulf never occur....
|
||||
cardLock(true);audiofile.close();cardLock(false);
|
||||
audiofile.close();
|
||||
AUDIO_INFO("Closing audio file");
|
||||
log_w("Closing audio file"); // for debug
|
||||
}
|
||||
@@ -2452,16 +2446,6 @@ bool Audio::playChunk() {
|
||||
}
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
void Audio::cardLock(bool lock){
|
||||
#if (TFT_CS!=255) || (SDC_CS!=255)
|
||||
if(lock){
|
||||
sdog.takeMutex();
|
||||
}else{
|
||||
sdog.giveMutex();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void Audio::loop() {
|
||||
|
||||
if(!m_f_running) return;
|
||||
@@ -2961,7 +2945,7 @@ void Audio::processLocalFile() {
|
||||
if(m_resumeFilePos){
|
||||
if(m_resumeFilePos < m_audioDataStart) m_resumeFilePos = m_audioDataStart;
|
||||
if(m_avr_bitrate) m_audioCurrentTime = ((m_resumeFilePos - m_audioDataStart) / m_avr_bitrate) * 8;
|
||||
cardLock(true);audiofile.seek(m_resumeFilePos);cardLock(false);
|
||||
audiofile.seek(m_resumeFilePos);
|
||||
InBuff.resetBuffer();
|
||||
if(m_f_Log) log_i("m_resumeFilePos %i", m_resumeFilePos);
|
||||
}
|
||||
@@ -2979,7 +2963,7 @@ void Audio::processLocalFile() {
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
|
||||
cardLock(true); bytesAddedToBuffer = audiofile.read(InBuff.getWritePtr(), bytesCanBeWritten); cardLock(false);
|
||||
bytesAddedToBuffer = audiofile.read(InBuff.getWritePtr(), bytesCanBeWritten);
|
||||
if(bytesAddedToBuffer > 0) {
|
||||
InBuff.bytesWritten(bytesAddedToBuffer);
|
||||
}
|
||||
@@ -3032,14 +3016,12 @@ void Audio::processLocalFile() {
|
||||
} //TEST loop
|
||||
f_stream = false;
|
||||
m_streamType = ST_NONE;
|
||||
cardLock(true);
|
||||
#ifdef SDFATFS_USED
|
||||
audiofile.getName(chbuf, sizeof(chbuf));
|
||||
char *afn =strdup(chbuf);
|
||||
#else
|
||||
char *afn =strdup(audiofile.name()); // store temporary the name
|
||||
#endif
|
||||
cardLock(false);
|
||||
stopSong();
|
||||
if(m_codec == CODEC_MP3) MP3Decoder_FreeBuffers();
|
||||
if(m_codec == CODEC_AAC) AACDecoder_FreeBuffers();
|
||||
@@ -4382,12 +4364,11 @@ void Audio::printDecodeError(int r) {
|
||||
}
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
bool Audio::setPinout(uint8_t BCLK, uint8_t LRC, uint8_t DOUT, int8_t DIN, int8_t MCK) {
|
||||
|
||||
m_pin_config.bck_io_num = BCLK;
|
||||
m_pin_config.ws_io_num = LRC; // wclk
|
||||
m_pin_config.data_out_num = DOUT;
|
||||
m_pin_config.data_in_num = DIN;
|
||||
#if(ESP_IDF_VERSION_MAJOR >= 4 && ESP_IDF_VERSION_MINOR >= 4)
|
||||
#if(ESP_IDF_VERSION_MAJOR >= 4 && ESP_IDF_VERSION_MINOR >= 4) || defined(ESP_ARDUINO_3)
|
||||
m_pin_config.mck_io_num = MCK;
|
||||
#endif
|
||||
const esp_err_t result = i2s_set_pin((i2s_port_t) m_i2s_num, &m_pin_config);
|
||||
@@ -4396,17 +4377,13 @@ bool Audio::setPinout(uint8_t BCLK, uint8_t LRC, uint8_t DOUT, int8_t DIN, int8_
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
uint32_t Audio::getFileSize() {
|
||||
if(!audiofile) return 0;
|
||||
cardLock(true);
|
||||
uint32_t s = audiofile.size();
|
||||
cardLock(false);
|
||||
return s;
|
||||
}
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
uint32_t Audio::getFilePos() {
|
||||
if(!audiofile) return 0;
|
||||
cardLock(true);
|
||||
uint32_t p = audiofile.position();
|
||||
cardLock(false);
|
||||
return p;
|
||||
}
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
@@ -4482,9 +4459,7 @@ bool Audio::setFilePos(uint32_t pos) {
|
||||
InBuff.resetBuffer();
|
||||
if(pos < m_audioDataStart) pos = m_audioDataStart; // issue #96
|
||||
if(m_avr_bitrate) m_audioCurrentTime = ((pos-m_audioDataStart) / m_avr_bitrate) * 8; // #96
|
||||
cardLock(true);
|
||||
uint32_t sk = audiofile.seek(pos);
|
||||
cardLock(false);
|
||||
return sk;
|
||||
}
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -35,7 +35,9 @@
|
||||
#ifndef AUDIOBUFFER_MULTIPLIER2
|
||||
#define AUDIOBUFFER_MULTIPLIER2 8
|
||||
#endif
|
||||
|
||||
#if ESP_ARDUINO_VERSION >= ESP_ARDUINO_VERSION_VAL(3, 0, 0)
|
||||
#include "hal/gpio_ll.h"
|
||||
#endif
|
||||
#ifdef SDFATFS_USED
|
||||
//typedef File32 File;
|
||||
typedef FsFile File;
|
||||
@@ -218,7 +220,6 @@ public:
|
||||
void setI2SCommFMT_LSB(bool commFMT);
|
||||
int getCodec() {return m_codec;}
|
||||
const char *getCodecname() {return codecname[m_codec];}
|
||||
void cardLock(bool lock);
|
||||
private:
|
||||
|
||||
#ifndef ESP_ARDUINO_VERSION_VAL
|
||||
|
||||
@@ -3279,7 +3279,8 @@ void UnpackZeros(int nVals, int *coef)
|
||||
**********************************************************************************************************************/
|
||||
void UnpackQuads(int cb, int nVals, int *coef)
|
||||
{
|
||||
int w, x, y, z, maxBits, nCodeBits, nSignBits, val;
|
||||
int w, x, y, z, maxBits, nCodeBits, nSignBits;
|
||||
int32_t val;
|
||||
uint32_t bitBuf;
|
||||
|
||||
maxBits = huffTabSpecInfo[cb - HUFFTAB_SPEC_OFFSET].maxBits + 4;
|
||||
@@ -3326,9 +3327,9 @@ void UnpackQuads(int cb, int nVals, int *coef)
|
||||
**********************************************************************************************************************/
|
||||
void UnpackPairsNoEsc(int cb, int nVals, int *coef)
|
||||
{
|
||||
int y, z, maxBits, nCodeBits, nSignBits, val;
|
||||
int y, z, maxBits, nCodeBits, nSignBits;
|
||||
uint32_t bitBuf;
|
||||
|
||||
int32_t val;
|
||||
maxBits = huffTabSpecInfo[cb - HUFFTAB_SPEC_OFFSET].maxBits + 2;
|
||||
while (nVals > 0) {
|
||||
/* decode pair */
|
||||
@@ -3368,9 +3369,9 @@ void UnpackPairsNoEsc(int cb, int nVals, int *coef)
|
||||
**********************************************************************************************************************/
|
||||
void UnpackPairsEsc(int cb, int nVals, int *coef)
|
||||
{
|
||||
int y, z, maxBits, nCodeBits, nSignBits, n, val;
|
||||
int y, z, maxBits, nCodeBits, nSignBits, n;
|
||||
uint32_t bitBuf;
|
||||
|
||||
int32_t val;
|
||||
maxBits = huffTabSpecInfo[cb - HUFFTAB_SPEC_OFFSET].maxBits + 2;
|
||||
while (nVals > 0) {
|
||||
/* decode pair with escape value */
|
||||
@@ -4171,9 +4172,9 @@ void DecodeSectionData(int winSequence, int numWinGrp, int maxSFB, uint8_t *sfbC
|
||||
**********************************************************************************************************************/
|
||||
int DecodeOneScaleFactor()
|
||||
{
|
||||
int nBits, val;
|
||||
int nBits;
|
||||
uint32_t bitBuf;
|
||||
|
||||
int32_t val;
|
||||
/* decode next scalefactor from bitstream */
|
||||
bitBuf = GetBitsNoAdvance(huffTabScaleFactInfo.maxBits) << (32 - huffTabScaleFactInfo.maxBits);
|
||||
nBits = DecodeHuffmanScalar(huffTabScaleFact, &huffTabScaleFactInfo, bitBuf, &val);
|
||||
@@ -5143,7 +5144,7 @@ int DeinterleaveShortBlocks(int ch)
|
||||
*
|
||||
* Notes: uses simple linear congruential generator
|
||||
**********************************************************************************************************************/
|
||||
unsigned int Get32BitVal(unsigned int *last)
|
||||
unsigned int Get32BitVal(uint32_t *last)
|
||||
{
|
||||
uint32_t r = *last;
|
||||
|
||||
@@ -8539,10 +8540,10 @@ int DecodeHuffmanScalar(const signed int *huffTab, const HuffInfo_t *huffTabInfo
|
||||
**********************************************************************************************************************/
|
||||
int DecodeOneSymbol(int huffTabIndex) {
|
||||
|
||||
int nBits, val;
|
||||
int nBits;
|
||||
unsigned int bitBuf;
|
||||
const HuffInfo_t *hi;
|
||||
|
||||
int32_t val;
|
||||
hi = &(huffTabSBRInfo[huffTabIndex]);
|
||||
|
||||
bitBuf = GetBitsNoAdvance(hi->maxBits) << (32 - hi->maxBits);
|
||||
|
||||
@@ -487,7 +487,8 @@ void DecodeTNSInfo(int winSequence, TNSInfo_t *ti, int8_t *tnsCoef);
|
||||
void DecodeGainControlInfo(int winSequence, GainControlInfo_t *gi);
|
||||
void DecodeICS(int ch);
|
||||
int DecodeNoiselessData(uint8_t **buf, int *bitOffset, int *bitsAvail, int ch);
|
||||
int DecodeHuffmanScalar(const signed short *huffTab, const HuffInfo_t *huffTabInfo, unsigned int bitBuf, int32_t *val);
|
||||
int DecodeHuffmanScalar(const signed short *huffTab, const HuffInfo_t *huffTabInfo, uint32_t bitBuf, int32_t *val);
|
||||
int DecodeHuffmanScalar(const signed int *huffTab, const HuffInfo_t *huffTabInfo, unsigned int bitBuf, signed int *val);
|
||||
int UnpackADTSHeader(uint8_t **buf, int *bitOffset, int *bitsAvail);
|
||||
int GetADTSChannelMapping(uint8_t *buf, int bitOffset, int bitsAvail);
|
||||
int GetNumChannelsADIF(int nPCE);
|
||||
@@ -498,7 +499,7 @@ int PrepareRawBlock();
|
||||
int DequantBlock(int *inbuf, int nSamps, int scale);
|
||||
int AACDequantize(int ch);
|
||||
int DeinterleaveShortBlocks(int ch);
|
||||
unsigned int Get32BitVal(unsigned int *last);
|
||||
unsigned int Get32BitVal(uint32_t *last);
|
||||
int InvRootR(int r);
|
||||
int ScaleNoiseVector(int *coef, int nVals, int sf);
|
||||
void GenerateNoiseVector(int *coef, int *last, int nVals);
|
||||
@@ -557,7 +558,7 @@ int CalcCovariance1(int *XBuf, int *p01reN, int *p01imN, int *p12reN, int *p12im
|
||||
int CalcCovariance2(int *XBuf, int *p02reN, int *p02imN);
|
||||
void CalcLPCoefs(int *XBuf, int *a0re, int *a0im, int *a1re, int *a1im, int gb);
|
||||
void GenerateHighFreq(SBRGrid *sbrGrid, SBRFreq *sbrFreq, SBRChan *sbrChan, int ch);
|
||||
int DecodeHuffmanScalar(const signed int *huffTab, const HuffInfo_t *huffTabInfo, unsigned int bitBuf, signed int *val);
|
||||
|
||||
int DecodeOneSymbol(int huffTabIndex);
|
||||
int DequantizeEnvelope(int nBands, int ampRes, int8_t *envQuant, int *envDequant);
|
||||
void DequantizeNoise(int nBands, int8_t *noiseQuant, int *noiseDequant);
|
||||
|
||||
Reference in New Issue
Block a user