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

Added Cymbal #8

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
132 changes: 132 additions & 0 deletions peaks/drums/cymbal.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
// Copyright 2013 Emilie Gillet.
//
// Author: Emilie Gillet ([email protected])
//
// 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.
//
// -----------------------------------------------------------------------------
//
// 808-style HH.

#include "peaks/drums/cymbal.h"

#include <cstdio>

#include "stmlib/utils/dsp.h"
#include "stmlib/utils/random.h"

#include "peaks/resources.h"

namespace peaks {

using namespace stmlib;



void Cymbal::Init() {

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

vca_envelope_.Init();
vca_envelope_.set_delay(0);
vca_envelope_.set_decay(4093);

// SVF for multifreq signal
svf_hat_noise1_.Init();
svf_hat_noise1_.set_frequency(105 << 7); // 8kHz
svf_hat_noise1_.set_resonance(24000);

// SVF for PNR signal
svf_hat_noise2_.Init();
svf_hat_noise2_.set_frequency(105 << 7); // 8kHz
svf_hat_noise2_.set_resonance(24000);

}



void Cymbal::Process(const GateFlags* gate_flags, int16_t* out, size_t size) {
while (size--) {
GateFlags gate_flag = *gate_flags++;
if (gate_flag & GATE_FLAG_RISING) {
vca_envelope_.Trigger(32768 * 15);
}

// Pseudo Random Noise Generation

phase_ += 93886874*20;
if (phase_ < 93886874*20) {
rng_state_ = rng_state_ * 1664525L + 1013904223L;
}


cym_phase_[0] += 48252847 - 4194176 + pitch_ ;
cym_phase_[1] += 71517253 - 4194176 + pitch_ ;
cym_phase_[2] += 36978557 - 4194176 + pitch_ ;
cym_phase_[3] += 54247905 - 4194176 + pitch_ ;
cym_phase_[4] += 66148544 - 4194176 + pitch_ ;
cym_phase_[5] += 93886874 - 4194176 + pitch_ ;

int16_t noise = 0;
noise += cym_phase_[0] >> 31;
noise += cym_phase_[1] >> 31;
noise += cym_phase_[2] >> 31;
noise += cym_phase_[3] >> 31;
noise += cym_phase_[4] >> 31;
noise += cym_phase_[5] >> 31;
noise <<= 12;

int32_t filtered_noise1 = svf_hat_noise1_.Process<SVF_MODE_BP>(noise);;
filtered_noise1 <<= 2;

// The 808-style VCA clipping
if (filtered_noise1 < clip_ - 32767) {
filtered_noise1 = clip_ - 32767;
} else if (filtered_noise1 > 32767) {
filtered_noise1 = 32767;
}

// Random Noise Processing
int32_t rng_noise = (rng_state_ >> 16) - 32768;
int32_t filtered_noise2 = svf_hat_noise2_.Process<SVF_MODE_BP>(rng_noise>>1);
// CLIP(filtered_noise2);


int32_t envelope = vca_envelope_.Process() >> 4;
int32_t vca_noise1 = (envelope * filtered_noise1 >> 15);
int32_t vca_noise2 = (envelope * filtered_noise2 >> 15);
CLIP(vca_noise1);
CLIP(vca_noise2);

// crossfading pseudo random noise and multifrequency signal
int32_t vca_noise = vca_noise1 + ((vca_noise2 - vca_noise1) * xfade_ >> 15);
int32_t hh = vca_coloration_.Process<SVF_MODE_HP>(vca_noise);
CLIP(hh);

*out++ = hh;
}
}



} // namespace peaks
100 changes: 100 additions & 0 deletions peaks/drums/cymbal.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
// Copyright 2013 Emilie Gillet.
//
// Author: Emilie Gillet ([email protected])
//
// 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.
//
// -----------------------------------------------------------------------------
//
// 808-style HH.

#ifndef PEAKS_DRUMS_CYMBAL_H_
#define PEAKS_DRUMS_CYMBAL_H_

#include "stmlib/stmlib.h"

#include "peaks/drums/svf.h"
#include "peaks/drums/excitation.h"

#include "peaks/gate_processor.h"

namespace peaks {

class Cymbal {
public:
Cymbal() { }
~Cymbal() { }

void Init();
void Process(const GateFlags* gate_flags, int16_t* out, size_t size);
void Configure(uint16_t* parameter, ControlMode control_mode) {
if (control_mode == CONTROL_MODE_HALF) {
set_pitch(32767);
set_clip(32767);
set_xfade(parameter[0]);
set_decay(parameter[1]);
}else{
set_pitch(parameter[0]);
set_clip(parameter[1]);
set_xfade(parameter[2]);
set_decay(parameter[3]);
}
}


void set_pitch(uint16_t pitch) {
pitch_ = pitch<<7;
}

void set_clip(uint16_t clip) {
clip_=clip;
}

void set_xfade(int32_t xfade) {
xfade_=xfade>>1;
}

void set_decay(uint16_t decay) {
vca_envelope_.set_decay(4092+ (decay >> 14));
}


private:
Svf svf_hat_noise1_;
Svf svf_hat_noise2_;
Svf vca_coloration_;
Excitation vca_envelope_;


uint32_t pitch_;
uint32_t phase_;
uint16_t clip_;
int32_t xfade_;
uint32_t rng_state_;
uint32_t cym_phase_[6];


DISALLOW_COPY_AND_ASSIGN(Cymbal);
};

} // namespace peaks

