mirror of
https://codeberg.org/armin/wavetable.git
synced 2026-09-01 05:50:46 +02:00
Fixed crash loading wavetable when changing preset
This commit is contained in:
parent
9d6da9bb2d
commit
2a5b9d973a
3 changed files with 51 additions and 33 deletions
|
|
@ -3,6 +3,7 @@
|
|||
- Fixed pan when unison enabled
|
||||
- Fixed preset overwrite dialog not showing
|
||||
- Added resizable UI
|
||||
- Fixed crash loading wavetable when changing preset
|
||||
|
||||
0.0.2:
|
||||
|
||||
|
|
|
|||
|
|
@ -351,39 +351,6 @@ void WavetableAudioProcessor::ReverbParams::setup (WavetableAudioProcessor& p)
|
|||
mix = p.addExtParam ("rvbMix", "Mix", "", "", {0.0f, 1.0f, 0.0f, 1.0f}, 0.0f, 0.0f);
|
||||
}
|
||||
|
||||
static bool loadWaveTable (juce::OwnedArray<gin::BandLimitedLookupTable>& table, double sr, const juce::MemoryBlock& wav, const juce::String& format)
|
||||
{
|
||||
auto is = new juce::MemoryInputStream (wav, false);
|
||||
|
||||
if (format == "wav")
|
||||
{
|
||||
if (auto reader = std::unique_ptr<juce::AudioFormatReader> (juce::WavAudioFormat().createReaderFor (is, true)))
|
||||
{
|
||||
if (auto sz = gin::getWavetableSize (wav); sz > 0)
|
||||
{
|
||||
juce::AudioSampleBuffer buf (1, int (reader->lengthInSamples));
|
||||
reader->read (&buf, 0, int (reader->lengthInSamples), 0, true, false);
|
||||
|
||||
loadWavetables (table, sr, buf, reader->sampleRate, sz);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (format == "flac")
|
||||
{
|
||||
if (auto reader = std::unique_ptr<juce::AudioFormatReader> (juce::FlacAudioFormat().createReaderFor (is, true)))
|
||||
{
|
||||
juce::AudioSampleBuffer buf (1, int (reader->lengthInSamples));
|
||||
reader->read (&buf, 0, int (reader->lengthInSamples), 0, true, false);
|
||||
|
||||
loadWavetables (table, sr, buf, reader->sampleRate, 2048);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void convertWavetables()
|
||||
{
|
||||
auto src = juce::File (__FILE__).getChildFile ("../../Resources/Wavetables");
|
||||
|
|
@ -688,6 +655,8 @@ void WavetableAudioProcessor::releaseResources()
|
|||
void WavetableAudioProcessor::processBlock (juce::AudioBuffer<float>& buffer, juce::MidiBuffer& midi)
|
||||
{
|
||||
juce::ScopedNoDenormals noDenormals;
|
||||
if (! dspLock.tryEnter())
|
||||
return;
|
||||
|
||||
startBlock();
|
||||
setMPE (globalParams.mpe->isOn());
|
||||
|
|
@ -729,6 +698,8 @@ void WavetableAudioProcessor::processBlock (juce::AudioBuffer<float>& buffer, ju
|
|||
scopeFifo.write (buffer);
|
||||
|
||||
endBlock (buffer.getNumSamples());
|
||||
|
||||
dspLock.exit();
|
||||
}
|
||||
|
||||
juce::Array<float> WavetableAudioProcessor::getLiveFilterCutoff()
|
||||
|
|
@ -911,6 +882,49 @@ void WavetableAudioProcessor::updateParams (int newBlockSize)
|
|||
outputGain.setGain (modMatrix.getValue (globalParams.level));
|
||||
}
|
||||
|
||||
bool WavetableAudioProcessor::loadWaveTable (juce::OwnedArray<gin::BandLimitedLookupTable>& table, double sr, const juce::MemoryBlock& wav, const juce::String& format)
|
||||
{
|
||||
auto is = new juce::MemoryInputStream (wav, false);
|
||||
|
||||
if (format == "wav")
|
||||
{
|
||||
if (auto reader = std::unique_ptr<juce::AudioFormatReader> (juce::WavAudioFormat().createReaderFor (is, true)))
|
||||
{
|
||||
if (auto sz = gin::getWavetableSize (wav); sz > 0)
|
||||
{
|
||||
juce::AudioSampleBuffer buf (1, int (reader->lengthInSamples));
|
||||
reader->read (&buf, 0, int (reader->lengthInSamples), 0, true, false);
|
||||
|
||||
juce::OwnedArray<gin::BandLimitedLookupTable> t;
|
||||
loadWavetables (t, sr, buf, reader->sampleRate, sz);
|
||||
|
||||
juce::ScopedLock sl (dspLock);
|
||||
std::swap (t, table);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (format == "flac")
|
||||
{
|
||||
if (auto reader = std::unique_ptr<juce::AudioFormatReader> (juce::FlacAudioFormat().createReaderFor (is, true)))
|
||||
{
|
||||
juce::AudioSampleBuffer buf (1, int (reader->lengthInSamples));
|
||||
reader->read (&buf, 0, int (reader->lengthInSamples), 0, true, false);
|
||||
|
||||
juce::OwnedArray<gin::BandLimitedLookupTable> t;
|
||||
loadWavetables (t, sr, buf, reader->sampleRate, 2048);
|
||||
|
||||
juce::ScopedLock sl (dspLock);
|
||||
std::swap (t, table);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void WavetableAudioProcessor::handleMidiEvent (const juce::MidiMessage& m)
|
||||
{
|
||||
MPESynthesiser::handleMidiEvent (m);
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ public:
|
|||
void loadUserWavetable (int osc, const juce::File f);
|
||||
|
||||
void applyEffects (juce::AudioSampleBuffer& buffer);
|
||||
bool loadWaveTable (juce::OwnedArray<gin::BandLimitedLookupTable>& table, double sr, const juce::MemoryBlock& wav, const juce::String& format);
|
||||
|
||||
// Voice Params
|
||||
struct OSCParams
|
||||
|
|
@ -275,6 +276,8 @@ public:
|
|||
|
||||
CurTable curTables[Cfg::numOSCs];
|
||||
|
||||
juce::CriticalSection dspLock;
|
||||
|
||||
//==============================================================================
|
||||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (WavetableAudioProcessor)
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue