/*
 * @(#)TestSoundSupport.java
 *
 * Summary: Tells you what formats javax.sound.sampled classes supports on this machine.
 *
 * Copyright: (c) 2009 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.6+
 *
 * Created with: IntelliJ IDEA IDE.
 *
 * 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.out;

/**
 * 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
    {
    // -------------------------- STATIC METHODS --------------------------

    /**
     * display formats supported
     *
     * @param li the line information.
     */
    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() );
                }
            }
        }

    // --------------------------- main() method ---------------------------

    /**
     * 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 progam 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().toString() );

            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() );
                }
            }
        }
    }