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

Reduce popping during audio initialization using the additive DAC #21642

Merged
merged 3 commits into from
Sep 25, 2023

Conversation

Nebuleon
Copy link
Contributor

@Nebuleon Nebuleon commented Jul 30, 2023

Description

The previous DAC initialization code caused two pops if AUDIO_DAC_OFF_VALUE was not 0 because the buffer sent to the DAC had one AUDIO_DAC_OFF_VALUE then the rest 0 before leaving the DAC again at AUDIO_DAC_OFF_VALUE:

static dacsample_t dac_buffer_empty[AUDIO_DAC_BUFFER_SIZE] = {AUDIO_DAC_OFF_VALUE}; /* other elements get initialized to 0 */

This commit corrects the initialization and eliminates this source of popping.

Types of Changes

  • Core
  • Bugfix
  • New feature
  • Enhancement/optimization
  • Keyboard (addition or update)
  • Keymap/layout/userspace (addition or update)
  • Documentation

Checklist

  • My code follows the code style of this project: C, Python
  • I have read the PR Checklist document and have made the appropriate changes.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • I have tested the changes and verified that they work and don't break anything (as well as I can manage).

The previous DAC initialization code caused two pops if `AUDIO_DAC_OFF_VALUE` was not 0 because the buffer sent to the DAC had one `AUDIO_DAC_OFF_VALUE` then the rest 0 before leaving the DAC again at `AUDIO_DAC_OFF_VALUE`:

```c
static dacsample_t dac_buffer_empty[AUDIO_DAC_BUFFER_SIZE] = {AUDIO_DAC_OFF_VALUE}; /* other elements get initialized to 0 */
```

This commit corrects the initialization and eliminates this source of popping.
@github-actions github-actions bot added the core label Jul 30, 2023
@drashna drashna requested a review from a team August 2, 2023 05:51
@Nebuleon Nebuleon marked this pull request as draft August 2, 2023 23:40
@Nebuleon
Copy link
Contributor Author

Nebuleon commented Aug 2, 2023

I've gone and marked this as a draft because, while investigating why that empty buffer wasn't marked const, I found out that that buffer is also what gets used when the DAC is emitting samples. I'll review the whole initialization, because the way this code is written, there might be some shenanigans with stale data going on.

@Nebuleon
Copy link
Contributor Author

Nebuleon commented Aug 3, 2023

Alright, now that's much better. I've made it so that the "empty" buffer, which is also used throughout the keyboard's runtime, is called dac_buffer rather than dac_buffer_empty, and moved its initialization such that, instead of being in .data, copied from flash into RAM, it's filled with AUDIO_DAC_OFF_VALUE whenever audio_driver_initialize gets called, so if for any reason the audio needs to be reinitialized, it will get a new empty buffer again. All the while taking 512 (AUDIO_DAC_BUFFER_SIZE * sizeof(dacsample_t)) fewer bytes of data and a few more bytes of code in flash to regenerate the whole thing. The RAM usage stays the same.

@Nebuleon Nebuleon marked this pull request as ready for review August 3, 2023 06:21
@tzarc tzarc merged commit 2f4e1a7 into qmk:develop Sep 25, 2023
mechlovin pushed a commit to mechlovin/qmk_firmware that referenced this pull request Oct 25, 2023
christrotter pushed a commit to christrotter/qmk_firmware that referenced this pull request Nov 28, 2023
zgagnon pushed a commit to zgagnon/qmk_firmware_waterfowl that referenced this pull request Dec 15, 2023
future-figs pushed a commit to future-figs/qmk_firmware that referenced this pull request Dec 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants