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

StdAudio.java 文件源码 项目:MusicToGraph 阅读 38 收藏 0 点赞 0 评论 0
private static void init() {
    try {
        // 44,100 samples per second, 16-bit audio, mono, signed PCM, little
        // Endian
        AudioFormat format = new AudioFormat((float) SAMPLE_RATE, BITS_PER_SAMPLE, 1, true, false);
        DataLine.Info info = new DataLine.Info(SourceDataLine.class, format);

        line = (SourceDataLine) AudioSystem.getLine(info);
        line.open(format, SAMPLE_BUFFER_SIZE * BYTES_PER_SAMPLE);

        // the internal buffer is a fraction of the actual buffer size, this
        // choice is arbitrary
        // it gets divided because we can't expect the buffered data to line
        // up exactly with when
        // the sound card decides to push out its samples.
        buffer = new byte[SAMPLE_BUFFER_SIZE * BYTES_PER_SAMPLE / 3];
    } catch (LineUnavailableException e) {
        System.out.println(e.getMessage());
    }

    // no sound gets made before this call
    line.start();
}
SoundPlayer.java 文件源码 项目:Caritemere 阅读 31 收藏 0 点赞 0 评论 0
/**
 * WAV files only
 * 
 * @param name
 *            Name to store sound as
 * @param file
 *            Sound file
 */
public static void loadSound(String name, String file) {
    try {
        System.out.print("Loading sound file: \"" + file + "\" into clip: \"" + name + "\", ");
        BufferedInputStream in = new BufferedInputStream(SoundPlayer.class.getResourceAsStream(file));
        AudioInputStream ain = AudioSystem.getAudioInputStream(in);

        Clip c = AudioSystem.getClip();
        c.open(ain);
        c.setLoopPoints(0, -1);
        clips.put(name, c);
        ain.close();
        in.close();
        System.out.println("Done.");
    } catch (Exception e) {
        System.out.println("Failed. (" + e.getMessage() + ")");
    }
}
Toolkit.java 文件源码 项目:openjdk-jdk10 阅读 40 收藏 0 点赞 0 评论 0
public static AudioInputStream getPCMConvertedAudioInputStream(AudioInputStream ais) {
    // we can't open the device for non-PCM playback, so we have
    // convert any other encodings to PCM here (at least we try!)
    AudioFormat af = ais.getFormat();

    if( (!af.getEncoding().equals(AudioFormat.Encoding.PCM_SIGNED)) &&
        (!af.getEncoding().equals(AudioFormat.Encoding.PCM_UNSIGNED))) {

        try {
            AudioFormat newFormat =
                new AudioFormat( AudioFormat.Encoding.PCM_SIGNED,
                                 af.getSampleRate(),
                                 16,
                                 af.getChannels(),
                                 af.getChannels() * 2,
                                 af.getSampleRate(),
                                 Platform.isBigEndian());
            ais = AudioSystem.getAudioInputStream(newFormat, ais);
        } catch (Exception e) {
            if (Printer.err) e.printStackTrace();
            ais = null;
        }
    }

    return ais;
}
AlawUlaw.java 文件源码 项目:openjdk-jdk10 阅读 29 收藏 0 点赞 0 评论 0
public static void test2(AudioFormat inFormat1, AudioFormat inFormat2, AudioFormat outFormat) throws Exception {
    AudioInputStream inStream1 = new AudioInputStream(in, inFormat1, -1);
    System.out.println("Input Format1: " + printFormat(inStream1.getFormat()));

    // get a converted stream
    AudioInputStream stream1 = AudioSystem.getAudioInputStream(outFormat, inStream1);
    System.out.println("Output Format 1: " + printFormat(stream1.getFormat()));

    AudioInputStream inStream2 = new AudioInputStream(in, inFormat2, -1);
    System.out.println("Input Format1: " + printFormat(inStream2.getFormat()));

    // get a converted stream in big endian ulaw
    AudioInputStream stream2 = AudioSystem.getAudioInputStream(outFormat, inStream2);
    System.out.println("Output Format 2: " + printFormat(stream2.getFormat()));

    compareStreams(stream1, stream2);
}
JavaSoundAudioClip.java 文件源码 项目:openjdk-jdk10 阅读 32 收藏 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;
}
PlayCommand.java 文件源码 项目:RexCord 阅读 27 收藏 0 点赞 0 评论 0
/**
 * Queues song for the audio player
 * @param player main instance of the AudioPlayer
 * @param event event triggered when command is sent
 * @param audioLink URL linking to audio file
 * @throws IOException thrown if connection could not be made
 * @throws UnsupportedAudioFileException thrown if audio file linked
 *                                       is not playable
 */
