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

I2S wrong bclk for internal DAC (IDFGH-6697) #8326

Closed
3 tasks
s-hadinger opened this issue Jan 31, 2022 · 1 comment
Closed
3 tasks

I2S wrong bclk for internal DAC (IDFGH-6697) #8326

s-hadinger opened this issue Jan 31, 2022 · 1 comment
Assignees
Labels
Resolution: Done Issue is done internally Status: Done Issue is done internally

Comments

@s-hadinger
Copy link
Contributor

Environment

  • Development Kit: [M5StickC]
  • Module or chip used: [ESP32-PICO-D4]
  • IDF version [4.4]
  • Build System: [Pio]
  • Compiler version toolchain-xtensa-esp32 8.4.0+2021r2-patch2
  • Operating System: [macOS]
  • Using an IDE?: [PlatformIO]
  • Power Supply: [USB]

Problem Description

When using I2S with internal DAC, 2 channels, 16000 frames/sec, the sound emitted is a short swaks and DMA buffers are emptied far too fast compared to regular I2S audio with external chip.

Problem is largely described in espressif/arduino-esp32#5938

Expected Behavior

The original PCM sound is the following and lasts over 660ms:

151602386-8ca194e2-ea6a-466b-8a92-b9760f4d027e

Actual Behavior

Recording the output with a scope shows a correct waveform but played 11x faster than normal speed.
151602460-e7997b68-d8c1-40fb-9442-6978bf8e68c0

I did a detour on i2s_hal_tx_clock_config() to check what clock values were calculated, and force-injected some different clock values until the sound was good again.

With the previous setting: 16KHz, 2 channels, internal DAC. IDF calculates the following clock:
sclk=160000000 mclk=128000 bclk=64000 mclk_div=1250 bclk_div=2

Although the number seem correct, mclk_div hardware is only 8 bits, so 1250 is overflowing.

Injecting my own calculated value, I made it work at correct speed with:
sclk=160000000 mclk=1024000 bclk=32000 mclk_div=156 bclk_div=32

Having a combined mclk_div=156 bclk_div=32 achieves a divider of ~5000 over sclk.

I suppose that an easy patch would be to set bclk_div=32 instead of bclk_div=2 and it should allow for all audio frequencies.

Steps to reproduce

Code to reproduce this issue

Debug Logs

Other items if possible

  • sdkconfig file (attach the sdkconfig file from your project folder)
  • elf file in the build folder (note this may contain all the code details and symbols of your project.)
  • coredump (This provides stacks of tasks.)
@espressif-bot espressif-bot added the Status: Opened Issue is new label Jan 31, 2022
@github-actions github-actions bot changed the title I2S wrong bclk for internal DAC I2S wrong bclk for internal DAC (IDFGH-6697) Jan 31, 2022
s-hadinger added a commit to s-hadinger/esp-idf that referenced this issue Jan 31, 2022
espressif-bot pushed a commit that referenced this issue Mar 3, 2022
espressif-bot pushed a commit that referenced this issue Mar 3, 2022
@Alvin1Zhang
Copy link
Collaborator

Thanks for reporting and sharing the updates, fix is available at 19f4eca, feel free to reopen.

@espressif-bot espressif-bot added Resolution: Done Issue is done internally Status: Done Issue is done internally and removed Status: Opened Issue is new labels Mar 8, 2022
cfint pushed a commit to cfint/esp-idf that referenced this issue Mar 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution: Done Issue is done internally Status: Done Issue is done internally
Projects
None yet
Development

No branches or pull requests

4 participants