Re: [AD] [SCM] Allegro branch 5.1 updated. 5.1.3-21-g1a7e633 |
[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]
On Mon, 3 Sep 2012 00:33:13 +1000, Peter Wang <novalazy@xxxxxxxxxx> wrote: > On Sun, 2 Sep 2012 11:29:34 +0200, Evert Glebbeek <eglebbk@xxxxxxxxxx> wrote: > > > > The method is extremely simple, described in http://adsabs.harvard.edu/abs/1990A%26A...239..443S. Is this something that is worth looking into for Allegro? > > Yes, worth a shot. I can see the overshoots clearly with a sawtooth wave. > I'll try it tomorrow or so. I think I implemented it correctly, but it sounds really bad (worse than linear interpolation). Frequency plot attached. But perhaps you can have a look over the patch and see if I got it completely wrong. Peter
diff --git a/addons/audio/kcm_mixer.c b/addons/audio/kcm_mixer.c index 10c40a6..efe7290 100644 --- a/addons/audio/kcm_mixer.c +++ b/addons/audio/kcm_mixer.c @@ -242,6 +242,18 @@ static bool fix_looped_position(ALLEGRO_SAMPLE_INSTANCE *spl) } +static inline float sign(float x) +{ + return (x >= 0.0f) ? 1.0 : -1.0; +} + + +static inline float min3(float a, float b, float c) +{ + return fminf(a, fminf(b, c)); +} + + #include "kcm_mixer_helpers.inc" diff --git a/misc/make_mixer_helpers.py b/misc/make_mixer_helpers.py index 7fe717b..7c83da0 100755 --- a/misc/make_mixer_helpers.py +++ b/misc/make_mixer_helpers.py @@ -268,6 +268,7 @@ def make_cubic_interpolator(name, fmt): # Resampling of Oversampled Audio" by Olli Niemitalo # http://yehar.com/blog/?p=197 print interp("""\ + /* case #{depth.constant()}: { const float t = (float)spl->pos_bresenham_error / spl->step_denom; @@ -286,6 +287,40 @@ def make_cubic_interpolator(name, fmt): } } break; + */ + + case #{depth.constant()}: + { + const float t = (float)spl->pos_bresenham_error / spl->step_denom; + signed int i; + for (i = 0; i < (signed int)maxc; i++) { + float y0 = #{value0}; + float y1 = #{value1}; + float y2 = #{value2}; + float y3 = #{value3}; + + float h = 1; /* size of interval */ + float s0 = (y1 - y0)/h; + float s1 = (y2 - y1)/h; + float s2 = (y3 - y2)/h; + + float p1 = (s0*h + s1*h)/(h+h); + float p2 = (s1*h + s2*h)/(h+h); + + float yp1 = (sign(s0) + sign(s1)) * min3( fabsf(s0), fabsf(s1), 0.5*fabsf(p1) ); + float yp2 = (sign(s1) + sign(s2)) * min3( fabsf(s1), fabsf(s2), 0.5*fabsf(p2) ); + + float a1 = (yp1 + yp2 - 2*s1)/(h*h); + float b1 = (3*s1 - 2*yp1 - yp2)/h; + float c1 = yp1; + float d1 = y1; + + float f1 = a1*(t*t*t) + b1*(t*t) + c1*t + d1; + + samp_buf->f32[i] = f1; + } + } + break; """) print interp("""\
Attachment:
ss1.png
Description: PNG image
Mail converted by MHonArc 2.6.19+ | http://listengine.tuxfamily.org/ |