Skip to content

playTone: short tones were silent, long ones lost their end - #2966

Open
p1oner15 wants to merge 1 commit into
BruceDevices:devfrom
p1oner15:fix/tone-short-silent
Open

p1oner15 wants to merge 1 commit into
BruceDevices:devfrom
p1oner15:fix/tone-short-silent

Conversation

@p1oner15

Copy link
Copy Markdown

Proposed Changes

Short tones from playTone() are not heard at all, and longer ones lose their end.

AudioOutputI2S::begin() fills the DMA with silence, and AudioGeneratorWAV stops the output as soon as the last sample is queued, so whatever is still in the DMA never plays. With the default 5 x 576 frames that is 360 ms at the 8 kHz tone rate: tones up to ~360 ms are silent and longer ones are cut by 360 ms. Every blocking call also waits ~70 ms for the first DMA slot.

Changes in src/modules/others/audio.cpp:

  • tones use a small DMA, 3 x 80 frames (30 ms at 8 kHz);
  • the generated wave gets one DMA worth of silence at the end, so the part that gets cut is silence.

Other audio (WAV/MP3 files, RTTTL, TTS) keeps the default DMA size.

Types of Changes

Bugfix

Verification

audio.tone() from a JS script on the T-Embed CC1101 speaker:

  • 30 ms and 150 ms tones: silent before, audible after; 660 Hz read as E5 on a phone tuner (with the frequency fix applied);
  • a blocking audio.tone(880, 10) took ~90 ms before and ~45 ms after (now() around the call).

Testing

Tested on LilyGO T-Embed CC1101 Plus (lilygo-t-embed-cc1101). Not tested on other I2S speaker boards.

Linked Issues

None found.

User-Facing Change

Short speaker beeps (menu clicks, JS audio.tone) are audible now; longer tones no longer lose their last ~360 ms.

Further Comments

Opened together with two other tone fixes (wrong pitch, JS non-blocking flag). The three touch playTone() in different places and each applies to dev on its own.

AudioOutputI2S::begin() fills the DMA with silence, and
AudioGeneratorWAV stops the output as soon as the last sample is
queued, so whatever is still in the DMA never plays. With the default
5 x 576 frames that is 360 ms at the 8 kHz tone rate: tones up to
~360 ms were not heard at all and longer ones were cut by 360 ms.
Every blocking call also waited ~70 ms for the first DMA slot.

Use a 3 x 80 frame DMA for tones (30 ms) and append one DMA worth of
silence to the generated wave, so the part that gets cut is silence.

This branch has not been deployed

No deployments
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

Successfully merging this pull request may close these issues.

1 participant