import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.DataLine;
import javax.sound.sampled.Line;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.SourceDataLine;

public class Main {

	public static void main(String[] args) 
	{
		// see what mixers are available
    	javax.sound.sampled.Mixer.Info [] mixerInfos = AudioSystem.getMixerInfo();

    	// the typical professional audio 24-bit, 48 kHz audio format
        AudioFormat format = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, 48000, 24, 2, 24 * 2 / 8, 48000, false);

        // hard code some mixer
        int mixerIndex = 3;

        // check which one it is
        System.out.println("Mixer name: " + mixerInfos[mixerIndex].getName());
        
        // get the mixer
        javax.sound.sampled.Mixer mixer = AudioSystem.getMixer(mixerInfos[mixerIndex]);

        // just check if this mixer is a playback mixer and not just a capture mixer
    	boolean done = false;
		Line.Info [] lineInfos = AudioSystem.getMixer(mixerInfos[mixerIndex]).getSourceLineInfo();
        for(int i = 0; i < lineInfos.length; i++)
        {
            if(lineInfos[i].getLineClass() == SourceDataLine.class)
            {
            	done = true;
            	break;
            }
        }
        
        if (! done)
        {
        	System.out.println("Not a playback mixer.  Choose a different mixer index");
        	return;
        }

    	if (mixer == null)
    	{
    		System.out.println("Error getting mixer");
    		return;
    	}

    	// TEST 1: This should return true on my system, where the soundcard has been tested to
    	//   properly handle 24-bit, 48 kHz audio
        DataLine.Info sourceInfo = new DataLine.Info(SourceDataLine.class, format);
        if (mixer.isLineSupported(sourceInfo))
        	System.out.println("TEST 1 succeeded");
        else
        {
        	System.out.println("TEST 1 failed");
        }
        
        // TEST 2: 
        try
        {
        	SourceDataLine sourceLine = (SourceDataLine) mixer.getLine(sourceInfo);
        	if (sourceLine != null)
        		System.out.println("TEST 2 succeeded");
        	else
        		System.out.println("TEST 2 failed");
        }
        catch (IllegalArgumentException | LineUnavailableException e)
        {
        	System.out.println("Cannot get the source data line from the mixer");
        	System.out.println("TEST 2 failed");
        }
	}
}
