Help - Search - Members - Calendar
Full Version: Last_sample in dsp_tutorial is reset when modifying GUI?
Hydrogenaudio Forums > Hosted Forums > foobar2000 > Development - (fb2k)
Esben84
Dear foobar experts,

I've made a DSP module based on the excellent foobar tutorial by foosion. The only remaining problem I'm experiencing is that the audio clicks and pops when modifying the GUI. I've traced the problem to an equivalent code in the tutorial.
In the on_chunk function, it starts with:

CODE
if (channel_count != m_last_sample.get_size()) {
    unsigned channel_count = chunk->get_channels();
    ...
    // number of channels has changed - (re)initialize "history"
    m_last_sample.set_size(channel_count);
    m_last_sample.fill<audio_sample>(0);
}


For some reason the size of m_last_sample is 0, when the GUI slider is moved. The scrolling action results in m_dirty = true; and update_display();
Maybe this causes the update_display() function to reset the array, or create a new blank instance?
In my DSP module more samples are stored (2. order IIR filter), so the buffer reset is noticeable. When this mystery is solved, I can finally upload the plugin smile.gif

I've not been able to locate where the array is reset. Is there any way to avoid this reset?
Yirkha
The m_last_sample array is "reset" (rather "appears reset") because a completely new instance of your DSP class is instantiated. The dsp_entry_impl helper works so that updated configuration preset is passed in to the constructor, hence a new instance needs to be created each time.
Esben84
Thanks a lot for the explanation Yirkha, that makes sense. Is it possible to pass the m_last_sample array between the two instances of the DSP class? The configuration preset with all the settings is passed without any problems. smile.gif
Yirkha
Yes, the preset is passed fine, but it's also stored in the configuration, for example. I'm sure you know abusing it for remembering old contents of some buffer would be really ugly.

Well you could try to use the old DSP API (dsp_entry_impl_t<> instead of dsp_entry_v2_impl_t<> etc.), it modified the original preset and operated on the same DSP instance all the time. I think.
Though maybe it won't work anyway, in case the core simply calls dsp_entry::g_show_config_popup_v2(), which supplies only emulation of the old behavior for compatibility.
Esben84
Yes, passing the samples through the preset would be a very ugly way to pass the last samples. My brother suggested moving the variables outside dsp_loudspeakereq, and it seems to work well, although it's probably not the nicest way to do it.

Thanks a lot for the suggestions smile.gif
foosion
There can be multiple instances of your DSP class, in different threads even, for example one for live playback and one for conversion. That is why storing the state of your DSP in a global variable is another really bad idea.
Esben84
Just tried converting a song at the same time as playing back a music file, and you're right, it does not work crying.gif

I wish there was a simple way to do it, I'm not skilled enough to change the code into another Foobar DSP API.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.