We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi!
I'm using a gain object in my sketch and I want to get his current dB value. I'm trying with
myGain.gain.getLastValue()
but it doesn't work. Any idea?
Thanks!
What do you mean by "it doesn't work".
float[] values = myGain.getLastValues(); println(values); float firstValue = values[0]; float lastValue = values[values.length-1];
I change the gain with the mouse. It works. But, if I want to print the gain dB value, it always prints 0.0 dB
import ddf.minim.*; import ddf.minim.ugens.*; Minim minim; Oscil myWave; Gain myGain; AudioOutput out; void setup() { size(512, 200); minim = new Minim(this); myWave = new Oscil( 440, 0.5f, Waves.SINE ); myGain = new Gain(); out = minim.getLineOut(); myWave.patch(myGain); myGain.patch(out); } void draw() { println(myGain.gain.getLastValue()); } void mouseMoved() { float dB = map(mouseY, 0, height, 0, -30); myGain.setValue(dB); }
See the source code: https://github.com/ddf/Minim/blob/master/src/ddf/minim/ugens/Gain.java
The original dBvalue is not saved, so if you want to keep that, you should save it yourself in another variable.
yes, I see
Thanks ammon!
Or you could put this customized class in your sketch...
import ddf.minim.*; import ddf.minim.ugens.*; Minim minim; Oscil myWave; Gain myGain; AudioOutput out; void setup() { size(512, 200); minim = new Minim(this); myWave = new Oscil( 440, 0.5f, Waves.SINE ); myGain = new Gain(); out = minim.getLineOut(); myWave.patch(myGain); myGain.patch(out); } void draw() { println(myGain.getLastdBValue()); } void mouseMoved() { float dB = map(mouseY, 0, height, 0, -30); myGain.setValue(dB); } class Gain extends UGen { UGenInput audio; UGenInput gain; float mValue; float dBvalue; public Gain() { this(0); } Gain(float dBvalue) { this.dBvalue = dBvalue; mValue = (float)Math.pow(10.0, (0.05 * dBvalue)); audio = new UGenInput(InputType.AUDIO); gain = new UGenInput(InputType.CONTROL); } void setValue( float dBvalue ) { this.dBvalue = dBvalue; mValue = (float)Math.pow(10.0, (0.05 * dBvalue)); } float getLastdBValue() { return dBvalue; } protected void uGenerate(float[] channels) { if ( gain.isPatched() ) { mValue = (float)Math.pow(10.0, (0.05 * gain.getLastValue())); } for (int i = 0; i < channels.length; ++i) { channels[i] = mValue * audio.getLastValues()[i]; } } }
yes, but I'm working on a tutorial for beginners. I think it would be clearer for them to save the gain value in a variable.
Thank you!
Answers
What do you mean by "it doesn't work".
I change the gain with the mouse. It works. But, if I want to print the gain dB value, it always prints 0.0 dB
See the source code: https://github.com/ddf/Minim/blob/master/src/ddf/minim/ugens/Gain.java
The original dBvalue is not saved, so if you want to keep that, you should save it yourself in another variable.
yes, I see
Thanks ammon!
Or you could put this customized class in your sketch...
yes, but I'm working on a tutorial for beginners. I think it would be clearer for them to save the gain value in a variable.
Thank you!