1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
Index: apps/codecs/libcook/cook.h
===================================================================
--- apps/codecs/libcook/cook.h  (revision 29912)
+++ apps/codecs/libcook/cook.h  (working copy)
@@ -27,6 +27,31 @@
 #include "../librm/rm.h"
 #include "cookdata_fixpoint.h"
 
+#include "codeclib.h"
+
+#if (CONFIG_CPU == PP5022) || (CONFIG_CPU == PP5024) || (CONFIG_CPU == MCF5250)
+/* PP5022/24, MCF5250 have large IRAM */
+#define IBSS_ATTR_COOK_LARGE_IRAM    IBSS_ATTR
+#define ICODE_ATTR_COOK_LARGE_IRAM   ICODE_ATTR
+#define ICONST_ATTR_COOK_LARGE_IRAM  ICONST_ATTR
+#define IBSS_ATTR_COOK_VLCBUF
+
+#elif defined(CPU_S5L870X)
+/* S5L870X have even larger IRAM */
+#define IBSS_ATTR_COOK_LARGE_IRAM    IBSS_ATTR
+#define ICODE_ATTR_COOK_LARGE_IRAM   ICODE_ATTR
+#define ICONST_ATTR_COOK_LARGE_IRAM  ICONST_ATTR
+#define IBSS_ATTR_COOK_VLCBUF        IBSS_ATTR
+
+#else
+/* other CPUs IRAM is not large enough */
+#define IBSS_ATTR_COOK_LARGE_IRAM
+#define ICODE_ATTR_COOK_LARGE_IRAM
+#define ICONST_ATTR_COOK_LARGE_IRAM
+#define IBSS_ATTR_COOK_VLCBUF
+
+#endif
+
 typedef struct {
     int *now;
     int *previous;
@@ -86,13 +111,14 @@
 
     /* data buffers */
 
-    uint8_t             decoded_bytes_buffer[1024];
-    REAL_T mono_mdct_output[2048] __attribute__ ((aligned(16)));
-    REAL_T              mono_previous_buffer1[1024];
-    REAL_T              mono_previous_buffer2[1024];
-    REAL_T              decode_buffer_1[1024];
-    REAL_T              decode_buffer_2[1024];
-    REAL_T              decode_buffer_0[1060]; /* static allocation for joint decode */
+    uint8_t             decoded_bytes_buffer[1024]  MEM_ALIGN_ATTR;
+    REAL_T              mono_mdct_output[2048]      MEM_ALIGN_ATTR;
+    REAL_T              mono_previous_buffer1[1024] MEM_ALIGN_ATTR;
+    REAL_T              mono_previous_buffer2[1024] MEM_ALIGN_ATTR;
+    REAL_T              decode_buffer_1[1024]       MEM_ALIGN_ATTR;
+    REAL_T              decode_buffer_2[1024]       MEM_ALIGN_ATTR;
+    /* static allocation for joint decode */
+    REAL_T              decode_buffer_0[1060]       MEM_ALIGN_ATTR;
 } COOKContext;
 
 int cook_decode_init(RMContext *rmctx, COOKContext *q);
Index: apps/codecs/libcook/cook.c
===================================================================
--- apps/codecs/libcook/cook.c  (revision 29912)
+++ apps/codecs/libcook/cook.c  (working copy)
@@ -102,32 +102,83 @@
 #endif
 
 /*************** init functions ***************/
