2 |

3 |
4 | # Dunne AudioKit
5 |
6 | [](https://github.com/AudioKit/DunneAudioKit/actions?query=workflow%3ACI)
7 | [](https://github.com/AudioKit/DunneAudioKit/blob/main/LICENSE)
8 | [](https://swiftpackageindex.com/AudioKit/DunneAudioKit)
9 | [](https://swiftpackageindex.com/AudioKit/DunneAudioKit)
10 | [](https://houndci.com)
11 | [](https://twitter.com/AudioKitPro)
12 |
13 |
14 |
15 | Chorus, Flanger, Sampler, Stereo Delay, and Synth for AudioKit, by Shane Dunne.
16 |
17 | ## Documentation
18 |
19 | Detailed documentation is provided on [AudioKit's Website](http://audiokit.io/Packages/DunneAudioKit/).
20 |
21 | ## API Reference
22 |
23 | * [Chorus](https://audiokit.io/DunneAudioKit/documentation/dunneaudiokit/chorus)
24 | * [Flanger](https://audiokit.io/DunneAudioKit/documentation/dunneaudiokit/flanger)
25 | * [Sampler](https://audiokit.io/DunneAudioKit/documentation/dunneaudiokit/sampler)
26 | * [Stereo Delay](https://audiokit.io/DunneAudioKit/documentation//dunneaudiokit/stereodelay)
27 | * [Synth](https://audiokit.io/DunneAudioKit/documentation/dunneaudiokit/synth)
28 | * [Transient Shaper](https://audiokit.io/DunneAudioKit/documentation/dunneaudiokit/transientshaper)
29 |
30 | ## Installation
31 |
32 | Install with Swift Package Manager.
33 |
34 | ## Examples
35 |
36 | See the [AudioKit Cookbook](https://github.com/AudioKit/Cookbook/) for examples.
37 |
--------------------------------------------------------------------------------
/AudioKit-Experiments/DunneAudioKit/Sources/CDunneAudioKit/DunneCore/Common/ADSREnvelope.h:
--------------------------------------------------------------------------------
1 | // Copyright AudioKit. All Rights Reserved.
2 |
3 | #include "EnvelopeGeneratorBase.h"
4 |
5 | namespace DunneCore
6 | {
7 |
8 | struct ADSREnvelopeParameters
9 | {
10 | float sampleRateHz;
11 | float attackSamples, decaySamples, releaseSamples;
12 | float sustainFraction; // [0.0, 1.0]
13 |
14 | ADSREnvelopeParameters();
15 | void init(float newSampleRateHz, float attackSeconds, float decaySeconds, float susFraction, float releaseSeconds);
16 | void init(float attackSeconds, float decaySeconds, float susFraction, float releaseSeconds);
17 | void updateSampleRate(float newSampleRateHz);
18 |
19 | void setAttackDurationSeconds(float attackSeconds) { attackSamples = attackSeconds * sampleRateHz; }
20 | float getAttackDurationSeconds() { return attackSamples / sampleRateHz; }
21 | void setDecayDurationSeconds(float decaySeconds) { decaySamples = decaySeconds * sampleRateHz; }
22 | float getDecayDurationSeconds() { return decaySamples / sampleRateHz; }
23 | void setReleaseDurationSeconds(float releaseSeconds) { releaseSamples = releaseSeconds * sampleRateHz; }
24 | float getReleaseDurationSeconds() { return releaseSamples / sampleRateHz; }
25 | };
26 |
27 | struct ADSREnvelope
28 | {
29 | ADSREnvelopeParameters* pParameters; // many ADSREnvelopes can share a common set of parameters
30 |
31 | enum EG_Segment
32 | {
33 | kIdle = 0,
34 | kSilence,
35 | kAttack,
36 | kDecay,
37 | kSustain,
38 | kRelease
39 | };
40 |
41 | enum CurvatureType
42 | {
43 | kLinear, // all segments linear
44 | kAnalogLike, // models CEM3310 integrated circuit
45 | kLinearInDb // decay and release are linear-in-dB
46 | };
47 |
48 | void init(CurvatureType curvatureType = kAnalogLike);
49 | void updateParams();
50 |
51 | void start(); // called for note-on
52 | void restart(); // quickly dampen note then start again
53 | void release(); // called for note-off
54 | void reset(); // reset to idle state
55 | bool isIdle() { return env.getCurrentSegmentIndex() == kIdle; }
56 | bool isPreStarting() { return env.getCurrentSegmentIndex() == kSilence; }
57 | bool isReleasing() { return env.getCurrentSegmentIndex() == kRelease; }
58 |
59 | inline float getValue()
60 | {
61 | return env.getValue();
62 | }
63 |
64 | inline float getSample()
65 | {
66 | float sample;
67 | env.getSample(sample);
68 | return sample;
69 | }
70 |
71 | protected:
72 | MultiSegmentEnvelopeGenerator env;
73 | MultiSegmentEnvelopeGenerator::Descriptor envDesc;
74 | };
75 |
76 | }
77 |
--------------------------------------------------------------------------------
/AudioKit-Experiments/DunneAudioKit/Sources/CDunneAudioKit/DunneCore/Common/AHDSHREnvelope.h:
--------------------------------------------------------------------------------
1 | // Copyright AudioKit. All Rights Reserved.
2 | //
3 | // Attack, Hold, Decay, Sustain, Release-hold, Release envelope
4 | // 1) Attack fades in from 0 for attackSamples
5 | // 2) Holds value at 1 for holdSamples
6 | // 3) Decays to sustainFraction for decaySamples
7 | // 4) Holds value at sustainFraction until release / noteOff
8 | // 5) Holds value at sustainFraction for releaseHoldSamples
9 | // 6) Fades to 0 for releaseSamples
10 |
11 | #include "EnvelopeGeneratorBase.h"
12 |
13 | namespace DunneCore
14 | {
15 |
16 | struct AHDSHREnvelopeParameters
17 | {
18 | float sampleRateHz;
19 | float attackSamples, holdSamples, decaySamples, releaseHoldSamples, releaseSamples;
20 | float sustainFraction; // [0.0, 1.0]
21 |
22 | AHDSHREnvelopeParameters();
23 | void init(float newSampleRateHz, float attackSeconds, float holdSeconds, float decaySeconds, float susFraction,
24 | float releaseHoldSeconds, float releaseSeconds);
25 | void init(float attackSeconds, float holdSeconds, float decaySeconds, float susFraction,
26 | float releaseHoldSeconds, float releaseSeconds);
27 | void updateSampleRate(float newSampleRateHz);
28 |
29 | void setAttackDurationSeconds(float attackSeconds) { attackSamples = attackSeconds * sampleRateHz; }
30 | float getAttackDurationSeconds() { return attackSamples / sampleRateHz; }
31 | void setHoldDurationSeconds(float holdSeconds) { holdSamples = holdSeconds * sampleRateHz; }
32 | float getHoldDurationSeconds() { return holdSamples / sampleRateHz; }
33 | void setDecayDurationSeconds(float decaySeconds) { decaySamples = decaySeconds * sampleRateHz; }
34 | float getDecayDurationSeconds() { return decaySamples / sampleRateHz; }
35 | void setReleaseHoldDurationSeconds(float releaseHoldSeconds) { releaseHoldSamples = releaseHoldSeconds * sampleRateHz; }
36 | float getReleaseHoldDurationSeconds() { return releaseHoldSamples / sampleRateHz; }
37 | void setReleaseDurationSeconds(float releaseSeconds) { releaseSamples = releaseSeconds * sampleRateHz; }
38 | float getReleaseDurationSeconds() { return releaseSamples / sampleRateHz; }
39 | };
40 |
41 | struct AHDSHREnvelope
42 | {
43 | AHDSHREnvelopeParameters* pParameters; // many ADSREnvelopes can share a common set of parameters
44 |
45 | enum EG_Segment
46 | {
47 | kIdle = 0,
48 | kSilence,
49 | kAttack,
50 | kHold,
51 | kDecay,
52 | kSustain,
53 | kReleaseHold,
54 | kRelease
55 | };
56 |
57 | enum CurvatureType
58 | {
59 | kLinear, // all segments linear
60 | kAnalogLike, // models CEM3310 integrated circuit
61 | kLinearInDb // decay and release are linear-in-dB
62 | };
63 |
64 | void init(CurvatureType curvatureType = kAnalogLike);
65 | void updateParams();
66 |
67 | void start(); // called for note-on
68 | void restart(); // quickly dampen note then start again
69 | void release(); // called for note-off
70 | void reset(); // reset to idle state
71 | bool isIdle() { return env.getCurrentSegmentIndex() == kIdle; }
72 | bool isPreStarting() { return env.getCurrentSegmentIndex() == kSilence; }
73 | bool isReleasing() {
74 | return env.getCurrentSegmentIndex() == kReleaseHold || env.getCurrentSegmentIndex() == kRelease;
75 | }
76 |
77 | inline float getValue()
78 | {
79 | return env.getValue();
80 | }
81 |
82 | inline float getSample()
83 | {
84 | float sample;
85 | env.getSample(sample);
86 | return sample;
87 | }
88 |
89 | protected:
90 | MultiSegmentEnvelopeGenerator env;
91 | MultiSegmentEnvelopeGenerator::Descriptor envDesc;
92 | };
93 |
94 | }
95 |
--------------------------------------------------------------------------------
/AudioKit-Experiments/DunneAudioKit/Sources/CDunneAudioKit/DunneCore/Common/AudioKitCore.h:
--------------------------------------------------------------------------------
1 | // Copyright AudioKit. All Rights Reserved.
2 |
3 | #pragma once
4 |
--------------------------------------------------------------------------------
/AudioKit-Experiments/DunneAudioKit/Sources/CDunneAudioKit/DunneCore/Common/CoreEnvelope.h:
--------------------------------------------------------------------------------
1 | // Copyright AudioKit. All Rights Reserved.
2 |
3 | #pragma once
4 | #include "LinearRamper.h"
5 | #include "FunctionTable.h"
6 |
7 | namespace DunneCore
8 | {
9 |
10 | struct EnvelopeSegmentParameters
11 | {
12 | // where this segment starts
13 | float initialLevel;
14 |
15 | // where it ends
16 | float finalLevel;
17 |
18 | // how long it takes to get there
19 | float seconds;
20 | };
21 |
22 | struct EnvelopeParameters
23 | {
24 | float sampleRateHz;
25 |
26 | // number of segments
27 | int nSegments;
28 |
29 | // points to an array of nSegments elements
30 | EnvelopeSegmentParameters *pSeg;
31 |
32 | // start() begins at this segment
33 | int attackSegmentIndex;
34 |
35 | // index of first sustain segment (-1 if none)
36 | int sustainSegmentIndex;
37 |
38 | // release() jumps to this segment
39 | int releaseSegmentIndex;
40 |
41 | EnvelopeParameters();
42 | void init(float newSampleRateHz,
43 | int nSegs,
44 | EnvelopeSegmentParameters *pSegParameters,
45 | int susSegIndex = -1,
46 | int attackSegIndex = 0,
47 | int releaseSegIndex = -1);
48 | void updateSampleRate(float newSampleRateHz);
49 | };
50 |
51 | struct Envelope
52 | {
53 | EnvelopeParameters *pParameters;
54 | LinearRamper ramper;
55 | int currentSegmentIndex;
56 |
57 | void init(EnvelopeParameters *pParameters);
58 |
59 | // begin attack segment
60 | void start();
61 |
62 | // go to segment 0
63 | void restart();
64 |
65 | // go to release segment
66 | void release();
67 |
68 | // reset to idle state
69 | void reset();
70 | bool isIdle() { return currentSegmentIndex < 0; }
71 | bool isReleasing() { return currentSegmentIndex >= pParameters->releaseSegmentIndex; }
72 |
73 | float getSample();
74 | };
75 | }
76 |
--------------------------------------------------------------------------------
/AudioKit-Experiments/DunneAudioKit/Sources/CDunneAudioKit/DunneCore/Common/DrawbarsOscillator.h:
--------------------------------------------------------------------------------
1 | // Copyright AudioKit. All Rights Reserved.
2 |
3 | #pragma once
4 |
5 | #include "FunctionTable.h"
6 | #include "WaveStack.h"
7 |
8 | namespace DunneCore
9 | {
10 |
11 | // DrawbarsOscillator is WaveStack-based oscillator which implements multiple simultaneous
12 | // waveform-readout phases, whose frequencies are related as a harmonic series, as in a
13 | // traditional "drawbar" organ.
14 |
15 | struct DrawbarsOscillator
16 | {
17 | // current output sample rate
18 | double sampleRateHz;
19 |
20 | // pointer to shared WaveStack
21 | WaveStack *pWaveStack;
22 |
23 | // per-phase variables
24 | static constexpr int phaseCount = 16;
25 |
26 | // WaveStack octave used by this phase
27 | int octave[phaseCount];
28 |
29 | // Fraction of the way through waveform
30 | float phase[phaseCount];
31 |
32 | // normalized frequency: cycles per sample
33 | float phaseDelta[phaseCount];
34 |
35 | // relative level of each phase (fraction)
36 | float *level;
37 | float safetyLevels[phaseCount];
38 |
39 | // performance variables
40 |
41 | // phaseDelta multiplier for pitchbend, vibrato
42 | float phaseDeltaMultiplier;
43 |
44 | void init(double sampleRate, WaveStack* pStack);
45 | void setFrequency(float frequency);
46 |
47 | float getSample();
48 | void getSamples(float *pLeft, float *pRight, float gain);
49 |
50 | // 9 Hammond-like drawbars mapped to level[] indices
51 | static const int drawBarMap[9];
52 | };
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/AudioKit-Experiments/DunneAudioKit/Sources/CDunneAudioKit/DunneCore/Common/EnsembleOscillator.h:
--------------------------------------------------------------------------------
1 | // Copyright AudioKit. All Rights Reserved.
2 |
3 | #pragma once
4 |
5 | #include "FunctionTable.h"
6 | #include "WaveStack.h"
7 | #include