private synchronized void queueSong(AudioPlayer player,
                       MessageReceivedEvent event,
                       String audioLink)
        throws IOException, UnsupportedAudioFileException {
    //Connection to server for music file
    //might be rejected because of no user agent
    URLConnection conn = new URL(audioLink.trim()).openConnection();
    conn.setRequestProperty("User-Agent", rexCord.USER_AGENT);
    AudioInputStream audioInputStream
            = AudioSystem.getAudioInputStream(conn.getInputStream());

    player.queue(audioInputStream);
    String message
            = String.format(
            "Song is now queued! Your song is #%d on the queue.",
            player.getPlaylistSize());
    rexCord.sendMessage(event.getChannel(), message);


    //Start playing music if there is nothing in the playlist.
    if (player.getPlaylistSize() == 0) {
        player.provide();
    }
}
JSMinim.java 文件源码 项目:romanov 阅读 25 收藏 0 点赞 0 评论 0
/**
 * This method is a replacement for
 * AudioSystem.getAudioInputStream(AudioFormat, AudioInputStream), which is
 * used for audio format conversion at the stream level. This method includes
 * a workaround for converting from an mp3 AudioInputStream when the sketch
 * is running in an applet. The workaround was developed by the Tritonus team
 * and originally comes from the package javazoom.jlgui.basicplayer
 * 
 * @param targetFormat
 *           the AudioFormat to convert the stream to
 * @param sourceStream
 *           the stream containing the unconverted audio
 * @return an AudioInputStream in the target format
 */
AudioInputStream getAudioInputStream(AudioFormat targetFormat,
        AudioInputStream sourceStream)
{
    try
    {
        return AudioSystem.getAudioInputStream(targetFormat, sourceStream);
    }
    catch (IllegalArgumentException iae)
    {
        debug("Using AppletMpegSPIWorkaround to get codec");
        try
        {
            Class.forName("javazoom.spi.mpeg.sampled.convert.MpegFormatConversionProvider");
            return new javazoom.spi.mpeg.sampled.convert.MpegFormatConversionProvider().getAudioInputStream(
                                                                                                                                            targetFormat,
                                                                                                                                            sourceStream);
        }
        catch (ClassNotFoundException cnfe)
        {
            throw new IllegalArgumentException("Mpeg codec not properly installed");
        }
    }
}
Toolkit.java 文件源码 项目:OpenJSharp 阅读 41 收藏 0 点赞 0 评论 0
public static AudioInputStream getPCMConvertedAudioInputStream(AudioInputStream ais) {
    // we can't open the device for non-PCM playback, so we have
    // convert any other encodings to PCM here (at least we try!)
    AudioFormat af = ais.getFormat();

    if( (!af.getEncoding().equals(AudioFormat.Encoding.PCM_SIGNED)) &&
        (!af.getEncoding().equals(AudioFormat.Encoding.PCM_UNSIGNED))) {

        try {
            AudioFormat newFormat =
                new AudioFormat( AudioFormat.Encoding.PCM_SIGNED,
                                 af.getSampleRate(),
                                 16,
                                 af.getChannels(),
                                 af.getChannels() * 2,
                                 af.getSampleRate(),
                                 Platform.isBigEndian());
            ais = AudioSystem.getAudioInputStream(newFormat, ais);
        } catch (Exception e) {
            if (Printer.err) e.printStackTrace();
            ais = null;
        }
    }

    return ais;
}
BufferedAudio.java 文件源码 项目:SimpleAudio 阅读 31 收藏 0 点赞 0 评论 0
@Override
public void open() throws AudioException {

    try {

        this.audioInputStream = Audio.getAudioInputStream(this.resource);
        this.clip = AudioSystem.getClip();
        this.clip.open(this.audioInputStream);
        this.clip.addLineListener(event -> {

            if(event.getType().equals(LineEvent.Type.STOP) && this.clip.getMicrosecondPosition() >= this.clip.getMicrosecondLength()) {

                this.trigger(AudioEvent.Type.REACHED_END);
            }
        });
        this.controls = AbstractAudio.extractControls(this.clip, this.controls);
        this.open = true;
        this.trigger(AudioEvent.Type.OPENED);

    } catch(Exception exception) {

        throw new AudioException(exception);
    }
}
ClipDuration.java 文件源码 项目:openjdk-jdk10 阅读 32 收藏 0 点赞 0 评论 0
/**
 * Returns true if at least one soundcard is correctly installed
 * on the system.
 */
