diff --git a/modules/gin b/modules/gin index 07b7cc5..39aa9c9 160000 --- a/modules/gin +++ b/modules/gin @@ -1 +1 @@ -Subproject commit 07b7cc59960212fe8f4257212927697e0d1b3ce6 +Subproject commit 39aa9c9bf5fc2427e41fad2f01ce3796be32172a diff --git a/plugin/Source/PluginProcessor.cpp b/plugin/Source/PluginProcessor.cpp index 80247b6..6aaef44 100644 --- a/plugin/Source/PluginProcessor.cpp +++ b/plugin/Source/PluginProcessor.cpp @@ -334,7 +334,7 @@ void WavetableAudioProcessor::ReverbParams::setup (WavetableAudioProcessor& p) mix = p.addExtParam ("rvbMix", "Mix", "", "", {0.0f, 1.0f, 0.0f, 1.0f}, 0.0f, 0.0f); } -static void loadWaveTable (juce::OwnedArray& table, const juce::MemoryBlock& wav) +static void loadWaveTable (juce::OwnedArray& table, double sr, const juce::MemoryBlock& wav) { auto is = new juce::MemoryInputStream (wav, false); if (auto reader = std::unique_ptr (juce::WavAudioFormat().createReaderFor (is, true))) @@ -342,7 +342,7 @@ static void loadWaveTable (juce::OwnedArray& table, juce::AudioSampleBuffer buf (1, int (reader->lengthInSamples)); reader->read (&buf, 0, int (reader->lengthInSamples), 0, true, false); - loadWavetables (table, buf, reader->sampleRate, gin::getWavetableSize (wav)); + loadWavetables (table, sr, buf, reader->sampleRate, gin::getWavetableSize (wav)); } } @@ -412,11 +412,28 @@ void WavetableAudioProcessor::reloadWavetables() return {}; }; + auto shouldLoad = [&] (int osc, const juce::String& name, double sr) + { + auto& v = curTables[osc]; + if (v.name == name && gin::almostEqual (v.sampleRate, sr)) + return false; + + v.name = name; + v.sampleRate = sr; + return true; + }; + + auto sr = gin::Processor::getSampleRate(); + if (sr == 0) + return; + if (auto mb = loadMemory (osc1Table.toString()); mb.getSize() > 0) - loadWaveTable (osc1Tables, mb); + if (shouldLoad (0, osc1Table.toString(), sr)) + loadWaveTable (osc1Tables, sr, mb); if (auto mb = loadMemory (osc2Table.toString()); mb.getSize() > 0) - loadWaveTable (osc2Tables, mb); + if (shouldLoad (1, osc2Table.toString(), sr)) + loadWaveTable (osc2Tables, sr, mb); } void WavetableAudioProcessor::incWavetable (int osc, int delta) diff --git a/plugin/Source/PluginProcessor.h b/plugin/Source/PluginProcessor.h index 1412c02..cd08a4b 100644 --- a/plugin/Source/PluginProcessor.h +++ b/plugin/Source/PluginProcessor.h @@ -251,6 +251,14 @@ public: juce::AudioPlayHead* playhead = nullptr; + struct CurTable + { + juce::String name; + double sampleRate = 0.0; + }; + + CurTable curTables[Cfg::numOSCs]; + //============================================================================== JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (WavetableAudioProcessor) };