mirror of
https://codeberg.org/armin/wavetable.git
synced 2026-09-01 05:50:46 +02:00
Use correct sample rate for generating wave tables
This commit is contained in:
parent
2dc994bcff
commit
134fe08983
3 changed files with 30 additions and 5 deletions
|
|
@ -1 +1 @@
|
||||||
Subproject commit 07b7cc59960212fe8f4257212927697e0d1b3ce6
|
Subproject commit 39aa9c9bf5fc2427e41fad2f01ce3796be32172a
|
||||||
|
|
@ -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);
|
mix = p.addExtParam ("rvbMix", "Mix", "", "", {0.0f, 1.0f, 0.0f, 1.0f}, 0.0f, 0.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void loadWaveTable (juce::OwnedArray<gin::BandLimitedLookupTable>& table, const juce::MemoryBlock& wav)
|
static void loadWaveTable (juce::OwnedArray<gin::BandLimitedLookupTable>& table, double sr, const juce::MemoryBlock& wav)
|
||||||
{
|
{
|
||||||
auto is = new juce::MemoryInputStream (wav, false);
|
auto is = new juce::MemoryInputStream (wav, false);
|
||||||
if (auto reader = std::unique_ptr<juce::AudioFormatReader> (juce::WavAudioFormat().createReaderFor (is, true)))
|
if (auto reader = std::unique_ptr<juce::AudioFormatReader> (juce::WavAudioFormat().createReaderFor (is, true)))
|
||||||
|
|
@ -342,7 +342,7 @@ static void loadWaveTable (juce::OwnedArray<gin::BandLimitedLookupTable>& table,
|
||||||
juce::AudioSampleBuffer buf (1, int (reader->lengthInSamples));
|
juce::AudioSampleBuffer buf (1, int (reader->lengthInSamples));
|
||||||
reader->read (&buf, 0, int (reader->lengthInSamples), 0, true, false);
|
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 {};
|
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)
|
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)
|
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)
|
void WavetableAudioProcessor::incWavetable (int osc, int delta)
|
||||||
|
|
|
||||||
|
|
@ -251,6 +251,14 @@ public:
|
||||||
|
|
||||||
juce::AudioPlayHead* playhead = nullptr;
|
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)
|
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (WavetableAudioProcessor)
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue