diff --git a/app/src/main/cpp/CMakeLists.txt b/app/src/main/cpp/CMakeLists.txt index 39bdefe..4656574 100644 --- a/app/src/main/cpp/CMakeLists.txt +++ b/app/src/main/cpp/CMakeLists.txt @@ -20,6 +20,7 @@ effects/Effect.cpp effects/LowPass.cpp effects/Noise.cpp + effects/Distortion.cpp ) find_library( diff --git a/app/src/main/cpp/CMakeLists.txt b/app/src/main/cpp/CMakeLists.txt index 39bdefe..4656574 100644 --- a/app/src/main/cpp/CMakeLists.txt +++ b/app/src/main/cpp/CMakeLists.txt @@ -20,6 +20,7 @@ effects/Effect.cpp effects/LowPass.cpp effects/Noise.cpp + effects/Distortion.cpp ) find_library( diff --git a/app/src/main/cpp/Instrument.cpp b/app/src/main/cpp/Instrument.cpp index d8b0f5d..5c91ad6 100644 --- a/app/src/main/cpp/Instrument.cpp +++ b/app/src/main/cpp/Instrument.cpp @@ -3,6 +3,7 @@ #include "waveforms/Sine.h" #include "waveforms/Square.h" #include "waveforms/Triangle.h" +#include "effects/Distortion.h" Instrument::Instrument(AudioHost *host) { this->host = host; @@ -15,6 +16,9 @@ auto *noise = new Noise(); noise->host = host; effects.push_back(noise); + auto *distortion = new Distortion(); + distortion->host = host; + effects.push_back(distortion); } void multiply(float *target, float *modulation, uint32_t size) { diff --git a/app/src/main/cpp/CMakeLists.txt b/app/src/main/cpp/CMakeLists.txt index 39bdefe..4656574 100644 --- a/app/src/main/cpp/CMakeLists.txt +++ b/app/src/main/cpp/CMakeLists.txt @@ -20,6 +20,7 @@ effects/Effect.cpp effects/LowPass.cpp effects/Noise.cpp + effects/Distortion.cpp ) find_library( diff --git a/app/src/main/cpp/Instrument.cpp b/app/src/main/cpp/Instrument.cpp index d8b0f5d..5c91ad6 100644 --- a/app/src/main/cpp/Instrument.cpp +++ b/app/src/main/cpp/Instrument.cpp @@ -3,6 +3,7 @@ #include "waveforms/Sine.h" #include "waveforms/Square.h" #include "waveforms/Triangle.h" +#include "effects/Distortion.h" Instrument::Instrument(AudioHost *host) { this->host = host; @@ -15,6 +16,9 @@ auto *noise = new Noise(); noise->host = host; effects.push_back(noise); + auto *distortion = new Distortion(); + distortion->host = host; + effects.push_back(distortion); } void multiply(float *target, float *modulation, uint32_t size) { diff --git a/app/src/main/cpp/JavaFunctions.cpp b/app/src/main/cpp/JavaFunctions.cpp index 2cc9efa..488e5f0 100644 --- a/app/src/main/cpp/JavaFunctions.cpp +++ b/app/src/main/cpp/JavaFunctions.cpp @@ -116,8 +116,8 @@ std::advance(source, from); auto destination = instrument->effects.begin(); std::advance(destination, to); - if (instrument->effects.size() == to + 1) { - destination = instrument->effects.end(); + if (from < to) { + std::advance(destination, 1); } instrument->effects.splice(destination, instrument->effects, source); } diff --git a/app/src/main/cpp/CMakeLists.txt b/app/src/main/cpp/CMakeLists.txt index 39bdefe..4656574 100644 --- a/app/src/main/cpp/CMakeLists.txt +++ b/app/src/main/cpp/CMakeLists.txt @@ -20,6 +20,7 @@ effects/Effect.cpp effects/LowPass.cpp effects/Noise.cpp + effects/Distortion.cpp ) find_library( diff --git a/app/src/main/cpp/Instrument.cpp b/app/src/main/cpp/Instrument.cpp index d8b0f5d..5c91ad6 100644 --- a/app/src/main/cpp/Instrument.cpp +++ b/app/src/main/cpp/Instrument.cpp @@ -3,6 +3,7 @@ #include "waveforms/Sine.h" #include "waveforms/Square.h" #include "waveforms/Triangle.h" +#include "effects/Distortion.h" Instrument::Instrument(AudioHost *host) { this->host = host; @@ -15,6 +16,9 @@ auto *noise = new Noise(); noise->host = host; effects.push_back(noise); + auto *distortion = new Distortion(); + distortion->host = host; + effects.push_back(distortion); } void multiply(float *target, float *modulation, uint32_t size) { diff --git a/app/src/main/cpp/JavaFunctions.cpp b/app/src/main/cpp/JavaFunctions.cpp index 2cc9efa..488e5f0 100644 --- a/app/src/main/cpp/JavaFunctions.cpp +++ b/app/src/main/cpp/JavaFunctions.cpp @@ -116,8 +116,8 @@ std::advance(source, from); auto destination = instrument->effects.begin(); std::advance(destination, to); - if (instrument->effects.size() == to + 1) { - destination = instrument->effects.end(); + if (from < to) { + std::advance(destination, 1); } instrument->effects.splice(destination, instrument->effects, source); } diff --git a/app/src/main/cpp/effects/Distortion.cpp b/app/src/main/cpp/effects/Distortion.cpp new file mode 100644 index 0000000..5f65da5 --- /dev/null +++ b/app/src/main/cpp/effects/Distortion.cpp @@ -0,0 +1,16 @@ +#include "Distortion.h" + +void Distortion::update() { +} + +void Distortion::doRender(uint32_t sampleCount) { + for (uint32_t i = 0; i < sampleCount; i++) { + float value = input[i] * parameter1; + if (value > 1.f) { + value = 1.f; + } else if (value < -1.f) { + value = -1.f; + } + buffer[i] = value; + } +} \ No newline at end of file diff --git a/app/src/main/cpp/CMakeLists.txt b/app/src/main/cpp/CMakeLists.txt index 39bdefe..4656574 100644 --- a/app/src/main/cpp/CMakeLists.txt +++ b/app/src/main/cpp/CMakeLists.txt @@ -20,6 +20,7 @@ effects/Effect.cpp effects/LowPass.cpp effects/Noise.cpp + effects/Distortion.cpp ) find_library( diff --git a/app/src/main/cpp/Instrument.cpp b/app/src/main/cpp/Instrument.cpp index d8b0f5d..5c91ad6 100644 --- a/app/src/main/cpp/Instrument.cpp +++ b/app/src/main/cpp/Instrument.cpp @@ -3,6 +3,7 @@ #include "waveforms/Sine.h" #include "waveforms/Square.h" #include "waveforms/Triangle.h" +#include "effects/Distortion.h" Instrument::Instrument(AudioHost *host) { this->host = host; @@ -15,6 +16,9 @@ auto *noise = new Noise(); noise->host = host; effects.push_back(noise); + auto *distortion = new Distortion(); + distortion->host = host; + effects.push_back(distortion); } void multiply(float *target, float *modulation, uint32_t size) { diff --git a/app/src/main/cpp/JavaFunctions.cpp b/app/src/main/cpp/JavaFunctions.cpp index 2cc9efa..488e5f0 100644 --- a/app/src/main/cpp/JavaFunctions.cpp +++ b/app/src/main/cpp/JavaFunctions.cpp @@ -116,8 +116,8 @@ std::advance(source, from); auto destination = instrument->effects.begin(); std::advance(destination, to); - if (instrument->effects.size() == to + 1) { - destination = instrument->effects.end(); + if (from < to) { + std::advance(destination, 1); } instrument->effects.splice(destination, instrument->effects, source); } diff --git a/app/src/main/cpp/effects/Distortion.cpp b/app/src/main/cpp/effects/Distortion.cpp new file mode 100644 index 0000000..5f65da5 --- /dev/null +++ b/app/src/main/cpp/effects/Distortion.cpp @@ -0,0 +1,16 @@ +#include "Distortion.h" + +void Distortion::update() { +} + +void Distortion::doRender(uint32_t sampleCount) { + for (uint32_t i = 0; i < sampleCount; i++) { + float value = input[i] * parameter1; + if (value > 1.f) { + value = 1.f; + } else if (value < -1.f) { + value = -1.f; + } + buffer[i] = value; + } +} \ No newline at end of file diff --git a/app/src/main/cpp/effects/Distortion.h b/app/src/main/cpp/effects/Distortion.h new file mode 100644 index 0000000..3edb70c --- /dev/null +++ b/app/src/main/cpp/effects/Distortion.h @@ -0,0 +1,14 @@ +#ifndef MUSIC_DISTORTION_H +#define MUSIC_DISTORTION_H + +#include "Effect.h" + +class Distortion : public Effect { +public: + void update(); + + void doRender(uint32_t sampleCount); +}; + + +#endif diff --git a/app/src/main/cpp/CMakeLists.txt b/app/src/main/cpp/CMakeLists.txt index 39bdefe..4656574 100644 --- a/app/src/main/cpp/CMakeLists.txt +++ b/app/src/main/cpp/CMakeLists.txt @@ -20,6 +20,7 @@ effects/Effect.cpp effects/LowPass.cpp effects/Noise.cpp + effects/Distortion.cpp ) find_library( diff --git a/app/src/main/cpp/Instrument.cpp b/app/src/main/cpp/Instrument.cpp index d8b0f5d..5c91ad6 100644 --- a/app/src/main/cpp/Instrument.cpp +++ b/app/src/main/cpp/Instrument.cpp @@ -3,6 +3,7 @@ #include "waveforms/Sine.h" #include "waveforms/Square.h" #include "waveforms/Triangle.h" +#include "effects/Distortion.h" Instrument::Instrument(AudioHost *host) { this->host = host; @@ -15,6 +16,9 @@ auto *noise = new Noise(); noise->host = host; effects.push_back(noise); + auto *distortion = new Distortion(); + distortion->host = host; + effects.push_back(distortion); } void multiply(float *target, float *modulation, uint32_t size) { diff --git a/app/src/main/cpp/JavaFunctions.cpp b/app/src/main/cpp/JavaFunctions.cpp index 2cc9efa..488e5f0 100644 --- a/app/src/main/cpp/JavaFunctions.cpp +++ b/app/src/main/cpp/JavaFunctions.cpp @@ -116,8 +116,8 @@ std::advance(source, from); auto destination = instrument->effects.begin(); std::advance(destination, to); - if (instrument->effects.size() == to + 1) { - destination = instrument->effects.end(); + if (from < to) { + std::advance(destination, 1); } instrument->effects.splice(destination, instrument->effects, source); } diff --git a/app/src/main/cpp/effects/Distortion.cpp b/app/src/main/cpp/effects/Distortion.cpp new file mode 100644 index 0000000..5f65da5 --- /dev/null +++ b/app/src/main/cpp/effects/Distortion.cpp @@ -0,0 +1,16 @@ +#include "Distortion.h" + +void Distortion::update() { +} + +void Distortion::doRender(uint32_t sampleCount) { + for (uint32_t i = 0; i < sampleCount; i++) { + float value = input[i] * parameter1; + if (value > 1.f) { + value = 1.f; + } else if (value < -1.f) { + value = -1.f; + } + buffer[i] = value; + } +} \ No newline at end of file diff --git a/app/src/main/cpp/effects/Distortion.h b/app/src/main/cpp/effects/Distortion.h new file mode 100644 index 0000000..3edb70c --- /dev/null +++ b/app/src/main/cpp/effects/Distortion.h @@ -0,0 +1,14 @@ +#ifndef MUSIC_DISTORTION_H +#define MUSIC_DISTORTION_H + +#include "Effect.h" + +class Distortion : public Effect { +public: + void update(); + + void doRender(uint32_t sampleCount); +}; + + +#endif diff --git a/app/src/main/java/com/lukas/music/instruments/effect/EffectType.kt b/app/src/main/java/com/lukas/music/instruments/effect/EffectType.kt index 963d4e3..8b90ec5 100644 --- a/app/src/main/java/com/lukas/music/instruments/effect/EffectType.kt +++ b/app/src/main/java/com/lukas/music/instruments/effect/EffectType.kt @@ -22,11 +22,17 @@ "cutoff: ${it.value.format(1)} octaves" } )), - Noise("noise", + Noise( + "noise", arrayOf( null ) - ) + ), + Distortion("distortion", arrayOf( + EffectParameterDescription(1f, 4f, 1f) { + "strength: ${it.value.format(1)}x" + } + )) ; override fun toString(): String {