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

Clarification of code implementation of audio_provider.cc in the micro_speech example (TFMIC-27) #84

Open
mingyr opened this issue Jun 18, 2024 · 2 comments

Comments

@mingyr
Copy link

mingyr commented Jun 18, 2024

I just wonder anyone can elaberate on a piece of code below which relates to audio capturing via I2S protocol on the ESP32 S3 platform?
It is excerpted from the CaptureSamples function. My question is why right shift by 14 bits not 16? I tried to find some reference but up to now without success.

Anyone can give some explanation in this matter is highly appreciated.

#if CONFIG_IDF_TARGET_ESP32S3
      // rescale the data
      for (int i = 0; i < bytes_read / 4; ++i) {
        ((int16_t *) g_i2s_read_buffer)[i] = ((int32_t *) g_i2s_read_buffer)[i] >> 14;
      }
      bytes_read = bytes_read / 2;
#endif
@github-actions github-actions bot changed the title Clarification of code implementation of audio_provider.cc in the micro_speech example Clarification of code implementation of audio_provider.cc in the micro_speech example (TFMIC-27) Jun 18, 2024
@vikramdattu
Copy link
Collaborator

Hi @mingyr
The capture is happening with 30 bits of data, and hence, I neglect the 14LSB to get 16 bit samples.

You can also set sample size to 16 and use 16 bit data directly.

@mingyr
Copy link
Author

mingyr commented Jun 18, 2024

Dear @vikramdattu, appreciate your explanation.
I would think there might exist some reference which details these technical stuff. It will be immensely helpful if you could please point it out for me (if the reference does exist) and thanks in advance.

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

2 participants