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

Last change on this file since 6617 was 6380, checked in by Don-vip, 10 years ago

update license/copyright information

  • Property svn:eol-style set to native
File size: 1.5 KB
Line 
1// License: GPL. For details, see LICENSE file.
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 final class AudioUtil {
20
21 private AudioUtil() {
22 // Hide default constructor for utils classes
23 }
24
25 /**
26 * Returns calibrated length of recording in seconds.
27 * @param wavFile the recording file (WAV format)
28 * @return the calibrated length of recording in seconds.
29 */
30 static public double getCalibratedDuration(File wavFile) {
31 try {
32 AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(
33 new URL("file:".concat(wavFile.getAbsolutePath())));
34 AudioFormat audioFormat = audioInputStream.getFormat();
35 long filesize = wavFile.length();
36 double bytesPerSecond = audioFormat.getFrameRate() /* frames per second */
37 * audioFormat.getFrameSize() /* bytes per frame */;
38 double naturalLength = filesize / bytesPerSecond;
39 Utils.close(audioInputStream);
40 double calibration = Main.pref.getDouble("audio.calibration", 1.0 /* default, ratio */);
41 return naturalLength / calibration;
42 } catch (Exception e) {
43 return 0.0;
44 }
45 }
46}
Note: See TracBrowser for help on using the repository browser.