From: WiESi <wi...@us...> - 2006-03-07 16:13:24
|
Update of /cvsroot/javaamp/javaamp/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21548/src Modified Files: EQLabel.java FileInformationDialog.java SongInfoLabel.java Added Files: Spline.java Log Message: Splines, ... Index: EQLabel.java =================================================================== RCS file: /cvsroot/javaamp/javaamp/src/EQLabel.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- EQLabel.java 28 Feb 2006 16:08:13 -0000 1.7 +++ EQLabel.java 7 Mar 2006 16:13:17 -0000 1.8 @@ -54,12 +54,17 @@ offg.setColor(Color.LIGHT_GRAY); offg.fillRect(0, 63 - owner.equalizerDialog.sliPre.getValue(), 239, 3); offg.setColor(Color.BLACK); + double[] xx = new double[10]; + double[] ff = new double[10]; for(int i = 0; i < 10; i++) { offg.fillRect(i * 24 + 10, owner.equalizerDialog.eqvals[i], 3, 3); - if(i < 9) - offg.drawLine(i * 24 + 11, 1 + owner.equalizerDialog.eqvals[i], - (i + 1) * 24 + 11, 1 + owner.equalizerDialog.eqvals[i + 1]); + xx[i] = i * 24 + 11; + ff[i] = owner.equalizerDialog.eqvals[i] + 1; } + Spline s = new Spline(xx, ff); + for(int i = 11; i < 227; i++) + offg.drawLine(i, (int)s.spline_value(i), i + 1, (int)s.spline_value( + i + 1)); g.drawImage(offscreen, 0, 0, this); } } \ No newline at end of file Index: FileInformationDialog.java =================================================================== RCS file: /cvsroot/javaamp/javaamp/src/FileInformationDialog.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- FileInformationDialog.java 4 Mar 2006 10:01:12 -0000 1.7 +++ FileInformationDialog.java 7 Mar 2006 16:13:18 -0000 1.8 @@ -146,7 +146,7 @@ return false; } - public int getIDfromType(int type) { + private int getIDfromType(int type) { for(int i = 0; i < types.length; i++) if(types[i] == type) return i; --- NEW FILE: Spline.java --- /* AUTHORS: Lawrence Shampine, Richard Allen, Steven Pruess for the text Fundamentals of Numerical Computing DATE: February 27, 1996 minimal change convertion to Java August 11, 2003 Modified and standardized by Andreas Wiesbauer, March 2006. */ import java.text.*; public class Spline { int n, last_interval; double x[], f[], b[], c[], d[]; boolean uniform; public Spline(double xx[], double ff[]) { // Calculate coefficients defining a smooth cubic interpolatory spline. // // Input parameters: // xx = vector of values of the independent variable ordered so that // x[i] < x[i + 1] for all i. // ff = vector of values of the dependent variable. // Class values constructed: // n = number of data points. // b = vector of S'(x[i]) values. // c = vector of S''(x[i]) / 2 values. // d = vector of S'''(x[i]) / 6 values (i < n). // x = xx // f = ff double fp1, fpn, h, p; DecimalFormat f1 = new DecimalFormat("00.00000"); boolean sorted = true; uniform = true; last_interval = 0; n = xx.length; if(n <= 3) throw new RuntimeException("Not enough points to build spline, n=" + n); if(n != ff.length) throw new RuntimeException("Not same number of x and f(x)"); x = new double[n]; f = new double[n]; b = new double[n]; c = new double[n]; d = new double[n]; for(int i = 0; i < n; i++) { x[i] = xx[i]; f[i] = ff[i]; if(i >= 1 && x[i] < x[i - 1]) sorted = false; } // Sort if necessary if(!sorted) dHeapSort(x, f); // Calculate coefficients for the tri-diagonal system: store // sub-diagonal in b, diagonal in d, difference quotient in c. b[0] = x[1] - x[0]; c[0] = (f[1] - f[0]) / b[0]; if(n == 2) { b[0] = c[0]; c[0] = 0.0; d[0] = 0.0; b[1] = b[0]; c[1] = 0.0; return; } d[0] = 2.0 * b[0]; for(int i = 1; i < n - 1; i++) { b[i] = x[i + 1] - x[i]; if(Math.abs(b[i] - b[0]) / b[0] > 1.0E-5) uniform = false; c[i] = (f[i + 1] - f[i]) / b[i]; d[i] = 2.0 * (b[i] + b[i - 1]); } d[n - 1] = 2.0 * b[n - 2]; // Calculate estimates for the end slopes. Use polynomials // interpolating data nearest the end. fp1 = c[0] - b[0] * (c[1] - c[0]) / (b[0] + b[1]); if(n > 3) fp1 = fp1 + b[0] * ((b[0] + b[1]) * (c[2] - c[1]) / (b[1] + b[2]) - c[1] + c[0]) / (x[3] - x[0]); fpn = c[n - 2] + b[n - 2] * (c[n - 2] - c[n - 3]) / (b[n - 3] + b [n - 2]); if(n > 3) fpn = fpn + b[n - 2] * (c[n - 2] - c[n - 3] - (b[n - 3] + b[n - 2]) * (c[n - 3] - c[n - 4]) / (b[n - 3] + b[n - 4])) / (x[n - 1] - x[n - 4]); // Calculate the right-hand-side and store it in c. c[n - 1] = 3.0 * (fpn - c[n - 2]); for(int i = n - 2; i > 0; i--) c[i] = 3.0 * (c[i] - c[i - 1]); c[0] = 3.0 * (c[0] - fp1); // Solve the tridiagonal system. for(int k = 1; k < n; k++) { p = b[k - 1] / d[k - 1]; d[k] = d[k] - p * b[k - 1]; c[k] = c[k] - p * c[k - 1]; } c[n - 1] = c[n - 1] / d[n - 1]; for(int k = n - 2; k >= 0; k--) c[k] = (c[k] - b[k] * c[k + 1]) / d[k]; // Calculate the coefficients defining the spline. h = x[1] - x[0]; for(int i = 0; i < n - 1; i++) { h = x[i + 1] - x[i]; d[i] = (c[i + 1] - c[i]) / (3.0 * h); b[i] = (f[i + 1] - f[i]) / h - h * (c[i] + h * d[i]); } b[n - 1] = b[n - 2] + h * (2.0 * c[n - 2] + h * 3.0 * d[n - 2]); } public double spline_value(double t) { // Evaluate the spline s at t using coefficients from Spline constructor // // Input parameters // Class variables // t = point where spline is to be evaluated. // Output: // s = value of spline at t. double dt, s; int interval; // Index such that t >= x[interval] and // t < x[interval + 1] if(n <= 1) throw new RuntimeException("Not enough points to compute value"); // Search for correct interval for t. interval = last_interval; // Heuristic if(t < x[0]) throw new RuntimeException("Requested point below Spline region"); if(t > x[n - 1]) throw new RuntimeException("Requested point above Spline region"); if(t > x[n - 2]) interval = n-2; else if (t >= x[last_interval]) for(int j = last_interval; j < n && t >= x[j]; j++) interval = j; else for(int j = last_interval; t < x[j]; j--) interval = j - 1; last_interval = interval; // Class variable for next call // Evaluate cubic polynomial on [x[interval], x[interval+1]]. dt = t - x[interval]; s = f[interval] + dt * (b[interval] + dt * (c[interval] + dt * d[interval])); return s; } public double integrate() { double suma, sumb, sumc, sumd; double dx, t; if(n <= 3) throw new RuntimeException("Not enough data to integrate"); if(!uniform) { t = 0.0; for(int i = 0; i < n - 1; i++) { dx = x[i + 1] - x[i]; t = t + (f[i] + (b[i] / 2.0 + (c[i] / 3.0 + dx * d[i] / 4.0) * dx) * dx) * dx; } return t; } // Compute uniform integral of spline fit suma = sumb = sumc = sumd = 0.0; for(int i = 0; i < n; i++) { suma = suma + d[i]; sumb = sumb + c[i]; sumc = sumc + b[i]; sumd = sumd + f[i]; } dx = x[1] - x[0]; // Assumes equally spaced points return (sumd + (sumc / 2.0 + (sumb / 3.0 + dx * suma / 4.0) * dx) * dx) * dx; } private final static void dHeapSort(double key[], double trail[]) { int nkey = key.length; int last_parent_pos = (nkey - 2) / 2; int last_parent_index = last_parent_pos; double tkey, ttrail; if(nkey <= 1) return; for(int i = last_parent_index; i >= 0; i--) dremake_heap(key, trail, i, nkey - 1); tkey = key [ 0]; key [ 0] = key [nkey - 1]; key [nkey - 1] = tkey; ttrail = trail[ 0]; trail[ 0] = trail[nkey - 1]; trail[nkey - 1] = ttrail; for(int i = nkey - 2; i > 0; i--) { dremake_heap(key, trail, 0, i); tkey = key[0]; key [0] = key [i]; key [i] = tkey; ttrail = trail[0]; trail [0] = trail[i]; trail [i] = ttrail; } } private final static void dremake_heap(double key[], double trail[], int parent_index, int last_index) { int last_parent_pos = (last_index - 1) / 2; int last_parent_index = last_parent_pos; int l_child, r_child, max_child_index; int parent_temp = parent_index; double tkey, ttrail; while(parent_temp <= last_parent_index) { l_child = parent_temp * 2 + 1; if(l_child == last_index) max_child_index = l_child; else { r_child = l_child + 1; max_child_index = key[l_child] > key[r_child] ? l_child : r_child; } if(key[max_child_index] > key[parent_temp]) { tkey = key[max_child_index]; key[max_child_index] = key[parent_temp]; key[parent_temp] = tkey; ttrail = trail[max_child_index]; trail[max_child_index] = trail[parent_temp]; trail[parent_temp] = ttrail; parent_temp = max_child_index; } else break; } } } Index: SongInfoLabel.java =================================================================== RCS file: /cvsroot/javaamp/javaamp/src/SongInfoLabel.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- SongInfoLabel.java 4 Mar 2006 16:56:00 -0000 1.6 +++ SongInfoLabel.java 7 Mar 2006 16:13:18 -0000 1.7 @@ -24,7 +24,7 @@ xt = 4; text2 = ""; - setText("JavaAmp"); + setText("JavaAmp 0.0.4"); setBorder(new BevelBorder(BevelBorder.LOWERED)); setFont(new Font("Dialog", Font.PLAIN, 10)); setCursor(Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR)); |