Skip to content
Open
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
5 changes: 3 additions & 2 deletions include/flucoma/algorithms/public/CepstrumF0.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ class CepstrumF0
mCepstrum.setZero();
}

void processFrame(const RealVectorView& input, RealVectorView output,
double minFreq, double maxFreq, double sampleRate, Allocator& alloc)
void processFrame(const InputRealVectorView input, RealVectorView output,
double minFreq, double maxFreq, double sampleRate,
Allocator& alloc)
{
using namespace Eigen;
using namespace std;
Expand Down
13 changes: 9 additions & 4 deletions include/flucoma/algorithms/public/ChromaFilterBank.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ under the European Union’s Horizon 2020 research and innovation programme
#include "../util/FluidEigenMappings.hpp"
#include "../../data/FluidIndex.hpp"
#include "../../data/FluidMemory.hpp"
#include "../../data/TensorTypes.hpp"
#include <Eigen/Core>
#include <cassert>
#include <cmath>
Expand All @@ -28,7 +29,8 @@ class ChromaFilterBank
{
public:
ChromaFilterBank(index maxBins, index maxFFT, Allocator& alloc)
: mMaxChroma(maxBins), mMaxFFT(maxFFT), mFilters(maxBins, maxFFT/2 + 1, alloc)
: mMaxChroma(maxBins), mMaxFFT(maxFFT),
mFilters(maxBins, maxFFT / 2 + 1, alloc), mFrame(maxFFT, alloc)
{}


Expand Down Expand Up @@ -80,13 +82,15 @@ class ChromaFilterBank
mSampleRate = sampleRate;
}

void processFrame(const RealVectorView in, RealVectorView out,
double minFreq = 0, double maxFreq = -1, index normalize = 0)
void processFrame(const InputRealVectorView in, RealVectorView out,
double minFreq = 0, double maxFreq = -1,
index normalize = 0)
{
using namespace Eigen;
using namespace std;

FluidEigenMap<Eigen::Array> frame = _impl::asEigen<Eigen::Array>(in);
auto frame = mFrame.topRows(in.rows());
frame = _impl::asEigen<Eigen::Array>(in);

if(minFreq != 0 || maxFreq != -1){
maxFreq = (maxFreq == -1) ? (mSampleRate / 2) : min(maxFreq, mSampleRate / 2);
Expand Down Expand Up @@ -121,6 +125,7 @@ class ChromaFilterBank
index mMaxChroma;
index mMaxFFT;
ScopedEigenMap<Eigen::MatrixXd> mFilters;
ScopedEigenMap<Eigen::ArrayXd> mFrame;
};
} // namespace algorithm
} // namespace fluid
4 changes: 2 additions & 2 deletions include/flucoma/algorithms/public/DCT.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ class DCT
mInitialized = true;
}

