-
Notifications
You must be signed in to change notification settings - Fork 5
[app_bricks] Add WaveGenerator brick #15
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
Open
BeanRepo
wants to merge
8
commits into
arduino:main
Choose a base branch
from
BeanRepo:pub/wave-generator-brick
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
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
Recent Updates to WaveGenerator BrickThis update refines the WaveGenerator brick's API and improves hardware volume control, along with comprehensive testing and documentation updates. Changes Summary1. External Speaker Instance Support (
|
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.
Wave Generator Brick
A continuous wave generator for real-time audio synthesis. Generates various waveforms (sine, square, sawtooth, triangle) and streams them to a USB speaker with smooth frequency and amplitude transitions.
Features
Usage
Basic Example
Advanced Configuration
Theremin-Style Controller
With WebUI Control
API Reference
Constructor
Parameters:
sample_rate: Audio sample rate in Hz (default: 16000)wave_type: Initial waveform - "sine", "square", "sawtooth", "triangle" (default: "sine")block_duration: Audio block duration in seconds (default: 0.03)attack: Amplitude attack time in seconds (default: 0.01)release: Amplitude release time in seconds (default: 0.03)glide: Frequency glide time (portamento) in seconds (default: 0.02)speaker_device: Speaker device identifier (default: USB_SPEAKER_1)speaker_format: Audio format (default: "FLOAT_LE")Methods
set_frequency(frequency: float)Set target output frequency with smooth glide transition.
Parameters:
frequency: Target frequency in Hz (typically 20-8000 Hz)set_amplitude(amplitude: float)Set target output amplitude with smooth attack/release.
Parameters:
amplitude: Target amplitude in range [0.0, 1.0]set_wave_type(wave_type: WaveType)Change the waveform type.
Parameters:
wave_type: One of "sine", "square", "sawtooth", "triangle"set_volume(volume: float)Set master volume level.
Parameters:
volume: Master volume in range [0.0, 1.0]set_envelope_params(attack=None, release=None, glide=None)Update envelope parameters.
Parameters:
attack: Attack time in seconds (optional)release: Release time in seconds (optional)glide: Frequency glide time in seconds (optional)get_state() -> dictGet current generator state.
Returns:
frequency,amplitude,wave_type,master_volume,phaseWaveform Types
Sine Wave
Classic smooth sine wave, ideal for pure tones and musical applications.
Square Wave
Sharp square wave with odd harmonics, creates a "hollow" or "clarinet-like" sound.
Sawtooth Wave
Bright sawtooth wave with all harmonics, creates a "buzzy" or "brassy" sound.
Triangle Wave
Softer than square, contains only odd harmonics with lower amplitude.
Envelope Parameters
Attack Time
Time to rise from current amplitude to target amplitude when increasing.
Typical values:
0.001- 1ms: Very fast, almost instant0.01- 10ms: Fast, percussive0.1- 100ms: Slow, pad-likeRelease Time
Time to fall from current amplitude to target amplitude when decreasing.
Typical values:
0.01- 10ms: Short decay0.05- 50ms: Medium decay0.5- 500ms: Long decay, reverb-likeGlide Time (Portamento)
Time to smoothly transition from current frequency to target frequency.
Typical values:
0.0- Disabled: Instant frequency changes (may cause clicks)0.005- 5ms: Minimal, just removes clicks0.02- 20ms: Natural, smooth transitions (recommended)0.05- 50ms: Noticeable portamento effect0.1+- 100ms+: Very "slidey", theremin-likeHardware Requirements
Note: Must run in Network Mode or SBC Mode as the USB-C port is needed for the hub.
Troubleshooting
No Sound Output
wave_gen.set_amplitude(0.5)wave_gen.set_volume(0.8)Choppy or Clicking Audio
wave_gen.set_envelope_params(glide=0.05)WaveGenerator(block_duration=0.02)"No USB speaker found" Error