java类javax.sound.sampled.Line.Info的实例源码

AudioSystem.java 文件源码 项目:TuxGuitar-1.3.1-fork 阅读 25 收藏 0 点赞 0 评论 0
/** Checks if a Mixer is appropriate.
    A Mixer is considered appropriate if it support the given line type.
    If isMixingRequired is true and the line type is an output one
    (SourceDataLine, Clip), the mixer is appropriate if it supports
    at least 2 (concurrent) lines of the given type.

    @return true if the mixer is considered appropriate according to the
    rules given above, false otherwise.
 */
private static boolean isAppropriateMixer(Mixer mixer,
                                          Line.Info lineInfo,
                                          boolean isMixingRequired) {
    if (! mixer.isLineSupported(lineInfo)) {
        return false;
    }
    Class lineClass = lineInfo.getLineClass();
    if (isMixingRequired
        && (SourceDataLine.class.isAssignableFrom(lineClass) ||
            Clip.class.isAssignableFrom(lineClass))) {
        int maxLines = mixer.getMaxLines(lineInfo);
        return ((maxLines == NOT_SPECIFIED) || (maxLines > 1));
    }
    return true;
}
SinkAudio.java 文件源码 项目:FoxTelem 阅读 18 收藏 0 点赞 0 评论 0
/**
 * FIXME:
 * specify the buffer size in the open(AudioFormat,int) method. A delay of 10ms-100ms will be acceptable for realtime audio. Very low latencies like will 
 * not work on all computer systems, and 100ms or more will probably be annoying for your users. A good tradeoff is, e.g. 50ms. For your audio format, 
 * 8-bit, mono at 44100Hz, a good buffer size is 2200 bytes, which is almost 50ms
 */
void initializeOutput() {

    DataLine.Info dataLineInfo = new DataLine.Info(  SourceDataLine.class, audioFormat);
    //line = (TargetDataLine) AudioSystem.getLine(info);
    //Mixer m = AudioSystem.getMixer(null);
    try {
        //sourceDataLine = (SourceDataLine)m.getLine(dataLineInfo);
        sourceDataLine = (SourceDataLine)AudioSystem.getLine(dataLineInfo);
        sourceDataLine.open(audioFormat);
        sourceDataLine.start();
    } catch (LineUnavailableException e) {
        // TODO Auto-generated catch block
        e.printStackTrace(Log.getWriter());
    }

}
ListAudio.java 文件源码 项目:rcom 阅读 18 收藏 0 点赞 0 评论 0
public static void commandline(String[] subArgs) {
    final Mixer mixer = AudioSystem.getMixer(null);
    System.out.println("Listing audio channels...");
    for(Info info: mixer.getTargetLineInfo())
    {
        DataLine.Info di=(DataLine.Info) info;
        System.out.println("Line: "+di);
        for(AudioFormat f: di.getFormats())
        {
            System.out.println("Supported format: "+f);
        }
    }
    System.out.println("Listing audio channels DONE");
}
AudioSystem.java 文件源码 项目:TuxGuitar-1.3.1-fork 阅读 21 收藏 0 点赞 0 评论 0
/** Return a Mixer with a given name from a given MixerProvider.
  This method never requires the returned Mixer to do mixing.
  @param mixerName The name of the Mixer to be returned.
  @param provider The MixerProvider to check for Mixers.
  @param info The type of line the returned Mixer is required to
  support.

  @return A Mixer matching the requirements, or null if none is found.
 */
private static Mixer getNamedMixer(String mixerName,
                                   MixerProvider provider,
                                   Line.Info info) {
    Mixer.Info[] infos = provider.getMixerInfo();
    for (int i = 0; i < infos.length; i++) {
        if (infos[i].getName().equals(mixerName)) {
            Mixer mixer = provider.getMixer(infos[i]);
            if (isAppropriateMixer(mixer, info, false)) {
                return mixer;
            }
        }
    }
    return null;
}
SinkAudio.java 文件源码 项目:FoxTelem 阅读 17 收藏 0 点赞 0 评论 0
public void setDevice(int position) throws LineUnavailableException, IllegalArgumentException {
    if (position == 0 || position == -1) {
        initializeOutput();
    } else {
        Mixer appMixer = mixerList[position];

        Info sdlLineInfo = new DataLine.Info(SourceDataLine.class, audioFormat);

        sourceDataLine = (SourceDataLine) appMixer.getLine(sdlLineInfo);
        sourceDataLine.open(audioFormat);
        sourceDataLine.start();
    }


}
MixerUtil.java 文件源码 项目:crowdpp 阅读 16 收藏 0 点赞 0 评论 0
/**
 * Find a mixer that matches a given name.
 * 
 * @param mixerName as returned by a previous call of Mixer.Info.getName()
 * @param forRecording whether looking for a recording device (or playback otherwise). This 
 * information is needed because otherwise, mixer names are ambiguous. 
 * @return the matching Mixer.Info from AudioSystem.getMixerInfo() or null when there's no match
 * @throws Exception for multiple matches
 */
