Chris@2
|
1 /*
|
Chris@2
|
2 Copyright (C) 2001, 2006 by Simon Dixon
|
Chris@2
|
3
|
Chris@2
|
4 This program is free software; you can redistribute it and/or modify
|
Chris@2
|
5 it under the terms of the GNU General Public License as published by
|
Chris@2
|
6 the Free Software Foundation; either version 2 of the License, or
|
Chris@2
|
7 (at your option) any later version.
|
Chris@2
|
8
|
Chris@2
|
9 This program is distributed in the hope that it will be useful,
|
Chris@2
|
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
|
Chris@2
|
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
Chris@2
|
12 GNU General Public License for more details.
|
Chris@2
|
13
|
Chris@2
|
14 You should have received a copy of the GNU General Public License along
|
Chris@2
|
15 with this program (the file gpl.txt); if not, download it from
|
Chris@2
|
16 http://www.gnu.org/licenses/gpl.txt or write to the
|
Chris@2
|
17 Free Software Foundation, Inc.,
|
Chris@2
|
18 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
Chris@2
|
19 */
|
Chris@2
|
20
|
Chris@2
|
21 package at.ofai.music.audio;
|
Chris@2
|
22
|
Chris@2
|
23 public class Util {
|
Chris@2
|
24
|
Chris@2
|
25 public static double rms(double[] d) {
|
Chris@2
|
26 double sum = 0;
|
Chris@2
|
27 for (int i=0; i < d.length; i++)
|
Chris@2
|
28 sum += d[i] * d[i];
|
Chris@2
|
29 return Math.sqrt(sum / d.length);
|
Chris@2
|
30 }
|
Chris@2
|
31
|
Chris@2
|
32 public static double min(double[] d) {
|
Chris@2
|
33 double min = d[0];
|
Chris@2
|
34 for (int i=1; i < d.length; i++)
|
Chris@2
|
35 if (d[i] < min)
|
Chris@2
|
36 min = d[i];
|
Chris@2
|
37 return min;
|
Chris@2
|
38 }
|
Chris@2
|
39
|
Chris@2
|
40 public static double max(double[] d) {
|
Chris@2
|
41 double max = d[0];
|
Chris@2
|
42 for (int i=1; i < d.length; i++)
|
Chris@2
|
43 if (d[i] > max)
|
Chris@2
|
44 max = d[i];
|
Chris@2
|
45 return max;
|
Chris@2
|
46 }
|
Chris@2
|
47
|
Chris@2
|
48 public static double threshold(double value, double min, double max) {
|
Chris@2
|
49 if (value < min)
|
Chris@2
|
50 return min;
|
Chris@2
|
51 if (value > max)
|
Chris@2
|
52 return max;
|
Chris@2
|
53 return value;
|
Chris@2
|
54 }
|
Chris@2
|
55
|
Chris@2
|
56 } // class Util
|