Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/describe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ int main(int argc, char* argv[])
STFT stft{windowSize, fftSize, hopSize};
MelBands bands{nBands, fftSize};
DCT dct{nBands, nCoefs};
YINFFT yin;
YINFFT yin{nBins, FluidDefaultAllocator()};
SpectralShape shape(FluidDefaultAllocator());
Loudness loudness{windowSize};
MultiStats stats;
Expand Down
12 changes: 10 additions & 2 deletions include/algorithms/public/YINFFT.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ class YINFFT
{

public:

YINFFT(index maxInputSize, Allocator& alloc = FluidDefaultAllocator())
: mFFT(2 * maxInputSize - 1, alloc)
{}

void processFrame(const RealVectorView& input, RealVectorView output,
double minFreq, double maxFreq, double sampleRate,
Allocator& alloc = FluidDefaultAllocator())
Expand All @@ -36,14 +41,15 @@ class YINFFT
squareMag = _impl::asEigen<Array>(input).square();

index nBins = input.size();
FFT fft(2 * (input.size() - 1));
double squareMagSum = 2 * squareMag.sum();

mFFT.resize(2 * (nBins - 1));

ScopedEigenMap<ArrayXd> squareMagSym(2 * (nBins - 1), alloc);
squareMagSym << squareMag[0], squareMag.segment(1, nBins - 1),
squareMag.segment(1, nBins - 2).reverse();

Eigen::Map<ArrayXcd> squareMagFFT = fft.process(squareMagSym);
Eigen::Map<ArrayXcd> squareMagFFT = mFFT.process(squareMagSym);
ScopedEigenMap<ArrayXd> yin(squareMagFFT.size(), alloc);
yin = squareMagSum - squareMagFFT.real();

Expand Down Expand Up @@ -83,6 +89,8 @@ class YINFFT
output(0) = pitch;
output(1) = pitchConfidence;
}

FFT mFFT;
};
} // namespace algorithm
} // namespace fluid
1 change: 1 addition & 0 deletions include/clients/rt/NoveltyFeatureClient.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class NoveltyFeatureClient : public FluidBaseClient,
mMelBands{40, get<kFFT>().max(), c.allocator()},
mDCT{40, 13, c.allocator()},
mChroma{12, get<kFFT>().max(), c.allocator()},
mYinFFT(get<kFFT>().maxFrameSize(), c.allocator()),
mLoudness{get<kFFT>().max(), c.allocator()}
{
audioChannelsIn(1);
Expand Down
4 changes: 2 additions & 2 deletions include/clients/rt/NoveltySliceClient.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ class NoveltySliceClient : public FluidBaseClient,
c.allocator()},
mChroma{12, get<kFFT>().max(), c.allocator()}, mLoudness{
get<kFFT>().max(),
c.allocator()}

c.allocator()},
mYinFFT(get<kFFT>().maxFrameSize(), c.allocator())
{
audioChannelsIn(1);
audioChannelsOut(1);
Expand Down
19 changes: 10 additions & 9 deletions include/clients/rt/PitchClient.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ class PitchClient : public FluidBaseClient, public AudioIn, public ControlOut

PitchClient(ParamSetViewType& p, FluidContext& c)
: mParams(p), mSTFTBufferedProcess(get<kFFT>(), 1, 0, c.hostVectorSize(), c.allocator()),
cepstrumF0(get<kFFT>().maxFrameSize(), c.allocator()),
mCepstrumF0(get<kFFT>().maxFrameSize(), c.allocator()),
mYinFFT(get<kFFT>().maxFrameSize(), c.allocator()),
mMagnitude(get<kFFT>().maxFrameSize(), c.allocator()),
mDescriptors(2, c.allocator())
{
Expand All @@ -99,7 +100,7 @@ class PitchClient : public FluidBaseClient, public AudioIn, public ControlOut

if (mParamTracker.changed(get<kFFT>().frameSize(), sampleRate(), c.hostVectorSize()))
{
cepstrumF0.init(get<kFFT>().frameSize(), c.allocator());
mCepstrumF0.init(get<kFFT>().frameSize(), c.allocator());
mSTFTBufferedProcess = STFTBufferedProcess(get<kFFT>(), 1, 0, c.hostVectorSize(), c.allocator());
// mMagnitude.resize(get<kFFT>().frameSize());
}
Expand All @@ -112,15 +113,15 @@ class PitchClient : public FluidBaseClient, public AudioIn, public ControlOut
switch (get<kAlgorithm>())
{
case 0:
cepstrumF0.processFrame(mags, mDescriptors, get<kMinFreq>(),
mCepstrumF0.processFrame(mags, mDescriptors, get<kMinFreq>(),
get<kMaxFreq>(), sampleRate(),c.allocator());
break;
case 1:
hps.processFrame(mags, mDescriptors, 4, get<kMinFreq>(),
mHPS.processFrame(mags, mDescriptors, 4, get<kMinFreq>(),
get<kMaxFreq>(), sampleRate(), c.allocator());
break;
case 2:
yinFFT.processFrame(mags, mDescriptors, get<kMinFreq>(),
mYinFFT.processFrame(mags, mDescriptors, get<kMinFreq>(),
get<kMaxFreq>(), sampleRate(), c.allocator());
break;
}
Expand Down Expand Up @@ -157,7 +158,7 @@ class PitchClient : public FluidBaseClient, public AudioIn, public ControlOut
void reset(FluidContext& c)
{
mSTFTBufferedProcess.reset();
cepstrumF0.init(get<kFFT>().frameSize(), c.allocator());
mCepstrumF0.init(get<kFFT>().frameSize(), c.allocator());
// mMagnitude.resize(get<kFFT>().frameSize());
}

Expand All @@ -166,9 +167,9 @@ class PitchClient : public FluidBaseClient, public AudioIn, public ControlOut

STFTBufferedProcess<> mSTFTBufferedProcess;

CepstrumF0 cepstrumF0;
HPS hps;
YINFFT yinFFT;
CepstrumF0 mCepstrumF0;
HPS mHPS;
YINFFT mYinFFT;
FluidTensor<double, 1> mMagnitude;
FluidTensor<double, 1> mDescriptors;
};
Expand Down
2 changes: 1 addition & 1 deletion tests/algorithms/public/TestNoveltySegmentation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ NoveltyPitchTest(fluid::FluidTensorView<const double, 1> testSignal, Params p)
FluidTensor<double, 1> pitchFrame(2);

auto stft = STFT{p.window, p.fft, p.hop};
auto pitch = fluid::algorithm::YINFFT();
auto pitch = fluid::algorithm::YINFFT((p.fft / 2) + 1);

auto makeInput = [&stft, &pitch, &stftFrame, &magnitudes,
&pitchFrame](auto source) {
Expand Down