Audacity 3.2.0
Functions | Variables
anonymous_namespace{StaffPadTimeAndPitch.cpp} Namespace Reference

Functions

void GetOffsetBuffer (float **offsetBuffer, float *const *buffer, size_t numChannels, size_t offset)
 
int GetFftSize (int sampleRate, bool formantPreservationOn)
 
std::unique_ptr< staffpad::TimeAndPitchCreateTimeAndPitch (int sampleRate, size_t numChannels, const TimeAndPitchInterface::Parameters &params, FormantShifter &shifter)
 
std::unique_ptr< FormantShifterLoggerInterfaceGetFormantShifterLogger (int sampleRate)
 

Variables

constexpr auto maxBlockSize = 1024
 

Function Documentation

◆ CreateTimeAndPitch()

std::unique_ptr< staffpad::TimeAndPitch > anonymous_namespace{StaffPadTimeAndPitch.cpp}::CreateTimeAndPitch ( int  sampleRate,
size_t  numChannels,
const TimeAndPitchInterface::Parameters params,
FormantShifter shifter 
)

Definition at line 44 of file StaffPadTimeAndPitch.cpp.

47{
48 const auto fftSize = GetFftSize(sampleRate, params.preserveFormants);
49 auto shiftTimbreCb = params.preserveFormants && params.pitchRatio != 1. ?
50 [&](
51 double factor, std::complex<float>* spectrum,
52 const float* magnitude) {
53 shifter.Process(magnitude, spectrum, factor);
54 } :
56 auto timeAndPitch = std::make_unique<staffpad::TimeAndPitch>(
57 fftSize,
59 true),
60 std::move(shiftTimbreCb));
61
62 timeAndPitch->setup(static_cast<int>(numChannels), maxBlockSize);
63 timeAndPitch->setTimeStretchAndPitchFactor(
64 params.timeRatio, params.pitchRatio);
65
66 return timeAndPitch;
67}
EffectDistortionSettings params
Definition: Distortion.cpp:77
void Process(const float *powerSpectrum, std::complex< float > *spectrum, double factor)
Processes spectrum in place, or does nothing if Reset(fftSize) wasn't called or Reset() was called si...
std::function< void(double factor, std::complex< float > *spectrum, const float *magnitude)> ShiftTimbreCb
Definition: TimeAndPitch.h:20
int GetFftSize(int sampleRate, bool formantPreservationOn)

References GetFftSize(), TimeAndPitchExperimentalSettings::GetReduceImagingOverride(), maxBlockSize, params, FormantShifter::Process(), and anonymous_namespace{ClipSegmentTest.cpp}::sampleRate.

Referenced by StaffPadTimeAndPitch::InitializeStretcher().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetFftSize()

int anonymous_namespace{StaffPadTimeAndPitch.cpp}::GetFftSize ( int  sampleRate,
bool  formantPreservationOn 
)

Definition at line 25 of file StaffPadTimeAndPitch.cpp.

26{
27 if (
28 const auto fftSize =
30 return *fftSize;
31
32 // 44.1kHz maps to 4096 samples (i.e., 93ms) without formant preservation,
33 // and 2048 with.
34 // We grow the FFT size proportionally with the sample rate to keep the
35 // window duration roughly constant, with quantization due to the
36 // power-of-two constraint.
37 // If needed some time in the future, we can decouple analysis window and
38 // FFT sizes by zero-padding, allowing for very fine-grained window duration
39 // without compromising performance.
40 return 1 << (formantPreservationOn ? 11 : 12) +
41 (int)std::round(std::log2(sampleRate / 44100.));
42}
fastfloat_really_inline void round(adjusted_mantissa &am, callback cb) noexcept
Definition: fast_float.h:2512

References TimeAndPitchExperimentalSettings::GetFftSizeOverride(), fast_float::round(), and anonymous_namespace{ClipSegmentTest.cpp}::sampleRate.

Referenced by CreateTimeAndPitch(), StaffPadTimeAndPitch::OnFormantPreservationChange(), and StaffPadTimeAndPitch::StaffPadTimeAndPitch().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetFormantShifterLogger()

std::unique_ptr< FormantShifterLoggerInterface > anonymous_namespace{StaffPadTimeAndPitch.cpp}::GetFormantShifterLogger ( int  sampleRate)

Definition at line 70 of file StaffPadTimeAndPitch.cpp.

71{
72 if (
73 const auto logSample =
75 return std::make_unique<FormantShifterLogger>(sampleRate, *logSample);
76 return std::make_unique<DummyFormantShifterLogger>();
77}
std::optional< int > GetLogSample(int sampleRate)

References TimeAndPitchExperimentalSettings::GetLogSample(), and anonymous_namespace{ClipSegmentTest.cpp}::sampleRate.

Here is the call graph for this function:

◆ GetOffsetBuffer()

void anonymous_namespace{StaffPadTimeAndPitch.cpp}::GetOffsetBuffer ( float **  offsetBuffer,
float *const *  buffer,
size_t  numChannels,
size_t  offset 
)

Definition at line 17 of file StaffPadTimeAndPitch.cpp.

20{
21 for (auto i = 0u; i < numChannels; ++i)
22 offsetBuffer[i] = buffer[i] + offset;
23}

Referenced by StaffPadTimeAndPitch::GetSamples().

Here is the caller graph for this function:

Variable Documentation

◆ maxBlockSize

constexpr auto anonymous_namespace{StaffPadTimeAndPitch.cpp}::maxBlockSize = 1024
constexpr