Logue trance gate modulation effect
unknown
c_cpp
4 months ago
2.7 kB
27
Indexable
#include "usermodfx.h" #include "simplelfo.hpp" // Check if k_samplerate_recipf is already defined #ifndef k_samplerate_recipf // Set 1/Fs based on a standard sample rate (e.g., 48000 Hz) constexpr float k_samplerate = 48000.0f; constexpr float k_samplerate_recipf = 1.0f / k_samplerate; #endif // An LFO for the gate effect static dsp::SimpleLFO lfo; static float mod_a = 0.0f; // Modifier a for gate spread static float mod_b = 0.0f; // Modifier b for gate depth void MODFX_INIT(uint32_t platform, uint32_t api) { lfo.reset(); lfo.setF0(2.0f, k_samplerate_recipf); // Initial frequency } // Function to handle note-on events extern "C" void OSC_NOTEON() { lfo.reset(); // Reset the LFO on each note-on event } void MODFX_PROCESS(const float *main_xn, float *main_yn, const float *sub_xn, float *sub_yn, uint32_t frames) { // Get current BPM from the unit and convert to BPM as float uint16_t bpm10 = _fx_get_bpm(); // BPM x10 for 1 decimal precision float bpm = bpm10 / 10.0f; // Divide by 10 for correct BPM const float beat_duration = 60.0f / bpm; // Calculate the length of one beat in seconds float note_duration = beat_duration / 1.0f; // 1/4 equals a 16th note // Set LFO frequency based on note duration float lfo_frequency = 1.0f / note_duration; lfo.setF0(lfo_frequency, k_samplerate_recipf); for (uint32_t i = 0; i < (frames * 2); i += 2) { lfo.cycle(); float gateL = fmax(lfo.triangle_bi(), 0); // just the positive triangles gateL = gateL * 20.0f; // scale up the triangles gateL = fmin(gateL, 1); // limit to 1 float gateR = fmax(lfo.triangle_bi_off(mod_a), 0); // just the positive triangles gateR = gateR * 20.0f; // scale up the triangles gateR = fmin(gateR, 1); // limit to 1 // Set the depth using parameter b gateL = fmax(gateL, 1.0f - mod_b); gateR = fmax(gateR, 1.0f - mod_b); int left_ix = i; int right_ix = i + 1; main_yn[left_ix] = main_xn[left_ix] * gateL; main_yn[right_ix] = main_xn[right_ix] * gateR; #ifdef PROLOGUE_PLATFORM sub_yn[i] = sub_xn[i] * gate; #endif } } void MODFX_PARAM(uint8_t index, int32_t value) { const float valf = q31_to_f32(value); switch (index) { case 0: // Parameter 1: Adjust stereo spread of the gate effect { mod_a = valf; break; } case 1: // Parameter 2: Adjust the gate depth mod_b = valf; break; default: break; } }
Editor is loading...
Leave a Comment