'i2s_pop_sample' was not declared in this scope

MEL_21
Posts: 6
Joined: Sun May 02, 2021 3:01 pm

'i2s_pop_sample' was not declared in this scope

Postby MEL_21 » Sun May 09, 2021 9:00 am

Hello All,

I am using the Arduino IDE 1.8.13 with the ESP32 boards definition v1.0.6 and I am trying to compile the I2S sample code (from: https://diyi0t.com/i2s-sound-tutorial-for-esp32) and get the error: 'i2s_pop_sample' was not declared in this scope.

What else do I need to install to make this work?
(the other calls in the code seem to be compiling fine)

Thanks,
Markus


Code: Select all

#include "driver/i2s.h"
const i2s_port_t I2S_PORT = I2S_NUM_0;

void setup() {
  Serial.begin(115200);
  esp_err_t err;

  // The I2S config as per the example
  const i2s_config_t i2s_config = {
      .mode = i2s_mode_t(I2S_MODE_MASTER | I2S_MODE_RX), // Receive, not transfer
      .sample_rate = 16000,                         // 16KHz
      .bits_per_sample = I2S_BITS_PER_SAMPLE_32BIT, // could only get it to work with 32bits
      .channel_format = I2S_CHANNEL_FMT_ONLY_RIGHT, // use right channel
      .communication_format = i2s_comm_format_t(I2S_COMM_FORMAT_I2S | I2S_COMM_FORMAT_I2S_MSB),
      .intr_alloc_flags = ESP_INTR_FLAG_LEVEL1,     // Interrupt level 1
      .dma_buf_count = 4,                           // number of buffers
      .dma_buf_len = 8                              // 8 samples per buffer (minimum)
  };

  // The pin config as per the setup
  const i2s_pin_config_t pin_config = {
      .bck_io_num = 26,   // Serial Clock (SCK)
      .ws_io_num = 25,    // Word Select (WS)
      .data_out_num = I2S_PIN_NO_CHANGE, // not used (only for speakers)
      .data_in_num = 33   // Serial Data (SD)
  };

  // Configuring the I2S driver and pins.
  // This function must be called before any I2S driver read/write operations.
  err = i2s_driver_install(I2S_PORT, &i2s_config, 0, NULL);
  if (err != ESP_OK) {
    Serial.printf("Failed installing driver: %d\n", err);
    while (true);
  }
  err = i2s_set_pin(I2S_PORT, &pin_config);
  if (err != ESP_OK) {
    Serial.printf("Failed setting pin: %d\n", err);
    while (true);
  }
  Serial.println("I2S driver installed.");
}

void loop() {
  // Read a single sample and log it for the Serial Plotter.
  int32_t sample = 0;
  int bytes_read = i2s_pop_sample(I2S_PORT, (char *)&sample, portMAX_DELAY); // no timeout
  if (bytes_read > 0) {
    Serial.println(sample);
  }
}

MEL_21
Posts: 6
Joined: Sun May 02, 2021 3:01 pm

Re: 'i2s_pop_sample' was not declared in this scope

Postby MEL_21 » Sun May 09, 2021 5:48 pm

OK found the issue: it's marked 'deprecated' - and has been replaced with 'i2s_read()'.

rv2442
Posts: 1
Joined: Mon Oct 18, 2021 9:52 am

Re: 'i2s_pop_sample' was not declared in this scope

Postby rv2442 » Mon Oct 18, 2021 9:55 am

im having the same issue can you guide on what you did to make it work?? pls explain in a way i can understand as im a noob in i2s as well as esp32

MEL_21
Posts: 6
Joined: Sun May 02, 2021 3:01 pm

Re: 'i2s_pop_sample' was not declared in this scope

Postby MEL_21 » Tue Oct 19, 2021 12:32 pm

As I wrote the function call is old and had been replaced. use something like this:

Code: Select all

void setup()
{
// The I2S config as per the example
  const i2s_config_t i2s_config = {
    .mode = i2s_mode_t(I2S_MODE_MASTER | I2S_MODE_RX), // Receive, not transfer
    .sample_rate = 5000,                         // 5KHz
    .bits_per_sample = I2S_BITS_PER_SAMPLE_16BIT, // 16bit samples
    .channel_format = I2S_CHANNEL_FMT_ONLY_LEFT, // use left channel
    .communication_format = i2s_comm_format_t(I2S_COMM_FORMAT_STAND_I2S),
    .intr_alloc_flags = ESP_INTR_FLAG_LEVEL1,     // Interrupt level 1
    .dma_buf_count = 3,                           // number of buffers
    .dma_buf_len = ARRAY_SIZE                     // samples per buffer
  };

  // The pin config as per the setup
  const i2s_pin_config_t pin_config = {
    .bck_io_num = 8,   // Serial Clock (SCK)
    .ws_io_num = 9,    // Word Select (WS)
    .data_out_num = I2S_PIN_NO_CHANGE, // not used (only for speakers)
    .data_in_num = 10   // Serial Data (SD)
  };

  // Configuring the I2S driver and pins.
  // This function must be called before any I2S driver read/write operations.
  err = i2s_driver_install(I2S_PORT, &i2s_config, 0, NULL);
  if (err != ESP_OK) {
    Serial.printf("Failed installing driver: %d\n", err);
    while (true);
  }
  err = i2s_set_pin(I2S_PORT, &pin_config);
  if (err != ESP_OK) {
    Serial.printf("Failed setting pin: %d\n", err);
    while (true);
  }
  Serial.println("I2S driver installed.");
  }
  
int16_t sBuffer[ARRAY_SIZE];
void loop()
{
    size_t bytesIn = 0;
    esp_err_t result = i2s_read(I2S_PORT, sBuffer, sizeof(sBuffer), &bytesIn, /*portMAX_DELAY*/ 10); // no timeout
    if (result == ESP_OK && bytesIn > 0)
    {
    	// do your processing
   }
}
 

Who is online

Users browsing this forum: No registered users and 142 guests