Skip to content

Commit

Permalink
MFCC - fixes startCoeff (#195)
Browse files Browse the repository at this point in the history
* fixes

* cleaner and proper check this time
  • Loading branch information
tremblap committed Aug 16, 2022
1 parent 2fbc4fe commit 62cd82a
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions include/clients/rt/MFCCClient.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class MFCCClient : public FluidBaseClient, public AudioIn, public ControlOut
{
mMagnitude = FluidTensor<double, 1>(get<kFFT>().maxFrameSize());
mBands = FluidTensor<double, 1>(get<kNBands>().max());
mCoefficients = FluidTensor<double, 1>(get<kNCoefs>().max() + get<kDrop0>());
mCoefficients = FluidTensor<double, 1>(get<kNCoefs>().max() + 1); //adding a spare item to the allocation to pad for has0
audioChannelsIn(1);
controlChannelsOut({1, get<kNCoefs>(), get<kNCoefs>().max()});
setInputLabels({"audio input"});
Expand All @@ -103,16 +103,16 @@ class MFCCClient : public FluidBaseClient, public AudioIn, public ControlOut
nBands, get<kMinFreq>(), get<kMaxFreq>(),
sampleRate()))
{
mMelBands.init(get<kMinFreq>(), get<kMaxFreq>(), get<kNBands>(),
mMelBands.init(get<kMinFreq>(), get<kMaxFreq>(), nBands,
get<kFFT>().frameSize(), sampleRate(),
get<kFFT>().winSize());
mDCT.init(get<kNBands>(), nCoefs + !has0);
mDCT.init(nBands, fmin(nCoefs + !has0, nBands)); //making sure that we don't ask for more than nBands coeff in case of has0
controlChannelsOut({1, nCoefs});
}

auto mags = mMagnitude(Slice(0,frameSize));
auto bands = mBands(Slice(0,nBands));
auto coefs = mCoefficients(Slice(get<kDrop0>(), nCoefs));
auto coefs = mCoefficients(Slice(0, fmin(nCoefs + !has0, nBands))); //making sure that we don't ask for more than nBands coeff in case of has0

mSTFTBufferedProcess.processInput(
mParams, input, c, [&](ComplexMatrixView in) {
Expand All @@ -121,22 +121,24 @@ class MFCCClient : public FluidBaseClient, public AudioIn, public ControlOut
mDCT.processFrame(bands, coefs);
});

output[0](Slice(0, nCoefs)) <<= coefs;
output[0](Slice(0, nCoefs)) <<= mCoefficients(Slice(get<kDrop0>(), nCoefs)); // copying from has0 for nCoefs
output[0](Slice(nCoefs, get<kNCoefs>().max() - nCoefs)).fill(0);
}

index latency() { return get<kFFT>().winSize(); }

void reset()
{
index nBands = get<kNBands>();

mSTFTBufferedProcess.reset();
mMagnitude.resize(get<kFFT>().frameSize());
mBands.resize(get<kNBands>());
mCoefficients.resize(get<kNCoefs>().max() + get<kDrop0>());
mMelBands.init(get<kMinFreq>(), get<kMaxFreq>(), get<kNBands>(),
mBands.resize(nBands);
mCoefficients.resize(get<kNCoefs>().max() + 1); //same as line 79
mMelBands.init(get<kMinFreq>(), get<kMaxFreq>(), nBands,
get<kFFT>().frameSize(), sampleRate(),
get<kFFT>().winSize());
mDCT.init(get<kNBands>(), get<kNCoefs>() + get<kDrop0>());
mDCT.init(nBands, fmin((get<kNCoefs>() + get<kDrop0>()), nBands)); //making sure that we don't ask for more than nBands coeff in case of has0
}

AnalysisSize analysisSettings()
Expand Down

0 comments on commit 62cd82a

Please sign in to comment.