Code Monkey home page Code Monkey logo

espidf_pdm_mic_out's Introduction

ESP32 PDM Microphone (SPM0405HD4H) and built-in DAC/PDM output Example

This is based on ESP-IDF i2s_adc_dac Example. Adapted to PlatformIO IDE for VSCode

Please refer to https://kunsen.net/ for details.


  • This is an example of:
    • Recording sound from PDM Microphone (SPM0405HD4H)
    • Replay the recorded sound via PDM or DAC
    • Play an audio file in flash

  • Run this example
    • Set partition table to "partitions_adc_dac_example.csv" in platformio.ini

  • This example will execute the following steps:
    1. Erase flash
    2. Record audio from PDM microphone and save in flash
    3. Read flash and replay the sound via PDM or DAC
    4. Play an example audio file(file format: 8bit/8khz/single channel)
    5. Loop back to step 3


  • How to generate audio files:

    • tools/generate_audio_file.py is an example of generate audio table from .wav files.
    • In this example, the wav file must be in 16k/16bit mono format.
    • generate_audio_file.py will bundle the wav files into a single table named audio_example_file.h
    • Since the ADC can only play 8-bit data, the script will scale each 16-bit value to a 8-bit value.
    • Since the ADC can only output positive value, the script will turn a signed value into an unsigned value.

  • Note:
    • DAC can only play 8-bit data, so the wav file data are scaled to 8-bit data.
    • I2S DMA can only output 16-bit/32-bit data to DAC, DAC will only take the highest 8-bit data and output accordingly.
    • Before I2S DMA can output data stream to DAC, the data format should be converted to 16-bit or 32-bit by padding zeros.

espidf_pdm_mic_out's People

Contributors

kunsen-an avatar

Stargazers

 avatar  avatar  avatar Ozgur BOSTAN avatar Tony Gauda avatar

Watchers

James Cloos avatar

espidf_pdm_mic_out's Issues

fail to compiling

please help i tring to compile with platformIO but it failed every time.

