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