Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need a working microphone example for M5AtomS3U #31

Open
2 tasks done
i-am-shodan opened this issue Dec 2, 2024 · 0 comments
Open
2 tasks done

Need a working microphone example for M5AtomS3U #31

i-am-shodan opened this issue Dec 2, 2024 · 0 comments

Comments

@i-am-shodan
Copy link

Describe the bug

There are very few examples to show how to pull mic samples with the M5AtomS3U. All my attempts have failed.

To reproduce

Here is some example code that I think should work. It does get samples but all of these are invalid.

    do
    {
        i2s_chan_config_t rx_chan_cfg = I2S_CHANNEL_DEFAULT_CONFIG(I2S_NUM_AUTO, I2S_ROLE_MASTER);
        if (i2s_new_channel(&rx_chan_cfg, NULL, &rx_chan) != ESP_OK)
        {
            Debug::Log.error(LOG_MIC, "i2s_new_channel error");
            break;
        }

        i2s_pdm_rx_config_t pdm_rx_cfg = {
            .clk_cfg = I2S_PDM_RX_CLK_DEFAULT_CONFIG(SAMPLE_RATE),
            /* The data bit-width of PDM mode is fixed to 16 */
            .slot_cfg = I2S_PDM_RX_SLOT_DEFAULT_CONFIG(I2S_DATA_BIT_WIDTH_16BIT, I2S_SLOT_MODE_MONO),
            .gpio_cfg = {
                .clk = (gpio_num_t)I2S_SPM1423_CLK,
                .din = (gpio_num_t)I2S_SPM1423_DATA,
                .invert_flags = {
                    .clk_inv = false,
                },
            },
        };

        pdm_rx_cfg.slot_cfg.slot_mask = I2S_PDM_SLOT_RIGHT;
        if (i2s_channel_init_pdm_rx_mode(rx_chan, &pdm_rx_cfg) != ESP_OK)
        {
            break;
        }

        /* Step 3: Enable the rx channels before reading data */
        if (i2s_channel_enable(rx_chan) != ESP_OK)
        {
            break;
        }

        size_t bytes_read = 0;
        if (i2s_channel_read(rx_chan, (microphonedata0 + data_offset), DATA_SIZE, &bytes_read, 1000) == ESP_OK && bytes_read != 0)
        {
                data_offset += bytes_read;
                // write to serial for debug
        }

    } while (false);

Expected behavior

A working example and some valid samples

Screenshots

No response

Environment

  • OS:
  • IDE &IDE Version:
  • Repository Version:

Additional context

No response

Issue checklist

  • I searched for previous reports in the issue tracker
  • My report contains all necessary details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant