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

Last change on this file since 2474 was 2017, checked in by Gubaer, 15 years ago

removed OptionPaneUtil
cleanup of deprecated Layer API
cleanup of deprecated APIs in OsmPrimitive and Way
cleanup of imports

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