Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds Kammerl Beat Repeat to Parasites #1

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
82 changes: 60 additions & 22 deletions clouds/cv_scaler.cc
Expand Up @@ -8,18 +8,18 @@
// 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.
//
// -----------------------------------------------------------------------------
Expand Down Expand Up @@ -76,20 +76,25 @@ void CvScaler::Init(CalibrationData* calibration_data) {
blend_parameter_ = BLEND_PARAMETER_DRY_WET;
blend_knob_quantized_ = -1.0f;
blend_knob_touched_ = false;

fill(&previous_trigger_[0], &previous_trigger_[kAdcLatency], false);
fill(&previous_gate_[0], &previous_gate_[kAdcLatency], false);
}

void CvScaler::UpdateBlendParameters(float knob_value, float cv) {
// Update the blending settings (base value and modulation) from the
float CvScaler::UpdateBlendParameters(float knob_value, float cv) {
// Update the blending settings (base value and modulation) from the
// Blend knob and CV.
float blend_smoothed_cv = 0.0f;

for (int32_t i = 0; i < BLEND_PARAMETER_LAST; ++i) {
float target = i == blend_parameter_ ? cv : 0.0f;
float coefficient = i == blend_parameter_ ? 0.1f : 0.002f;
blend_mod_[i] += coefficient * (target - blend_mod_[i]);
if (i==blend_parameter_) {
blend_smoothed_cv = blend_mod_[i];
}
}

// Determines if the blend knob has been touched.
if (blend_knob_quantized_ == -1.0f) {
blend_knob_quantized_ = knob_value;
Expand All @@ -98,13 +103,13 @@ void CvScaler::UpdateBlendParameters(float knob_value, float cv) {
if (blend_knob_touched_) {
blend_knob_quantized_ = knob_value;
}

if (previous_blend_knob_value_ == -1.0f) {
blend_[blend_parameter_] = knob_value;
previous_blend_knob_value_ = knob_value;
blend_knob_origin_ = knob_value;
}

float parameter_value = blend_[blend_parameter_];
float delta = knob_value - previous_blend_knob_value_;
float skew_ratio = delta > 0.0f
Expand All @@ -120,12 +125,14 @@ void CvScaler::UpdateBlendParameters(float knob_value, float cv) {
CONSTRAIN(parameter_value, 0.0f, 1.0f);
blend_[blend_parameter_] = parameter_value;
previous_blend_knob_value_ = knob_value;

return parameter_value + blend_smoothed_cv;
}

void CvScaler::Read(Parameters* parameters) {
for (size_t i = 0; i < ADC_CHANNEL_LAST; ++i) {
const CvTransformation& transformation = transformations_[i];

float value = adc_.float_value(i);
if (transformation.flip) {
value = 1.0f - value;
Expand All @@ -136,26 +143,53 @@ void CvScaler::Read(Parameters* parameters) {
smoothed_adc_value_[i] += transformation.filter_coefficient * \
(value - smoothed_adc_value_[i]);
}

parameters->position = smoothed_adc_value_[ADC_POSITION_POTENTIOMETER_CV];

float texture = smoothed_adc_value_[ADC_TEXTURE_POTENTIOMETER];
texture -= smoothed_adc_value_[ADC_TEXTURE_CV] * 2.0f;
CONSTRAIN(texture, 0.0f, 1.0f);
parameters->texture = texture;

parameters->kammerl.slice_selection = smoothed_adc_value_[ADC_TEXTURE_CV];
CONSTRAIN(parameters->kammerl.slice_selection, 0.0f, 1.0f);
parameters->kammerl.slice_modulation = smoothed_adc_value_[ADC_TEXTURE_POTENTIOMETER];
CONSTRAIN(parameters->kammerl.slice_modulation, 0.0f, 1.0f);

float density = smoothed_adc_value_[ADC_DENSITY_POTENTIOMETER_CV];
CONSTRAIN(density, 0.0f, 1.0f);
parameters->density = density;

parameters->kammerl.size_modulation = density;
CONSTRAIN(parameters->kammerl.size_modulation, 0.0f, 1.0f);

parameters->size = smoothed_adc_value_[ADC_SIZE_POTENTIOMETER];
parameters->size -= smoothed_adc_value_[ADC_SIZE_CV];
CONSTRAIN(parameters->size, 0.0f, 1.0f);

UpdateBlendParameters(
smoothed_adc_value_[ADC_BLEND_POTENTIOMETER],
-smoothed_adc_value_[ADC_BLEND_CV] * 2.0f);

float blend_parameter = UpdateBlendParameters(
smoothed_adc_value_[ADC_BLEND_POTENTIOMETER],
-smoothed_adc_value_[ADC_BLEND_CV] * 2.0f);

// Update KAMMERL_MODE parameters
CONSTRAIN(blend_parameter, 0.0f, 1.0f);
switch (blend_parameter_) {
case BLEND_PARAMETER_DRY_WET:
parameters->kammerl.probability = blend_parameter;
break;
case BLEND_PARAMETER_STEREO_SPREAD:
parameters->kammerl.clock_divider = blend_parameter;
break;
case BLEND_PARAMETER_FEEDBACK:
parameters->kammerl.pitch_mode = blend_parameter;
break;
case BLEND_PARAMETER_REVERB:
parameters->kammerl.distortion = blend_parameter;
break;
default:
break;
}

float dry_wet = blend_[BLEND_PARAMETER_DRY_WET];
dry_wet += blend_mod_[BLEND_PARAMETER_DRY_WET];
dry_wet = dry_wet * 1.05f - 0.025f;
Expand All @@ -176,30 +210,34 @@ void CvScaler::Read(Parameters* parameters) {
stereo_spread += blend_mod_[BLEND_PARAMETER_STEREO_SPREAD];
CONSTRAIN(stereo_spread, 0.0f, 1.0f);
parameters->stereo_spread = stereo_spread;

parameters->pitch = stmlib::Interpolate(
lut_quantized_pitch,
smoothed_adc_value_[ADC_PITCH_POTENTIOMETER],
1024.0f);

float note = calibration_data_->pitch_offset;
note += smoothed_adc_value_[ADC_V_OCT_CV] * calibration_data_->pitch_scale;
if (fabs(note - note_) > 0.5f) {
note_ = note;
} else {
ONE_POLE(note_, note, 0.2f)
}

parameters->pitch += note_;
CONSTRAIN(parameters->pitch, -48.0f, 48.0f);


parameters->kammerl.pitch = smoothed_adc_value_[ADC_PITCH_POTENTIOMETER];
parameters->kammerl.pitch += smoothed_adc_value_[ADC_V_OCT_CV] - 0.5f;
CONSTRAIN(parameters->kammerl.pitch, 0.0f, 1.0f);

gate_input_.Read();
if (gate_input_.freeze_rising_edge()) {
parameters->freeze = true;
} else if (gate_input_.freeze_falling_edge()) {
parameters->freeze = false;
}

parameters->trigger = previous_trigger_[0];
parameters->gate = previous_gate_[0];
for (int i = 0; i < kAdcLatency - 1; ++i) {
Expand All @@ -208,7 +246,7 @@ void CvScaler::Read(Parameters* parameters) {
}
previous_trigger_[kAdcLatency - 1] = gate_input_.trigger_rising_edge();
previous_gate_[kAdcLatency - 1] = gate_input_.gate();

adc_.Convert();
}

Expand Down
42 changes: 21 additions & 21 deletions clouds/cv_scaler.h
Expand Up @@ -8,18 +8,18 @@
// 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.
//
// -----------------------------------------------------------------------------
Expand Down Expand Up @@ -56,10 +56,10 @@ class CvScaler {
public:
CvScaler() { }
~CvScaler() { }

void Init(CalibrationData* calibration_data);
void Read(Parameters* parameters);

void CalibrateC1() {
cv_c1_ = adc_.float_value(ADC_V_OCT_CV);
}
Expand All @@ -69,7 +69,7 @@ class CvScaler {
calibration_data_->offset[i] = adc_.float_value(i);
}
}

bool CalibrateC3() {
float c3 = adc_.float_value(ADC_V_OCT_CV); // 0.4848 v0.1 ; 0.3640 v0.2
float c1 = cv_c1_; // 0.6666 v0.1 ; 0.6488 v0.2
Expand All @@ -83,53 +83,53 @@ class CvScaler {
return false;
}
}

inline uint8_t adc_value(size_t index) const {
return adc_.value(index) >> 8;
}

inline bool gate(size_t index) const {
return index == 0 ? gate_input_.freeze() : gate_input_.trigger();
}

inline void set_blend_parameter(BlendParameter parameter) {
blend_parameter_ = parameter;
blend_knob_origin_ = previous_blend_knob_value_;
}

inline BlendParameter blend_parameter() const {
return blend_parameter_;
}

inline float blend_value(BlendParameter parameter) const {
return blend_[parameter];
}

inline void set_blend_value(BlendParameter parameter, float value) {
blend_[parameter] = value;
}

inline bool blend_knob_touched() const {
return blend_knob_touched_;
}

void UnlockBlendKnob() {
previous_blend_knob_value_ = -1.0f;
}

private:
void UpdateBlendParameters(float knob, float cv);
float UpdateBlendParameters(float knob, float cv);
static const int kAdcLatency = 5;

Adc adc_;
GateInput gate_input_;
CalibrationData* calibration_data_;

float smoothed_adc_value_[ADC_CHANNEL_LAST];
static CvTransformation transformations_[ADC_CHANNEL_LAST];

float note_;

BlendParameter blend_parameter_;
float blend_[BLEND_PARAMETER_LAST];
float blend_mod_[BLEND_PARAMETER_LAST];
Expand All @@ -140,10 +140,10 @@ class CvScaler {
bool blend_knob_touched_;

float cv_c1_;

bool previous_trigger_[kAdcLatency];
bool previous_gate_[kAdcLatency];

DISALLOW_COPY_AND_ASSIGN(CvScaler);
};

Expand Down