Skip to content

Commit

Permalink
Re-instate high hats, make decay settable and randomisable
Browse files Browse the repository at this point in the history
  • Loading branch information
timchurches committed Oct 25, 2015
1 parent ce6fca7 commit f18c1ae
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 48 deletions.
35 changes: 18 additions & 17 deletions peaks/drums/high_hat.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ void HighHat::Init() {
noise_.set_resonance(24000);
noise_.set_mode(SVF_MODE_BP);

vca_coloration_.Init();
vca_coloration_.set_frequency(110 << 7); // 13kHz
vca_coloration_.set_resonance(0);
vca_coloration_.set_mode(SVF_MODE_HP);
// vca_coloration_.Init();
// vca_coloration_.set_frequency(110 << 7); // 13kHz
// vca_coloration_.set_resonance(0);
// vca_coloration_.set_mode(SVF_MODE_HP);

vca_envelope_.Init();
vca_envelope_.set_delay(0);
Expand Down Expand Up @@ -87,29 +87,29 @@ int16_t HighHat::ProcessSingleSample(uint8_t control) {
set_frequency(randomised_frequency) ;
last_frequency_ = randomised_frequency ;

// colour
// decay
random_value = stmlib::Random::GetWord() ;
freq_up = (random_value > 2147483647) ? true : false ;
randomised_frequency = freq_up ?
(last_colour_ + (colour_randomness_ >> 2)) :
(last_colour_ - (colour_randomness_ >> 2));
(last_decay_ + (decay_randomness_ >> 2)) :
(last_decay_ - (decay_randomness_ >> 2));
// Check if we haven't walked out-of-bounds, and if so, reverse direction on last step
if (randomised_frequency < 0 || randomised_frequency > 65535) {
// flip the direction
freq_up = !freq_up ;
randomised_frequency = freq_up ?
(last_colour_ + (colour_randomness_ >> 2)) :
(last_colour_ - (colour_randomness_ >> 2));
(last_decay_ + (decay_randomness_ >> 2)) :
(last_decay_ - (decay_randomness_ >> 2));
}
// constrain randomised frequency - probably not necessary
if (randomised_frequency < 0) {
randomised_frequency = 0;
} else if (randomised_frequency > 65535) {
randomised_frequency = 65535;
}
// set new random frequency
set_colour(randomised_frequency) ;
last_colour_ = randomised_frequency ;
// set new random decay
set_decay(randomised_frequency) ;
last_decay_ = randomised_frequency ;

// Hit it!
vca_envelope_.Trigger(32768 * 15);
Expand Down Expand Up @@ -146,13 +146,14 @@ int16_t HighHat::ProcessSingleSample(uint8_t control) {
int32_t envelope = vca_envelope_.Process() >> 4;
int32_t vca_noise = envelope * filtered_noise >> 14;
CLIP(vca_noise);
int32_t hh = 0;
hh += vca_coloration_.Process(vca_noise);
return vca_noise;
// int32_t hh = 0;
// hh += vca_coloration_.Process(vca_noise);
// hh += vca_coloration_.Process(vca_noise);
hh <<= 1;
// hh <<= 1;
// hh <<= 2;
CLIP(hh);
return hh;
// CLIP(hh);
// return hh;
}


Expand Down
31 changes: 15 additions & 16 deletions peaks/drums/high_hat.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,36 +54,35 @@ class HighHat {
set_frequency(parameter[0]);
base_frequency_ = parameter[0];
last_frequency_ = base_frequency_;
set_colour(parameter[1]);
base_colour_ = parameter[1];
last_colour_ = base_colour_;
set_decay(parameter[1]);
base_decay_ = parameter[1];
last_decay_ = base_decay_;
} else {
set_frequency(parameter[0]);
base_frequency_ = parameter[0];
last_frequency_ = base_frequency_;
set_colour(parameter[1]);
base_colour_ = parameter[1];
last_colour_ = base_colour_;
set_decay(parameter[1]);
base_decay_ = parameter[1];
last_decay_ = base_decay_;
set_frequency_randomness(parameter[2]);
set_colour_randomness(parameter[3]);
set_decay_randomness(parameter[3]);
}
}

void set_frequency(uint16_t frequency) {
noise_.set_frequency((105 << 7) - ((32767 - frequency) >> 6)); // 8kHz
}

void set_colour(uint16_t colour) {
//vca_coloration_.set_frequency((110 << 7) - ((32767 - colour) >> 6)); // 13kHz
vca_coloration_.set_frequency((65535 - (colour >> 1)) >> 2); // 13kHz
void set_decay(uint16_t decay) {
vca_envelope_.set_decay(4065 + (decay >> 11));
}

void set_frequency_randomness(uint16_t frequency_randomness) {
frequency_randomness_ = frequency_randomness;
}

void set_colour_randomness(uint16_t colour_randomness) {
colour_randomness_ = colour_randomness;
void set_decay_randomness(uint16_t decay_randomness) {
decay_randomness_ = decay_randomness;
}

inline void set_open(bool open) {
Expand All @@ -92,19 +91,19 @@ class HighHat {

private:
Svf noise_;
Svf vca_coloration_;
// Svf vca_coloration_;
Excitation vca_envelope_;

uint32_t phase_[6];

uint16_t frequency_randomness_ ;
uint16_t colour_randomness_ ;
uint16_t decay_randomness_ ;
int32_t randomised_hit_ ;

uint16_t base_frequency_ ;
uint16_t last_frequency_ ;
uint16_t base_colour_ ;
uint16_t last_colour_ ;
uint16_t base_decay_ ;
uint16_t last_decay_ ;

bool open_ ;

Expand Down
6 changes: 3 additions & 3 deletions peaks/processors.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ Processors::callbacks_table_[PROCESSOR_FUNCTION_LAST] = {
REGISTER_BUFFERED_PROCESSOR(Lfo)
REGISTER_UNBUFFERED_PROCESSOR(BassDrum)
REGISTER_UNBUFFERED_PROCESSOR(SnareDrum)
// REGISTER_UNBUFFERED_PROCESSOR(HighHat)
REGISTER_UNBUFFERED_PROCESSOR(HighHat)
REGISTER_BUFFERED_PROCESSOR(FmDrum)
REGISTER_BUFFERED_PROCESSOR(PulseShaper)
REGISTER_BUFFERED_PROCESSOR(PulseRandomizer)
Expand Down Expand Up @@ -94,8 +94,8 @@ void Processors::Init(uint8_t index) {

bass_drum_.Init();
snare_drum_.Init();
// high_hat_.Init();
// high_hat_.set_open(index == 1);
high_hat_.Init();
high_hat_.set_open(index == 1);
fm_drum_.Init();
fm_drum_.set_sd_range(index == 1);
bouncing_ball_.Init();
Expand Down
6 changes: 3 additions & 3 deletions peaks/processors.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
#include "peaks/drums/bass_drum.h"
#include "peaks/drums/fm_drum.h"
#include "peaks/drums/snare_drum.h"
// #include "peaks/drums/high_hat.h"
#include "peaks/drums/high_hat.h"
#include "peaks/modulations/bouncing_ball.h"
#include "peaks/modulations/lfo.h"
#include "peaks/modulations/mini_sequencer.h"
Expand All @@ -61,7 +61,7 @@ enum ProcessorFunction {
PROCESSOR_FUNCTION_TAP_LFO,
PROCESSOR_FUNCTION_BASS_DRUM,
PROCESSOR_FUNCTION_SNARE_DRUM,
// PROCESSOR_FUNCTION_HIGH_HAT,
PROCESSOR_FUNCTION_HIGH_HAT,
PROCESSOR_FUNCTION_FM_DRUM,
PROCESSOR_FUNCTION_PULSE_SHAPER,
PROCESSOR_FUNCTION_PULSE_RANDOMIZER,
Expand Down Expand Up @@ -213,7 +213,7 @@ class Processors {
DECLARE_BUFFERED_PROCESSOR(Lfo, lfo_);
DECLARE_UNBUFFERED_PROCESSOR(BassDrum, bass_drum_);
DECLARE_UNBUFFERED_PROCESSOR(SnareDrum, snare_drum_);
// DECLARE_UNBUFFERED_PROCESSOR(HighHat, high_hat_);
DECLARE_UNBUFFERED_PROCESSOR(HighHat, high_hat_);
DECLARE_BUFFERED_PROCESSOR(FmDrum, fm_drum_);
DECLARE_BUFFERED_PROCESSOR(PulseShaper, pulse_shaper_);
DECLARE_BUFFERED_PROCESSOR(PulseRandomizer, pulse_randomizer_);
Expand Down
14 changes: 7 additions & 7 deletions peaks/ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const ProcessorFunction Ui::function_table_[FUNCTION_LAST][2] = {

{ PROCESSOR_FUNCTION_FM_DRUM, PROCESSOR_FUNCTION_FM_DRUM },
{ PROCESSOR_FUNCTION_RANDOMISED_BASS_DRUM, PROCESSOR_FUNCTION_RANDOMISED_SNARE_DRUM },
// { PROCESSOR_FUNCTION_HIGH_HAT, PROCESSOR_FUNCTION_HIGH_HAT },
{ PROCESSOR_FUNCTION_HIGH_HAT, PROCESSOR_FUNCTION_HIGH_HAT },
};

Storage<0x8020000, 16> storage;
Expand Down Expand Up @@ -188,7 +188,7 @@ inline void Ui::RefreshLeds() {
leds_.set_pattern(4); // top LED-> X X x X
break;
// extended DRUM functions
// case FUNCTION_HIGH_HAT:
case FUNCTION_HIGH_HAT:
case FUNCTION_FM_DRUM_GENERATOR:
case FUNCTION_RANDOMISED_DRUM_GENERATOR:
leds_.set_pattern(8); // top LED-> 0 0 X x
Expand Down Expand Up @@ -244,9 +244,9 @@ inline void Ui::RefreshLeds() {
leds_.set_pattern(15); // top LED-> X X x X
break;
// extended DRUM functions
// case FUNCTION_HIGH_HAT:
// leds_.set_pattern(10); // top LED-> 0 X 0 x
// break;
case FUNCTION_HIGH_HAT:
leds_.set_pattern(10); // top LED-> 0 X 0 x
break;
case FUNCTION_FM_DRUM_GENERATOR:
leds_.set_pattern(9); // top LED-> X 0 0 x
break;
Expand All @@ -266,7 +266,7 @@ inline void Ui::RefreshLeds() {
case FUNCTION_DRUM_GENERATOR:
case FUNCTION_FM_DRUM_GENERATOR:
case FUNCTION_RANDOMISED_DRUM_GENERATOR:
// case FUNCTION_HIGH_HAT:
case FUNCTION_HIGH_HAT:
b[i] = abs(brightness_[i]) >> 8;
b[i] = b[i] > 255 ? 255 : b[i];
break;
Expand Down Expand Up @@ -444,7 +444,7 @@ void Ui::SetFunction(uint8_t index, Function f) {
}
break;
case FUNCTION_FM_DRUM_GENERATOR:
// case FUNCTION_HIGH_HAT:
case FUNCTION_HIGH_HAT:
case FUNCTION_RANDOMISED_DRUM_GENERATOR:
if (edit_mode_ == EDIT_MODE_SPLIT || edit_mode_ == EDIT_MODE_TWIN) {
last_ext_drum_function_[0] = last_ext_drum_function_[1] = f;
Expand Down
4 changes: 2 additions & 2 deletions peaks/ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ enum Function {

FUNCTION_FM_DRUM_GENERATOR,
FUNCTION_RANDOMISED_DRUM_GENERATOR,
// FUNCTION_HIGH_HAT,
FUNCTION_HIGH_HAT,

FUNCTION_LAST,
FUNCTION_FIRST_BASIC_FUNCTION = FUNCTION_ENVELOPE,
Expand All @@ -101,7 +101,7 @@ enum Function {
FUNCTION_LAST_EXTENDED_TAP_FUNCTION = FUNCTION_BYTEBEATS,

FUNCTION_FIRST_EXTENDED_DRUM_FUNCTION = FUNCTION_FM_DRUM_GENERATOR,
FUNCTION_LAST_EXTENDED_DRUM_FUNCTION = FUNCTION_RANDOMISED_DRUM_GENERATOR,
FUNCTION_LAST_EXTENDED_DRUM_FUNCTION = FUNCTION_HIGH_HAT,
};

struct Settings {
Expand Down

0 comments on commit f18c1ae

Please sign in to comment.