How to compare 2 audio signals?

Chauso Bonaparte's icon

Hi, i want to compare two different stereo audio signals' peak to see which is louder (on a per sample basis?)

I want to compare them using an if statement but it won't take such inputs as ones coming from plugin~ for example.

👽!t W∆s ∆lienz!👽's icon

the 'if/then' object in max doesn't take signals so if you want a proper if/then statement to use with signals, best recommendation is to use gen~...

you could do the same using visual objects in MSP, here i've shown you both in case it helps thinking of simpler ways in the future, but understandable if you really need an 'if/then' to break out the branches with more specifics than just comparison(my if/then here doesn't feel concise at all, haha):

Chauso Bonaparte's icon

Can you use codebox with audio signal? How does that work if i also want to output audio?

👽!t W∆s ∆lienz!👽's icon

ya, this is in the 'gen~' part of Max, you can read documentation here:

also the reference can be read within Max, so the links will link directly to patches they talk about, from the 'Help' menu like so:


in short, when you also want to output audio, you just assign it to the appropriate 'out#' variable(in my codebox from my first post, the pic shows the 'out1' and 'out2' variables(they turn blue within codebox to signify they are 'reserved keywords'), and this is where i write the output to.. in that case, it was the contents of the other variables called 'out1val' and 'out2val' which were always initialized to 0 before doing any comparison each new sample).

this'll get explained in the docs better than i can explain(especially all the 'reserved keywords' and the specific syntax for different conditionals, etc.)... but in short, you can work discretely over audio samples with if/then statements, best/easiest by doing it in the gen~ environment.