Browse Source

Update to latest math.hpp API

tags/v0.6.0
Andrew Belt 7 years ago
parent
commit
74f16497de
10 changed files with 52 additions and 52 deletions
  1. +1
    -1
      eurorack
  2. +1
    -1
      src/Blinds.cpp
  3. +4
    -4
      src/Braids.cpp
  4. +12
    -12
      src/Clouds.cpp
  5. +3
    -3
      src/Elements.cpp
  6. +5
    -5
      src/Frames.cpp
  7. +10
    -10
      src/Rings.cpp
  8. +5
    -5
      src/Tides.cpp
  9. +3
    -3
      src/Veils.cpp
  10. +8
    -8
      src/Warps.cpp

+ 1
- 1
eurorack

@@ -1 +1 @@
Subproject commit eb6c8e9a5728a109ebe559aa78c4023be0b710e8
Subproject commit 916d9620b538e004c8d1480ce378152805979eba

+ 1
- 1
src/Blinds.cpp View File

@@ -55,7 +55,7 @@ void Blinds::step() {
for (int i = 0; i < 4; i++) {
float g = params[GAIN1_PARAM + i].value;
g += params[MOD1_PARAM + i].value * inputs[CV1_INPUT + i].value / 5.0;
g = clampf(g, -2.0, 2.0);
g = clamp(g, -2.0f, 2.0f);
lights[CV1_POS_LIGHT + 2*i].setBrightnessSmooth(fmaxf(0.0, g));
lights[CV1_NEG_LIGHT + 2*i].setBrightnessSmooth(fmaxf(0.0, -g));
out += g * inputs[IN1_INPUT + i].normalize(5.0);


+ 4
- 4
src/Braids.cpp View File

@@ -112,7 +112,7 @@ void Braids::step() {
if (settings.meta_modulation) {
shape += roundf(fm / 10.0 * braids::MACRO_OSC_SHAPE_LAST_ACCESSIBLE_FROM_META);
}
settings.shape = clampi(shape, 0, braids::MACRO_OSC_SHAPE_LAST_ACCESSIBLE_FROM_META);
settings.shape = clamp(shape, 0, braids::MACRO_OSC_SHAPE_LAST_ACCESSIBLE_FROM_META);

// Setup oscillator from settings
osc.set_shape((braids::MacroOscillatorShape) settings.shape);
@@ -120,8 +120,8 @@ void Braids::step() {
// Set timbre/modulation
float timbre = params[TIMBRE_PARAM].value + params[MODULATION_PARAM].value * inputs[TIMBRE_INPUT].value / 5.0;
float modulation = params[COLOR_PARAM].value + inputs[COLOR_INPUT].value / 5.0;
int16_t param1 = rescalef(clampf(timbre, 0.0, 1.0), 0.0, 1.0, 0, INT16_MAX);
int16_t param2 = rescalef(clampf(modulation, 0.0, 1.0), 0.0, 1.0, 0, INT16_MAX);
int16_t param1 = rescale(clamp(timbre, 0.0f, 1.0f), 0.0f, 1.0f, 0, INT16_MAX);
int16_t param2 = rescale(clamp(modulation, 0.0f, 1.0f), 0.0f, 1.0f, 0, INT16_MAX);
osc.set_parameters(param1, param2);

// Set pitch
@@ -132,7 +132,7 @@ void Braids::step() {
pitchV += log2f(96000.0 / engineGetSampleRate());
int32_t pitch = (pitchV * 12.0 + 60) * 128;
pitch += jitter_source.Render(settings.vco_drift);
pitch = clampi(pitch, 0, 16383);
pitch = clamp(pitch, 0, 16383);
osc.set_pitch(pitch);

// TODO: add a sync input buffer (must be sample rate converted)


+ 12
- 12
src/Clouds.cpp View File

@@ -163,8 +163,8 @@ void Clouds::step() {

// We might not fill all of the input buffer if there is a deficiency, but this cannot be avoided due to imprecisions between the input and output SRC.
for (int i = 0; i < outLen; i++) {
input[i].l = clampf(inputFrames[i].samples[0] * 32767.0, -32768, 32767);
input[i].r = clampf(inputFrames[i].samples[1] * 32767.0, -32768, 32767);
input[i].l = clamp(inputFrames[i].samples[0] * 32767.0f, -32768.0f, 32767.0f);
input[i].r = clamp(inputFrames[i].samples[1] * 32767.0f, -32768.0f, 32767.0f);
}
}

@@ -177,34 +177,34 @@ void Clouds::step() {
p->trigger = triggered;
p->gate = triggered;
p->freeze = freeze || (inputs[FREEZE_INPUT].value >= 1.0);
p->position = clampf(params[POSITION_PARAM].value + inputs[POSITION_INPUT].value / 5.0, 0.0, 1.0);
p->size = clampf(params[SIZE_PARAM].value + inputs[SIZE_INPUT].value / 5.0, 0.0, 1.0);
p->pitch = clampf((params[PITCH_PARAM].value + inputs[PITCH_INPUT].value) * 12.0, -48.0, 48.0);
p->density = clampf(params[DENSITY_PARAM].value + inputs[DENSITY_INPUT].value / 5.0, 0.0, 1.0);
p->texture = clampf(params[TEXTURE_PARAM].value + inputs[TEXTURE_INPUT].value / 5.0, 0.0, 1.0);
p->position = clamp(params[POSITION_PARAM].value + inputs[POSITION_INPUT].value / 5.0f, 0.0f, 1.0f);
p->size = clamp(params[SIZE_PARAM].value + inputs[SIZE_INPUT].value / 5.0f, 0.0f, 1.0f);
p->pitch = clamp((params[PITCH_PARAM].value + inputs[PITCH_INPUT].value) * 12.0f, -48.0f, 48.0f);
p->density = clamp(params[DENSITY_PARAM].value + inputs[DENSITY_INPUT].value / 5.0f, 0.0f, 1.0f);
p->texture = clamp(params[TEXTURE_PARAM].value + inputs[TEXTURE_INPUT].value / 5.0f, 0.0f, 1.0f);
p->dry_wet = params[BLEND_PARAM].value;
p->stereo_spread = params[SPREAD_PARAM].value;
p->feedback = params[FEEDBACK_PARAM].value;
// TODO
// Why doesn't dry audio get reverbed?
p->reverb = params[REVERB_PARAM].value;
float blend = inputs[BLEND_INPUT].value / 5.0;
float blend = inputs[BLEND_INPUT].value / 5.0f;
switch (blendMode) {
case 0:
p->dry_wet += blend;
p->dry_wet = clampf(p->dry_wet, 0.0, 1.0);
p->dry_wet = clamp(p->dry_wet, 0.0f, 1.0f);
break;
case 1:
p->stereo_spread += blend;
p->stereo_spread = clampf(p->stereo_spread, 0.0, 1.0);
p->stereo_spread = clamp(p->stereo_spread, 0.0f, 1.0f);
break;
case 2:
p->feedback += blend;
p->feedback = clampf(p->feedback, 0.0, 1.0);
p->feedback = clamp(p->feedback, 0.0f, 1.0f);
break;
case 3:
p->reverb += blend;
p->reverb = clampf(p->reverb, 0.0, 1.0);
p->reverb = clamp(p->reverb, 0.0f, 1.0f);
break;
}



+ 3
- 3
src/Elements.cpp View File

@@ -161,7 +161,7 @@ void Elements::step() {
p->exciter_blow_level = params[BLOW_PARAM].value;
p->exciter_strike_level = params[STRIKE_PARAM].value;

#define BIND(_p, _m, _i) clampf(params[_p].value + 3.3*quadraticBipolar(params[_m].value)*inputs[_i].value/5.0, 0.0, 0.9995)
#define BIND(_p, _m, _i) clamp(params[_p].value + 3.3f*quadraticBipolar(params[_m].value)*inputs[_i].value/5.0f, 0.0f, 0.9995f)

p->exciter_bow_timbre = BIND(BOW_TIMBRE_PARAM, BOW_TIMBRE_MOD_PARAM, BOW_TIMBRE_MOD_INPUT);
p->exciter_blow_meta = BIND(FLOW_PARAM, FLOW_MOD_PARAM, FLOW_MOD_INPUT);
@@ -172,14 +172,14 @@ void Elements::step() {
p->resonator_brightness = BIND(BRIGHTNESS_PARAM, BRIGHTNESS_MOD_PARAM, BRIGHTNESS_MOD_INPUT);
p->resonator_damping = BIND(DAMPING_PARAM, DAMPING_MOD_PARAM, DAMPING_MOD_INPUT);
p->resonator_position = BIND(POSITION_PARAM, POSITION_MOD_PARAM, POSITION_MOD_INPUT);
p->space = clampf(params[SPACE_PARAM].value + params[SPACE_MOD_PARAM].value*inputs[SPACE_MOD_INPUT].value/5.0, 0.0, 2.0);
p->space = clamp(params[SPACE_PARAM].value + params[SPACE_MOD_PARAM].value*inputs[SPACE_MOD_INPUT].value/5.0f, 0.0f, 2.0f);

// Get performance inputs
elements::PerformanceState performance;
performance.note = 12.0*inputs[NOTE_INPUT].value + roundf(params[COARSE_PARAM].value) + params[FINE_PARAM].value + 69.0;
performance.modulation = 3.3*quarticBipolar(params[FM_PARAM].value) * 49.5 * inputs[FM_INPUT].value/5.0;
performance.gate = params[PLAY_PARAM].value >= 1.0 || inputs[GATE_INPUT].value >= 1.0;
performance.strength = clampf(1.0 - inputs[STRENGTH_INPUT].value/5.0, 0.0, 1.0);
performance.strength = clamp(1.0 - inputs[STRENGTH_INPUT].value/5.0f, 0.0f, 1.0f);

// Generate audio
part->Process(performance, blow, strike, main, aux, 16);


+ 5
- 5
src/Frames.cpp View File

@@ -151,8 +151,8 @@ void Frames::step() {

int32_t timestamp = params[FRAME_PARAM].value * 65535.0;
int32_t timestampMod = timestamp + params[MODULATION_PARAM].value * inputs[FRAME_INPUT].value / 10.0 * 65535.0;
timestamp = clampi(timestamp, 0, 65535);
timestampMod = clampi(timestampMod, 0, 65535);
timestamp = clamp(timestamp, 0, 65535);
timestampMod = clamp(timestampMod, 0, 65535);
int16_t nearestIndex = -1;
if (!poly_lfo_mode) {
nearestIndex = keyframer.FindNearestKeyframe(timestamp, 2048);
@@ -212,8 +212,8 @@ void Frames::step() {
// Simulate SSM2164
if (keyframer.mutable_settings(i)->response > 0) {
const float expBase = 200.0;
float expGain = rescalef(powf(expBase, gains[i]), 1.0, expBase, 0.0, 1.0);
gains[i] = crossf(gains[i], expGain, keyframer.mutable_settings(i)->response / 255.0);
float expGain = rescale(powf(expBase, gains[i]), 1.0f, expBase, 0.0f, 1.0f);
gains[i] = crossfade(gains[i], expGain, keyframer.mutable_settings(i)->response / 255.0f);
}
}

@@ -245,7 +245,7 @@ void Frames::step() {
}
}

outputs[MIX_OUTPUT].value = clampf(mix / 2.0, -10.0, 10.0);
outputs[MIX_OUTPUT].value = clamp(mix / 2.0, -10.0f, 10.0f);

// Set lights
for (int i = 0; i < 4; i++) {


+ 10
- 10
src/Rings.cpp View File

@@ -176,10 +176,10 @@ void Rings::step() {
// Patch
rings::Patch patch;
float structure = params[STRUCTURE_PARAM].value + 3.3*quadraticBipolar(params[STRUCTURE_MOD_PARAM].value)*inputs[STRUCTURE_MOD_INPUT].value/5.0;
patch.structure = clampf(structure, 0.0, 0.9995);
patch.brightness = clampf(params[BRIGHTNESS_PARAM].value + 3.3*quadraticBipolar(params[BRIGHTNESS_MOD_PARAM].value)*inputs[BRIGHTNESS_MOD_INPUT].value/5.0, 0.0, 1.0);
patch.damping = clampf(params[DAMPING_PARAM].value + 3.3*quadraticBipolar(params[DAMPING_MOD_PARAM].value)*inputs[DAMPING_MOD_INPUT].value/5.0, 0.0, 0.9995);
patch.position = clampf(params[POSITION_PARAM].value + 3.3*quadraticBipolar(params[POSITION_MOD_PARAM].value)*inputs[POSITION_MOD_INPUT].value/5.0, 0.0, 0.9995);
patch.structure = clamp(structure, 0.0f, 0.9995f);
patch.brightness = clamp(params[BRIGHTNESS_PARAM].value + 3.3*quadraticBipolar(params[BRIGHTNESS_MOD_PARAM].value)*inputs[BRIGHTNESS_MOD_INPUT].value/5.0, 0.0f, 1.0f);
patch.damping = clamp(params[DAMPING_PARAM].value + 3.3*quadraticBipolar(params[DAMPING_MOD_PARAM].value)*inputs[DAMPING_MOD_INPUT].value/5.0, 0.0f, 0.9995f);
patch.position = clamp(params[POSITION_PARAM].value + 3.3*quadraticBipolar(params[POSITION_MOD_PARAM].value)*inputs[POSITION_MOD_INPUT].value/5.0, 0.0f, 0.9995f);

// Performance
rings::PerformanceState performance_state;
@@ -189,8 +189,8 @@ void Rings::step() {
if (inputs[PITCH_INPUT].active) {
transpose = roundf(transpose);
}
performance_state.tonic = 12.0 + clampf(transpose, 0, 60.0);
performance_state.fm = clampf(48.0 * 3.3*quarticBipolar(params[FREQUENCY_MOD_PARAM].value) * inputs[FREQUENCY_MOD_INPUT].normalize(1.0)/5.0, -48.0, 48.0);
performance_state.tonic = 12.0 + clamp(transpose, 0.0f, 60.0f);
performance_state.fm = clamp(48.0 * 3.3*quarticBipolar(params[FREQUENCY_MOD_PARAM].value) * inputs[FREQUENCY_MOD_INPUT].normalize(1.0)/5.0, -48.0f, 48.0f);

performance_state.internal_exciter = !inputs[IN_INPUT].active;
performance_state.internal_strum = !inputs[STRUM_INPUT].active;
@@ -202,7 +202,7 @@ void Rings::step() {
lastStrum = strum;
strum = false;

performance_state.chord = clampf(roundf(structure * (rings::kNumChords - 1)), 0, rings::kNumChords - 1);
performance_state.chord = clamp((int) roundf(structure * (rings::kNumChords - 1)), 0, rings::kNumChords - 1);

// Process audio
float out[24];
@@ -237,11 +237,11 @@ void Rings::step() {
Frame<2> outputFrame = outputBuffer.shift();
// "Note that you need to insert a jack into each output to split the signals: when only one jack is inserted, both signals are mixed together."
if (outputs[ODD_OUTPUT].active && outputs[EVEN_OUTPUT].active) {
outputs[ODD_OUTPUT].value = clampf(outputFrame.samples[0], -1.0, 1.0)*5.0;
outputs[EVEN_OUTPUT].value = clampf(outputFrame.samples[1], -1.0, 1.0)*5.0;
outputs[ODD_OUTPUT].value = clamp(outputFrame.samples[0], -1.0, 1.0)*5.0;
outputs[EVEN_OUTPUT].value = clamp(outputFrame.samples[1], -1.0, 1.0)*5.0;
}
else {
float v = clampf(outputFrame.samples[0] + outputFrame.samples[1], -1.0, 1.0)*5.0;
float v = clamp(outputFrame.samples[0] + outputFrame.samples[1], -1.0, 1.0)*5.0;
outputs[ODD_OUTPUT].value = v;
outputs[EVEN_OUTPUT].value = v;
}


+ 5
- 5
src/Tides.cpp View File

@@ -132,12 +132,12 @@ void Tides::step() {
pitch += 60.0;
// Scale to the global sample rate
pitch += log2f(48000.0 / engineGetSampleRate()) * 12.0;
generator.set_pitch(clampf(pitch * 0x80, -0x8000, 0x7fff));
generator.set_pitch((int) clamp(pitch * 0x80, (float) -0x8000, (float) 0x7fff));

// Slope, smoothness, pitch
int16_t shape = clampf(params[SHAPE_PARAM].value + inputs[SHAPE_INPUT].value / 5.0, -1.0, 1.0) * 0x7fff;
int16_t slope = clampf(params[SLOPE_PARAM].value + inputs[SLOPE_INPUT].value / 5.0, -1.0, 1.0) * 0x7fff;
int16_t smoothness = clampf(params[SMOOTHNESS_PARAM].value + inputs[SMOOTHNESS_INPUT].value / 5.0, -1.0, 1.0) * 0x7fff;
int16_t shape = clamp(params[SHAPE_PARAM].value + inputs[SHAPE_INPUT].value / 5.0f, -1.0f, 1.0f) * 0x7fff;
int16_t slope = clamp(params[SLOPE_PARAM].value + inputs[SLOPE_INPUT].value / 5.0f, -1.0f, 1.0f) * 0x7fff;
int16_t smoothness = clamp(params[SMOOTHNESS_PARAM].value + inputs[SMOOTHNESS_INPUT].value / 5.0f, -1.0f, 1.0f) * 0x7fff;
generator.set_shape(shape);
generator.set_slope(slope);
generator.set_smoothness(smoothness);
@@ -152,7 +152,7 @@ void Tides::step() {
}

// Level
uint16_t level = clampf(inputs[LEVEL_INPUT].normalize(8.0) / 8.0, 0.0, 1.0) * 0xffff;
uint16_t level = clamp(inputs[LEVEL_INPUT].normalize(8.0) / 8.0f, 0.0f, 1.0f) * 0xffff;
if (level < 32)
level = 0;



+ 3
- 3
src/Veils.cpp View File

@@ -52,10 +52,10 @@ void Veils::step() {
float in = inputs[IN1_INPUT + i].value * params[GAIN1_PARAM + i].value;
if (inputs[CV1_INPUT + i].active) {
float linear = fmaxf(inputs[CV1_INPUT + i].value / 5.0, 0.0);
linear = clampf(linear, 0.0, 2.0);
linear = clamp(linear, 0.0f, 2.0f);
const float base = 200.0;
float exponential = rescalef(powf(base, linear / 2.0), 1.0, base, 0.0, 10.0);
in *= crossf(exponential, linear, params[RESPONSE1_PARAM + i].value);
float exponential = rescale(powf(base, linear / 2.0f), 1.0f, base, 0.0f, 10.0f);
in *= crossfade(exponential, linear, params[RESPONSE1_PARAM + i].value);
}
out += in;
lights[OUT1_POS_LIGHT + 2*i].setBrightnessSmooth(fmaxf(0.0, out / 5.0));


+ 8
- 8
src/Warps.cpp View File

@@ -90,9 +90,9 @@ void Warps::step() {
if (++frame >= 60) {
frame = 0;

p->channel_drive[0] = clampf(params[LEVEL1_PARAM].value + inputs[LEVEL1_INPUT].value / 5.0, 0.0, 1.0);
p->channel_drive[1] = clampf(params[LEVEL2_PARAM].value + inputs[LEVEL2_INPUT].value / 5.0, 0.0, 1.0);
p->modulation_algorithm = clampf(params[ALGORITHM_PARAM].value / 8.0 + inputs[ALGORITHM_INPUT].value / 5.0, 0.0, 1.0);
p->channel_drive[0] = clamp(params[LEVEL1_PARAM].value + inputs[LEVEL1_INPUT].value / 5.0f, 0.0f, 1.0f);
p->channel_drive[1] = clamp(params[LEVEL2_PARAM].value + inputs[LEVEL2_INPUT].value / 5.0f, 0.0f, 1.0f);
p->modulation_algorithm = clamp(params[ALGORITHM_PARAM].value / 8.0f + inputs[ALGORITHM_INPUT].value / 5.0f, 0.0f, 1.0f);

{
// TODO
@@ -103,19 +103,19 @@ void Warps::step() {
lights[ALGORITHM_LIGHT + 2].setBrightness(algorithmColor.b);
}

p->modulation_parameter = clampf(params[TIMBRE_PARAM].value + inputs[TIMBRE_INPUT].value / 5.0, 0.0, 1.0);
p->modulation_parameter = clamp(params[TIMBRE_PARAM].value + inputs[TIMBRE_INPUT].value / 5.0f, 0.0f, 1.0f);

p->frequency_shift_pot = params[ALGORITHM_PARAM].value / 8.0;
p->frequency_shift_cv = clampf(inputs[ALGORITHM_INPUT].value / 5.0, -1.0, 1.0);
p->frequency_shift_cv = clamp(inputs[ALGORITHM_INPUT].value / 5.0f, -1.0f, 1.0f);
p->phase_shift = p->modulation_algorithm;
p->note = 60.0 * params[LEVEL1_PARAM].value + 12.0 * inputs[LEVEL1_INPUT].normalize(2.0) + 12.0;
p->note += log2f(96000.0 / engineGetSampleRate()) * 12.0;
p->note += log2f(96000.0f * engineGetSampleTime()) * 12.0f;

modulator.Process(inputFrames, outputFrames, 60);
}

inputFrames[frame].l = clampf(inputs[CARRIER_INPUT].value / 16.0 * 0x8000, -0x8000, 0x7fff);
inputFrames[frame].r = clampf(inputs[MODULATOR_INPUT].value / 16.0 * 0x8000, -0x8000, 0x7fff);
inputFrames[frame].l = clamp((int) (inputs[CARRIER_INPUT].value / 16.0 * 0x8000), -0x8000, 0x7fff);
inputFrames[frame].r = clamp((int) (inputs[MODULATOR_INPUT].value / 16.0 * 0x8000), -0x8000, 0x7fff);
outputs[MODULATOR_OUTPUT].value = (float)outputFrames[frame].l / 0x8000 * 5.0;
outputs[AUX_OUTPUT].value = (float)outputFrames[frame].r / 0x8000 * 5.0;
}


Loading…
Cancel
Save