java类javax.sound.sampled.SourceDataLine的实例源码

JDK13Services.java 文件源码 项目:jdk8u_jdk 阅读 22 收藏 0 点赞 0 评论 0
/** Obtain the value of a default provider property.
    @param typeClass The type of the default provider property. This
    should be one of Receiver.class, Transmitter.class, Sequencer.class,
    Synthesizer.class, SourceDataLine.class, TargetDataLine.class,
    Clip.class or Port.class.
    @return The complete value of the property, if available.
    If the property is not set, null is returned.
 */
private static synchronized String getDefaultProvider(Class typeClass) {
    if (!SourceDataLine.class.equals(typeClass)
            && !TargetDataLine.class.equals(typeClass)
            && !Clip.class.equals(typeClass)
            && !Port.class.equals(typeClass)
            && !Receiver.class.equals(typeClass)
            && !Transmitter.class.equals(typeClass)
            && !Synthesizer.class.equals(typeClass)
            && !Sequencer.class.equals(typeClass)) {
        return null;
    }
    String name = typeClass.getName();
    String value = AccessController.doPrivileged(
            (PrivilegedAction<String>) () -> System.getProperty(name));
    if (value == null) {
        value = getProperties().getProperty(name);
    }
    if ("".equals(value)) {
        value = null;
    }
    return value;
}
JavaSoundAudioClip.java 文件源码 项目:lookaside_java-1.8.0-openjdk 阅读 19 收藏 0 点赞 0 评论 0
private boolean createSourceDataLine() {
    if (DEBUG || Printer.debug)Printer.debug("JavaSoundAudioClip.createSourceDataLine()");
    try {
        DataLine.Info info = new DataLine.Info(SourceDataLine.class, loadedAudioFormat);
        if (!(AudioSystem.isLineSupported(info)) ) {
            if (DEBUG || Printer.err)Printer.err("Line not supported: "+loadedAudioFormat);
            // fail silently
            return false;
        }
        SourceDataLine source = (SourceDataLine) AudioSystem.getLine(info);
        datapusher = new DataPusher(source, loadedAudioFormat, loadedAudio, loadedAudioByteLength);
    } catch (Exception e) {
        if (DEBUG || Printer.err)e.printStackTrace();
        // fail silently
        return false;
    }

    if (datapusher==null) {
        // fail silently
        return false;
    }

    if (DEBUG || Printer.debug)Printer.debug("Created SourceDataLine.");
    return true;
}
SoftAudioPusher.java 文件源码 项目:lookaside_java-1.8.0-openjdk 阅读 22 收藏 0 点赞 0 评论 0
public void run() {
    byte[] buffer = SoftAudioPusher.this.buffer;
    AudioInputStream ais = SoftAudioPusher.this.ais;
    SourceDataLine sourceDataLine = SoftAudioPusher.this.sourceDataLine;

    try {
        while (active) {
            // Read from audio source
            int count = ais.read(buffer);
            if(count < 0) break;
            // Write byte buffer to source output
            sourceDataLine.write(buffer, 0, count);
        }
    } catch (IOException e) {
        active = false;
        //e.printStackTrace();
    }

}
JDK13Services.java 文件源码 项目:lookaside_java-1.8.0-openjdk 阅读 21 收藏 0 点赞 0 评论 0
/** Obtain the value of a default provider property.
    @param typeClass The type of the default provider property. This
    should be one of Receiver.class, Transmitter.class, Sequencer.class,
    Synthesizer.class, SourceDataLine.class, TargetDataLine.class,
    Clip.class or Port.class.
    @return The complete value of the property, if available.
    If the property is not set, null is returned.
 */