src/app_main.c: In function 'example_pdm_mic_init':
src/app_main.c:145:9: warning: 'I2S_COMM_FORMAT_I2S_MSB' is deprecated [-Wdeprecated-declarations]
145 | .communication_format = I2S_COMM_FORMAT_I2S_MSB, //pcm data format
| ^
In file included from C:/Users/prase/.platformio/packages/framework-espidf/components/driver/deprecated/driver/i2s.h:20:
C:/Users/prase/.platformio/packages/framework-espidf/components/driver/deprecated/driver/i2s_types_legacy.h:89:5: note: declared here
89 | I2S_COMM_FORMAT_I2S_MSB attribute((deprecated)) = 0x01, /!< I2S format MSB, (I2S_COMM_FORMAT_I2S |I2S_COMM_FORMAT_I2S_MSB) correspond to I2S_COMM_FORMAT_STAND_I2S/
| ^~~~~~~~~~~~~~~~~~~~~~~
src/app_main.c: In function 'example_pdm_out_init':
src/app_main.c:179:9: warning: 'I2S_COMM_FORMAT_I2S_MSB' is deprecated [-Wdeprecated-declarations]
179 | .communication_format = I2S_COMM_FORMAT_I2S_MSB, //pcm data format
| ^
C:/Users/prase/.platformio/packages/framework-espidf/components/driver/deprecated/driver/i2s_types_legacy.h:89:5: note: declared here
89 | I2S_COMM_FORMAT_I2S_MSB attribute((deprecated)) = 0x01, /!< I2S format MSB, (I2S_COMM_FORMAT_I2S |I2S_COMM_FORMAT_I2S_MSB) correspond to I2S_COMM_FORMAT_STAND_I2S/
| ^~~~~~~~~~~~~~~~~~~~~~~
src/app_main.c:198:5: warning: 'DAC_CHANNEL_1' is deprecated: please use 'DAC_CHAN_0' instead [-Wdeprecated-declarations]
198 | dac_output_disable(DAC_CHANNEL_1);
| ^~~~~~~~~~~~~~~~~~
In file included from C:/Users/prase/.platformio/packages/framework-espidf/components/driver/deprecated/driver/dac_types_legacy.h:14,
from C:/Users/prase/.platformio/packages/framework-espidf/components/driver/deprecated/driver/dac.h:13:
C:/Users/prase/.platformio/packages/framework-espidf/components/hal/include/hal/dac_types.h:10:5: note: declared here
10 | DAC_CHANNEL_1 attribute((deprecated("please use 'DAC_CHAN_0' instead"))) = 0, /!< Alias of 'DAC_CHAN_0', now the channel index start from '0' /
| ^~~~~~~~~~~~~
src/app_main.c: In function 'example_i2s_dac_out_init':
src/app_main.c:211:9: warning: 'I2S_COMM_FORMAT_I2S_MSB' is deprecated [-Wdeprecated-declarations]
211 | .communication_format = I2S_COMM_FORMAT_I2S_MSB,
| ^
C:/Users/prase/.platformio/packages/framework-espidf/components/driver/deprecated/driver/i2s_types_legacy.h:89:5: note: declared here
89 | I2S_COMM_FORMAT_I2S_MSB attribute((deprecated)) = 0x01, /
!< I2S format MSB, (I2S_COMM_FORMAT_I2S |I2S_COMM_FORMAT_I2S_MSB) correspond to I2S_COMM_FORMAT_STAND_I2S
/
| ^~~~~~~~~~~~~~~~~~~~~~~
In file included from C:/Users/prase/.platformio/packages/framework-espidf/components/esp_hw_support/include/esp_cpu.h:20,
from C:/Users/prase/.platformio/packages/framework-espidf/components/esp_hw_support/include/spinlock.h:11,
from C:/Users/prase/.platformio/packages/framework-espidf/components/freertos/FreeRTOS-Kernel/portable/xtensa/include/freertos/portmacro.h:49,
from C:/Users/prase/.platformio/packages/framework-espidf/components/freertos/FreeRTOS-Kernel/include/freertos/portable.h:57,
from C:/Users/prase/.platformio/packages/framework-espidf/components/freertos/FreeRTOS-Kernel/include/freertos/FreeRTOS.h:69,
from src/app_main.c:3:
C:/Users/prase/.platformio/packages/framework-espidf/components/esp_hw_support/include/esp_intr_alloc.h:33:37: warning: initialized field overwritten [-Woverride-init]
33 | #define ESP_INTR_FLAG_LEVEL1 (1<<1) ///< Accept a Level 1 interrupt vector (lowest priority)
| ^
src/app_main.c:218:29: note: in expansion of macro 'ESP_INTR_FLAG_LEVEL1'
218 | .intr_alloc_flags = ESP_INTR_FLAG_LEVEL1 // Interrupt level 1
| ^~~~~~~~~~~~~~~~~~~~
C:/Users/prase/.platformio/packages/framework-espidf/components/esp_hw_support/include/esp_intr_alloc.h:33:37: note: (near initialization for 'i2s_config_tx.intr_alloc_flags')
33 | #define ESP_INTR_FLAG_LEVEL1 (1<<1) ///< Accept a Level 1 interrupt vector (lowest priority)
| ^
src/app_main.c:218:29: note: in expansion of macro 'ESP_INTR_FLAG_LEVEL1'
218 | .intr_alloc_flags = ESP_INTR_FLAG_LEVEL1 // Interrupt level 1
| ^~~~~~~~~~~~~~~~~~~~
src/app_main.c: In function 'example_erase_flash':
src/app_main.c:256:37: error: format '%x' expects argument of type 'unsigned int', but argument 2 has type 'uint32_t' {aka 'long unsigned int'} [-Werror=format=]
256 | printf("partiton addr: 0x%08x; size: %d; label: %s\n", data_partition->address, data_partition->size, data_partition->label);
Compiling .pio\build\esp32dev\console\argtable3\arg_hashtable.c.o
| ~~~^ ~~~~~~~~~~~~~~~~~~~~~~~
| | |
| unsigned int uint32_t {aka long unsigned int}
| %08lx
src/app_main.c:256:47: error: format '%d' expects argument of type 'int', but argument 3 has type 'uint32_t' {aka 'long unsigned int'} [-Werror=format=]
256 | printf("partiton addr: 0x%08x; size: %d; label: %s\n", data_partition->address, data_partition->size, data_partition->label);
Compiling .pio\build\esp32dev\console\argtable3\arg_int.c.o
| ~^ ~~~~~~~~~~~~~~~~~~~~
| | |
| int uint32_t {aka long unsigned int}
| %ld
src/app_main.c: In function 'example_pdm_out':
src/app_main.c:410:37: error: format '%x' expects argument of type 'unsigned int', but argument 2 has type 'uint32_t' {aka 'long unsigned int'} [-Werror=format=]
410 | printf("partiton addr: 0x%08x; size: %d; label: %s\n", data_partition->address, data_partition->size, data_partition->label);
| ~~~^ ~~~~~~~~~~~~~~~~~~~~~~~
| | |
| unsigned int uint32_t {aka long unsigned int}
| %08lx
src/app_main.c:410:47: error: format '%d' expects argument of type 'int', but argument 3 has type 'uint32_t' {aka 'long unsigned int'} [-Werror=format=]
410 | printf("partiton addr: 0x%08x; size: %d; label: %s\n", data_partition->address, data_partition->size, data_partition->label);
| ~^ ~~~~~~~~~~~~~~~~~~~~
| | |
| int uint32_t {aka long unsigned int}
| %ld
src/app_main.c:437:9: error: implicit declaration of function 'ets_printf'; did you mean 'vsiprintf'? [-Werror=implicit-function-declaration]
437 | ets_printf("Sound recording %u%%\n", flash_wr_size * 100 / FLASH_RECORD_SIZE);
| ^~~~~~~~~~
| vsiprintf
cc1.exe: some warnings being treated as errors
*** [.pio\build\esp32dev\src\app_main.c.o] Error 1
==================================================================== [FAILED] Took 6.71 seconds ====================================================================

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.