From 64755bbc5c44baf9317a31f19e7124f23a8e35b1 Mon Sep 17 00:00:00 2001 From: fd Date: Sat, 7 Mar 2015 19:45:56 -0500 Subject: [PATCH 1/2] Attempts to load music with incorrect file names. #33 --- src/org/newdawn/slick/openal/OpenALStreamPlayer.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/org/newdawn/slick/openal/OpenALStreamPlayer.java b/src/org/newdawn/slick/openal/OpenALStreamPlayer.java index ba9df8fa..6bad011d 100644 --- a/src/org/newdawn/slick/openal/OpenALStreamPlayer.java +++ b/src/org/newdawn/slick/openal/OpenALStreamPlayer.java @@ -149,6 +149,14 @@ public class OpenALStreamPlayer { audio = new Mp3InputStream(ResourceLoader.getResourceAsStream(ref)); else audio = new OggInputStream(ResourceLoader.getResourceAsStream(ref)); + + if(audio.getRate() == 0 && audio.getChannels() == 0) { + if (ref.toLowerCase().endsWith(".mp3")) + audio = new OggInputStream(ResourceLoader.getResourceAsStream(ref)); + else + audio = new Mp3InputStream(ResourceLoader.getResourceAsStream(ref)); + + } } this.audio = audio; From 421cfad6ad4693f438d9726800fedf366bd1c9d2 Mon Sep 17 00:00:00 2001 From: fd Date: Sat, 7 Mar 2015 20:54:16 -0500 Subject: [PATCH 2/2] Fixes some sliders with too much control points. --- .../opsu/objects/curves/Bezier2.java | 29 +++++++++++++------ .../opsu/objects/curves/Curve.java | 9 ------ 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/src/itdelatrisu/opsu/objects/curves/Bezier2.java b/src/itdelatrisu/opsu/objects/curves/Bezier2.java index e71a53aa..d7a60893 100644 --- a/src/itdelatrisu/opsu/objects/curves/Bezier2.java +++ b/src/itdelatrisu/opsu/objects/curves/Bezier2.java @@ -77,8 +77,9 @@ public class Bezier2 { Vec2f c = new Vec2f(); int n = points.length - 1; for (int i = 0; i <= n; i++) { - c.x += points[i].x * bernstein(i, n, t); - c.y += points[i].y * bernstein(i, n, t); + double b = bernstein(i, n, t); + c.x += points[i].x * b; + c.y += points[i].y * b; } return c; } @@ -102,14 +103,23 @@ public class Bezier2 { * Returns the total distances of this Bezier curve. */ public float totalDistance() { return totalDistance; } - + /** - * Calculates the factorial of a number. + * http://en.wikipedia.org/wiki/Binomial_coefficient#Binomial_coefficient_in_programming_languages + * */ - private static long factorial(int n) { - return (n <= 1 || n > 20) ? 1 : n * factorial(n - 1); + public static long binomialCoefficient(int n, int k) { + if (k < 0 || k > n) + return 0; + if (k == 0 || k == n) + return 1; + k = Math.min(k, n - k); // # take advantage of symmetry + long c = 1; + for (int i = 0; i < k; i++) { + c = c * (n - i) / (i + 1); + } + return c; } - /** * Calculates the Bernstein polynomial. * @param i the index @@ -117,7 +127,8 @@ public class Bezier2 { * @param t the t value [0, 1] */ private static double bernstein(int i, int n, float t) { - return factorial(n) / (factorial(i) * factorial(n - i)) * - Math.pow(t, i) * Math.pow(1 - t, n - i); + return binomialCoefficient(n, i) * Math.pow(t, i) * Math.pow(1 - t, n - i); } + + } diff --git a/src/itdelatrisu/opsu/objects/curves/Curve.java b/src/itdelatrisu/opsu/objects/curves/Curve.java index 1a593f40..65c22c3c 100644 --- a/src/itdelatrisu/opsu/objects/curves/Curve.java +++ b/src/itdelatrisu/opsu/objects/curves/Curve.java @@ -87,13 +87,4 @@ public abstract class Curve { return a * (1 - t) + b * t; } - /** - * A recursive method to evaluate polynomials in Bernstein form or Bezier curves. - * http://en.wikipedia.org/wiki/De_Casteljau%27s_algorithm - */ - protected float deCasteljau(float[] a, int i, int order, float t) { - if (order == 0) - return a[i]; - return lerp(deCasteljau(a, i, order - 1, t), deCasteljau(a, i + 1, order - 1, t), t); - } }