public static Mixer.Info getMixerInfoFromName(String mixerName, boolean forRecording) throws Exception{
    if (mixerName == null)
        return AudioSystem.getMixer(null).getMixerInfo();

    Mixer.Info [] availableMixers = AudioSystem.getMixerInfo();

    Mixer.Info info = null;

    for (Mixer.Info m : availableMixers){
        // don't consider playing mixers - otherwise, the mixer names are ambiguous
        if (!AudioSystem.getMixer(m).isLineSupported(
                forRecording ? 
                        new Info(TargetDataLine.class) :
                            new Info(SourceDataLine.class))){
            //System.out.println(mixerName + ": Not considering");

            continue;
        }
        if (m.getName().trim().equals(mixerName)){
            if (info != null){
                throw new Exception(String.format("multiple matches for \"%s\": \"%s\" and \"%s\"",
                        mixerName, info, m.getName()));
            }
            info = m;
        }
    }
    return info;
}
HelperSound.java 文件源码 项目:wichtel 阅读 61 收藏 0 点赞 0 评论 0
private static Clip getClip(final AudioInputStream ais) throws LineUnavailableException, IOException {
    if (log.isTraceEnabled()) log.trace(HelperLog.methodStart(ais));

    try {
        final Info info = new DataLine.Info(Clip.class, ais.getFormat());
        final Clip result = (Clip) AudioSystem.getLine(info);
        result.open(ais);

        if (log.isTraceEnabled()) log.trace(HelperLog.methodExit(result));
        return result;
    }
    finally {
        ais.close();
    }
}
SinkAudio.java 文件源码 项目:FoxTelem 阅读 19 收藏 0 点赞 0 评论 0
private static String getMixerIdString(Mixer appMixer) {
    Mixer.Info info = appMixer.getMixerInfo();
    return info.getName() + info.getDescription() + info.getVendor() + info.getVersion();
}
SourceSoundCardAudio.java 文件源码 项目:FoxTelem 阅读 18 收藏 0 点赞 0 评论 0
private static String getMixerIdString(Mixer appMixer) {
    Mixer.Info info = appMixer.getMixerInfo();
    return info.getName() + info.getDescription() + info.getVendor() + info.getVersion();
}
SourceSoundCardAudio.java 文件源码 项目:FoxTelem 阅读 19 收藏 0 点赞 0 评论 0
/**
 * Pass the combo box position and select this device
 * @param position
 * @throws LineUnavailableException
 * @throws IllegalArgumentException
 */
private void setDevice(int position) throws LineUnavailableException, IllegalArgumentException {
    //Mixer.Info[] mixers = AudioSystem.getMixerInfo();
    //AudioFormat audioFmt = getAudioFormat();

    Mixer appMixer = mixerList[position];

    Info sdlLineInfo = new DataLine.Info(TargetDataLine.class, makeAudioFormat(sampleRate));

    stop();

    targetDataLine = (TargetDataLine) appMixer.getLine(sdlLineInfo);

    init();

}
AudioSystem.java 文件源码 项目:TuxGuitar-1.3.1-fork 阅读 20 收藏 0 点赞 0 评论 0
/**
 * Obtains a source data line that can be used for playing back
 * audio data in the format specified by the
 * <code>AudioFormat</code> object. The returned line
 * will be provided by the default system mixer, or,
 * if not possible, by any other mixer installed in the
 * system that supports a matching
 * <code>SourceDataLine</code> object.
 *
 * <p>The returned line should be opened with the
 * <code>open(AudioFormat)</code> or
 * <code>open(AudioFormat, int)</code> method.
 *
 * <p>This is a high-level method that uses <code>getMixer</code>
 * and <code>getLine</code> internally.
 *
 * <p>The returned <code>SourceDataLine</code>'s default
 * audio format will be initialized with <code>format</code>.
 *
 * <p>If the system property
 * <code>javax.sound.sampled.SourceDataLine</code>
 * is defined or it is defined in the file &quot;sound.properties&quot;,
 * it is used to retrieve the default source data line.
 * For details, refer to the {@link AudioSystem class description}.
 *
 * @param format an <code>AudioFormat</code> object specifying
 *        the supported audio format of the returned line,
 *        or <code>null</code> for any audio format
 * @return the desired <code>SourceDataLine</code> object
 *
 * @throws LineUnavailableException if a matching source data line
 *         is not available due to resource restrictions
 * @throws SecurityException if a matching source data line
 *         is not available due to security restrictions
 * @throws IllegalArgumentException if the system does not
 *         support at least one source data line supporting the
 *         specified audio format through any installed mixer
 *
 * @see #getSourceDataLine(AudioFormat, Mixer.Info)
 * @since 1.5
 */
public static SourceDataLine getSourceDataLine(AudioFormat format)
        throws LineUnavailableException{
        DataLine.Info info = new DataLine.Info(SourceDataLine.class, format);
        return (SourceDataLine) AudioSystem.getLine(info);
    }


问题


面经


文章

微信
公众号

扫码关注公众号