#endif
#include <math.h>
+#include <string.h>
#include "private/bitmath.h"
#include "private/fixed.h"
#include "FLAC/assert.h"
switch(order) {
case 0:
- for(i = 0; i < idata_len; i++) {
- residual[i] = data[i];
- }
+ FLAC__ASSERT(sizeof(residual[0]) == sizeof(data[0]));
+ memcpy(residual, data, sizeof(residual[0])*data_len);
break;
case 1:
- for(i = 0; i < idata_len; i++) {
+ for(i = 0; i < idata_len; i++)
residual[i] = data[i] - data[i-1];
- }
break;
case 2:
- for(i = 0; i < idata_len; i++) {
- /* == data[i] - 2*data[i-1] + data[i-2] */
+ for(i = 0; i < idata_len; i++)
+#if 1 /* OPT: may be faster with some compilers on some systems */
residual[i] = data[i] - (data[i-1] << 1) + data[i-2];
- }
+#else
+ residual[i] = data[i] - 2*data[i-1] + data[i-2];
+#endif
break;
case 3:
- for(i = 0; i < idata_len; i++) {
- /* == data[i] - 3*data[i-1] + 3*data[i-2] - data[i-3] */
+ for(i = 0; i < idata_len; i++)
+#if 1 /* OPT: may be faster with some compilers on some systems */
residual[i] = data[i] - (((data[i-1]-data[i-2])<<1) + (data[i-1]-data[i-2])) - data[i-3];
- }
+#else
+ residual[i] = data[i] - 3*data[i-1] + 3*data[i-2] - data[i-3];
+#endif
break;
case 4:
- for(i = 0; i < idata_len; i++) {
- /* == data[i] - 4*data[i-1] + 6*data[i-2] - 4*data[i-3] + data[i-4] */
+ for(i = 0; i < idata_len; i++)
+#if 1 /* OPT: may be faster with some compilers on some systems */
residual[i] = data[i] - ((data[i-1]+data[i-3])<<2) + ((data[i-2]<<2) + (data[i-2]<<1)) + data[i-4];
- }
+#else
+ residual[i] = data[i] - 4*data[i-1] + 6*data[i-2] - 4*data[i-3] + data[i-4];
+#endif
break;
default:
FLAC__ASSERT(0);
switch(order) {
case 0:
- for(i = 0; i < idata_len; i++) {
- data[i] = residual[i];
- }
+ FLAC__ASSERT(sizeof(residual[0]) == sizeof(data[0]));
+ memcpy(data, residual, sizeof(residual[0])*data_len);
break;
case 1:
- for(i = 0; i < idata_len; i++) {
+ for(i = 0; i < idata_len; i++)
data[i] = residual[i] + data[i-1];
- }
break;
case 2:
- for(i = 0; i < idata_len; i++) {
- /* == residual[i] + 2*data[i-1] - data[i-2] */
+ for(i = 0; i < idata_len; i++)
+#if 1 /* OPT: may be faster with some compilers on some systems */
data[i] = residual[i] + (data[i-1]<<1) - data[i-2];
- }
+#else
+ data[i] = residual[i] + 2*data[i-1] - data[i-2];
+#endif
break;
case 3:
- for(i = 0; i < idata_len; i++) {
- /* residual[i] + 3*data[i-1] - 3*data[i-2]) + data[i-3] */
+ for(i = 0; i < idata_len; i++)
+#if 1 /* OPT: may be faster with some compilers on some systems */
data[i] = residual[i] + (((data[i-1]-data[i-2])<<1) + (data[i-1]-data[i-2])) + data[i-3];
- }
+#else
+ data[i] = residual[i] + 3*data[i-1] - 3*data[i-2] + data[i-3];
+#endif
break;
case 4:
- for(i = 0; i < idata_len; i++) {
- /* == residual[i] + 4*data[i-1] - 6*data[i-2] + 4*data[i-3] - data[i-4] */
+ for(i = 0; i < idata_len; i++)
+#if 1 /* OPT: may be faster with some compilers on some systems */
data[i] = residual[i] + ((data[i-1]+data[i-3])<<2) - ((data[i-2]<<2) + (data[i-2]<<1)) - data[i-4];
- }
+#else
+ data[i] = residual[i] + 4*data[i-1] - 6*data[i-2] + 4*data[i-3] - data[i-4];
+#endif
break;
default:
FLAC__ASSERT(0);