diff options
-rw-r--r-- | apps/codecs/libmusepack/synth_filter.c | 32 | ||||
-rwxr-xr-x | apps/codecs/libmusepack/synth_filter_arm.S | 5 | ||||
-rw-r--r-- | apps/codecs/mpc.c | 4 |
3 files changed, 25 insertions, 16 deletions
diff --git a/apps/codecs/libmusepack/synth_filter.c b/apps/codecs/libmusepack/synth_filter.c index 44d7192664..ae94741368 100644 --- a/apps/codecs/libmusepack/synth_filter.c +++ b/apps/codecs/libmusepack/synth_filter.c | |||
@@ -44,11 +44,15 @@ | |||
44 | 44 | ||
45 | #if defined(MPC_FIXED_POINT) | 45 | #if defined(MPC_FIXED_POINT) |
46 | #if defined(OPTIMIZE_FOR_SPEED) | 46 | #if defined(OPTIMIZE_FOR_SPEED) |
47 | // round to +/- 2^14 as pre-shift before 32=32x32-multiply | 47 | // round at compile time to +/- 2^14 as a pre-shift before 32=32x32-multiply |
48 | #define D(value) (MPC_SHR_RND(value, 3)) | 48 | #define D(value) (MPC_SHR_RND(value, 3)) |
49 | 49 | ||
50 | // round to +/- 2^17 as pre-shift before 32=32x32-multiply | 50 | // round at runtime to +/- 2^17 as a pre-shift before 32=32x32-multiply |
51 | #define MPC_V_PRESHIFT(X) MPC_SHR_RND(X, 14) | 51 | // samples are 18.14 fixed point. 30.2 after this shift, whereas the |
52 | // 15.2 bits are significant (not including sign) | ||
53 | #define MPC_V_PRESHIFT(X) MPC_SHR_RND(X, 12) | ||
54 | |||
55 | // in this configuration a post-shift by >>1 is needed after synthesis | ||
52 | #else | 56 | #else |
53 | // saturate to +/- 2^31 (= value << (31-17)), D-values are +/- 2^17 | 57 | // saturate to +/- 2^31 (= value << (31-17)), D-values are +/- 2^17 |
54 | #define D(value) (value << (14)) | 58 | #define D(value) (value << (14)) |
@@ -65,7 +69,7 @@ | |||
65 | #define MPC_V_PRESHIFT(X) (X) | 69 | #define MPC_V_PRESHIFT(X) (X) |
66 | #endif | 70 | #endif |
67 | 71 | ||
68 | // Di_opt coefficients are +/- 2^17 | 72 | // Di_opt coefficients are +/- 2^17 (pre-shifted by <<16) |
69 | static const MPC_SAMPLE_FORMAT Di_opt [512] ICONST_ATTR = { | 73 | static const MPC_SAMPLE_FORMAT Di_opt [512] ICONST_ATTR = { |
70 | /* 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 */ | 74 | /* 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 */ |
71 | /* 0 */ D( 0), -D( 29), D( 213), -D( 459), D(2037), -D(5153), D( 6574), -D(37489), D(75038), D(37489), D(6574), D(5153), D(2037), D(459), D(213), D(29), | 75 | /* 0 */ D( 0), -D( 29), D( 213), -D( 459), D(2037), -D(5153), D( 6574), -D(37489), D(75038), D(37489), D(6574), D(5153), D(2037), D(459), D(213), D(29), |
@@ -462,6 +466,7 @@ mpc_decoder_windowing_D(MPC_SAMPLE_FORMAT * Data, | |||
462 | + V[256]*D[ 4] + V[352]*D[ 5] + V[384]*D[ 6] + V[480]*D[ 7] | 466 | + V[256]*D[ 4] + V[352]*D[ 5] + V[384]*D[ 6] + V[480]*D[ 7] |
463 | + V[512]*D[ 8] + V[608]*D[ 9] + V[640]*D[10] + V[736]*D[11] | 467 | + V[512]*D[ 8] + V[608]*D[ 9] + V[640]*D[10] + V[736]*D[11] |
464 | + V[768]*D[12] + V[864]*D[13] + V[896]*D[14] + V[992]*D[15]; | 468 | + V[768]*D[12] + V[864]*D[13] + V[896]*D[14] + V[992]*D[15]; |
469 | *Data >>= 1; // post shift to compensate for pre-shifting | ||
465 | Data += 1; | 470 | Data += 1; |
466 | // total: 32 * (16 muls, 15 adds) | 471 | // total: 32 * (16 muls, 15 adds) |
467 | } | 472 | } |
@@ -493,6 +498,7 @@ mpc_decoder_windowing_D(MPC_SAMPLE_FORMAT * Data, | |||
493 | "mac.l %%d2, %%a5, (992*4, %[V]), %%a5, %%acc0\n\t" | 498 | "mac.l %%d2, %%a5, (992*4, %[V]), %%a5, %%acc0\n\t" |
494 | "mac.l %%d3, %%a5, %%acc0 \n\t" | 499 | "mac.l %%d3, %%a5, %%acc0 \n\t" |
495 | "movclr.l %%acc0, %%d0 \n\t" | 500 | "movclr.l %%acc0, %%d0 \n\t" |
501 | "lsl.l #1, %%d0 \n\t" | ||
496 | "move.l %%d0, (%[Data])+ \n" | 502 | "move.l %%d0, (%[Data])+ \n" |
497 | : [Data] "+a" (Data) | 503 | : [Data] "+a" (Data) |
498 | : [V] "a" (V), [D] "a" (D) | 504 | : [V] "a" (V), [D] "a" (D) |
@@ -500,16 +506,16 @@ mpc_decoder_windowing_D(MPC_SAMPLE_FORMAT * Data, | |||
500 | } | 506 | } |
501 | #else | 507 | #else |
502 | // 64=64x64-multiply (FIXED_POINT) or float=float*float (!FIXED_POINT) in C | 508 | // 64=64x64-multiply (FIXED_POINT) or float=float*float (!FIXED_POINT) in C |
503 | for ( k = 0; k < 32; k++, D += 16, V++ ) | 509 | for ( k = 0; k < 32; k++, D += 16, V++ ) |
504 | { | 510 | { |
505 | *Data = MPC_MULTIPLY_EX(V[ 0],D[ 0],31) + MPC_MULTIPLY_EX(V[ 96],D[ 1],31) | 511 | *Data = MPC_MULTIPLY_EX(V[ 0],D[ 0],30) + MPC_MULTIPLY_EX(V[ 96],D[ 1],30) |
506 | + MPC_MULTIPLY_EX(V[128],D[ 2],31) + MPC_MULTIPLY_EX(V[224],D[ 3],31) | 512 | + MPC_MULTIPLY_EX(V[128],D[ 2],30) + MPC_MULTIPLY_EX(V[224],D[ 3],30) |
507 | + MPC_MULTIPLY_EX(V[256],D[ 4],31) + MPC_MULTIPLY_EX(V[352],D[ 5],31) | 513 | + MPC_MULTIPLY_EX(V[256],D[ 4],30) + MPC_MULTIPLY_EX(V[352],D[ 5],30) |
508 | + MPC_MULTIPLY_EX(V[384],D[ 6],31) + MPC_MULTIPLY_EX(V[480],D[ 7],31) | 514 | + MPC_MULTIPLY_EX(V[384],D[ 6],30) + MPC_MULTIPLY_EX(V[480],D[ 7],30) |
509 | + MPC_MULTIPLY_EX(V[512],D[ 8],31) + MPC_MULTIPLY_EX(V[608],D[ 9],31) | 515 | + MPC_MULTIPLY_EX(V[512],D[ 8],30) + MPC_MULTIPLY_EX(V[608],D[ 9],30) |
510 | + MPC_MULTIPLY_EX(V[640],D[10],31) + MPC_MULTIPLY_EX(V[736],D[11],31) | 516 | + MPC_MULTIPLY_EX(V[640],D[10],30) + MPC_MULTIPLY_EX(V[736],D[11],30) |
511 | + MPC_MULTIPLY_EX(V[768],D[12],31) + MPC_MULTIPLY_EX(V[864],D[13],31) | 517 | + MPC_MULTIPLY_EX(V[768],D[12],30) + MPC_MULTIPLY_EX(V[864],D[13],30) |
512 | + MPC_MULTIPLY_EX(V[896],D[14],31) + MPC_MULTIPLY_EX(V[992],D[15],31); | 518 | + MPC_MULTIPLY_EX(V[896],D[14],30) + MPC_MULTIPLY_EX(V[992],D[15],30); |
513 | Data += 1; | 519 | Data += 1; |
514 | // total: 16 muls, 15 adds, 16 shifts | 520 | // total: 16 muls, 15 adds, 16 shifts |
515 | } | 521 | } |
diff --git a/apps/codecs/libmusepack/synth_filter_arm.S b/apps/codecs/libmusepack/synth_filter_arm.S index ce668e888c..7b2d2dfd23 100755 --- a/apps/codecs/libmusepack/synth_filter_arm.S +++ b/apps/codecs/libmusepack/synth_filter_arm.S | |||
@@ -75,7 +75,8 @@ mpc_decoder_windowing_D: | |||
75 | ldr r11, [r1, #896*4] /* 14 */ | 75 | ldr r11, [r1, #896*4] /* 14 */ |
76 | mla r12, r9, r11, r12 | 76 | mla r12, r9, r11, r12 |
77 | ldr r11, [r1, #992*4] /* 15 */ | 77 | ldr r11, [r1, #992*4] /* 15 */ |
78 | mla r12, r10, r11, r12 | 78 | mla r12, r10, r11, r12 |
79 | mov r12, r12, asr #1 /* post shift to compensate for pre-shifting */ | ||
79 | str r12, [r0], #4 /* store Data */ | 80 | str r12, [r0], #4 /* store Data */ |
80 | add r1, r1, #4 /* V++ */ | 81 | add r1, r1, #4 /* V++ */ |
81 | 82 | ||
@@ -142,7 +143,7 @@ mpc_decoder_windowing_D: | |||
142 | smlal r11, r12, r9, r11 | 143 | smlal r11, r12, r9, r11 |
143 | ldr r11, [r1, #992*4] /* 15 */ | 144 | ldr r11, [r1, #992*4] /* 15 */ |
144 | smlal r11, r12, r10, r11 | 145 | smlal r11, r12, r10, r11 |
145 | mov r4, r12, lsl #1 /* get result from hi-part */ | 146 | mov r4, r12, lsl #2 /* get result from hi-part, loose 2 bits */ |
146 | str r4, [r0], #4 /* store Data */ | 147 | str r4, [r0], #4 /* store Data */ |
147 | add r1, r1, #4 /* V++ */ | 148 | add r1, r1, #4 /* V++ */ |
148 | 149 | ||
diff --git a/apps/codecs/mpc.c b/apps/codecs/mpc.c index 79264d3bfc..bdf675d169 100644 --- a/apps/codecs/mpc.c +++ b/apps/codecs/mpc.c | |||
@@ -76,7 +76,9 @@ enum codec_status codec_main(void) | |||
76 | mpc_streaminfo info; | 76 | mpc_streaminfo info; |
77 | int retval = CODEC_OK; | 77 | int retval = CODEC_OK; |
78 | 78 | ||
79 | ci->configure(DSP_SET_SAMPLE_DEPTH, 28); | 79 | /* musepack's sample representation is 18.14 |
80 | * DSP_SET_SAMPLE_DEPTH = 14 (FRACT) + 16 (NATIVE) - 1 (SIGN) = 29 */ | ||
81 | ci->configure(DSP_SET_SAMPLE_DEPTH, 29); | ||
80 | 82 | ||
81 | /* Create a decoder instance */ | 83 | /* Create a decoder instance */ |
82 | reader.read = read_impl; | 84 | reader.read = read_impl; |