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

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

Sonar - fix various issues

  • Property svn:eol-style set to native
File size: 1.7 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.tools;
3
4import java.io.File;
5import java.io.IOException;
6import java.net.MalformedURLException;
7import java.net.URL;
8
9import javax.sound.sampled.AudioFormat;
10import javax.sound.sampled.AudioInputStream;
11import javax.sound.sampled.AudioSystem;
12import javax.sound.sampled.UnsupportedAudioFileException;
13
14import org.openstreetmap.josm.Main;
15
16/**
17 * Utils functions for audio.
18 *
19 * @author David Earl <david@frankieandshadow.com>
20 * @since 1462
21 */
22public final class AudioUtil {
23
24 private AudioUtil() {
25 // Hide default constructor for utils classes
26 }
27
28 /**
29 * Returns calibrated length of recording in seconds.
30 * @param wavFile the recording file (WAV format)
31 * @return the calibrated length of recording in seconds.
32 */
33 public static double getCalibratedDuration(File wavFile) {
34 try {
35 AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(
36 new URL("file:".concat(wavFile.getAbsolutePath())));
37 AudioFormat audioFormat = audioInputStream.getFormat();
38 long filesize = wavFile.length();
39 double bytesPerSecond = audioFormat.getFrameRate() /* frames per second */
40 * audioFormat.getFrameSize() /* bytes per frame */;
41 double naturalLength = filesize / bytesPerSecond;
42 Utils.close(audioInputStream);
43 double calibration = Main.pref.getDouble("audio.calibration", 1.0 /* default, ratio */);
44 return naturalLength / calibration;
45 } catch (UnsupportedAudioFileException | IOException e) {
46 return 0.0;
47 }
48 }
49}
Note: See TracBrowser for help on using the repository browser.