Apply gain change to buffer IF signal level is over a certain amount

m0dit's icon

Hi all,

I know i can change the gain inside a [buffer~] but
Is it possible to check the samples highest point (inside the buffer) and if it is over 0.80 then apply a gain change?
[info~] seems to only report MIDI velocity. I have a feeling [if/then/else] would do this, but not really sure on how to gather the info from [buffer~]

Thanks!

pdelges's icon

See mxj buf.op.

With max you'll get the maximum sample, there are also methods to change the gain.

p

m0dit's icon

I tried with (~) and without but i get an error:
java.lang.NoClassDefFoundError: buf/op (wrong name: buf/Op)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
    at com.cycling74.max.MXJClassLoaderImpl.doLoadClass(MXJClassLoaderImpl.java:119)
    at com.cycling74.max.MXJClassLoader.loadClazz(MXJClassLoader.java:88)
Could not load class 'buf.op'

When you say " you'll get the maximum sample" you mean the sample loaded gets Normalised to the maximum?

KrisW's icon

ive tried to load buf.op in 6.1 some time ago ,and i could not do it for some reason . it was strange becasue absence of support for mxj wasnt listed inside release notes . just the ~mxj .

pdelges's icon

Ooopps, I meant mxj buf.Op!

m0dit's icon

Thanks Patrick, i found the helpfile but honestly its quite hard for me to understand. The gain portion i get but not the "max $1" message. How would i go about using that|? Would i have to take n2 output (393 0.XXXXX) then split it and use the second number and write an [if/then] function of some sort?
Could someone help me out a bit here? :/

mattyo's icon

In the "max $1" message, the $1 is a placeholder for a variable. The message "max 1" will give you the maximum amplitude for channel 1 of the bufffer in question. You then query the buf.Op, and use the result to set your volume reduction. See attached....

Max Patch
Copy patch and select New From Clipboard in Max.

M

m0dit's icon
Max Patch
Copy patch and select New From Clipboard in Max.

Thanks mattyo, I managed to come up with my own

mattyo's icon
Max Patch
Copy patch and select New From Clipboard in Max.

cool. A couple of notes for you:

m0dit's icon

Nice one, thank you! All noted. Previously i thought of combining the normalize and gain, but never put it together.....Not sure why...
Thanks again!