Unverified Commit 076234c0 authored by Wolle's avatar Wolle Committed by GitHub

SdFat support

parent f3554645
......@@ -2,7 +2,7 @@
* Audio.cpp
*
* Created on: Oct 26,2018
* Updated on: May 12,2021
* Updated on: May 15,2021
* Author: Wolle (schreibfaul1)
*
*/
......@@ -11,6 +11,10 @@
#include "aac_decoder/aac_decoder.h"
#include "flac_decoder/flac_decoder.h"
#ifdef SDFATFS_USED
fs::SDFATFS SD_SDFAT;
#endif
//---------------------------------------------------------------------------------------------------------------------
AudioBuffer::AudioBuffer(size_t maxBlockSize) {
// if maxBlockSize isn't set use defaultspace (1600 bytes) is enough for aac and mp3 player
......@@ -421,6 +425,19 @@ bool Audio::setFileLoop(bool input){
//---------------------------------------------------------------------------------------------------------------------
void Audio::UTF8toASCII(char* str){
#ifdef SDFATFS_USED
//UTF8->UTF16 (lowbyte)
const uint8_t ascii[60] = {
//129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148 // UTF8(C3)
// Ä Å Æ Ç É Ñ // CHAR
000, 000, 000, 0xC4, 143, 0xC6,0xC7, 000,0xC9,000, 000, 000, 000, 000, 000, 000, 0xD1, 000, 000, 000, // ASCII (Latin1)
//149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168
// Ö Ü ß à ä å æ è
000, 0xD6,000, 000, 000, 000, 000, 0xDC, 000, 000, 0xDF,0xE0, 000, 000, 000,0xE4,0xE5,0xE6, 000,0xE8,
//169, 170, 171, 172. 173. 174. 175, 176, 177, 179, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188
// ê ë ì î ï ñ ò ô ö ù û ü
000, 0xEA, 0xEB,0xEC, 000,0xEE,0xEB, 000,0xF1,0xF2, 000,0xF4, 000,0xF6, 000, 000,0xF9, 000,0xFB,0xFC};
#else
const uint8_t ascii[60] = {
//129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148 // UTF8(C3)
// Ä Å Æ Ç É Ñ // CHAR
......@@ -431,6 +448,7 @@ void Audio::UTF8toASCII(char* str){
//169, 170, 171, 172. 173. 174. 175, 176, 177, 179, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188
// ê ë ì î ï ñ ò ô ö ù û ü
000, 136, 137, 141, 000, 140, 139, 000, 164, 149, 000, 147, 000, 148, 000, 000, 151, 000, 150, 129};
#endif
uint16_t i = 0, j=0, s = 0;
bool f_C3_seen = false;
......@@ -492,7 +510,13 @@ bool Audio::connecttoFS(fs::FS &fs, const char* path) {
m_f_localfile = true;
m_file_size = audiofile.size();//TEST loop
#ifdef SDFATFS_USED
audiofile.getName(chbuf, sizeof(chbuf));
String afn = chbuf;
#else
String afn = (String) audiofile.name(); // audioFileName
#endif
afn.toLowerCase();
if(afn.endsWith(".mp3")) { // MP3 section
m_codec = CODEC_MP3;
......@@ -2096,7 +2120,14 @@ void Audio::processLocalFile() {
} //TEST loop
m_f_stream = false;
m_f_localfile = false;
#ifdef SDFATFS_USED
audiofile.getName(chbuf, sizeof(chbuf));
char *afn =strdup(chbuf);
#else
char *afn =strdup(audiofile.name()); // store temporary the name
#endif
stopSong();
if(m_codec == CODEC_MP3) MP3Decoder_FreeBuffers();
if(m_codec == CODEC_AAC) AACDecoder_FreeBuffers();
......@@ -3442,8 +3473,8 @@ uint32_t Audio::getBitRate(){
return m_bitRate;
}
//---------------------------------------------------------------------------------------------------------------------
void Audio::setInternalDAC(bool internalDAC /* = true */, i2s_dac_mode_t channelEnabled /* = I2S_DAC_CHANNEL_LEFT_EN */ ) {
[[deprecated]]void Audio::setInternalDAC(bool internalDAC /* = true */, i2s_dac_mode_t channelEnabled /* = I2S_DAC_CHANNEL_LEFT_EN */ ) {
// is deprecated, set internal DAC in constructor e.g. Audio audio(true, I2S_DAC_CHANNEL_BOTH_EN);
m_f_channelEnabled = channelEnabled;
m_f_internalDAC = internalDAC;
i2s_driver_uninstall((i2s_port_t)m_i2s_num);
......
......@@ -2,25 +2,67 @@
* Audio.h
*
* Created on: Oct 26,2018
* Updated on: May 12,2021
* Updated on: May 15,2021
* Author: Wolle (schreibfaul1)
*/
#ifndef AUDIO_H_
#define AUDIO_H_
//#define SDFATFS_USED // activate for SdFat
#pragma once
#pragma GCC optimize ("Ofast")
#define FF_LFN_UNICODE 2
#include "Arduino.h"
#include "base64.h"
#include "SPI.h"
#include "WiFi.h"
#include "WiFiClientSecure.h"
#include "driver/i2s.h"
#ifdef SDFATFS_USED
#include "SdFat.h" // use https://github.com/greiman/SdFat-beta for UTF-8 filenames
#else
#include "SD.h"
#include "SD_MMC.h"
#include "SPIFFS.h"
#include "FS.h"
#include "FFat.h"
#include "WiFiClientSecure.h"
#include "driver/i2s.h"
#endif // SDFATFS_USED
#ifdef SDFATFS_USED
typedef File32 File;
namespace fs {
class FS : public SdFat {
public:
bool begin(SdCsPin_t csPin = SS, uint32_t maxSck = SD_SCK_MHZ(25)) { return SdFat::begin(csPin, maxSck); }
};
class SDFATFS : public fs::FS {
public:
// sdcard_type_t cardType();
uint64_t cardSize() {
return totalBytes();
}
uint64_t usedBytes() {
// set SdFatConfig MAINTAIN_FREE_CLUSTER_COUNT non-zero. Then only the first call will take time.
return (uint64_t)(clusterCount() - freeClusterCount()) * (uint64_t)bytesPerCluster();
}
uint64_t totalBytes() {
return (uint64_t)clusterCount() * (uint64_t)bytesPerCluster();
}
};
}
extern fs::SDFATFS SD_SDFAT;
using namespace fs;
#define SD SD_SDFAT
#endif //SDFATFS_USED
extern __attribute__((weak)) void audio_info(const char*);
extern __attribute__((weak)) void audio_id3data(const char*); //ID3 metadata
......@@ -106,61 +148,45 @@ class Audio : private AudioBuffer{
public:
Audio(bool internalDAC = false, i2s_dac_mode_t channelEnabled = I2S_DAC_CHANNEL_LEFT_EN); // #99
~Audio();
bool connecttohost(const char* host, const char* user = "", const char* pwd = "");
bool connecttospeech(const char* speech, const char* lang);
bool connecttoFS(fs::FS &fs, const char* path);
bool connecttoSD(const char* path);
bool setFileLoop(bool input);//TEST loop
void UTF8toASCII(char* str);
bool connecttohost(const char* host, const char* user = "", const char* pwd = "");
bool connecttospeech(const char* speech, const char* lang);
void loop();
uint32_t getFileSize();
uint32_t getFilePos();
uint32_t getSampleRate();
uint8_t getBitsPerSample();
uint8_t getChannels();
uint32_t getBitRate();
/**
* @brief Get the audio file duration in seconds
*
* @return uint32_t file duration in seconds, 0 if no file active
*/
uint32_t getAudioFileDuration();
/**
* @brief Get the current plying time in seconds
*
* @return uint32_t current second of audio file, 0 if no file active
*/
uint32_t getAudioCurrentTime();
bool setAudioPlayPosition(uint16_t sec);
bool setFilePos(uint32_t pos);
bool audioFileSeek(const float speed);
uint32_t getTotalPlayingTime();
bool setTimeOffset(int sec);
bool setPinout(uint8_t BCLK, uint8_t LRC, uint8_t DOUT, int8_t DIN=I2S_PIN_NO_CHANGE);
void stopSong();
/**
* @brief pauseResume pauses current playback
*
* @return true if audio file or stream is active, false otherwise
*/
bool pauseResume();
bool isRunning() {return m_f_running;}
void loop();
void stopSong();
void forceMono(bool m);
void setBalance(int8_t bal = 0);
void setVolume(uint8_t vol);
uint8_t getVolume();
inline uint8_t getDatamode(){return m_datamode;}
inline void setDatamode(uint8_t dm){m_datamode=dm;}
inline uint32_t streamavail() {if(m_f_ssl==false) return client.available(); else return clientsecure.available();}
bool isRunning() {return m_f_running;}
uint32_t getFileSize();
uint32_t getFilePos();
uint32_t getSampleRate();
uint8_t getBitsPerSample();
uint8_t getChannels();
uint32_t getBitRate();
uint32_t getAudioFileDuration();
uint32_t getAudioCurrentTime();
uint32_t getTotalPlayingTime();
esp_err_t i2s_mclk_pin_select(const uint8_t pin);
uint32_t inBufferFilled(); // returns the number of stored bytes in the inputbuffer
uint32_t inBufferFree(); // returns the number of free bytes in the inputbuffer
void setTone(int8_t gainLowPass, int8_t gainBandPass, int8_t gainHighPass);
void setInternalDAC(bool internalDAC = true, i2s_dac_mode_t channelEnabled = I2S_DAC_CHANNEL_LEFT_EN);
[[deprecated]]void setInternalDAC(bool internalDAC = true, i2s_dac_mode_t channelEnabled = I2S_DAC_CHANNEL_LEFT_EN);
void setI2SCommFMT_LSB(bool commFMT);
private:
void UTF8toASCII(char* str);
void setDefaults(); // free buffers and set defaults
void initInBuff();
void processLocalFile();
......@@ -197,6 +223,9 @@ private:
int16_t* IIR_filterChain0(int16_t iir_in[2], bool clear = false);
int16_t* IIR_filterChain1(int16_t* iir_in, bool clear = false);
int16_t* IIR_filterChain2(int16_t* iir_in, bool clear = false);
inline void setDatamode(uint8_t dm){m_datamode=dm;}
inline uint8_t getDatamode(){return m_datamode;}
inline uint32_t streamavail() {if(m_f_ssl==false) return client.available(); else return clientsecure.available();}
void IIR_calculateCoefficients(int8_t G1, int8_t G2, int8_t G3);
// implement several function with respect to the index of string
......@@ -353,4 +382,5 @@ private:
int8_t m_gain2 = 0;
};
#endif /* AUDIO_H_ */
//----------------------------------------------------------------------------------------------------------------------
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