/*
 * [TestSoundSupport.java]
 *
 * Summary: Tells you what formats javax.sound.sampled classes supports on this machine.
 *
 * Copyright: (c) 2009-2017 Roedy Green, Canadian Mind Products, http://mindprod.com
 *
 * Licence: This software may be copied and used freely for any purpose but military.
 *          http://mindprod.com/contact/nonmil.html
 *
 * Requires: JDK 1.8+
 *
 * Created with: JetBrains IntelliJ IDEA IDE http://www.jetbrains.com/idea/
 *
 * Version History:
 *  1.0 2009-03-06 initial version
 */
package com.mindprod.example;

import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Control;
import javax.sound.sampled.DataLine;
import javax.sound.sampled.Line;
import javax.sound.sampled.Mixer;

import static java.lang.System.*;

/**
 * Tells you what formats javax.sound.sampled classes supports on this machine.
 *
 * @author Roedy Green, Canadian Mind Products
 * @version 1.0 2009-03-06 initial version
 * @since 2009-03-06
 */
public class TestSoundSupport
    {
    /**
     * display formats supported
     *
     * @param li the line information.
     */
    private static void showFormats( Line.Info li )
        {
        if ( li instanceof DataLine.Info )
            {
            AudioFormat[] afs = ( ( DataLine.Info ) li ).getFormats();
            for ( AudioFormat af : afs )
                {
                out.println( "        " + af.toString() );
                }
            }
        }

    /**
     * Tells you what formats javax.sound.sampled classes supports on this machine.
     * Unfortunately, this is not as detailed as you need.
     * You get get a much more detailed program from http://amug.org/~glguerin/other/AboutSound.zip
     *
     * @param args not used
     */
    public static void main( String[] args )
        {
        // loop through all mixers, and all source and target lines within each mixer.
        Mixer.Info[] mis = AudioSystem.getMixerInfo();
        for ( Mixer.Info mi : mis )
            {
            Mixer mixer = AudioSystem.getMixer( mi );
            // e.g. com.sun.media.sound.DirectAudioDevice
            out.println( "mixer: " + mixer.getClass().getName() );
            Line.Info[] lis = mixer.getSourceLineInfo();
            for ( Line.Info li : lis )
                {
                out.println( "    source line: " + li.toString() );
                showFormats( li );
                }
            lis = mixer.getTargetLineInfo();
            for ( Line.Info li : lis )
                {
                out.println( "    target line: " + li.toString() );
                showFormats( li );
                }
            Control[] cs = mixer.getControls();
            for ( Control c : cs )
                {
                out.println( "    control: " + c.toString() );
                }
            }
        }
    }