Reputation: 469
I'm using the JAVA sound API and I'm trying to get some controls (at least the volume) on the mixers and lines but, it seems there are no control. Here is a part of the code I'm using :
for (Mixer.Info mixerInfo : AudioSystem.getMixerInfo()) {
//System.out.println("MixerInfo : "+mixerInfo.getName());
if (mixerInfo.getName().compareTo("PulseAudio Mixer")==0) {
System.out.println("Java Sound Audio Engine : "+AudioSystem.getMixer(mixerInfo));
mixer=AudioSystem.getMixer(mixerInfo);
System.out.println("\t Controls supported by Mixer:");
for(Control c : mixer.getControls()) {
System.out.println("\t =>" + c);
}
System.out.println("\t TargetLine availabe for this mixer : ");
for (Line.Info i : mixer.getTargetLineInfo()) {
System.out.println("\t => "+i);
System.out.println("\t\t Controls supported by Target Line :");
try {
for (Control c : AudioSystem.getLine(i).getControls()) {
System.out.println("\t\t =>"+c);
}
} catch (LineUnavailableException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
System.out.println("--------------------------");
//break;
} else {
//System.out.println("Other Mixer : "+AudioSystem.getMixer(mixerInfo));
System.out.println("Other Sound Audio Engine : "+AudioSystem.getMixer(mixerInfo));
mixer2=AudioSystem.getMixer(mixerInfo);
System.out.println("\t Controls supported by Mixer:");
for(Control c : mixer2.getControls()) {
System.out.println("\t =>" + c);
}
System.out.println("\t TargetLine availabe for this mixer :");
for (Line.Info i : mixer2.getSourceLineInfo()) {
System.out.println("\t => "+i);
System.out.println("\t\t Controls supported by Target Line :");
try {
for (Control c : AudioSystem.getLine(i).getControls()) {
System.out.println("\t\t =>"+c);
}
} catch (LineUnavailableException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
System.out.println("--------------------------");
}
}
And here is the result produced in the console :
Java Sound Audio Engine : org.classpath.icedtea.pulseaudio.PulseAudioMixer@1404d1 Controls supported by Mixer:
TargetLine availabe for this mixer :
=> interface TargetDataLine supporting 42 audio formats, and buffers of 0 to 1000000 bytes
Controls supported by Target Line :
Other Sound Audio Engine : com.sun.media.sound.DirectAudioDevice@13b8dae
Controls supported by Mixer:
TargetLine availabe for this mixer :
=> interface SourceDataLine supporting 512 audio formats, and buffers of at least 32 bytes
Controls supported by Target Line :
=> interface Clip supporting 512 audio formats, and buffers of at least 32 bytes
Controls supported by Target Line :
Other Sound Audio Engine : com.sun.media.sound.DirectAudioDevice@1cad7c3 Controls supported by Mixer:
TargetLine availabe for this mixer :
=> interface SourceDataLine supporting 24 audio formats, and buffers of at least 32 bytes
Controls supported by Target Line :
=> interface Clip supporting 24 audio formats, and buffers of at least 32 bytes
Controls supported by Target Line :
Other Sound Audio Engine : com.sun.media.sound.DirectAudioDevice@1a9cf86
Controls supported by Mixer:
TargetLine availabe for this mixer :
=> interface SourceDataLine supporting 24 audio formats, and buffers of at least 32 bytes
Controls supported by Target Line :
=> interface Clip supporting 24 audio formats, and buffers of at least 32 bytes
Controls supported by Target Line :
Other Sound Audio Engine : com.sun.media.sound.PortMixer@17fd320 Controls supported by Mixer:
TargetLine availabe for this mixer :
=> Mic Boost source port
Controls supported by Target Line :
=> Capture source port
Controls supported by Target Line :
=> Digital source port
What can be the problem ?
Note : I'm not on a Windows OS but on a Xubuntu (linux) OS. That's why I don't have a Java Sound Audio Engine but a PulseAudioMixer.
Upvotes: 0
Views: 934
Reputation: 1110
There truly are no controls in JavaSound on Linux, not even with the latest JDK, when using PulseAudio.
Upvotes: 0
Reputation: 7910
What Andrew said in the comment about the support for the various lines being spotty is something I've also found to be true. And in addition, the volume control, when present, is often less than ideal. It can only change the volume with each buffer load of audio data, so rapid changes tend to cause big level jumps between buffers which in turn causes clicks or a zippering effect.
I recommend writing your own controls. There is a good example you can use as a starting structure in the Java Tutorials, the section called Using Files and Format Convertors. There's a code example a short way down under the heading "Reading Sound Files." Notice the comment:
// Here, do something useful with the audio data that's
// now in the audioBytes array...
At that point, you would convert the bytes to PCM data, then multiply the values by a volume factor (usually a float ranging from 0 to 1), then convert back to bytes for playback. Writing your own, you can make the buffer smaller, or come up with other schemes to spread out a volume change so that it is not too abrupt. Also, a function can be made so that the change from 0 to 1 will more closely map perceived volume. For all these steps, you can consult previous posts on StackOverflow.
I just remembered the last part of the Java Tutorials section on Controls. There, they mention the option of writing your own. Unfortunately, they don't provide much in the way of examples at that point.
Upvotes: 1