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;
}
}
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);
}
}
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();
}
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();
}
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);
}
Aggregations