Skip to content

Commit 8efc951

Browse files
committed
use_apll
1 parent 2fe9a67 commit 8efc951

File tree

4 files changed

+34
-30
lines changed

4 files changed

+34
-30
lines changed

examples/examples-stream/streams-i2s-csv/streams-i2s-csv.ino

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,9 @@
1111
#include "AudioTools.h"
1212

1313
using namespace audio_tools;
14-
ConverterSwapBytes<int32_t> swap;
15-
ConverterOutlierFilter<int32_t> outlier;
16-
MultiConverter<int32_t> mc(outlier);
1714

1815
I2SStream i2sStream; // Access I2S as stream
1916
CsvStream<int32_t> csvStream(Serial);
20-
//HexDumpStream csvStream(Serial);
2117
StreamCopy copier(csvStream, i2sStream); // copy i2sStream to csvStream
2218

2319
// Arduino Setup
@@ -28,9 +24,9 @@ void setup(void) {
2824
auto cfg = i2sStream.defaultConfig(RX_MODE);
2925
cfg.bits_per_sample = 32;
3026
cfg.channels = 2;
31-
cfg.sample_rate = 96000;
32-
cfg.is_master = false;
33-
cfg.i2s_format = I2S_MSB_FORMAT;
27+
cfg.sample_rate = 44100;
28+
cfg.is_master = true;
29+
cfg.i2s_format = I2S_MSB_FORMAT; // or try with I2S_LSB_FORMAT
3430
i2sStream.begin(cfg);
3531

3632
// make sure that we have the correct channels set up
@@ -40,5 +36,5 @@ void setup(void) {
4036

4137
// Arduino loop - copy data
4238
void loop() {
43-
copier.copy(mc);
39+
copier.copy();
4440
}

src/AudioConfig.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,9 @@
157157
#define PIN_ADC1 34
158158
#define PIN_ADC2 35
159159

160+
#define I2S_AUTO_CLEAR true
161+
162+
160163
// URLStream
161164
#define URL_STREAM_CORE 0
162165
#define URL_STREAM_PRIORITY 2

src/AudioI2S/I2SConfig.h

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ enum I2SFormat {
1515
I2S_PCM_SHORT
1616
};
1717

18+
const char* i2s_formats[] = {"I2S_STD_FORMAT","I2S_LSB_FORMAT","I2S_MSB_FORMAT","I2S_PHILIPS_FORMAT","I2S_RIGHT_JUSTIFIED_FORMAT","I2S_LEFT_JUSTIFIED_FORMAT","I2S_PCM_LONG","I2S_PCM_SHORT"};
19+
1820

1921
/**
2022
* @brief configuration for all common i2s settings
@@ -50,14 +52,31 @@ class I2SConfig : public AudioBaseInfo {
5052
int pin_bck = PIN_I2S_BCK;
5153
int pin_data = PIN_I2S_DATA_OUT;
5254
I2SFormat i2s_format = I2S_STD_FORMAT;
55+
56+
#ifdef ESP32
5357
bool is_digital = true; // e.g. the ESP32 supports analog input or output
58+
bool use_apll = I2S_USE_APLL;
59+
uint32_t apll_frequency_factor = 0; // apll frequency = sample_rate * apll_frequency_factor
60+
#endif
5461

5562
void logInfo() {
63+
LOGI("rx/tx mode: %s", rx_tx_mode == TX_MODE ? "TX":"RX");
5664
LOGI("port_no: %d", port_no);
65+
LOGI("is_master: %s", is_master ? "Master":"Slave");
66+
LOGI("sample rate: %d", sample_rate);
67+
LOGI("bits per sample: %d", bits_per_sample);
68+
LOGI("number of channels: %d", channels);
69+
LOGI("i2s_format: %s", i2s_formats[i2s_format]);
70+
#ifdef ESP32
71+
if (use_apll) {
72+
LOGI("use_apll: %s", use_apll ? "true" : "false");
73+
LOGI("apll_frequency_factor: %d", apll_frequency_factor);
74+
}
75+
#endif
76+
5777
LOGI("pin_ws: %d", pin_ws);
5878
LOGI("pin_bck: %d", pin_bck);
5979
LOGI("pin_data: %d", pin_data);
60-
LOGI("i2s_format: %d", i2s_format);
6180
}
6281

6382
};

src/AudioI2S/I2SESP32.h

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#include "driver/i2s.h"
99
#include "esp_a2dp_api.h"
10+
#include "esp_system.h"
1011

1112
namespace audio_tools {
1213

@@ -35,6 +36,7 @@ class I2SBase {
3536
/// starts the DAC
3637
void begin(I2SConfig cfg) {
3738
LOGD(LOG_METHOD);
39+
cfg.logInfo();
3840
this->cfg = cfg;
3941
this->i2s_num = (i2s_port_t) cfg.port_no;
4042
setChannels(cfg.channels);
@@ -48,12 +50,13 @@ class I2SBase {
4850
.intr_alloc_flags = ESP_INTR_FLAG_LEVEL1, // default interrupt priority
4951
.dma_buf_count = I2S_BUFFER_COUNT,
5052
.dma_buf_len = I2S_BUFFER_SIZE,
51-
.use_apll = I2S_USE_APLL,
52-
.tx_desc_auto_clear = true // avoiding noise in case of data unavailability
53+
.use_apll = cfg.use_apll,
54+
.tx_desc_auto_clear = I2S_AUTO_CLEAR,
55+
.fixed_mclk = cfg.use_apll ? cfg.sample_rate * cfg.apll_frequency_factor : 0
56+
5357
};
5458
i2s_config = i2s_config_new;
55-
logConfig();
56-
59+
5760
// We make sure that we can reconfigure
5861
if (is_started) {
5962
end();
@@ -73,7 +76,6 @@ class I2SBase {
7376
.data_out_num = cfg.rx_tx_mode == TX_MODE ? cfg.pin_data : I2S_PIN_NO_CHANGE,
7477
.data_in_num = cfg.rx_tx_mode == RX_MODE ? cfg.pin_data : I2S_PIN_NO_CHANGE
7578
};
76-
logConfigPins(pin_config);
7779

7880
if (i2s_set_pin(i2s_num, &pin_config)!= ESP_OK){
7981
LOGE("%s - %s", __func__, "i2s_set_pin");
@@ -244,22 +246,6 @@ class I2SBase {
244246
return mode;
245247
}
246248

247-
248-
void logConfig() {
249-
LOGI("rx/tx mode: %s", cfg.rx_tx_mode == TX_MODE ? "TX":"RX");
250-
LOGI("sample rate: %d", cfg.sample_rate);
251-
LOGI("bits per sample: %d", cfg.bits_per_sample);
252-
LOGI("number of channels: %d", cfg.channels);
253-
LOGI("is_master: %s", cfg.is_master ? "Master":"Slave");
254-
LOGI("mode: %d", cfg.i2s_format);
255-
}
256-
257-
void logConfigPins(i2s_pin_config_t pin_config){
258-
LOGI("pin bck_io_num: %d", cfg.pin_bck);
259-
LOGI("pin ws_io_num: %d", cfg.pin_ws);
260-
LOGI("pin data_num: %d", cfg.pin_data);
261-
}
262-
263249
};
264250

265251
}

0 commit comments

Comments
 (0)