Search in sources :

Example 6 with AudioFormat

use of javax.sound.sampled.AudioFormat in project jdk8u_jdk by JetBrains.

the class Matches_NOT_SPECIFIED method main.

public static void main(String[] args) throws Exception {
    AudioFormat f3;
    f1 = new AudioFormat(44100, 16, 2, true, false);
    f2 = new AudioFormat(Encoding.PCM_SIGNED, AudioSystem.NOT_SPECIFIED, AudioSystem.NOT_SPECIFIED, AudioSystem.NOT_SPECIFIED, AudioSystem.NOT_SPECIFIED, AudioSystem.NOT_SPECIFIED, false);
    test(true);
    //        f1 = new AudioFormat(44100, 8, 16, true, false);
    f2 = new AudioFormat(Encoding.PCM_SIGNED, AudioSystem.NOT_SPECIFIED, AudioSystem.NOT_SPECIFIED, AudioSystem.NOT_SPECIFIED, AudioSystem.NOT_SPECIFIED, AudioSystem.NOT_SPECIFIED, true);
    test(false);
    f1 = new AudioFormat(44100, 8, 8, true, false);
    test(true);
    if (success) {
        out("The test PASSED.");
    } else {
        out("The test FAILED.");
        throw new Exception("The test FAILED");
    }
}
Also used : AudioFormat(javax.sound.sampled.AudioFormat)

Example 7 with AudioFormat

use of javax.sound.sampled.AudioFormat in project jdk8u_jdk by JetBrains.

the class TestPreciseTimestampRendering method createTestSoundbankWithChannelMixer.

public static Soundbank createTestSoundbankWithChannelMixer() {
    SF2Soundbank soundbank = createTestSoundbank();
    SimpleSoundbank simplesoundbank = new SimpleSoundbank();
    SimpleInstrument simpleinstrument = new SimpleInstrument() {

        public ModelChannelMixer getChannelMixer(MidiChannel channel, AudioFormat format) {
            return new ModelAbstractChannelMixer() {

                boolean active = true;

                public boolean process(float[][] buffer, int offset, int len) {
                    for (int i = 0; i < buffer.length; i++) {
                        float[] cbuffer = buffer[i];
                        for (int j = 0; j < cbuffer.length; j++) {
                            cbuffer[j] = -cbuffer[j];
                        }
                    }
                    return active;
                }

                public void stop() {
                    active = false;
                }
            };
        }
    };
    simpleinstrument.add(soundbank.getInstruments()[0]);
    simplesoundbank.addInstrument(simpleinstrument);
    return simplesoundbank;
}
Also used : SF2Soundbank(com.sun.media.sound.SF2Soundbank) MidiChannel(javax.sound.midi.MidiChannel) SimpleSoundbank(com.sun.media.sound.SimpleSoundbank) AudioFormat(javax.sound.sampled.AudioFormat) ModelAbstractChannelMixer(com.sun.media.sound.ModelAbstractChannelMixer) SimpleInstrument(com.sun.media.sound.SimpleInstrument)

Example 8 with AudioFormat

use of javax.sound.sampled.AudioFormat in project jdk8u_jdk by JetBrains.

the class SkipTest method main.

public static void main(String[] args) throws Exception {
    AudioFloatFormatConverter converter = new AudioFloatFormatConverter();
    byte[] data = { 10, 20, 30, 40, 30, 20, 10 };
    AudioFormat format = new AudioFormat(8000, 8, 1, true, false);
    AudioFormat format2 = new AudioFormat(16000, 8, 1, true, false);
    AudioInputStream ais = new AudioInputStream(new ByteArrayInputStream(data), format, data.length);
    AudioInputStream ais2 = converter.getAudioInputStream(format2, ais);
    byte[] data2 = new byte[30];
    int ret = ais2.read(data2, 0, data2.length);
    ais.reset();
    AudioInputStream ais3 = converter.getAudioInputStream(format2, ais);
    byte[] data3 = new byte[100];
    ais3.skip(7);
    int ret2 = ais3.read(data3, 7, data3.length);
    if (ret2 != ret - 7)
        throw new Exception("Skip doesn't work correctly (" + ret2 + " != " + (ret - 7) + ")");
    for (int i = 7; i < ret2 + 7; i++) {
        if (data3[i] != data2[i])
            throw new Exception("Skip doesn't work correctly (" + data3[i] + " != " + data2[i] + ")");
    }
}
Also used : AudioInputStream(javax.sound.sampled.AudioInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) AudioFormat(javax.sound.sampled.AudioFormat) AudioFloatFormatConverter(com.sun.media.sound.AudioFloatFormatConverter)

Example 9 with AudioFormat

use of javax.sound.sampled.AudioFormat in project jdk8u_jdk by JetBrains.

the class NoteOverFlowTest method main.