void processFrame(const RealVectorView in, RealVectorView out)
void processFrame(const InputRealVectorView in, RealVectorView out)
{
assert(mInitialized && "DCT: processFrame() called before init()");
assert(in.size() == mInputSize &&
"DCT: actual input size doesn't match expected size");
assert(out.size() == mOutputSize &&
"DCT: actual output size doesn't maatch expected size");

FluidEigenMap<Eigen::Matrix> frame = _impl::asEigen<Eigen::Matrix>(in);
auto frame = _impl::asEigen<Eigen::Matrix>(in);
_impl::asEigen<Eigen::Matrix>(out).noalias() =
(mTable.topLeftCorner(mOutputSize, mInputSize) * frame);
}
Expand Down
2 changes: 1 addition & 1 deletion include/flucoma/algorithms/public/HPS.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class HPS
{

public:
void processFrame(const RealVectorView& input, RealVectorView output,
void processFrame(const InputRealVectorView input, RealVectorView output,
index nHarmonics, double minFreq, double maxFreq,
double sampleRate, Allocator& alloc)
{
Expand Down
7 changes: 4 additions & 3 deletions include/flucoma/algorithms/public/Loudness.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,16 @@ class Loudness
mInitialized = true;
}

void processFrame(const RealVectorView& input, RealVectorView output,
bool weighting, bool truePeak, Allocator& alloc = FluidDefaultAllocator())
void processFrame(const InputRealVectorView input, RealVectorView output,
bool weighting, bool truePeak,
Allocator& alloc = FluidDefaultAllocator())
{
using namespace Eigen;
using namespace std;
assert(mInitialized);
assert(output.size() == 2);
assert(input.size() == mSize);
FluidEigenMap<Eigen::Array> in = _impl::asEigen<Array>(input);
auto in = _impl::asEigen<Array>(input);
ScopedEigenMap<ArrayXd> filtered(mSize, alloc);
for (index i = 0; i < mSize; i++)
filtered(i) = weighting ? mFilter.processSample(input(i)) : input(i);
Expand Down
13 changes: 8 additions & 5 deletions include/flucoma/algorithms/public/MelBands.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ under the European Union’s Horizon 2020 research and innovation programme
#include "../util/FluidEigenMappings.hpp"
#include "../../data/FluidIndex.hpp"
#include "../../data/FluidMemory.hpp"
#include "../../data/TensorTypes.hpp"
#include <Eigen/Core>
#include <cassert>
#include <cmath>
Expand All @@ -26,7 +27,8 @@ class MelBands
public:
MelBands(
index maxBands, index maxFFT, Allocator& alloc = FluidDefaultAllocator())
: mFilters(maxBands, maxFFT / 2 + 1, alloc)
: mFrame(maxFFT, alloc),
mFilters(maxBands, maxFFT / 2 + 1, alloc)
{}

/*static inline double mel2hz(double x) {
Expand Down Expand Up @@ -76,13 +78,13 @@ class MelBands
mNBins = nBins;
}

void processFrame(const RealVectorView in, RealVectorView out, bool magNorm,
void processFrame(const InputRealVectorView in, RealVectorView out, bool magNorm,
bool usePower, bool logOutput, Allocator&)
{
using namespace Eigen;

FluidEigenMap<Array> frame = _impl::asEigen<Array>(in);
FluidEigenMap<Array> result = _impl::asEigen<Array>(out);
auto frame = mFrame.topRows(in.rows());
frame = _impl::asEigen<Array>(in);
auto result = _impl::asEigen<Array>(out);

if (magNorm) frame = frame * mScale1;
double energy = frame.sum() * mScale2;
Expand All @@ -100,6 +102,7 @@ class MelBands
double mScale2{1.0};

private:
ScopedEigenMap<Eigen::ArrayXd> mFrame;
ScopedEigenMap<Eigen::MatrixXd> mFilters;
index mNBands;
index mNBins;
Expand Down
4 changes: 2 additions & 2 deletions include/flucoma/algorithms/public/MultiStats.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ under the European Union’s Horizon 2020 research and innovation programme
#include "../../data/TensorTypes.hpp"
#include <Eigen/Core>
#include <cassert>
#include <cmath>


namespace fluid {
namespace algorithm {
Expand All @@ -45,7 +45,7 @@ class MultiStats
return in.segment(1, in.size() - 1) - in.segment(0, in.size() - 1);
}

void process(const RealMatrixView in, RealMatrixView out, double cutoff = -1,
void process(const InputRealMatrixView in, RealMatrixView out, double cutoff = -1,
RealVectorView w = RealVectorView(nullptr, 0, 0))
{
using namespace Eigen;
Expand Down
14 changes: 8 additions & 6 deletions include/flucoma/algorithms/public/NMF.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class NMF
// cancelled)
using ProgressCallback = std::function<bool(index)>;

static void estimate(const RealMatrixView W, const RealMatrixView H,
static void estimate(const InputRealMatrixView W, const InputRealMatrixView H,
index idx, RealMatrixView V)
{
using namespace Eigen;
Expand All @@ -42,14 +42,15 @@ class NMF
}

// processFrame computes activations of a dictionary W in a given frame
void processFrame(const RealVectorView x, const RealMatrixView W0,
void processFrame(const InputRealVectorView x, const InputRealMatrixView W0,
RealVectorView out, index nIterations, RealVectorView v,
index randomSeed, Allocator& alloc)
{
using namespace Eigen;
using namespace _impl;
index rank = W0.extent(0);
FluidEigenMap<Matrix> W = asEigen<Matrix>(W0);
ScopedEigenMap<MatrixXd> W{W0.rows(),W0.cols(),alloc};
W = asEigen<Matrix>(W0);
Comment on lines +52 to +53

ScopedEigenMap<VectorXd> h(rank, alloc);
h = EigenRandom<VectorXd>(rank, RandomSeed{randomSeed}, Range{0.0, 1.0});
Expand Down Expand Up @@ -88,9 +89,10 @@ class NMF
if (v.data()) _impl::asEigen<Matrix>(v).noalias() = (W.transpose() * h);
}

void process(const RealMatrixView X, RealMatrixView W1, RealMatrixView H1,
RealMatrixView V1, index rank, index nIterations, bool updateW,
bool updateH = false, index randomSeed = -1,
void process(const InputRealMatrixView X, RealMatrixView W1,
RealMatrixView H1, RealMatrixView V1, index rank,
index nIterations, bool updateW, bool updateH = false,
index randomSeed = -1,
RealMatrixView W0 = RealMatrixView(nullptr, 0, 0, 0),
RealMatrixView H0 = RealMatrixView(nullptr, 0, 0, 0))
{
Expand Down
11 changes: 5 additions & 6 deletions include/flucoma/algorithms/public/NMFCross.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,12 @@ under the European Union’s Horizon 2020 research and innovation programme

#pragma once

#include "STFT.hpp"
#include "../util/EigenRandom.hpp"
#include "../util/FluidEigenMappings.hpp"
#include "../../data/FluidIndex.hpp"
#include "../../data/TensorTypes.hpp"
#include <Eigen/Core>
#include <Eigen/Dense>
#include <iostream>
#include <vector>

namespace fluid {
Expand All @@ -46,7 +44,7 @@ class NMFCross

NMFCross(index nIterations) : mIterations(nIterations) {}

static void synthesize(const RealMatrixView h, const ComplexMatrixView w,
static void synthesize(const InputRealMatrixView h, const ComplexMatrixView w,
ComplexMatrixView out)
{
using namespace Eigen;
Expand All @@ -57,8 +55,9 @@ class NMFCross
out <<= asFluid(V);
}

void process(const RealMatrixView X, RealMatrixView H1, RealMatrixView W0,
index r, index p, index c, index randomSeed = -1) const
void process(const InputRealMatrixView X, RealMatrixView H1,
RealMatrixView W0, index r, index p, index c,
index randomSeed = -1) const
{
index nFrames = X.extent(0);
// index nBins = X.extent(1);
Expand Down Expand Up @@ -129,7 +128,7 @@ class NMFCross
VectorXd::Index maxIndex{0};
neighborhood.maxCoeff(&maxIndex);
if (int(maxIndex) != halfSize)
{ output(i, j) = H(i, j) * (1 - ((iteration + 1) / mIterations)); }
{ output(i, j) = H(i, j) * (1 - ((iteration + 1.0) / mIterations)); }
else
{
output(i, j) = H(i, j);
Expand Down
9 changes: 4 additions & 5 deletions include/flucoma/algorithms/public/Normalization.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ under the European Union’s Horizon 2020 research and innovation programme
#include "../../data/TensorTypes.hpp"
#include <Eigen/Core>
#include <cassert>
#include <cmath>

namespace fluid {
namespace algorithm {
Expand Down Expand Up @@ -58,13 +57,13 @@ class Normalization
mInitialized = true;
}

void processFrame(const RealVectorView in, RealVectorView out,
void processFrame(const InputRealVectorView in, RealVectorView out,
bool inverse = false) const
{
using namespace Eigen;
using namespace _impl;
FluidEigenMap<Array> input = asEigen<Array>(in);
FluidEigenMap<Array> result = asEigen<Array>(out);
auto input = asEigen<Array>(in);
auto result = asEigen<Array>(out);
if (!inverse)
{
result = (input - mDataMin) / mDataRange;
Expand All @@ -77,7 +76,7 @@ class Normalization
}
}

void process(const RealMatrixView in, RealMatrixView out,
void process(const InputRealMatrixView in, RealMatrixView out,
bool inverse = false) const
{
using namespace Eigen;
Expand Down
2 changes: 1 addition & 1 deletion include/flucoma/algorithms/public/NoveltyFeature.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class NoveltyFeature
mInitialized = true;
}

double processFrame(const RealVectorView input, Allocator& alloc)
double processFrame(const InputRealVectorView input, Allocator& alloc)
{
assert(mInitialized);
double novelty =
Expand Down
6 changes: 3 additions & 3 deletions include/flucoma/algorithms/public/NoveltySegmentation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ under the European Union’s Horizon 2020 research and innovation programme
#pragma once

#include "NoveltyFeature.hpp"
#include "../util/FluidEigenMappings.hpp"
#include "../../data/FluidIndex.hpp"
#include "../../data/FluidMemory.hpp"
#include "../../data/TensorTypes.hpp"
Expand Down Expand Up @@ -40,8 +39,9 @@ class NoveltySegmentation
mPeakBuffer.setZero();
}

double processFrame(const RealVectorView input, double threshold,
index minSliceLength, Allocator& alloc = FluidDefaultAllocator())
double processFrame(const InputRealVectorView input, double threshold,
index minSliceLength,
Allocator& alloc = FluidDefaultAllocator())
{
double detected = 0.;

Expand Down
14 changes: 7 additions & 7 deletions include/flucoma/algorithms/public/PCA.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ under the European Union’s Horizon 2020 research and innovation programme

#pragma once

#include "../util/AlgorithmUtils.hpp"
#include "../util/FluidEigenMappings.hpp"
#include "../../data/TensorTypes.hpp"
#include <Eigen/Core>
#include <Eigen/SVD>
#include <cassert>
#include <cmath>


namespace fluid {
namespace algorithm {
Expand Down Expand Up @@ -53,18 +54,17 @@ class PCA
mInitialized = true;
}

void processFrame(const RealVectorView in, RealVectorView out, index k,
void processFrame(const InputRealVectorView in, RealVectorView out, index k,
bool whiten = false) const
{
using namespace Eigen;
using namespace _impl;
if (k > mBases.cols()) return;
FluidEigenMap<Matrix> input = asEigen<Matrix>(in);
input = input - mMean;
FluidEigenMap<Matrix> result = asEigen<Matrix>(out);
auto input = asEigen<Matrix>(in);
auto result = asEigen<Matrix>(out);
// this avoids Eigen making a temporary (sorry):
result.transpose().noalias() =
input.transpose() * mBases.block(0, 0, mBases.rows(), k);
(input - mMean).transpose() * mBases.block(0, 0, mBases.rows(), k);

if (whiten)
{
Expand All @@ -91,7 +91,7 @@ class PCA
}
}

double process(const RealMatrixView in, RealMatrixView out, index k,
double process(const InputRealMatrixView in, RealMatrixView out, index k,
bool whiten = false) const
{
using namespace Eigen;
Expand Down
8 changes: 4 additions & 4 deletions include/flucoma/algorithms/public/RobustScaling.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,21 +68,21 @@ class RobustScaling
mInitialized = true;
}

void processFrame(const RealVectorView in, RealVectorView out,
void processFrame(const InputRealVectorView in, RealVectorView out,
bool inverse = false) const
{
using namespace Eigen;
using namespace _impl;
FluidEigenMap<Array> input = asEigen<Array>(in);
FluidEigenMap<Array> result = asEigen<Array>(out);
auto input = asEigen<Array>(in);
auto result = asEigen<Array>(out);
if (!inverse) { result = (input - mMedian) / mRange; }
else
{
result = (input * mRange) + mMedian;
}
}

void process(const RealMatrixView in, RealMatrixView out,
void process(const InputRealMatrixView in, RealMatrixView out,
bool inverse = false) const
{
using namespace Eigen;
Expand Down
Loading
Loading