Skip to content

Commit

Permalink
Change to reduce click when proper note IDs are not provided from DAW
Browse files Browse the repository at this point in the history
  • Loading branch information
ryukau committed Nov 15, 2024
1 parent 1b411f3 commit de150f6
Show file tree
Hide file tree
Showing 42 changed files with 456 additions and 222 deletions.
1 change: 0 additions & 1 deletion ClangSynth/source/dsp/dspcore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,6 @@ void DSPCore::noteOn(

// Pick up note from resting one.
for (size_t index = 0; index < nVoice; ++index) {
if (notes[index].id == noteId) noteIndices.push_back(index);
if (notes[index].state == NoteState::rest) noteIndices.push_back(index);
if (noteIndices.size() >= nUnison) break;
}
Expand Down
8 changes: 4 additions & 4 deletions ClangSynth/source/version.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
#define SUB_VERSION_STR "1"
#define SUB_VERSION_INT 1

#define RELEASE_NUMBER_STR "9"
#define RELEASE_NUMBER_INT 9
#define RELEASE_NUMBER_STR "10"
#define RELEASE_NUMBER_INT 10

#define BUILD_NUMBER_STR "10"
#define BUILD_NUMBER_INT 10
#define BUILD_NUMBER_STR "11"
#define BUILD_NUMBER_INT 11

#define FULL_VERSION_STR \
MAJOR_VERSION_STR "." SUB_VERSION_STR "." RELEASE_NUMBER_STR "." BUILD_NUMBER_STR
Expand Down
1 change: 0 additions & 1 deletion CollidingCombSynth/source/dsp/dspcore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,6 @@ void DSPCore::noteOn(int32_t noteId, int16_t pitch, float tuning, float velocity

// Pick up note from resting one.
for (uint32_t index = 0; index < nVoice; ++index) {
if (notes[index].id == noteId) noteIndices.push_back(index);
if (notes[index].state == NoteState::rest) noteIndices.push_back(index);
if (noteIndices.size() >= nUnison) break;
}
Expand Down
8 changes: 4 additions & 4 deletions CollidingCombSynth/source/version.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
#define SUB_VERSION_STR "1"
#define SUB_VERSION_INT 1

#define RELEASE_NUMBER_STR "16"
#define RELEASE_NUMBER_INT 16
#define RELEASE_NUMBER_STR "17"
#define RELEASE_NUMBER_INT 17

#define BUILD_NUMBER_STR "16"
#define BUILD_NUMBER_INT 16
#define BUILD_NUMBER_STR "17"
#define BUILD_NUMBER_INT 17

#define FULL_VERSION_STR \
MAJOR_VERSION_STR "." SUB_VERSION_STR "." RELEASE_NUMBER_STR "." BUILD_NUMBER_STR
Expand Down
9 changes: 7 additions & 2 deletions CubicPadSynth/source/dsp/dspcore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ void NOTE_NAME::noteOn(
unit.lfo.setFrequency(vecIndex, sampleRate, 1.0f);
if (param.value[ID::lfoPhaseReset]->getInt()) unit.lfo.reset(vecIndex);

std::uniform_real_distribution<float> dist(0.0, 1.0);
std::uniform_real_distribution<float> dist(0.0f, 1.0f);
unit.notePitch.insert(vecIndex, notePitch);
if (param.value[ID::oscPhaseReset]->getInt()) {
const auto phaseRnd
Expand Down Expand Up @@ -402,7 +402,6 @@ void DSPCORE_NAME::noteOn(int32_t identifier, int16_t pitch, float tuning, float

// Pick up note from resting one.
for (size_t index = 0; index < nVoice; ++index) {
if (notes[index].id == identifier) noteIndices.push_back(index);
if (notes[index].state == NoteState::rest) noteIndices.push_back(index);
if (noteIndices.size() >= nUnison) break;
}
Expand Down Expand Up @@ -549,6 +548,12 @@ void DSPCORE_NAME::fillTransitionBuffer(size_t noteIndex)

float gain0 = unit.gain0[vecIndex];
float gain1 = unit.gain1[vecIndex];

// Don't write to `transitionBuffer` twice in a row. `noteOn` must be called for this
// voice after this method.
unit.gain0.insert(vecIndex, 0.0f);
unit.gain1.insert(vecIndex, 0.0f);

float pitch = unit.lowpassPitch[vecIndex] + unit.pitch[vecIndex];
trOsc.phase = unit.osc.phase.extract(vecIndex);
trOsc.tick = unit.osc.tick.extract(vecIndex);
Expand Down
8 changes: 4 additions & 4 deletions CubicPadSynth/source/version.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
#define SUB_VERSION_STR "1"
#define SUB_VERSION_INT 1

#define RELEASE_NUMBER_STR "26"
#define RELEASE_NUMBER_INT 26
#define RELEASE_NUMBER_STR "27"
#define RELEASE_NUMBER_INT 27

#define BUILD_NUMBER_STR "26"
#define BUILD_NUMBER_INT 26
#define BUILD_NUMBER_STR "27"
#define BUILD_NUMBER_INT 27

#define FULL_VERSION_STR \
MAJOR_VERSION_STR "." SUB_VERSION_STR "." RELEASE_NUMBER_STR "." BUILD_NUMBER_STR
Expand Down
2 changes: 1 addition & 1 deletion EnvelopedSine/source/dsp/dspcore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ void DSPCORE_NAME::noteOn(int32_t identifier, int16_t pitch, float tuning, float
size_t index = 0;
while (index < indices.size() && noteIndices.size() < nUnison) {
const auto ndx = indices[index];
if (notes[ndx].id == identifier || notes[ndx].state == NoteState::rest) {
if (notes[ndx].state == NoteState::rest) {
noteIndices.push_back(ndx);
indices.erase(indices.begin() + index);
} else {
Expand Down
8 changes: 4 additions & 4 deletions EnvelopedSine/source/version.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
#define SUB_VERSION_STR "1"
#define SUB_VERSION_INT 1

#define RELEASE_NUMBER_STR "25"
#define RELEASE_NUMBER_INT 25
#define RELEASE_NUMBER_STR "26"
#define RELEASE_NUMBER_INT 26

#define BUILD_NUMBER_STR "25"
#define BUILD_NUMBER_INT 25
#define BUILD_NUMBER_STR "26"
#define BUILD_NUMBER_INT 26

#define FULL_VERSION_STR \
MAJOR_VERSION_STR "." SUB_VERSION_STR "." RELEASE_NUMBER_STR "." BUILD_NUMBER_STR
Expand Down
10 changes: 3 additions & 7 deletions IterativeSinCluster/source/dsp/dspcore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ template<typename Sample> void NOTE_NAME<Sample>::rest()
state = NoteState::rest;
id = -1;
gain = 0;
gainEnvelope.terminate();
}

template<typename Sample> std::array<Sample, 2> NOTE_NAME<Sample>::process()
Expand Down Expand Up @@ -340,7 +341,6 @@ void DSPCORE_NAME::noteOn(int32_t noteId, int16_t pitch, float tuning, float vel
size_t mostSilent = 0;
float gain = 1.0f;
for (; noteIdx < nVoice; ++noteIdx) {
if (notes[noteIdx].id == noteId) break;
if (notes[noteIdx].state == NoteState::rest) break;
if (!notes[noteIdx].gainEnvelope.isAttacking() && notes[noteIdx].gain < gain) {
gain = notes[noteIdx].gain;
Expand Down Expand Up @@ -383,11 +383,7 @@ void DSPCORE_NAME::noteOn(int32_t noteId, int16_t pitch, float tuning, float vel

void DSPCORE_NAME::noteOff(int32_t noteId)
{
size_t i = 0;
for (; i < notes.size(); ++i) {
if (notes[i].id == noteId) break;
for (auto &x : notes) {
if (x.id == noteId && x.state != NoteState::release) x.release();
}
if (i >= notes.size()) return;

notes[i].release();
}
22 changes: 9 additions & 13 deletions IterativeSinCluster/source/dsp/envelope.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,17 +121,15 @@ template<typename Sample> class ExpADSREnvelope {
Sample sustainLevel,
Sample releaseTime,
Sample noteFreq,
Sample curve)
Sample curve_)
{
if (declickCounter >= declickLength || state == State::terminated) declickCounter = 0;
declickCounter = 0;
state = State::attack;

sustain = std::max<Sample>(Sample(0.0), std::min<Sample>(sustainLevel, Sample(1.0)));

offset = value;
range = Sample(1.0) - value;

this->curve = curve;
range = Sample(1);
curve = curve_;

attackTime = adaptTime(attackTime, noteFreq);
atk.reset(sampleRate, attackTime);
Expand Down Expand Up @@ -182,7 +180,6 @@ template<typename Sample> class ExpADSREnvelope {
{
state = State::terminated;
value = 0;
offset = 0;
range = 1;
sustain = 1;
}
Expand All @@ -204,31 +201,31 @@ template<typename Sample> class ExpADSREnvelope {
case State::attack: {
const auto atkPos = atk.process();
const auto atkMix = atkPos + curve * (atkNeg.process() - atkPos);
value = range * declickIn(atkMix) + offset;
value = range * atkMix;
if (atk.isTerminated()) {
state = State::decay;
range = Sample(1.0) - sustain;
}
} break;

case State::decay:
value = range * declickIn(dec.process()) + sustain;
value = range * dec.process() + sustain;
if (value <= sustain) state = State::sustain;
break;

case State::sustain:
value = declickIn(sustain);
value = sustain;
break;

case State::release:
value = range * declickIn(rel.process());
value = range * rel.process();
if (rel.isTerminated()) state = State::terminated;
break;

default:
return 0;
}
return value;
return declickIn(value);
}

protected:
Expand All @@ -246,7 +243,6 @@ template<typename Sample> class ExpADSREnvelope {
Sample value = 0;
Sample curve = 0;
Sample sampleRate = 44100;
Sample offset = 0;
Sample range = 1;
Sample sustain = 1;
};
Expand Down
1 change: 1 addition & 0 deletions IterativeSinCluster/source/plugprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ tresult PLUGIN_API PlugProcessor::setActive(TBool state)
if (state) {
dsp->setup(processSetup.sampleRate);
} else {
dsp->reset();
lastState = 0;
}
return AudioEffect::setActive(state);
Expand Down
8 changes: 4 additions & 4 deletions IterativeSinCluster/source/version.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
#define SUB_VERSION_STR "1"
#define SUB_VERSION_INT 1

#define RELEASE_NUMBER_STR "27"
#define RELEASE_NUMBER_INT 27
#define RELEASE_NUMBER_STR "28"
#define RELEASE_NUMBER_INT 28

#define BUILD_NUMBER_STR "27"
#define BUILD_NUMBER_INT 27
#define BUILD_NUMBER_STR "28"
#define BUILD_NUMBER_INT 28

#define FULL_VERSION_STR \
MAJOR_VERSION_STR "." SUB_VERSION_STR "." RELEASE_NUMBER_STR "." BUILD_NUMBER_STR
Expand Down
1 change: 0 additions & 1 deletion LightPadSynth/source/dsp/dspcore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,6 @@ void DSPCore::noteOn(int32_t identifier, int16_t pitch, float tuning, float velo

// Pick up note from resting one.
for (size_t index = 0; index < nVoice; ++index) {
if (notes[index].id == identifier) noteIndices.push_back(index);
if (notes[index].state == NoteState::rest) noteIndices.push_back(index);
if (noteIndices.size() >= nUnison) break;
}
Expand Down
8 changes: 4 additions & 4 deletions LightPadSynth/source/version.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
#define SUB_VERSION_STR "1"
#define SUB_VERSION_INT 1

#define RELEASE_NUMBER_STR "24"
#define RELEASE_NUMBER_INT 24
#define RELEASE_NUMBER_STR "25"
#define RELEASE_NUMBER_INT 25

#define BUILD_NUMBER_STR "24"
#define BUILD_NUMBER_INT 24
#define BUILD_NUMBER_STR "25"
#define BUILD_NUMBER_INT 25

#define FULL_VERSION_STR \
MAJOR_VERSION_STR "." SUB_VERSION_STR "." RELEASE_NUMBER_STR "." BUILD_NUMBER_STR
Expand Down
20 changes: 12 additions & 8 deletions SyncSawSynth/source/dsp/dspcore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,6 @@ void DSPCore::noteOn(int32_t noteId, int16_t pitch, float tuning, float velocity
size_t mostSilent = 0;
float gain = 1.0f;
for (; i < nVoice; ++i) {
if (notes[i][0]->id == noteId) break;
if (notes[i][0]->state == NoteState::rest) break;
if (!notes[i][0]->gainEnvelope.isAttacking() && notes[i][0]->gain < gain) {
gain = notes[i][0]->gain;
Expand Down Expand Up @@ -566,12 +565,17 @@ void DSPCore::noteOn(int32_t noteId, int16_t pitch, float tuning, float velocity

void DSPCore::noteOff(int32_t noteId)
{
size_t i = 0;
for (; i < notes.size(); ++i) {
if (notes[i][0]->id == noteId) break;
// size_t i = 0;
// for (; i < notes.size(); ++i) {
// if (notes[i][0]->id == noteId) break;
// }
// if (i >= notes.size()) return;

// notes[i][0]->release();
// notes[i][1]->release();

for (auto &x : notes) {
if (x[0]->id == noteId) x[0]->release();
if (x[1]->id == noteId) x[1]->release();
}
if (i >= notes.size()) return;

notes[i][0]->release();
notes[i][1]->release();
}
11 changes: 6 additions & 5 deletions SyncSawSynth/source/dsp/envelope.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@ template<typename Sample> class ExpADSREnvelope {
Sample declickTime = Sample(0.001),
Sample threshold = Sample(1e-5))
{
if (state == State::terminated) sustain.reset(sustainLevel);
state = State::attack;

value = threshold;
sustain.reset(sustainLevel);
set(attackTime, decayTime, sustainLevel, releaseTime, declickTime, threshold);
}

Expand Down Expand Up @@ -107,12 +108,12 @@ template<typename Sample> class ExpADSREnvelope {
releaseRange = value - value * sustain.getValue() + sustain.getValue();
break;

case State::terminated:
return;

default:
case State::sustain:
releaseRange = sustain.getValue();
break;

default:
return;
}

value = Sample(1.0);
Expand Down
14 changes: 7 additions & 7 deletions SyncSawSynth/source/plugprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,17 +121,17 @@ void PlugProcessor::handleEvent(Vst::ProcessData &data)
// List of DAW that doesn't support note ID. Probably more.
// - Ableton Live 10.1.6
// - PreSonus Studio One 4.6.1
auto noteId
= event.noteOn.noteId == -1 ? event.noteOn.pitch : event.noteOn.noteId;
dsp.pushMidiNote(
true, event.sampleOffset,
event.noteOn.noteId == -1 ? event.noteOn.pitch : event.noteOn.noteId,
event.noteOn.pitch, event.noteOn.tuning, event.noteOn.velocity);
true, event.sampleOffset, noteId, event.noteOn.pitch, event.noteOn.tuning,
event.noteOn.velocity);
} break;

case Vst::Event::kNoteOffEvent: {
dsp.pushMidiNote(
false, event.sampleOffset,
event.noteOff.noteId == -1 ? event.noteOff.pitch : event.noteOff.noteId, 0, 0,
0);
auto noteId
= event.noteOff.noteId == -1 ? event.noteOff.pitch : event.noteOff.noteId;
dsp.pushMidiNote(false, event.sampleOffset, noteId, 0, 0, 0);
} break;

// Add other event type here.
Expand Down
8 changes: 4 additions & 4 deletions SyncSawSynth/source/version.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
#define SUB_VERSION_STR "1"
#define SUB_VERSION_INT 1

#define RELEASE_NUMBER_STR "29"
#define RELEASE_NUMBER_INT 29
#define RELEASE_NUMBER_STR "30"
#define RELEASE_NUMBER_INT 30

#define BUILD_NUMBER_STR "29"
#define BUILD_NUMBER_INT 29
#define BUILD_NUMBER_STR "30"
#define BUILD_NUMBER_INT 30

#define FULL_VERSION_STR \
MAJOR_VERSION_STR "." SUB_VERSION_STR "." RELEASE_NUMBER_STR "." BUILD_NUMBER_STR
Expand Down
1 change: 0 additions & 1 deletion TestBedSynth/source/dsp/dspcore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,6 @@ void DSPCore::noteOn(

// Pick up note from resting one.
for (size_t index = 0; index < nVoice; ++index) {
if (notes[index].id == noteId) noteIndices.push_back(index);
if (notes[index].state == NoteState::rest) noteIndices.push_back(index);
if (noteIndices.size() >= nUnison) break;
}
Expand Down
8 changes: 4 additions & 4 deletions TestBedSynth/source/version.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
#define SUB_VERSION_STR "0"
#define SUB_VERSION_INT 0

#define RELEASE_NUMBER_STR "5"
#define RELEASE_NUMBER_INT 5
#define RELEASE_NUMBER_STR "6"
#define RELEASE_NUMBER_INT 6

#define BUILD_NUMBER_STR "5"
#define BUILD_NUMBER_INT 5
#define BUILD_NUMBER_STR "6"
#define BUILD_NUMBER_INT 6

#define FULL_VERSION_STR \
MAJOR_VERSION_STR "." SUB_VERSION_STR "." RELEASE_NUMBER_STR "." BUILD_NUMBER_STR
Expand Down
Loading

0 comments on commit de150f6

Please sign in to comment.