18 float** offsetBuffer,
float*
const* buffer,
size_t numChannels,
21 for (
auto i = 0u; i < numChannels; ++i)
22 offsetBuffer[i] = buffer[i] + offset;
40 return 1 << (formantPreservationOn ? 11 : 12) +
49 auto shiftTimbreCb =
params.preserveFormants &&
params.pitchRatio != 1. ?
51 double factor, std::complex<float>* spectrum,
52 const float* magnitude) {
53 shifter.
Process(magnitude, spectrum, factor);
56 auto timeAndPitch = std::make_unique<staffpad::TimeAndPitch>(
60 std::move(shiftTimbreCb));
62 timeAndPitch->setup(
static_cast<int>(numChannels),
maxBlockSize);
63 timeAndPitch->setTimeStretchAndPitchFactor(
69std::unique_ptr<FormantShifterLoggerInterface>
73 const auto logSample =
75 return std::make_unique<FormantShifterLogger>(
sampleRate, *logSample);
76 return std::make_unique<DummyFormantShifterLogger>();
84 , mParameters(parameters)
90 *mFormantShifterLogger)
91 , mAudioSource(audioSource)
93 , mNumChannels(numChannels)
112 auto numOutputSamples = 0u;
113 while (numOutputSamples < outputLen)
119 output[i] + numOutputSamples, outputLen - numOutputSamples, 0.f);
122 auto numOutputSamplesAvailable =
124 while (numOutputSamplesAvailable <= 0)
127 while (numRequired > 0)
133 numRequired -= numSamplesToFeed;
135 numOutputSamplesAvailable =
138 while (numOutputSamples < outputLen && numOutputSamplesAvailable > 0)
140 const auto numSamplesToGet =
142 static_cast<int>(outputLen - numOutputSamples) });
148 numOutputSamplesAvailable -= numSamplesToGet;
149 numOutputSamples += numSamplesToGet;
182 auto numOutputSamplesToDiscard =
186 while (numOutputSamplesToDiscard > 0)
191 while (numRequired > 0)
196 numRequired -= numSamplesToFeed;
198 const auto totalNumSamplesToRetrieve =
std::min(
200 numOutputSamplesToDiscard);
201 auto totalNumRetrievedSamples = 0;
202 while (totalNumRetrievedSamples < totalNumSamplesToRetrieve)
204 const auto numSamplesToRetrieve =
std::min(
205 maxBlockSize, totalNumSamplesToRetrieve - totalNumRetrievedSamples);
207 totalNumRetrievedSamples += numSamplesToRetrieve;
209 numOutputSamplesToDiscard -= totalNumSamplesToRetrieve;
EffectDistortionSettings params
void OnFormantPreservationChange(bool preserve) override
FormantShifter mFormantShifter
StaffPadTimeAndPitch(int sampleRate, size_t numChannels, TimeAndPitchSource &, const Parameters &)
const std::unique_ptr< FormantShifterLoggerInterface > mFormantShifterLogger
TimeAndPitchSource & mAudioSource
void OnCentShiftChange(int cents) override
TimeAndPitchInterface::Parameters mParameters
void GetSamples(float *const *, size_t) override
const size_t mNumChannels
std::unique_ptr< staffpad::TimeAndPitch > mTimeAndPitch
AudioContainer mReadBuffer
void InitializeStretcher()
static bool IsPassThroughMode(double stretchRatio)
virtual void Pull(float *const *, size_t samplesPerChannel)=0
std::function< void(double factor, std::complex< float > *spectrum, const float *magnitude)> ShiftTimbreCb
std::optional< int > GetLogSample(int sampleRate)
std::optional< bool > GetReduceImagingOverride()
std::optional< double > GetCutoffQuefrencyOverride()
std::optional< int > GetFftSizeOverride()
constexpr auto sampleRate
std::unique_ptr< staffpad::TimeAndPitch > CreateTimeAndPitch(int sampleRate, size_t numChannels, const TimeAndPitchInterface::Parameters ¶ms, FormantShifter &shifter)
int GetFftSize(int sampleRate, bool formantPreservationOn)
constexpr auto maxBlockSize
void GetOffsetBuffer(float **offsetBuffer, float *const *buffer, size_t numChannels, size_t offset)
std::unique_ptr< FormantShifterLoggerInterface > GetFormantShifterLogger(int sampleRate)
fastfloat_really_inline void round(adjusted_mantissa &am, callback cb) noexcept
float *const * Get() const