| 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 */  | 
 | 
 | 
 | 
package com.sun.media.sound;  | 
 | 
 | 
 | 
import javax.sound.sampled.Mixer;  | 
 | 
import javax.sound.sampled.spi.MixerProvider;  | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 */  | 
 | 
public final class DirectAudioDeviceProvider extends MixerProvider { | 
 | 
 | 
 | 
    // STATIC VARIABLES  | 
 | 
 | 
 | 
      | 
 | 
 | 
 | 
     */  | 
 | 
    private static DirectAudioDeviceInfo[] infos;  | 
 | 
 | 
 | 
      | 
 | 
 | 
 | 
     */  | 
 | 
    private static DirectAudioDevice[] devices;  | 
 | 
 | 
 | 
 | 
 | 
    // STATIC  | 
 | 
 | 
 | 
    static { | 
 | 
          | 
 | 
        Platform.initialize();  | 
 | 
    }  | 
 | 
 | 
 | 
 | 
 | 
    // CONSTRUCTOR  | 
 | 
 | 
 | 
 | 
 | 
      | 
 | 
 | 
 | 
     */  | 
 | 
    public DirectAudioDeviceProvider() { | 
 | 
        synchronized (DirectAudioDeviceProvider.class) { | 
 | 
            if (Platform.isDirectAudioEnabled()) { | 
 | 
                init();  | 
 | 
            } else { | 
 | 
                infos = new DirectAudioDeviceInfo[0];  | 
 | 
                devices = new DirectAudioDevice[0];  | 
 | 
            }  | 
 | 
        }  | 
 | 
    }  | 
 | 
 | 
 | 
    private static void init() { | 
 | 
          | 
 | 
        int numDevices = nGetNumDevices();  | 
 | 
 | 
 | 
        if (infos == null || infos.length != numDevices) { | 
 | 
            if (Printer.trace) Printer.trace("DirectAudioDeviceProvider: init()"); | 
 | 
              | 
 | 
            infos = new DirectAudioDeviceInfo[numDevices];  | 
 | 
            devices = new DirectAudioDevice[numDevices];  | 
 | 
 | 
 | 
              | 
 | 
            for (int i = 0; i < infos.length; i++) { | 
 | 
                infos[i] = nNewDirectAudioDeviceInfo(i);  | 
 | 
            }  | 
 | 
            if (Printer.trace) Printer.trace("DirectAudioDeviceProvider: init(): found numDevices: " + numDevices); | 
 | 
        }  | 
 | 
    }  | 
 | 
 | 
 | 
    public Mixer.Info[] getMixerInfo() { | 
 | 
        synchronized (DirectAudioDeviceProvider.class) { | 
 | 
            Mixer.Info[] localArray = new Mixer.Info[infos.length];  | 
 | 
            System.arraycopy(infos, 0, localArray, 0, infos.length);  | 
 | 
            return localArray;  | 
 | 
        }  | 
 | 
    }  | 
 | 
 | 
 | 
 | 
 | 
    public Mixer getMixer(Mixer.Info info) { | 
 | 
        synchronized (DirectAudioDeviceProvider.class) { | 
 | 
            // if the default device is asked, we provide the mixer  | 
 | 
              | 
 | 
            if (info == null) { | 
 | 
                for (int i = 0; i < infos.length; i++) { | 
 | 
                    Mixer mixer = getDevice(infos[i]);  | 
 | 
                    if (mixer.getSourceLineInfo().length > 0) { | 
 | 
                        return mixer;  | 
 | 
                    }  | 
 | 
                }  | 
 | 
            }  | 
 | 
            // otherwise get the first mixer that matches  | 
 | 
              | 
 | 
            for (int i = 0; i < infos.length; i++) { | 
 | 
                if (infos[i].equals(info)) { | 
 | 
                    return getDevice(infos[i]);  | 
 | 
                }  | 
 | 
            }  | 
 | 
        }  | 
 | 
        throw new IllegalArgumentException("Mixer " + info.toString() + " not supported by this provider."); | 
 | 
    }  | 
 | 
 | 
 | 
 | 
 | 
    private static Mixer getDevice(DirectAudioDeviceInfo info) { | 
 | 
        int index = info.getIndex();  | 
 | 
        if (devices[index] == null) { | 
 | 
            devices[index] = new DirectAudioDevice(info);  | 
 | 
        }  | 
 | 
        return devices[index];  | 
 | 
    }  | 
 | 
 | 
 | 
    // INNER CLASSES  | 
 | 
 | 
 | 
 | 
 | 
      | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
     */  | 
 | 
    static final class DirectAudioDeviceInfo extends Mixer.Info { | 
 | 
        private final int index;  | 
 | 
        private final int maxSimulLines;  | 
 | 
 | 
 | 
          | 
 | 
        private final int deviceID;  | 
 | 
 | 
 | 
        private DirectAudioDeviceInfo(int index, int deviceID, int maxSimulLines,  | 
 | 
                                      String name, String vendor,  | 
 | 
                                      String description, String version) { | 
 | 
            super(name, vendor, "Direct Audio Device: "+description, version);  | 
 | 
            this.index = index;  | 
 | 
            this.maxSimulLines = maxSimulLines;  | 
 | 
            this.deviceID = deviceID;  | 
 | 
        }  | 
 | 
 | 
 | 
        int getIndex() { | 
 | 
            return index;  | 
 | 
        }  | 
 | 
 | 
 | 
        int getMaxSimulLines() { | 
 | 
            return maxSimulLines;  | 
 | 
        }  | 
 | 
 | 
 | 
        int getDeviceID() { | 
 | 
            return deviceID;  | 
 | 
        }  | 
 | 
    } // class DirectAudioDeviceInfo  | 
 | 
 | 
 | 
      | 
 | 
    private static native int nGetNumDevices();  | 
 | 
      | 
 | 
    private static native DirectAudioDeviceInfo nNewDirectAudioDeviceInfo(int deviceIndex);  | 
 | 
}  |