Synchronizing Effects

Status
Not open for further replies.

gfvalvo

Well-known member
Hi All.

I hope using the picture below will help me ask my question in a coherent manner. Suppose in this system that Waveform1 and Waveform2 are arbitrary waveform objects with identical frequency and phase. Thus, I assume they're essentially synchronized. Also assume that Effect1 and Effect2 each receive and transmit 'AUDIO_BLOCK_SAMPLES' (i.e. 128) samples every time their update() method runs.

Without Delay.jpg

Now, I want the actions of Effect1 and Effect2 (as controlled by Waveform1 and Waveform2) to be synchronized with respect to each audio packet passing through them.

But, I'm thinking that Effect1 introduces 1 Audio Block delay so it's not working like I want. Is that thinking correct? If so, can I add a 1 Audio Block (exactly) delay to the output of Waveform2 like this:

With Delay.jpg

So, if I'm on the right track so far, does such a delay object already exist? If not, seems easy enough to create one.

If all this thinking is wrong, I'd appreciate being straightened out.

Thanks.
 
I did not try it, did not look at the code in the lib, and it's a blind guess :D: Have you tried to insert a mixer (between wafeform2 and effect2 ?
 
Thanks for the reply. I haven't tried anything yet, still in the "thinking about the problem" phase. I may just create a 3-input Audio class that combines the two effects in one.
 
The order of the object instances in your Arduino code matters. The design tool will generally put them in order from left to right, but the important point is the audio library actually executes their update() functions in the order they are listed in the actual exported Arduino code.

Connections that go from the output of an object to the input of any others *later* in the list effectively have zero delay. In your first example, the 3 sources generate blocks. Then Effect1 operates on the outputs of Waveform1 and adc1. Then within that same update, Effect2 operates on the output of Effect1 and Waveform2. At the end of the update, the result will be a 128 sample block depending only on the data during that 1 update.

However, if you were to physically move those blocks around on the canvas, which causes the design tool to generate the list in a different order, then you could get 128 sample delays. The design tool doesn't do any sort of sophisticated graph or flow analysis. It just exports the list in roughly left to right order (with a very slight top to bottom effect when objects are very close to the same horizontal position).

If you were to put Effect2 before Effect1 in the exported code (or just edit the code to move the lines around), then the output of Effect1 would see a 128 sample delay. When the connections go from any object to the input of that same object or any earlier object, the 128 samples are held in memory and used during the next update. This is a consequence of the audio library executing all the objects in the order they are created in the Arduino code. If Effect2 runs first and receives the output from Effect1, it will process the output Effect1 send during the previous update.

Normally people draw their designs to flow from left to right, so the simple left to right export order tends to generate systems without delays between the objects. But if delays matter, pay close attention to the actual order of exported code.

Also remember to use AudioNoInterrupts() if you make multiple changes from your Arduino code and you need them to all apply at the same moment. If you don't do this, the audio update could run during that brief moment when you change multiple settings, causing some to take effect 2.9 ms before the rest.
 
Status
Not open for further replies.
Back
Top