source: josm/trunk/src/org/openstreetmap/josm/tools/AudioUtil.java@ 1685

Last change on this file since 1685 was 1685, checked in by stoecker, 15 years ago

fixed audio handling a bit

File size: 1.3 KB
Line 
1// License: GPL. Copyright 2009 by David Earl and others
2package org.openstreetmap.josm.tools;
3
4import java.io.IOException;
5import java.net.URL;
6import java.io.File;
7
8import javax.sound.sampled.AudioFormat;
9import javax.sound.sampled.AudioInputStream;
10import javax.sound.sampled.AudioSystem;
11
12import org.openstreetmap.josm.Main;
13
14/**
15 * Returns calibrated length of recording in seconds.
16 *
17 * @author David Earl <david@frankieandshadow.com>
18 *
19 */
20public class AudioUtil {
21 static public double getCalibratedDuration(File wavFile) {
22 try {
23 AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(
24 new URL("file:".concat(wavFile.getAbsolutePath())));
25 AudioFormat audioFormat = audioInputStream.getFormat();
26 long filesize = wavFile.length();
27 double bytesPerSecond = audioFormat.getFrameRate() /* frames per second */
28 * audioFormat.getFrameSize() /* bytes per frame */;
29 double naturalLength = filesize / bytesPerSecond;
30 audioInputStream.close();
31 double calibration = Main.pref.getDouble("audio.calibration", "1.0" /* default, ratio */);
32 return naturalLength / calibration;
33 } catch (Exception e) {
34 return 0.0;
35 }
36 }
37}
Note: See TracBrowser for help on using the repository browser.