public static boolean isSoundcardInstalled() {
    boolean result = false;
    try {
        Mixer.Info[] mixers = AudioSystem.getMixerInfo();
        if (mixers.length > 0) {
            result = AudioSystem.getSourceDataLine(null) != null;
        }
    } catch (Exception e) {
        System.err.println("Exception occured: "+e);
    }
    if (!result) {
        System.err.println("Soundcard does not exist or sound drivers not installed!");
        System.err.println("This test requires sound drivers for execution.");
    }
    return result;
}
WaveData.java 文件源码 项目:Spark 阅读 35 收藏 0 点赞 0 评论 0
/**
 * Creates a WaveData container from the specified url
 * 
 * @param path
 *            URL to file
 * @return WaveData containing data, or null if a failure occured
 */
public static WaveData create(URL path)
{
    try
    {
        return create(AudioSystem
                .getAudioInputStream(new BufferedInputStream(path
                        .openStream())));
    }
    catch (Exception e)
    {
        org.lwjgl.LWJGLUtil.log("Unable to create from: " + path);
        e.printStackTrace();
        return null;
    }
}
MainWindow.java 文件源码 项目:snake-game 阅读 40 收藏 0 点赞 0 评论 0
private synchronized void playSound(final String audioFileName) {
    if(isSoundEnabled) {
        try {
            Clip clip = AudioSystem.getClip();
            InputStream inputStream = MainWindow.class.getResourceAsStream(audioFileName);
            if(inputStream != null) {
                AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(inputStream);
                clip.open(audioInputStream);
                clip.start();
            }
            else {
                System.out.println("Input stream not valid");
            }
        } 
        catch (Exception e) {
            e.printStackTrace();
        }
    }
}
SoundGenerator.java 文件源码 项目:Explorium 阅读 25 收藏 0 点赞 0 评论 0
/**
 * Play a sound at a given frequency freq during duration (in seconds) with volume as strenght
 * <br/><br/>
 * <code>SoundGenerator.playSound(440.0,1.0,0.5,SoundGenerator.FADE_LINEAR,SoundGenerator.WAVE_SIN);</code><br/>
 * Available fades : FADE_NONE, FADE_LINEAR, FADE_QUADRATIC<br/>
 * Available waves : WAVE_SIN, WAVE_SQUARE, WAVE_TRIANGLE, WAVE_SAWTOOTH<br/>
 */
public static void playSound(double freq,double duration,double volume,byte fade,byte wave){

    double[] soundData = generateSoundData(freq,duration,volume,fade,wave);
    byte[] freqdata = new byte[soundData.length];

    for(int i = 0;i < soundData.length;i++) {
        freqdata[i] = (byte)soundData[i];
    }

    // Play it
    try {
        final AudioFormat af = new AudioFormat(SAMPLE_RATE, 8, 1, true, true);
        SourceDataLine line = AudioSystem.getSourceDataLine(af);
        line.open(af, SAMPLE_RATE);
        line.start();
        line.write(freqdata, 0, freqdata.length);
        line.drain();
        line.close();
    }catch(LineUnavailableException e) {
        e.printStackTrace();
    }
}
AudioInterface.java 文件源码 项目:BassNES 阅读 38 收藏 0 点赞 0 评论 0
public void restartSDL(){
    AudioFormat form = new AudioFormat(sys.getSampleRate(),16,2,true,false);

    bufptr=0;
    audioints = new int[(int)((sys.getSampleRate()/1000.0)*sys.getBufferSize())*2];
    if(scope!=null)
        scope.setAudio(audioints);
    audiobuffer = new byte[audioints.length*2];
    try {
        if(sdl!=null)
            sdl.close();
        sdl = AudioSystem.getSourceDataLine(form);
        sdl.open(form,audiobuffer.length*3);
        sdl.start();
    } catch (LineUnavailableException e) {
        e.printStackTrace();
    }

}
AiffFileWriter.java 文件源码 项目:jdk8u-jdk 阅读 25 收藏 0 点赞 0 评论 0
public int write(AudioInputStream stream, AudioFileFormat.Type fileType, OutputStream out) throws IOException {

        //$$fb the following check must come first ! Otherwise
        // the next frame length check may throw an IOException and
        // interrupt iterating File Writers. (see bug 4351296)

        // throws IllegalArgumentException if not supported
        AiffFileFormat aiffFileFormat = (AiffFileFormat)getAudioFileFormat(fileType, stream);

        // we must know the total data length to calculate the file length
        if( stream.getFrameLength() == AudioSystem.NOT_SPECIFIED ) {
            throw new IOException("stream length not specified");
        }

        int bytesWritten = writeAiffFile(stream, aiffFileFormat, out);
        return bytesWritten;
    }
