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

Last change on this file since 6340 was 6070, checked in by stoecker, 11 years ago

see #8853 remove tabs, trailing spaces, windows line ends, strange characters

  • Property svn:eol-style set to native
File size: 1.4 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 * Utils functions for audio.
15 *
16 * @author David Earl <david@frankieandshadow.com>
17 * @since 1462
18 */
19public class AudioUtil {
20
21 /**
22 * Returns calibrated length of recording in seconds.
23 * @param wavFile the recording file (WAV format)
24 * @return the calibrated length of recording in seconds.
25 */
26 static public double getCalibratedDuration(File wavFile) {
27 try {
28 AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(
29 new URL("file:".concat(wavFile.getAbsolutePath())));
30 AudioFormat audioFormat = audioInputStream.getFormat();
31 long filesize = wavFile.length();
32 double bytesPerSecond = audioFormat.getFrameRate() /* frames per second */
33 * audioFormat.getFrameSize() /* bytes per frame */;
34 double naturalLength = filesize / bytesPerSecond;
35 Utils.close(audioInputStream);
36 double calibration = Main.pref.getDouble("audio.calibration", 1.0 /* default, ratio */);
37 return naturalLength / calibration;
38 } catch (Exception e) {
39 return 0.0;
40 }
41 }
42}
Note: See TracBrowser for help on using the repository browser.