Adjust Mixers Volume (Master, Wave, Mixer, Microphone,)

I woul like to adjust mixers volume such Master Volume, Wave Volume, Mixer, Microphone. How can I do it in Java Sound API?Thanks.
[157 byte] By [wr34ta] at [2007-11-27 2:27:43]
# 1

The audio sytem provides special port mixers with port lines.

You have to open this lines, get the controls and adjust them.

Here is a small program which prints the current values of the controls.

It may help you to learn how to access the controls.

import javax.sound.sampled.AudioSystem;

import javax.sound.sampled.BooleanControl;

import javax.sound.sampled.CompoundControl;

import javax.sound.sampled.Control;

import javax.sound.sampled.EnumControl;

import javax.sound.sampled.FloatControl;

import javax.sound.sampled.Line;

import javax.sound.sampled.LineUnavailableException;

import javax.sound.sampled.Mixer;

import javax.sound.sampled.Port;

public class MixerTest {

public MixerTest() throws LineUnavailableException {

Mixer.Info[] mixerInfos = AudioSystem.getMixerInfo();

for (Mixer.Info mixerInfo:mixerInfos) {

Mixer m = AudioSystem.getMixer(mixerInfo);

Line.Info[] lineInfos = m.getSourceLineInfo();

for (Line.Info li:lineInfos) {

if (li instanceof Port.Info){

Port.Info pi=(Port.Info)li;

Line portLine=m.getLine(pi);

printPortControls(portLine);

}

}

lineInfos = m.getTargetLineInfo();

for (Line.Info li:lineInfos) {

if (li instanceof Port.Info){

if (li instanceof Port.Info){

Port.Info pi=(Port.Info)li;

Line portLine=m.getLine(pi);

printPortControls(portLine);

}

}

}

}

}

private void printPortControls(Line portLine) throws LineUnavailableException{

portLine.open();

Control[] pCtrls=portLine.getControls();

for(Control memberControl:pCtrls){

printControl(memberControl);

}

portLine.close();

}

public void printControl(Control memberControl) {

if (memberControl instanceof BooleanControl) {

BooleanControl bc = (BooleanControl) memberControl;

System.out.println(bc + ": " + bc.getValue());

} else if (memberControl instanceof FloatControl) {

FloatControl fc = (FloatControl) memberControl;

System.out.println(fc + ": " + fc.getValue());

} else if (memberControl instanceof EnumControl) {

EnumControl ec = (EnumControl) memberControl;

System.out.println(ec + ": " + ec.getValue());

} else if (memberControl instanceof CompoundControl) {

CompoundControl cc = (CompoundControl) memberControl;

System.out.println(cc);

for (Control compControl:cc.getMemberControls()) {

printControl(compControl);

}

}

}

/**

* @param args

*/

public static void main(String[] args) {

try {

new MixerTest();

} catch (LineUnavailableException e) {

e.printStackTrace();

}

}

}

KlausJJa at 2007-7-12 2:38:47 > top of Java-index,Security,Cryptography...
# 2
How can I change volume for RECORDING mixer? Thanks in advance,Pas.
dkmorba at 2007-7-12 2:38:48 > top of Java-index,Security,Cryptography...
# 3
JavaSound uses the terms SourceLine for playback lines and TargetLine for recording lines. Controls of target lines are responsible for recording.The structure of Port lines and controls is similar to the structure of the OS audio mixer, because it depends on the audio hardware.
KlausJJa at 2007-7-12 2:38:48 > top of Java-index,Security,Cryptography...
# 4
Hey, thank you, KlausJJ... I don't now TargetLine defines recording lines.Bye,dkmorb.
dkmorba at 2007-7-12 2:38:48 > top of Java-index,Security,Cryptography...