-#define VLCBUFSIZE 1500
-VLC_TYPE vlcbuf[21][VLCBUFSIZE][2];
+/* Codebook sizes (11586 * 4 bytes in total) */
+/* Used for envelope_quant_index[]. */
+static VLC_TYPE vlcbuf00[ 520][2] IBSS_ATTR_COOK_LARGE_IRAM;
+static VLC_TYPE vlcbuf01[ 640][2] IBSS_ATTR_COOK_LARGE_IRAM;
+static VLC_TYPE vlcbuf02[ 544][2] IBSS_ATTR_COOK_LARGE_IRAM;
+static VLC_TYPE vlcbuf03[ 528][2] IBSS_ATTR_COOK_VLCBUF;
+static VLC_TYPE vlcbuf04[ 544][2] IBSS_ATTR_COOK_VLCBUF;
+static VLC_TYPE vlcbuf05[ 544][2] IBSS_ATTR_COOK_VLCBUF;
+static VLC_TYPE vlcbuf06[ 640][2] IBSS_ATTR_COOK_VLCBUF;
+static VLC_TYPE vlcbuf07[ 576][2] IBSS_ATTR_COOK_VLCBUF;
+static VLC_TYPE vlcbuf08[ 528][2] IBSS_ATTR_COOK_VLCBUF;
+static VLC_TYPE vlcbuf09[ 544][2] IBSS_ATTR_COOK_VLCBUF;
+static VLC_TYPE vlcbuf10[ 544][2] IBSS_ATTR_COOK_VLCBUF;
+static VLC_TYPE vlcbuf11[ 640][2] IBSS_ATTR_COOK_VLCBUF;
+static VLC_TYPE vlcbuf12[ 544][2] IBSS_ATTR_COOK_LARGE_IRAM;
+/* Used for sqvh[]. */
+static VLC_TYPE vlcbuf13[ 622][2] IBSS_ATTR_COOK_LARGE_IRAM;
+static VLC_TYPE vlcbuf14[ 308][2] IBSS_ATTR_COOK_LARGE_IRAM; 
+static VLC_TYPE vlcbuf15[ 280][2] IBSS_ATTR_COOK_LARGE_IRAM;
+static VLC_TYPE vlcbuf16[1456][2] IBSS_ATTR_COOK_LARGE_IRAM;
+static VLC_TYPE vlcbuf17[ 694][2] IBSS_ATTR_COOK_LARGE_IRAM;
+static VLC_TYPE vlcbuf18[ 698][2] IBSS_ATTR_COOK_LARGE_IRAM;
+static VLC_TYPE vlcbuf19[ 104][2] IBSS_ATTR_COOK_LARGE_IRAM;
+/* Used for ccpl. */
+static VLC_TYPE vlcbuf20[  88][2] IBSS_ATTR_COOK_VLCBUF;
 
