source: trunk/src_apollo/org/apollo/util/AudioMath.java@ 315

Last change on this file since 315 was 315, checked in by bjn8, 16 years ago

Apollo spin-off added

File size: 985 bytes
Line 
1package org.apollo.util;
2
3import javax.sound.sampled.AudioFormat;
4
5/**
6 * Misc audio routines.
7 *
8 * @author Brook Novak
9 *
10 */
11public class AudioMath {
12 private AudioMath() {}
13
14 public static float volToDb(float volume) {
15 return (float) (Math.log(volume==0.0 ? 0.0001 : volume) / Math.log(10.0) * 20.0);
16 }
17
18 public static float dBToVol(float dB) {
19 return (float) Math.pow(10.0, dB / 20.0);
20 }
21
22 /**
23 *
24 * @param ms
25 * @param format
26 * @return How many frames are in the given ms time
27 */
28 public static int millisecondsToFrames(long ms, AudioFormat format) {
29 double portion = ms;
30 portion /= 1000.0;
31 return (int)(format.getFrameRate() * portion);
32 }
33
34 public static long framesToMilliseconds(long frames, AudioFormat format) {
35 double portion = frames;
36 portion /= (double)format.getFrameRate();
37 return (long)(portion * 1000.0);
38 }
39
40 public static int framesToSeconds(long frames, AudioFormat format) {
41 return (int)(frames / format.getFrameRate());
42 }
43}
Note: See TracBrowser for help on using the repository browser.