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

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

update license/copyright information

  • Property svn:eol-style set to native
File size: 1.5 KB
RevLine 
[6380]1// License: GPL. For details, see LICENSE file.
[2512]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/**
[5871]14 * Utils functions for audio.
[2512]15 *
16 * @author David Earl <david@frankieandshadow.com>
[5871]17 * @since 1462
[2512]18 */
[6362]19public final class AudioUtil {
[6070]20
[6362]21 private AudioUtil() {
22 // Hide default constructor for utils classes
23 }
24
[5871]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 */
[2512]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;
[5874]39 Utils.close(audioInputStream);
[5871]40 double calibration = Main.pref.getDouble("audio.calibration", 1.0 /* default, ratio */);
[2512]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.