private static synchronized String getDefaultProvider(Class typeClass) {
    if (!SourceDataLine.class.equals(typeClass)
            && !TargetDataLine.class.equals(typeClass)
            && !Clip.class.equals(typeClass)
            && !Port.class.equals(typeClass)
            && !Receiver.class.equals(typeClass)
            && !Transmitter.class.equals(typeClass)
            && !Synthesizer.class.equals(typeClass)
            && !Sequencer.class.equals(typeClass)) {
        return null;
    }
    String name = typeClass.getName();
    String value = AccessController.doPrivileged(
            (PrivilegedAction<String>) () -> System.getProperty(name));
    if (value == null) {
        value = getProperties().getProperty(name);
    }
    if ("".equals(value)) {
        value = null;
    }
    return value;
}
TGMixer.java 文件源码 项目:TuxGuitar-1.3.1-fork 阅读 18 收藏 0 点赞 0 评论 0
public TGMixer() {
    super(new Line.Info(Mixer.class));

    this.lines = new HashMap<Class<?>, Line>();
    this.sourceLineInfo = new ArrayList<DataLine.Info>();
    this.targetLineInfo = new ArrayList<DataLine.Info>();

    List<AudioFormat> formats = new ArrayList<AudioFormat>();
    for (int channels = 1; channels <= 2; channels++) {
        formats.add(new AudioFormat(Encoding.PCM_SIGNED, AudioSystem.NOT_SPECIFIED, 8, channels, channels, AudioSystem.NOT_SPECIFIED, false)); 
        formats.add(new AudioFormat(Encoding.PCM_UNSIGNED, AudioSystem.NOT_SPECIFIED, 8, channels, channels, AudioSystem.NOT_SPECIFIED, false));
            for (int bits = 16; bits < 32; bits += 8) {
                formats.add(new AudioFormat(Encoding.PCM_SIGNED, AudioSystem.NOT_SPECIFIED, bits, channels, channels * bits / 8, AudioSystem.NOT_SPECIFIED, false));
                formats.add(new AudioFormat(Encoding.PCM_UNSIGNED, AudioSystem.NOT_SPECIFIED, bits, channels, channels * bits / 8, AudioSystem.NOT_SPECIFIED, false));
                formats.add(new AudioFormat(Encoding.PCM_SIGNED, AudioSystem.NOT_SPECIFIED, bits, channels, channels * bits / 8, AudioSystem.NOT_SPECIFIED, true));
                formats.add(new AudioFormat(Encoding.PCM_UNSIGNED, AudioSystem.NOT_SPECIFIED, bits, channels, channels * bits / 8, AudioSystem.NOT_SPECIFIED, true));
            }
            formats.add(new AudioFormat(AudioFloatConverter.PCM_FLOAT, AudioSystem.NOT_SPECIFIED, 32, channels, channels * 4, AudioSystem.NOT_SPECIFIED, false));
            formats.add(new AudioFormat(AudioFloatConverter.PCM_FLOAT, AudioSystem.NOT_SPECIFIED, 32, channels, channels * 4, AudioSystem.NOT_SPECIFIED, true));
            formats.add(new AudioFormat(AudioFloatConverter.PCM_FLOAT, AudioSystem.NOT_SPECIFIED, 64, channels, channels * 8, AudioSystem.NOT_SPECIFIED, false));
            formats.add(new AudioFormat(AudioFloatConverter.PCM_FLOAT, AudioSystem.NOT_SPECIFIED, 64, channels, channels * 8, AudioSystem.NOT_SPECIFIED, true));
        }

        this.sourceLineInfo.add(new DataLine.Info(SourceDataLine.class, formats.toArray(new AudioFormat[formats.size()]), AudioSystem.NOT_SPECIFIED, AudioSystem.NOT_SPECIFIED));
}
SoftAudioPusher.java 文件源码 项目:TuxGuitar-1.3.1-fork 阅读 19 收藏 0 点赞 0 评论 0
public void run() {
    byte[] buffer = SoftAudioPusher.this.buffer;
    AudioInputStream ais = SoftAudioPusher.this.ais;
    SourceDataLine sourceDataLine = SoftAudioPusher.this.sourceDataLine;

    try {
        while (active) {
            // Read from audio source
            int count = ais.read(buffer);
            if(count < 0) break;
            // Write byte buffer to source output
            sourceDataLine.write(buffer, 0, count);
        }
    } catch (IOException e) {
        active = false;
        //e.printStackTrace();
    }

}
AudioSystem.java 文件源码 项目:TuxGuitar-1.3.1-fork 阅读 27 收藏 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;
}
AudioPlayer.java 文件源码 项目:Tuntuni 阅读 23 收藏 0 点赞 0 评论 0
/**
 * Starts the player
 */
public void start() {
    try {
        // start source line
        DataLine.Info info = new DataLine.Info(
                SourceDataLine.class, VideoFormat.getAudioFormat());
        mSourceLine = (SourceDataLine) AudioSystem.getLine(info);
        mSourceLine.open(VideoFormat.getAudioFormat());

        mPlayerThread = new Thread(this);
        mPlayerThread.setDaemon(true);
        mPlayerThread.start();
    } catch (LineUnavailableException ex) {
        Logs.error(getClass(), "Failed to start the audio line. ERROR: {0}", ex);
    }
}
MP3Player.java 文件源码 项目:JavaVAD 阅读 26 收藏 0 点赞 0 评论 0
private void rawplay(AudioFormat targetFormat, AudioInputStream din) throws IOException,                                                                                                LineUnavailableException
{
  byte[] data = new byte[4096];
  SourceDataLine line = getLine(targetFormat); 
  if (line != null)
  {
    // Start
    line.start();
    int nBytesRead = 0, nBytesWritten = 0;
    while (nBytesRead != -1)
    {
        nBytesRead = din.read(data, 0, data.length);
        if (nBytesRead != -1) nBytesWritten = line.write(data, 0, nBytesRead);
    }
    // Stop
    line.drain();
    line.stop();
    line.close();
    din.close();
  } 
}
AudioReceiver.java 文件源码 项目:javacuriosities 阅读 24 收藏 0 点赞 0 评论 0
private static void reproduce( byte soundbytes[]) {
    try {
        DataLine.Info dataLineInfo = new DataLine.Info(SourceDataLine.class, AudioFormatHelper.getAudioFormat());

        // El source data line se usa para escribir datos en el
        SourceDataLine sourceDataLine = (SourceDataLine) AudioSystem.getLine(dataLineInfo);
        sourceDataLine.open(AudioFormatHelper.getAudioFormat());
        sourceDataLine.start();

        sourceDataLine.write(soundbytes, 0, soundbytes.length);
        sourceDataLine.drain();
        sourceDataLine.close();
    } catch (Exception e) {
        // Log and Handle exception
        e.printStackTrace();
    }
}


问题


面经


文章

微信
公众号

扫码关注公众号