Skip to content

Commit

Permalink
audio_stream: fix warnings with ESP-IDF >= 5
Browse files Browse the repository at this point in the history
Fix the following warnings when building with ESP-IDF 5:

    In file included from /willow/deps/esp-adf/components/audio_stream/lib/gzip/miniz_inflate.h:32,
                     from /willow/deps/esp-adf/components/audio_stream/lib/gzip/gzip_miniz.c:30:
    /opt/esp/idf/components/esp_rom/include/esp32s3/rom/miniz.h:7:2: warning: #warning "{target}/rom/miniz.h is deprecated, please use (#include "miniz.h") instead" [-Wcpp]
        7 | #warning "{target}/rom/miniz.h is deprecated, please use (#include "miniz.h") instead"
          |  ^~~~~~~

    /willow/deps/esp-adf/components/audio_stream/i2s_stream.c:142:5: warning: 'dma_buf_count' is deprecated [-Wdeprecated-declarations]
      142 |     int index = i2s->config.i2s_config.dma_buf_count;
          |     ^~~
    In file included from /opt/esp/idf/components/driver/deprecated/driver/i2s.h:20,
                     from /willow/deps/esp-adf/components/audio_stream/i2s_stream.c:33:
    /opt/esp/idf/components/driver/deprecated/driver/i2s_types_legacy.h:225:13: note: declared here
      225 |         int dma_buf_count __attribute__((deprecated));  /*!< This is an alias to 'dma_desc_num' for backward compatibility */
          |             ^~~~~~~~~~~~~

    /willow/deps/esp-adf/components/audio_stream/i2s_stream.c:143:5: warning: 'dma_buf_len' is deprecated [-Wdeprecated-declarations]
      143 |     uint8_t *buf = audio_calloc(1, i2s->config.i2s_config.dma_buf_len * 4);
          |     ^~~~~~~
    /opt/esp/idf/components/driver/deprecated/driver/i2s_types_legacy.h:229:13: note: declared here
      229 |         int dma_buf_len __attribute__((deprecated));    /*!< This is an alias to 'dma_frame_num' for backward compatibility */
          |             ^~~~~~~~~~~
    /willow/deps/esp-adf/components/audio_stream/i2s_stream.c:151:9: warning: 'dma_buf_len' is deprecated [-Wdeprecated-declarations]
      151 |         audio_element_output(self, (char *)buf, i2s->config.i2s_config.dma_buf_len * 4);
          |         ^~~~~~~~~~~~~~~~~~~~
    /opt/esp/idf/components/driver/deprecated/driver/i2s_types_legacy.h:229:13: note: declared here
      229 |         int dma_buf_len __attribute__((deprecated));    /*!< This is an alias to 'dma_frame_num' for backward compatibility */
          |             ^~~~~~~~~~~
  • Loading branch information
