Terminate an active Audio Object?

Status
Not open for further replies.

Synthetech

Active member
I noticed a Audio Object isn't active until you make the Begin statement.

But is there a End statement of sorts??

I was curious if I could terminate either Audio Waveforms, amps, mixers, filters and effects objects in a running sketch.

Point is to stop them to give relinquish processing power for other objects when the previous ones are not needed.


I would like to have multiple branched configurations of objects and switch back and forth..
It would also be helpful to stop one effect while starting another.
 
My understanding is that setting gain to zero for a object causes it to not consume most of the CPU cycles normally allocated, but still occupies the relevant RAM so not as powerful as what you are trying to do.
 
The audio library doesn't have any way to turn off individual objects. Perhaps this will be added someday, but it seems unlikely its extra overhead would be worthwhile.

Several of the objects have code to detect when their output is silent and they avoid transmitting data. Almost all objects have code to detect when they receive no data (as opposed to a block of all zeros) and they avoid doing any work and avoid sending any data. You can use that to effectively turn off parts of your system.

Of course, some objects still produce output. But even those usually have code to detect the no data case. For example, the variable filter detects if no data is arriving on the filter frequency modulation input. If it gets an incoming signal to filter, but no modulation, it runs the faster code that doesn't recompute the filter coefficients. Of course, if it gets no main input signal, it discards any incoming modulation signal and doesn't send any output.

Almost everything in the library is designed this way, to detect no data inputs and avoid doing extra work and especially to send no data when the output would be silent. So adding another layer to selectively disable objects hardly seems like a good use of the extra overhead it would add to all audio processing.
 
Thank you for that explanation Paul.

Armed with this knowledge, I feel more confident in building a design with multiple object configurations.

And thanks to you also Gremlin for what appears to be the same info..
 
What I have been doing to achieve your goal is to add public functions to objects so as to enable/disable the blocks so that I have:
MyObject.enable(); and MyObject.disable();
which set/reset a private boolean. Then the update() function simply tests the boolean, and if disabled - simply releases the input data blocks and returns, otherwise completes the processing. It has worked well for me so far when I need only one of several time-consuming operations at a time. For example, today I needed to select (from a menu) one of five demodulation schemes in an SDR, so each demodulator object has its enable/disable functions, and the five outputs fed into a pair of summers.

I have also similarly modded several of the standard audio library objects to provide a pass-through mode that can be set/reset to include/exclude series operations in a processing chain.
 
Last edited:
Several of the objects have code to detect when their output is silent and they avoid transmitting data. Almost all objects have code to detect when they receive no data (as opposed to a block of all zeros) and they avoid doing any work and avoid sending any data. You can use that to effectively turn off parts of your system.
If I understand that correctly, I'll just insert Faders (or Mixers) before the effect chains I might want to turn on/off?

Like in this example:
audio_conf.jpg
There is two effect chains there: one with a chorus and a flanger, the other with a delay.

If I want just the chorus and the flanger, I'll set the fade1 to full, and the mixer1 inputs to zero.

If I want just the delay, I'll set the fade1 to zero (fadeOut), and input 0 of mixer1 to zero, and input 1 to full.

If I want both effects chains in parallel, I'll set the fade1 to full, and input 0 of mixer1 to zero, and input 1 to full.

If I want both effects chains in serial, I'll set the fade1 to full, and input 0 of mixer1 to full, and input 1 to zero.

(In all cases the outMixer inputs could be set to 0.5.)

Ok, but this is just a simple system. When more effect combinations are needed, things will get a little convoluted.

If AudioConnections could be created and deleted run-time, that would be ideal, but maybe a little hard to implement. Maybe I'll try to implement some kind of multiplex object...
 
I tested this method and it works as expected. However, I found out that AudioEffectDelay was a poor choice for this exercise, because it makes AudioMemoryUsage running wild. So I can't see how much memory the system actually takes. The problem explained here: https://forum.pjrc.com/threads/4260...fectDelay-quot?p=141487&viewfull=1#post141487

I also implemented simple mux and demux objects, they make the task a little simpler and maybe a little more efficient too.
 
Is sine.fm object also terminated by this method (muting input signal)? I have 35 voice polyphony synth based on sine_fm and I want to terminate it ( to start another type of synthesis - also 35voice polyphonic). I tried to mute fm modulation signal input, also all sine_fm amplitudes, all mixers, even I set all sine_fm frequencies to 0 and still it is consuming around 77-80% of CPU.
Is there any method how to disable sine_fm oscillator? Thank you very much!!!
 
Is sine.fm object also terminated by this method (muting input signal)?

Seems it isn't. My guess was setting amplitude(0.0), but you already tried that.

Seems that someone should modify the AudioSynthWaveformSineModulated::update method, to test if magnitude is zero. There is that kind of test in the AudioSynthWaveformSineHires::update()
 
I've added this to my low priority bug list. Eventually (perhaps many months) I'll update sinefm to skip computations when the amplitude is zero.
 
Status
Not open for further replies.
Back
Top