Package javax.sound.sampled

Examples of javax.sound.sampled.AudioFormat


     * ranges or if error occurs during conversion.
     */
    public AudioInputStream getAudioInputStreamMixedDown(double start_time, double end_time)
            throws Exception {
        // Specify that only one channel is used
        AudioFormat mixed_down_audio_format = new AudioFormat(audio_format.getSampleRate(),
                audio_format.getSampleSizeInBits(),
                1,
                true,
                audio_format.isBigEndian());

View Full Code Here


        int channels = 1;
        if (channel_samples == null)
            channels = channel_samples.length;

        return new AudioFormat(sampling_rate, bit_depth, channels, signed, big_endian);
    }
View Full Code Here

     *
     * @param    old_audio_format    The AudioFormat to copy.
     * @return A copy of old_audio_format.
     */
    public static AudioFormat getCopyOfAudioFormat(AudioFormat old_audio_format) {
        return new AudioFormat(old_audio_format.getEncoding(),
                old_audio_format.getSampleRate(),
                old_audio_format.getSampleSizeInBits(),
                old_audio_format.getChannels(),
                old_audio_format.getFrameSize(),
                old_audio_format.getFrameRate(),
View Full Code Here

     */
    public static AudioFormat getConvertedAudioFormat(AudioFormat original_format) {
        int bit_depth = original_format.getSampleSizeInBits();
        if (bit_depth != 8 && bit_depth != 16)
            bit_depth = 16;
        return new AudioFormat(AudioFormat.Encoding.PCM_SIGNED,
                original_format.getSampleRate(),
                bit_depth,
                original_format.getChannels(),
                original_format.getChannels() * (bit_depth / 8),
                original_format.getSampleRate(),
View Full Code Here

     * @return A copy of the passed AudioInputStream  with the
     * new encoding.
     */
    public static AudioInputStream getConvertedAudioStream(AudioInputStream audio_input_stream) {
        audio_input_stream = convertUnsupportedFormat(audio_input_stream);
        AudioFormat original_audio_format = audio_input_stream.getFormat();
        AudioFormat new_audio_format = getConvertedAudioFormat(original_audio_format);
        if (!new_audio_format.matches(original_audio_format))
            audio_input_stream = AudioSystem.getAudioInputStream(new_audio_format, audio_input_stream);
        return audio_input_stream;
    }
View Full Code Here

     */
    public static AudioInputStream convertUnsupportedFormat(AudioInputStream audio_input_stream) {
        DataLine.Info info = new DataLine.Info(SourceDataLine.class,
                audio_input_stream.getFormat());
        if (!AudioSystem.isLineSupported(info)) {
            AudioFormat original_format = audio_input_stream.getFormat();
            int bit_depth = 16;
            AudioFormat new_audio_format = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED,
                    original_format.getSampleRate(),
                    bit_depth,
                    original_format.getChannels(),
                    original_format.getChannels() * (bit_depth / 8),
                    original_format.getSampleRate(),
View Full Code Here

        // Converts the contents of audio_input_stream into an array of bytes
        byte[] audio_bytes = getBytesFromAudioInputStream(audio_input_stream);
        int number_bytes = audio_bytes.length;

        // Note the AudioFormat
        AudioFormat this_audio_format = audio_input_stream.getFormat();

        // Extract information from this_audio_format
        int number_of_channels = this_audio_format.getChannels();
        int bit_depth = this_audio_format.getSampleSizeInBits();

        // Throw exception if incompatible this_audio_format provided
        if ((bit_depth != 16 && bit_depth != 8) ||
                !this_audio_format.isBigEndian() ||
                this_audio_format.getEncoding() != AudioFormat.Encoding.PCM_SIGNED)
            throw new Exception("Only 8 or 16 bit signed PCM samples with a big-endian\n" +
                    "byte order can be analyzed currently.");

        // Find the number of samples in the audio_bytes
        int number_of_bytes = audio_bytes.length;
View Full Code Here

     *                   reading or pre- processing.
     */
    private double[] preProcessRecording(File recordingFile) throws Exception {
        // Get the original audio and its format
        AudioInputStream originalStream = AudioSystem.getAudioInputStream(recordingFile);
        AudioFormat originalFormat = originalStream.getFormat();

        // Set the bit depth
        int bitDepth = originalFormat.getSampleSizeInBits();
        if (bitDepth != 8 && bitDepth != 16) {
            bitDepth = 16;
        }

        // If the audio is not PCM signed big endian, then convert it to PCM
        // signed
        // This is particularly necessary when dealing with MP3s
        AudioInputStream secondStream = originalStream;
        if (originalFormat.getEncoding() != AudioFormat.Encoding.PCM_SIGNED || !originalFormat.isBigEndian()) {
            AudioFormat newFormat = new AudioFormat(
                    AudioFormat.Encoding.PCM_SIGNED,
                    originalFormat.getSampleRate(),
                    bitDepth,
                    originalFormat.getChannels(),
                    originalFormat.getChannels() * (bitDepth / 8),
                    originalFormat.getSampleRate(),
                    true);
            secondStream = AudioSystem.getAudioInputStream(newFormat, originalStream);
        }

        // Convert to the set sampling rate, if it is not already at this
        // sampling rate.
        // Also, convert to an appropriate bit depth if necessary.
        AudioInputStream newStream = secondStream;
        if (originalFormat.getSampleRate() !=  settings.getSamplingRate().floatValue()
                || bitDepth != originalFormat.getSampleSizeInBits() ) {
            AudioFormat newFormat = new AudioFormat(
                    AudioFormat.Encoding.PCM_SIGNED,
                    settings.getSamplingRate().floatValue(),
                    bitDepth,
                    originalFormat.getChannels(),
                    originalFormat.getChannels() * (bitDepth / 8),
View Full Code Here

        xhtml.startDocument();

        // AudioSystem expects the stream to support the mark feature
        InputStream buffered = new BufferedInputStream(stream);
        try {
            AudioFormat format =
                AudioSystem.getAudioFileFormat(buffered).getFormat();

            float rate = format.getSampleRate();
            if (rate != AudioSystem.NOT_SPECIFIED) {
                metadata.set("samplerate", String.valueOf(rate));
            }

            int channels = format.getChannels();
            if (channels != AudioSystem.NOT_SPECIFIED) {
                metadata.set("channels", String.valueOf(channels));
            }

            int bits = format.getSampleSizeInBits();
            if (bits != AudioSystem.NOT_SPECIFIED) {
                metadata.set("bits", String.valueOf(bits));
            }

            metadata.set("encoding", format.getEncoding().toString());

            // Javadoc suggests that some of the following properties might
            // be available, but I had no success in finding any:

            // "duration" Long playback duration of the file in microseconds
            // "author" String name of the author of this file
            // "title" String title of this file
            // "copyright" String copyright message
            // "date" Date date of the recording or release
            // "comment" String an arbitrary text

            for (Entry<String, Object> entry : format.properties().entrySet()) {
                metadata.set(entry.getKey(), entry.getValue().toString());
            }
        } catch (UnsupportedAudioFileException e) {
            // There is no way to know whether this exception was
            // caused by the document being corrupted or by the format
View Full Code Here

    public SoundManager(boolean mediaDebug, Logger logger, String peersHome) {
        this.mediaDebug = mediaDebug;
        this.logger = logger;
        this.peersHome = peersHome;
        // linear PCM 8kHz, 16 bits signed, mono-channel, little endian
        audioFormat = new AudioFormat(8000, 16, 1, true, false);
        targetInfo = new DataLine.Info(TargetDataLine.class, audioFormat);
        sourceInfo = new DataLine.Info(SourceDataLine.class, audioFormat);
    }
View Full Code Here

TOP

Related Classes of javax.sound.sampled.AudioFormat

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.