Skip to content

Commit

Permalink
Add compiling into LV2 plugin, testing required.
Browse files Browse the repository at this point in the history
Restructure the project.
  • Loading branch information
werman committed Jan 28, 2018
1 parent c14d686 commit fb46246
Show file tree
Hide file tree
Showing 42 changed files with 1,375 additions and 159 deletions.
8 changes: 5 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
cmake-build-debug/
cmake-build-release/

bin/

#VST sdk files are ignored due to license
src/vst2.x/*.h
src/vst2.x/*.cpp
src/pluginterfaces/vst2.x/*.h
src/vst_plugin/vst2.x/*.h
src/vst_plugin/vst2.x/*.cpp
src/vst_plugin/pluginterfaces/vst2.x/*.h

*.dll

68 changes: 4 additions & 64 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,68 +1,8 @@
cmake_minimum_required(VERSION 3.6)
project(rnnoise_vst)

set(CMAKE_CXX_STANDARD 14)

include_directories(src/)

set(PLUGIN_INTERFACE_SRC
src/pluginterfaces/vst2.x/aeffect.h
src/pluginterfaces/vst2.x/aeffectx.h
src/pluginterfaces/vst2.x/vstfxstore.h)

set(VST2_SRC
src/vst2.x/aeffeditor.h
src/vst2.x/audioeffect.h
src/vst2.x/audioeffectx.h
src/vst2.x/vstplugmain.cpp
src/vst2.x/audioeffect.cpp
src/vst2.x/audioeffectx.cpp)

set(RNNOISE_SRC
src/rnnoise/rnnoise.h
src/rnnoise/_kiss_fft_guts.h
src/rnnoise/arch.h
src/rnnoise/celt_lpc.c
src/rnnoise/celt_lpc.h
src/rnnoise/common.h
src/rnnoise/denoise.c
src/rnnoise/kiss_fft.c
src/rnnoise/kiss_fft.h
src/rnnoise/opus_types.h
src/rnnoise/pitch.c
src/rnnoise/pitch.h
src/rnnoise/rnn.c
src/rnnoise/rnn.h
src/rnnoise/rnn_data.c
src/rnnoise/rnn_data.h
src/rnnoise/tansig_table.h)

set(ALL_SOURCES
${PLUGIN_INTERFACE_SRC}
${VST2_SRC}
${RNNOISE_SRC}
src/RnNoiseAudioEffect.h
src/RnNoiseAudioEffect.cpp)
include(GNUInstallDirs)

add_subdirectory(src/rnnoise)

set(TARGET_X64 rnnoise_vst_x64)
set(TARGET_X32 rnnoise_vst_x32)

add_library(${TARGET_X64} SHARED ${ALL_SOURCES})
add_library(${TARGET_X32} SHARED ${ALL_SOURCES})

target_link_libraries(${TARGET_X64} "-static -static-libgcc -static-libstdc++ -m64")
target_link_libraries(${TARGET_X32} "-static -static-libgcc -static-libstdc++ -m32")

target_compile_options(${TARGET_X64}
PRIVATE
"-m64;"
"$<$<CONFIG:RELEASE>:-O3;>"
)

target_compile_options(${TARGET_X32}
PRIVATE
"-m32;"
"$<$<CONFIG:RELEASE>:-O3;>"
)
add_subdirectory(src/common)
add_subdirectory(src/vst_plugin)
add_subdirectory(src/lv2_plugin)
34 changes: 0 additions & 34 deletions src/RnNoiseAudioEffect.h

This file was deleted.

23 changes: 23 additions & 0 deletions src/common/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
cmake_minimum_required(VERSION 3.6)
project(RnNoisePluginCommon LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 14)

set(COMMON_SRC
include/common/RnNoiseCommonPlugin.h
src/RnNoiseCommonPlugin.cpp)

add_library(RnNoisePluginCommon STATIC ${COMMON_SRC})

target_link_libraries(RnNoisePluginCommon RnNoise)

target_include_directories(RnNoisePluginCommon PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
PRIVATE src)

install(TARGETS RnNoisePluginCommon
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
33 changes: 33 additions & 0 deletions src/common/include/common/RnNoiseCommonPlugin.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#pragma once

#include <cstdint>
#include <memory>
#include <vector>

struct DenoiseState;

class RnNoiseCommonPlugin {
public:

void init();

void deinit();

void process(const float *in, float *out, int32_t sampleFrames);

private:

void createDenoiseState();

private:
static const int k_denoiseFrameSize = 480;
static const int k_denoiseSampleRate = 48000;

std::shared_ptr<DenoiseState> m_denoiseState;

std::vector<float> m_inputBuffer;
std::vector<float> m_outputBuffer;
};



Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
#include "common/RnNoiseCommonPlugin.h"

#include <cstring>
#include <ios>
#include <limits>
#include <algorithm>

#include <rnnoise/rnnoise.h>

#include "RnNoiseAudioEffect.h"

RnNoiseAudioEffect::RnNoiseAudioEffect(audioMasterCallback audioMaster, VstInt32 numPrograms, VstInt32 numParams)
: AudioEffectX(audioMaster, numPrograms, numParams) {
setNumInputs(1); // mono in
setNumOutputs(1); // mono out
setUniqueID(366056);
canProcessReplacing(); // supports replacing mode
void RnNoiseCommonPlugin::init() {
deinit();
createDenoiseState();
}

RnNoiseAudioEffect::~RnNoiseAudioEffect() = default;
void RnNoiseCommonPlugin::deinit() {
m_denoiseState.reset();
}

void RnNoiseAudioEffect::processReplacing(float **inputs, float **outputs, VstInt32 sampleFrames) {
void RnNoiseCommonPlugin::process(const float *in, float *out, int32_t sampleFrames) {
if (sampleFrames == 0) {
return;
}
Expand All @@ -26,22 +25,18 @@ void RnNoiseAudioEffect::processReplacing(float **inputs, float **outputs, VstIn
createDenoiseState();
}

// Mono in/out only
float *inChannel0 = inputs[0];
float *outChannel0 = outputs[0];

// Good case, we can copy less data around and rnnoise lib is built for it
if (sampleFrames == k_denoiseFrameSize) {
m_inputBuffer.resize(sampleFrames);

for (size_t i = 0; i < sampleFrames; i++) {
m_inputBuffer[i] = inChannel0[i] * std::numeric_limits<short>::max();
m_inputBuffer[i] = in[i] * std::numeric_limits<short>::max();
}

rnnoise_process_frame(m_denoiseState.get(), outChannel0, &m_inputBuffer[0]);
rnnoise_process_frame(m_denoiseState.get(), out, &m_inputBuffer[0]);

for (size_t i = 0; i < sampleFrames; i++) {
outChannel0[i] /= std::numeric_limits<short>::max();
out[i] /= std::numeric_limits<short>::max();
}
} else {
m_inputBuffer.resize(m_inputBuffer.size() + sampleFrames);
Expand All @@ -50,7 +45,7 @@ void RnNoiseAudioEffect::processReplacing(float **inputs, float **outputs, VstIn
{
float *inputBufferWriteStart = (m_inputBuffer.end() - sampleFrames).base();
for (size_t i = 0; i < sampleFrames; i++) {
inputBufferWriteStart[i] = inChannel0[i] * std::numeric_limits<short>::max();
inputBufferWriteStart[i] = in[i] * std::numeric_limits<short>::max();
}
}

Expand All @@ -76,35 +71,19 @@ void RnNoiseAudioEffect::processReplacing(float **inputs, float **outputs, VstIn

const size_t toCopyIntoOutput = std::min(m_outputBuffer.size(), static_cast<size_t>(sampleFrames));

std::memcpy(outChannel0, &m_outputBuffer[0], toCopyIntoOutput * sizeof(float));
std::memcpy(out, &m_outputBuffer[0], toCopyIntoOutput * sizeof(float));

m_inputBuffer.erase(m_inputBuffer.begin(), m_inputBuffer.begin() + framesToProcess);
m_outputBuffer.erase(m_outputBuffer.begin(), m_outputBuffer.begin() + toCopyIntoOutput);

if (toCopyIntoOutput < sampleFrames) {
std::fill(outChannel0 + toCopyIntoOutput, outChannel0 + sampleFrames, 0.f);
std::fill(out + toCopyIntoOutput, out + sampleFrames, 0.f);
}
}
}

VstInt32 RnNoiseAudioEffect::startProcess() {
createDenoiseState();

return AudioEffectX::startProcess();
}

VstInt32 RnNoiseAudioEffect::stopProcess() {
m_denoiseState.reset();

return AudioEffectX::stopProcess();
}

void RnNoiseAudioEffect::createDenoiseState() {
void RnNoiseCommonPlugin::createDenoiseState() {
m_denoiseState = std::shared_ptr<DenoiseState>(rnnoise_create(), [](DenoiseState *st) {
rnnoise_destroy(st);
});
}

extern AudioEffect *createEffectInstance(audioMasterCallback audioMaster) {
return new RnNoiseAudioEffect(audioMaster, 0, 0);
}
47 changes: 47 additions & 0 deletions src/lv2_plugin/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
cmake_minimum_required(VERSION 3.6)
project(rnnoise_lv2_plugin LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 14)

include_directories(/)

set(PROJECT_ROOT ../../../)

set(LV2_INTERFACE_SRC
lv2/lv2plug.in/ns/lv2core/lv2.h
lv2/lv2plug.in/ns/lv2core/lv2_util.h
lv2/lv2plug.in/ns/lv2core/Plugin.hpp
lv2/lv2plug.in/ns/lv2core/Lib.hpp)

set(LV2_IMPL_SRC
RnNoiseLv2Plugin.h
RnNoiseLv2Plugin.cpp
RnNoiseLv2Lib.h
RnNoiseLv2Lib.cpp)

set(LV2_PLUGIN_SOURCES
${LV2_INTERFACE_SRC}
${LV2_IMPL_SRC})

function(build bit)
set(LV2_TARGET_X${bit} rnnoise_lv2_x${bit})

add_library(${LV2_TARGET_X${bit}} SHARED ${LV2_PLUGIN_SOURCES})

target_link_libraries(${LV2_TARGET_X${bit}} RnNoisePluginCommon "-static -static-libgcc -static-libstdc++ -m${bit}")

set(X${bit}_COMPILE_OPTIONS
"-m${bit};"
"$<$<CONFIG:RELEASE>:-O3;>")

target_compile_options(${LV2_TARGET_X${bit}} PRIVATE ${X${bit}_COMPILE_OPTIONS})

set_target_properties(${LV2_TARGET_X${bit}} PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${PROJECT_ROOT}/bin/x${bit}/rnnoise.lv2")

configure_file(resources/manifest_x${bit}.ttl ${PROJECT_ROOT}/bin/x${bit}/rnnoise.lv2/manifest.ttl)
configure_file(resources/rnnoise.ttl ${PROJECT_ROOT}/bin/x${bit}/rnnoise.lv2/rnnoise.ttl)
endfunction()

build(32)
build(64)
19 changes: 19 additions & 0 deletions src/lv2_plugin/RnNoiseLv2Lib.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include "RnNoiseLv2Lib.h"

LV2_SYMBOL_EXTERN const LV2_Lib_Descriptor *
lv2_lib_descriptor(const char *bundle_path,
const LV2_Feature *const *features) {
return new RnNoiseLib(bundle_path, features);
}

RnNoiseLib::RnNoiseLib(const char *bundle_path, const LV2_Feature *const *features)
: Lib(bundle_path, features),
m_rnNoisePluginDescriptor("https://github.com/werman/noise-suppression-for-voice") {
}

const LV2_Descriptor *RnNoiseLib::get_plugin(uint32_t index) {
if (index == 0) {
return &m_rnNoisePluginDescriptor;
}
return nullptr;
}
20 changes: 20 additions & 0 deletions src/lv2_plugin/RnNoiseLv2Lib.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#pragma once

#include <memory>
#include "lv2/lv2plug.in/ns/lv2core/Lib.hpp"

#include "RnNoiseLv2Plugin.h"

class RnNoiseLib : public lv2::Lib {
public:
RnNoiseLib(const char *bundle_path, const LV2_Feature *const *features);

const LV2_Descriptor *get_plugin(uint32_t index) override;

private:

const lv2::Descriptor<RnNoiseLv2Plugin> m_rnNoisePluginDescriptor;
};



Loading

0 comments on commit fb46246

Please sign in to comment.