Skip to content

Instantly share code, notes, and snippets.

@halldorel
Created May 20, 2016 15:34
Show Gist options
  • Save halldorel/5693240c35795761a8f4055a456539f8 to your computer and use it in GitHub Desktop.
Save halldorel/5693240c35795761a8f4055a456539f8 to your computer and use it in GitHub Desktop.
//
// BassDrumNew.cpp
// Synthesizer
//
// Created by Halldór Eldjárn on 06/08/14.
// Copyright (c) 2014 Edu. All rights reserved.
//
#ifndef __Synthesizer__BassDrum__
#define __Synthesizer__BassDrum__
#include "Tonic.h"
using namespace Tonic;
class BassDrum : public Synth
{
public:
ControlParameter trigger = addParameter("trigger");
BassDrum()
{
ADSR envelope = ADSR(0.01, 0.30, 0.0, 0.15)
.trigger(trigger)
.doesSustain(false)
.legato(false);
ADSR pitchEnvelope = ADSR(0.01, 0.06, 0, 0.1)
.trigger(trigger)
.doesSustain(false)
.legato(false);
ADSR filterEnvelope = ADSR(0.01, 0.22, 0, 0.1)
.trigger(trigger)
.doesSustain(false)
.legato(false);
ADSR noiseEnvelope = ADSR(0.0, 0.01, 0.0, 0.0)
.trigger(trigger)
.doesSustain(true)
.legato(false);
ADSR noiseFilterEnvelope = ADSR(0.0, 0.009, 0, 0.0)
.trigger(trigger)
.doesSustain(false)
.legato(false);
Generator sawtooth = (SineWave().freq( 40 + 100 * pitchEnvelope )
+ (0.1 * SawtoothWave().freq( 200 ) * noiseEnvelope))
>> LPF24().cutoff(10000 * filterEnvelope + 100);
sawtooth = sawtooth * envelope;
Generator noise = Noise() >> HPF12().cutoff(8000 * noiseFilterEnvelope + 1000);
noise = noise * noiseEnvelope;
Generator bassDrum = (((sawtooth + noise * 0.7) >> LPF24().cutoff(10000))) * 0.25;
setOutputGen(bassDrum);
}
};
#endif
//
// BassSynth.cpp
// Synthesizer
//
// Created by Halldór Eldjárn on 26/07/14.
// Copyright (c) 2014 Edu. All rights reserved.
//
#ifndef __Synthesizer__BassSynth__
#define __Synthesizer__BassSynth__
#include "Tonic.h"
using namespace Tonic;
class BassSynth : public Synth
{
public:
ControlParameter midiNote = addParameter("midiNote", 38);
ControlParameter trigger = addParameter("trigger", 0);
ControlParameter moodParameter;
BassSynth(ControlParameter mood, ControlMetro metro)
{
moodParameter = mood;
RampedValue moodRamped = moodParameter.smoothed();
ControlGenerator pitchControl = ControlMidiToFreq().input(midiNote);
ControlGenerator pitchFifthControl = ControlMidiToFreq().input(midiNote + 19);
SineWave subOsc = SineWave().freq(pitchControl);
Generator saw = SawtoothWave().freq(pitchControl)
>> LPF12().cutoff(400 + 2000 * moodParameter);
SineWave fifthMod = SineWave().freq(0.3);
SawtoothWave sawFifth = SawtoothWave().freq(pitchFifthControl + fifthMod * 0.5);
ADSR volumeEnvelope = ADSR(0.0001, 0.3, 0.0, 0.1)
.trigger(trigger)
.decay(0.3 + (moodParameter * 0.2)).exponential(2);
ADSR bassFilterEnvelope = ADSR(0.0001, 0.17, 0.4, 0.1)
.decay(0.05 + mood * 0.1)
.trigger(trigger)
.exponential(1.2);
SineWave sweep = SineWave().freq(0.5);
LPF12 bassFilter = LPF12()
.cutoff(900 + 400 * sweep + moodRamped * 4000 + (moodRamped * 300 + 100)
* SineWave().freq(1.2) + 2000 * bassFilterEnvelope);
Generator bassSynth = (((saw * 0.5 + subOsc + sawFifth * moodRamped * 0.2) * volumeEnvelope) * 0.8)
>> bassFilter;
//>> StereoDelay(0.1, 0.12).feedback(0.2 + moodRamped * 0.6).wetLevel(0.07).dryLevel(0.9).delayTimeLeft(metro).delayTimeRight(metro * 0.66);
setOutputGen(bassSynth);
}
};
#endif
//
// LeadSynth.cpp
// Synthesizer
//
// Created by Halldór Eldjárn on 09/11/14.
// Copyright (c) 2014 Edu. All rights reserved.
//
#ifndef __Synthesizer__LeadSynth__
#define __Synthesizer__LeadSynth__
#include "Tonic.h"
using namespace Tonic;
class LeadSynth : public Synth
{
public:
ControlParameter midiNote = addParameter("midiNote");
ControlParameter trigger = addParameter("trigger");
LeadSynth(ControlParameter mood, ControlMetro metro)
{
ControlGenerator freq = ControlMidiToFreq().input(midiNote + 24);
ADSR envelope = ADSR(0.0001, 0.5, 0.0, 0.0).decay(0.4 + mood * 0.4).exponential(0.3 + 0.4 * mood).trigger(trigger);
ControlParameter moodLog = mood.logarithmic(true);
Generator modulator = SineWave().freq(4000);
Generator sineOne = SineWave().freq(freq + SineWave().freq(3) * 2 + modulator * moodLog * 100);
setOutputGen(sineOne * envelope >> StereoDelay(1.0, 1.0).delayTimeLeft(metro * 0.5).delayTimeRight(metro * 0.75).wetLevel(0.02 + 0.2 * mood).dryLevel(1.0).feedback(0.2 + mood * 0.4));
/*
ControlGenerator freq = ControlMidiToFreq().input(midiNote);
ADSR envelope = ADSR(0.01, 0.4, 0.0, 0.0) ;
Generator leadSynth = (SineWave().freq(freq * 4)
+ SquareWave().freq(freq * 4 + SineWave().freq(7) * 2))
* envelope
.trigger(trigger) >> LPF12().cutoff(mood * 10000 * envelope) >> StereoDelay(0.350, 0.350)
.feedback(0.3)
.wetLevel(0.02);
setOutputGen(leadSynth);*/
}
};
#endif
//
// HiHat.h
// Synthesizer
//
// Created by Halldór Eldjárn on 11/11/14.
// Copyright (c) 2014 Edu. All rights reserved.
//
#ifndef Synthesizer_HiHat_h
#define Synthesizer_HiHat_h
#include "Tonic.h"
using namespace Tonic;
class HiHat : public Synth
{
public:
ControlParameter trigger = addParameter("trigger", 0);
HiHat(ControlParameter mood, ControlMetro metro)
{
Generator dynamic = SineWave().freq(metro * 1.33333);
ADSR hihatEnv = ADSR(0.0001, 0.02, 0.0, 0.0).decay(0.02 + 0.1 * mood).exponential(0.8 + 0.5 * mood).trigger(trigger);
Generator hiHat = PinkNoise() * hihatEnv >> HPF12().cutoff(10000 + dynamic * 7000).Q(0.4);
setOutputGen(hiHat * (0.7 + dynamic * mood * 0.3) >> StereoDelay(1.0, 1.0).delayTimeLeft(metro).delayTimeRight(metro * 0.5).wetLevel(0.02 + 0.2 * mood).dryLevel(1.0));
}
};
#endif
//
// Snare.cpp
// Synthesizer
//
// Created by Halldór Eldjárn on 10/11/14.
// Copyright (c) 2014 Edu. All rights reserved.
//
#ifndef __Synthesizer__Snare__
#define __Synthesizer__Snare__
#include "Tonic.h"
using namespace Tonic;
class Snare : public Synth
{
public:
ControlParameter trigger;
Snare()
{
trigger = addParameter("trigger");
ADSR snarePitchEnvelope = ADSR(0.0, 0.05, 0.0, 0.0)
.trigger(trigger);
Generator snare = (PinkNoise() + SineWave().freq(81 + 200 * snarePitchEnvelope)) \
* ADSR(0.0001, 0.2, 0.0, 0.0)
.exponential(true)
.trigger(trigger);
// Trigger is also velocity
snare = snare * trigger;
setOutputGen(snare);
}
};
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment