tags:

views:

613

answers:

3

Hello

I'm using the javax.sound.sampled package in a radio data mode decoding program. To use the program the user feeds audio from their radio receiver into their PC's line input. The user is also required to use their mixer program to select the line in as the recording input. The trouble is some users don't know how to do this and also sometimes other programs alter the recording input setting. So my question is how can my program detect if the line in is set as the recording input ? Also is it possible for my program to change the recording input setting if it detects it is incorrect ?

Thanks for your time.

Ian

+2  A: 

To answer your first question, you can check if the Line.Info object for your recording input matches Port.Info.LINE_IN like this:

public static boolean isLineIn(Line.Info lineInfo) {
    Line.Info[] detected = AudioSystem.getSourceLineInfo(Port.Info.LINE_IN);
    for (Line.Info lineIn : detected) {
        if (lineIn.matches(lineInfo)) {
            return true;
        }
    }
    return false;
}

However, this doesn't work with operating systems or soundcard driver APIs that don't provide the type of each available mixer channel. So when I test it on Windows it works, but not on Linux or Mac. For more information and recommendations, see this FAQ.

Regarding your second question, you can try changing the recording input settings through a Control class. In particular, see FloatControl.Type for some common settings. Keep in mind that the availability of these controls depends on the operating system and soundcard drivers, just like line-in detection.

David Crow
A: 

Thanks for the answer David. I know I have a few users who run Linux so it looks like the solution will be to write some code that detects if the app is running under Windows and if it does then runs the code you suggest.

IanW
A: 

Hello

Can anyone tell me how I generate the Line.Info object for my recording input ?

Currently my code looks like this ..

TargetDataLine Line;
AudioFormat format;
format=new AudioFormat(10800,8,1,true,true);    
DataLine.Info info=new DataLine.Info(TargetDataLine.class, format);
Line=(TargetDataLine) AudioSystem.getLine(info);
Line.open(format);

isLineIn(Line.getLineInfo());

Line.start();

But the Line.Info object being created by getLineInfo seems to contain meaningless values. Can anyone tell me how to create a valid Line.Info ?

Thanks for your time

Ian

IanW