FrameLengthAfterConversion.java 文件源码 项目:openjdk-jdk10 阅读 26 收藏 0 点赞 0 评论 0
/**
 * Verifies the frame length after the stream was saved/read to/from file.
 */
private static void testAfterSaveToFile(final AudioFileWriter afw,
                                        final AudioFileFormat.Type type,
                                        AudioInputStream ais)
        throws IOException {
    final File temp = File.createTempFile("sound", ".tmp");
    try {
        afw.write(ais, type, temp);
        ais = AudioSystem.getAudioInputStream(temp);
        final long frameLength = ais.getFrameLength();
        ais.close();
        validate(frameLength);
    } catch (IllegalArgumentException | UnsupportedAudioFileException
            ignored) {
    } finally {
        Files.delete(Paths.get(temp.getAbsolutePath()));
    }
}
PCM_FLOAT_support.java 文件源码 项目:openjdk-jdk10 阅读 32 收藏 0 点赞 0 评论 0
public static void main(String[] args) throws Exception {
    // 1st checks Encoding.PCM_FLOAT is available
    pcmFloatEnc = Encoding.PCM_FLOAT;

    Encoding[] encodings = AudioSystem.getTargetEncodings(pcmFloatEnc);
    out("conversion from PCM_FLOAT to " + encodings.length + " encodings:");
    for (Encoding e: encodings) {
        out("  - " + e);
    }
    if (encodings.length == 0) {
        testFailed = true;
    }

    test(Encoding.PCM_SIGNED);
    test(Encoding.PCM_UNSIGNED);

    if (testFailed) {
        throw new Exception("test failed");
    }
    out("test passed.");
}
VirtualDrummerMicrophoneInput.java 文件源码 项目:jaer 阅读 33 收藏 0 点赞 0 评论 0
/** Creates a new instance of test. Opens the microphone input as the target line.
     * To start the reporting, {@link #start} the thread.
     * @throws LineUnavailableException if microphone input is not available
     */
    public VirtualDrummerMicrophoneInput () throws LineUnavailableException{
//        getAudioInfo();  // prints lots of useless information
        format = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED,sampleRate,8,1,1,sampleRate,false);

        DataLine.Info dlinfo = new DataLine.Info(TargetDataLine.class,
                format);
        if ( AudioSystem.isLineSupported(dlinfo) ){
            targetDataLine = (TargetDataLine)AudioSystem.getLine(dlinfo);
        }
        targetDataLine.open(format,bufferSize);
        bufferSize=targetDataLine.getBufferSize();
        gui = new DrumSoundDetectorDemo();
        gui.setVirtualDrummerMicrophoneInput(this);

    }
AiffFileWriter.java 文件源码 项目:openjdk-jdk10 阅读 30 收藏 0 点赞 0 评论 0
@Override
public int write(AudioInputStream stream, AudioFileFormat.Type fileType, OutputStream out) throws IOException {
    Objects.requireNonNull(stream);
    Objects.requireNonNull(fileType);
    Objects.requireNonNull(out);

    //$$fb the following check must come first ! Otherwise
    // the next frame length check may throw an IOException and
    // interrupt iterating File Writers. (see bug 4351296)

    // throws IllegalArgumentException if not supported
    AiffFileFormat aiffFileFormat = (AiffFileFormat)getAudioFileFormat(fileType, stream);

    // we must know the total data length to calculate the file length
    if( stream.getFrameLength() == AudioSystem.NOT_SPECIFIED ) {
        throw new IOException("stream length not specified");
    }

    return writeAiffFile(stream, aiffFileFormat, out);
}
StreamPlayer.java 文件源码 项目:java-stream-player 阅读 34 收藏 0 点赞 0 评论 0
/**
 * Returns all available mixers.
 *
 * @return A List of available Mixers
 */
