|
arduino-audio-tools
|
Sine wave generator that does not use any floating point operations in the readSample() hot path: it advances a 32 bit phase accumulator with an integer increment and looks up the result in a Q15 fixed point table. All floating point math (converting frequency/sample_rate into the phase increment) is done once in setFrequency()/setAudioInfo(), never per sample. This makes it a good fit for MCUs without a hardware FPU - e.g. the RP2040 - where sinf() is comparatively expensive. More...
#include <SoundGenerator.h>
Public Member Functions | |
| FastIntSineGenerator (float amplitude=NumberConverter::maxValueT< T >(), float phase=0.0f) | |
| virtual AudioInfo | audioInfo () |
| Provides the AudioInfo. | |
| bool | begin () override |
| Starts the processing. | |
| bool | begin (AudioInfo info) override |
| Starts the processing with the provided AudioInfo. | |
| bool | begin (AudioInfo info, float frequency) |
| bool | begin (int channels, int sample_rate, float frequency) |
| virtual AudioInfo | defaultConfig () |
| Provides the default configuration. | |
| virtual void | end () |
| Ends the processing. | |
| virtual bool | isActive () |
| Checks if the begin method has been called - after end() isActive is false. | |
| virtual size_t | readBytes (uint8_t *data, size_t len) |
| Provides the data as byte array with the requested number of channels. | |
| virtual T | readSample () override |
| Provides a single sample - integer only, no float ops or sin() calls! | |
| void | setAmplitude (float amp) |
| virtual void | setAudioInfo (AudioInfo info) override |
| Defines/updates the AudioInfo. | |
| void | setFrequency (float frequency) override |
| Defines the frequency - the only place where float math is used. | |
| void | setPhase (float phase) |
| Defines the starting phase in radians. | |
| void | setPlayTime (uint32_t playMs, uint8_t upPercent=20, uint8_t downPercent=30) |
| Defines the play time in ms and the ramp up and ramp down time in percent. | |
Protected Member Functions | |
| T | applyRamp (T sample) |
| size_t | readBytesFrames (uint8_t *buffer, size_t lengthBytes, int frames, int channels) |
| size_t | readBytesFromBuffer (uint8_t *buffer, size_t lengthBytes, int frame_size, int channels) |
| void | recalculatePlayTime () |
| void | updatePhaseIncrement () |
Protected Attributes | |
| bool | active = false |
| bool | activeWarningIssued = false |
| uint32_t | currentSample = 0 |
| uint8_t | downPercent = 40 |
| float | factor = 1.0f |
| AudioInfo | info |
| float | m_amplitude = 1.0f |
| int32_t | m_amplitude_i = 32767 |
| volatile float | m_frequency = 0.0f |
| uint32_t | m_phase_acc = 0 |
| uint32_t | m_phase_increment = 0 |
| uint32_t | m_phase_offset = 0 |
| uint32_t | playMs = 0 |
| uint32_t | playSamples = 0 |
| float | rampDownDec = 0.0 |
| uint32_t | rampDownSamples = 0 |
| float | rampUpInc = 0.0 |
| RingBuffer< uint8_t > | ring_buffer {0} |
| uint8_t | upPercent = 5 |
| uint32_t | upSamples = 0 |
Static Protected Attributes | |
| static const int | kIndexShift = 32 - kTableBits |
| static const int | kTableBits = 8 |
| static const int | kTableSize = 1 << kTableBits |
| static constexpr int16_t | sine_table [kTableSize] |
Sine wave generator that does not use any floating point operations in the readSample() hot path: it advances a 32 bit phase accumulator with an integer increment and looks up the result in a Q15 fixed point table. All floating point math (converting frequency/sample_rate into the phase increment) is done once in setFrequency()/setAudioInfo(), never per sample. This makes it a good fit for MCUs without a hardware FPU - e.g. the RP2040 - where sinf() is comparatively expensive.
| T |
|
inline |
|
inlineprotectedinherited |
|
inlinevirtualinherited |
Provides the AudioInfo.
|
inlineoverridevirtual |
Starts the processing.
Reimplemented from SoundGenerator< T >.
|
inlineoverridevirtual |
Starts the processing with the provided AudioInfo.
Reimplemented from SoundGenerator< T >.
|
inline |
|
inline |
|
inlinevirtualinherited |
Provides the default configuration.
Reimplemented in STKGenerator< StkCls, T >, STKGenerator< stk::Instrmnt, int16_t >, STKGenerator< StkCls, int16_t >, SineGenerator< T >, and SineGenerator< int16_t >.
|
inlinevirtualinherited |
Ends the processing.
Reimplemented in GeneratorFromArray< T >.
|
inlinevirtualinherited |
Checks if the begin method has been called - after end() isActive is false.
|
inlinevirtualinherited |
Provides the data as byte array with the requested number of channels.
|
inlineprotectedinherited |
|
inlineprotectedinherited |
|
inlineoverridevirtual |
Provides a single sample - integer only, no float ops or sin() calls!
Implements SoundGenerator< T >.
|
inlineprotectedinherited |
|
inline |
|
inlineoverridevirtual |
Defines/updates the AudioInfo.
Reimplemented from SoundGenerator< T >.
|
inlineoverridevirtual |
Defines the frequency - the only place where float math is used.
Reimplemented from SoundGenerator< T >.
|
inline |
Defines the starting phase in radians.
|
inlineinherited |
Defines the play time in ms and the ramp up and ramp down time in percent.
|
inlineprotected |
|
protectedinherited |
|
protectedinherited |
|
protectedinherited |
|
protectedinherited |
|
protectedinherited |
|
protectedinherited |
|
staticprotected |
|
staticprotected |
|
staticprotected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protectedinherited |
|
protectedinherited |
|
protectedinherited |
|
protectedinherited |
|
protectedinherited |
|
protectedinherited |
|
staticconstexprprotected |
|
protectedinherited |
|
protectedinherited |