Skip to content

Commit f9f0168

Browse files
committed
delete old stuff
1 parent 6a84894 commit f9f0168

File tree

2 files changed

+7
-133
lines changed

2 files changed

+7
-133
lines changed

src/Audio.cpp

Lines changed: 5 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ uint32_t AudioBuffer::getWritePos() { return m_writePtr - m_buffer; }
158158
uint32_t AudioBuffer::getReadPos() { return m_readPtr - m_buffer; }
159159
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
160160
// clang-format off
161-
Audio::Audio(bool internalDAC /* = false */, uint8_t channelEnabled /* = I2S_SLOT_MODE_STEREO */, uint8_t i2sPort) {
161+
Audio::Audio(uint8_t i2sPort) {
162162

163163
mutex_playAudioData = xSemaphoreCreateMutex();
164164
mutex_audioTask = xSemaphoreCreateMutex();
@@ -177,12 +177,9 @@ Audio::Audio(bool internalDAC /* = false */, uint8_t channelEnabled /* = I2S_SLO
177177
#define AUDIO_INFO(...) { snprintf(m_ibuff, m_ibuffSize, __VA_ARGS__); if(audio_info) audio_info(m_ibuff); }
178178

179179
clientsecure.setInsecure();
180-
m_f_channelEnabled = channelEnabled;
181-
m_f_internalDAC = internalDAC;
182180
m_i2s_num = i2sPort; // i2s port number
183181

184182
// -------- I2S configuration -------------------------------------------------------------------------------------------
185-
#if ESP_IDF_VERSION_MAJOR == 5
186183
m_i2s_chan_cfg.id = (i2s_port_t)m_i2s_num; // I2S_NUM_AUTO, I2S_NUM_0, I2S_NUM_1
187184
m_i2s_chan_cfg.role = I2S_ROLE_MASTER; // I2S controller master role, bclk and lrc signal will be set to output
188185
m_i2s_chan_cfg.dma_desc_num = 32; // number of DMA buffer
@@ -206,45 +203,6 @@ Audio::Audio(bool internalDAC /* = false */, uint8_t channelEnabled /* = I2S_SLO
206203
I2Sstart(m_i2s_num);
207204
m_sampleRate = 44100;
208205

209-
if (internalDAC) {
210-
#ifdef CONFIG_IDF_TARGET_ESP32 // ESP32S3 has no DAC
211-
printf("internal DAC is not supported");
212-
// no support in V5 ???
213-
#endif
214-
}
215-
#else
216-
m_i2s_config.sample_rate = 44100;
217-
m_i2s_config.bits_per_sample = I2S_BITS_PER_SAMPLE_16BIT;
218-
m_i2s_config.channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT;
219-
m_i2s_config.intr_alloc_flags = ESP_INTR_FLAG_LEVEL1; // interrupt priority
220-
m_i2s_config.dma_buf_count = 16;
221-
m_i2s_config.dma_buf_len = 512;
222-
m_i2s_config.use_apll = APLL_DISABLE;
223-
m_i2s_config.tx_desc_auto_clear = true;
224-
m_i2s_config.fixed_mclk = true;
225-
m_i2s_config.mclk_multiple = I2S_MCLK_MULTIPLE_128;
226-
227-
if (internalDAC) {
228-
#ifdef CONFIG_IDF_TARGET_ESP32 // ESP32S3 has no DAC
229-
printf("internal DAC");
230-
m_i2s_config.mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_TX | I2S_MODE_DAC_BUILT_IN );
231-
m_i2s_config.communication_format = (i2s_comm_format_t)(I2S_COMM_FORMAT_STAND_MSB); // vers >= 2.0.5
232-
i2s_driver_install((i2s_port_t)m_i2s_num, &m_i2s_config, 0, NULL);
233-
i2s_set_dac_mode((i2s_dac_mode_t)m_f_channelEnabled);
234-
if(m_f_channelEnabled != I2S_DAC_CHANNEL_BOTH_EN) {
235-
m_f_forceMono = true;
236-
}
237-
#endif
238-
}
239-
else {
240-
m_i2s_config.mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_TX);
241-
m_i2s_config.communication_format = (i2s_comm_format_t)(I2S_COMM_FORMAT_STAND_I2S); // Arduino vers. > 2.0.0
242-
i2s_driver_install((i2s_port_t)m_i2s_num, &m_i2s_config, 0, NULL);
243-
m_f_forceMono = false;
244-
}
245-
i2s_zero_dma_buffer((i2s_port_t) m_i2s_num);
246-
247-
#endif // ESP_IDF_VERSION_MAJOR == 5
248206
for(int i = 0; i < 3; i++) {
249207
m_filter[i].a0 = 1;
250208
m_filter[i].a1 = 0;
@@ -261,12 +219,8 @@ Audio::~Audio() {
261219
// InBuff.~AudioBuffer(); #215 the AudioBuffer is automatically destroyed by the destructor
262220
setDefaults();
263221

264-
#if ESP_IDF_VERSION_MAJOR == 5
265222
i2s_channel_disable(m_i2s_tx_handle);
266223
i2s_del_channel(m_i2s_tx_handle);
267-
#else
268-
i2s_driver_uninstall((i2s_port_t)m_i2s_num); // #215 free I2S buffer
269-
#endif
270224

271225
x_ps_free(&m_playlistBuff);
272226
x_ps_free(&m_chbuf);
@@ -300,21 +254,11 @@ void Audio::initInBuff() {
300254

301255
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
302256
esp_err_t Audio::I2Sstart(uint8_t i2s_num) {
303-
#if ESP_IDF_VERSION_MAJOR == 5
304257
return i2s_channel_enable(m_i2s_tx_handle);
305-
#else
306-
// It is not necessary to call this function after i2s_driver_install() (it is started automatically),
307-
// however it is necessary to call it after i2s_stop()
308-
return i2s_start((i2s_port_t)i2s_num);
309-
#endif
310258
}
311259

312260
esp_err_t Audio::I2Sstop(uint8_t i2s_num) {
313-
#if ESP_IDF_VERSION_MAJOR == 5
314261
return i2s_channel_disable(m_i2s_tx_handle);
315-
#else
316-
return i2s_stop((i2s_port_t)i2s_num);
317-
#endif
318262
}
319263
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
320264
void Audio::setDefaults() {
@@ -2343,12 +2287,6 @@ void Audio::playChunk() {
23432287
(*sample)[LEFTCHANNEL] = (int16_t)xy;
23442288
}
23452289
Gain(*sample);
2346-
2347-
if(m_f_internalDAC) {
2348-
s2 = *sample;
2349-
s2[LEFTCHANNEL] += 0x8000;
2350-
s2[RIGHTCHANNEL] += 0x8000;
2351-
}
23522290
i += 2;
23532291
validSamples -= 1;
23542292
}
@@ -2367,13 +2305,7 @@ void Audio::playChunk() {
23672305

23682306
validSamples = m_validSamples;
23692307

2370-
2371-
#if(ESP_IDF_VERSION_MAJOR == 5)
23722308
err = i2s_channel_write(m_i2s_tx_handle, (int16_t*)m_outBuff + count, validSamples * sampleSize, &i2s_bytesConsumed, 10);
2373-
#else
2374-
err = i2s_write((i2s_port_t)m_i2s_num, (int16_t*)m_outBuff + count, validSamples * sampleSize, &i2s_bytesConsumed, 10);
2375-
#endif
2376-
23772309
if( ! (err == ESP_OK || err == ESP_ERR_TIMEOUT)) goto exit;
23782310
m_validSamples -= i2s_bytesConsumed / sampleSize;
23792311
count += i2s_bytesConsumed / 2;
@@ -4774,21 +4706,10 @@ bool Audio::setPinout(uint8_t BCLK, uint8_t LRC, uint8_t DOUT, int8_t MCLK) {
47744706
}
47754707
esp_err_t result = ESP_OK;
47764708

4777-
if(m_f_internalDAC) {
4778-
#if(ESP_IDF_VERSION_MAJOR != 5)
4779-
i2s_set_pin((i2s_port_t)m_i2s_num, NULL);
4780-
#endif
4781-
return true;
4782-
}
4783-
4784-
#if(ESP_ARDUINO_VERSION_MAJOR < 2)
4785-
log_e("Arduino Version too old!");
4786-
#endif
4787-
#if(ESP_ARDUINO_VERSION_MAJOR == 2 && ESP_ARDUINO_VERSION_PATCH < 8)
4788-
log_e("Arduino Version must be 2.0.8 or higher!");
4709+
#if(ESP_ARDUINO_VERSION_MAJOR < 3)
4710+
log_e("Arduino Version must be 3.0.0 or higher!");
47894711
#endif
47904712

4791-
#if(ESP_IDF_VERSION_MAJOR == 5)
47924713
i2s_std_gpio_config_t gpio_cfg = {};
47934714
gpio_cfg.bclk = (gpio_num_t)BCLK;
47944715
gpio_cfg.din = (gpio_num_t)I2S_GPIO_UNUSED;
@@ -4798,14 +4719,7 @@ bool Audio::setPinout(uint8_t BCLK, uint8_t LRC, uint8_t DOUT, int8_t MCLK) {
47984719
I2Sstop(m_i2s_num);
47994720
result = i2s_channel_reconfig_std_gpio(m_i2s_tx_handle, &gpio_cfg);
48004721
I2Sstart(m_i2s_num);
4801-
#else
4802-
m_pin_config.bck_io_num = BCLK;
4803-
m_pin_config.ws_io_num = LRC; // wclk = lrc
4804-
m_pin_config.data_out_num = DOUT;
4805-
m_pin_config.data_in_num = I2S_GPIO_UNUSED;
4806-
m_pin_config.mck_io_num = MCLK;
4807-
result = i2s_set_pin((i2s_port_t)m_i2s_num, &m_pin_config);
4808-
#endif
4722+
48094723
return (result == ESP_OK);
48104724
}
48114725
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
@@ -4912,24 +4826,6 @@ bool Audio::setFilePos(uint32_t pos) {
49124826
return false;
49134827
}
49144828
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
4915-
bool Audio::audioFileSeek(const float speed) {
4916-
// 0.5 is half speed
4917-
// 1.0 is normal speed
4918-
// 1.5 is one and half speed
4919-
// if((speed > 1.5f) || (speed < 0.25f)) return false;
4920-
4921-
// uint32_t srate = getSampleRate() * speed;
4922-
// #if ESP_IDF_VERSION_MAJOR == 5
4923-
// I2Sstop(m_i2s_num);
4924-
// m_i2s_std_cfg.clk_cfg.sample_rate_hz = srate;
4925-
// i2s_channel_reconfig_std_clock(m_i2s_tx_handle, &m_i2s_std_cfg.clk_cfg);
4926-
// I2Sstart(m_i2s_num);
4927-
// #else
4928-
// i2s_set_sample_rates((i2s_port_t)m_i2s_num, srate);
4929-
// #endif
4930-
return true;
4931-
}
4932-
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
49334829
bool Audio::setSampleRate(uint32_t sampRate) {
49344830
if(!sampRate) sampRate = 44100; // fuse, if there is no value -> set default #209
49354831
m_sampleRate = sampRate;
@@ -4958,7 +4854,6 @@ uint8_t Audio::getChannels() {
49584854
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
49594855
void Audio::reconfigI2S(){
49604856

4961-
#if ESP_IDF_VERSION_MAJOR == 5
49624857
I2Sstop(0);
49634858

49644859
if(getBitsPerSample() == 8 && getChannels() == 2) m_i2s_std_cfg.clk_cfg.sample_rate_hz = getSampleRate() * 2;
@@ -4973,10 +4868,7 @@ void Audio::reconfigI2S(){
49734868
i2s_channel_reconfig_std_slot(m_i2s_tx_handle, &m_i2s_std_cfg.slot_cfg);
49744869

49754870
I2Sstart(m_i2s_num);
4976-
#else
4977-
m_i2s_config.channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT;
4978-
i2s_set_clk((i2s_port_t)m_i2s_num, m_sampleRate, I2S_BITS_PER_SAMPLE_16BIT, I2S_CHANNEL_STEREO);
4979-
#endif
4871+
49804872
memset(m_filterBuff, 0, sizeof(m_filterBuff)); // Clear FilterBuffer
49814873
IIR_calculateCoefficients(m_gain0, m_gain1, m_gain2); // must be recalculated after each samplerate change
49824874
return;
@@ -4999,18 +4891,6 @@ void Audio::setI2SCommFMT_LSB(bool commFMT) {
49994891

50004892
m_f_commFMT = commFMT;
50014893

5002-
#if ESP_IDF_VERSION_MAJOR < 5
5003-
if(commFMT) {
5004-
AUDIO_INFO("commFMT = LSBJ (Least Significant Bit Justified)");
5005-
m_i2s_config.communication_format = (i2s_comm_format_t)(I2S_COMM_FORMAT_STAND_MSB);
5006-
}
5007-
else {
5008-
AUDIO_INFO("commFMT = Philips");
5009-
m_i2s_config.communication_format = (i2s_comm_format_t)(I2S_COMM_FORMAT_STAND_I2S);
5010-
}
5011-
i2s_driver_uninstall((i2s_port_t)m_i2s_num);
5012-
i2s_driver_install((i2s_port_t)m_i2s_num, &m_i2s_config, 0, NULL);
5013-
#else
50144894
i2s_channel_disable(m_i2s_tx_handle);
50154895
if(commFMT) {
50164896
AUDIO_INFO("commFMT = LSBJ (Least Significant Bit Justified)");
@@ -5022,7 +4902,6 @@ void Audio::setI2SCommFMT_LSB(bool commFMT) {
50224902
}
50234903
i2s_channel_reconfig_std_slot(m_i2s_tx_handle, &m_i2s_std_cfg.slot_cfg);
50244904
i2s_channel_enable(m_i2s_tx_handle);
5025-
#endif
50264905
}
50274906
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
50284907
void Audio::computeVUlevel(int16_t sample[2]) {
@@ -5134,9 +5013,6 @@ void Audio::setBalance(int8_t bal) { // bal -16...16
51345013
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
51355014
void Audio::setVolume(uint8_t vol, uint8_t curve) { // curve 0: default, curve 1: flat at the beginning
51365015

5137-
uint16_t v = ESP_ARDUINO_VERSION_MAJOR * 100 + ESP_ARDUINO_VERSION_MINOR * 10 + ESP_ARDUINO_VERSION_PATCH;
5138-
if(v < 207) AUDIO_INFO("Do not use this ancient Adruino version V%d.%d.%d", ESP_ARDUINO_VERSION_MAJOR, ESP_ARDUINO_VERSION_MINOR, ESP_ARDUINO_VERSION_PATCH);
5139-
51405016
if(vol > m_vol_steps) m_vol = m_vol_steps;
51415017
else m_vol = vol;
51425018

src/Audio.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ class Audio : private AudioBuffer{
142142
AudioBuffer InBuff; // instance of input buffer
143143

144144
public:
145-
Audio(bool internalDAC = false, uint8_t channelEnabled = 3, uint8_t i2sPort = I2S_NUM_0); // #99
145+
Audio(uint8_t i2sPort = I2S_NUM_0);
146146
~Audio();
147147
void setBufsize(int rambuf_sz, int psrambuf_sz);
148148
bool openai_speech(const String& api_key, const String& model, const String& input, const String& voice, const String& response_format, const String& speed);
@@ -153,7 +153,6 @@ class Audio : private AudioBuffer{
153153
void setConnectionTimeout(uint16_t timeout_ms, uint16_t timeout_ms_ssl);
154154
bool setAudioPlayPosition(uint16_t sec);
155155
bool setFilePos(uint32_t pos);
156-
bool audioFileSeek(const float speed);
157156
bool setTimeOffset(int sec);
158157
bool setPinout(uint8_t BCLK, uint8_t LRC, uint8_t DOUT, int8_t MCLK = I2S_GPIO_UNUSED);
159158
bool pauseResume();
@@ -682,7 +681,6 @@ uint64_t bigEndian(uint8_t* base, uint8_t numBytes, uint8_t shiftLeft = 8) {
682681
bool m_f_tts = false; // text to speech
683682
bool m_f_loop = false; // Set if audio file should loop
684683
bool m_f_forceMono = false; // if true stereo -> mono
685-
bool m_f_internalDAC = false; // false: output vis I2S, true output via internal DAC
686684
bool m_f_rtsp = false; // set if RTSP is used (m3u8 stream)
687685
bool m_f_m3u8data = false; // used in processM3U8entries
688686
bool m_f_Log = false; // set in platformio.ini -DAUDIO_LOG and -DCORE_DEBUG_LEVEL=3 or 4
@@ -699,7 +697,7 @@ uint64_t bigEndian(uint8_t* base, uint8_t numBytes, uint8_t shiftLeft = 8) {
699697
bool m_f_lockInBuffer = false; // lock inBuffer for manipulation
700698
bool m_f_audioTaskIsDecoding = false;
701699
bool m_f_acceptRanges = false;
702-
uint8_t m_f_channelEnabled = 3; // internal DAC, both channels
700+
uint8_t m_f_channelEnabled = 3; //
703701
uint32_t m_audioFileDuration = 0;
704702
float m_audioCurrentTime = 0;
705703
uint32_t m_audioDataStart = 0; // in bytes

0 commit comments

Comments
 (0)