public List<String> getMixers() {
    List<String> mixers = new ArrayList<>();

    // Obtains an array of mixer info objects that represents the set of
    // audio mixers that are currently installed on the system.
    Mixer.Info[] mixerInfos = AudioSystem.getMixerInfo();

    if (mixerInfos != null)
        Arrays.stream(mixerInfos).forEach(mInfo -> {
            // line info
            Line.Info lineInfo = new Line.Info(SourceDataLine.class);
            Mixer mixer = AudioSystem.getMixer(mInfo);

            // if line supported
            if (mixer.isLineSupported(lineInfo))
                mixers.add(mInfo.getName());

        });

    return mixers;
}
ClipDrain.java 文件源码 项目:openjdk-jdk10 阅读 32 收藏 0 点赞 0 评论 0
/**
 * Returns true if at least one soundcard is correctly installed
 * on the system.
 */
public static boolean isSoundcardInstalled() {
    boolean result = false;
    try {
        Mixer.Info[] mixers = AudioSystem.getMixerInfo();
        if (mixers.length > 0) {
            result = AudioSystem.getSourceDataLine(null) != null;
        }
    } catch (Exception e) {
        System.err.println("Exception occured: "+e);
    }
    if (!result) {
        System.err.println("Soundcard does not exist or sound drivers not installed!");
        System.err.println("This test requires sound drivers for execution.");
    }
    return result;
}
Record.java 文件源码 项目:rcom 阅读 31 收藏 0 点赞 0 评论 0
public static void main(String[] args) throws Exception {
    AudioFormat format=ManualTestEchoCancel.getFormat();
    final Mixer mixer = AudioSystem.getMixer(null);
    Mic m=new Mic(mixer, format, ManualTestEchoCancel.frameSamples);
    m.start();
    try(Scanner br=new Scanner(System.in))
    {
        System.out.println("Press ENTER to start recording");
        br.nextLine();
        try(FileOutputStream fos=new FileOutputStream("/tmp/out.sw"))
        {
            m.setRecord(fos);
            System.out.println("Press ENTER to stop recording");
            br.nextLine();
            m.setRecord(null);
        }
    }
    System.exit(0);
}
AudioFileTypeUniqueness.java 文件源码 项目:openjdk-jdk10 阅读 37 收藏 0 点赞 0 评论 0
public static void main(String[] args) throws Exception {
    boolean foundDuplicates = false;
    AudioFileFormat.Type[]  aTypes = AudioSystem.getAudioFileTypes();
    for (int i = 0; i < aTypes.length; i++)
    {
        for (int j = 0; j < aTypes.length; j++)
        {
            if (aTypes[i].equals(aTypes[j]) && i != j) {
                foundDuplicates = true;
            }
        }
    }
    if (foundDuplicates) {
        throw new Exception("Test failed");
    } else {
        System.out.println("Test passed");
    }
}
AudioFileSoundbankReader.java 文件源码 项目:OpenJSharp 阅读 43 收藏 0 点赞 0 评论 0
public Soundbank getSoundbank(File file)
        throws InvalidMidiDataException, IOException {
    try {
        AudioInputStream ais = AudioSystem.getAudioInputStream(file);
        ais.close();
        ModelByteBufferWavetable osc = new ModelByteBufferWavetable(
                new ModelByteBuffer(file, 0, file.length()), -4800);
        ModelPerformer performer = new ModelPerformer();
        performer.getOscillators().add(osc);
        SimpleSoundbank sbk = new SimpleSoundbank();
        SimpleInstrument ins = new SimpleInstrument();
        ins.add(performer);
        sbk.addInstrument(ins);
        return sbk;
    } catch (UnsupportedAudioFileException e1) {
        return null;
    } catch (IOException e) {
        return null;
    }
}
ClipLinuxCrash2.java 文件源码 项目:openjdk-jdk10 阅读 38 收藏 0 点赞 0 评论 0
/**
 * Returns true if at least one soundcard is correctly installed
 * on the system.
 */
