Skip to content

Commit

Permalink
plugin: maintain samplerate when switching jsfx
Browse files Browse the repository at this point in the history
without this, switching plugins will re-initialize the jsfx to 44100 Hz
  • Loading branch information
JoepVanlier committed Jul 8, 2024
1 parent f5ae7e5 commit ef4a161
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions plugin/processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ struct YsfxProcessor::Impl : public juce::AudioProcessorListener {
ysfx::sync_bitset64 m_sliderParametersChanged;
YsfxInfo::Ptr m_info{new YsfxInfo};

double m_sample_rate{44100.0};
uint32_t m_block_size{256};

//==========================================================================
void processBlockGenerically(const void *inputs[], void *outputs[], uint32_t numIns, uint32_t numOuts, uint32_t numFrames, uint32_t processBits, juce::MidiBuffer &midiMessages);
void processMidiInput(juce::MidiBuffer &midi);
Expand Down Expand Up @@ -212,6 +215,9 @@ void YsfxProcessor::prepareToPlay(double sampleRate, int samplesPerBlock)
sus.lockCallbacks();

ysfx_t *fx = m_impl->m_fx.get();
m_impl->m_sample_rate = sampleRate;
m_impl->m_block_size = samplesPerBlock;

ysfx_set_sample_rate(fx, sampleRate);
ysfx_set_block_size(fx, (uint32_t)samplesPerBlock);

Expand Down Expand Up @@ -648,6 +654,10 @@ void YsfxProcessor::Impl::installNewFx(YsfxInfo::Ptr info)
ysfx_add_ref(fx);
std::atomic_store(&m_info, info);

ysfx_set_sample_rate(fx, m_sample_rate);
ysfx_set_block_size(fx, m_block_size);
ysfx_init(fx);

for (uint32_t i = 0; i < ysfx_max_sliders; ++i) {
YsfxParameter *param = m_self->getYsfxParameter((int)i);
param->setEffect(fx);
Expand Down

0 comments on commit ef4a161

Please sign in to comment.