arduino-audio-tools
|
Real-time pitch shifting audio effect. More...
#include <PitchShift.h>
Public Member Functions | |
PitchShiftOutput (Print &out) | |
Constructor. | |
virtual void | addNotifyAudioChange (AudioInfoSupport &bi) |
Adds target to be notified about audio changes. | |
virtual AudioInfo | audioInfo () override |
provides the actual input AudioInfo | |
virtual AudioInfo | audioInfoOut () |
virtual int | availableForWrite () override |
bool | begin () |
Initialize pitch shifting with current configuration. | |
virtual bool | begin (AudioInfo info) |
bool | begin (PitchShiftInfo info) |
Initialize pitch shifting with configuration. | |
virtual void | clearNotifyAudioChange () |
Deletes all change notify subscriptions. | |
PitchShiftInfo | defaultConfig () |
Get default configuration for pitch shifting. | |
void | end () |
Stop pitch shifting and deactivate the effect. | |
virtual void | flush () |
virtual bool | isDeletable () |
If true we need to release the related memory in the destructor. | |
bool | isNotifyActive () |
Checks if the automatic AudioInfo update is active. | |
virtual | operator bool () |
virtual bool | removeNotifyAudioChange (AudioInfoSupport &bi) |
Removes a target in order not to be notified about audio changes. | |
virtual void | setAudioInfo (AudioInfo newInfo) override |
Defines the input AudioInfo. | |
void | setNotifyActive (bool flag) |
Deactivate/Reactivate automatic AudioInfo updates: (default is active) | |
size_t | write (const uint8_t *data, size_t len) override |
Process and write audio data with pitch shifting applied. | |
virtual size_t | write (uint8_t ch) override |
virtual void | writeSilence (size_t len) |
Protected Member Functions | |
void | notifyAudioChange (AudioInfo info) |
T | pitchShift (T value) |
Execute pitch shift on a single sample. | |
Protected Attributes | |
int | _timeout = 10 |
bool | active = false |
Whether pitch shifting is currently active. | |
BufferT | buffer |
Variable speed buffer for pitch shifting. | |
PitchShiftInfo | cfg |
Current configuration. | |
bool | is_active = false |
bool | is_notify_active = true |
Vector< AudioInfoSupport * > | notify_vector |
Print * | p_out = nullptr |
Output stream for processed audio. | |
SingleBuffer< uint8_t > | tmp {MAX_SINGLE_CHARS} |
int | tmpPos = 0 |
Real-time pitch shifting audio effect.
This class implements real-time pitch shifting that changes the frequency of audio without affecting its duration. It can shift pitch up or down while maintaining the original playback speed. The implementation:
The pitch shifting is accomplished using a variable-speed ring buffer that reads at different rates than it writes. Three buffer implementations are available:
T | Sample data type (int16_t, int32_t, float, etc.) |
BufferT | Buffer implementation type (one of the VariableSpeedRingBuffer variants) |
|
inline |
Constructor.
out | Reference to the output stream where processed audio will be written |
|
inlinevirtualinherited |
Adds target to be notified about audio changes.
Reimplemented in CodecNOP, EncodedAudioOutput, EncodedAudioStream, AACDecoderFDK, DecoderBasic, MP3DecoderHelix, MP3DecoderMAD, OggContainerDecoder, Pipeline, and Pipeline::ModifyingStreamAdapter.
|
inlineoverridevirtualinherited |
provides the actual input AudioInfo
Implements AudioInfoSupport.
Reimplemented in AdapterPrintToAudioOutput, and AdapterAudioStreamToAudioOutput.
|
inlinevirtualinherited |
provides the actual output AudioInfo: this is usually the same as audioInfo() unless we use a transforming stream
Reimplemented in PureDataStream, PWMAudioOutput, ChannelFormatConverterStreamT< T >, ChannelFormatConverterStream, NumberFormatConverterStreamT< TFrom, TTo >, NumberFormatConverterStream, FormatConverterStream, Pipeline, ResampleStream, and ResampleStreamT< TInterpolator >.
|
inlineoverridevirtualinherited |
Reimplemented from Print.
Reimplemented in RTSPOutput.
|
inlinevirtual |
Initialize pitch shifting with current configuration.
Reimplemented from AudioOutput.
|
inlinevirtualinherited |
Reimplemented in AudioESP32ULP, CsvOutput< T >, and EncodedAudioOutput.
|
inline |
Initialize pitch shifting with configuration.
info | Configuration containing pitch_shift factor, buffer_size, and audio format |
|
inline |
Get default configuration for pitch shifting.
|
inlinevirtual |
Stop pitch shifting and deactivate the effect.
Reimplemented from AudioOutput.
|
inlinevirtualinherited |
Reimplemented from Print.
|
inlinevirtualinherited |
If true we need to release the related memory in the destructor.
Reimplemented in AdapterPrintToAudioOutput, and AdapterAudioStreamToAudioOutput.
|
inlinevirtualinherited |
Reimplemented in RTSPOutput, and EncodedAudioOutput.
|
inlineprotected |
Execute pitch shift on a single sample.
This method performs the core pitch shifting operation by writing the input sample to the buffer and reading back the pitch-shifted result. The time difference between write and read operations, controlled by the buffer's increment factor, creates the pitch shift effect.
value | Input sample value |
|
inlineoverridevirtualinherited |
Defines the input AudioInfo.
Implements AudioInfoSupport.
Reimplemented in ChannelsSelectOutput, AdapterPrintToAudioOutput, MultiOutput, AdapterAudioStreamToAudioOutput, CsvOutput< T >, PWMAudioOutput, and EncodedAudioOutput.
|
inlineoverridevirtual |
Process and write audio data with pitch shifting applied.
This method processes the input audio by:
data | Pointer to input audio data |
len | Number of bytes to process |
Implements AudioOutput.
|
inlinevirtualinherited |
Writes n 0 values (= silence)
len |