mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
Synthesiser and MPESynthesiser: added an additional parameter to setMinimumRenderingSubdivisionSize to allow for both the legacy behaviour (setting the strict minimum on subdivision size) and the current behaviour (first sample will always be sample-accurate, but then the first subdivision may be < minimum).
This commit is contained in:
parent
6fdb7e33bc
commit
9100d1c89e
4 changed files with 25 additions and 7 deletions
|
|
@ -25,7 +25,8 @@
|
|||
MPESynthesiserBase::MPESynthesiserBase()
|
||||
: instrument (new MPEInstrument),
|
||||
sampleRate (0),
|
||||
minimumSubBlockSize (32)
|
||||
minimumSubBlockSize (32),
|
||||
subBlockSubdivisionIsStrict (false)
|
||||
{
|
||||
instrument->addListener (this);
|
||||
}
|
||||
|
|
@ -123,7 +124,7 @@ void MPESynthesiserBase::renderNextBlock (AudioBuffer<floatType>& outputAudio,
|
|||
break;
|
||||
}
|
||||
|
||||
if (samplesToNextMidiMessage < (firstEvent ? 1 : minimumSubBlockSize))
|
||||
if (samplesToNextMidiMessage < ((firstEvent && ! subBlockSubdivisionIsStrict) ? 1 : minimumSubBlockSize))
|
||||
{
|
||||
handleMidiEvent (m);
|
||||
continue;
|
||||
|
|
@ -157,8 +158,9 @@ void MPESynthesiserBase::setCurrentPlaybackSampleRate (const double newRate)
|
|||
}
|
||||
|
||||
//==============================================================================
|
||||
void MPESynthesiserBase::setMinimumRenderingSubdivisionSize (int numSamples) noexcept
|
||||
void MPESynthesiserBase::setMinimumRenderingSubdivisionSize (int numSamples, bool shouldBeStrict) noexcept
|
||||
{
|
||||
jassert (numSamples > 0); // it wouldn't make much sense for this to be less than 1
|
||||
minimumSubBlockSize = numSamples;
|
||||
subBlockSubdivisionIsStrict = shouldBeStrict;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -127,8 +127,14 @@ public:
|
|||
The default setting is 32, which means that midi messages are accurate to about < 1ms
|
||||
accuracy, which is probably fine for most purposes, but you may want to increase or
|
||||
decrease this value for your synth.
|
||||
|
||||
If shouldBeStrict is true, the audio sub-blocks will strictly never be smaller than numSamples.
|
||||
|
||||
If shouldBeStrict is false (default), the first audio sub-block in the buffer is allowed
|
||||
to be smaller, to make sure that the first MIDI event in a buffer will always be sample-accurate
|
||||
(this can sometimes help to avoid quantisation or phasing issues).
|
||||
*/
|
||||
void setMinimumRenderingSubdivisionSize (int numSamples) noexcept;
|
||||
void setMinimumRenderingSubdivisionSize (int numSamples, bool shouldBeStrict = false) noexcept;
|
||||
|
||||
//==============================================================================
|
||||
/** Puts the synthesiser into legacy mode.
|
||||
|
|
@ -185,6 +191,7 @@ private:
|
|||
CriticalSection noteStateLock;
|
||||
double sampleRate;
|
||||
int minimumSubBlockSize;
|
||||
bool subBlockSubdivisionIsStrict;
|
||||
|
||||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MPESynthesiserBase)
|
||||
};
|
||||
|
|
|
|||
|
|
@ -88,6 +88,7 @@ Synthesiser::Synthesiser()
|
|||
: sampleRate (0),
|
||||
lastNoteOnCounter (0),
|
||||
minimumSubBlockSize (32),
|
||||
subBlockSubdivisionIsStrict (false),
|
||||
shouldStealNotes (true)
|
||||
{
|
||||
for (int i = 0; i < numElementsInArray (lastPitchWheelValues); ++i)
|
||||
|
|
@ -147,10 +148,11 @@ void Synthesiser::setNoteStealingEnabled (const bool shouldSteal)
|
|||
shouldStealNotes = shouldSteal;
|
||||
}
|
||||
|
||||
void Synthesiser::setMinimumRenderingSubdivisionSize (int numSamples) noexcept
|
||||
void Synthesiser::setMinimumRenderingSubdivisionSize (int numSamples, bool shouldBeStrict) noexcept
|
||||
{
|
||||
jassert (numSamples > 0); // it wouldn't make much sense for this to be less than 1
|
||||
minimumSubBlockSize = numSamples;
|
||||
subBlockSubdivisionIsStrict = shouldBeStrict;
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
|
|
@ -204,7 +206,7 @@ void Synthesiser::processNextBlock (AudioBuffer<floatType>& outputAudio,
|
|||
break;
|
||||
}
|
||||
|
||||
if (samplesToNextMidiMessage < (firstEvent ? 1 : minimumSubBlockSize))
|
||||
if (samplesToNextMidiMessage < ((firstEvent && ! subBlockSubdivisionIsStrict) ? 1 : minimumSubBlockSize))
|
||||
{
|
||||
handleMidiEvent (m);
|
||||
continue;
|
||||
|
|
|
|||
|
|
@ -539,8 +539,14 @@ public:
|
|||
The default setting is 32, which means that midi messages are accurate to about < 1ms
|
||||
accuracy, which is probably fine for most purposes, but you may want to increase or
|
||||
decrease this value for your synth.
|
||||
|
||||
If shouldBeStrict is true, the audio sub-blocks will strictly never be smaller than numSamples.
|
||||
|
||||
If shouldBeStrict is false (default), the first audio sub-block in the buffer is allowed
|
||||
to be smaller, to make sure that the first MIDI event in a buffer will always be sample-accurate
|
||||
(this can sometimes help to avoid quantisation or phasing issues).
|
||||
*/
|
||||
void setMinimumRenderingSubdivisionSize (int numSamples) noexcept;
|
||||
void setMinimumRenderingSubdivisionSize (int numSamples, bool shouldBeStrict = false) noexcept;
|
||||
|
||||
protected:
|
||||
//==============================================================================
|
||||
|
|
@ -615,6 +621,7 @@ private:
|
|||
double sampleRate;
|
||||
uint32 lastNoteOnCounter;
|
||||
int minimumSubBlockSize;
|
||||
bool subBlockSubdivisionIsStrict;
|
||||
bool shouldStealNotes;
|
||||
BigInteger sustainPedalsDown;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue