Audacity 3.2.0
|
#include <TimeAndPitch.h>
Classes | |
struct | impl |
Public Types | |
using | ShiftTimbreCb = std::function< void(double factor, std::complex< float > *spectrum, const float *magnitude)> |
Public Member Functions | |
TimeAndPitch (int fftSize, bool reduceImaging=true, ShiftTimbreCb shiftTimbreCb={}) | |
~TimeAndPitch () | |
void | setup (int numChannels, int maxBlockSize) |
void | setTimeStretchAndPitchFactor (double timeStretch, double pitchFactor) |
int | getSamplesToNextHop () const |
int | getNumAvailableOutputSamples () const |
void | feedAudio (const float *const *in_smp, int numSamples) |
void | retrieveAudio (float *const *out_smp, int numSamples) |
void | processPitchShift (float *const *smp, int numSamples, double pitchFactor) |
int | getLatencySamples () const |
int | getLatencySamplesForStretchRatio (float timeStretch) const |
void | reset () |
Private Member Functions | |
void | _process_hop (int hop_a, int hop_s) |
process one hop/chunk in _fft_timeSeries and add the result to output circular buffer More... | |
template<int num_channels> | |
void | _time_stretch (float hop_a, float hop_s) |
void | _applyImagingReduction () |
Private Attributes | |
const int | fftSize |
std::shared_ptr< impl > | d |
const bool | _reduceImaging |
const ShiftTimbreCb | _shiftTimbreCb |
int | _numChannels = 1 |
int | _maxBlockSize = 1024 |
double | _resampleReadPos = 0.0 |
int | _availableOutputSamples = 0 |
int | _numBins = fftSize / 2 + 1 |
double | _overlap_a = overlap |
int | _analysis_hop_counter = 0 |
double | _expectedPhaseChangePerBinPerSample = 0.01 |
double | _timeStretch = 1.0 |
double | _pitchFactor = 1.0 |
int | _outBufferWriteOffset = 0 |
Static Private Attributes | |
static constexpr int | overlap = 4 |
static constexpr bool | normalize_window = true |
static constexpr bool | modulate_synthesis_hop = true |
Definition at line 13 of file TimeAndPitch.h.
using staffpad::TimeAndPitch::ShiftTimbreCb = std::function<void( double factor, std::complex<float>* spectrum, const float* magnitude)> |
magnitude
may be null, in which case the callback should re-compute it.
Definition at line 19 of file TimeAndPitch.h.
staffpad::TimeAndPitch::TimeAndPitch | ( | int | fftSize, |
bool | reduceImaging = true , |
||
ShiftTimbreCb | shiftTimbreCb = {} |
||
) |
Definition at line 90 of file TimeAndPitch.cpp.
staffpad::TimeAndPitch::~TimeAndPitch | ( | ) |
Definition at line 98 of file TimeAndPitch.cpp.
|
private |
Definition at line 342 of file TimeAndPitch.cpp.
References _numBins, _pitchFactor, d, fftSize, and staffpad::vo::rotate().
Referenced by _process_hop().
|
private |
process one hop/chunk in _fft_timeSeries and add the result to output circular buffer
Definition at line 371 of file TimeAndPitch.cpp.
References _applyImagingReduction(), _availableOutputSamples, staffpad::anonymous_namespace{TimeAndPitch.cpp}::_fft_shift(), staffpad::anonymous_namespace{TimeAndPitch.cpp}::_lr_to_ms(), staffpad::anonymous_namespace{TimeAndPitch.cpp}::_ms_to_lr(), _numBins, _numChannels, _outBufferWriteOffset, _overlap_a, _pitchFactor, _reduceImaging, _shiftTimbreCb, _timeStretch, staffpad::anonymous_namespace{TimeAndPitch.cpp}::_unwrapPhaseVec(), staffpad::vo::calcNorms(), staffpad::vo::calcPhases(), staffpad::vo::constantMultiply(), d, fftSize, staffpad::vo::multiply(), normalize_window, and staffpad::vo::rotate().
Referenced by feedAudio().
|
private |
Definition at line 239 of file TimeAndPitch.cpp.
References _expectedPhaseChangePerBinPerSample, _numBins, staffpad::anonymous_namespace{TimeAndPitch.cpp}::_unwrapPhase(), d, staffpad::vo::findMaxElement(), and fn.
void staffpad::TimeAndPitch::feedAudio | ( | const float *const * | in_smp, |
int | numSamples | ||
) |
Feed more input samples.
getSamplesToNextHop()
to know how much to feed to produce more output samples. Definition at line 472 of file TimeAndPitch.cpp.
References _analysis_hop_counter, _maxBlockSize, _numChannels, _pitchFactor, _process_hop(), _resampleReadPos, d, fftSize, and staffpad::anonymous_namespace{TimeAndPitch.cpp}::lagrange6().
Referenced by processPitchShift().
int staffpad::TimeAndPitch::getLatencySamples | ( | ) | const |
Latency in input samples
Definition at line 558 of file TimeAndPitch.cpp.
References fftSize, and overlap.
Referenced by getLatencySamplesForStretchRatio().
int staffpad::TimeAndPitch::getLatencySamplesForStretchRatio | ( | float | timeStretch | ) | const |
Latency in output samples, calculated on the given timeStretch factor
Definition at line 564 of file TimeAndPitch.cpp.
References getLatencySamples().
int staffpad::TimeAndPitch::getNumAvailableOutputSamples | ( | ) | const |
Tells the number of already processed output samples (after time-stretching) that are ready for consumption.
Definition at line 164 of file TimeAndPitch.cpp.
References _availableOutputSamples.
int staffpad::TimeAndPitch::getSamplesToNextHop | ( | ) | const |
Return the ~number of samples until the next hop gets analysed (might be 1 or 2 too high). For extremely small stretch ratios, several analyses might be needed to produce samples, so you may have to repeat the process. Eventually, more output samples are produced.
Definition at line 158 of file TimeAndPitch.cpp.
References _analysis_hop_counter, and d.
void staffpad::TimeAndPitch::processPitchShift | ( | float *const * | smp, |
int | numSamples, | ||
double | pitchFactor | ||
) |
Pitch-shift only in-place processing.
Definition at line 551 of file TimeAndPitch.cpp.
References feedAudio(), retrieveAudio(), and setTimeStretchAndPitchFactor().
void staffpad::TimeAndPitch::reset | ( | ) |
Resets the internal state, discards any buffered input
Definition at line 169 of file TimeAndPitch.cpp.
References _analysis_hop_counter, _availableOutputSamples, _numChannels, _outBufferWriteOffset, _resampleReadPos, and d.
Referenced by setup().
void staffpad::TimeAndPitch::retrieveAudio | ( | float *const * | out_smp, |
int | numSamples | ||
) |
Retrieved shifted/stretched samples in output.
getNumAvailableOutputSamples()
to ask a valid amount of numSamples
. Definition at line 522 of file TimeAndPitch.cpp.
References _availableOutputSamples, _maxBlockSize, _numChannels, _outBufferWriteOffset, d, modulate_synthesis_hop, and normalize_window.
Referenced by processPitchShift().
void staffpad::TimeAndPitch::setTimeStretchAndPitchFactor | ( | double | timeStretch, |
double | pitchFactor | ||
) |
Set independent time stretch and pitch factors (synchronously to processing thread). The factor change resolution follows the processing block size, with some approximation. As a general rule, smaller block sizes result in finer changes, although there's a lower bound due to internal windowed segmentation and OLA resynthesis.
Definition at line 444 of file TimeAndPitch.cpp.
References _overlap_a, _pitchFactor, _timeStretch, d, fftSize, modulate_synthesis_hop, and overlap.
Referenced by processPitchShift().
void staffpad::TimeAndPitch::setup | ( | int | numChannels, |
int | maxBlockSize | ||
) |
Setup at least once before processing.
numChannels | Must be 1 or 2 |
maxBlockSize | The caller's maximum block size, e.g. 1024 samples |
Definition at line 103 of file TimeAndPitch.cpp.
References _expectedPhaseChangePerBinPerSample, _maxBlockSize, _numBins, _numChannels, d, fftSize, staffpad::anonymous_namespace{TimeAndPitch.cpp}::generateRandomPhaseVector(), anonymous_namespace{StaffPadTimeAndPitch.cpp}::maxBlockSize, reset(), and staffpad::anonymous_namespace{TimeAndPitch.cpp}::twoPi.
|
private |
Definition at line 110 of file TimeAndPitch.h.
Referenced by feedAudio(), getSamplesToNextHop(), and reset().
|
private |
Definition at line 106 of file TimeAndPitch.h.
Referenced by _process_hop(), getNumAvailableOutputSamples(), reset(), and retrieveAudio().
|
private |
Definition at line 112 of file TimeAndPitch.h.
Referenced by _time_stretch(), and setup().
|
private |
Definition at line 104 of file TimeAndPitch.h.
Referenced by feedAudio(), retrieveAudio(), and setup().
|
private |
Definition at line 107 of file TimeAndPitch.h.
Referenced by _applyImagingReduction(), _process_hop(), _time_stretch(), and setup().
|
private |
Definition at line 103 of file TimeAndPitch.h.
Referenced by _process_hop(), feedAudio(), reset(), retrieveAudio(), and setup().
|
private |
Definition at line 116 of file TimeAndPitch.h.
Referenced by _process_hop(), reset(), and retrieveAudio().
|
private |
Definition at line 108 of file TimeAndPitch.h.
Referenced by _process_hop(), and setTimeStretchAndPitchFactor().
|
private |
Definition at line 114 of file TimeAndPitch.h.
Referenced by _applyImagingReduction(), _process_hop(), feedAudio(), and setTimeStretchAndPitchFactor().
|
private |
Definition at line 100 of file TimeAndPitch.h.
Referenced by _process_hop().
|
private |
Definition at line 105 of file TimeAndPitch.h.
Referenced by feedAudio(), and reset().
|
private |
Definition at line 101 of file TimeAndPitch.h.
Referenced by _process_hop().
|
private |
Definition at line 113 of file TimeAndPitch.h.
Referenced by _process_hop(), and setTimeStretchAndPitchFactor().
|
private |
Definition at line 98 of file TimeAndPitch.h.
Referenced by _applyImagingReduction(), _process_hop(), _time_stretch(), feedAudio(), getSamplesToNextHop(), reset(), retrieveAudio(), setTimeStretchAndPitchFactor(), and setup().
|
private |
Definition at line 87 of file TimeAndPitch.h.
Referenced by _applyImagingReduction(), _process_hop(), feedAudio(), getLatencySamples(), setTimeStretchAndPitchFactor(), and setup().
|
staticconstexprprivate |
Definition at line 90 of file TimeAndPitch.h.
Referenced by retrieveAudio(), and setTimeStretchAndPitchFactor().
|
staticconstexprprivate |
Definition at line 89 of file TimeAndPitch.h.
Referenced by _process_hop(), and retrieveAudio().
|
staticconstexprprivate |
Definition at line 88 of file TimeAndPitch.h.
Referenced by getLatencySamples(), and setTimeStretchAndPitchFactor().