Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
ESP32-audioI2S
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
ESP32-audioI2S
Commits
337c3cbf
Unverified
Commit
337c3cbf
authored
May 19, 2022
by
Wolle
Committed by
GitHub
May 19, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
prepare for ESP32-S3
parent
d97aa317
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
53 additions
and
70 deletions
+53
-70
src/Audio.cpp
src/Audio.cpp
+50
-66
src/Audio.h
src/Audio.h
+3
-4
No files found.
src/Audio.cpp
View file @
337c3cbf
...
@@ -154,7 +154,17 @@ uint32_t AudioBuffer::getReadPos() {
...
@@ -154,7 +154,17 @@ uint32_t AudioBuffer::getReadPos() {
return m_readPtr - m_buffer;
return m_readPtr - m_buffer;
}
}
//---------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------
Audio::Audio(bool internalDAC /* = false */, i2s_dac_mode_t channelEnabled /* = I2S_DAC_CHANNEL_LEFT_EN */ ) {
Audio::Audio(bool internalDAC /* = false */, uint8_t channelEnabled /* = I2S_DAC_CHANNEL_BOTH_EN */ ) {
// build-in-DAC works only with ESP32 (ESP32-S3 has no build-in-DAC)
// build-in-DAC last working Arduino Version: 2.0.0-RC2
// possible values for channelEnabled are:
// I2S_DAC_CHANNEL_DISABLE = 0, Disable I2S built-in DAC signals
// I2S_DAC_CHANNEL_RIGHT_EN = 1, Enable I2S built-in DAC right channel, maps to DAC channel 1 on GPIO25
// I2S_DAC_CHANNEL_LEFT_EN = 2, Enable I2S built-in DAC left channel, maps to DAC channel 2 on GPIO26
// I2S_DAC_CHANNEL_BOTH_EN = 0x3, Enable both of the I2S built-in DAC channels.
// I2S_DAC_CHANNEL_MAX = 0x4, I2S built-in DAC mode max index
clientsecure.setInsecure(); // if that can't be resolved update to ESP32 Arduino version 1.0.5-rc05 or higher
clientsecure.setInsecure(); // if that can't be resolved update to ESP32 Arduino version 1.0.5-rc05 or higher
m_f_channelEnabled = channelEnabled;
m_f_channelEnabled = channelEnabled;
m_f_internalDAC = internalDAC;
m_f_internalDAC = internalDAC;
...
@@ -169,21 +179,29 @@ Audio::Audio(bool internalDAC /* = false */, i2s_dac_mode_t channelEnabled /* =
...
@@ -169,21 +179,29 @@ Audio::Audio(bool internalDAC /* = false */, i2s_dac_mode_t channelEnabled /* =
m_i2s_config.use_apll = APLL_DISABLE; // must be disabled in V2.0.1-RC1
m_i2s_config.use_apll = APLL_DISABLE; // must be disabled in V2.0.1-RC1
m_i2s_config.tx_desc_auto_clear = true; // new in V1.0.1
m_i2s_config.tx_desc_auto_clear = true; // new in V1.0.1
m_i2s_config.fixed_mclk = I2S_PIN_NO_CHANGE;
m_i2s_config.fixed_mclk = I2S_PIN_NO_CHANGE;
if (internalDAC) {
if (internalDAC) {
log_i("internal DAC");
m_i2s_config.mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_TX | I2S_MODE_DAC_BUILT_IN );
#if ESP_ARDUINO_VERSION_MAJOR >= 2
#ifdef CONFIG_IDF_TARGET_ESP32
m_i2s_config.communication_format = (i2s_comm_format_t)(I2S_COMM_FORMAT_STAND_I2S); // vers >= 2.0.0
#else
log_i("internal DAC");
m_i2s_config.communication_format = (i2s_comm_format_t)(I2S_COMM_FORMAT_I2S_MSB);
m_i2s_config.mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_TX | I2S_MODE_DAC_BUILT_IN );
#if ESP_ARDUINO_VERSION_MAJOR >= 2
m_i2s_config.communication_format = (i2s_comm_format_t)(I2S_COMM_FORMAT_STAND_I2S); // vers >= 2.0.0
#else
m_i2s_config.communication_format = (i2s_comm_format_t)(I2S_COMM_FORMAT_I2S_MSB);
#endif
i2s_driver_install((i2s_port_t)m_i2s_num, &m_i2s_config, 0, NULL);
i2s_set_dac_mode((i2s_dac_mode_t)m_f_channelEnabled);
if(m_f_channelEnabled != I2S_DAC_CHANNEL_BOTH_EN) {
m_f_forceMono = true;
}
#endif
#endif
i2s_driver_install((i2s_port_t)m_i2s_num, &m_i2s_config, 0, NULL);
i2s_set_dac_mode(m_f_channelEnabled);
if(m_f_channelEnabled != I2S_DAC_CHANNEL_BOTH_EN) {
m_f_forceMono = true;
}
}
}
else {
else {
m_i2s_config.mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_TX);
m_i2s_config.mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_TX);
...
@@ -243,22 +261,26 @@ esp_err_t Audio::i2s_mclk_pin_select(const uint8_t pin) {
...
@@ -243,22 +261,26 @@ esp_err_t Audio::i2s_mclk_pin_select(const uint8_t pin) {
log_e("Only support GPIO0/GPIO1/GPIO3, gpio_num:%d", pin);
log_e("Only support GPIO0/GPIO1/GPIO3, gpio_num:%d", pin);
return ESP_ERR_INVALID_ARG;
return ESP_ERR_INVALID_ARG;
}
}
switch(pin){
case 0:
#ifdef CONFIG_IDF_TARGET_ESP32
PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO0_U, FUNC_GPIO0_CLK_OUT1);
switch(pin){
WRITE_PERI_REG(PIN_CTRL, 0xFFF0);
case 0:
break;
PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO0_U, FUNC_GPIO0_CLK_OUT1);
case 1:
WRITE_PERI_REG(PIN_CTRL, 0xFFF0);
PIN_FUNC_SELECT(PERIPHS_IO_MUX_U0TXD_U, FUNC_U0TXD_CLK_OUT3);
break;
WRITE_PERI_REG(PIN_CTRL, 0xF0F0);
case 1:
break;
PIN_FUNC_SELECT(PERIPHS_IO_MUX_U0TXD_U, FUNC_U0TXD_CLK_OUT3);
case 3:
WRITE_PERI_REG(PIN_CTRL, 0xF0F0);
PIN_FUNC_SELECT(PERIPHS_IO_MUX_U0RXD_U, FUNC_U0RXD_CLK_OUT2);
break;
WRITE_PERI_REG(PIN_CTRL, 0xFF00);
case 3:
break;
PIN_FUNC_SELECT(PERIPHS_IO_MUX_U0RXD_U, FUNC_U0RXD_CLK_OUT2);
default:
WRITE_PERI_REG(PIN_CTRL, 0xFF00);
break;
break;
}
default:
break;
}
#endif
return ESP_OK;
return ESP_OK;
}
}
//---------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------
...
@@ -4024,44 +4046,6 @@ uint32_t Audio::getBitRate(bool avg){
...
@@ -4024,44 +4046,6 @@ uint32_t Audio::getBitRate(bool avg){
return m_bitRate;
return m_bitRate;
}
}
//---------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------
[[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);
if (internalDAC) {
log_i("internal DAC");
m_i2s_config.mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_TX | I2S_MODE_DAC_BUILT_IN );
#if ESP_ARDUINO_VERSION_MAJOR >= 2
m_i2s_config.communication_format = (i2s_comm_format_t)(I2S_COMM_FORMAT_STAND_I2S); // vers >= 2.0.0
#else
m_i2s_config.communication_format = (i2s_comm_format_t)(I2S_COMM_FORMAT_I2S_MSB);
#endif
i2s_driver_install((i2s_port_t) m_i2s_num, &m_i2s_config, 0, NULL);
// enable the DAC channels
i2s_set_dac_mode(m_f_channelEnabled);
if(m_f_channelEnabled != I2S_DAC_CHANNEL_BOTH_EN) {
m_f_forceMono = true;
}
}
else { // external DAC
m_i2s_config.mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_TX);
#if ESP_ARDUINO_VERSION_MAJOR >= 2
m_i2s_config.communication_format = (i2s_comm_format_t)(I2S_COMM_FORMAT_STAND_I2S); // vers >= 2.0.0
#else
m_i2s_config.communication_format = (i2s_comm_format_t)(I2S_COMM_FORMAT_I2S | I2S_COMM_FORMAT_I2S_MSB);
#endif
i2s_driver_install ((i2s_port_t)m_i2s_num, &m_i2s_config, 0, NULL);
i2s_set_pin((i2s_port_t) m_i2s_num, &m_pin_config);
}
// clear the DMA buffers
i2s_zero_dma_buffer((i2s_port_t) m_i2s_num);
}
//---------------------------------------------------------------------------------------------------------------------
void Audio::setI2SCommFMT_LSB(bool commFMT) {
void Audio::setI2SCommFMT_LSB(bool commFMT) {
// false: I2S communication format is by default I2S_COMM_FORMAT_I2S_MSB, right->left (AC101, PCM5102A)
// false: I2S communication format is by default I2S_COMM_FORMAT_I2S_MSB, right->left (AC101, PCM5102A)
// true: changed to I2S_COMM_FORMAT_I2S_LSB for some DACs (PT8211)
// true: changed to I2S_COMM_FORMAT_I2S_LSB for some DACs (PT8211)
...
...
src/Audio.h
View file @
337c3cbf
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
* Audio.h
* Audio.h
*
*
* Created on: Oct 26,2018
* Created on: Oct 26,2018
* Updated on: May
03
,2022
* Updated on: May
19
,2022
* Author: Wolle (schreibfaul1)
* Author: Wolle (schreibfaul1)
*/
*/
...
@@ -155,7 +155,7 @@ class Audio : private AudioBuffer{
...
@@ -155,7 +155,7 @@ class Audio : private AudioBuffer{
AudioBuffer
InBuff
;
// instance of input buffer
AudioBuffer
InBuff
;
// instance of input buffer
public:
public:
Audio
(
bool
internalDAC
=
false
,
i2s_dac_mode_t
channelEnabled
=
I2S_DAC_CHANNEL_LEFT_EN
);
// #99
Audio
(
bool
internalDAC
=
false
,
uint8_t
channelEnabled
=
3
);
// #99
~
Audio
();
~
Audio
();
void
setBufsize
(
int
rambuf_sz
,
int
psrambuf_sz
);
void
setBufsize
(
int
rambuf_sz
,
int
psrambuf_sz
);
bool
connecttohost
(
const
char
*
host
,
const
char
*
user
=
""
,
const
char
*
pwd
=
""
);
bool
connecttohost
(
const
char
*
host
,
const
char
*
user
=
""
,
const
char
*
pwd
=
""
);
...
@@ -193,7 +193,6 @@ public:
...
@@ -193,7 +193,6 @@ public:
uint32_t
inBufferFilled
();
// returns the number of stored bytes in the inputbuffer
uint32_t
inBufferFilled
();
// returns the number of stored bytes in the inputbuffer
uint32_t
inBufferFree
();
// returns the number of free 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
setTone
(
int8_t
gainLowPass
,
int8_t
gainBandPass
,
int8_t
gainHighPass
);
[[
deprecated
]]
void
setInternalDAC
(
bool
internalDAC
=
true
,
i2s_dac_mode_t
channelEnabled
=
I2S_DAC_CHANNEL_LEFT_EN
);
void
setI2SCommFMT_LSB
(
bool
commFMT
);
void
setI2SCommFMT_LSB
(
bool
commFMT
);
int
getCodec
()
{
return
m_codec
;}
int
getCodec
()
{
return
m_codec
;}
const
char
*
getCodecname
()
{
return
codecname
[
m_codec
];}
const
char
*
getCodecname
()
{
return
codecname
[
m_codec
];}
...
@@ -472,7 +471,7 @@ private:
...
@@ -472,7 +471,7 @@ 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
i2s_dac_mode_t
m_f_channelEnabled
=
I2S_DAC_CHANNEL_LEFT_EN
;
// internal DAC on GPIO26 for M5StickC/Plu
s
uint8_t
m_f_channelEnabled
=
3
;
// internal DAC, both channel
s
uint32_t
m_audioFileDuration
=
0
;
uint32_t
m_audioFileDuration
=
0
;
float
m_audioCurrentTime
=
0
;
float
m_audioCurrentTime
=
0
;
uint32_t
m_audioDataStart
=
0
;
// in bytes
uint32_t
m_audioDataStart
=
0
;
// in bytes
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment