summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
authorDave Chapman <dave@dchapman.com>2009-05-10 22:26:02 +0000
committerDave Chapman <dave@dchapman.com>2009-05-10 22:26:02 +0000
commitfc28cb4ed5adf4a0bc548af38ca6de95bbf027e5 (patch)
tree5902a50d7efe84a5f3e6270c464dbf54572a744a /apps
parent3a0a9915eb802d558c0399d17a5ac045934d6be1 (diff)
downloadrockbox-fc28cb4ed5adf4a0bc548af38ca6de95bbf027e5.tar.gz
rockbox-fc28cb4ed5adf4a0bc548af38ca6de95bbf027e5.zip
Patch by Mohamed Tarek from FS#10182 - convert codec to fixed-point using patches submitted to the ffmpeg mailing list in 2007 by Ian Braithwaite.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@20901 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps')
-rw-r--r--apps/codecs/libcook/README.rockbox18
-rw-r--r--apps/codecs/libcook/cook.c91
-rw-r--r--apps/codecs/libcook/cook.h24
-rw-r--r--apps/codecs/libcook/cook_fixp_mdct.h545
-rw-r--r--apps/codecs/libcook/cook_fixpoint.h243
-rw-r--r--apps/codecs/libcook/cookdata.h82
-rw-r--r--apps/codecs/libcook/cookdata_fixpoint.h433
7 files changed, 1313 insertions, 123 deletions
diff --git a/apps/codecs/libcook/README.rockbox b/apps/codecs/libcook/README.rockbox
index 9447b96be5..b51508f8a9 100644
--- a/apps/codecs/libcook/README.rockbox
+++ b/apps/codecs/libcook/README.rockbox
@@ -31,6 +31,24 @@ compile cook.c and the related files outside ffmpeg.
31The decoder still uses floating point and relies on dynamic allocations 31The decoder still uses floating point and relies on dynamic allocations
32in some parts of it. It's still not ready to be ported to rockbox. 32in some parts of it. It's still not ready to be ported to rockbox.
33 33
34CONVERSION TO FIXED-POINT
35
36A patch from ffmpeg's mailing list was used to convert the decoder to
37use fixed-point arithmetic. The patch was done by Ian Braithwaite, and
38discussed here :
39
40http://thread.gmane.org/gmane.comp.video.ffmpeg.devel/46024
41
42The patch is a bit dated (2007) so the modifications to cook.c had to
43be done manually. The patch was also applied to cookdata.h and was
44used to create cookdata_fixpoint.h, cook_fixpoint.h and
45cook_fixp_mdct.h.
46
47The patch used a cook_random() function for noise filling. this was
48dropped and av_lfg_get() was used instead for consistency.
49
50Note : Only parts of the patch were committed to ffmpeg's repository.
51
34TESTING 52TESTING
35 53
36The test program should compile in any Unix-like environment using the 54The test program should compile in any Unix-like environment using the
diff --git a/apps/codecs/libcook/cook.c b/apps/codecs/libcook/cook.c
index e3a919ddec..8bb3b5a113 100644
--- a/apps/codecs/libcook/cook.c
+++ b/apps/codecs/libcook/cook.c
@@ -70,11 +70,11 @@ const uint8_t ff_log2_tab[256]={
70#define SUBBAND_SIZE 20 70#define SUBBAND_SIZE 20
71#define MAX_SUBPACKETS 5 71#define MAX_SUBPACKETS 5
72//#define COOKDEBUG 72//#define COOKDEBUG
73//#define DUMP_RAW_FRAMES
74#define DEBUGF(message,args ...) av_log(NULL,AV_LOG_ERROR,message,## args) 73#define DEBUGF(message,args ...) av_log(NULL,AV_LOG_ERROR,message,## args)
75 74
76static float pow2tab[127]; 75static float pow2tab[127];
77static float rootpow2tab[127]; 76static float rootpow2tab[127];
77#include "cook_fixpoint.h"
78 78
79/* debug functions */ 79/* debug functions */
80 80
@@ -189,7 +189,7 @@ static const float *maybe_reformat_buffer32 (COOKContext *q, const float *ptr, i
189static av_cold void init_cplscales_table (COOKContext *q) { 189static av_cold void init_cplscales_table (COOKContext *q) {
190 int i; 190 int i;
191 for (i=0;i<5;i++) 191 for (i=0;i<5;i++)
192 q->cplscales[i] = maybe_reformat_buffer32 (q, cplscales[i], (1<<(i+2))-1); 192 q->cplscales[i] = maybe_reformat_buffer32 (q, q->cplscales[i], (1<<(i+2))-1);
193} 193}
194 194
195/*************** init functions end ***********/ 195/*************** init functions end ***********/
@@ -454,6 +454,7 @@ static inline void expand_category(COOKContext *q, int* category,
454 * @param mlt_p pointer into the mlt buffer 454 * @param mlt_p pointer into the mlt buffer
455 */ 455 */
456 456
457#if 0
457static void scalar_dequant_float(COOKContext *q, int index, int quant_index, 458static void scalar_dequant_float(COOKContext *q, int index, int quant_index,
458 int* subband_coef_index, int* subband_coef_sign, 459 int* subband_coef_index, int* subband_coef_sign,
459 float* mlt_p){ 460 float* mlt_p){
@@ -472,6 +473,7 @@ static void scalar_dequant_float(COOKContext *q, int index, int quant_index,
472 mlt_p[i] = f1 * rootpow2tab[quant_index+63]; 473 mlt_p[i] = f1 * rootpow2tab[quant_index+63];
473 } 474 }
474} 475}
476#endif
475/** 477/**
476 * Unpack the subband_coef_index and subband_coef_sign vectors. 478 * Unpack the subband_coef_index and subband_coef_sign vectors.
477 * 479 *
@@ -527,7 +529,7 @@ static int unpack_SQVH(COOKContext *q, int category, int* subband_coef_index,
527 529
528 530
529static void decode_vectors(COOKContext* q, int* category, 531static void decode_vectors(COOKContext* q, int* category,
530 int *quant_index_table, float* mlt_buffer){ 532 int *quant_index_table, REAL_T* mlt_buffer){
531 /* A zero in this table means that the subband coefficient is 533 /* A zero in this table means that the subband coefficient is
532 random noise coded. */ 534 random noise coded. */
533 int subband_coef_index[SUBBAND_SIZE]; 535 int subband_coef_index[SUBBAND_SIZE];
@@ -567,7 +569,7 @@ static void decode_vectors(COOKContext* q, int* category,
567 * @param mlt_buffer pointer to mlt coefficients 569 * @param mlt_buffer pointer to mlt coefficients
568 */ 570 */
569 571
570static void mono_decode(COOKContext *q, float* mlt_buffer) { 572static void mono_decode(COOKContext *q, REAL_T* mlt_buffer) {
571 573
572 int category_index[128]; 574 int category_index[128];
573 int quant_index_table[102]; 575 int quant_index_table[102];
@@ -593,6 +595,7 @@ static void mono_decode(COOKContext *q, float* mlt_buffer) {
593 * @param gain_index_next index for the next block multiplier 595 * @param gain_index_next index for the next block multiplier
594 */ 596 */
595 597
598#if 0
596static void interpolate_float(COOKContext *q, float* buffer, 599static void interpolate_float(COOKContext *q, float* buffer,
597 int gain_index, int gain_index_next){ 600 int gain_index, int gain_index_next){
598 int i; 601 int i;
@@ -613,6 +616,7 @@ static void interpolate_float(COOKContext *q, float* buffer,
613 return; 616 return;
614 } 617 }
615} 618}
619#endif
616 620
617/** 621/**
618 * Apply transform window, overlap buffers. 622 * Apply transform window, overlap buffers.
@@ -652,12 +656,12 @@ static void imlt_window_float (COOKContext *q, float *buffer1,
652 * @param gains_ptr current and previous gains 656 * @param gains_ptr current and previous gains
653 * @param previous_buffer pointer to the previous buffer to be used for overlapping 657 * @param previous_buffer pointer to the previous buffer to be used for overlapping
654 */ 658 */
655 659#if 0
656static void imlt_gain(COOKContext *q, float *inbuffer, 660static void imlt_gain(COOKContext *q, REAL_T *inbuffer,
657 cook_gains *gains_ptr, float* previous_buffer) 661 cook_gains *gains_ptr, REAL_T* previous_buffer)
658{ 662{
659 float *buffer0 = q->mono_mdct_output; 663 REAL_T *buffer0 = q->mono_mdct_output;
660 float *buffer1 = q->mono_mdct_output + q->samples_per_channel; 664 REAL_T *buffer1 = q->mono_mdct_output + q->samples_per_channel;
661 int i; 665 int i;
662 666
663 /* Inverse modified discrete cosine transform */ 667 /* Inverse modified discrete cosine transform */
@@ -676,7 +680,7 @@ static void imlt_gain(COOKContext *q, float *inbuffer,
676 memcpy(previous_buffer, buffer0, sizeof(float)*q->samples_per_channel); 680 memcpy(previous_buffer, buffer0, sizeof(float)*q->samples_per_channel);
677} 681}
678 682
679 683#endif
680/** 684/**
681 * function for getting the jointstereo coupling information 685 * function for getting the jointstereo coupling information
682 * 686 *
@@ -720,9 +724,9 @@ static void decouple_info(COOKContext *q, int* decouple_tab){
720 */ 724 */
721static void decouple_float (COOKContext *q, 725static void decouple_float (COOKContext *q,
722 int subband, 726 int subband,
723 float f1, float f2, 727 REAL_T f1, REAL_T f2,
724 float *decode_buffer, 728 REAL_T *decode_buffer,
725 float *mlt_buffer1, float *mlt_buffer2) 729 REAL_T *mlt_buffer1, REAL_T *mlt_buffer2)
726{ 730{
727 int j, tmp_idx; 731 int j, tmp_idx;
728 for (j=0 ; j<SUBBAND_SIZE ; j++) { 732 for (j=0 ; j<SUBBAND_SIZE ; j++) {
@@ -740,21 +744,19 @@ static void decouple_float (COOKContext *q,
740 * @param mlt_buffer2 pointer to right channel mlt coefficients 744 * @param mlt_buffer2 pointer to right channel mlt coefficients
741 */ 745 */
742 746
743static void joint_decode(COOKContext *q, float* mlt_buffer1, 747static void joint_decode(COOKContext *q, REAL_T* mlt_buffer1,
744 float* mlt_buffer2) { 748 REAL_T* mlt_buffer2) {
745 int i,j; 749 int i,j;
746 int decouple_tab[SUBBAND_SIZE]; 750 int decouple_tab[SUBBAND_SIZE];
747 float *decode_buffer = q->decode_buffer_0; 751 REAL_T *decode_buffer = q->decode_buffer_0;
748 int idx, cpl_tmp; 752 int idx;
749 float f1,f2;
750 const float* cplscale;
751 753
752 memset(decouple_tab, 0, sizeof(decouple_tab)); 754 memset(decouple_tab, 0, sizeof(decouple_tab));
753 memset(decode_buffer, 0, sizeof(decode_buffer)); 755 memset(decode_buffer, 0, sizeof(decode_buffer));
754 756
755 /* Make sure the buffers are zeroed out. */ 757 /* Make sure the buffers are zeroed out. */
756 memset(mlt_buffer1,0, 1024*sizeof(float)); 758 memset(mlt_buffer1,0, 1024*sizeof(REAL_T));
757 memset(mlt_buffer2,0, 1024*sizeof(float)); 759 memset(mlt_buffer2,0, 1024*sizeof(REAL_T));
758 decouple_info(q, decouple_tab); 760 decouple_info(q, decouple_tab);
759 mono_decode(q, decode_buffer); 761 mono_decode(q, decode_buffer);
760 762
@@ -770,13 +772,13 @@ static void joint_decode(COOKContext *q, float* mlt_buffer1,
770 the coefficients are stored in a coupling scheme. */ 772 the coefficients are stored in a coupling scheme. */
771 idx = (1 << q->js_vlc_bits) - 1; 773 idx = (1 << q->js_vlc_bits) - 1;
772 for (i=q->js_subband_start ; i<q->subbands ; i++) { 774 for (i=q->js_subband_start ; i<q->subbands ; i++) {
773 cpl_tmp = cplband[i]; 775 int i1 = decouple_tab[cplband[i]];
774 idx -=decouple_tab[cpl_tmp]; 776 int i2 = idx - i1 - 1;
775 cplscale = q->cplscales[q->js_vlc_bits-2]; //choose decoupler table 777 for (j=0 ; j<SUBBAND_SIZE ; j++) {
776 f1 = cplscale[decouple_tab[cpl_tmp]]; 778 REAL_T x = decode_buffer[((q->js_subband_start + i)*20)+j];
777 f2 = cplscale[idx-1]; 779 mlt_buffer1[20*i+j] = cplscale_math(x, q->js_vlc_bits, i1);
778 q->decouple (q, i, f1, f2, decode_buffer, mlt_buffer1, mlt_buffer2); 780 mlt_buffer2[20*i+j] = cplscale_math(x, q->js_vlc_bits, i2);
779 idx = (1 << q->js_vlc_bits) - 1; 781 }
780 } 782 }
781} 783}
782 784
@@ -818,7 +820,7 @@ static void
818saturate_output_float (COOKContext *q, int chan, int16_t *out) 820saturate_output_float (COOKContext *q, int chan, int16_t *out)
819{ 821{
820 int j; 822 int j;
821 float *output = q->mono_mdct_output + q->samples_per_channel; 823 float *output = (float*)q->mono_mdct_output + q->samples_per_channel;
822 /* Clip and convert floats to 16 bits. 824 /* Clip and convert floats to 16 bits.
823 */ 825 */
824 for (j = 0; j < q->samples_per_channel; j++) { 826 for (j = 0; j < q->samples_per_channel; j++) {
@@ -841,12 +843,29 @@ saturate_output_float (COOKContext *q, int chan, int16_t *out)
841 */ 843 */
842 844
843static inline void 845static inline void
844mlt_compensate_output(COOKContext *q, float *decode_buffer, 846mlt_compensate_output(COOKContext *q, REAL_T *decode_buffer,
845 cook_gains *gains, float *previous_buffer, 847 cook_gains *gains, REAL_T *previous_buffer,
846 int16_t *out, int chan) 848 int16_t *out, int chan)
847{ 849{
848 imlt_gain(q, decode_buffer, gains, previous_buffer); 850 REAL_T *buffer = q->mono_mdct_output;
849 q->saturate_output (q, chan, out); 851 int i;
852 imlt_math(q, decode_buffer);
853
854 /* Overlap with the previous block. */
855 overlap_math(q, gains->previous[0], previous_buffer);
856
857 /* Apply gain profile */
858 for (i = 0; i < 8; i++) {
859 if (gains->now[i] || gains->now[i + 1])
860 interpolate_math(q, &buffer[q->samples_per_channel/8 * i],
861 gains->now[i], gains->now[i + 1]);
862 }
863
864 /* Save away the current to be previous block. */
865 memcpy(previous_buffer, buffer+q->samples_per_channel,
866 sizeof(REAL_T)*q->samples_per_channel);
867
868 output_math(q, out, chan);
850} 869}
851 870
852 871
@@ -946,6 +965,7 @@ static void dump_cook_context(COOKContext *q)
946} 965}
947#endif 966#endif
948 967
968#if 0
949static av_cold int cook_count_channels(unsigned int mask){ 969static av_cold int cook_count_channels(unsigned int mask){
950 int i; 970 int i;
951 int channels = 0; 971 int channels = 0;
@@ -955,6 +975,7 @@ static av_cold int cook_count_channels(unsigned int mask){
955 } 975 }
956 return channels; 976 return channels;
957} 977}
978#endif
958 979
959/** 980/**
960 * Cook initialization 981 * Cook initialization
@@ -1077,10 +1098,10 @@ av_cold int cook_decode_init(RMContext *rmctx, COOKContext *q)
1077 1098
1078 /* Initialize COOK signal arithmetic handling */ 1099 /* Initialize COOK signal arithmetic handling */
1079 if (1) { 1100 if (1) {
1080 q->scalar_dequant = scalar_dequant_float; 1101 q->scalar_dequant = scalar_dequant_math;
1081 q->decouple = decouple_float; 1102 q->decouple = decouple_float;
1082 q->imlt_window = imlt_window_float; 1103 q->imlt_window = imlt_window_float;
1083 q->interpolate = interpolate_float; 1104 q->interpolate = interpolate_math;
1084 q->saturate_output = saturate_output_float; 1105 q->saturate_output = saturate_output_float;
1085 } 1106 }
1086 1107
diff --git a/apps/codecs/libcook/cook.h b/apps/codecs/libcook/cook.h
index 8d4c078f1a..c4c06cd4f1 100644
--- a/apps/codecs/libcook/cook.h
+++ b/apps/codecs/libcook/cook.h
@@ -19,7 +19,6 @@
19 * License along with FFmpeg; if not, write to the Free Software 19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */ 21 */
22
23#ifndef _COOK_H 22#ifndef _COOK_H
24#define _COOK_H 23#define _COOK_H
25 24
@@ -29,6 +28,7 @@
29#include "dsputil.h" 28#include "dsputil.h"
30#include "bytestream.h" 29#include "bytestream.h"
31#include "rm2wav.h" 30#include "rm2wav.h"
31#include "cookdata_fixpoint.h"
32 32
33typedef struct { 33typedef struct {
34 int *now; 34 int *now;
@@ -42,18 +42,18 @@ typedef struct cook {
42 */ 42 */
43 void (* scalar_dequant)(struct cook *q, int index, int quant_index, 43 void (* scalar_dequant)(struct cook *q, int index, int quant_index,
44 int* subband_coef_index, int* subband_coef_sign, 44 int* subband_coef_index, int* subband_coef_sign,
45 float* mlt_p); 45 REAL_T* mlt_p);
46 46
47 void (* decouple) (struct cook *q, 47 void (* decouple) (struct cook *q,
48 int subband, 48 int subband,
49 float f1, float f2, 49 REAL_T f1, REAL_T f2,
50 float *decode_buffer, 50 REAL_T *decode_buffer,
51 float *mlt_buffer1, float *mlt_buffer2); 51 REAL_T *mlt_buffer1, REAL_T *mlt_buffer2);
52 52
53 void (* imlt_window) (struct cook *q, float *buffer1, 53 void (* imlt_window) (struct cook *q, float *buffer1,
54 cook_gains *gains_ptr, float *previous_buffer); 54 cook_gains *gains_ptr, float *previous_buffer);
55 55
56 void (* interpolate) (struct cook *q, float* buffer, 56 void (* interpolate) (struct cook *q, REAL_T* buffer,
57 int gain_index, int gain_index_next); 57 int gain_index, int gain_index_next);
58 58
59 void (* saturate_output) (struct cook *q, int chan, int16_t *out); 59 void (* saturate_output) (struct cook *q, int chan, int16_t *out);
@@ -104,12 +104,12 @@ typedef struct cook {
104 /* data buffers */ 104 /* data buffers */
105 105
106 uint8_t* decoded_bytes_buffer; 106 uint8_t* decoded_bytes_buffer;
107 float mono_mdct_output[2048] __attribute__ ((aligned(16))); //DECLARE_ALIGNED_16(float,mono_mdct_output[2048]); 107 REAL_T mono_mdct_output[2048] __attribute__ ((aligned(16))); //DECLARE_ALIGNED_16(float,mono_mdct_output[2048]);
108 float mono_previous_buffer1[1024]; 108 REAL_T mono_previous_buffer1[1024];
109 float mono_previous_buffer2[1024]; 109 REAL_T mono_previous_buffer2[1024];
110 float decode_buffer_1[1024]; 110 REAL_T decode_buffer_1[1024];
111 float decode_buffer_2[1024]; 111 REAL_T decode_buffer_2[1024];
112 float decode_buffer_0[1060]; /* static allocation for joint decode */ 112 REAL_T decode_buffer_0[1060]; /* static allocation for joint decode */
113 113
114 const float *cplscales[5]; 114 const float *cplscales[5];
115} COOKContext; 115} COOKContext;
diff --git a/apps/codecs/libcook/cook_fixp_mdct.h b/apps/codecs/libcook/cook_fixp_mdct.h
new file mode 100644
index 0000000000..dcd6d96227
--- /dev/null
+++ b/apps/codecs/libcook/cook_fixp_mdct.h
@@ -0,0 +1,545 @@
1/*
2 * The following (normalized modified discrete cosine transform)
3 * is taken from the OggVorbis 'TREMOR' source code.
4 *
5 * It has been modified for the ffmpeg cook fixed point decoder.
6 */
7
8/********************************************************************
9 * *
10 * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002 *
11 * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ *
12 * *
13 ********************************************************************
14
15 Redistribution and use in source and binary forms, with or without
16 modification, are permitted provided that the following conditions
17 are met:
18
19 - Redistributions of source code must retain the above copyright
20 notice, this list of conditions and the following disclaimer.
21
22 - Redistributions in binary form must reproduce the above copyright
23 notice, this list of conditions and the following disclaimer in the
24 documentation and/or other materials provided with the distribution.
25
26 - Neither the name of the Xiph.org Foundation nor the names of its
27 contributors may be used to endorse or promote products derived from
28 this software without specific prior written permission.
29
30 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
31 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
32 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
33 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION
34 OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
35 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
36 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
37 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
38 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
39 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
40 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41
42 *********************************************************************
43
44 function: normalized modified discrete cosine transform
45 power of two length transform only [64 <= n ]
46 last mod: $Id: mdct.c 14281 2004-12-30 12:11:32Z henry $
47
48 Original algorithm adapted long ago from _The use of multirate filter
49 banks for coding of high quality digital audio_, by T. Sporer,
50 K. Brandenburg and B. Edler, collection of the European Signal
51 Processing Conference (EUSIPCO), Amsterdam, June 1992, Vol.1, pp
52 211-214
53
54 The below code implements an algorithm that no longer looks much like
55 that presented in the paper, but the basic structure remains if you
56 dig deep enough to see it.
57
58 This module DOES NOT INCLUDE code to generate/apply the window
59 function. Everybody has their own weird favorite including me... I
60 happen to like the properties of y=sin(.5PI*sin^2(x)), but others may
61 vehemently disagree.
62
63 ********************************************************************/
64
65#define STIN static inline
66
67typedef int32_t ogg_int32_t;
68
69#define DATA_TYPE ogg_int32_t
70#define REG_TYPE register ogg_int32_t
71#define LOOKUP_T const uint16_t
72
73static inline ogg_int32_t MULT32(ogg_int32_t x, ogg_int32_t y) {
74 return fixp_mult_su(x, y) >> 1;
75}
76
77static inline ogg_int32_t MULT31(ogg_int32_t x, ogg_int32_t y) {
78 return fixp_mult_su(x, y);
79}
80
81/*
82 * This should be used as a memory barrier, forcing all cached values in
83 * registers to wr writen back to memory. Might or might not be beneficial
84 * depending on the architecture and compiler.
85 */
86#define MB()
87
88/*
89 * The XPROD functions are meant to optimize the cross products found all
90 * over the place in mdct.c by forcing memory operation ordering to avoid
91 * unnecessary register reloads as soon as memory is being written to.
92 * However this is only beneficial on CPUs with a sane number of general
93 * purpose registers which exclude the Intel x86. On Intel, better let the
94 * compiler actually reload registers directly from original memory by using
95 * macros.
96 */
97
98#ifdef __i386__
99
100#define XPROD32(_a, _b, _t, _v, _x, _y) \
101 { *(_x)=MULT32(_a,_t)+MULT32(_b,_v); \
102 *(_y)=MULT32(_b,_t)-MULT32(_a,_v); }
103#define XPROD31(_a, _b, _t, _v, _x, _y) \
104 { *(_x)=MULT31(_a,_t)+MULT31(_b,_v); \
105 *(_y)=MULT31(_b,_t)-MULT31(_a,_v); }
106#define XNPROD31(_a, _b, _t, _v, _x, _y) \
107 { *(_x)=MULT31(_a,_t)-MULT31(_b,_v); \
108 *(_y)=MULT31(_b,_t)+MULT31(_a,_v); }
109
110#else
111
112static inline void XPROD32(ogg_int32_t a, ogg_int32_t b,
113 ogg_int32_t t, ogg_int32_t v,
114 ogg_int32_t *x, ogg_int32_t *y)
115{
116 *x = MULT32(a, t) + MULT32(b, v);
117 *y = MULT32(b, t) - MULT32(a, v);
118}
119
120static inline void XPROD31(ogg_int32_t a, ogg_int32_t b,
121 ogg_int32_t t, ogg_int32_t v,
122 ogg_int32_t *x, ogg_int32_t *y)
123{
124 *x = MULT31(a, t) + MULT31(b, v);
125 *y = MULT31(b, t) - MULT31(a, v);
126}
127
128static inline void XNPROD31(ogg_int32_t a, ogg_int32_t b,
129 ogg_int32_t t, ogg_int32_t v,
130 ogg_int32_t *x, ogg_int32_t *y)
131{
132 *x = MULT31(a, t) - MULT31(b, v);
133 *y = MULT31(b, t) + MULT31(a, v);
134}
135
136#endif
137
138
139/* 8 point butterfly (in place) */
140STIN void mdct_butterfly_8(DATA_TYPE *x){
141
142 REG_TYPE r0 = x[4] + x[0];
143 REG_TYPE r1 = x[4] - x[0];
144 REG_TYPE r2 = x[5] + x[1];
145 REG_TYPE r3 = x[5] - x[1];
146 REG_TYPE r4 = x[6] + x[2];
147 REG_TYPE r5 = x[6] - x[2];
148 REG_TYPE r6 = x[7] + x[3];
149 REG_TYPE r7 = x[7] - x[3];
150
151 x[0] = r5 + r3;
152 x[1] = r7 - r1;
153 x[2] = r5 - r3;
154 x[3] = r7 + r1;
155 x[4] = r4 - r0;
156 x[5] = r6 - r2;
157 x[6] = r4 + r0;
158 x[7] = r6 + r2;
159 MB();
160}
161
162/* 16 point butterfly (in place, 4 register) */
163STIN void mdct_butterfly_16(DATA_TYPE *x){
164
165 REG_TYPE r0, r1;
166
167 r0 = x[ 0] - x[ 8]; x[ 8] += x[ 0];
168 r1 = x[ 1] - x[ 9]; x[ 9] += x[ 1];
169 x[ 0] = MULT31((r0 + r1) , cPI2_8);
170 x[ 1] = MULT31((r1 - r0) , cPI2_8);
171 MB();
172
173 r0 = x[10] - x[ 2]; x[10] += x[ 2];
174 r1 = x[ 3] - x[11]; x[11] += x[ 3];
175 x[ 2] = r1; x[ 3] = r0;
176 MB();
177
178 r0 = x[12] - x[ 4]; x[12] += x[ 4];
179 r1 = x[13] - x[ 5]; x[13] += x[ 5];
180 x[ 4] = MULT31((r0 - r1) , cPI2_8);
181 x[ 5] = MULT31((r0 + r1) , cPI2_8);
182 MB();
183
184 r0 = x[14] - x[ 6]; x[14] += x[ 6];
185 r1 = x[15] - x[ 7]; x[15] += x[ 7];
186 x[ 6] = r0; x[ 7] = r1;
187 MB();
188
189 mdct_butterfly_8(x);
190 mdct_butterfly_8(x+8);
191}
192
193/* 32 point butterfly (in place, 4 register) */
194STIN void mdct_butterfly_32(DATA_TYPE *x){
195
196 REG_TYPE r0, r1;
197
198 r0 = x[30] - x[14]; x[30] += x[14];
199 r1 = x[31] - x[15]; x[31] += x[15];
200 x[14] = r0; x[15] = r1;
201 MB();
202
203 r0 = x[28] - x[12]; x[28] += x[12];
204 r1 = x[29] - x[13]; x[29] += x[13];
205 XNPROD31( r0, r1, cPI1_8, cPI3_8, &x[12], &x[13] );
206 MB();
207
208 r0 = x[26] - x[10]; x[26] += x[10];
209 r1 = x[27] - x[11]; x[27] += x[11];
210 x[10] = MULT31((r0 - r1) , cPI2_8);
211 x[11] = MULT31((r0 + r1) , cPI2_8);
212 MB();
213
214 r0 = x[24] - x[ 8]; x[24] += x[ 8];
215 r1 = x[25] - x[ 9]; x[25] += x[ 9];
216 XNPROD31( r0, r1, cPI3_8, cPI1_8, &x[ 8], &x[ 9] );
217 MB();
218
219 r0 = x[22] - x[ 6]; x[22] += x[ 6];
220 r1 = x[ 7] - x[23]; x[23] += x[ 7];
221 x[ 6] = r1; x[ 7] = r0;
222 MB();
223
224 r0 = x[ 4] - x[20]; x[20] += x[ 4];
225 r1 = x[ 5] - x[21]; x[21] += x[ 5];
226 XPROD31 ( r0, r1, cPI3_8, cPI1_8, &x[ 4], &x[ 5] );
227 MB();
228
229 r0 = x[ 2] - x[18]; x[18] += x[ 2];
230 r1 = x[ 3] - x[19]; x[19] += x[ 3];
231 x[ 2] = MULT31((r1 + r0) , cPI2_8);
232 x[ 3] = MULT31((r1 - r0) , cPI2_8);
233 MB();
234
235 r0 = x[ 0] - x[16]; x[16] += x[ 0];
236 r1 = x[ 1] - x[17]; x[17] += x[ 1];
237 XPROD31 ( r0, r1, cPI1_8, cPI3_8, &x[ 0], &x[ 1] );
238 MB();
239
240 mdct_butterfly_16(x);
241 mdct_butterfly_16(x+16);
242}
243
244/* N/stage point generic N stage butterfly (in place, 2 register) */
245STIN void mdct_butterfly_generic(DATA_TYPE *x,int points,int step){
246
247 LOOKUP_T *T = sincos_lookup;
248 DATA_TYPE *x1 = x + points - 8;
249 DATA_TYPE *x2 = x + (points>>1) - 8;
250 REG_TYPE r0;
251 REG_TYPE r1;
252
253 //av_log(0, 0, "bfly: points=%d, step=%d\n", points, step);
254
255 do{
256 r0 = x1[6] - x2[6]; x1[6] += x2[6];
257 r1 = x2[7] - x1[7]; x1[7] += x2[7];
258 XPROD31( r1, r0, T[0], T[1], &x2[6], &x2[7] ); T+=step;
259
260 r0 = x1[4] - x2[4]; x1[4] += x2[4];
261 r1 = x2[5] - x1[5]; x1[5] += x2[5];
262 XPROD31( r1, r0, T[0], T[1], &x2[4], &x2[5] ); T+=step;
263
264 r0 = x1[2] - x2[2]; x1[2] += x2[2];
265 r1 = x2[3] - x1[3]; x1[3] += x2[3];
266 XPROD31( r1, r0, T[0], T[1], &x2[2], &x2[3] ); T+=step;
267
268 r0 = x1[0] - x2[0]; x1[0] += x2[0];
269 r1 = x2[1] - x1[1]; x1[1] += x2[1];
270 XPROD31( r1, r0, T[0], T[1], &x2[0], &x2[1] ); T+=step;
271
272 x1-=8; x2-=8;
273 }while(T<sincos_lookup+2048);
274 do{
275 r0 = x1[6] - x2[6]; x1[6] += x2[6];
276 r1 = x1[7] - x2[7]; x1[7] += x2[7];
277 XNPROD31( r0, r1, T[0], T[1], &x2[6], &x2[7] ); T-=step;
278
279 r0 = x1[4] - x2[4]; x1[4] += x2[4];
280 r1 = x1[5] - x2[5]; x1[5] += x2[5];
281 XNPROD31( r0, r1, T[0], T[1], &x2[4], &x2[5] ); T-=step;
282
283 r0 = x1[2] - x2[2]; x1[2] += x2[2];
284 r1 = x1[3] - x2[3]; x1[3] += x2[3];
285 XNPROD31( r0, r1, T[0], T[1], &x2[2], &x2[3] ); T-=step;
286
287 r0 = x1[0] - x2[0]; x1[0] += x2[0];
288 r1 = x1[1] - x2[1]; x1[1] += x2[1];
289 XNPROD31( r0, r1, T[0], T[1], &x2[0], &x2[1] ); T-=step;
290
291 x1-=8; x2-=8;
292 }while(T>sincos_lookup);
293 do{
294 r0 = x2[6] - x1[6]; x1[6] += x2[6];
295 r1 = x2[7] - x1[7]; x1[7] += x2[7];
296 XPROD31( r0, r1, T[0], T[1], &x2[6], &x2[7] ); T+=step;
297
298 r0 = x2[4] - x1[4]; x1[4] += x2[4];
299 r1 = x2[5] - x1[5]; x1[5] += x2[5];
300 XPROD31( r0, r1, T[0], T[1], &x2[4], &x2[5] ); T+=step;
301
302 r0 = x2[2] - x1[2]; x1[2] += x2[2];
303 r1 = x2[3] - x1[3]; x1[3] += x2[3];
304 XPROD31( r0, r1, T[0], T[1], &x2[2], &x2[3] ); T+=step;
305
306 r0 = x2[0] - x1[0]; x1[0] += x2[0];
307 r1 = x2[1] - x1[1]; x1[1] += x2[1];
308 XPROD31( r0, r1, T[0], T[1], &x2[0], &x2[1] ); T+=step;
309
310 x1-=8; x2-=8;
311 }while(T<sincos_lookup+2048);
312 do{
313 r0 = x1[6] - x2[6]; x1[6] += x2[6];
314 r1 = x2[7] - x1[7]; x1[7] += x2[7];
315 XNPROD31( r1, r0, T[0], T[1], &x2[6], &x2[7] ); T-=step;
316
317 r0 = x1[4] - x2[4]; x1[4] += x2[4];
318 r1 = x2[5] - x1[5]; x1[5] += x2[5];
319 XNPROD31( r1, r0, T[0], T[1], &x2[4], &x2[5] ); T-=step;
320
321 r0 = x1[2] - x2[2]; x1[2] += x2[2];
322 r1 = x2[3] - x1[3]; x1[3] += x2[3];
323 XNPROD31( r1, r0, T[0], T[1], &x2[2], &x2[3] ); T-=step;
324
325 r0 = x1[0] - x2[0]; x1[0] += x2[0];
326 r1 = x2[1] - x1[1]; x1[1] += x2[1];
327 XNPROD31( r1, r0, T[0], T[1], &x2[0], &x2[1] ); T-=step;
328
329 x1-=8; x2-=8;
330 }while(T>sincos_lookup);
331}
332
333STIN void mdct_butterflies(DATA_TYPE *x,int points,int shift){
334
335 int stages=8-shift;
336 int i,j;
337
338 for(i=0;--stages>0;i++){
339 for(j=0;j<(1<<i);j++)
340 mdct_butterfly_generic(x+(points>>i)*j,points>>i,8<<(i+shift));
341 }
342
343 for(j=0;j<points;j+=32)
344 mdct_butterfly_32(x+j);
345
346}
347
348static unsigned char bitrev[16]={0,8,4,12,2,10,6,14,1,9,5,13,3,11,7,15};
349
350STIN int bitrev12(int x){
351 return bitrev[x>>8]|(bitrev[(x&0x0f0)>>4]<<4)|(((int)bitrev[x&0x00f])<<8);
352}
353
354STIN void mdct_bitreverse(DATA_TYPE *x,int n,int step,int shift){
355
356 int bit = 0;
357 DATA_TYPE *w0 = x;
358 DATA_TYPE *w1 = x = w0+(n>>1);
359 LOOKUP_T *T = sincos_lookup+(step>>1);
360 LOOKUP_T *Ttop = T+2048;
361 DATA_TYPE r2;
362
363 //av_log(0, 0, "brev: shift=%d, step=%d\n", shift, step);
364
365 do{
366 DATA_TYPE r3 = bitrev12(bit++);
367 DATA_TYPE *x0 = x + ((r3 ^ 0xfff)>>shift) -1;
368 DATA_TYPE *x1 = x + (r3>>shift);
369
370 REG_TYPE r0 = x0[0] + x1[0];
371 REG_TYPE r1 = x1[1] - x0[1];
372
373 XPROD32( r0, r1, T[1], T[0], &r2, &r3 ); T+=step;
374
375 w1 -= 4;
376
377 r0 = (x0[1] + x1[1])>>1;
378 r1 = (x0[0] - x1[0])>>1;
379 w0[0] = r0 + r2;
380 w0[1] = r1 + r3;
381 w1[2] = r0 - r2;
382 w1[3] = r3 - r1;
383
384 r3 = bitrev12(bit++);
385 x0 = x + ((r3 ^ 0xfff)>>shift) -1;
386 x1 = x + (r3>>shift);
387
388 r0 = x0[0] + x1[0];
389 r1 = x1[1] - x0[1];
390
391 XPROD32( r0, r1, T[1], T[0], &r2, &r3 ); T+=step;
392
393 r0 = (x0[1] + x1[1])>>1;
394 r1 = (x0[0] - x1[0])>>1;
395 w0[2] = r0 + r2;
396 w0[3] = r1 + r3;
397 w1[0] = r0 - r2;
398 w1[1] = r3 - r1;
399
400 w0 += 4;
401 }while(T<Ttop);
402 do{
403 DATA_TYPE r3 = bitrev12(bit++);
404 DATA_TYPE *x0 = x + ((r3 ^ 0xfff)>>shift) -1;
405 DATA_TYPE *x1 = x + (r3>>shift);
406
407 REG_TYPE r0 = x0[0] + x1[0];
408 REG_TYPE r1 = x1[1] - x0[1];
409
410 T-=step; XPROD32( r0, r1, T[0], T[1], &r2, &r3 );
411
412 w1 -= 4;
413
414 r0 = (x0[1] + x1[1])>>1;
415 r1 = (x0[0] - x1[0])>>1;
416 w0[0] = r0 + r2;
417 w0[1] = r1 + r3;
418 w1[2] = r0 - r2;
419 w1[3] = r3 - r1;
420
421 r3 = bitrev12(bit++);
422 x0 = x + ((r3 ^ 0xfff)>>shift) -1;
423 x1 = x + (r3>>shift);
424
425 r0 = x0[0] + x1[0];
426 r1 = x1[1] - x0[1];
427
428 T-=step; XPROD32( r0, r1, T[0], T[1], &r2, &r3 );
429
430 r0 = (x0[1] + x1[1])>>1;
431 r1 = (x0[0] - x1[0])>>1;
432 w0[2] = r0 + r2;
433 w0[3] = r1 + r3;
434 w1[0] = r0 - r2;
435 w1[1] = r3 - r1;
436
437 w0 += 4;
438 }while(w0<w1);
439}
440
441STIN void cook_mdct_backward(int n, DATA_TYPE *in, DATA_TYPE *out){
442 int n2=n>>1;
443 int n4=n>>2;
444 DATA_TYPE *iX;
445 DATA_TYPE *oX;
446 LOOKUP_T *T;
447 int shift;
448 int step;
449
450 for (shift=6;!(n&(1<<shift));shift++);
451
452 shift=13-shift;
453 step=4<<shift;
454 //step=16;
455 //av_log(0, 0, "mdct: shift=%d, step=%d\n", shift, step);
456
457 /* rotate */
458
459 iX = in+n2-7;
460 oX = out+n2+n4;
461 T = sincos_lookup;
462
463 do{
464 oX-=4;
465 XPROD31( iX[4], iX[6], T[0], T[1], &oX[2], &oX[3] ); T+=step;
466 XPROD31( iX[0], iX[2], T[0], T[1], &oX[0], &oX[1] ); T+=step;
467 iX-=8;
468 }while(iX>=in+n4);
469 do{
470 oX-=4;
471 XPROD31( iX[4], iX[6], T[1], T[0], &oX[2], &oX[3] ); T-=step;
472 XPROD31( iX[0], iX[2], T[1], T[0], &oX[0], &oX[1] ); T-=step;
473 iX-=8;
474 }while(iX>=in);
475
476 iX = in+n2-8;
477 oX = out+n2+n4;
478 T = sincos_lookup;
479
480 do{
481 T+=step; XNPROD31( iX[6], iX[4], T[0], T[1], &oX[0], &oX[1] );
482 T+=step; XNPROD31( iX[2], iX[0], T[0], T[1], &oX[2], &oX[3] );
483 iX-=8;
484 oX+=4;
485 }while(iX>=in+n4);
486 do{
487 T-=step; XNPROD31( iX[6], iX[4], T[1], T[0], &oX[0], &oX[1] );
488 T-=step; XNPROD31( iX[2], iX[0], T[1], T[0], &oX[2], &oX[3] );
489 iX-=8;
490 oX+=4;
491 }while(iX>=in);
492
493 mdct_butterflies(out+n2,n2,shift);
494 mdct_bitreverse(out,n,step,shift);
495
496 /* rotate */
497
498 step>>=2;
499 //step=4;
500 {
501 DATA_TYPE *oX1=out+n2+n4;
502 DATA_TYPE *oX2=out+n2+n4;
503 DATA_TYPE *iX =out;
504
505 T=sincos_lookup+(step>>1);
506 do{
507 oX1-=4;
508 XPROD31( iX[0], -iX[1], T[0], T[1], &oX1[3], &oX2[0] ); T+=step;
509 XPROD31( iX[2], -iX[3], T[0], T[1], &oX1[2], &oX2[1] ); T+=step;
510 XPROD31( iX[4], -iX[5], T[0], T[1], &oX1[1], &oX2[2] ); T+=step;
511 XPROD31( iX[6], -iX[7], T[0], T[1], &oX1[0], &oX2[3] ); T+=step;
512 oX2+=4;
513 iX+=8;
514 }while(iX<oX1);
515
516 iX=out+n2+n4;
517 oX1=out+n4;
518 oX2=oX1;
519
520 do{
521 oX1-=4;
522 iX-=4;
523
524 oX2[0] = -(oX1[3] = iX[3]);
525 oX2[1] = -(oX1[2] = iX[2]);
526 oX2[2] = -(oX1[1] = iX[1]);
527 oX2[3] = -(oX1[0] = iX[0]);
528
529 oX2+=4;
530 }while(oX2<iX);
531
532 iX=out+n2+n4;
533 oX1=out+n2+n4;
534 oX2=out+n2;
535
536 do{
537 oX1-=4;
538 oX1[0]= iX[3];
539 oX1[1]= iX[2];
540 oX1[2]= iX[1];
541 oX1[3]= iX[0];
542 iX+=4;
543 }while(oX1>oX2);
544 }
545}
diff --git a/apps/codecs/libcook/cook_fixpoint.h b/apps/codecs/libcook/cook_fixpoint.h
new file mode 100644
index 0000000000..b8182bfcd0
--- /dev/null
+++ b/apps/codecs/libcook/cook_fixpoint.h
@@ -0,0 +1,243 @@
1/*
2 * COOK compatible decoder, fixed point implementation.
3 * Copyright (c) 2007 Ian Braithwaite
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 *
21 */
22
23/**
24 * @file cook_float.h
25 *
26 * Cook AKA RealAudio G2 fixed point functions.
27 *
28 * Fixed point values are represented as 32 bit signed integers,
29 * which can be added and subtracted directly in C (without checks for
30 * overflow/saturation.
31 * Two multiplication routines are provided:
32 * 1) Multiplication by powers of two (2^-31 .. 2^31), implemented
33 * with C's bit shift operations.
34 * 2) Multiplication by 16 bit fractions (0 <= x < 1), implemented
35 * in C using two 32 bit integer multiplications.
36 */
37
38/**
39 * Initialise fixed point implementation.
40 * Nothing to do for fixed point.
41 *
42 * @param q pointer to the COOKContext
43 */
44static inline int init_cook_math(COOKContext *q)
45{
46 return 0;
47}
48
49/**
50 * Free resources used by floating point implementation.
51 * Nothing to do for fixed point.
52 *
53 * @param q pointer to the COOKContext
54 */
55static inline void free_cook_math(COOKContext *q)
56{
57 return;
58}
59
60
61/**
62 * Fixed point multiply by power of two.
63 *
64 * @param x fix point value
65 * @param i integer power-of-two, -31..+31
66 */
67static inline FIXP fixp_pow2(FIXP x, int i)
68{
69 if (i < 0)
70 return (x >> -i) + ((x >> (-i-1)) & 1);
71 else
72 return x << i; /* no check for overflow */
73}
74
75/**
76 * Fixed point multiply by fraction.
77 *
78 * @param a fix point value
79 * @param b fix point fraction, 0 <= b < 1
80 */
81static inline FIXP fixp_mult_su(FIXP a, FIXPU b)
82{
83 int32_t hb = (a >> 16) * b;
84 uint32_t lb = (a & 0xffff) * b;
85
86 return hb + (lb >> 16) + ((lb & 0x8000) >> 15);
87}
88
89
90/**
91 * The real requantization of the mltcoefs
92 *
93 * @param q pointer to the COOKContext
94 * @param index index
95 * @param quant_index quantisation index for this band
96 * @param subband_coef_index array of indexes to quant_centroid_tab
97 * @param subband_coef_sign use random noise instead of predetermined value
98 * @param mlt_ptr pointer to the mlt coefficients
99 */
100static void scalar_dequant_math(COOKContext *q, int index,
101 int quant_index, int* subband_coef_index,
102 int* subband_coef_sign, REAL_T *mlt_p)
103{
104 /* Num. half bits to right shift */
105 const int s = 33 - quant_index + av_log2(q->samples_per_channel);
106 const FIXP *table = quant_tables[s & 1][index];
107 FIXP f;
108 int i;
109
110 for(i=0 ; i<SUBBAND_SIZE ; i++) {
111 f = table[subband_coef_index[i]];
112 /* noise coding if subband_coef_index[i] == 0 */
113 if (((subband_coef_index[i] == 0) && av_lfg_get(&q->random_state) < 0x80000000) ||
114 ((subband_coef_index[i] != 0) && subband_coef_sign[i]))
115 f = -f;
116
117 mlt_p[i] = (s >= 64) ? 0 : fixp_pow2(f, -(s/2));
118 }
119}
120
121
122/**
123 * The modulated lapped transform, this takes transform coefficients
124 * and transforms them into timedomain samples.
125 * A window step is also included.
126 *
127 * @param q pointer to the COOKContext
128 * @param inbuffer pointer to the mltcoefficients
129 * @param outbuffer pointer to the timedomain buffer
130 * @param mlt_tmp pointer to temporary storage space
131 */
132#include "cook_fixp_mdct.h"
133
134static inline void imlt_math(COOKContext *q, FIXP *in)
135{
136 const int n = q->samples_per_channel;
137 const int step = 4 << (10 - av_log2(n));
138 int i = 0, j = step>>1;
139
140 cook_mdct_backward(2 * n, in, q->mono_mdct_output);
141
142 do {
143 FIXP tmp = q->mono_mdct_output[i];
144
145 q->mono_mdct_output[i] =
146 fixp_mult_su(-q->mono_mdct_output[n + i], sincos_lookup[j]);
147 q->mono_mdct_output[n + i] = fixp_mult_su(tmp, sincos_lookup[j+1]);
148 j += step;
149 } while (++i < n/2);
150 do {
151 FIXP tmp = q->mono_mdct_output[i];
152
153 j -= step;
154 q->mono_mdct_output[i] =
155 fixp_mult_su(-q->mono_mdct_output[n + i], sincos_lookup[j+1]);
156 q->mono_mdct_output[n + i] = fixp_mult_su(tmp, sincos_lookup[j]);
157 } while (++i < n);
158}
159
160
161/**
162 * Perform buffer overlapping.
163 *
164 * @param q pointer to the COOKContext
165 * @param gain gain correction to apply first to output buffer
166 * @param buffer data to overlap
167 */
168static inline void overlap_math(COOKContext *q, int gain, FIXP buffer[])
169{
170 int i;
171 for(i=0 ; i<q->samples_per_channel ; i++) {
172 q->mono_mdct_output[i] =
173 fixp_pow2(q->mono_mdct_output[i], gain) + buffer[i];
174 }
175}
176
177
178/**
179 * the actual requantization of the timedomain samples
180 *
181 * @param q pointer to the COOKContext
182 * @param buffer pointer to the timedomain buffer
183 * @param gain_index index for the block multiplier
184 * @param gain_index_next index for the next block multiplier
185 */
186static inline void
187interpolate_math(COOKContext *q, FIXP* buffer,
188 int gain_index, int gain_index_next)
189{
190 int i;
191 int gain_size_factor = q->samples_per_channel / 8;
192
193 if(gain_index == gain_index_next){ //static gain
194 for(i = 0; i < gain_size_factor; i++) {
195 buffer[i] = fixp_pow2(buffer[i], gain_index);
196 }
197 } else { //smooth gain
198 int step = (gain_index_next - gain_index)
199 << (7 - av_log2(gain_size_factor));
200 int x = 0;
201
202 for(i = 0; i < gain_size_factor; i++) {
203 buffer[i] = fixp_mult_su(buffer[i], pow128_tab[x]);
204 buffer[i] = fixp_pow2(buffer[i], gain_index+1);
205
206 x += step;
207 gain_index += (x + 128) / 128 - 1;
208 x = (x + 128) % 128;
209 }
210 }
211}
212
213
214/**
215 * Decoupling calculation for joint stereo coefficients.
216 *
217 * @param x mono coefficient
218 * @param table number of decoupling table
219 * @param i table index
220 */
221static inline FIXP cplscale_math(FIXP x, int table, int i)
222{
223 return fixp_mult_su(x, cplscales[table-2][i]);
224}
225
226
227/**
228 * Final converion from floating point values to
229 * signed, 16 bit sound samples. Round and clip.
230 *
231 * @param q pointer to the COOKContext
232 * @param out pointer to the output buffer
233 * @param chan 0: left or single channel, 1: right channel
234 */
235static inline void output_math(COOKContext *q, int16_t *out, int chan)
236{
237 int j;
238
239 for (j = 0; j < q->samples_per_channel; j++) {
240 out[chan + q->nb_channels * j] =
241 av_clip(fixp_pow2(q->mono_mdct_output[j], -11), -32768, 32767);
242 }
243}
diff --git a/apps/codecs/libcook/cookdata.h b/apps/codecs/libcook/cookdata.h
index e2e81fbab6..a73b96c5f5 100644
--- a/apps/codecs/libcook/cookdata.h
+++ b/apps/codecs/libcook/cookdata.h
@@ -18,38 +18,20 @@
18 * You should have received a copy of the GNU Lesser General Public 18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software 19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 *
21 */ 22 */
22 23
23/** 24/**
24 * @file libavcodec/cookdata.h 25 * @file cookdata.h
25 * Cook AKA RealAudio G2 compatible decoderdata 26 * Cook AKA RealAudio G2 compatible decoderdata
26 */ 27 */
27 28
28#ifndef AVCODEC_COOKDATA_H
29#define AVCODEC_COOKDATA_H
30
31#include <stdint.h>
32
33/* various data tables */ 29/* various data tables */
34 30
35static const int expbits_tab[8] = { 31static const int expbits_tab[8] = {
36 52,47,43,37,29,22,16,0, 32 52,47,43,37,29,22,16,0,
37}; 33};
38 34
39static const float dither_tab[8] = {
40 0.0, 0.0, 0.0, 0.0, 0.0, 0.176777, 0.25, 0.707107,
41};
42
43static const float quant_centroid_tab[7][14] = {
44 { 0.000, 0.392, 0.761, 1.120, 1.477, 1.832, 2.183, 2.541, 2.893, 3.245, 3.598, 3.942, 4.288, 4.724 },
45 { 0.000, 0.544, 1.060, 1.563, 2.068, 2.571, 3.072, 3.562, 4.070, 4.620, 0.000, 0.000, 0.000, 0.000 },
46 { 0.000, 0.746, 1.464, 2.180, 2.882, 3.584, 4.316, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000 },
47 { 0.000, 1.006, 2.000, 2.993, 3.985, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000 },
48 { 0.000, 1.321, 2.703, 3.983, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000 },
49 { 0.000, 1.657, 3.491, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000 },
50 { 0.000, 1.964, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000 }
51};
52
53static const int invradix_tab[7] = { 35static const int invradix_tab[7] = {
54 74899, 104858, 149797, 209716, 262144, 349526, 524288, 36 74899, 104858, 149797, 209716, 262144, 349526, 524288,
55}; 37};
@@ -422,12 +404,12 @@ static const uint16_t cvh_huffcodes6[32] = {
422 0x003c,0x01fc,0x00fb,0x03fd,0x00fc,0x03fe,0x01fd,0x07ff, 404 0x003c,0x01fc,0x00fb,0x03fd,0x00fc,0x03fe,0x01fd,0x07ff,
423}; 405};
424 406
425static const uint16_t* const cvh_huffcodes[7] = { 407static const uint16_t* cvh_huffcodes[7] = {
426 cvh_huffcodes0, cvh_huffcodes1, cvh_huffcodes2, cvh_huffcodes3, 408 cvh_huffcodes0, cvh_huffcodes1, cvh_huffcodes2, cvh_huffcodes3,
427 cvh_huffcodes4, cvh_huffcodes5, cvh_huffcodes6, 409 cvh_huffcodes4, cvh_huffcodes5, cvh_huffcodes6,
428}; 410};
429 411
430static const uint8_t* const cvh_huffbits[7] = { 412static const uint8_t* cvh_huffbits[7] = {
431 cvh_huffbits0, cvh_huffbits1, cvh_huffbits2, cvh_huffbits3, 413 cvh_huffbits0, cvh_huffbits1, cvh_huffbits2, cvh_huffbits3,
432 cvh_huffbits4, cvh_huffbits5, cvh_huffbits6, 414 cvh_huffbits4, cvh_huffbits5, cvh_huffbits6,
433}; 415};
@@ -488,12 +470,12 @@ static const uint8_t ccpl_huffbits6[63] = {
488 14,14,16, 470 14,14,16,
489}; 471};
490 472
491static const uint16_t* const ccpl_huffcodes[5] = { 473static const uint16_t* ccpl_huffcodes[5] = {
492 ccpl_huffcodes2,ccpl_huffcodes3, 474 ccpl_huffcodes2,ccpl_huffcodes3,
493 ccpl_huffcodes4,ccpl_huffcodes5,ccpl_huffcodes6 475 ccpl_huffcodes4,ccpl_huffcodes5,ccpl_huffcodes6
494}; 476};
495 477
496static const uint8_t* const ccpl_huffbits[5] = { 478static const uint8_t* ccpl_huffbits[5] = {
497 ccpl_huffbits2,ccpl_huffbits3, 479 ccpl_huffbits2,ccpl_huffbits3,
498 ccpl_huffbits4,ccpl_huffbits5,ccpl_huffbits6 480 ccpl_huffbits4,ccpl_huffbits5,ccpl_huffbits6
499}; 481};
@@ -509,55 +491,3 @@ static const int cplband[51] = {
509 18,18,19,19,19,19,19,19,19,19, 491 18,18,19,19,19,19,19,19,19,19,
510 19, 492 19,
511}; 493};
512
513static const float cplscale2[3] = {
5140.953020632266998,0.70710676908493,0.302905440330505,
515};
516
517static const float cplscale3[7] = {
5180.981279790401459,0.936997592449188,0.875934481620789,0.70710676908493,
5190.482430040836334,0.349335819482803,0.192587479948997,
520};
521
522static const float cplscale4[15] = {
5230.991486728191376,0.973249018192291,0.953020632266998,0.930133521556854,
5240.903453230857849,0.870746195316315,0.826180458068848,0.70710676908493,
5250.563405573368073,0.491732746362686,0.428686618804932,0.367221474647522,
5260.302905440330505,0.229752898216248,0.130207896232605,
527};
528
529static const float cplscale5[31] = {
5300.995926380157471,0.987517595291138,0.978726446628571,0.969505727291107,
5310.95979779958725,0.949531257152557,0.938616216182709,0.926936149597168,
5320.914336204528809,0.900602877140045,0.885426938533783,0.868331849575043,
5330.84851086139679,0.824381768703461,0.791833400726318,0.70710676908493,
5340.610737144947052,0.566034197807312,0.529177963733673,0.495983630418777,
5350.464778542518616,0.434642940759659,0.404955863952637,0.375219136476517,
5360.344963222742081,0.313672333955765,0.280692428350449,0.245068684220314,
5370.205169528722763,0.157508864998817,0.0901700109243393,
538};
539
540static const float cplscale6[63] = {
5410.998005926609039,0.993956744670868,0.989822506904602,0.985598564147949,
5420.981279790401459,0.976860702037811,0.972335040569305,0.967696130275726,
5430.962936460971832,0.958047747612000,0.953020632266998,0.947844684123993,
5440.942508161067963,0.936997592449188,0.931297719478607,0.925390899181366,
5450.919256627559662,0.912870943546295,0.906205296516418,0.899225592613220,
5460.891890347003937,0.884148240089417,0.875934481620789,0.867165684700012,
5470.857730865478516,0.847477376461029,0.836184680461884,0.823513329029083,
5480.808890223503113,0.791194140911102,0.767520070075989,0.707106769084930,
5490.641024887561798,0.611565053462982,0.587959706783295,0.567296981811523,
5500.548448026180267,0.530831515789032,0.514098942279816,0.498019754886627,
5510.482430040836334,0.467206478118896,0.452251672744751,0.437485188245773,
5520.422837972640991,0.408248275518417,0.393658757209778,0.379014074802399,
5530.364258885383606,0.349335819482803,0.334183186292648,0.318732559680939,
5540.302905440330505,0.286608695983887,0.269728302955627,0.252119421958923,
5550.233590632677078,0.213876649737358,0.192587479948997,0.169101938605309,
5560.142307326197624,0.109772264957428,0.0631198287010193,
557};
558
559static const float* const cplscales[5] = {
560 cplscale2, cplscale3, cplscale4, cplscale5, cplscale6,
561};
562
563#endif /* AVCODEC_COOKDATA_H */
diff --git a/apps/codecs/libcook/cookdata_fixpoint.h b/apps/codecs/libcook/cookdata_fixpoint.h
new file mode 100644
index 0000000000..10f5d35c07
--- /dev/null
+++ b/apps/codecs/libcook/cookdata_fixpoint.h
@@ -0,0 +1,433 @@
1/*
2 * COOK compatible decoder fixed point data types and constants
3 * Copyright (c) 2007 Ian Braithwaite
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 *
21 */
22
23/**
24 * @file cookdata_fixpoint.h
25 * Cook AKA RealAudio G2 compatible decoder
26 * fixed point data types and constants
27 */
28
29#include <stdint.h>
30typedef int32_t FIXP; /* Fixed point variable type */
31typedef uint16_t FIXPU; /* Fixed point fraction 0<=x<1 */
32
33typedef FIXP REAL_T;
34
35
36/* No additional variables in COOKContext
37 * for fixed point routines
38 */
39typedef struct {
40} realvars_t;
41
42
43#define cPI1_8 0xec83 /* 1pi/8 2^16 */
44#define cPI2_8 0xb505 /* 2pi/8 2^16 */
45#define cPI3_8 0x61f8 /* 3pi/8 2^16 */
46
47static const FIXPU sincos_lookup[2050] = {
48 /* x_i = 2^16 sin(i 2pi/8192), 2^16 cos(i 2pi/8192); i=0..1024 */
49 0x0000, 0xffff, 0x0032, 0xffff, 0x0065, 0xffff, 0x0097, 0xffff,
50 0x00c9, 0xffff, 0x00fb, 0xffff, 0x012e, 0xffff, 0x0160, 0xffff,
51 0x0192, 0xffff, 0x01c4, 0xfffe, 0x01f7, 0xfffe, 0x0229, 0xfffe,
52 0x025b, 0xfffd, 0x028d, 0xfffd, 0x02c0, 0xfffc, 0x02f2, 0xfffc,
53 0x0324, 0xfffb, 0x0356, 0xfffa, 0x0389, 0xfffa, 0x03bb, 0xfff9,
54 0x03ed, 0xfff8, 0x0420, 0xfff7, 0x0452, 0xfff7, 0x0484, 0xfff6,
55 0x04b6, 0xfff5, 0x04e9, 0xfff4, 0x051b, 0xfff3, 0x054d, 0xfff2,
56 0x057f, 0xfff1, 0x05b2, 0xfff0, 0x05e4, 0xffef, 0x0616, 0xffed,
57 0x0648, 0xffec, 0x067b, 0xffeb, 0x06ad, 0xffea, 0x06df, 0xffe8,
58 0x0711, 0xffe7, 0x0744, 0xffe6, 0x0776, 0xffe4, 0x07a8, 0xffe3,
59 0x07da, 0xffe1, 0x080d, 0xffe0, 0x083f, 0xffde, 0x0871, 0xffdc,
60 0x08a3, 0xffdb, 0x08d5, 0xffd9, 0x0908, 0xffd7, 0x093a, 0xffd5,
61 0x096c, 0xffd4, 0x099e, 0xffd2, 0x09d1, 0xffd0, 0x0a03, 0xffce,
62 0x0a35, 0xffcc, 0x0a67, 0xffca, 0x0a9a, 0xffc8, 0x0acc, 0xffc6,
63 0x0afe, 0xffc4, 0x0b30, 0xffc1, 0x0b62, 0xffbf, 0x0b95, 0xffbd,
64 0x0bc7, 0xffbb, 0x0bf9, 0xffb8, 0x0c2b, 0xffb6, 0x0c5d, 0xffb4,
65 0x0c90, 0xffb1, 0x0cc2, 0xffaf, 0x0cf4, 0xffac, 0x0d26, 0xffa9,
66 0x0d59, 0xffa7, 0x0d8b, 0xffa4, 0x0dbd, 0xffa2, 0x0def, 0xff9f,
67 0x0e21, 0xff9c, 0x0e53, 0xff99, 0x0e86, 0xff96, 0x0eb8, 0xff94,
68 0x0eea, 0xff91, 0x0f1c, 0xff8e, 0x0f4e, 0xff8b, 0x0f81, 0xff88,
69 0x0fb3, 0xff85, 0x0fe5, 0xff82, 0x1017, 0xff7e, 0x1049, 0xff7b,
70 0x107b, 0xff78, 0x10ae, 0xff75, 0x10e0, 0xff71, 0x1112, 0xff6e,
71 0x1144, 0xff6b, 0x1176, 0xff67, 0x11a8, 0xff64, 0x11da, 0xff60,
72 0x120d, 0xff5d, 0x123f, 0xff59, 0x1271, 0xff56, 0x12a3, 0xff52,
73 0x12d5, 0xff4e, 0x1307, 0xff4b, 0x1339, 0xff47, 0x136c, 0xff43,
74 0x139e, 0xff3f, 0x13d0, 0xff3b, 0x1402, 0xff38, 0x1434, 0xff34,
75 0x1466, 0xff30, 0x1498, 0xff2c, 0x14ca, 0xff28, 0x14fc, 0xff23,
76 0x152e, 0xff1f, 0x1561, 0xff1b, 0x1593, 0xff17, 0x15c5, 0xff13,
77 0x15f7, 0xff0e, 0x1629, 0xff0a, 0x165b, 0xff06, 0x168d, 0xff01,
78 0x16bf, 0xfefd, 0x16f1, 0xfef8, 0x1723, 0xfef4, 0x1755, 0xfeef,
79 0x1787, 0xfeeb, 0x17b9, 0xfee6, 0x17eb, 0xfee1, 0x181d, 0xfedd,
80 0x1850, 0xfed8, 0x1882, 0xfed3, 0x18b4, 0xfece, 0x18e6, 0xfec9,
81 0x1918, 0xfec4, 0x194a, 0xfebf, 0x197c, 0xfeba, 0x19ae, 0xfeb5,
82 0x19e0, 0xfeb0, 0x1a12, 0xfeab, 0x1a44, 0xfea6, 0x1a76, 0xfea1,
83 0x1aa8, 0xfe9c, 0x1ada, 0xfe97, 0x1b0c, 0xfe91, 0x1b3e, 0xfe8c,
84 0x1b70, 0xfe87, 0x1ba2, 0xfe81, 0x1bd4, 0xfe7c, 0x1c06, 0xfe76,
85 0x1c38, 0xfe71, 0x1c69, 0xfe6b, 0x1c9b, 0xfe66, 0x1ccd, 0xfe60,
86 0x1cff, 0xfe5a, 0x1d31, 0xfe55, 0x1d63, 0xfe4f, 0x1d95, 0xfe49,
87 0x1dc7, 0xfe43, 0x1df9, 0xfe3d, 0x1e2b, 0xfe37, 0x1e5d, 0xfe31,
88 0x1e8f, 0xfe2b, 0x1ec1, 0xfe25, 0x1ef3, 0xfe1f, 0x1f24, 0xfe19,
89 0x1f56, 0xfe13, 0x1f88, 0xfe0d, 0x1fba, 0xfe07, 0x1fec, 0xfe01,
90 0x201e, 0xfdfa, 0x2050, 0xfdf4, 0x2082, 0xfdee, 0x20b3, 0xfde7,
91 0x20e5, 0xfde1, 0x2117, 0xfdda, 0x2149, 0xfdd4, 0x217b, 0xfdcd,
92 0x21ad, 0xfdc7, 0x21de, 0xfdc0, 0x2210, 0xfdb9, 0x2242, 0xfdb3,
93 0x2274, 0xfdac, 0x22a6, 0xfda5, 0x22d7, 0xfd9e, 0x2309, 0xfd97,
94 0x233b, 0xfd90, 0x236d, 0xfd89, 0x239f, 0xfd83, 0x23d0, 0xfd7c,
95 0x2402, 0xfd74, 0x2434, 0xfd6d, 0x2466, 0xfd66, 0x2497, 0xfd5f,
96 0x24c9, 0xfd58, 0x24fb, 0xfd51, 0x252d, 0xfd49, 0x255e, 0xfd42,
97 0x2590, 0xfd3b, 0x25c2, 0xfd33, 0x25f4, 0xfd2c, 0x2625, 0xfd24,
98 0x2657, 0xfd1d, 0x2689, 0xfd15, 0x26ba, 0xfd0e, 0x26ec, 0xfd06,
99 0x271e, 0xfcfe, 0x274f, 0xfcf7, 0x2781, 0xfcef, 0x27b3, 0xfce7,
100 0x27e4, 0xfcdf, 0x2816, 0xfcd8, 0x2848, 0xfcd0, 0x2879, 0xfcc8,
101 0x28ab, 0xfcc0, 0x28dd, 0xfcb8, 0x290e, 0xfcb0, 0x2940, 0xfca8,
102 0x2971, 0xfca0, 0x29a3, 0xfc97, 0x29d5, 0xfc8f, 0x2a06, 0xfc87,
103 0x2a38, 0xfc7f, 0x2a69, 0xfc76, 0x2a9b, 0xfc6e, 0x2acc, 0xfc66,
104 0x2afe, 0xfc5d, 0x2b30, 0xfc55, 0x2b61, 0xfc4c, 0x2b93, 0xfc44,
105 0x2bc4, 0xfc3b, 0x2bf6, 0xfc33, 0x2c27, 0xfc2a, 0x2c59, 0xfc21,
106 0x2c8a, 0xfc18, 0x2cbc, 0xfc10, 0x2ced, 0xfc07, 0x2d1f, 0xfbfe,
107 0x2d50, 0xfbf5, 0x2d82, 0xfbec, 0x2db3, 0xfbe3, 0x2de5, 0xfbda,
108 0x2e16, 0xfbd1, 0x2e47, 0xfbc8, 0x2e79, 0xfbbf, 0x2eaa, 0xfbb6,
109 0x2edc, 0xfbad, 0x2f0d, 0xfba4, 0x2f3f, 0xfb9a, 0x2f70, 0xfb91,
110 0x2fa1, 0xfb88, 0x2fd3, 0xfb7e, 0x3004, 0xfb75, 0x3035, 0xfb6b,
111 0x3067, 0xfb62, 0x3098, 0xfb58, 0x30ca, 0xfb4f, 0x30fb, 0xfb45,
112 0x312c, 0xfb3c, 0x315e, 0xfb32, 0x318f, 0xfb28, 0x31c0, 0xfb1f,
113 0x31f1, 0xfb15, 0x3223, 0xfb0b, 0x3254, 0xfb01, 0x3285, 0xfaf7,
114 0x32b7, 0xfaed, 0x32e8, 0xfae3, 0x3319, 0xfad9, 0x334a, 0xfacf,
115 0x337c, 0xfac5, 0x33ad, 0xfabb, 0x33de, 0xfab1, 0x340f, 0xfaa7,
116 0x3440, 0xfa9c, 0x3472, 0xfa92, 0x34a3, 0xfa88, 0x34d4, 0xfa7d,
117 0x3505, 0xfa73, 0x3536, 0xfa69, 0x3568, 0xfa5e, 0x3599, 0xfa54,
118 0x35ca, 0xfa49, 0x35fb, 0xfa3e, 0x362c, 0xfa34, 0x365d, 0xfa29,
119 0x368e, 0xfa1f, 0x36c0, 0xfa14, 0x36f1, 0xfa09, 0x3722, 0xf9fe,
120 0x3753, 0xf9f3, 0x3784, 0xf9e8, 0x37b5, 0xf9de, 0x37e6, 0xf9d3,
121 0x3817, 0xf9c8, 0x3848, 0xf9bd, 0x3879, 0xf9b2, 0x38aa, 0xf9a6,
122 0x38db, 0xf99b, 0x390c, 0xf990, 0x393d, 0xf985, 0x396e, 0xf97a,
123 0x399f, 0xf96e, 0x39d0, 0xf963, 0x3a01, 0xf958, 0x3a32, 0xf94c,
124 0x3a63, 0xf941, 0x3a94, 0xf935, 0x3ac5, 0xf92a, 0x3af6, 0xf91e,
125 0x3b27, 0xf913, 0x3b58, 0xf907, 0x3b88, 0xf8fb, 0x3bb9, 0xf8f0,
126 0x3bea, 0xf8e4, 0x3c1b, 0xf8d8, 0x3c4c, 0xf8cc, 0x3c7d, 0xf8c0,
127 0x3cae, 0xf8b4, 0x3cde, 0xf8a9, 0x3d0f, 0xf89d, 0x3d40, 0xf891,
128 0x3d71, 0xf885, 0x3da2, 0xf878, 0x3dd2, 0xf86c, 0x3e03, 0xf860,
129 0x3e34, 0xf854, 0x3e65, 0xf848, 0x3e95, 0xf83b, 0x3ec6, 0xf82f,
130 0x3ef7, 0xf823, 0x3f28, 0xf816, 0x3f58, 0xf80a, 0x3f89, 0xf7fe,
131 0x3fba, 0xf7f1, 0x3fea, 0xf7e5, 0x401b, 0xf7d8, 0x404c, 0xf7cb,
132 0x407c, 0xf7bf, 0x40ad, 0xf7b2, 0x40de, 0xf7a5, 0x410e, 0xf799,
133 0x413f, 0xf78c, 0x416f, 0xf77f, 0x41a0, 0xf772, 0x41d1, 0xf765,
134 0x4201, 0xf758, 0x4232, 0xf74b, 0x4262, 0xf73e, 0x4293, 0xf731,
135 0x42c3, 0xf724, 0x42f4, 0xf717, 0x4324, 0xf70a, 0x4355, 0xf6fd,
136 0x4385, 0xf6ef, 0x43b6, 0xf6e2, 0x43e6, 0xf6d5, 0x4417, 0xf6c7,
137 0x4447, 0xf6ba, 0x4478, 0xf6ad, 0x44a8, 0xf69f, 0x44d9, 0xf692,
138 0x4509, 0xf684, 0x4539, 0xf677, 0x456a, 0xf669, 0x459a, 0xf65b,
139 0x45cb, 0xf64e, 0x45fb, 0xf640, 0x462b, 0xf632, 0x465c, 0xf624,
140 0x468c, 0xf616, 0x46bc, 0xf609, 0x46ec, 0xf5fb, 0x471d, 0xf5ed,
141 0x474d, 0xf5df, 0x477d, 0xf5d1, 0x47ae, 0xf5c3, 0x47de, 0xf5b5,
142 0x480e, 0xf5a6, 0x483e, 0xf598, 0x486f, 0xf58a, 0x489f, 0xf57c,
143 0x48cf, 0xf56e, 0x48ff, 0xf55f, 0x492f, 0xf551, 0x495f, 0xf543,
144 0x4990, 0xf534, 0x49c0, 0xf526, 0x49f0, 0xf517, 0x4a20, 0xf509,
145 0x4a50, 0xf4fa, 0x4a80, 0xf4eb, 0x4ab0, 0xf4dd, 0x4ae0, 0xf4ce,
146 0x4b10, 0xf4bf, 0x4b40, 0xf4b1, 0x4b71, 0xf4a2, 0x4ba1, 0xf493,
147 0x4bd1, 0xf484, 0x4c01, 0xf475, 0x4c31, 0xf466, 0x4c61, 0xf457,
148 0x4c90, 0xf448, 0x4cc0, 0xf439, 0x4cf0, 0xf42a, 0x4d20, 0xf41b,
149 0x4d50, 0xf40c, 0x4d80, 0xf3fd, 0x4db0, 0xf3ed, 0x4de0, 0xf3de,
150 0x4e10, 0xf3cf, 0x4e40, 0xf3c0, 0x4e70, 0xf3b0, 0x4e9f, 0xf3a1,
151 0x4ecf, 0xf391, 0x4eff, 0xf382, 0x4f2f, 0xf372, 0x4f5f, 0xf363,
152 0x4f8e, 0xf353, 0x4fbe, 0xf343, 0x4fee, 0xf334, 0x501e, 0xf324,
153 0x504d, 0xf314, 0x507d, 0xf304, 0x50ad, 0xf2f5, 0x50dd, 0xf2e5,
154 0x510c, 0xf2d5, 0x513c, 0xf2c5, 0x516c, 0xf2b5, 0x519b, 0xf2a5,
155 0x51cb, 0xf295, 0x51fb, 0xf285, 0x522a, 0xf275, 0x525a, 0xf265,
156 0x5289, 0xf254, 0x52b9, 0xf244, 0x52e8, 0xf234, 0x5318, 0xf224,
157 0x5348, 0xf213, 0x5377, 0xf203, 0x53a7, 0xf1f3, 0x53d6, 0xf1e2,
158 0x5406, 0xf1d2, 0x5435, 0xf1c1, 0x5464, 0xf1b1, 0x5494, 0xf1a0,
159 0x54c3, 0xf18f, 0x54f3, 0xf17f, 0x5522, 0xf16e, 0x5552, 0xf15d,
160 0x5581, 0xf14c, 0x55b0, 0xf13c, 0x55e0, 0xf12b, 0x560f, 0xf11a,
161 0x563e, 0xf109, 0x566e, 0xf0f8, 0x569d, 0xf0e7, 0x56cc, 0xf0d6,
162 0x56fc, 0xf0c5, 0x572b, 0xf0b4, 0x575a, 0xf0a3, 0x5789, 0xf092,
163 0x57b9, 0xf080, 0x57e8, 0xf06f, 0x5817, 0xf05e, 0x5846, 0xf04d,
164 0x5875, 0xf03b, 0x58a5, 0xf02a, 0x58d4, 0xf018, 0x5903, 0xf007,
165 0x5932, 0xeff5, 0x5961, 0xefe4, 0x5990, 0xefd2, 0x59bf, 0xefc1,
166 0x59ee, 0xefaf, 0x5a1d, 0xef9d, 0x5a4c, 0xef8c, 0x5a7b, 0xef7a,
167 0x5aaa, 0xef68, 0x5ad9, 0xef56, 0x5b08, 0xef45, 0x5b37, 0xef33,
168 0x5b66, 0xef21, 0x5b95, 0xef0f, 0x5bc4, 0xeefd, 0x5bf3, 0xeeeb,
169 0x5c22, 0xeed9, 0x5c51, 0xeec7, 0x5c80, 0xeeb4, 0x5caf, 0xeea2,
170 0x5cde, 0xee90, 0x5d0c, 0xee7e, 0x5d3b, 0xee6b, 0x5d6a, 0xee59,
171 0x5d99, 0xee47, 0x5dc8, 0xee34, 0x5df6, 0xee22, 0x5e25, 0xee0f,
172 0x5e54, 0xedfd, 0x5e83, 0xedea, 0x5eb1, 0xedd8, 0x5ee0, 0xedc5,
173 0x5f0f, 0xedb3, 0x5f3d, 0xeda0, 0x5f6c, 0xed8d, 0x5f9b, 0xed7a,
174 0x5fc9, 0xed68, 0x5ff8, 0xed55, 0x6026, 0xed42, 0x6055, 0xed2f,
175 0x6084, 0xed1c, 0x60b2, 0xed09, 0x60e1, 0xecf6, 0x610f, 0xece3,
176 0x613e, 0xecd0, 0x616c, 0xecbd, 0x619b, 0xecaa, 0x61c9, 0xec97,
177 0x61f8, 0xec83, 0x6226, 0xec70, 0x6254, 0xec5d, 0x6283, 0xec4a,
178 0x62b1, 0xec36, 0x62e0, 0xec23, 0x630e, 0xec0f, 0x633c, 0xebfc,
179 0x636b, 0xebe8, 0x6399, 0xebd5, 0x63c7, 0xebc1, 0x63f5, 0xebae,
180 0x6424, 0xeb9a, 0x6452, 0xeb86, 0x6480, 0xeb73, 0x64ae, 0xeb5f,
181 0x64dd, 0xeb4b, 0x650b, 0xeb37, 0x6539, 0xeb23, 0x6567, 0xeb0f,
182 0x6595, 0xeafc, 0x65c3, 0xeae8, 0x65f2, 0xead4, 0x6620, 0xeac0,
183 0x664e, 0xeaab, 0x667c, 0xea97, 0x66aa, 0xea83, 0x66d8, 0xea6f,
184 0x6706, 0xea5b, 0x6734, 0xea47, 0x6762, 0xea32, 0x6790, 0xea1e,
185 0x67be, 0xea0a, 0x67ec, 0xe9f5, 0x681a, 0xe9e1, 0x6848, 0xe9cc,
186 0x6876, 0xe9b8, 0x68a3, 0xe9a3, 0x68d1, 0xe98f, 0x68ff, 0xe97a,
187 0x692d, 0xe966, 0x695b, 0xe951, 0x6989, 0xe93c, 0x69b6, 0xe927,
188 0x69e4, 0xe913, 0x6a12, 0xe8fe, 0x6a40, 0xe8e9, 0x6a6d, 0xe8d4,
189 0x6a9b, 0xe8bf, 0x6ac9, 0xe8aa, 0x6af6, 0xe895, 0x6b24, 0xe880,
190 0x6b52, 0xe86b, 0x6b7f, 0xe856, 0x6bad, 0xe841, 0x6bdb, 0xe82c,
191 0x6c08, 0xe817, 0x6c36, 0xe801, 0x6c63, 0xe7ec, 0x6c91, 0xe7d7,
192 0x6cbe, 0xe7c2, 0x6cec, 0xe7ac, 0x6d19, 0xe797, 0x6d47, 0xe781,
193 0x6d74, 0xe76c, 0x6da2, 0xe756, 0x6dcf, 0xe741, 0x6dfc, 0xe72b,
194 0x6e2a, 0xe716, 0x6e57, 0xe700, 0x6e85, 0xe6ea, 0x6eb2, 0xe6d5,
195 0x6edf, 0xe6bf, 0x6f0d, 0xe6a9, 0x6f3a, 0xe693, 0x6f67, 0xe67d,
196 0x6f94, 0xe667, 0x6fc2, 0xe652, 0x6fef, 0xe63c, 0x701c, 0xe626,
197 0x7049, 0xe610, 0x7076, 0xe5f9, 0x70a3, 0xe5e3, 0x70d1, 0xe5cd,
198 0x70fe, 0xe5b7, 0x712b, 0xe5a1, 0x7158, 0xe58b, 0x7185, 0xe574,
199 0x71b2, 0xe55e, 0x71df, 0xe548, 0x720c, 0xe531, 0x7239, 0xe51b,
200 0x7266, 0xe504, 0x7293, 0xe4ee, 0x72c0, 0xe4d7, 0x72ed, 0xe4c1,
201 0x731a, 0xe4aa, 0x7347, 0xe494, 0x7373, 0xe47d, 0x73a0, 0xe466,
202 0x73cd, 0xe450, 0x73fa, 0xe439, 0x7427, 0xe422, 0x7454, 0xe40b,
203 0x7480, 0xe3f4, 0x74ad, 0xe3de, 0x74da, 0xe3c7, 0x7507, 0xe3b0,
204 0x7533, 0xe399, 0x7560, 0xe382, 0x758d, 0xe36b, 0x75b9, 0xe353,
205 0x75e6, 0xe33c, 0x7612, 0xe325, 0x763f, 0xe30e, 0x766c, 0xe2f7,
206 0x7698, 0xe2df, 0x76c5, 0xe2c8, 0x76f1, 0xe2b1, 0x771e, 0xe299,
207 0x774a, 0xe282, 0x7777, 0xe26b, 0x77a3, 0xe253, 0x77d0, 0xe23c,
208 0x77fc, 0xe224, 0x7828, 0xe20d, 0x7855, 0xe1f5, 0x7881, 0xe1dd,
209 0x78ad, 0xe1c6, 0x78da, 0xe1ae, 0x7906, 0xe196, 0x7932, 0xe17e,
210 0x795f, 0xe167, 0x798b, 0xe14f, 0x79b7, 0xe137, 0x79e3, 0xe11f,
211 0x7a10, 0xe107, 0x7a3c, 0xe0ef, 0x7a68, 0xe0d7, 0x7a94, 0xe0bf,
212 0x7ac0, 0xe0a7, 0x7aec, 0xe08f, 0x7b18, 0xe077, 0x7b44, 0xe05e,
213 0x7b70, 0xe046, 0x7b9c, 0xe02e, 0x7bc8, 0xe016, 0x7bf4, 0xdffd,
214 0x7c20, 0xdfe5, 0x7c4c, 0xdfcd, 0x7c78, 0xdfb4, 0x7ca4, 0xdf9c,
215 0x7cd0, 0xdf83, 0x7cfc, 0xdf6b, 0x7d28, 0xdf52, 0x7d54, 0xdf39,
216 0x7d7f, 0xdf21, 0x7dab, 0xdf08, 0x7dd7, 0xdef0, 0x7e03, 0xded7,
217 0x7e2f, 0xdebe, 0x7e5a, 0xdea5, 0x7e86, 0xde8c, 0x7eb2, 0xde74,
218 0x7edd, 0xde5b, 0x7f09, 0xde42, 0x7f35, 0xde29, 0x7f60, 0xde10,
219 0x7f8c, 0xddf7, 0x7fb7, 0xddde, 0x7fe3, 0xddc5, 0x800f, 0xddab,
220 0x803a, 0xdd92, 0x8066, 0xdd79, 0x8091, 0xdd60, 0x80bc, 0xdd47,
221 0x80e8, 0xdd2d, 0x8113, 0xdd14, 0x813f, 0xdcfb, 0x816a, 0xdce1,
222 0x8195, 0xdcc8, 0x81c1, 0xdcae, 0x81ec, 0xdc95, 0x8217, 0xdc7b,
223 0x8243, 0xdc62, 0x826e, 0xdc48, 0x8299, 0xdc2f, 0x82c4, 0xdc15,
224 0x82f0, 0xdbfb, 0x831b, 0xdbe1, 0x8346, 0xdbc8, 0x8371, 0xdbae,
225 0x839c, 0xdb94, 0x83c7, 0xdb7a, 0x83f2, 0xdb60, 0x841d, 0xdb46,
226 0x8449, 0xdb2c, 0x8474, 0xdb12, 0x849f, 0xdaf8, 0x84ca, 0xdade,
227 0x84f5, 0xdac4, 0x851f, 0xdaaa, 0x854a, 0xda90, 0x8575, 0xda76,
228 0x85a0, 0xda5c, 0x85cb, 0xda41, 0x85f6, 0xda27, 0x8621, 0xda0d,
229 0x864c, 0xd9f2, 0x8676, 0xd9d8, 0x86a1, 0xd9be, 0x86cc, 0xd9a3,
230 0x86f7, 0xd989, 0x8721, 0xd96e, 0x874c, 0xd954, 0x8777, 0xd939,
231 0x87a1, 0xd91e, 0x87cc, 0xd904, 0x87f6, 0xd8e9, 0x8821, 0xd8ce,
232 0x884c, 0xd8b4, 0x8876, 0xd899, 0x88a1, 0xd87e, 0x88cb, 0xd863,
233 0x88f6, 0xd848, 0x8920, 0xd82d, 0x894a, 0xd812, 0x8975, 0xd7f8,
234 0x899f, 0xd7dc, 0x89ca, 0xd7c1, 0x89f4, 0xd7a6, 0x8a1e, 0xd78b,
235 0x8a49, 0xd770, 0x8a73, 0xd755, 0x8a9d, 0xd73a, 0x8ac7, 0xd71f,
236 0x8af2, 0xd703, 0x8b1c, 0xd6e8, 0x8b46, 0xd6cd, 0x8b70, 0xd6b1,
237 0x8b9a, 0xd696, 0x8bc5, 0xd67a, 0x8bef, 0xd65f, 0x8c19, 0xd644,
238 0x8c43, 0xd628, 0x8c6d, 0xd60c, 0x8c97, 0xd5f1, 0x8cc1, 0xd5d5,
239 0x8ceb, 0xd5ba, 0x8d15, 0xd59e, 0x8d3f, 0xd582, 0x8d69, 0xd566,
240 0x8d93, 0xd54b, 0x8dbc, 0xd52f, 0x8de6, 0xd513, 0x8e10, 0xd4f7,
241 0x8e3a, 0xd4db, 0x8e64, 0xd4bf, 0x8e8d, 0xd4a3, 0x8eb7, 0xd487,
242 0x8ee1, 0xd46b, 0x8f0b, 0xd44f, 0x8f34, 0xd433, 0x8f5e, 0xd417,
243 0x8f88, 0xd3fb, 0x8fb1, 0xd3df, 0x8fdb, 0xd3c2, 0x9004, 0xd3a6,
244 0x902e, 0xd38a, 0x9057, 0xd36d, 0x9081, 0xd351, 0x90aa, 0xd335,
245 0x90d4, 0xd318, 0x90fd, 0xd2fc, 0x9127, 0xd2df, 0x9150, 0xd2c3,
246 0x9179, 0xd2a6, 0x91a3, 0xd28a, 0x91cc, 0xd26d, 0x91f5, 0xd250,
247 0x921f, 0xd234, 0x9248, 0xd217, 0x9271, 0xd1fa, 0x929a, 0xd1de,
248 0x92c4, 0xd1c1, 0x92ed, 0xd1a4, 0x9316, 0xd187, 0x933f, 0xd16a,
249 0x9368, 0xd14d, 0x9391, 0xd130, 0x93ba, 0xd113, 0x93e3, 0xd0f6,
250 0x940c, 0xd0d9, 0x9435, 0xd0bc, 0x945e, 0xd09f, 0x9487, 0xd082,
251 0x94b0, 0xd065, 0x94d9, 0xd047, 0x9502, 0xd02a, 0x952b, 0xd00d,
252 0x9554, 0xcff0, 0x957d, 0xcfd2, 0x95a5, 0xcfb5, 0x95ce, 0xcf98,
253 0x95f7, 0xcf7a, 0x9620, 0xcf5d, 0x9648, 0xcf3f, 0x9671, 0xcf22,
254 0x969a, 0xcf04, 0x96c2, 0xcee7, 0x96eb, 0xcec9, 0x9713, 0xceab,
255 0x973c, 0xce8e, 0x9765, 0xce70, 0x978d, 0xce52, 0x97b6, 0xce34,
256 0x97de, 0xce17, 0x9807, 0xcdf9, 0x982f, 0xcddb, 0x9857, 0xcdbd,
257 0x9880, 0xcd9f, 0x98a8, 0xcd81, 0x98d0, 0xcd63, 0x98f9, 0xcd45,
258 0x9921, 0xcd27, 0x9949, 0xcd09, 0x9972, 0xcceb, 0x999a, 0xcccd,
259 0x99c2, 0xccae, 0x99ea, 0xcc90, 0x9a12, 0xcc72, 0x9a3a, 0xcc54,
260 0x9a63, 0xcc35, 0x9a8b, 0xcc17, 0x9ab3, 0xcbf9, 0x9adb, 0xcbda,
261 0x9b03, 0xcbbc, 0x9b2b, 0xcb9e, 0x9b53, 0xcb7f, 0x9b7b, 0xcb61,
262 0x9ba3, 0xcb42, 0x9bca, 0xcb23, 0x9bf2, 0xcb05, 0x9c1a, 0xcae6,
263 0x9c42, 0xcac7, 0x9c6a, 0xcaa9, 0x9c92, 0xca8a, 0x9cb9, 0xca6b,
264 0x9ce1, 0xca4d, 0x9d09, 0xca2e, 0x9d31, 0xca0f, 0x9d58, 0xc9f0,
265 0x9d80, 0xc9d1, 0x9da7, 0xc9b2, 0x9dcf, 0xc993, 0x9df7, 0xc974,
266 0x9e1e, 0xc955, 0x9e46, 0xc936, 0x9e6d, 0xc917, 0x9e95, 0xc8f8,
267 0x9ebc, 0xc8d9, 0x9ee3, 0xc8ba, 0x9f0b, 0xc89a, 0x9f32, 0xc87b,
268 0x9f5a, 0xc85c, 0x9f81, 0xc83c, 0x9fa8, 0xc81d, 0x9fd0, 0xc7fe,
269 0x9ff7, 0xc7de, 0xa01e, 0xc7bf, 0xa045, 0xc7a0, 0xa06c, 0xc780,
270 0xa094, 0xc761, 0xa0bb, 0xc741, 0xa0e2, 0xc721, 0xa109, 0xc702,
271 0xa130, 0xc6e2, 0xa157, 0xc6c2, 0xa17e, 0xc6a3, 0xa1a5, 0xc683,
272 0xa1cc, 0xc663, 0xa1f3, 0xc644, 0xa21a, 0xc624, 0xa241, 0xc604,
273 0xa268, 0xc5e4, 0xa28e, 0xc5c4, 0xa2b5, 0xc5a4, 0xa2dc, 0xc584,
274 0xa303, 0xc564, 0xa32a, 0xc544, 0xa350, 0xc524, 0xa377, 0xc504,
275 0xa39e, 0xc4e4, 0xa3c4, 0xc4c4, 0xa3eb, 0xc4a4, 0xa412, 0xc483,
276 0xa438, 0xc463, 0xa45f, 0xc443, 0xa485, 0xc423, 0xa4ac, 0xc402,
277 0xa4d2, 0xc3e2, 0xa4f9, 0xc3c2, 0xa51f, 0xc3a1, 0xa545, 0xc381,
278 0xa56c, 0xc360, 0xa592, 0xc340, 0xa5b8, 0xc31f, 0xa5df, 0xc2ff,
279 0xa605, 0xc2de, 0xa62b, 0xc2be, 0xa652, 0xc29d, 0xa678, 0xc27c,
280 0xa69e, 0xc25c, 0xa6c4, 0xc23b, 0xa6ea, 0xc21a, 0xa710, 0xc1f9,
281 0xa736, 0xc1d8, 0xa75c, 0xc1b8, 0xa782, 0xc197, 0xa7a8, 0xc176,
282 0xa7ce, 0xc155, 0xa7f4, 0xc134, 0xa81a, 0xc113, 0xa840, 0xc0f2,
283 0xa866, 0xc0d1, 0xa88c, 0xc0b0, 0xa8b2, 0xc08f, 0xa8d7, 0xc06e,
284 0xa8fd, 0xc04c, 0xa923, 0xc02b, 0xa949, 0xc00a, 0xa96e, 0xbfe9,
285 0xa994, 0xbfc7, 0xa9ba, 0xbfa6, 0xa9df, 0xbf85, 0xaa05, 0xbf63,
286 0xaa2a, 0xbf42, 0xaa50, 0xbf21, 0xaa76, 0xbeff, 0xaa9b, 0xbede,
287 0xaac1, 0xbebc, 0xaae6, 0xbe9b, 0xab0b, 0xbe79, 0xab31, 0xbe57,
288 0xab56, 0xbe36, 0xab7b, 0xbe14, 0xaba1, 0xbdf2, 0xabc6, 0xbdd1,
289 0xabeb, 0xbdaf, 0xac11, 0xbd8d, 0xac36, 0xbd6b, 0xac5b, 0xbd4a,
290 0xac80, 0xbd28, 0xaca5, 0xbd06, 0xacca, 0xbce4, 0xacef, 0xbcc2,
291 0xad14, 0xbca0, 0xad39, 0xbc7e, 0xad5e, 0xbc5c, 0xad83, 0xbc3a,
292 0xada8, 0xbc18, 0xadcd, 0xbbf6, 0xadf2, 0xbbd4, 0xae17, 0xbbb1,
293 0xae3c, 0xbb8f, 0xae61, 0xbb6d, 0xae85, 0xbb4b, 0xaeaa, 0xbb28,
294 0xaecf, 0xbb06, 0xaef4, 0xbae4, 0xaf18, 0xbac1, 0xaf3d, 0xba9f,
295 0xaf62, 0xba7d, 0xaf86, 0xba5a, 0xafab, 0xba38, 0xafcf, 0xba15,
296 0xaff4, 0xb9f3, 0xb018, 0xb9d0, 0xb03d, 0xb9ae, 0xb061, 0xb98b,
297 0xb086, 0xb968, 0xb0aa, 0xb946, 0xb0ce, 0xb923, 0xb0f3, 0xb900,
298 0xb117, 0xb8dd, 0xb13b, 0xb8bb, 0xb160, 0xb898, 0xb184, 0xb875,
299 0xb1a8, 0xb852, 0xb1cc, 0xb82f, 0xb1f0, 0xb80c, 0xb215, 0xb7e9,
300 0xb239, 0xb7c6, 0xb25d, 0xb7a3, 0xb281, 0xb780, 0xb2a5, 0xb75d,
301 0xb2c9, 0xb73a, 0xb2ed, 0xb717, 0xb311, 0xb6f4, 0xb335, 0xb6d1,
302 0xb358, 0xb6ad, 0xb37c, 0xb68a, 0xb3a0, 0xb667, 0xb3c4, 0xb644,
303 0xb3e8, 0xb620, 0xb40b, 0xb5fd, 0xb42f, 0xb5da, 0xb453, 0xb5b6,
304 0xb477, 0xb593, 0xb49a, 0xb56f, 0xb4be, 0xb54c, 0xb4e1, 0xb528,
305 0xb505, 0xb505
306};
307
308static const FIXPU pow128_tab[128] = {
309 /* x_i = 2^(15+i/128) */
310 0x8000, 0x80b2, 0x8165, 0x8219, 0x82ce, 0x8383, 0x843a, 0x84f2, 0x85ab,
311 0x8665, 0x871f, 0x87db, 0x8898, 0x8956, 0x8a15, 0x8ad5, 0x8b96, 0x8c58,
312 0x8d1b, 0x8ddf, 0x8ea4, 0x8f6b, 0x9032, 0x90fa, 0x91c4, 0x928e, 0x935a,
313 0x9427, 0x94f5, 0x95c4, 0x9694, 0x9765, 0x9838, 0x990c, 0x99e0, 0x9ab6,
314 0x9b8d, 0x9c65, 0x9d3f, 0x9e19, 0x9ef5, 0x9fd2, 0xa0b0, 0xa190, 0xa270,
315 0xa352, 0xa435, 0xa519, 0xa5ff, 0xa6e6, 0xa7ce, 0xa8b7, 0xa9a1, 0xaa8d,
316 0xab7a, 0xac69, 0xad58, 0xae49, 0xaf3b, 0xb02f, 0xb124, 0xb21a, 0xb312,
317 0xb40b, 0xb505, 0xb601, 0xb6fe, 0xb7fc, 0xb8fc, 0xb9fd, 0xbaff, 0xbc03,
318 0xbd09, 0xbe0f, 0xbf18, 0xc021, 0xc12c, 0xc239, 0xc347, 0xc456, 0xc567,
319 0xc67a, 0xc78d, 0xc8a3, 0xc9ba, 0xcad2, 0xcbec, 0xcd08, 0xce25, 0xcf43,
320 0xd063, 0xd185, 0xd2a8, 0xd3cd, 0xd4f3, 0xd61b, 0xd745, 0xd870, 0xd99d,
321 0xdacc, 0xdbfc, 0xdd2e, 0xde61, 0xdf96, 0xe0cd, 0xe205, 0xe340, 0xe47b,
322 0xe5b9, 0xe6f8, 0xe839, 0xe97c, 0xeac1, 0xec07, 0xed4f, 0xee99, 0xefe5,
323 0xf132, 0xf281, 0xf3d3, 0xf525, 0xf67a, 0xf7d1, 0xf929, 0xfa84, 0xfbe0,
324 0xfd3e, 0xfe9e
325};
326
327
328/* dither_table and quant_centroid_table.
329 * Index 1: [0] - scaled by 2^13, [1] - scaled by 2^13 / sqrt(2)
330 * Index 2: [0..7] - category
331 * Index 3: [0] - dither_table, [1..13] - quant_centroid_table
332 */
333static const FIXP quant_tables[2][8][14] = {{{
334 0x00000000, 0x0645a1cb, 0x0c2d0e56, 0x11eb851f, 0x17a1cac1, 0x1d4fdf3b,
335 0x22ed9168, 0x28a7ef9e, 0x2e49ba5e, 0x33eb851f, 0x39916873, 0x3f126e98,
336 0x449ba5e3, 0x4b958106
337},{
338 0x00000000, 0x08b43958, 0x10f5c28f, 0x19020c4a, 0x2116872b, 0x2922d0e5,
339 0x3126e979, 0x38fdf3b6, 0x411eb852, 0x49eb851f, 0x00000000, 0x00000000,
340 0x00000000, 0x00000000
341},{
342 0x00000000, 0x0bef9db2, 0x176c8b44, 0x22e147ae, 0x2e1cac08, 0x39581062,
343 0x450e5604, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
344 0x00000000, 0x00000000
345},{
346 0x00000000, 0x10189375, 0x20000000, 0x2fe353f8, 0x3fc28f5c, 0x00000000,
347 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
348 0x00000000, 0x00000000
349},{
350 0x00000000, 0x1522d0e5, 0x2b3f7cee, 0x3fba5e35, 0x00000000, 0x00000000,
351 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
352 0x00000000, 0x00000000
353},{
354 0x02d413cd, 0x1a83126f, 0x37db22d1, 0x00000000, 0x00000000, 0x00000000,
355 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
356 0x00000000, 0x00000000
357},{
358 0x04000000, 0x1f6c8b44, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
359 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
360 0x00000000, 0x00000000
361},{
362 0x0b504f33, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
363 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
364 0x00000000, 0x00000000
365}},{{
366 0x00000000, 0x046f5a70, 0x089c1768, 0x0cabddd3, 0x10b5d955, 0x14ba09ed,
367 0x18b2a4b4, 0x1cbf85aa, 0x20bb05e5, 0x24b68620, 0x28b4ebcf, 0x2c994066,
368 0x30835fe6, 0x35722a5e
369},{
370 0x00000000, 0x062797a1, 0x0bfe1683, 0x11aeee7a, 0x1765915b, 0x1d166952,
371 0x22c17660, 0x284ca76c, 0x2e0bfaaa, 0x3444f306, 0x00000000, 0x00000000,
372 0x00000000, 0x00000000
373},{
374 0x00000000, 0x0870a594, 0x1090326a, 0x18a9f456, 0x209b29e3, 0x288c5f70,
375 0x30d478a5, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
376 0x00000000, 0x00000000
377},{
378 0x00000000, 0x0b61afee, 0x16a09e66, 0x21dca76a, 0x2d15caf9, 0x00000000,
379 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
380 0x00000000, 0x00000000
381},{
382 0x00000000, 0x0ef20652, 0x1e94b968, 0x2d100010, 0x00000000, 0x00000000,
383 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
384 0x00000000, 0x00000000
385},{
386 0x02000000, 0x12bf2f44, 0x277f041b, 0x00000000, 0x00000000, 0x00000000,
387 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
388 0x00000000, 0x00000000
389},{
390 0x02d413cd, 0x16385a03, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
391 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
392 0x00000000, 0x00000000
393},{
394 0x08000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
395 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
396 0x00000000, 0x00000000
397}}};
398
399static const FIXPU cplscale2[3] = {
400 /* 2^16 C_ij */
401 0xf3f9, 0xb505, 0x4d8b
402};
403static const FIXPU cplscale3[7] = {
404 /* 2^16 C_ij */
405 0xfb35, 0xefdf, 0xe03d, 0xb505, 0x7b81, 0x596e, 0x314d
406};
407static const FIXPU cplscale4[15] = {
408 /* 2^16 C_ij */
409 0xfdd2, 0xf927, 0xf3f9, 0xee1d, 0xe749, 0xdee9, 0xd381, 0xb505, 0x903b,
410 0x7de2, 0x6dbe, 0x5e02, 0x4d8b, 0x3ad1, 0x2155
411};
412static const FIXPU cplscale5[31] = {
413 /* 2^16 C_ij */
414 0xfef5, 0xfcce, 0xfa8e, 0xf832, 0xf5b5, 0xf314, 0xf049, 0xed4c, 0xea12,
415 0xe68e, 0xe2ab, 0xde4b, 0xd938, 0xd30b, 0xcab6, 0xb505, 0x9c59, 0x90e8,
416 0x8778, 0x7ef9, 0x76fc, 0x6f45, 0x67ab, 0x600e, 0x5850, 0x504d, 0x47db,
417 0x3ebd, 0x3486, 0x2853, 0x1715
418};
419static const FIXPU cplscale6[63] = {
420 /* 2^16 C_ij */
421 0xff7d, 0xfe74, 0xfd65, 0xfc50, 0xfb35, 0xfa14, 0xf8eb, 0xf7bb, 0xf683,
422 0xf543, 0xf3f9, 0xf2a6, 0xf148, 0xefdf, 0xee6a, 0xece6, 0xeb54, 0xe9b2,
423 0xe7fd, 0xe634, 0xe453, 0xe258, 0xe03d, 0xddff, 0xdb94, 0xd8f4, 0xd610,
424 0xd2d2, 0xcf13, 0xca8c, 0xc47c, 0xb505, 0xa41a, 0x9c90, 0x9685, 0x913a,
425 0x8c67, 0x87e5, 0x839c, 0x7f7e, 0x7b81, 0x779b, 0x73c7, 0x6fff, 0x6c3f,
426 0x6883, 0x64c7, 0x6107, 0x5d40, 0x596e, 0x558d, 0x5198, 0x4d8b, 0x495f,
427 0x450d, 0x408b, 0x3bcd, 0x36c1, 0x314d, 0x2b4a, 0x246e, 0x1c1a, 0x1029
428};
429
430static const FIXPU* cplscales[5] = {
431 cplscale2, cplscale3, cplscale4, cplscale5, cplscale6
432};
433