+/* Code book sizes (11586 entries in total) */
+static int env_size[13] = {520,640,544, 528,544,544,640,576,528,544,544,640,544};
+static int sqvh_size[7] = {622,308,280,1456,694,698,104};
+static int ccpl_size    = 88;
+
+
 static int init_cook_vlc_tables(COOKContext *q) {
-    int i, result;
+    int i, result = 0;
+    
+    /* Set pointers for codebooks. */
+    q->envelope_quant_index[ 0].table = vlcbuf00;
+    q->envelope_quant_index[ 1].table = vlcbuf01;
+    q->envelope_quant_index[ 2].table = vlcbuf02;
+    q->envelope_quant_index[ 3].table = vlcbuf03;
+    q->envelope_quant_index[ 4].table = vlcbuf04;
+    q->envelope_quant_index[ 5].table = vlcbuf05;
+    q->envelope_quant_index[ 6].table = vlcbuf06;
+    q->envelope_quant_index[ 7].table = vlcbuf07;
+    q->envelope_quant_index[ 8].table = vlcbuf08;
+    q->envelope_quant_index[ 9].table = vlcbuf09;
+    q->envelope_quant_index[10].table = vlcbuf10;
+    q->envelope_quant_index[11].table = vlcbuf11;
+    q->envelope_quant_index[12].table = vlcbuf12;
+    q->sqvh[0].table = vlcbuf13; 
+    q->sqvh[1].table = vlcbuf14;
+    q->sqvh[2].table = vlcbuf15; 
+    q->sqvh[3].table = vlcbuf16;
+    q->sqvh[4].table = vlcbuf17; 
+    q->sqvh[5].table = vlcbuf18;
+    q->sqvh[6].table = vlcbuf19;
+    q->ccpl.table = vlcbuf20;
 
-    result = 0;
+    /* Init envelope VLC (13 books) */
     for (i=0 ; i<13 ; i++) {
-        q->envelope_quant_index[i].table = vlcbuf[i];
-        q->envelope_quant_index[i].table_allocated = VLCBUFSIZE;
+        q->envelope_quant_index[i].table_allocated = env_size[i];
         result |= init_vlc (&q->envelope_quant_index[i], 9, 24,
             envelope_quant_index_huffbits[i], 1, 1,
             envelope_quant_index_huffcodes[i], 2, 2, INIT_VLC_USE_NEW_STATIC);
     }
-    DEBUGF("sqvh VLC init\n");
+
+    /* Init subband VLC (7 books) */
     for (i=0 ; i<7 ; i++) {
-        q->sqvh[i].table = vlcbuf[i+13];
-        q->sqvh[i].table_allocated = VLCBUFSIZE;
+        q->sqvh[i].table_allocated = sqvh_size[i];
         result |= init_vlc (&q->sqvh[i], vhvlcsize_tab[i], vhsize_tab[i],
             cvh_huffbits[i], 1, 1,
             cvh_huffcodes[i], 2, 2, INIT_VLC_USE_NEW_STATIC);
     }
 
+    /* Init Joint-Stereo VLC (1 book) */
     if (q->nb_channels==2 && q->joint_stereo==1){
-        q->ccpl.table = vlcbuf[20];
-        q->ccpl.table_allocated = VLCBUFSIZE;
+        q->ccpl.table_allocated = ccpl_size;
         result |= init_vlc (&q->ccpl, 6, (1<<q->js_vlc_bits)-1,
             ccpl_huffbits[q->js_vlc_bits-2], 1, 1,
             ccpl_huffcodes[q->js_vlc_bits-2], 2, 2, INIT_VLC_USE_NEW_STATIC);
@@ -228,7 +279,7 @@
             if(vlc_index < 1) vlc_index = 1;
         }
         if (vlc_index>13) vlc_index = 13;           //the VLC tables >13 are identical to No. 13
-
+        
         j = get_vlc2(&q->gb, q->envelope_quant_index[vlc_index-1].table,
                      q->envelope_quant_index[vlc_index-1].bits,2);
         quant_index_table[i] = quant_index_table[i-1] + j - 12;    //differential encoding
@@ -368,6 +419,18 @@
     result = 0;
     for(i=0 ; i<vpr_tab[category] ; i++)
     {
+        /*
+        {
+            int m;
+            static int cnt = 0;
+            static int ff[7];
+            ++ff[category];
+            if (cnt%100==0)
+                for (m=0; m<7; ++m)
+                    printf("(%d) %d\n", m, ff[m]);
+            ++cnt;
+        }
+        */
         vlc = get_vlc2(&q->gb, q->sqvh[category].table, q->sqvh[category].bits, 3);
         if (q->bits_per_subpacket < get_bits_count(&q->gb))
         {
Index: apps/codecs/cook.c
===================================================================
--- apps/codecs/cook.c  (revision 29912)
+++ apps/codecs/cook.c  (working copy)
@@ -28,10 +28,10 @@
 
 CODEC_HEADER
 
-static RMContext rmctx;
-static RMPacket pkt;
-static COOKContext q IBSS_ATTR;
-static int32_t rm_outbuf[2048];
+static RMContext rmctx         IBSS_ATTR_COOK_LARGE_IRAM;
+static RMPacket pkt            IBSS_ATTR_COOK_LARGE_IRAM;
+static COOKContext q           IBSS_ATTR;
+static int32_t rm_outbuf[2048] IBSS_ATTR_COOK_LARGE_IRAM MEM_ALIGN_ATTR;
 
 static void init_rm(RMContext *rmctx)
 {