dsp_free() - is it possible to disable and enable DSP within an external?
Heya,
I'm waning to create a function that can disable and enable the dsp within my external, so that it can save resources when it isn't needed without the need for deleting the object in MAX.
I thought I'd start off by trying calling dsp_free() for disabling and dsp_setup() for enabling. Whilst it does stop and start the audio processing, on disabling (dsp_free) it sends out a nasty noise (like a saw tooth wave) permanently until I call dsp_setup() again.
Is there a proper way to do this within-side an external?
Cheers!
Yes, of course there is.
First of all, dsp_setup() and dsp_free() allocate and deallocate internal resources to allow Max to successfully include your object perform routine in the DSP chain. They are intended to be called in your "myobject_new" and "myobject_free" methods respectively. Nowhere else in your code you should be calling dsp_setup() and dsp_free().
The way you bypass audio processing in your external is very simple, maybe too simple...
In your perform method you write:
if (x->bypass) {
while (sampleframes--) {
*out++ = *in++;
}
/*
or you could write also:
sysmem_copyptr(in, out, sizeof(double) * sampleframes);
*/
}
else {
// do your dsp here...
}
Obviously that's pseudo-code that I just wrote off the top of my head, but it should give you the idea.
Hope it helps.
-Luigi
Awesome, that helps a lot. Thanks Luigi!