public static void main(String[] args) throws Exception {
    AudioSynthesizer synth = new SoftSynthesizer();
    AudioFormat format = new AudioFormat(44100, 16, 2, true, false);
    AudioInputStream stream = synth.openStream(format, null);
    // Make all voices busy, e.g.
    // send midi on and midi off on all available voices
    MidiChannel ch1 = synth.getChannels()[0];
    // Use contionus instrument like string ensemble
    ch1.programChange(48);
    for (int i = 0; i < synth.getMaxPolyphony(); i++) {
        ch1.noteOn(64, 64);
        ch1.noteOff(64);
    }
    // Now send single midi on, and midi off message
    ch1.noteOn(64, 64);
    ch1.noteOff(64);
    // Read 10 sec from stream, by this time all voices should be inactvie
    stream.skip(format.getFrameSize() * ((int) (format.getFrameRate() * 20)));
    // If no voice are active, then this test will pass
    VoiceStatus[] v = synth.getVoiceStatus();
    for (int i = 0; i < v.length; i++) {
        if (v[i].active) {
            throw new RuntimeException("Not all voices are inactive!");
        }
    }
    // Close the synthesizer after use
    synth.close();
}
Also used : AudioInputStream(javax.sound.sampled.AudioInputStream) MidiChannel(javax.sound.midi.MidiChannel) SoftSynthesizer(com.sun.media.sound.SoftSynthesizer) AudioFormat(javax.sound.sampled.AudioFormat) AudioSynthesizer(com.sun.media.sound.AudioSynthesizer) VoiceStatus(javax.sound.midi.VoiceStatus)

Example 10 with AudioFormat

use of javax.sound.sampled.AudioFormat in project ACS by ACS-Community.

the class AlarmSound method dumpAudioInformation.

/**
	 * Dump info about supported audio, file types and so on...
	 * <P>
	 * This method is useful while updating the audio files.
	 */
private void dumpAudioInformation() {
    // Java supported file types
    AudioFileFormat.Type[] fileTypes = AudioSystem.getAudioFileTypes();
    if (fileTypes == null || fileTypes.length == 0) {
        System.out.println("No audio file types supported.");
    } else {
        for (AudioFileFormat.Type type : fileTypes) {
            System.out.println(type.toString() + ", extension " + type.getExtension());
        }
    }
    Mixer.Info[] mixerInfos = AudioSystem.getMixerInfo();
    System.out.println("Mixers found: " + mixerInfos.length);
    for (Mixer.Info mi : mixerInfos) {
        System.out.println("\tMixer " + mi.getName() + ": " + mi.getVendor() + ", " + mi.getDescription());
    }
    // Dump info about the alarm files
    for (URL url : soundURLs) {
        AudioFileFormat format = null;
        try {
            format = AudioSystem.getAudioFileFormat(url);
        } catch (IOException ioe) {
            System.err.println("Error " + ioe.getMessage() + " accessing URL " + url.toString());
            continue;
        } catch (UnsupportedAudioFileException ue) {
            System.err.println("Unsupported audio format for " + url + " (" + ue.getMessage() + ")");
        }
        System.out.println("Properties of " + url);
        System.out.println("\tAudio file type " + format.getType().toString());
        System.out.println("\tIs file type supported: " + AudioSystem.isFileTypeSupported(format.getType()));
        System.out.println("\tLength in byes " + format.getByteLength());
        Map<String, Object> props = format.properties();
        Set<String> keys = props.keySet();
        for (String str : keys) {
            System.out.println("\t[" + str + ", " + props.get(str).toString() + "]");
        }
        AudioFormat aFormat = format.getFormat();
        System.out.println("\tEncoding " + aFormat.getEncoding().toString());
        System.out.print("\tByte order ");
        if (aFormat.isBigEndian()) {
            System.out.println("big endian");
        } else {
            System.out.println("little endian");
        }
        System.out.println("\tSample rate: " + aFormat.getSampleRate());
        System.out.println("\tNum. of bits of a sample: " + aFormat.getSampleSizeInBits());
        System.out.println("\tNum. of channels: " + aFormat.getChannels());
    }
}
Also used : Mixer(javax.sound.sampled.Mixer) IOException(java.io.IOException) AudioFileFormat(javax.sound.sampled.AudioFileFormat) URL(java.net.URL) UnsupportedAudioFileException(javax.sound.sampled.UnsupportedAudioFileException) AudioFormat(javax.sound.sampled.AudioFormat)

Aggregations

AudioFormat (javax.sound.sampled.AudioFormat)74 AudioInputStream (javax.sound.sampled.AudioInputStream)32 IOException (java.io.IOException)12 InputStream (java.io.InputStream)12 UnsupportedAudioFileException (javax.sound.sampled.UnsupportedAudioFileException)11 AudioFileFormat (javax.sound.sampled.AudioFileFormat)10 SourceDataLine (javax.sound.sampled.SourceDataLine)8 ByteArrayInputStream (java.io.ByteArrayInputStream)7 MpegAudioFormat (javazoom.spi.mpeg.sampled.file.MpegAudioFormat)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 DataInputStream (java.io.DataInputStream)6 File (java.io.File)6 BufferedInputStream (java.io.BufferedInputStream)5 FileInputStream (java.io.FileInputStream)5 Vector (java.util.Vector)5 DataLine (javax.sound.sampled.DataLine)5 LineUnavailableException (javax.sound.sampled.LineUnavailableException)5 SequenceInputStream (java.io.SequenceInputStream)4 AudioMetaData (ddf.minim.AudioMetaData)3 DataOutputStream (java.io.DataOutputStream)3