diff options
author | Rob Sykes <rob-Ideapad-S205> | 2013-10-04 10:52:50 +0400 |
---|---|---|
committer | Rob Sykes <rob-Ideapad-S205> | 2013-10-04 10:52:50 +0400 |
commit | 3c44f12164b3965c9016a03202ceac3edb45c9ef (patch) | |
tree | a0fc8ae48813fff194f621e518cc11a8d7643d4b | |
parent | 988f8303c7f30d0db5db3e15bf973e2bdf5c867e (diff) |
refactor: move vr-coefs to an include file (since they can be generated)
-rw-r--r-- | src/CMakeLists.txt | 15 | ||||
-rw-r--r-- | src/vr-coefs.c | 112 | ||||
-rw-r--r-- | src/vr-coefs.h | 91 | ||||
-rw-r--r-- | src/vr32.c | 129 |
4 files changed, 226 insertions, 121 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2a21156..56756bf 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,6 +1,21 @@ # SoX Resampler Library Copyright (c) 2007-13 robs@users.sourceforge.net # Licence for this file: LGPL v2.1 See LICENCE for details. + + +# Can generate vr-coefs.h but it complicates cross-compiling & non-cmake builds + +if (NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/vr-coefs.h) + include_directories(${CMAKE_CURRENT_BINARY_DIR}) + set_property(SOURCE vr32.c APPEND PROPERTY OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/vr-coefs.h) + add_executable (vr-coefs vr-coefs.c) + ADD_CUSTOM_COMMAND(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/vr-coefs.h + COMMAND vr-coefs > ${CMAKE_CURRENT_BINARY_DIR}/vr-coefs.h + DEPENDS vr-coefs) +endif () + + + add_definitions (${PROJECT_C_FLAGS} -DSOXR_LIB) diff --git a/src/vr-coefs.c b/src/vr-coefs.c new file mode 100644 index 0000000..d480aed --- /dev/null +++ b/src/vr-coefs.c @@ -0,0 +1,112 @@ +/* SoX Resampler Library Copyright (c) 2013 robs@users.sourceforge.net + * Licence for this file: LGPL v2.1 See LICENCE for details. */ + +/* Generate the filter coefficients for variable-rate resampling. */ + +#include <stdio.h> +#include <stdlib.h> +#include <math.h> +#define PI 3.14159265358979323846 /* Since M_PI can't be relied on */ + +static void print(double * h, int m, double l, char const * name) +{ /* Print out a filter: */ + int i, N = l? (int)(l*m)-(l>1) : m, R=(N+1)/2; + int a = !l||l>1? 0:N-R, b = l>1? R:N; + printf("static float const %s[] = {\n", name); + if (l>1) printf(" 0.f,"); else if (!l) l=1; + for (i=a; h && i<b; ++i, printf("% .9gf,%c",l*h[i-1],"\n "[(i-a)&3 && i<b])); + puts("};\n"); + free(h); +} + /* Parks McClellan FIR LPF: */ +#define even_adj(f) ((N&1)? 1 : cos(PI*.5*(f))) +#define W(f) (((f) < Fp+1e-9? weight : 1) * even_adj(f)) /* Weighting fn */ +#define D(f) (((f) < Fp+1e-9) / even_adj(f)) /* Desired response fn */ +#define F(i) ((i) <= end[0]? (i)*inc[0] : 1-(end[1]-(i))*inc[1]) +#define EE(x,z) (_1 != x 1 && x E[i] > 0 && x E[i] >= x E[i z 1]) +#define PEAK do {if (k<NP+1) peak[k]=i; ++k,_1=(E[i]>0)-(E[i]<0);} while (0) + +typedef struct {double x, beta, gamma;} coef_t; + +static double amp_response(coef_t * coef, int R, double f, int i) +{ + double n = 0, d = 0, x = cos(PI*f), t; + for (; i < R; d += t = coef[i].beta / t, n += coef[i].gamma * t, ++i) + if (fabs(t = x - coef[i].x) < 1e-9) return coef[i].gamma; + return n/d; +} + +static void fir(int m, double l, double Fp0, double Fs0, + double weight0, int density, char const * name) +{ + double Fp=Fp0/l, Fs=Fs0/l, weight=1/weight0, inc[2], Ws=1-Fs; + int N = (int)(l*m)-(l>1), R=(N+1)/2, NP=R+1, grid_size=1+density*R+1, pass=0; + int n1 = Ws>=(2*R-1)*Fp? 1:(int)(R*Fp/(Fp+Ws)+.5), n2=NP-n1, _1, i, j, k; + int * peak = malloc(sizeof(*peak) * (size_t)(NP+1)), * P=peak, end[2]; + coef_t * coef = malloc(sizeof(*coef) * (size_t)(NP)); + float * E = malloc(sizeof(*E ) * (size_t)(grid_size)); + double d, n, e, f, mult, delta, sum, hi, lo, * A = (double*)E, *h=0; + + if (!P || !coef || !E) goto END; + end[0] = n1 * density, end[1] = grid_size-1; /* Create prototype peaks: */ + inc[0] = Fp/end[0], inc[1] = n2==1? 0 : Ws / ((n2-1)*density); + for (i=0; i<n1; P[n1-1-i] = end[0] - i*density,++i); + for (i=0; i<n2; P[n1+i] = 1+end[0] + i*density,++i); + + do { /* Coefs for amp. resp.: */ + for (i = 0; i<NP; coef[i].x = cos(PI*F(P[i])), ++i); + for (_1=-1, n=d=i=0; i < NP; ++i) { + for (mult = 1, j = 0; j < R; ++j) if (j != i) mult *= coef[i].x-coef[j].x; + if (mult) coef[i].beta = 1/mult; else goto END; + if (i != R) mult *= coef[i].x - coef[R].x; + f = F(P[i]), n += D(f)/mult, d += (_1=-_1)/(W(f)*mult); + } + for (delta = n/d, _1 = -1, i = 0; i < R; ++i) + f = F(P[i]), coef[i].gamma = D(f)-(_1=-_1)*delta/W(f); + for (i = 0; i <= end[1]; ++i) /* Amplitude response and error: */ + f = F(i), E[i] = (float)(W(f)*(D(f) - amp_response(coef, R, f, 0))); + + i = k = _1 = 0; /* Find new peaks: */ + if (end[0]) if (EE(+,+) || EE(-,+)) PEAK; /* At F=0 */ + for (++i, j = 0; j < 2; ++j) { /* In band j: */ + for (; i < end[j]; ++i) + if ((EE(+,-) && E[i]>E[i+1]) || (EE(-,-) && E[i]<E[i+1])) PEAK; + if (!j) {PEAK; ++i; PEAK; ++i;} /* At Fp & Fs */ + } + if (i==end[1]) if (EE(+,-) || EE(-,-)) PEAK; /* At F=1 */ + if ((unsigned)(k = k-NP) > 1) goto END; /* Too many/few? */ + P = peak + k * (fabs(E[peak[0]]) < fabs(E[peak[NP]])); /* rm 1st? */ + + for (lo = hi = fabs(E[P[0]]), i=1; i<NP; ++i) /* Converged?: */ + e = fabs(E[P[i]]), lo = e<lo? e:lo, hi = e>hi? e:hi; + } while ((hi-lo)/hi > .001 && ++pass < 20); + /* Create impulse response from final amp. resp. coefs: */ + if (!(h = malloc(sizeof(*h)*(size_t)N))) goto END; + for (i = 0; i < R; f = 2.*i/N, A[i++] = amp_response(coef,R,f,0)*even_adj(f)); + for (i = 0; i < R; h[N-1-i] = h[i] = sum/N, ++i) + for (sum=*A, j=1; j<R; sum += 2*cos(2*PI*(i-(N-1)/2.)/N*j)*A[j], ++j); + END: free(coef), free(E), free(peak); + print(h, m, l, name); +} + /* Half-band IIR LPF (Mitra DSP 3/e, 13_9): */ +static void iir(int N, double Fp, char const * name) +{ + double d=tan(PI*.5*Fp), r=d*d, t=sqrt(1-r*r), n=(1-sqrt(t))/(1+sqrt(t))*.5; + double x=(n*n)*(n*n), Q=(((150*x+15)*x+2)*x+1)*n, q=pow(Q,.25), *h; + int i=0, j, _1; + if (!(h = malloc(sizeof(*h)*(size_t)N))) goto END; + for (; i<N; t=n*q/d, t=t*t, t=sqrt((1-t*r)*(1-t/r))/(1+t), h[i++]=(1-t)/(1+t)) + for (_1=1, d=-.5, n=j=0, x=(i+1)*PI/(N+.5); j<7; ++j, _1=-_1) + n += _1*pow(Q,j*(j+1))*sin(x*(j+.5)), d += _1*pow(Q,j*j)*cos(x*j); + END: print(h, N, 0, name); +} + +int main(int argc, char **argv) +{ + fir(241, 1, .45, .5, 160, 32, "half_fir_coefs"); + fir( 24, .5, .25, .5, 1, 31, "fast_half_fir_coefs"); + fir( 20, 12, .9 , 1.5, 160, 58, "coefs0_d"); + fir( 12, 6, .45, 1.5, 80, 29, "coefs0_u"); + iir( 15, .492, "iir_coefs"); + return 0*argc*!argv; +} diff --git a/src/vr-coefs.h b/src/vr-coefs.h new file mode 100644 index 0000000..9790ec0 --- /dev/null +++ b/src/vr-coefs.h @@ -0,0 +1,91 @@ +static float const half_fir_coefs[] = { + 0.471112154f, 0.316907549f, 0.0286963396f, -0.101927032f, +-0.0281272982f, 0.0568029535f, 0.027196876f, -0.0360795942f, +-0.0259313561f, 0.023641162f, 0.0243660538f, -0.0151238564f, +-0.0225440668f, 0.00886927471f, 0.0205146088f, -0.00411434209f, +-0.0183312132f, 0.000458525335f, 0.0160497772f, 0.00233248286f, +-0.0137265989f, -0.0044106884f, 0.011416442f, 0.005885487f, +-0.00917074467f, -0.00684373006f, 0.00703601669f, 0.00736018933f, +-0.00505250698f, -0.00750298261f, 0.00325317131f, 0.00733618346f, +-0.00166298445f, -0.00692082025f, 0.000298598848f, 0.00631493711f, + 0.000831644129f, -0.0055731438f, -0.00172737872f, 0.00474591812f, + 0.0023955814f, -0.0038788491f, -0.00284969263f, 0.00301194082f, + 0.00310854264f, -0.00217906496f, -0.00319514679f, 0.00140761062f, + 0.00313542959f, -0.000718361916f, -0.00295694328f, 0.000125607323f, + 0.00268763625f, 0.000362527878f, -0.00235472525f, -0.000743552559f, + 0.00198371228f, 0.00101991741f, -0.0015975797f, -0.00119820218f, + 0.00121618271f, 0.0012882279f, -0.000855849209f, -0.00130214036f, + 0.000529184474f, 0.00125350876f, -0.000245067778f, -0.00115647977f, + 8.82118676e-06f, 0.00102502052f, 0.000177478031f, -0.000872275256f, +-0.000314572995f, 0.000710055602f, 0.000405526007f, -0.000548470439f, +-0.000455174442f, 0.000395698685f, 0.000469579667f, -0.000257895884f, +-0.000455495078f, 0.000139222702f, 0.000419883982f, -4.19753541e-05f, +-0.00036950051f, -3.32020844e-05f, 0.000310554015f, 8.7050045e-05f, +-0.000248456595f, -0.000121389974f, 0.000187662656f, 0.000138813233f, +-0.000131587954f, -0.000142374865f, 8.26090549e-05f, 0.000135318039f, +-4.21208043e-05f, -0.000120830917f, 1.06505085e-05f, 0.00010185819f, + 1.20015129e-05f, -8.09558888e-05f, -2.65925299e-05f, 6.02101571e-05f, + 3.42775752e-05f, -4.11911155e-05f, -3.64462477e-05f, 2.49654252e-05f, + 3.46090513e-05f, -1.21078107e-05f, -3.03027209e-05f, 2.73562006e-06f, + 2.51329043e-05f, 3.66157998e-06f, -2.0990973e-05f, -9.38752332e-06f, + 2.07133365e-05f, 3.2060847e-05f, 1.98462364e-05f, 4.90328648e-06f, +-5.28550107e-07f, +}; + +static float const fast_half_fir_coefs[] = { + 0.309418476f, -0.0819805418f, 0.0305513441f, -0.0101582224f, + 0.00251293175f, -0.000346895324f, +}; + +static float const coefs0_d[] = { + 0.f, 1.40520362e-05f, 2.32939994e-05f, 4.00699869e-05f, 6.18938797e-05f, + 8.79406317e-05f, 0.000116304226f, 0.000143862785f, 0.000166286173f, + 0.000178229431f, 0.00017374107f, 0.00014689118f, 9.25928444e-05f, + 7.55567388e-06f, -0.000108723934f, -0.000253061416f, -0.000417917952f, +-0.000591117466f, -0.000756082504f, -0.000892686881f, -0.000978762367f, +-0.000992225841f, -0.00091370246f, -0.000729430325f, -0.000434153678f, +-3.36489703e-05f, 0.000453499646f, 0.000995243588f, 0.00154683724f, + 0.00205322353f, 0.00245307376f, 0.0026843294f, 0.0026908874f, + 0.00242986868f, 0.00187874742f, 0.00104150259f, -4.70759945e-05f, +-0.00131972748f, -0.00267834298f, -0.00399923407f, -0.00514205849f, +-0.00596200535f, -0.00632441105f, -0.00612058374f, -0.00528328869f, +-0.00380015804f, -0.0017232609f, 0.000826765169f, 0.0036632503f, + 0.00654337507f, 0.00918536843f, 0.0112922007f, 0.0125801323f, + 0.0128097433f, 0.0118164904f, 0.00953750551f, 0.00603133188f, + 0.00148762708f, -0.00377544588f, -0.009327395f, -0.014655127f, +-0.0192047839f, -0.0224328082f, -0.0238620596f, -0.0231377935f, +-0.0200777417f, -0.0147104883f, -0.00729690011f, 0.0016694689f, + 0.0114853672f, 0.02128446f, 0.0301054204f, 0.03697694f, + 0.0410129138f, 0.0415093321f, 0.0380333749f, 0.0304950299f, + 0.0191923285f, 0.00482304203f, -0.0115416941f, -0.0285230397f, +-0.0445368533f, -0.0579264573f, -0.0671158215f, -0.070770308f, +-0.0679502076f, -0.0582416438f, -0.0418501969f, -0.0196448429f, + 0.00685658762f, 0.0355644891f, 0.0639556622f, 0.0892653703f, + 0.108720484f, 0.11979613f, 0.120474745f, 0.109484562f, + 0.0864946948f, 0.0522461633f, 0.00860233712f, -0.041491734f, +-0.0941444939f, -0.144742955f, -0.188255118f, -0.219589829f, +-0.233988169f, -0.227416437f, -0.196929062f, -0.140970726f, +-0.0595905561f, 0.0454527813f, 0.170708227f, 0.311175511f, + 0.460568159f, 0.61168037f, 0.756833088f, 0.888367707f, + 0.999151395f, 1.08305644f, 1.13537741f, 1.15315438f, +}; + +static float const coefs0_u[] = { + 0.f, 2.4378013e-05f, 9.70782157e-05f, 0.000256572953f, 0.000527352928f, + 0.000890796838f, 0.00124949518f, 0.00140604793f, 0.00107945998f, +-2.15586031e-05f, -0.00206589462f, -0.00493342625f, -0.00807135101f, +-0.0104515787f, -0.0107039866f, -0.00746258988f, 0.000109078838f, + 0.0117345872f, 0.0255795186f, 0.0381690155f, 0.0448461522f, + 0.0408218138f, 0.0226797758f, -0.00999595371f, -0.0533441602f, +-0.0987927774f, -0.133827418f, -0.144042973f, -0.116198269f, +-0.0416493482f, 0.0806808506f, 0.242643854f, 0.427127981f, + 0.610413245f, 0.766259257f, 0.8708884f, 0.907742029f, +}; + +static float const iir_coefs[] = { + 0.0262852045f, 0.0998310478f, 0.206865061f, 0.330224134f, + 0.454420362f, 0.568578357f, 0.666944466f, 0.747869771f, + 0.812324404f, 0.8626001f, 0.901427744f, 0.931486057f, + 0.955191529f, 0.974661783f, 0.991776305f, +}; + @@ -17,6 +17,7 @@ #define FIFO_SIZE_T int #define FIFO_MIN 0x8000 #include "fifo.h" +#include "vr-coefs.h" #define FADE_LEN_BITS 9 #define PHASE_BITS_D (8 + PHASE_MORE) @@ -32,50 +33,6 @@ #define PHASES_D (1 << PHASE_BITS_D) #define PHASES_U (1 << PHASE_BITS_U) -static float const half_fir_coefs[] = { - 4.7111692735253413e-1f, 3.1690797657656167e-1f, 2.8691667164678896e-2f, - -1.0192825848403946e-1f, -2.8122856237424654e-2f, 5.6804928137780292e-2f, - 2.7192768359197508e-2f, -3.6082309197154230e-2f, -2.5927789156038026e-2f, - 2.3644444384060669e-2f, 2.4363075319345607e-2f, -1.5127630198606428e-2f, - -2.2541790286342567e-2f, 8.8733836742880233e-3f, 2.0513077413933017e-2f, - -4.1186431656279818e-3f, -1.8330444480421631e-2f, 4.6288071358217028e-4f, - 1.6049769308921290e-2f, 2.3282106680446069e-3f, -1.3727327353082214e-2f, - -4.4066375505196096e-3f, 1.1417847550661287e-2f, 5.8817724081355978e-3f, - -9.1727580349157123e-3f, -6.8404638339394346e-3f, 7.0385357033205332e-3f, - 7.3574525331962567e-3f, -5.0554197628506353e-3f, -7.5008330890673153e-3f, - 3.2563575907277676e-3f, 7.3346538206330259e-3f, -1.6663208501478607e-3f, - -6.9199171108861694e-3f, 3.0196567996023190e-4f, 6.3146436955438768e-3f, - 8.2835711466756098e-4f, -5.5734271982033918e-3f, -1.7242765658561860e-3f, - 4.7467223803576682e-3f, 2.3927523666941205e-3f, -3.8801054688632139e-3f, - -2.8472115748114728e-3f, 3.0135659731132642e-3f, 3.1064651802365259e-3f, - -2.1809660142807748e-3f, -3.1935061143485862e-3f, 1.4096923923208671e-3f, - 3.1342382222281609e-3f, -7.2053095076414931e-4f, -2.9561940489039682e-3f, - 1.2777585046118889e-4f, 2.6873033434313882e-3f, 3.6043554054680685e-4f, - -2.3547716396561816e-3f, -7.4160208709749312e-4f, 1.9840894915230177e-3f, - 1.0181606831615856e-3f, -1.5982325266851590e-3f, -1.1966774804490967e-3f, - 1.2170528733224913e-3f, 1.2869618709883193e-3f, -8.5687504489877664e-4f, - -1.3011452950496001e-3f, 5.3030588389885972e-4f, 1.2527854026453923e-3f, - -2.4622758430821288e-4f, -1.1560181289625195e-3f, 9.9661643910782316e-6f, - 1.0247989665318426e-3f, 1.7639297561664703e-4f, -8.7226452073196350e-4f, - -3.1358436147401782e-4f, 7.1022054657665971e-4f, 4.0466151692224986e-4f, - -5.4877022848030636e-4f, -4.5444807961399138e-4f, 3.9609542800868769e-4f, - 4.6899779918507020e-4f, -2.5835154936239735e-4f, -4.5505391611721792e-4f, - 1.3970512544147175e-4f, 4.1957352577882777e-4f, -4.2458993694471047e-5f, - -3.6930861782460262e-4f, -3.2738549063278822e-5f, 3.1046609224355927e-4f, - 8.6624679037202785e-5f, -2.4845427128026068e-4f, -1.2101300074995281e-4f, - 1.8773208187021294e-4f, 1.3849844077872591e-4f, -1.3170611080827864e-4f, - -1.4212373327156217e-4f, 8.2758595879431528e-5f, 1.3513059684140468e-4f, - -4.2284127775471251e-5f, -1.2070298779675768e-4f, 1.0811692847491609e-5f, - 1.0178008299781669e-4f, 1.1852545451857104e-5f, -8.0914539313342186e-5f, - -2.6454558961220653e-5f, 6.0208388858339534e-5f, 3.4169979203255580e-5f, - -4.1203296686185329e-5f, -3.6353143441156863e-5f, 2.4999186627094098e-5f, - 3.4542829080466582e-5f, -1.2148053427488782e-5f, -3.0260855999161159e-5f, - 2.7687092952335852e-6f, 2.5095689880235108e-5f, 3.6223160417538916e-6f, - -2.0960977068565079e-5f, -9.3312292092513232e-6f, 2.0711288605113663e-5f, - 3.1992093654438569e-5f, 1.9772538588596925e-5f, 4.8667740603532560e-6f, - -5.3495033191567977e-7f, -}; - #define CONVOLVE \ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \ @@ -119,25 +76,14 @@ static float double_fir1(float const * input) static float fast_half_fir(float const * input) { - static const float coefs[] = { - .3094188462713818f, -.08198144615199748f, .03055232105456833f, - -.01015890277986387f, .002513237297525149f, -.0003469672050347395f, - }; int i = 0; float sum = input[0] * .5f; -#define _ sum += (input[-(2*i+1)] + input[2*i+1]) * coefs[i], ++i; +#define _ sum += (input[-(2*i+1)] + input[2*i+1]) * fast_half_fir_coefs[i], ++i; _ _ _ _ _ _ #undef _ return (float)sum; } -static const float iir_coefs[] = { - .0262852045255816f, .0998310478296204f, .2068650611060755f, - .3302241336172489f, .4544203620946318f, .5685783569471244f, - .6669444657994612f, .7478697711807407f, .8123244036799226f, - .8626000999654434f, .9014277444199280f, .9314860567781748f, - .9551915287878752f, .9746617828910630f, .9917763050166036f, - }; #define IIR_FILTER _ _ _ _ _ _ _ #define _ in1=(in1-p->y[i])*iir_coefs[i]+tmp1;tmp1=p->y[i],p->y[i]=in1;++i;\ in0=(in0-p->y[i])*iir_coefs[i]+tmp0;tmp0=p->y[i],p->y[i]=in0;++i; @@ -175,77 +121,18 @@ static void half_phase(half_iir_t * p, float * buf, int len) #undef _ } -#define raw_coef_t float -static const raw_coef_t coefs0_d[POLY_FIR_LEN_D / 2 * PHASES0_D + 1] = { - 0.f, 1.4057457935754080e-5f, 2.3302768424632188e-5f, 4.0084897378442095e-5f, - 6.1916773126231636e-5f, 8.7973434034929016e-5f, 1.1634847507082481e-4f, - 1.4391931654629385e-4f, 1.6635470822160746e-4f, 1.7830838562749493e-4f, - 1.7382737311735053e-4f, 1.4698011689178234e-4f, 9.2677933545427018e-5f, - 7.6288745483685147e-6f, -1.0867156553965507e-4f, -2.5303924530322309e-4f, - -4.1793463959360433e-4f, -5.9118012513731508e-4f, -7.5619603440508576e-4f, - -8.9285245696990080e-4f, -9.7897684238178358e-4f, -9.9248131798952959e-4f, - -9.1398576537725926e-4f, -7.2972364732199553e-4f, -4.3443557115962946e-4f, - -3.3895523979487613e-5f, 4.5331297364457429e-4f, 9.9513966802111057e-4f, - 1.5468348913161652e-3f, 2.0533350794358640e-3f, 2.4533031436958950e-3f, - 2.6846707315385087e-3f, 2.6913237051575155e-3f, 2.4303724507982708e-3f, - 1.8792817173578587e-3f, 1.0420231121204950e-3f, -4.6617252898486750e-5f, - -1.3193786988492551e-3f, -2.6781478874181100e-3f, -3.9992272197487003e-3f, - -5.1422613336274056e-3f, -5.9624224517967755e-3f, -6.3250283969908542e-3f, - -6.1213677360236101e-3f, -5.2841872043022185e-3f, -3.8011036067186429e-3f, - -1.7241752288145494e-3f, 8.2596463599396213e-4f, 3.6626436307478369e-3f, - 6.5430316636724021e-3f, 9.1853404499045010e-3f, 1.1292516396583619e-2f, - 1.2580791345879052e-2f, 1.2810714562937180e-2f, 1.1817712330677889e-2f, - 9.5388893881204976e-3f, 6.0327678128662696e-3f, 1.4889921444742027e-3f, - -3.7742770128030593e-3f, -9.3265389310393538e-3f, -1.4654680466977541e-2f, - -1.9204813565928323e-2f, -2.2433342812570076e-2f, -2.3863084249865732e-2f, - -2.3139248817097825e-2f, -2.0079526147977360e-2f, -1.4712465100990968e-2f, - -7.2989072959128900e-3f, 1.6676055337427264e-3f, 1.1483818597217116e-2f, - 2.1283378291010333e-2f, 3.0104924254589629e-2f, 3.6977102234817580e-2f, - 4.1013752396638667e-2f, 4.1510805491867378e-2f, 3.8035383354576423e-2f, - 3.0497421566956902e-2f, 1.9194910514469185e-2f, 4.8255960959712636e-3f, - -1.1539393212932630e-2f, -2.8521204184392364e-2f, -4.4535662544571142e-2f, - -5.7926040870466614e-2f, -6.7116245375785713e-2f, -7.0771566186484461e-2f, - -6.7952220045636696e-2f, -5.8244261062898019e-2f, -4.1853211028450271e-2f, - -1.9648003905967236e-2f, 6.8535507014343263e-3f, 3.5561844452076982e-2f, - 6.3953651316164553e-2f, 8.9264185854578418e-2f, 1.0872025112127688e-1f, - 1.1979689474056175e-1f, 1.2047646491371326e-1f, 1.0948710929592399e-1f, - 8.6497869185231543e-2f, 5.2249701648862154e-2f, 8.6059406690018377e-3f, - -4.1488376792262582e-2f, -9.4141677945723271e-2f, -1.4474093381170536e-1f, - -1.8825408052888104e-1f, -2.1958987927558168e-1f, -2.3398931875783419e-1f, - -2.2741860176576378e-1f, -1.9693206642095332e-1f, -1.4097432039328661e-1f, - -5.9594435654526039e-2f, 4.5448949025739843e-2f, 1.7070477403312445e-1f, - 3.1117273816011837e-1f, 4.6056631075658744e-1f, 6.1167961235662682e-1f, - 7.5683349228721264e-1f, 8.8836924234920911e-1f, 9.9915393319190682e-1f, - 1.0830597619389459e+0f, 1.1353812335460003e+0f, 1.1531583819295732e+0f, -}; - -static const raw_coef_t coefs0_u[POLY_FIR_LEN_U / 2 * PHASES0_U + 1] = { - 0.f, 2.4376543962047211e-5f, 9.7074354091545404e-5f, 2.5656573977863553e-4f, - 5.2734092391248152e-4f, 8.9078135146855391e-4f, 1.2494786883827907e-3f, - 1.4060353542261659e-3f, 1.0794576035695273e-3f, -2.1547711862939183e-5f, - -2.0658693124381805e-3f, -4.9333908355966233e-3f, -8.0713165910440213e-3f, - -1.0451560117817383e-2f, -1.0703998868319438e-2f, -7.4626412699536097e-3f, - 1.0898921033926621e-4f, 1.1734475997741493e-2f, 2.5579413661660957e-2f, - 3.8168952738129619e-2f, 4.4846162998312754e-2f, 4.0821915377309274e-2f, - 2.2679961923658700e-2f, -9.9957152600624218e-3f, -5.3343924460223908e-2f, - -9.8792607573741240e-2f, -1.3382736970823086e-1f, -1.4404307655147228e-1f, - -1.1619851747063137e-1f, -4.1649695271274462e-2f, 8.0680482815468343e-2f, - 2.4264355486537642e-1f, 4.2712782955601925e-1f, 6.1041328492424185e-1f, - 7.6625948559498691e-1f, 8.7088876549652772e-1f, 9.0774244518772884e-1f, -}; - #define coef(coef_p, interp_order, fir_len, phase_num, coef_interp_num, \ fir_coef_num) coef_p[(fir_len) * ((interp_order) + 1) * (phase_num) + \ ((interp_order) + 1) * (fir_coef_num) + (interp_order - coef_interp_num)] #define COEF(h,l,i) ((i)<0||(i)>=(l)?0:(h)[(i)>(l)/2?(l)-(i):(i)]) static void prepare_coefs(float * coefs, int n, int phases0, int phases, - raw_coef_t const * coefs0, double multiplier) + float const * coefs0, double multiplier) { double k[6]; int length0 = n * phases0, length = n * phases, K0 = iAL(k)/2 - 1, i, j, pos; - raw_coef_t * coefs1 = malloc(((size_t)length / 2 + 1) * sizeof(*coefs1)); - raw_coef_t * p = coefs1, f0, f1 = 0; + float * coefs1 = malloc(((size_t)length / 2 + 1) * sizeof(*coefs1)); + float * p = coefs1, f0, f1 = 0; for (j = 0; j < iAL(k); k[j] = COEF(coefs0, length0, j - K0), ++j); for (pos = i = 0; i < length0 / 2; ++i) { @@ -254,18 +141,18 @@ static void prepare_coefs(float * coefs, int n, int phases0, int phases, double c=(1/12.)*(k[4]-k[0]-2*(k[3]-k[1])-60*a),e=.5*(k[3]-k[1])-a-c; for (; pos / phases == i; pos += phases0) { double x = (double)(pos % phases) / phases; - *p++ = (raw_coef_t)(k[K0] + ((((a*x + b)*x + c)*x + d)*x + e)*x); + *p++ = (float)(k[K0] + ((((a*x + b)*x + c)*x + d)*x + e)*x); } for (j = 0; j < iAL(k) - 1; k[j] = k[j + 1], ++j); k[j] = COEF(coefs0, length0, i + iAL(k) / 2 + 1); } if (!(length & 1)) - *p++ = (raw_coef_t)k[K0]; + *p++ = (float)k[K0]; assert(p - coefs1 == length / 2 + 1); for (i = 0; i < n; ++i) for (j = phases - 1; j >= 0; --j, f1 = f0) { pos = (n - 1 - i) * phases + j; - f0 = COEF(coefs1, length, pos) * (raw_coef_t)multiplier; + f0 = COEF(coefs1, length, pos) * (float)multiplier; coef(coefs, 1, n, j, 0, i) = (float)f0; coef(coefs, 1, n, j, 1, i) = (float)(f1 - f0); } |