public static boolean isSoundcardInstalled() {
    boolean result = false;
    try {
        Mixer.Info[] mixers = AudioSystem.getMixerInfo();
        if (mixers.length > 0) {
            result = AudioSystem.getSourceDataLine(null) != null;
        }
    } catch (Exception e) {
        System.err.println("Exception occured: "+e);
    }
    if (!result) {
        System.err.println("Soundcard does not exist or sound drivers not installed!");
        System.err.println("This test requires sound drivers for execution.");
    }
    return result;
}
ClipFlushCrash.java 文件源码 项目:openjdk-jdk10 阅读 26 收藏 0 点赞 0 评论 0
public static void main(String[] args) throws Exception     {
    if (isSoundcardInstalled()) {
            bais.mark(0);
        run(null);
        Mixer.Info[] infos = AudioSystem.getMixerInfo();
        for (int i = 0; i<infos.length; i++) {
            try {
                    Mixer m = AudioSystem.getMixer(infos[i]);
                    run(m);
            } catch (Exception e) {
            }
        }
        if (success > 0) {
            out("No crash -> Test passed");
        } else {
            System.err.println("Test could not execute: please install an audio device");
        }
    }
}
WaveData.java 文件源码 项目:trashjam2017 阅读 39 收藏 0 点赞 0 评论 0
/**
 * Creates a WaveData container from the specified inputstream
 * 
 * @param is InputStream to read from 
 * @return WaveData containing data, or null if a failure occured
 */
public static WaveData create(InputStream is) {
    try {
        return create(
            AudioSystem.getAudioInputStream(is));
    } catch (Exception e) {
        org.lwjgl.LWJGLUtil.log("Unable to create from inputstream");
        e.printStackTrace();
        return null;
    }       
}
SoftMixingClip.java 文件源码 项目:openjdk-jdk10 阅读 34 收藏 0 点赞 0 评论 0
@Override
public void open(AudioInputStream stream) throws LineUnavailableException,
                                                 IOException {
    if (isOpen()) {
        throw new IllegalStateException("Clip is already open with format "
                + getFormat() + " and frame lengh of " + getFrameLength());
    }
    if (AudioFloatConverter.getConverter(stream.getFormat()) == null)
        throw new IllegalArgumentException("Invalid format : "
                + stream.getFormat().toString());

    if (stream.getFrameLength() != AudioSystem.NOT_SPECIFIED) {
        byte[] data = new byte[(int) stream.getFrameLength()
                * stream.getFormat().getFrameSize()];
        int readsize = 512 * stream.getFormat().getFrameSize();
        int len = 0;
        while (len != data.length) {
            if (readsize > data.length - len)
                readsize = data.length - len;
            int ret = stream.read(data, len, readsize);
            if (ret == -1)
                break;
            if (ret == 0)
                Thread.yield();
            len += ret;
        }
        open(stream.getFormat(), data, 0, len);
    } else {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        byte[] b = new byte[512 * stream.getFormat().getFrameSize()];
        int r = 0;
        while ((r = stream.read(b)) != -1) {
            if (r == 0)
                Thread.yield();
            baos.write(b, 0, r);
        }
        open(stream.getFormat(), baos.toByteArray(), 0, baos.size());
    }

}
AiffData.java 文件源码 项目:trashjam2017 阅读 34 收藏 0 点赞 0 评论 0
/**
 * Creates a AiffData container from the specified url
 * 
 * @param path URL to file 
 * @return AiffData containing data, or null if a failure occured
 */
public static AiffData create(URL path) {
    try {
        return create(
            AudioSystem.getAudioInputStream(
                new BufferedInputStream(path.openStream())));
    } catch (Exception e) {
        org.lwjgl.LWJGLUtil.log("Unable to create from: " + path);
        e.printStackTrace();
        return null;
    }       
}
Has16and32KHz.java 文件源码 项目:openjdk-jdk10 阅读 28 收藏 0 点赞 0 评论 0
public static void main(String[] args) throws Exception {
    boolean res=true;

    Mixer.Info[] mixerInfo = AudioSystem.getMixerInfo();
    System.out.println(mixerInfo.length+" mixers on system.");
    if (mixerInfo.length == 0) {
        System.out.println("Cannot execute test. Not Failed!");
    } else {
        for (int i = 0; i < mixerInfo.length; i++) {
            Mixer mixer = AudioSystem.getMixer(mixerInfo[i]);
            System.out.println();
            System.out.println(mixer+":");
            showMixerLines(mixer.getSourceLineInfo());
            showMixerLines(mixer.getTargetLineInfo());


        }
        res=ok16 && ok32;
    }
    if (res) {
        System.out.println("Test passed");
    } else {
        System.out.println("Test failed");
        throw new Exception("Test failed");
    }
    //ystem.exit(res?0:1);
}


问题


面经


文章

微信
公众号

扫码关注公众号