flac_lpc.c 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378
  1. /* libFLAC - Free Lossless Audio Codec library
  2. * Copyright (C) 2000,2001,2002,2003,2004,2005,2006,2007 Josh Coalson
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. *
  8. * - Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. *
  11. * - Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. *
  15. * - Neither the name of the Xiph.org Foundation nor the names of its
  16. * contributors may be used to endorse or promote products derived from
  17. * this software without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  20. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  22. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
  23. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  24. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  25. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  26. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  27. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  28. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  29. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30. */
  31. #if HAVE_CONFIG_H
  32. # include <config.h>
  33. #endif
  34. #include <math.h>
  35. #include "flac_FLAC_assert.h"
  36. #include "flac_FLAC_format.h"
  37. #include "flac_private_bitmath.h"
  38. #include "flac_private_lpc.h"
  39. #if defined DEBUG || defined FLAC__OVERFLOW_DETECT || defined FLAC__OVERFLOW_DETECT_VERBOSE
  40. #include <stdio.h>
  41. #endif
  42. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  43. #ifndef M_LN2
  44. /* math.h in VC++ doesn't seem to have this (how Microsoft is that?) */
  45. #define M_LN2 0.69314718055994530942
  46. #endif
  47. /* OPT: #undef'ing this may improve the speed on some architectures */
  48. #define FLAC__LPC_UNROLLED_FILTER_LOOPS
  49. void FLAC__lpc_window_data(const FLAC__int32 in[], const FLAC__real window[], FLAC__real out[], unsigned data_len)
  50. {
  51. unsigned i;
  52. for(i = 0; i < data_len; i++)
  53. out[i] = in[i] * window[i];
  54. }
  55. void FLAC__lpc_compute_autocorrelation(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[])
  56. {
  57. /* a readable, but slower, version */
  58. #if 0
  59. FLAC__real d;
  60. unsigned i;
  61. FLAC__ASSERT(lag > 0);
  62. FLAC__ASSERT(lag <= data_len);
  63. /*
  64. * Technically we should subtract the mean first like so:
  65. * for(i = 0; i < data_len; i++)
  66. * data[i] -= mean;
  67. * but it appears not to make enough of a difference to matter, and
  68. * most signals are already closely centered around zero
  69. */
  70. while(lag--) {
  71. for(i = lag, d = 0.0; i < data_len; i++)
  72. d += data[i] * data[i - lag];
  73. autoc[lag] = d;
  74. }
  75. #endif
  76. /*
  77. * this version tends to run faster because of better data locality
  78. * ('data_len' is usually much larger than 'lag')
  79. */
  80. FLAC__real d;
  81. unsigned sample, coeff;
  82. const unsigned limit = data_len - lag;
  83. FLAC__ASSERT(lag > 0);
  84. FLAC__ASSERT(lag <= data_len);
  85. for(coeff = 0; coeff < lag; coeff++)
  86. autoc[coeff] = 0.0;
  87. for(sample = 0; sample <= limit; sample++) {
  88. d = data[sample];
  89. for(coeff = 0; coeff < lag; coeff++)
  90. autoc[coeff] += d * data[sample+coeff];
  91. }
  92. for(; sample < data_len; sample++) {
  93. d = data[sample];
  94. for(coeff = 0; coeff < data_len - sample; coeff++)
  95. autoc[coeff] += d * data[sample+coeff];
  96. }
  97. }
  98. void FLAC__lpc_compute_lp_coefficients(const FLAC__real autoc[], unsigned *max_order, FLAC__real lp_coeff[][FLAC__MAX_LPC_ORDER], FLAC__double error[])
  99. {
  100. unsigned i, j;
  101. FLAC__double r, err, ref[FLAC__MAX_LPC_ORDER], lpc[FLAC__MAX_LPC_ORDER];
  102. FLAC__ASSERT(0 != max_order);
  103. FLAC__ASSERT(0 < *max_order);
  104. FLAC__ASSERT(*max_order <= FLAC__MAX_LPC_ORDER);
  105. FLAC__ASSERT(autoc[0] != 0.0);
  106. err = autoc[0];
  107. for(i = 0; i < *max_order; i++) {
  108. /* Sum up this iteration's reflection coefficient. */
  109. r = -autoc[i+1];
  110. for(j = 0; j < i; j++)
  111. r -= lpc[j] * autoc[i-j];
  112. ref[i] = (r/=err);
  113. /* Update LPC coefficients and total error. */
  114. lpc[i]=r;
  115. for(j = 0; j < (i>>1); j++) {
  116. FLAC__double tmp = lpc[j];
  117. lpc[j] += r * lpc[i-1-j];
  118. lpc[i-1-j] += r * tmp;
  119. }
  120. if(i & 1)
  121. lpc[j] += lpc[j] * r;
  122. err *= (1.0 - r * r);
  123. /* save this order */
  124. for(j = 0; j <= i; j++)
  125. lp_coeff[i][j] = (FLAC__real)(-lpc[j]); /* negate FIR filter coeff to get predictor coeff */
  126. error[i] = err;
  127. /* see SF bug #1601812 http://sourceforge.net/tracker/index.php?func=detail&aid=1601812&group_id=13478&atid=113478 */
  128. if(err == 0.0) {
  129. *max_order = i+1;
  130. return;
  131. }
  132. }
  133. }
  134. int FLAC__lpc_quantize_coefficients(const FLAC__real lp_coeff[], unsigned order, unsigned precision, FLAC__int32 qlp_coeff[], int *shift)
  135. {
  136. unsigned i;
  137. FLAC__double cmax;
  138. FLAC__int32 qmax, qmin;
  139. FLAC__ASSERT(precision > 0);
  140. FLAC__ASSERT(precision >= FLAC__MIN_QLP_COEFF_PRECISION);
  141. /* drop one bit for the sign; from here on out we consider only |lp_coeff[i]| */
  142. precision--;
  143. qmax = 1 << precision;
  144. qmin = -qmax;
  145. qmax--;
  146. /* calc cmax = max( |lp_coeff[i]| ) */
  147. cmax = 0.0;
  148. for(i = 0; i < order; i++) {
  149. const FLAC__double d = fabs(lp_coeff[i]);
  150. if(d > cmax)
  151. cmax = d;
  152. }
  153. if(cmax <= 0.0) {
  154. /* => coefficients are all 0, which means our constant-detect didn't work */
  155. return 2;
  156. }
  157. else {
  158. const int max_shiftlimit = (1 << (FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN-1)) - 1;
  159. const int min_shiftlimit = -max_shiftlimit - 1;
  160. int log2cmax;
  161. (void)frexp(cmax, &log2cmax);
  162. log2cmax--;
  163. *shift = (int)precision - log2cmax - 1;
  164. if(*shift > max_shiftlimit)
  165. *shift = max_shiftlimit;
  166. else if(*shift < min_shiftlimit)
  167. return 1;
  168. }
  169. if(*shift >= 0) {
  170. FLAC__double error = 0.0;
  171. FLAC__int32 q;
  172. for(i = 0; i < order; i++) {
  173. error += lp_coeff[i] * (1 << *shift);
  174. #if 1 /* unfortunately lround() is C99 */
  175. if(error >= 0.0)
  176. q = (FLAC__int32)(error + 0.5);
  177. else
  178. q = (FLAC__int32)(error - 0.5);
  179. #else
  180. q = lround(error);
  181. #endif
  182. #ifdef FLAC__OVERFLOW_DETECT
  183. if(q > qmax+1) /* we expect q==qmax+1 occasionally due to rounding */
  184. fprintf(stderr,"FLAC__lpc_quantize_coefficients: quantizer overflow: q>qmax %d>%d shift=%d cmax=%f precision=%u lpc[%u]=%f\n",q,qmax,*shift,cmax,precision+1,i,lp_coeff[i]);
  185. else if(q < qmin)
  186. fprintf(stderr,"FLAC__lpc_quantize_coefficients: quantizer overflow: q<qmin %d<%d shift=%d cmax=%f precision=%u lpc[%u]=%f\n",q,qmin,*shift,cmax,precision+1,i,lp_coeff[i]);
  187. #endif
  188. if(q > qmax)
  189. q = qmax;
  190. else if(q < qmin)
  191. q = qmin;
  192. error -= q;
  193. qlp_coeff[i] = q;
  194. }
  195. }
  196. /* negative shift is very rare but due to design flaw, negative shift is
  197. * a NOP in the decoder, so it must be handled specially by scaling down
  198. * coeffs
  199. */
  200. else {
  201. const int nshift = -(*shift);
  202. FLAC__double error = 0.0;
  203. FLAC__int32 q;
  204. #ifdef DEBUG
  205. fprintf(stderr,"FLAC__lpc_quantize_coefficients: negative shift=%d order=%u cmax=%f\n", *shift, order, cmax);
  206. #endif
  207. for(i = 0; i < order; i++) {
  208. error += lp_coeff[i] / (1 << nshift);
  209. #if 1 /* unfortunately lround() is C99 */
  210. if(error >= 0.0)
  211. q = (FLAC__int32)(error + 0.5);
  212. else
  213. q = (FLAC__int32)(error - 0.5);
  214. #else
  215. q = lround(error);
  216. #endif
  217. #ifdef FLAC__OVERFLOW_DETECT
  218. if(q > qmax+1) /* we expect q==qmax+1 occasionally due to rounding */
  219. fprintf(stderr,"FLAC__lpc_quantize_coefficients: quantizer overflow: q>qmax %d>%d shift=%d cmax=%f precision=%u lpc[%u]=%f\n",q,qmax,*shift,cmax,precision+1,i,lp_coeff[i]);
  220. else if(q < qmin)
  221. fprintf(stderr,"FLAC__lpc_quantize_coefficients: quantizer overflow: q<qmin %d<%d shift=%d cmax=%f precision=%u lpc[%u]=%f\n",q,qmin,*shift,cmax,precision+1,i,lp_coeff[i]);
  222. #endif
  223. if(q > qmax)
  224. q = qmax;
  225. else if(q < qmin)
  226. q = qmin;
  227. error -= q;
  228. qlp_coeff[i] = q;
  229. }
  230. *shift = 0;
  231. }
  232. return 0;
  233. }
  234. void FLAC__lpc_compute_residual_from_qlp_coefficients(const FLAC__int32 *data, unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 residual[])
  235. #if defined(FLAC__OVERFLOW_DETECT) || !defined(FLAC__LPC_UNROLLED_FILTER_LOOPS)
  236. {
  237. FLAC__int64 sumo;
  238. unsigned i, j;
  239. FLAC__int32 sum;
  240. const FLAC__int32 *history;
  241. #ifdef FLAC__OVERFLOW_DETECT_VERBOSE
  242. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients: data_len=%d, order=%u, lpq=%d",data_len,order,lp_quantization);
  243. for(i=0;i<order;i++)
  244. fprintf(stderr,", q[%u]=%d",i,qlp_coeff[i]);
  245. fprintf(stderr,"\n");
  246. #endif
  247. FLAC__ASSERT(order > 0);
  248. for(i = 0; i < data_len; i++) {
  249. sumo = 0;
  250. sum = 0;
  251. history = data;
  252. for(j = 0; j < order; j++) {
  253. sum += qlp_coeff[j] * (*(--history));
  254. sumo += (FLAC__int64)qlp_coeff[j] * (FLAC__int64)(*history);
  255. #if defined _MSC_VER
  256. if(sumo > 2147483647I64 || sumo < -2147483648I64)
  257. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients: OVERFLOW, i=%u, j=%u, c=%d, d=%d, sumo=%I64d\n",i,j,qlp_coeff[j],*history,sumo);
  258. #else
  259. if(sumo > 2147483647ll || sumo < -2147483648ll)
  260. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients: OVERFLOW, i=%u, j=%u, c=%d, d=%d, sumo=%lld\n",i,j,qlp_coeff[j],*history,(long long)sumo);
  261. #endif
  262. }
  263. *(residual++) = *(data++) - (sum >> lp_quantization);
  264. }
  265. /* Here's a slower but clearer version:
  266. for(i = 0; i < data_len; i++) {
  267. sum = 0;
  268. for(j = 0; j < order; j++)
  269. sum += qlp_coeff[j] * data[i-j-1];
  270. residual[i] = data[i] - (sum >> lp_quantization);
  271. }
  272. */
  273. }
  274. #else /* fully unrolled version for normal use */
  275. {
  276. int i;
  277. FLAC__int32 sum;
  278. FLAC__ASSERT(order > 0);
  279. FLAC__ASSERT(order <= 32);
  280. /*
  281. * We do unique versions up to 12th order since that's the subset limit.
  282. * Also they are roughly ordered to match frequency of occurrence to
  283. * minimize branching.
  284. */
  285. if(order <= 12) {
  286. if(order > 8) {
  287. if(order > 10) {
  288. if(order == 12) {
  289. for(i = 0; i < (int)data_len; i++) {
  290. sum = 0;
  291. sum += qlp_coeff[11] * data[i-12];
  292. sum += qlp_coeff[10] * data[i-11];
  293. sum += qlp_coeff[9] * data[i-10];
  294. sum += qlp_coeff[8] * data[i-9];
  295. sum += qlp_coeff[7] * data[i-8];
  296. sum += qlp_coeff[6] * data[i-7];
  297. sum += qlp_coeff[5] * data[i-6];
  298. sum += qlp_coeff[4] * data[i-5];
  299. sum += qlp_coeff[3] * data[i-4];
  300. sum += qlp_coeff[2] * data[i-3];
  301. sum += qlp_coeff[1] * data[i-2];
  302. sum += qlp_coeff[0] * data[i-1];
  303. residual[i] = data[i] - (sum >> lp_quantization);
  304. }
  305. }
  306. else { /* order == 11 */
  307. for(i = 0; i < (int)data_len; i++) {
  308. sum = 0;
  309. sum += qlp_coeff[10] * data[i-11];
  310. sum += qlp_coeff[9] * data[i-10];
  311. sum += qlp_coeff[8] * data[i-9];
  312. sum += qlp_coeff[7] * data[i-8];
  313. sum += qlp_coeff[6] * data[i-7];
  314. sum += qlp_coeff[5] * data[i-6];
  315. sum += qlp_coeff[4] * data[i-5];
  316. sum += qlp_coeff[3] * data[i-4];
  317. sum += qlp_coeff[2] * data[i-3];
  318. sum += qlp_coeff[1] * data[i-2];
  319. sum += qlp_coeff[0] * data[i-1];
  320. residual[i] = data[i] - (sum >> lp_quantization);
  321. }
  322. }
  323. }
  324. else {
  325. if(order == 10) {
  326. for(i = 0; i < (int)data_len; i++) {
  327. sum = 0;
  328. sum += qlp_coeff[9] * data[i-10];
  329. sum += qlp_coeff[8] * data[i-9];
  330. sum += qlp_coeff[7] * data[i-8];
  331. sum += qlp_coeff[6] * data[i-7];
  332. sum += qlp_coeff[5] * data[i-6];
  333. sum += qlp_coeff[4] * data[i-5];
  334. sum += qlp_coeff[3] * data[i-4];
  335. sum += qlp_coeff[2] * data[i-3];
  336. sum += qlp_coeff[1] * data[i-2];
  337. sum += qlp_coeff[0] * data[i-1];
  338. residual[i] = data[i] - (sum >> lp_quantization);
  339. }
  340. }
  341. else { /* order == 9 */
  342. for(i = 0; i < (int)data_len; i++) {
  343. sum = 0;
  344. sum += qlp_coeff[8] * data[i-9];
  345. sum += qlp_coeff[7] * data[i-8];
  346. sum += qlp_coeff[6] * data[i-7];
  347. sum += qlp_coeff[5] * data[i-6];
  348. sum += qlp_coeff[4] * data[i-5];
  349. sum += qlp_coeff[3] * data[i-4];
  350. sum += qlp_coeff[2] * data[i-3];
  351. sum += qlp_coeff[1] * data[i-2];
  352. sum += qlp_coeff[0] * data[i-1];
  353. residual[i] = data[i] - (sum >> lp_quantization);
  354. }
  355. }
  356. }
  357. }
  358. else if(order > 4) {
  359. if(order > 6) {
  360. if(order == 8) {
  361. for(i = 0; i < (int)data_len; i++) {
  362. sum = 0;
  363. sum += qlp_coeff[7] * data[i-8];
  364. sum += qlp_coeff[6] * data[i-7];
  365. sum += qlp_coeff[5] * data[i-6];
  366. sum += qlp_coeff[4] * data[i-5];
  367. sum += qlp_coeff[3] * data[i-4];
  368. sum += qlp_coeff[2] * data[i-3];
  369. sum += qlp_coeff[1] * data[i-2];
  370. sum += qlp_coeff[0] * data[i-1];
  371. residual[i] = data[i] - (sum >> lp_quantization);
  372. }
  373. }
  374. else { /* order == 7 */
  375. for(i = 0; i < (int)data_len; i++) {
  376. sum = 0;
  377. sum += qlp_coeff[6] * data[i-7];
  378. sum += qlp_coeff[5] * data[i-6];
  379. sum += qlp_coeff[4] * data[i-5];
  380. sum += qlp_coeff[3] * data[i-4];
  381. sum += qlp_coeff[2] * data[i-3];
  382. sum += qlp_coeff[1] * data[i-2];
  383. sum += qlp_coeff[0] * data[i-1];
  384. residual[i] = data[i] - (sum >> lp_quantization);
  385. }
  386. }
  387. }
  388. else {
  389. if(order == 6) {
  390. for(i = 0; i < (int)data_len; i++) {
  391. sum = 0;
  392. sum += qlp_coeff[5] * data[i-6];
  393. sum += qlp_coeff[4] * data[i-5];
  394. sum += qlp_coeff[3] * data[i-4];
  395. sum += qlp_coeff[2] * data[i-3];
  396. sum += qlp_coeff[1] * data[i-2];
  397. sum += qlp_coeff[0] * data[i-1];
  398. residual[i] = data[i] - (sum >> lp_quantization);
  399. }
  400. }
  401. else { /* order == 5 */
  402. for(i = 0; i < (int)data_len; i++) {
  403. sum = 0;
  404. sum += qlp_coeff[4] * data[i-5];
  405. sum += qlp_coeff[3] * data[i-4];
  406. sum += qlp_coeff[2] * data[i-3];
  407. sum += qlp_coeff[1] * data[i-2];
  408. sum += qlp_coeff[0] * data[i-1];
  409. residual[i] = data[i] - (sum >> lp_quantization);
  410. }
  411. }
  412. }
  413. }
  414. else {
  415. if(order > 2) {
  416. if(order == 4) {
  417. for(i = 0; i < (int)data_len; i++) {
  418. sum = 0;
  419. sum += qlp_coeff[3] * data[i-4];
  420. sum += qlp_coeff[2] * data[i-3];
  421. sum += qlp_coeff[1] * data[i-2];
  422. sum += qlp_coeff[0] * data[i-1];
  423. residual[i] = data[i] - (sum >> lp_quantization);
  424. }
  425. }
  426. else { /* order == 3 */
  427. for(i = 0; i < (int)data_len; i++) {
  428. sum = 0;
  429. sum += qlp_coeff[2] * data[i-3];
  430. sum += qlp_coeff[1] * data[i-2];
  431. sum += qlp_coeff[0] * data[i-1];
  432. residual[i] = data[i] - (sum >> lp_quantization);
  433. }
  434. }
  435. }
  436. else {
  437. if(order == 2) {
  438. for(i = 0; i < (int)data_len; i++) {
  439. sum = 0;
  440. sum += qlp_coeff[1] * data[i-2];
  441. sum += qlp_coeff[0] * data[i-1];
  442. residual[i] = data[i] - (sum >> lp_quantization);
  443. }
  444. }
  445. else { /* order == 1 */
  446. for(i = 0; i < (int)data_len; i++)
  447. residual[i] = data[i] - ((qlp_coeff[0] * data[i-1]) >> lp_quantization);
  448. }
  449. }
  450. }
  451. }
  452. else { /* order > 12 */
  453. for(i = 0; i < (int)data_len; i++) {
  454. sum = 0;
  455. switch(order) {
  456. case 32: sum += qlp_coeff[31] * data[i-32];
  457. case 31: sum += qlp_coeff[30] * data[i-31];
  458. case 30: sum += qlp_coeff[29] * data[i-30];
  459. case 29: sum += qlp_coeff[28] * data[i-29];
  460. case 28: sum += qlp_coeff[27] * data[i-28];
  461. case 27: sum += qlp_coeff[26] * data[i-27];
  462. case 26: sum += qlp_coeff[25] * data[i-26];
  463. case 25: sum += qlp_coeff[24] * data[i-25];
  464. case 24: sum += qlp_coeff[23] * data[i-24];
  465. case 23: sum += qlp_coeff[22] * data[i-23];
  466. case 22: sum += qlp_coeff[21] * data[i-22];
  467. case 21: sum += qlp_coeff[20] * data[i-21];
  468. case 20: sum += qlp_coeff[19] * data[i-20];
  469. case 19: sum += qlp_coeff[18] * data[i-19];
  470. case 18: sum += qlp_coeff[17] * data[i-18];
  471. case 17: sum += qlp_coeff[16] * data[i-17];
  472. case 16: sum += qlp_coeff[15] * data[i-16];
  473. case 15: sum += qlp_coeff[14] * data[i-15];
  474. case 14: sum += qlp_coeff[13] * data[i-14];
  475. case 13: sum += qlp_coeff[12] * data[i-13];
  476. sum += qlp_coeff[11] * data[i-12];
  477. sum += qlp_coeff[10] * data[i-11];
  478. sum += qlp_coeff[ 9] * data[i-10];
  479. sum += qlp_coeff[ 8] * data[i- 9];
  480. sum += qlp_coeff[ 7] * data[i- 8];
  481. sum += qlp_coeff[ 6] * data[i- 7];
  482. sum += qlp_coeff[ 5] * data[i- 6];
  483. sum += qlp_coeff[ 4] * data[i- 5];
  484. sum += qlp_coeff[ 3] * data[i- 4];
  485. sum += qlp_coeff[ 2] * data[i- 3];
  486. sum += qlp_coeff[ 1] * data[i- 2];
  487. sum += qlp_coeff[ 0] * data[i- 1];
  488. }
  489. residual[i] = data[i] - (sum >> lp_quantization);
  490. }
  491. }
  492. }
  493. #endif
  494. void FLAC__lpc_compute_residual_from_qlp_coefficients_wide(const FLAC__int32 *data, unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 residual[])
  495. #if defined(FLAC__OVERFLOW_DETECT) || !defined(FLAC__LPC_UNROLLED_FILTER_LOOPS)
  496. {
  497. unsigned i, j;
  498. FLAC__int64 sum;
  499. const FLAC__int32 *history;
  500. #ifdef FLAC__OVERFLOW_DETECT_VERBOSE
  501. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients_wide: data_len=%d, order=%u, lpq=%d",data_len,order,lp_quantization);
  502. for(i=0;i<order;i++)
  503. fprintf(stderr,", q[%u]=%d",i,qlp_coeff[i]);
  504. fprintf(stderr,"\n");
  505. #endif
  506. FLAC__ASSERT(order > 0);
  507. for(i = 0; i < data_len; i++) {
  508. sum = 0;
  509. history = data;
  510. for(j = 0; j < order; j++)
  511. sum += (FLAC__int64)qlp_coeff[j] * (FLAC__int64)(*(--history));
  512. if(FLAC__bitmath_silog2_wide(sum >> lp_quantization) > 32) {
  513. #if defined _MSC_VER
  514. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients_wide: OVERFLOW, i=%u, sum=%I64d\n", i, sum >> lp_quantization);
  515. #else
  516. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients_wide: OVERFLOW, i=%u, sum=%lld\n", i, (long long)(sum >> lp_quantization));
  517. #endif
  518. break;
  519. }
  520. if(FLAC__bitmath_silog2_wide((FLAC__int64)(*data) - (sum >> lp_quantization)) > 32) {
  521. #if defined _MSC_VER
  522. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients_wide: OVERFLOW, i=%u, data=%d, sum=%I64d, residual=%I64d\n", i, *data, sum >> lp_quantization, (FLAC__int64)(*data) - (sum >> lp_quantization));
  523. #else
  524. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients_wide: OVERFLOW, i=%u, data=%d, sum=%lld, residual=%lld\n", i, *data, (long long)(sum >> lp_quantization), (long long)((FLAC__int64)(*data) - (sum >> lp_quantization)));
  525. #endif
  526. break;
  527. }
  528. *(residual++) = *(data++) - (FLAC__int32)(sum >> lp_quantization);
  529. }
  530. }
  531. #else /* fully unrolled version for normal use */
  532. {
  533. int i;
  534. FLAC__int64 sum;
  535. FLAC__ASSERT(order > 0);
  536. FLAC__ASSERT(order <= 32);
  537. /*
  538. * We do unique versions up to 12th order since that's the subset limit.
  539. * Also they are roughly ordered to match frequency of occurrence to
  540. * minimize branching.
  541. */
  542. if(order <= 12) {
  543. if(order > 8) {
  544. if(order > 10) {
  545. if(order == 12) {
  546. for(i = 0; i < (int)data_len; i++) {
  547. sum = 0;
  548. sum += qlp_coeff[11] * (FLAC__int64)data[i-12];
  549. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  550. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  551. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  552. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  553. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  554. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  555. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  556. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  557. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  558. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  559. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  560. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  561. }
  562. }
  563. else { /* order == 11 */
  564. for(i = 0; i < (int)data_len; i++) {
  565. sum = 0;
  566. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  567. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  568. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  569. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  570. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  571. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  572. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  573. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  574. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  575. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  576. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  577. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  578. }
  579. }
  580. }
  581. else {
  582. if(order == 10) {
  583. for(i = 0; i < (int)data_len; i++) {
  584. sum = 0;
  585. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  586. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  587. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  588. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  589. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  590. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  591. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  592. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  593. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  594. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  595. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  596. }
  597. }
  598. else { /* order == 9 */
  599. for(i = 0; i < (int)data_len; i++) {
  600. sum = 0;
  601. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  602. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  603. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  604. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  605. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  606. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  607. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  608. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  609. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  610. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  611. }
  612. }
  613. }
  614. }
  615. else if(order > 4) {
  616. if(order > 6) {
  617. if(order == 8) {
  618. for(i = 0; i < (int)data_len; i++) {
  619. sum = 0;
  620. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  621. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  622. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  623. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  624. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  625. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  626. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  627. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  628. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  629. }
  630. }
  631. else { /* order == 7 */
  632. for(i = 0; i < (int)data_len; i++) {
  633. sum = 0;
  634. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  635. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  636. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  637. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  638. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  639. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  640. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  641. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  642. }
  643. }
  644. }
  645. else {
  646. if(order == 6) {
  647. for(i = 0; i < (int)data_len; i++) {
  648. sum = 0;
  649. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  650. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  651. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  652. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  653. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  654. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  655. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  656. }
  657. }
  658. else { /* order == 5 */
  659. for(i = 0; i < (int)data_len; i++) {
  660. sum = 0;
  661. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  662. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  663. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  664. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  665. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  666. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  667. }
  668. }
  669. }
  670. }
  671. else {
  672. if(order > 2) {
  673. if(order == 4) {
  674. for(i = 0; i < (int)data_len; i++) {
  675. sum = 0;
  676. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  677. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  678. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  679. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  680. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  681. }
  682. }
  683. else { /* order == 3 */
  684. for(i = 0; i < (int)data_len; i++) {
  685. sum = 0;
  686. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  687. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  688. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  689. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  690. }
  691. }
  692. }
  693. else {
  694. if(order == 2) {
  695. for(i = 0; i < (int)data_len; i++) {
  696. sum = 0;
  697. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  698. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  699. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  700. }
  701. }
  702. else { /* order == 1 */
  703. for(i = 0; i < (int)data_len; i++)
  704. residual[i] = data[i] - (FLAC__int32)((qlp_coeff[0] * (FLAC__int64)data[i-1]) >> lp_quantization);
  705. }
  706. }
  707. }
  708. }
  709. else { /* order > 12 */
  710. for(i = 0; i < (int)data_len; i++) {
  711. sum = 0;
  712. switch(order) {
  713. case 32: sum += qlp_coeff[31] * (FLAC__int64)data[i-32];
  714. case 31: sum += qlp_coeff[30] * (FLAC__int64)data[i-31];
  715. case 30: sum += qlp_coeff[29] * (FLAC__int64)data[i-30];
  716. case 29: sum += qlp_coeff[28] * (FLAC__int64)data[i-29];
  717. case 28: sum += qlp_coeff[27] * (FLAC__int64)data[i-28];
  718. case 27: sum += qlp_coeff[26] * (FLAC__int64)data[i-27];
  719. case 26: sum += qlp_coeff[25] * (FLAC__int64)data[i-26];
  720. case 25: sum += qlp_coeff[24] * (FLAC__int64)data[i-25];
  721. case 24: sum += qlp_coeff[23] * (FLAC__int64)data[i-24];
  722. case 23: sum += qlp_coeff[22] * (FLAC__int64)data[i-23];
  723. case 22: sum += qlp_coeff[21] * (FLAC__int64)data[i-22];
  724. case 21: sum += qlp_coeff[20] * (FLAC__int64)data[i-21];
  725. case 20: sum += qlp_coeff[19] * (FLAC__int64)data[i-20];
  726. case 19: sum += qlp_coeff[18] * (FLAC__int64)data[i-19];
  727. case 18: sum += qlp_coeff[17] * (FLAC__int64)data[i-18];
  728. case 17: sum += qlp_coeff[16] * (FLAC__int64)data[i-17];
  729. case 16: sum += qlp_coeff[15] * (FLAC__int64)data[i-16];
  730. case 15: sum += qlp_coeff[14] * (FLAC__int64)data[i-15];
  731. case 14: sum += qlp_coeff[13] * (FLAC__int64)data[i-14];
  732. case 13: sum += qlp_coeff[12] * (FLAC__int64)data[i-13];
  733. sum += qlp_coeff[11] * (FLAC__int64)data[i-12];
  734. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  735. sum += qlp_coeff[ 9] * (FLAC__int64)data[i-10];
  736. sum += qlp_coeff[ 8] * (FLAC__int64)data[i- 9];
  737. sum += qlp_coeff[ 7] * (FLAC__int64)data[i- 8];
  738. sum += qlp_coeff[ 6] * (FLAC__int64)data[i- 7];
  739. sum += qlp_coeff[ 5] * (FLAC__int64)data[i- 6];
  740. sum += qlp_coeff[ 4] * (FLAC__int64)data[i- 5];
  741. sum += qlp_coeff[ 3] * (FLAC__int64)data[i- 4];
  742. sum += qlp_coeff[ 2] * (FLAC__int64)data[i- 3];
  743. sum += qlp_coeff[ 1] * (FLAC__int64)data[i- 2];
  744. sum += qlp_coeff[ 0] * (FLAC__int64)data[i- 1];
  745. }
  746. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  747. }
  748. }
  749. }
  750. #endif
  751. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  752. void FLAC__lpc_restore_signal(const FLAC__int32 residual[], unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 data[])
  753. #if defined(FLAC__OVERFLOW_DETECT) || !defined(FLAC__LPC_UNROLLED_FILTER_LOOPS)
  754. {
  755. FLAC__int64 sumo;
  756. unsigned i, j;
  757. FLAC__int32 sum;
  758. const FLAC__int32 *r = residual, *history;
  759. #ifdef FLAC__OVERFLOW_DETECT_VERBOSE
  760. fprintf(stderr,"FLAC__lpc_restore_signal: data_len=%d, order=%u, lpq=%d",data_len,order,lp_quantization);
  761. for(i=0;i<order;i++)
  762. fprintf(stderr,", q[%u]=%d",i,qlp_coeff[i]);
  763. fprintf(stderr,"\n");
  764. #endif
  765. FLAC__ASSERT(order > 0);
  766. for(i = 0; i < data_len; i++) {
  767. sumo = 0;
  768. sum = 0;
  769. history = data;
  770. for(j = 0; j < order; j++) {
  771. sum += qlp_coeff[j] * (*(--history));
  772. sumo += (FLAC__int64)qlp_coeff[j] * (FLAC__int64)(*history);
  773. #if defined _MSC_VER
  774. if(sumo > 2147483647I64 || sumo < -2147483648I64)
  775. fprintf(stderr,"FLAC__lpc_restore_signal: OVERFLOW, i=%u, j=%u, c=%d, d=%d, sumo=%I64d\n",i,j,qlp_coeff[j],*history,sumo);
  776. #else
  777. if(sumo > 2147483647ll || sumo < -2147483648ll)
  778. fprintf(stderr,"FLAC__lpc_restore_signal: OVERFLOW, i=%u, j=%u, c=%d, d=%d, sumo=%lld\n",i,j,qlp_coeff[j],*history,(long long)sumo);
  779. #endif
  780. }
  781. *(data++) = *(r++) + (sum >> lp_quantization);
  782. }
  783. /* Here's a slower but clearer version:
  784. for(i = 0; i < data_len; i++) {
  785. sum = 0;
  786. for(j = 0; j < order; j++)
  787. sum += qlp_coeff[j] * data[i-j-1];
  788. data[i] = residual[i] + (sum >> lp_quantization);
  789. }
  790. */
  791. }
  792. #else /* fully unrolled version for normal use */
  793. {
  794. int i;
  795. FLAC__int32 sum;
  796. FLAC__ASSERT(order > 0);
  797. FLAC__ASSERT(order <= 32);
  798. /*
  799. * We do unique versions up to 12th order since that's the subset limit.
  800. * Also they are roughly ordered to match frequency of occurrence to
  801. * minimize branching.
  802. */
  803. if(order <= 12) {
  804. if(order > 8) {
  805. if(order > 10) {
  806. if(order == 12) {
  807. for(i = 0; i < (int)data_len; i++) {
  808. sum = 0;
  809. sum += qlp_coeff[11] * data[i-12];
  810. sum += qlp_coeff[10] * data[i-11];
  811. sum += qlp_coeff[9] * data[i-10];
  812. sum += qlp_coeff[8] * data[i-9];
  813. sum += qlp_coeff[7] * data[i-8];
  814. sum += qlp_coeff[6] * data[i-7];
  815. sum += qlp_coeff[5] * data[i-6];
  816. sum += qlp_coeff[4] * data[i-5];
  817. sum += qlp_coeff[3] * data[i-4];
  818. sum += qlp_coeff[2] * data[i-3];
  819. sum += qlp_coeff[1] * data[i-2];
  820. sum += qlp_coeff[0] * data[i-1];
  821. data[i] = residual[i] + (sum >> lp_quantization);
  822. }
  823. }
  824. else { /* order == 11 */
  825. for(i = 0; i < (int)data_len; i++) {
  826. sum = 0;
  827. sum += qlp_coeff[10] * data[i-11];
  828. sum += qlp_coeff[9] * data[i-10];
  829. sum += qlp_coeff[8] * data[i-9];
  830. sum += qlp_coeff[7] * data[i-8];
  831. sum += qlp_coeff[6] * data[i-7];
  832. sum += qlp_coeff[5] * data[i-6];
  833. sum += qlp_coeff[4] * data[i-5];
  834. sum += qlp_coeff[3] * data[i-4];
  835. sum += qlp_coeff[2] * data[i-3];
  836. sum += qlp_coeff[1] * data[i-2];
  837. sum += qlp_coeff[0] * data[i-1];
  838. data[i] = residual[i] + (sum >> lp_quantization);
  839. }
  840. }
  841. }
  842. else {
  843. if(order == 10) {
  844. for(i = 0; i < (int)data_len; i++) {
  845. sum = 0;
  846. sum += qlp_coeff[9] * data[i-10];
  847. sum += qlp_coeff[8] * data[i-9];
  848. sum += qlp_coeff[7] * data[i-8];
  849. sum += qlp_coeff[6] * data[i-7];
  850. sum += qlp_coeff[5] * data[i-6];
  851. sum += qlp_coeff[4] * data[i-5];
  852. sum += qlp_coeff[3] * data[i-4];
  853. sum += qlp_coeff[2] * data[i-3];
  854. sum += qlp_coeff[1] * data[i-2];
  855. sum += qlp_coeff[0] * data[i-1];
  856. data[i] = residual[i] + (sum >> lp_quantization);
  857. }
  858. }
  859. else { /* order == 9 */
  860. for(i = 0; i < (int)data_len; i++) {
  861. sum = 0;
  862. sum += qlp_coeff[8] * data[i-9];
  863. sum += qlp_coeff[7] * data[i-8];
  864. sum += qlp_coeff[6] * data[i-7];
  865. sum += qlp_coeff[5] * data[i-6];
  866. sum += qlp_coeff[4] * data[i-5];
  867. sum += qlp_coeff[3] * data[i-4];
  868. sum += qlp_coeff[2] * data[i-3];
  869. sum += qlp_coeff[1] * data[i-2];
  870. sum += qlp_coeff[0] * data[i-1];
  871. data[i] = residual[i] + (sum >> lp_quantization);
  872. }
  873. }
  874. }
  875. }
  876. else if(order > 4) {
  877. if(order > 6) {
  878. if(order == 8) {
  879. for(i = 0; i < (int)data_len; i++) {
  880. sum = 0;
  881. sum += qlp_coeff[7] * data[i-8];
  882. sum += qlp_coeff[6] * data[i-7];
  883. sum += qlp_coeff[5] * data[i-6];
  884. sum += qlp_coeff[4] * data[i-5];
  885. sum += qlp_coeff[3] * data[i-4];
  886. sum += qlp_coeff[2] * data[i-3];
  887. sum += qlp_coeff[1] * data[i-2];
  888. sum += qlp_coeff[0] * data[i-1];
  889. data[i] = residual[i] + (sum >> lp_quantization);
  890. }
  891. }
  892. else { /* order == 7 */
  893. for(i = 0; i < (int)data_len; i++) {
  894. sum = 0;
  895. sum += qlp_coeff[6] * data[i-7];
  896. sum += qlp_coeff[5] * data[i-6];
  897. sum += qlp_coeff[4] * data[i-5];
  898. sum += qlp_coeff[3] * data[i-4];
  899. sum += qlp_coeff[2] * data[i-3];
  900. sum += qlp_coeff[1] * data[i-2];
  901. sum += qlp_coeff[0] * data[i-1];
  902. data[i] = residual[i] + (sum >> lp_quantization);
  903. }
  904. }
  905. }
  906. else {
  907. if(order == 6) {
  908. for(i = 0; i < (int)data_len; i++) {
  909. sum = 0;
  910. sum += qlp_coeff[5] * data[i-6];
  911. sum += qlp_coeff[4] * data[i-5];
  912. sum += qlp_coeff[3] * data[i-4];
  913. sum += qlp_coeff[2] * data[i-3];
  914. sum += qlp_coeff[1] * data[i-2];
  915. sum += qlp_coeff[0] * data[i-1];
  916. data[i] = residual[i] + (sum >> lp_quantization);
  917. }
  918. }
  919. else { /* order == 5 */
  920. for(i = 0; i < (int)data_len; i++) {
  921. sum = 0;
  922. sum += qlp_coeff[4] * data[i-5];
  923. sum += qlp_coeff[3] * data[i-4];
  924. sum += qlp_coeff[2] * data[i-3];
  925. sum += qlp_coeff[1] * data[i-2];
  926. sum += qlp_coeff[0] * data[i-1];
  927. data[i] = residual[i] + (sum >> lp_quantization);
  928. }
  929. }
  930. }
  931. }
  932. else {
  933. if(order > 2) {
  934. if(order == 4) {
  935. for(i = 0; i < (int)data_len; i++) {
  936. sum = 0;
  937. sum += qlp_coeff[3] * data[i-4];
  938. sum += qlp_coeff[2] * data[i-3];
  939. sum += qlp_coeff[1] * data[i-2];
  940. sum += qlp_coeff[0] * data[i-1];
  941. data[i] = residual[i] + (sum >> lp_quantization);
  942. }
  943. }
  944. else { /* order == 3 */
  945. for(i = 0; i < (int)data_len; i++) {
  946. sum = 0;
  947. sum += qlp_coeff[2] * data[i-3];
  948. sum += qlp_coeff[1] * data[i-2];
  949. sum += qlp_coeff[0] * data[i-1];
  950. data[i] = residual[i] + (sum >> lp_quantization);
  951. }
  952. }
  953. }
  954. else {
  955. if(order == 2) {
  956. for(i = 0; i < (int)data_len; i++) {
  957. sum = 0;
  958. sum += qlp_coeff[1] * data[i-2];
  959. sum += qlp_coeff[0] * data[i-1];
  960. data[i] = residual[i] + (sum >> lp_quantization);
  961. }
  962. }
  963. else { /* order == 1 */
  964. for(i = 0; i < (int)data_len; i++)
  965. data[i] = residual[i] + ((qlp_coeff[0] * data[i-1]) >> lp_quantization);
  966. }
  967. }
  968. }
  969. }
  970. else { /* order > 12 */
  971. for(i = 0; i < (int)data_len; i++) {
  972. sum = 0;
  973. switch(order) {
  974. case 32: sum += qlp_coeff[31] * data[i-32];
  975. case 31: sum += qlp_coeff[30] * data[i-31];
  976. case 30: sum += qlp_coeff[29] * data[i-30];
  977. case 29: sum += qlp_coeff[28] * data[i-29];
  978. case 28: sum += qlp_coeff[27] * data[i-28];
  979. case 27: sum += qlp_coeff[26] * data[i-27];
  980. case 26: sum += qlp_coeff[25] * data[i-26];
  981. case 25: sum += qlp_coeff[24] * data[i-25];
  982. case 24: sum += qlp_coeff[23] * data[i-24];
  983. case 23: sum += qlp_coeff[22] * data[i-23];
  984. case 22: sum += qlp_coeff[21] * data[i-22];
  985. case 21: sum += qlp_coeff[20] * data[i-21];
  986. case 20: sum += qlp_coeff[19] * data[i-20];
  987. case 19: sum += qlp_coeff[18] * data[i-19];
  988. case 18: sum += qlp_coeff[17] * data[i-18];
  989. case 17: sum += qlp_coeff[16] * data[i-17];
  990. case 16: sum += qlp_coeff[15] * data[i-16];
  991. case 15: sum += qlp_coeff[14] * data[i-15];
  992. case 14: sum += qlp_coeff[13] * data[i-14];
  993. case 13: sum += qlp_coeff[12] * data[i-13];
  994. sum += qlp_coeff[11] * data[i-12];
  995. sum += qlp_coeff[10] * data[i-11];
  996. sum += qlp_coeff[ 9] * data[i-10];
  997. sum += qlp_coeff[ 8] * data[i- 9];
  998. sum += qlp_coeff[ 7] * data[i- 8];
  999. sum += qlp_coeff[ 6] * data[i- 7];
  1000. sum += qlp_coeff[ 5] * data[i- 6];
  1001. sum += qlp_coeff[ 4] * data[i- 5];
  1002. sum += qlp_coeff[ 3] * data[i- 4];
  1003. sum += qlp_coeff[ 2] * data[i- 3];
  1004. sum += qlp_coeff[ 1] * data[i- 2];
  1005. sum += qlp_coeff[ 0] * data[i- 1];
  1006. }
  1007. data[i] = residual[i] + (sum >> lp_quantization);
  1008. }
  1009. }
  1010. }
  1011. #endif
  1012. void FLAC__lpc_restore_signal_wide(const FLAC__int32 residual[], unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 data[])
  1013. #if defined(FLAC__OVERFLOW_DETECT) || !defined(FLAC__LPC_UNROLLED_FILTER_LOOPS)
  1014. {
  1015. unsigned i, j;
  1016. FLAC__int64 sum;
  1017. const FLAC__int32 *r = residual, *history;
  1018. #ifdef FLAC__OVERFLOW_DETECT_VERBOSE
  1019. fprintf(stderr,"FLAC__lpc_restore_signal_wide: data_len=%d, order=%u, lpq=%d",data_len,order,lp_quantization);
  1020. for(i=0;i<order;i++)
  1021. fprintf(stderr,", q[%u]=%d",i,qlp_coeff[i]);
  1022. fprintf(stderr,"\n");
  1023. #endif
  1024. FLAC__ASSERT(order > 0);
  1025. for(i = 0; i < data_len; i++) {
  1026. sum = 0;
  1027. history = data;
  1028. for(j = 0; j < order; j++)
  1029. sum += (FLAC__int64)qlp_coeff[j] * (FLAC__int64)(*(--history));
  1030. if(FLAC__bitmath_silog2_wide(sum >> lp_quantization) > 32) {
  1031. #ifdef _MSC_VER
  1032. fprintf(stderr,"FLAC__lpc_restore_signal_wide: OVERFLOW, i=%u, sum=%I64d\n", i, sum >> lp_quantization);
  1033. #else
  1034. fprintf(stderr,"FLAC__lpc_restore_signal_wide: OVERFLOW, i=%u, sum=%lld\n", i, (long long)(sum >> lp_quantization));
  1035. #endif
  1036. break;
  1037. }
  1038. if(FLAC__bitmath_silog2_wide((FLAC__int64)(*r) + (sum >> lp_quantization)) > 32) {
  1039. #ifdef _MSC_VER
  1040. fprintf(stderr,"FLAC__lpc_restore_signal_wide: OVERFLOW, i=%u, residual=%d, sum=%I64d, data=%I64d\n", i, *r, sum >> lp_quantization, (FLAC__int64)(*r) + (sum >> lp_quantization));
  1041. #else
  1042. fprintf(stderr,"FLAC__lpc_restore_signal_wide: OVERFLOW, i=%u, residual=%d, sum=%lld, data=%lld\n", i, *r, (long long)(sum >> lp_quantization), (long long)((FLAC__int64)(*r) + (sum >> lp_quantization)));
  1043. #endif
  1044. break;
  1045. }
  1046. *(data++) = *(r++) + (FLAC__int32)(sum >> lp_quantization);
  1047. }
  1048. }
  1049. #else /* fully unrolled version for normal use */
  1050. {
  1051. int i;
  1052. FLAC__int64 sum;
  1053. FLAC__ASSERT(order > 0);
  1054. FLAC__ASSERT(order <= 32);
  1055. /*
  1056. * We do unique versions up to 12th order since that's the subset limit.
  1057. * Also they are roughly ordered to match frequency of occurrence to
  1058. * minimize branching.
  1059. */
  1060. if(order <= 12) {
  1061. if(order > 8) {
  1062. if(order > 10) {
  1063. if(order == 12) {
  1064. for(i = 0; i < (int)data_len; i++) {
  1065. sum = 0;
  1066. sum += qlp_coeff[11] * (FLAC__int64)data[i-12];
  1067. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  1068. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  1069. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  1070. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  1071. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  1072. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  1073. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  1074. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  1075. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  1076. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  1077. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  1078. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  1079. }
  1080. }
  1081. else { /* order == 11 */
  1082. for(i = 0; i < (int)data_len; i++) {
  1083. sum = 0;
  1084. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  1085. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  1086. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  1087. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  1088. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  1089. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  1090. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  1091. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  1092. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  1093. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  1094. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  1095. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  1096. }
  1097. }
  1098. }
  1099. else {
  1100. if(order == 10) {
  1101. for(i = 0; i < (int)data_len; i++) {
  1102. sum = 0;
  1103. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  1104. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  1105. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  1106. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  1107. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  1108. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  1109. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  1110. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  1111. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  1112. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  1113. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  1114. }
  1115. }
  1116. else { /* order == 9 */
  1117. for(i = 0; i < (int)data_len; i++) {
  1118. sum = 0;
  1119. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  1120. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  1121. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  1122. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  1123. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  1124. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  1125. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  1126. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  1127. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  1128. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  1129. }
  1130. }
  1131. }
  1132. }
  1133. else if(order > 4) {
  1134. if(order > 6) {
  1135. if(order == 8) {
  1136. for(i = 0; i < (int)data_len; i++) {
  1137. sum = 0;
  1138. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  1139. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  1140. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  1141. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  1142. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  1143. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  1144. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  1145. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  1146. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  1147. }
  1148. }
  1149. else { /* order == 7 */
  1150. for(i = 0; i < (int)data_len; i++) {
  1151. sum = 0;
  1152. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  1153. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  1154. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  1155. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  1156. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  1157. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  1158. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  1159. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  1160. }
  1161. }
  1162. }
  1163. else {
  1164. if(order == 6) {
  1165. for(i = 0; i < (int)data_len; i++) {
  1166. sum = 0;
  1167. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  1168. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  1169. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  1170. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  1171. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  1172. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  1173. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  1174. }
  1175. }
  1176. else { /* order == 5 */
  1177. for(i = 0; i < (int)data_len; i++) {
  1178. sum = 0;
  1179. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  1180. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  1181. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  1182. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  1183. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  1184. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  1185. }
  1186. }
  1187. }
  1188. }
  1189. else {
  1190. if(order > 2) {
  1191. if(order == 4) {
  1192. for(i = 0; i < (int)data_len; i++) {
  1193. sum = 0;
  1194. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  1195. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  1196. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  1197. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  1198. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  1199. }
  1200. }
  1201. else { /* order == 3 */
  1202. for(i = 0; i < (int)data_len; i++) {
  1203. sum = 0;
  1204. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  1205. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  1206. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  1207. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  1208. }
  1209. }
  1210. }
  1211. else {
  1212. if(order == 2) {
  1213. for(i = 0; i < (int)data_len; i++) {
  1214. sum = 0;
  1215. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  1216. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  1217. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  1218. }
  1219. }
  1220. else { /* order == 1 */
  1221. for(i = 0; i < (int)data_len; i++)
  1222. data[i] = residual[i] + (FLAC__int32)((qlp_coeff[0] * (FLAC__int64)data[i-1]) >> lp_quantization);
  1223. }
  1224. }
  1225. }
  1226. }
  1227. else { /* order > 12 */
  1228. for(i = 0; i < (int)data_len; i++) {
  1229. sum = 0;
  1230. switch(order) {
  1231. case 32: sum += qlp_coeff[31] * (FLAC__int64)data[i-32];
  1232. case 31: sum += qlp_coeff[30] * (FLAC__int64)data[i-31];
  1233. case 30: sum += qlp_coeff[29] * (FLAC__int64)data[i-30];
  1234. case 29: sum += qlp_coeff[28] * (FLAC__int64)data[i-29];
  1235. case 28: sum += qlp_coeff[27] * (FLAC__int64)data[i-28];
  1236. case 27: sum += qlp_coeff[26] * (FLAC__int64)data[i-27];
  1237. case 26: sum += qlp_coeff[25] * (FLAC__int64)data[i-26];
  1238. case 25: sum += qlp_coeff[24] * (FLAC__int64)data[i-25];
  1239. case 24: sum += qlp_coeff[23] * (FLAC__int64)data[i-24];
  1240. case 23: sum += qlp_coeff[22] * (FLAC__int64)data[i-23];
  1241. case 22: sum += qlp_coeff[21] * (FLAC__int64)data[i-22];
  1242. case 21: sum += qlp_coeff[20] * (FLAC__int64)data[i-21];
  1243. case 20: sum += qlp_coeff[19] * (FLAC__int64)data[i-20];
  1244. case 19: sum += qlp_coeff[18] * (FLAC__int64)data[i-19];
  1245. case 18: sum += qlp_coeff[17] * (FLAC__int64)data[i-18];
  1246. case 17: sum += qlp_coeff[16] * (FLAC__int64)data[i-17];
  1247. case 16: sum += qlp_coeff[15] * (FLAC__int64)data[i-16];
  1248. case 15: sum += qlp_coeff[14] * (FLAC__int64)data[i-15];
  1249. case 14: sum += qlp_coeff[13] * (FLAC__int64)data[i-14];
  1250. case 13: sum += qlp_coeff[12] * (FLAC__int64)data[i-13];
  1251. sum += qlp_coeff[11] * (FLAC__int64)data[i-12];
  1252. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  1253. sum += qlp_coeff[ 9] * (FLAC__int64)data[i-10];
  1254. sum += qlp_coeff[ 8] * (FLAC__int64)data[i- 9];
  1255. sum += qlp_coeff[ 7] * (FLAC__int64)data[i- 8];
  1256. sum += qlp_coeff[ 6] * (FLAC__int64)data[i- 7];
  1257. sum += qlp_coeff[ 5] * (FLAC__int64)data[i- 6];
  1258. sum += qlp_coeff[ 4] * (FLAC__int64)data[i- 5];
  1259. sum += qlp_coeff[ 3] * (FLAC__int64)data[i- 4];
  1260. sum += qlp_coeff[ 2] * (FLAC__int64)data[i- 3];
  1261. sum += qlp_coeff[ 1] * (FLAC__int64)data[i- 2];
  1262. sum += qlp_coeff[ 0] * (FLAC__int64)data[i- 1];
  1263. }
  1264. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  1265. }
  1266. }
  1267. }
  1268. #endif
  1269. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  1270. FLAC__double FLAC__lpc_compute_expected_bits_per_residual_sample(FLAC__double lpc_error, unsigned total_samples)
  1271. {
  1272. FLAC__double error_scale;
  1273. FLAC__ASSERT(total_samples > 0);
  1274. error_scale = 0.5 * M_LN2 * M_LN2 / (FLAC__double)total_samples;
  1275. return FLAC__lpc_compute_expected_bits_per_residual_sample_with_error_scale(lpc_error, error_scale);
  1276. }
  1277. FLAC__double FLAC__lpc_compute_expected_bits_per_residual_sample_with_error_scale(FLAC__double lpc_error, FLAC__double error_scale)
  1278. {
  1279. if(lpc_error > 0.0) {
  1280. FLAC__double bps = (FLAC__double)0.5 * log(error_scale * lpc_error) / M_LN2;
  1281. if(bps >= 0.0)
  1282. return bps;
  1283. else
  1284. return 0.0;
  1285. }
  1286. else if(lpc_error < 0.0) { /* error should not be negative but can happen due to inadequate floating-point resolution */
  1287. return 1e32;
  1288. }
  1289. else {
  1290. return 0.0;
  1291. }
  1292. }
  1293. unsigned FLAC__lpc_compute_best_order(const FLAC__double lpc_error[], unsigned max_order, unsigned total_samples, unsigned overhead_bits_per_order)
  1294. {
  1295. unsigned order, index, best_index; /* 'index' the index into lpc_error; index==order-1 since lpc_error[0] is for order==1, lpc_error[1] is for order==2, etc */
  1296. FLAC__double bits, best_bits, error_scale;
  1297. FLAC__ASSERT(max_order > 0);
  1298. FLAC__ASSERT(total_samples > 0);
  1299. error_scale = 0.5 * M_LN2 * M_LN2 / (FLAC__double)total_samples;
  1300. best_index = 0;
  1301. best_bits = (unsigned)(-1);
  1302. for(index = 0, order = 1; index < max_order; index++, order++) {
  1303. bits = FLAC__lpc_compute_expected_bits_per_residual_sample_with_error_scale(lpc_error[index], error_scale) * (FLAC__double)(total_samples - order) + (FLAC__double)(order * overhead_bits_per_order);
  1304. if(bits < best_bits) {
  1305. best_index = index;
  1306. best_bits = bits;
  1307. }
  1308. }
  1309. return best_index+1; /* +1 since index of lpc_error[] is order-1 */
  1310. }
  1311. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */