Search in sources :

Example 91 with AudioFormat

use of javax.sound.sampled.AudioFormat in project blue by kunstmusik.

the class AudioFileEditor method setAudioFileInfo.

private void setAudioFileInfo(String audioFile) {
    if (audioFile == null || audioFile.equals("")) {
        audioFileName.setText("Choose an Audio File");
        clearAudioInfo();
        return;
    }
    File soundFile = BlueSystem.findFile(audioFile);
    if (soundFile == null || !soundFile.exists() || !soundFile.isFile()) {
        audioFileName.setText("Could not find file: " + audioFile);
        clearAudioInfo();
        return;
    }
    audioFileName.setText(audioFile);
    try {
        AudioFileFormat aFormat = AudioSystem.getAudioFileFormat(soundFile);
        AudioFormat format = aFormat.getFormat();
        durationText.setText(getDuration(aFormat, format));
        formatTypeText.setText(aFormat.getType().toString());
        byteLengthText.setText(Integer.toString(aFormat.getByteLength()));
        encodingTypeText.setText(format.getEncoding().toString());
        sampleRateText.setText(Float.toString(format.getSampleRate()));
        sampleSizeInBitsText.setText(Integer.toString(format.getSampleSizeInBits()));
        int numChannels = format.getChannels();
        channelsText.setText(Integer.toString(numChannels));
        setChannelVariablesInfo(numChannels);
        isBigEndianText.setText(getBooleanString(format.isBigEndian()));
    } catch (java.io.IOException ioe) {
        JOptionPane.showMessageDialog(null, BlueSystem.getString("soundfile.infoPanel.error.couldNotOpenFile") + " " + soundFile.getAbsolutePath());
        clearAudioInfo();
        return;
    } catch (javax.sound.sampled.UnsupportedAudioFileException uae) {
        JOptionPane.showMessageDialog(null, BlueSystem.getString("soundfile.infoPanel.error.unsupportedAudio") + " " + uae.getLocalizedMessage());
        clearAudioInfo();
        return;
    }
}
Also used : AudioFormat(javax.sound.sampled.AudioFormat) AudioFile(blue.soundObject.AudioFile) File(java.io.File) AudioFileFormat(javax.sound.sampled.AudioFileFormat)

Example 92 with AudioFormat

use of javax.sound.sampled.AudioFormat in project blue by kunstmusik.

the class AudioClip method readAudioFileProperties.

protected void readAudioFileProperties() {
    AudioFileFormat aFormat;
    try {
        aFormat = AudioSystem.getAudioFileFormat(audioFile.get());
        AudioFormat format = aFormat.getFormat();
        numChannels = format.getChannels();
        audioDuration = aFormat.getByteLength() / (format.getSampleRate() * (format.getSampleSizeInBits() / 8) * format.getChannels());
    } catch (UnsupportedAudioFileException | IOException ex) {
        Exceptions.printStackTrace(ex);
    }
}
Also used : UnsupportedAudioFileException(javax.sound.sampled.UnsupportedAudioFileException) IOException(java.io.IOException) AudioFormat(javax.sound.sampled.AudioFormat) AudioFileFormat(javax.sound.sampled.AudioFileFormat)

Example 93 with AudioFormat

use of javax.sound.sampled.AudioFormat in project blue by kunstmusik.

the class SoundFileUtilities method getSampleRate.

/**
 * @param fileName
 * @return
 */
public static float getSampleRate(String soundFileName) throws IOException, UnsupportedAudioFileException {
    File soundFile = BlueSystem.findFile(soundFileName);
    AudioFileFormat aFormat = AudioSystem.getAudioFileFormat(soundFile);
    AudioFormat format = aFormat.getFormat();
    return format.getSampleRate();
}
Also used : AudioFormat(javax.sound.sampled.AudioFormat) File(java.io.File) AudioFileFormat(javax.sound.sampled.AudioFileFormat)

Example 94 with AudioFormat

use of javax.sound.sampled.AudioFormat in project blue by kunstmusik.

the class SoundFileUtilities method getNumberOfChannels.

public static int getNumberOfChannels(String soundFileName) throws IOException, UnsupportedAudioFileException {
    File soundFile = BlueSystem.findFile(soundFileName);
    AudioFileFormat aFormat = AudioSystem.getAudioFileFormat(soundFile);
    AudioFormat format = aFormat.getFormat();
    return format.getChannels();
}
Also used : AudioFormat(javax.sound.sampled.AudioFormat) File(java.io.File) AudioFileFormat(javax.sound.sampled.AudioFileFormat)

Example 95 with AudioFormat

use of javax.sound.sampled.AudioFormat in project blue by kunstmusik.

the class AudioFilePlayer method setSoundFile.

public void setSoundFile(File soundFile) {
    Object oldSoundFile = this.soundFile;
    this.soundFile = soundFile;
    boolean isAudioFile = true;
    AudioFileFormat aFormat = null;
    AudioFormat format = null;
    try {
        aFormat = AudioSystem.getAudioFileFormat(soundFile);
        format = aFormat.getFormat();
    } catch (UnsupportedAudioFileException | IOException | NullPointerException e) {
        isAudioFile = false;
        timeDivisor = -1;
    }
    stop();
    if (this.soundFile == null || !isAudioFile) {
        this.fileNameText.setText("");
        this.playStopButton.setEnabled(false);
        playStopButton.setText(BlueSystem.getString("soundfile.player.noFileSelected"));
    } else {
        this.fileNameText.setText(soundFile.getAbsolutePath());
        this.playStopButton.setEnabled(true);
        playStopButton.setText(BlueSystem.getString("soundfile.player.playStop"));
        timeDivisor = format.getSampleRate() * (format.getSampleSizeInBits() / 8) * format.getChannels();
        currentTime = "00:00:00";
        duration = getTimeString(aFormat.getByteLength());
        timeDisplay.setText(currentTime + "/" + duration);
    }
    firePropertyChange("soundFile", oldSoundFile, this.soundFile);
}
Also used : UnsupportedAudioFileException(javax.sound.sampled.UnsupportedAudioFileException) IOException(java.io.IOException) AudioFormat(javax.sound.sampled.AudioFormat) AudioFileFormat(javax.sound.sampled.AudioFileFormat)

Aggregations

AudioFormat (javax.sound.sampled.AudioFormat)112 AudioInputStream (javax.sound.sampled.AudioInputStream)43 IOException (java.io.IOException)24 DataLine (javax.sound.sampled.DataLine)21 SourceDataLine (javax.sound.sampled.SourceDataLine)21 AudioFileFormat (javax.sound.sampled.AudioFileFormat)18 UnsupportedAudioFileException (javax.sound.sampled.UnsupportedAudioFileException)18 LineUnavailableException (javax.sound.sampled.LineUnavailableException)17 File (java.io.File)15 InputStream (java.io.InputStream)14 ByteArrayInputStream (java.io.ByteArrayInputStream)13 TargetDataLine (javax.sound.sampled.TargetDataLine)7 MpegAudioFormat (javazoom.spi.mpeg.sampled.file.MpegAudioFormat)7 BufferedInputStream (java.io.BufferedInputStream)6 FileInputStream (java.io.FileInputStream)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 DataInputStream (java.io.DataInputStream)5 Vector (java.util.Vector)5 SequenceInputStream (java.io.SequenceInputStream)4 Clip (javax.sound.sampled.Clip)4