Open
Conversation
Passive buzzers have a resonant frequency sweet spot well above the standard RTTTL note range (200-800Hz). Previously users had to create a custom setToneFunction wrapper to shift frequencies, which is boilerplate that every buzzer user ends up writing. This adds an octaveShift property to rtttl_context_t that shifts all note frequencies up or down by N octaves before calling tone(). Default is 0 (no shift), so existing behavior is fully preserved. API: - anyrtttl::setOctaveShift(N) for the global context - anyrtttl::setOctaveShift(context, N) for a specific context
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
octaveShiftproperty tortttl_context_tthat shifts all note frequencies up or down by N octaves before callingtone()setToneFunctionwrapper just to shift pitch for passive buzzersMotivation
Passive buzzers have a resonant frequency sweet spot (often 2500Hz+), but RTTTL melodies are written for the standard musical range (200-800Hz). Currently the only way to shift frequencies is to override
setToneFunctionwith a wrapper that multiplies the frequency before passing it totone(). This is boilerplate that every passive buzzer user ends up writing.API
Changes
src/anyrtttl.h: Addedint8_t octaveShiftfield tortttl_context_t, addedsetOctaveShift()declarationssrc/anyrtttl.cpp: Implemented setter, initialized field ininitContext(), applied shift at frequency lookup innextNote(), preserved shift acrossbegin()callsexamples/OctaveShift/OctaveShift.ino: Example showing normal vs shifted playbackREADME.md: Documentation section with usage exampleCHANGES: Entry for v2.7.0Test plan
setToneFunctionwrapper behavior