Files
-
blinds / hardware_design / pcb / blinds_v60.brd
-
blinds / hardware_design / pcb / blinds_v60.sch
-
braids / hardware_design / pcb / braids_v50.brd
-
braids / hardware_design / pcb / braids_v50.sch
-
branches / hardware_design / pcb / branches_v40.brd
-
branches / hardware_design / pcb / branches_v40.sch
-
clouds / hardware_design / pcb / clouds_v30.brd
-
clouds / hardware_design / pcb / clouds_v30.sch
-
ears / hardware_design / panel / ears_panel_v30.brd
-
ears / hardware_design / panel / ears_panel_v30.sch
-
ears / hardware_design / pcb / ears_v40.brd
-
ears / hardware_design / pcb / ears_v40.sch
-
edges / hardware_design / pcb / edges_expander_v01.brd
-
edges / hardware_design / pcb / edges_expander_v01.sch
-
edges / hardware_design / pcb / edges_v20.brd
-
edges / hardware_design / pcb / edges_v20.sch
-
elements / hardware_design / pcb / elements_v02.brd
-
elements / hardware_design / pcb / elements_v02.sch
-
frames / hardware_design / pcb / frames_v03.brd
-
frames / hardware_design / pcb / frames_v03.sch
-
grids / hardware_design / pcb / grids_v02.brd
-
grids / hardware_design / pcb / grids_v02.sch
-
kinks / hardware_design / pcb / kinks_v41.brd
-
kinks / hardware_design / pcb / kinks_v41.sch
-
links / hardware_design / pcb / links_v40.brd
-
links / hardware_design / pcb / links_v40.sch
-
marbles / hardware_design / pcb / marbles_v70.brd
-
marbles / hardware_design / pcb / marbles_v70.sch
-
peaks / hardware_design / pcb / peaks_v30.brd
-
peaks / hardware_design / pcb / peaks_v30.sch
-
plaits / hardware_design / pcb / plaits_v50.brd
-
plaits / hardware_design / pcb / plaits_v50.sch
-
rings / hardware_design / pcb / rings_v30.brd
-
rings / hardware_design / pcb / rings_v30.sch
-
ripples / hardware_design / pcb / ripples_v40.brd
-
ripples / hardware_design / pcb / ripples_v40.sch
-
shades / hardware_design / pcb / shades_v30.brd
-
shades / hardware_design / pcb / shades_v30.sch
-
shelves / hardware_design / pcb / shelves_expander_v10.brd
-
shelves / hardware_design / pcb / shelves_expander_v10.sch
-
shelves / hardware_design / pcb / shelves_v05.brd
-
shelves / hardware_design / pcb / shelves_v05.sch
-
stages / hardware_design / pcb / stages_v70.brd
-
stages / hardware_design / pcb / stages_v70.sch
-
streams / hardware_design / pcb / streams_v02_bargraph.brd
-
streams / hardware_design / pcb / streams_v02_bargraph.sch
-
streams / hardware_design / pcb / streams_v05.brd
-
streams / hardware_design / pcb / streams_v05.sch
-
tides / hardware_design / pcb / tides_v40.brd
-
tides / hardware_design / pcb / tides_v40.sch
-
veils / hardware_design / pcb / veils_v40.brd
-
veils / hardware_design / pcb / veils_v40.sch
-
volts / hardware_design / pcb / volts_v01.brd
-
volts / hardware_design / pcb / volts_v01.sch
-
warps / hardware_design / pcb / warps_v30.brd
-
warps / hardware_design / pcb / warps_v30.sch
-
yarns / hardware_design / pcb / yarns_v03.brd
-
yarns / hardware_design / pcb / yarns_v03.sch
Last update 6 years 1 month
by
Olivier Gillet
modulator.h// Copyright 2014 Olivier Gillet. // // Author: Olivier Gillet (ol.gillet@gmail.com) // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. // // See http://creativecommons.org/licenses/MIT/ for more information. // // ----------------------------------------------------------------------------- // // Modulator. #ifndef WARPS_DSP_MODULATOR_H_ #define WARPS_DSP_MODULATOR_H_ #include "stmlib/stmlib.h" #include "stmlib/dsp/dsp.h" #include "stmlib/dsp/parameter_interpolator.h" #include "warps/dsp/oscillator.h" #include "warps/dsp/parameters.h" #include "warps/dsp/quadrature_oscillator.h" #include "warps/dsp/quadrature_transform.h" #include "warps/dsp/sample_rate_converter.h" #include "warps/dsp/vocoder.h" #include "warps/resources.h" namespace warps { const size_t kMaxBlockSize = 96; const size_t kOversampling = 6; const size_t kNumOscillators = 1; typedef struct { short l; short r; } ShortFrame; typedef struct { float l; float r; } FloatFrame; class SaturatingAmplifier { public: SaturatingAmplifier() { } ~SaturatingAmplifier() { } void Init() { drive_ = 0.0f; } void Process( float drive, float limit, short* in, float* out, float* out_raw, size_t in_stride, size_t size) { // Process noise gate and compute raw output stmlib::ParameterInterpolator drive_modulation(&drive_, drive, size); float level = level_; for (size_t i = 0; i < size; ++i) { float s = static_cast<float>(*in) / 32768.0f; float error = s * s - level; level += error * (error > 0.0f ? 0.1f: 0.0001f); s *= level <= 0.0001f ? (1.0f / 0.0001f) * level : 1.0f; out[i] = s; out_raw[i] += s * drive_modulation.Next(); in += in_stride; } level_ = level; // Process overdrive / gain float drive_2 = drive * drive; float pre_gain_a = drive * 0.5f; float pre_gain_b = drive_2 * drive_2 * drive * 24.0f; float pre_gain = pre_gain_a + (pre_gain_b - pre_gain_a) * drive_2; float drive_squished = drive * (2.0f - drive); float post_gain = 1.0f / stmlib::SoftClip( 0.33f + drive_squished * (pre_gain - 0.33f)); stmlib::ParameterInterpolator pre_gain_modulation( &pre_gain_, pre_gain, size); stmlib::ParameterInterpolator post_gain_modulation( &post_gain_, post_gain, size); for (size_t i = 0; i < size; ++i) { float pre = pre_gain_modulation.Next() * out[i]; float post = stmlib::SoftClip(pre) * post_gain_modulation.Next(); out[i] = pre + (post - pre) * limit; } } private: float level_; float drive_; float post_gain_; float pre_gain_; float unclipped_gain_; DISALLOW_COPY_AND_ASSIGN(SaturatingAmplifier); }; enum XmodAlgorithm { ALGORITHM_XFADE, ALGORITHM_FOLD, ALGORITHM_ANALOG_RING_MODULATION, ALGORITHM_DIGITAL_RING_MODULATION, ALGORITHM_XOR, ALGORITHM_COMPARATOR, ALGORITHM_NOP, ALGORITHM_LAST }; class Modulator { public: typedef void (Modulator::*XmodFn)( float balance, float balance_end, float parameter, float parameter_end, const float* in_1, const float* in_2, float* out, size_t size); Modulator() { } ~Modulator() { } void Init(float sample_rate); void Process(ShortFrame* input, ShortFrame* output, size_t size); void ProcessEasterEgg(ShortFrame* input, ShortFrame* output, size_t size); inline Parameters* mutable_parameters() { return ¶meters_; } inline const Parameters& parameters() { return parameters_; } inline bool bypass() const { return bypass_; } inline void set_bypass(bool bypass) { bypass_ = bypass; } inline bool easter_egg() const { return easter_egg_; } inline void set_easter_egg(bool easter_egg) { easter_egg_ = easter_egg; } private: template<XmodAlgorithm algorithm_1, XmodAlgorithm algorithm_2> void ProcessXmod( float balance, float balance_end, float parameter, float parameter_end, const float* in_1, const float* in_2, float* out, size_t size) { float step = 1.0f / static_cast<float>(size); float parameter_increment = (parameter_end - parameter) * step; float balance_increment = (balance_end - balance) * step; while (size) { { const float x_1 = *in_1++; const float x_2 = *in_2++; float a = Xmod<algorithm_1>(x_1, x_2, parameter); float b = Xmod<algorithm_2>(x_1, x_2, parameter); *out++ = a + (b - a) * balance; parameter += parameter_increment; balance += balance_increment; size--; } { const float x_1 = *in_1++; const float x_2 = *in_2++; float a = Xmod<algorithm_1>(x_1, x_2, parameter); float b = Xmod<algorithm_2>(x_1, x_2, parameter); *out++ = a + (b - a) * balance; parameter += parameter_increment; balance += balance_increment; size--; } { const float x_1 = *in_1++; const float x_2 = *in_2++; float a = Xmod<algorithm_1>(x_1, x_2, parameter); float b = Xmod<algorithm_2>(x_1, x_2, parameter); *out++ = a + (b - a) * balance; parameter += parameter_increment; balance += balance_increment; size--; } } } template<XmodAlgorithm algorithm> static float Xmod(float x_1, float x_2, float parameter); static float Diode(float x); bool bypass_; bool easter_egg_; Parameters parameters_; Parameters previous_parameters_; SaturatingAmplifier amplifier_[2]; Oscillator xmod_oscillator_; Oscillator vocoder_oscillator_; QuadratureOscillator quadrature_oscillator_; SampleRateConverter<SRC_UP, kOversampling, 48> src_up_[2]; SampleRateConverter<SRC_DOWN, kOversampling, 48> src_down_; Vocoder vocoder_; QuadratureTransform quadrature_transform_[2]; float internal_modulation_[kMaxBlockSize]; float buffer_[3][kMaxBlockSize]; float src_buffer_[2][kMaxBlockSize * kOversampling]; float feedback_sample_; static XmodFn xmod_table_[]; DISALLOW_COPY_AND_ASSIGN(Modulator); }; } // namespace warps #endif // WARPS_DSP_MODULATOR_H_