stintel committed Sep 27, 2023
1 parent 5d76d8c commit d8bb73e
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 2 deletions.
13 changes: 13 additions & 0 deletions components/audio_stream/i2s_stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,16 +139,29 @@ static inline esp_err_t i2s_stream_check_data_bits(i2s_stream_t *i2s, int bits)
static int i2s_stream_clear_dma_buffer(audio_element_handle_t self)
{
i2s_stream_t *i2s = (i2s_stream_t *)audio_element_getdata(self);
#if (ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0))
int index = i2s->config.i2s_config.dma_desc_num;
uint8_t *buf = audio_calloc(1, i2s->config.i2s_config.dma_frame_num * 4);
#else
int index = i2s->config.i2s_config.dma_buf_count;
uint8_t *buf = audio_calloc(1, i2s->config.i2s_config.dma_buf_len * 4);
#endif
AUDIO_MEM_CHECK(TAG, buf, return ESP_ERR_NO_MEM);
#if SOC_I2S_SUPPORTS_ADC_DAC
if ((i2s->config.i2s_config.mode & I2S_MODE_DAC_BUILT_IN) != 0) {
#if (ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0))
memset(buf, 0x80, i2s->config.i2s_config.dma_frame_num * 4);
#else
memset(buf, 0x80, i2s->config.i2s_config.dma_buf_len * 4);
#endif
}
#endif
while (index--) {
#if (ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0))
audio_element_output(self, (char *)buf, i2s->config.i2s_config.dma_frame_num * 4);
#else
audio_element_output(self, (char *)buf, i2s->config.i2s_config.dma_buf_len * 4);
#endif
}
if (buf) {
audio_free(buf);
Expand Down
90 changes: 89 additions & 1 deletion components/audio_stream/include/i2s_stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ typedef struct {
.need_expand = false, \
.expand_src_bits = I2S_BITS_PER_SAMPLE_16BIT, \
}
#else
#elif (ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0, 0))
#define I2S_STREAM_CFG_DEFAULT() { \
.type = AUDIO_STREAM_WRITER, \
.i2s_config = { \
Expand Down Expand Up @@ -236,6 +236,94 @@ typedef struct {
.need_expand = false, \
.expand_src_bits = I2S_BITS_PER_SAMPLE_16BIT, \
}
#else
#define I2S_STREAM_CFG_DEFAULT() { \
.type = AUDIO_STREAM_WRITER, \
.i2s_config = { \
.mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_TX | I2S_MODE_RX), \
.sample_rate = 44100, \
.bits_per_sample = I2S_BITS_PER_SAMPLE_16BIT, \
.channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT, \
.communication_format = I2S_COMM_FORMAT_STAND_I2S, \
.intr_alloc_flags = ESP_INTR_FLAG_LEVEL2 | ESP_INTR_FLAG_IRAM, \
.dma_desc_num = 3, \
.dma_frame_num = 300, \
.use_apll = true, \
.tx_desc_auto_clear = true, \
.fixed_mclk = 0 \
}, \
.i2s_port = I2S_NUM_0, \
.use_alc = false, \
.volume = 0, \
.out_rb_size = I2S_STREAM_RINGBUFFER_SIZE, \
.task_stack = I2S_STREAM_TASK_STACK, \
.task_core = I2S_STREAM_TASK_CORE, \
.task_prio = I2S_STREAM_TASK_PRIO, \
.stack_in_ext = false, \
.multi_out_num = 0, \
.uninstall_drv = true, \
.need_expand = false, \
.expand_src_bits = I2S_BITS_PER_SAMPLE_16BIT, \
.buffer_len = I2S_STREAM_BUF_SIZE, \
}

#define I2S_STREAM_INTERNAL_DAC_CFG_DEFAULT() { \
.type = AUDIO_STREAM_WRITER, \
.i2s_config = { \
.mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_DAC_BUILT_IN | I2S_MODE_TX),\
.sample_rate = 44100, \
.bits_per_sample = I2S_BITS_PER_SAMPLE_16BIT, \
.channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT, \
.communication_format = I2S_COMM_FORMAT_STAND_MSB, \
.intr_alloc_flags = ESP_INTR_FLAG_LEVEL2, \
.dma_desc_num = 3, \
.dma_frame_num = 300, \
.use_apll = false, \
.tx_desc_auto_clear = true, \
.fixed_mclk = 0 \
}, \
.i2s_port = I2S_NUM_0, \
.use_alc = false, \
.volume = 0, \
.out_rb_size = I2S_STREAM_RINGBUFFER_SIZE, \
.task_stack = I2S_STREAM_TASK_STACK, \
.task_core = I2S_STREAM_TASK_CORE, \
.task_prio = I2S_STREAM_TASK_PRIO, \
.stack_in_ext = false, \
.multi_out_num = 0, \
.uninstall_drv = false, \
.need_expand = false, \
.expand_src_bits = I2S_BITS_PER_SAMPLE_16BIT, \
}

#define I2S_STREAM_TX_PDM_CFG_DEFAULT() { \
.type = AUDIO_STREAM_WRITER, \
.i2s_config = { \
.mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_PDM | I2S_MODE_TX), \
.sample_rate = 48000, \
.bits_per_sample = I2S_BITS_PER_SAMPLE_16BIT, \
.channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT, \
.communication_format = I2S_COMM_FORMAT_STAND_MSB, \
.dma_desc_num = 3, \
.dma_frame_num = 300, \
.use_apll = true, \
.tx_desc_auto_clear = true, \
.fixed_mclk = 0 \
}, \
.i2s_port = I2S_NUM_0, \
.use_alc = false, \
.volume = 0, \
.out_rb_size = I2S_STREAM_RINGBUFFER_SIZE, \
.task_stack = I2S_STREAM_TASK_STACK, \
.task_core = I2S_STREAM_TASK_CORE, \
.task_prio = I2S_STREAM_TASK_PRIO, \
.stack_in_ext = false, \
.multi_out_num = 0, \
.uninstall_drv = false, \
.need_expand = false, \
.expand_src_bits = I2S_BITS_PER_SAMPLE_16BIT, \
}

#endif

/**
Expand Down
4 changes: 3 additions & 1 deletion components/audio_stream/lib/gzip/miniz_inflate.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@
#include "esp_idf_version.h"
#if (ESP_IDF_VERSION_MAJOR == 4) && (ESP_IDF_VERSION_MINOR < 3)
#include "esp32/rom/miniz.h"
#else
#elif (ESP_IDF_VERSION_MAJOR < 5) && (ESP_IDF_VERSION_MINOR < 1)
#include "rom/miniz.h"
#else
#include "miniz.h"
#endif

// Add the API missing in miniz of ROM code
Expand Down

0 comments on commit d8bb73e

Please sign in to comment.