Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release] 1.0.5 #210

Merged
merged 30 commits into from
Dec 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
bb64647
mfcc fix - replaced fmin by std:min - and tested on the new UTs for b…
tremblap Aug 22, 2022
025c6a1
Merge branch 'main' into dev
tremblap Sep 1, 2022
c7d1eb3
Bump Spectra dependency to v1.0.1
weefuzzy Sep 16, 2022
1216284
RunningStatsClient: Better initializing
weefuzzy Sep 20, 2022
4513203
Formatting
weefuzzy Sep 20, 2022
571789c
WIP: Making Real-time objects allocator-aware (#190)
weefuzzy Sep 28, 2022
7948c72
delete ConvolutionTools.hpp :trash:
weefuzzy Sep 28, 2022
9d87adb
ARModel: fix possible div 0
weefuzzy Sep 28, 2022
c15e9a1
HISSTools: Update dependency
weefuzzy Sep 28, 2022
92bff72
Tests: Don't generate files into source tree if poss
weefuzzy Sep 28, 2022
511b9b1
Enable multiple outputs for NRT wrapped descriptor objects
weefuzzy Oct 21, 2022
d63469b
Merge pull request #201 from weefuzzy/enhance/multiout_nrt_descriptor
tremblap Oct 21, 2022
04c8c68
parenthesis bug found in client wrapper
tremblap Nov 11, 2022
854bf5d
Feature/peaks (#202)
tremblap Dec 8, 2022
7e655d1
TruePeak: Replace FFT with filter
weefuzzy Dec 9, 2022
c0fc015
DS: working method for bruteforce knearest query (#204)
tremblap Dec 9, 2022
4a827b2
adding name in print for labelset, sorts issue #110
tremblap Dec 10, 2022
52fa0b2
Merge pull request #206 from flucoma/fix/labelset-name-in-print
tremblap Dec 10, 2022
b5bc590
feature/kdtree-distance-with-optional-k
tremblap Dec 10, 2022
2ccf188
Merge pull request #205 from weefuzzy/enhance/TruePeakFilter
weefuzzy Dec 13, 2022
9acc33a
Merge pull request #207 from flucoma/feature/kdtree-distance-with-opt…
tremblap Dec 13, 2022
1543b31
(buf)sines: consistent naming of interface
tremblap Dec 13, 2022
8ebc263
Warnings and formatting
weefuzzy Dec 13, 2022
bc2f70e
Add functions for applying constraints to param maxima
weefuzzy Dec 13, 2022
be48983
Merge pull request #209 from weefuzzy/fix/params_maxima
tremblap Dec 13, 2022
5f0b80c
CMakeList - set CMP0135 for more recent versions
tremblap Dec 13, 2022
4814122
Make MSVC happy
weefuzzy Dec 14, 2022
698e029
Fix build for TestNoveltySeg
weefuzzy Dec 14, 2022
4c193ca
Disable real material tests in TransientSlice and Novelty + loudness
weefuzzy Dec 14, 2022
eb39004
update to 1.0.5
tremblap Dec 15, 2022
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
52 changes: 43 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0")
cmake_policy(SET CMP0135 NEW)
endif()

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/script")

Expand Down Expand Up @@ -53,7 +56,7 @@ FetchContent_Declare(
HISSTools
GIT_REPOSITORY https://github.com/AlexHarker/HISSTools_Library
GIT_PROGRESS TRUE
GIT_TAG 5dd8530
GIT_TAG 559b5c8
)

FetchContent_Declare(
Expand All @@ -67,10 +70,11 @@ FetchContent_Declare(

FetchContent_Declare(
Spectra
GIT_SHALLOW TRUE
GIT_REPOSITORY https://github.com/yixuan/spectra
GIT_PROGRESS TRUE
GIT_BRANCH "master"
GIT_TAG "v0.9.0"
GIT_TAG "v1.0.1"
)

FetchContent_Declare(
Expand All @@ -80,16 +84,25 @@ FetchContent_Declare(
GIT_PROGRESS TRUE
)

#see https://json.nlohmann.me/integration/cmake/#fetchcontent
FetchContent_Declare(json URL https://github.com/nlohmann/json/releases/download/v3.11.2/json.tar.xz)
set(JSON_SystemInclude ON CACHE BOOL "")

FetchContent_Declare(
json
GIT_SHALLOW TRUE
# GIT_REPOSITORY https://github.com/nlohmann/json.git
# advice on nlohmann repo is to use this mirror unless we really want ~150 meg of test data as well as headers:
GIT_REPOSITORY https://github.com/ArthurSonzogni/nlohmann_json_cmake_fetchcontent
Memory
GIT_SHALLOW TRUE
GIT_REPOSITORY https://github.com/foonathan/memory.git
GIT_PROGRESS TRUE
GIT_TAG v3.10.5
GIT_TAG main
)

FetchContent_Declare(
fmt
GIT_SHALLOW TRUE
GIT_REPOSITORY https://github.com/fmtlib/fmt
GIT_PROGRESS TRUE
GIT_TAG master
)
set(JSON_SystemInclude ON CACHE BOOL "")

if(HISS_PATH) #if hiss path is set, this will stop it downloading
get_filename_component(FETCHCONTENT_SOURCE_DIR_HISSTOOLS ${HISS_PATH} ABSOLUTE)
Expand Down Expand Up @@ -138,6 +151,18 @@ endif()

add_subdirectory(${json_SOURCE_DIR} ${json_BINARY_DIR} EXCLUDE_FROM_ALL)

set(FOONATHAN_MEMORY_BUILD_TOOLS OFF CACHE BOOL "" FORCE)
set(FOONATHAN_MEMORY_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
set(FOONATHAN_MEMORY_BUILD_TESTS OFF CACHE BOOL "" FORCE)

FetchContent_GetProperties(Memory)
if(NOT memory_POPULATED)
FetchContent_Populate(Memory)
endif()
add_subdirectory(${memory_SOURCE_DIR} ${memory_BINARY_DIR} EXCLUDE_FROM_ALL)

FetchContent_MakeAvailable(fmt)

# HISSTools FFT target
add_library(
HISSTools_FFT STATIC "${hisstools_SOURCE_DIR}/HISSTools_FFT/HISSTools_FFT.cpp"
Expand Down Expand Up @@ -183,13 +208,17 @@ target_include_directories(
"${eigen_SOURCE_DIR}"
"${spectra_SOURCE_DIR}/include"
"${hisstools_SOURCE_DIR}"
"${memory_SOURCE_DIR}/include/foonathan"
"${fmt_SOURCE_DIR}/include"
)
target_link_libraries(
FLUID_DECOMPOSITION INTERFACE
HISSTools_FFT
flucoma_VERSION_LIB
tl::optional
nlohmann_json::nlohmann_json
foonathan_memory
fmt::fmt
)
target_sources(
FLUID_DECOMPOSITION INTERFACE ${HEADERS}
Expand Down Expand Up @@ -224,9 +253,14 @@ if(DEFINED FLUID_ARCH)
endif()

#Examples

option(BUILD_EXAMPLES "Build C++ example code (off by default)" OFF)

if(BUILD_EXAMPLES)
add_subdirectory(
"${CMAKE_CURRENT_SOURCE_DIR}/examples"
)
endif()

enable_testing()

Expand Down
2 changes: 2 additions & 0 deletions FlucomaClients.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ add_client(BufSTFT clients/nrt/BufSTFTClient.hpp CLASS NRTThreadedBufferSTFTClie
add_client(BufScale clients/nrt/BufScaleClient.hpp CLASS NRTThreadedBufferScaleClient )
add_client(BufSelect clients/nrt/BufSelectClient.hpp CLASS NRTThreadingSelectClient )
add_client(BufSelectEvery clients/nrt/BufSelectEveryClient.hpp CLASS NRTThreadingSelectEveryClient )
add_client(BufSineFeature clients/rt/SineFeatureClient.hpp CLASS NRTThreadedSineFeatureClient )
add_client(BufSines clients/rt/SinesClient.hpp CLASS NRTThreadedSinesClient )
add_client(BufSpectralShape clients/rt/SpectralShapeClient.hpp CLASS NRTThreadedSpectralShapeClient )
add_client(BufStats clients/nrt/BufStatsClient.hpp CLASS NRTThreadedBufferStatsClient )
Expand All @@ -132,6 +133,7 @@ add_client(OnsetFeature clients/rt/OnsetFeatureClient.hpp CLASS RTOnsetFeatureCl
add_client(OnsetSlice clients/rt/OnsetSliceClient.hpp CLASS RTOnsetSliceClient )
add_client(Pitch clients/rt/PitchClient.hpp CLASS RTPitchClient )
add_client(STFTPass clients/rt/BaseSTFTClient.hpp CLASS RTSTFTPassClient NOINSTALL)
add_client(SineFeature clients/rt/SineFeatureClient.hpp CLASS RTSineFeatureClient )
add_client(Sines clients/rt/SinesClient.hpp CLASS RTSinesClient )
add_client(SpectralShape clients/rt/SpectralShapeClient.hpp CLASS RTSpectralShapeClient )
add_kr_in_client(Stats clients/rt/RunningStatsClient.hpp CLASS RunningStatsClient )
Expand Down
2 changes: 1 addition & 1 deletion FlucomaVersion.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ find_package(Git REQUIRED)

set(flucoma_VERSION_MAJOR 1)
set(flucoma_VERSION_MINOR 0)
set(flucoma_VERSION_PATCH 4)
set(flucoma_VERSION_PATCH 5)
set(flucoma_VERSION_SUFFIX "")

function(make_flucoma_version_string output_variable)
Expand Down
162 changes: 93 additions & 69 deletions include/algorithms/public/AudioTransport.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ under the European Union’s Horizon 2020 research and innovation programme
#include "../util/FFT.hpp"
#include "../util/FluidEigenMappings.hpp"
#include "../../data/FluidIndex.hpp"
#include "../../data/FluidMemory.hpp"
#include "../../data/TensorTypes.hpp"
#include <Eigen/Core>
#include <cmath>
Expand All @@ -41,77 +42,88 @@ class AudioTransport
using ArrayXcd = Eigen::ArrayXcd;
template <typename T>
using Ref = Eigen::Ref<T>;
using TransportMatrix = std::vector<std::tuple<index, index, double>>;
using TransportMatrix = rt::vector<std::tuple<index, index, double>>;
template <typename T>
using vector = std::vector<T>;
using vector = rt::vector<T>;

public:
AudioTransport(index maxFFTSize)
AudioTransport(index maxFFTSize, Allocator& alloc)
: mWindowSize(maxFFTSize), mFFTSize(maxFFTSize),
mBins(maxFFTSize / 2 + 1), mFFT(maxFFTSize),
mSTFT(maxFFTSize, maxFFTSize, maxFFTSize / 2),
mISTFT(maxFFTSize, maxFFTSize, maxFFTSize / 2),
mReassignSTFT(maxFFTSize, maxFFTSize, maxFFTSize / 2)
mReassignSTFT(maxFFTSize, maxFFTSize, maxFFTSize / 2,
static_cast<index>(WindowFuncs::WindowTypes::kHannD)),
mBinFreqs(maxFFTSize / 2 + 1, alloc), mWindow(maxFFTSize, alloc),
mWindowSquared(maxFFTSize, alloc), mPhase(maxFFTSize / 2 + 1, alloc),
mPhaseDiff(maxFFTSize / 2 + 1, alloc),
mChanged(maxFFTSize / 2 + 1, alloc)
{}

void init(index windowSize, index fftSize, index hopSize)
{
mWindowSize = windowSize;
mWindow = ArrayXd::Zero(mWindowSize);
WindowFuncs::map()[WindowFuncs::WindowTypes::kHann](mWindowSize, mWindow);
mWindow.head(mWindowSize).setZero();
WindowFuncs::map()[WindowFuncs::WindowTypes::kHann](
mWindowSize, mWindow.head(mWindowSize));
mWindowSquared = mWindow * mWindow;
mFFTSize = fftSize;
mHopSize = hopSize;
mBins = fftSize / 2 + 1;
mPhase = ArrayXd::Zero(mBins);
mChanged = ArrayXi::Zero(mBins);
mBinFreqs = ArrayXd::LinSpaced(mBins, 0, mBins - 1) * (2 * pi) / mFFTSize;
mPhaseDiff = mBinFreqs * mHopSize;
mSTFT = STFT(windowSize, fftSize, hopSize);
mISTFT = ISTFT(windowSize, fftSize, hopSize);
mReassignSTFT = STFT(windowSize, fftSize, hopSize,
static_cast<index>(WindowFuncs::WindowTypes::kHannD));
mPhase.setZero();
mChanged.setZero();
mBinFreqs.head(mBins) =
ArrayXd::LinSpaced(mBins, 0, mBins - 1) * (2 * pi) / mFFTSize;
mPhaseDiff.head(mBins) = mBinFreqs * mHopSize;
mSTFT.resize(windowSize, fftSize, hopSize);
mISTFT.resize(windowSize, fftSize, hopSize);
mReassignSTFT.resize(windowSize, fftSize, hopSize);
mFFT.resize(fftSize);
mInitialized = true;
}

bool initialized() const { return mInitialized; }

void processFrame(RealVectorView in1, RealVectorView in2, double weight,
RealMatrixView out)
RealMatrixView out, Allocator& alloc)
{
using namespace _impl;
using namespace Eigen;
assert(mInitialized);
ArrayXd frame1 = asEigen<Array>(in1);
ArrayXd frame2 = asEigen<Array>(in2);
ArrayXcd spectrum1(mBins);
ArrayXcd spectrum1Dh(mBins);
ArrayXcd spectrum2(mBins);
ArrayXcd spectrum2Dh(mBins);
ArrayXd output(frame1.size());
ScopedEigenMap<ArrayXd> frame1(in1.size(), alloc);
frame1 = asEigen<Array>(in1);
ScopedEigenMap<ArrayXd> frame2(in2.size(), alloc);
frame2 = asEigen<Array>(in2);
ScopedEigenMap<ArrayXcd> spectrum1(mBins, alloc);
ScopedEigenMap<ArrayXcd> spectrum1Dh(mBins, alloc);
ScopedEigenMap<ArrayXcd> spectrum2(mBins, alloc);
ScopedEigenMap<ArrayXcd> spectrum2Dh(mBins, alloc);
ScopedEigenMap<ArrayXd> output(frame1.size(), alloc);
mSTFT.processFrame(frame1, spectrum1);
mReassignSTFT.processFrame(frame1, spectrum1Dh);
mSTFT.processFrame(frame2, spectrum2);
mReassignSTFT.processFrame(frame2, spectrum2Dh);
ArrayXcd result =
interpolate(spectrum1, spectrum1Dh, spectrum2, spectrum2Dh, weight);
ScopedEigenMap<ArrayXcd> result = interpolate(
spectrum1, spectrum1Dh, spectrum2, spectrum2Dh, weight, alloc);
mISTFT.processFrame(result, output);
out.row(0) <<= asFluid(output);
out.row(1) <<= asFluid(mWindowSquared);
_impl::asEigen<Array>(out.row(0)) = output;
_impl::asEigen<Array>(out.row(1)) = mWindowSquared.head(mWindowSize);
}

vector<SpetralMass> segmentSpectrum(const Ref<ArrayXd> mag,
const Ref<ArrayXd> reasignedFreq)
const Ref<ArrayXd> reasignedFreq,
Allocator& alloc)
{

vector<SpetralMass> masses;
double totalMass = mag.sum() + epsilon;
ArrayXi sign = (reasignedFreq > mBinFreqs).cast<int>();
vector<SpetralMass> masses(alloc);
double totalMass = mag.sum() + epsilon;
ScopedEigenMap<ArrayXi> sign(reasignedFreq.size(), alloc);
sign = (reasignedFreq > mBinFreqs.head(reasignedFreq.size())).cast<int>();
mChanged.setZero();
mChanged.segment(1, mBins - 1) =
sign.segment(1, mBins - 1) - sign.segment(0, mBins - 1);
SpetralMass currentMass{0, 0, 0, 0};
for (index i = 1; i < mChanged.size(); i++)
for (index i = 1; i < mBins; i++)
{
if (mChanged(i) == -1)
{
Expand All @@ -137,10 +149,11 @@ class AudioTransport
return masses;
}

TransportMatrix computeTransportMatrix(std::vector<SpetralMass> m1,
std::vector<SpetralMass> m2)
TransportMatrix computeTransportMatrix(rt::vector<SpetralMass>& m1,
rt::vector<SpetralMass>& m2,
Allocator& alloc)
{
TransportMatrix matrix;
TransportMatrix matrix(alloc);
index index1 = 0, index2 = 0;
double mass1 = m1[0].mass;
double mass2 = m2[0].mass;
Expand Down Expand Up @@ -186,41 +199,52 @@ class AudioTransport
}
}

ArrayXcd interpolate(Ref<ArrayXcd> in1, Ref<ArrayXcd> in1Dh,
Ref<ArrayXcd> in2, Ref<ArrayXcd> in2Dh,
double interpolation)
ScopedEigenMap<ArrayXcd> interpolate(Ref<ArrayXcd> in1, Ref<ArrayXcd> in1Dh,
Ref<ArrayXcd> in2, Ref<ArrayXcd> in2Dh,
double interpolation, Allocator& alloc)
{
ArrayXd mag1 = in1.abs().real();
ArrayXd mag2 = in2.abs().real();
ArrayXcd result = ArrayXcd::Zero(mBins);
double mag1Sum = mag1.sum();
double mag2Sum = mag2.sum();
ScopedEigenMap<ArrayXd> mag1(in1.size(), alloc);
mag1 = in1.abs().real();
ScopedEigenMap<ArrayXd> mag2(in2.size(), alloc);
mag2 = in2.abs().real();
ScopedEigenMap<ArrayXcd> result(mBins, alloc);
result.setZero();
double mag1Sum = mag1.sum();
double mag2Sum = mag2.sum();
if (mag1Sum <= 0 && mag2Sum <= 0) { return result; }
else if (mag1Sum > 0 && mag2Sum <= 0)
{
return in1;
result = in1;
return result;
}
else if (mag1Sum <= 0 && mag2Sum > 0)
{
return in2;
result = in2;
return result;
}
ArrayXd phase1 = in1.arg().real();
ArrayXd phase2 = in2.arg().real();
ArrayXd reasignedW1 = mBinFreqs - (in1Dh / in1).imag();
ArrayXd reasignedW2 = mBinFreqs - (in2Dh / in2).imag();
ArrayXd newAmplitudes = ArrayXd::Zero(mBins);
ArrayXd newPhases = ArrayXd::Zero(mBins);
std::vector<SpetralMass> s1 = segmentSpectrum(mag1, reasignedW1);
std::vector<SpetralMass> s2 = segmentSpectrum(mag2, reasignedW2);
ScopedEigenMap<ArrayXd> phase1(in1.size(), alloc);
phase1 = in1.arg().real();
ScopedEigenMap<ArrayXd> phase2(in2.size(), alloc);
phase2 = in2.arg().real();
ScopedEigenMap<ArrayXd> reasignedW1(in1.size(), alloc);
reasignedW1 = mBinFreqs.head(in1.size()) - (in1Dh / in1).imag();
ScopedEigenMap<ArrayXd> reasignedW2(in2.size(), alloc);
reasignedW2 = mBinFreqs.head(in2.size()) - (in2Dh / in2).imag();
ScopedEigenMap<ArrayXd> newAmplitudes(mBins, alloc);
newAmplitudes.setZero();
ScopedEigenMap<ArrayXd> newPhases(mBins, alloc);
newPhases.setZero();
rt::vector<SpetralMass> s1 = segmentSpectrum(mag1, reasignedW1, alloc);
rt::vector<SpetralMass> s2 = segmentSpectrum(mag2, reasignedW2, alloc);
if (s1.size() == 0 || s2.size() == 0) { return result; }

TransportMatrix matrix = computeTransportMatrix(s1, s2);
TransportMatrix matrix = computeTransportMatrix(s1, s2, alloc);
for (auto t : matrix)
{
SpetralMass m1 = s1[asUnsigned(std::get<0>(t))];
SpetralMass m2 = s2[asUnsigned(std::get<1>(t))];
index interpolatedBin = std::lrint((1 - interpolation) * m1.centerBin +
interpolation * m2.centerBin);
interpolation * m2.centerBin);
double interpolationFactor = interpolation;
if (m1.centerBin != m2.centerBin)
{
Expand All @@ -243,21 +267,21 @@ class AudioTransport
return result;
}

index mWindowSize{1024};
index mHopSize{512};
ArrayXd mBinFreqs;
ArrayXd mWindow;
ArrayXd mWindowSquared;
index mFFTSize{1024};
index mBins{513};
FFT mFFT;
bool mInitialized{false};
ArrayXd mPhase;
ArrayXd mPhaseDiff;
ArrayXi mChanged;
STFT mSTFT;
ISTFT mISTFT;
STFT mReassignSTFT;
index mWindowSize{1024};
index mHopSize{512};
index mFFTSize{1024};
index mBins{513};
FFT mFFT;
STFT mSTFT;
ISTFT mISTFT;
STFT mReassignSTFT;
bool mInitialized{false};
ScopedEigenMap<ArrayXd> mBinFreqs;
ScopedEigenMap<ArrayXd> mWindow;
ScopedEigenMap<ArrayXd> mWindowSquared;
ScopedEigenMap<ArrayXd> mPhase;
ScopedEigenMap<ArrayXd> mPhaseDiff;
ScopedEigenMap<ArrayXi> mChanged;
};
} // namespace algorithm
} // namespace fluid
Loading