#endif // PEAKS_DRUMS_CYMBAL_H_
2 changes: 2 additions & 0 deletions peaks/processors.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ Processors::callbacks_table_[PROCESSOR_FUNCTION_LAST] = {
REGISTER_PROCESSOR(BassDrum)
REGISTER_PROCESSOR(SnareDrum)
REGISTER_PROCESSOR(HighHat)
REGISTER_PROCESSOR(Cymbal)
REGISTER_PROCESSOR(FmDrum)
REGISTER_PROCESSOR(PulseShaper)
REGISTER_PROCESSOR(PulseRandomizer)
Expand Down Expand Up @@ -84,6 +85,7 @@ void Processors::Init(uint8_t index) {
snare_drum_.Init();
high_hat_.Init();
high_hat_.set_open(index == 1);
cymbal_.Init();
fm_drum_.Init();
fm_drum_.set_sd_range(index == 1);
bouncing_ball_.Init();
Expand Down
3 changes: 3 additions & 0 deletions peaks/processors.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include "peaks/drums/fm_drum.h"
#include "peaks/drums/snare_drum.h"
#include "peaks/drums/high_hat.h"
#include "peaks/drums/cymbal.h"
#include "peaks/modulations/bouncing_ball.h"
#include "peaks/modulations/lfo.h"
#include "peaks/modulations/mini_sequencer.h"
Expand All @@ -62,6 +63,7 @@ enum ProcessorFunction {
PROCESSOR_FUNCTION_BASS_DRUM,
PROCESSOR_FUNCTION_SNARE_DRUM,
PROCESSOR_FUNCTION_HIGH_HAT,
PROCESSOR_FUNCTION_CYMBAL,
PROCESSOR_FUNCTION_FM_DRUM,
PROCESSOR_FUNCTION_PULSE_SHAPER,
PROCESSOR_FUNCTION_PULSE_RANDOMIZER,
Expand Down Expand Up @@ -167,6 +169,7 @@ class Processors {
DECLARE_PROCESSOR(BassDrum, bass_drum_);
DECLARE_PROCESSOR(SnareDrum, snare_drum_);
DECLARE_PROCESSOR(HighHat, high_hat_);
DECLARE_PROCESSOR(Cymbal, cymbal_);
DECLARE_PROCESSOR(FmDrum, fm_drum_);
DECLARE_PROCESSOR(PulseShaper, pulse_shaper_);
DECLARE_PROCESSOR(PulseRandomizer, pulse_randomizer_);
Expand Down
8 changes: 7 additions & 1 deletion peaks/ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ const ProcessorFunction Ui::function_table_[FUNCTION_LAST][2] = {
{ PROCESSOR_FUNCTION_BYTEBEATS, PROCESSOR_FUNCTION_BYTEBEATS },

{ PROCESSOR_FUNCTION_FM_DRUM, PROCESSOR_FUNCTION_FM_DRUM },
{ PROCESSOR_FUNCTION_CYMBAL, PROCESSOR_FUNCTION_CYMBAL },
{ PROCESSOR_FUNCTION_RANDOMISED_BASS_DRUM, PROCESSOR_FUNCTION_RANDOMISED_SNARE_DRUM },
{ PROCESSOR_FUNCTION_HIGH_HAT, PROCESSOR_FUNCTION_HIGH_HAT },
};
Expand Down Expand Up @@ -207,6 +208,7 @@ inline void Ui::RefreshLeds() {
break;
// extended DRUM functions
case FUNCTION_HIGH_HAT:
case FUNCTION_CYMBAL:
case FUNCTION_FM_DRUM_GENERATOR:
case FUNCTION_RANDOMISED_DRUM_GENERATOR:
leds_.set_pattern(8); // top LED-> 0 0 X x
Expand Down Expand Up @@ -272,13 +274,16 @@ inline void Ui::RefreshLeds() {
break;
// extended DRUM functions
case FUNCTION_HIGH_HAT:
leds_.set_pattern(12); // top LED-> 0 0 X x
break;
case FUNCTION_CYMBAL:
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;
case FUNCTION_RANDOMISED_DRUM_GENERATOR:
leds_.set_pattern(12); // top LED-> 0 0 X x
leds_.set_pattern(11); // top LED-> X X 0 x
break;
// the remainder
default:
Expand Down Expand Up @@ -489,6 +494,7 @@ void Ui::SetFunction(uint8_t index, Function f) {
break;
case FUNCTION_FM_DRUM_GENERATOR:
case FUNCTION_HIGH_HAT:
case FUNCTION_CYMBAL:
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
1 change: 1 addition & 0 deletions peaks/ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ enum Function {

FUNCTION_FM_DRUM_GENERATOR,
FUNCTION_RANDOMISED_DRUM_GENERATOR,
FUNCTION_CYMBAL,
FUNCTION_HIGH_HAT,

FUNCTION_LAST,
Expand Down
Loading