View Full Version : Audio Object intercommunications

03-17-2016, 03:33 PM
I have an Audio project using the mixer object and an Analyze object (that I created myself). I declared these object in my Sketch and the Sketch is the mediator between objects as in the examples. The Analyze object obtains information from the audio stream that I then use to set the gain of the mixer in realtime. So, the sketch reads data from the Anaalyze object then uses that to compute the mixer gain and sends that to the mixer with mixer1.gain(0,value). This works except that the process takes longer than I need.

So, what I'd like to do is have the Analyze object make the calculation of gain (value) and send it directly to mixer1 using mixer1.gain(0,value). Since the Mixer object is positioned well after the Analyze object in the connection path, I reason that the changes in gain determined by the Analyze object will have immediate effect on the mixer gain. I tried this and the compiler complains that ""mixer1" was not declared in this scope. BTW I also, need the Sketch to communicate with the same mixer and analyze object for other purposes. This is likely a basic C++ lack of understanding on my part. I have tried reading on approaches to making the Analyze object aware of the mixer object with no success and could use some advise. Thanks, Brillo

Later .... Appears I have found the solution. added "extern AudioMixer4 mixer1; " to my Analyze object file and no compiler complaints.

03-18-2016, 09:27 PM
The extern allows your object to know about the mixer, but it only works when there's a mixer with that name, and the same input is connected to the same channel.

There are a couple of more flexible variations you might consider.

The first would be to add a method to your analyze object that you use to inform it of where it's mixer is. Something like Analyze.connectMixer(&mixer, channelNum). The object would store a pointer to the mixer, and channel number, to use when it needs to set the gain. This effectively means that you'd need to update the mixer gain once per update() call, and sudden changes might result in pops or clicks. It also involves a potentially tricky piece of initialization.
A second option fits a little better into the way the audio library works: you could add an audio stream output to your Analyze object, and write the gain adjustment to the output buffer on a sample-by-sample basis. You'd then follow that with a multiply object to apply the gain changes to the audio data. Then you can use the patching GUI, and it doesn't require any pointer wrangling in setup().

03-20-2016, 06:58 AM
Thanks B. !!
The extern worked perfectly for my case.