~ubuntu-branches/ubuntu/quantal/libmpc/quantal

« back to all changes in this revision

Viewing changes to libmpcenc/encode_sv7.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastian Dröge
  • Date: 2009-03-04 10:08:01 UTC
  • Revision ID: james.westby@ubuntu.com-20090304100801-k5vtj8jz06nomhlu
Tags: upstream-0.1~r435
Import upstream version 0.1~r435

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Musepack audio compression
 
3
 * Copyright (c) 2005-2009, The Musepack Development Team
 
4
 * Copyright (C) 1999-2004 Buschmann/Klemm/Piecha/Wolf
 
5
 *
 
6
 * This library is free software; you can redistribute it and/or
 
7
 * modify it under the terms of the GNU Lesser General Public
 
8
 * License as published by the Free Software Foundation; either
 
9
 * version 2.1 of the License, or (at your option) any later version.
 
10
 *
 
11
 * This library is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
14
 * Lesser General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU Lesser General Public
 
17
 * License along with this library; if not, write to the Free Software
 
18
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
19
 */
 
20
 
 
21
#include <stdlib.h>
 
22
#include <stdio.h>
 
23
 
 
24
#include "libmpcenc.h"
 
25
#include <mpc/minimax.h>
 
26
 
 
27
void Klemm ( void );
 
28
void Init_Skalenfaktoren ( void );
 
29
 
 
30
// huffsv7.c
 
31
extern Huffman_t const HuffBands [33];
 
32
extern Huffman_t const HuffRes [2][17];
 
33
extern Huffman_t const HuffSCFI_1 [4];         // contains tables for SV7-scalefactor select
 
34
extern Huffman_t const HuffSCFI_2 [16];         // contains tables for SV7-scalefactor select
 
35
extern Huffman_t const HuffDSCF_1 [64];         // contains tables for SV7-scalefactor coding
 
36
extern Huffman_t const HuffDSCF_2 [65];         // contains tables for SV7-scalefactor coding
 
37
extern Huffman_t const * const HuffQ [2][8];         // points to tables for SV7-sample coding
 
38
extern Huffman_t const HuffQ9up [256];
 
39
 
 
40
/*
 
41
 *  SV1:   DATE 13.12.1998
 
42
 *  SV2:   DATE 12.06.1999
 
43
 *  SV3:   DATE 19.10.1999
 
44
 *  SV4:   DATE 20.10.1999
 
45
 *  SV5:   DATE 18.06.2000
 
46
 *  SV6:   DATE 10.08.2000
 
47
 *  SV7:   DATE 23.08.2000
 
48
 *  SV7.f: DATE 20.07.2002
 
49
 */
 
50
 
 
51
// initialize SV8
 
52
void
 
53
mpc_encoder_init ( mpc_encoder_t * e,
 
54
                                   mpc_uint64_t SamplesInWAVE,
 
55
                                   unsigned int FramesBlockPwr,
 
56
                                   unsigned int SeekDistance )
 
57
{
 
58
        Init_Skalenfaktoren ();
 
59
        Klemm    ();
 
60
 
 
61
        memset(e, 0, sizeof(*e));
 
62
 
 
63
        if (SeekDistance > 15)
 
64
                SeekDistance = 1;
 
65
        if (FramesBlockPwr > 14)
 
66
                FramesBlockPwr = 6;
 
67
 
 
68
        e->seek_pwr = SeekDistance;
 
69
        e->frames_per_block_pwr = FramesBlockPwr;
 
70
 
 
71
        if (SamplesInWAVE == 0)
 
72
                e->seek_table = malloc((1 << 16) * sizeof(mpc_uint32_t));
 
73
        else
 
74
                e->seek_table = malloc((size_t)(2 + SamplesInWAVE / (MPC_FRAME_LENGTH << (e->seek_pwr + e->frames_per_block_pwr))) * sizeof(mpc_uint32_t));
 
75
 
 
76
        e->buffer = malloc(MAX_FRAME_SIZE * (1 << e->frames_per_block_pwr) * sizeof(mpc_uint8_t));
 
77
}
 
78
 
 
79
void
 
80
mpc_encoder_exit ( mpc_encoder_t * e )
 
81
{
 
82
        free(e->seek_table);
 
83
        free(e->buffer);
 
84
}
 
85
 
 
86
// writes replay gain info
 
87
void writeGainInfo ( mpc_encoder_t * e,
 
88
                                         unsigned short t_gain,
 
89
                                         unsigned short t_peak,
 
90
                                         unsigned short a_gain,
 
91
                                         unsigned short a_peak)
 
92
{
 
93
        writeBits ( e, 1,  8 ); // version
 
94
        writeBits ( e, t_gain,  16 ); // Title gain
 
95
        writeBits ( e, t_peak,  16 ); // Title peak
 
96
        writeBits ( e, a_gain,  16 ); // Album gain
 
97
        writeBits ( e, a_peak,  16 ); // Album peak
 
98
}
 
99
 
 
100
// writes SV8-header
 
101
void
 
102
writeStreamInfo ( mpc_encoder_t*e,
 
103
                                  const unsigned int  MaxBand,
 
104
                  const unsigned int  MS_on,
 
105
                  const unsigned int  SamplesCount,
 
106
                                  const unsigned int  SamplesSkip,
 
107
                  const unsigned int  SampleFreq,
 
108
                                  const unsigned int  ChannelCount)
 
109
{
 
110
        unsigned char tmp[10];
 
111
        int i, len;
 
112
 
 
113
    writeBits ( e, 8,  8 );    // StreamVersion
 
114
 
 
115
        len = encodeSize(SamplesCount, (char *)tmp, MPC_FALSE);
 
116
        for( i = 0; i < len; i++) // nb of samples
 
117
                writeBits ( e, tmp[i], 8 );
 
118
        len = encodeSize(SamplesSkip, (char *)tmp, MPC_FALSE);
 
119
        for( i = 0; i < len; i++) // nb of samples to skip at beginning
 
120
                writeBits ( e, tmp[i], 8 );
 
121
 
 
122
        switch ( SampleFreq ) {
 
123
                case 44100: writeBits ( e, 0, 3 ); break;
 
124
                case 48000: writeBits ( e, 1, 3 ); break;
 
125
                case 37800: writeBits ( e, 2, 3 ); break;
 
126
                case 32000: writeBits ( e, 3, 3 ); break;
 
127
                default   : fprintf(stderr, "Internal error\n");// FIXME : stderr_printf ( "Internal error\n");
 
128
                exit (1);
 
129
        }
 
130
 
 
131
        writeBits ( e, MaxBand - 1  ,  5 );    // Bandwidth
 
132
        writeBits ( e, ChannelCount - 1  ,  4 );    // Channels
 
133
        writeBits ( e, MS_on        ,  1 );    // MS-Coding Flag
 
134
        writeBits ( e, e->frames_per_block_pwr >> 1,  3 );    // frames per block (log4 unit)
 
135
}
 
136
 
 
137
// writes encoder signature
 
138
void writeEncoderInfo ( mpc_encoder_t * e,
 
139
                                                const float profile,
 
140
                                                const int PNS_on,
 
141
                                                const int version_major,
 
142
                                                const int version_minor,
 
143
                                                const int version_build )
 
144
{
 
145
        writeBits ( e, (mpc_uint32_t)(profile * 8 + .5),  7 );
 
146
        writeBits ( e, PNS_on,  1 );
 
147
        writeBits ( e, version_major,  8 );
 
148
        writeBits ( e, version_minor,  8 );
 
149
        writeBits ( e, version_build,  8 );
 
150
}
 
151
 
 
152
// formatting and writing SV8-bitstream for one frame
 
153
void
 
154
writeBitstream_SV8 ( mpc_encoder_t* e, int MaxBand)
 
155
{
 
156
        int n;
 
157
        const Huffman_t * Table, * Tables[2];
 
158
        mpc_int32_t * Res_L = e->Res_L;
 
159
        mpc_int32_t * Res_R = e->Res_R;
 
160
        mpc_bool_t * DSCF_Flag_L = e->DSCF_Flag_L;
 
161
        mpc_bool_t * DSCF_Flag_R = e->DSCF_Flag_R;
 
162
        mpc_int32_t * SCF_Last_L = e->SCF_Last_L;
 
163
        mpc_int32_t * SCF_Last_R = e->SCF_Last_R;
 
164
 
 
165
        for( n = MaxBand; n >= 0; n--)
 
166
                if (Res_L[n] != 0 || Res_R[n] != 0) break;
 
167
 
 
168
        n++;
 
169
        if (e->framesInBlock == 0) {
 
170
                encodeLog(e, n, MaxBand + 1);
 
171
                MaxBand = e->MaxBand = n;
 
172
        } else {
 
173
                n = n - e->MaxBand;
 
174
                MaxBand = e->MaxBand = n + e->MaxBand;
 
175
                if (n < 0) n += 33;
 
176
                writeBits(e, HuffBands[n].Code, HuffBands[n].Length);
 
177
        }
 
178
 
 
179
        /************************************ Resolution *********************************/
 
180
 
 
181
        if (MaxBand) {
 
182
                {
 
183
                        int tmp = Res_L[MaxBand - 1];
 
184
                        if (tmp < 0) tmp += 17;
 
185
                        writeBits(e, HuffRes[0][tmp].Code, HuffRes[0][tmp].Length);
 
186
                        tmp = Res_R[MaxBand - 1];
 
187
                        if (tmp < 0) tmp += 17;
 
188
                        writeBits(e, HuffRes[0][tmp].Code, HuffRes[0][tmp].Length);
 
189
                }
 
190
                for ( n = MaxBand - 2; n >= 0; n--) {
 
191
                        int tmp = Res_L[n] - Res_L[n + 1];
 
192
                        if (tmp < 0) tmp += 17;
 
193
                        writeBits(e, HuffRes[Res_L[n + 1] > 2][tmp].Code, HuffRes[Res_L[n + 1] > 2][tmp].Length);
 
194
 
 
195
                        tmp = Res_R[n] - Res_R[n + 1];
 
196
                        if (tmp < 0) tmp += 17;
 
197
                        writeBits(e, HuffRes[Res_R[n + 1] > 2][tmp].Code, HuffRes[Res_R[n + 1] > 2][tmp].Length);
 
198
                }
 
199
 
 
200
                if (e->MS_Channelmode > 0) {
 
201
                        mpc_uint32_t tmp = 0;
 
202
                        int cnt = 0, tot = 0;
 
203
                        mpc_bool_t * MS_Flag = e->MS_Flag;
 
204
                        for( n = 0; n < MaxBand; n++) {
 
205
                                if ( Res_L[n] != 0 || Res_R[n] != 0 ) {
 
206
                                        tmp = (tmp << 1) | MS_Flag[n];
 
207
                                        cnt += MS_Flag[n];
 
208
                                        tot++;
 
209
                                }
 
210
                        }
 
211
                        encodeLog(e, cnt, tot);
 
212
                        if (cnt * 2 > tot) tmp = ~tmp;
 
213
                        encodeEnum(e, tmp, tot);
 
214
                }
 
215
        }
 
216
 
 
217
        /************************************ SCF encoding type ***********************************/
 
218
 
 
219
        if (e->framesInBlock == 0){
 
220
                for( n = 0; n < 32; n++)
 
221
                        DSCF_Flag_L[n] = DSCF_Flag_R[n] = 1; // new block -> force key frame
 
222
        }
 
223
 
 
224
        Tables[0] = HuffSCFI_1;
 
225
        Tables[1] = HuffSCFI_2;
 
226
        for ( n = 0; n < MaxBand; n++ ) {
 
227
                int tmp = 0, cnt = -1;
 
228
                if (Res_L[n]) {
 
229
                        tmp = (e->SCF_Index_L[n][1] == e->SCF_Index_L[n][0]) * 2 + (e->SCF_Index_L[n][2] == e->SCF_Index_L[n][1]);
 
230
                        cnt++;
 
231
                }
 
232
                if (Res_R[n]) {
 
233
                        tmp = (tmp << 2) | ((e->SCF_Index_R[n][1] == e->SCF_Index_R[n][0]) * 2 + (e->SCF_Index_R[n][2] == e->SCF_Index_R[n][1]));
 
234
                        cnt++;
 
235
                }
 
236
                if (cnt >= 0)
 
237
                        writeBits(e, Tables[cnt][tmp].Code, Tables[cnt][tmp].Length);
 
238
        }
 
239
 
 
240
        /************************************* SCF **********************************/
 
241
 
 
242
        for ( n = 0; n < MaxBand; n++ ) {
 
243
                if ( Res_L[n] ) {
 
244
                        int m;
 
245
                        mpc_int32_t * SCFI_L_n = e->SCF_Index_L[n];
 
246
                        if (DSCF_Flag_L[n] == 1) {
 
247
                                writeBits(e, SCFI_L_n[0] + 6, 7);
 
248
                                DSCF_Flag_L[n] = 0;
 
249
                        } else {
 
250
                                unsigned int tmp = (SCFI_L_n[0] - SCF_Last_L[n] + 31) & 127;
 
251
                                if (tmp < 64)
 
252
                                        writeBits(e, HuffDSCF_2[tmp].Code, HuffDSCF_2[tmp].Length);
 
253
                                else {
 
254
                                        writeBits(e, HuffDSCF_2[64].Code, HuffDSCF_2[64].Length);
 
255
                                        writeBits(e, tmp - 64, 6);
 
256
                                }
 
257
                        }
 
258
                        for( m = 0; m < 2; m++){
 
259
                                if (SCFI_L_n[m+1] != SCFI_L_n[m]) {
 
260
                                        unsigned int tmp = (SCFI_L_n[m+1] - SCFI_L_n[m] + 31) & 127;
 
261
                                        if (tmp < 64)
 
262
                                                writeBits(e, HuffDSCF_1[tmp].Code, HuffDSCF_1[tmp].Length);
 
263
                                        else {
 
264
                                                writeBits(e, HuffDSCF_1[31].Code, HuffDSCF_1[31].Length);
 
265
                                                writeBits(e, tmp - 64, 6);
 
266
                                        }
 
267
                                }
 
268
                        }
 
269
                        SCF_Last_L[n] = SCFI_L_n[2];
 
270
                }
 
271
                if ( Res_R[n] ) {
 
272
                        int m;
 
273
                        mpc_int32_t * SCFI_R_n = e->SCF_Index_R[n];
 
274
                        if (DSCF_Flag_R[n] == 1) {
 
275
                                writeBits(e, SCFI_R_n[0] + 6, 7);
 
276
                                DSCF_Flag_R[n] = 0;
 
277
                        } else {
 
278
                                unsigned int tmp = (SCFI_R_n[0] - SCF_Last_R[n] + 31) & 127;
 
279
                                if (tmp < 64)
 
280
                                        writeBits(e, HuffDSCF_2[tmp].Code, HuffDSCF_2[tmp].Length);
 
281
                                else {
 
282
                                        writeBits(e, HuffDSCF_2[64].Code, HuffDSCF_2[64].Length);
 
283
                                        writeBits(e, tmp - 64, 6);
 
284
                                }
 
285
                        }
 
286
                        for( m = 0; m < 2; m++){
 
287
                                if (SCFI_R_n[m+1] != SCFI_R_n[m]) {
 
288
                                        unsigned int tmp = (SCFI_R_n[m+1] - SCFI_R_n[m] + 31) & 127;
 
289
                                        if (tmp < 64)
 
290
                                                writeBits(e, HuffDSCF_1[tmp].Code, HuffDSCF_1[tmp].Length);
 
291
                                        else {
 
292
                                                writeBits(e, HuffDSCF_1[31].Code, HuffDSCF_1[31].Length);
 
293
                                                writeBits(e, tmp - 64, 6);
 
294
                                        }
 
295
                                }
 
296
                        }
 
297
                        SCF_Last_R[n] = SCFI_R_n[2];
 
298
                }
 
299
        }
 
300
 
 
301
        /*********************************** Samples *********************************/
 
302
        for ( n = 0; n < MaxBand; n++ ) {
 
303
                int Res = Res_L[n];
 
304
                const mpc_int16_t * q = e->Q[n].L;
 
305
                static const unsigned int thres[] = {0, 0, 3, 7, 9, 1, 3, 4, 8};
 
306
                static const int HuffQ2_var[5*5*5] =
 
307
                {6, 5, 4, 5, 6, 5, 4, 3, 4, 5, 4, 3, 2, 3, 4, 5, 4, 3, 4, 5, 6, 5, 4, 5, 6, 5, 4, 3, 4, 5, 4, 3, 2, 3, 4, 3, 2, 1, 2, 3, 4, 3, 2, 3, 4, 5, 4, 3, 4, 5, 4, 3, 2, 3, 4, 3, 2, 1, 2, 3, 2, 1, 0, 1, 2, 3, 2, 1, 2, 3, 4, 3, 2, 3, 4, 5, 4, 3, 4, 5, 4, 3, 2, 3, 4, 3, 2, 1, 2, 3, 4, 3, 2, 3, 4, 5, 4, 3, 4, 5, 6, 5, 4, 5, 6, 5, 4, 3, 4, 5, 4, 3, 2, 3, 4, 5, 4, 3, 4, 5, 6, 5, 4, 5, 6};
 
308
 
 
309
                do {
 
310
                        int k = 0, idx = 1, cnt = 0, sng;
 
311
                        switch ( Res ) {
 
312
                                case -1:
 
313
                                case  0:
 
314
                                        break;
 
315
                                case  1:
 
316
                                        Table = HuffQ [0][0];
 
317
                                        for( ; k < 36; ){
 
318
                                                int kmax = k + 18;
 
319
                                                cnt = 0, sng = 0;
 
320
                                                for ( ; k < kmax; k++) {
 
321
                                                        idx <<= 1;
 
322
                                                        if (q[k] != 1) {
 
323
                                                                cnt++;
 
324
                                                                idx |= 1;
 
325
                                                                sng = (sng << 1) | (q[k] >> 1);
 
326
                                                        }
 
327
                                                }
 
328
                                                writeBits(e, Table[cnt].Code, Table[cnt].Length);
 
329
                                                if (cnt > 0) {
 
330
                                                        if (cnt > 9) idx = ~idx;
 
331
                                                        encodeEnum(e, idx, 18);
 
332
                                                        writeBits(e, sng, cnt);
 
333
                                                }
 
334
                                        }
 
335
                                        break;
 
336
                                case  2:
 
337
                                        Tables[0] = HuffQ [0][1];
 
338
                                        Tables[1] = HuffQ [1][1];
 
339
                                        idx = 2 * thres[Res];
 
340
                                        for ( ; k < 36; k += 3) {
 
341
                                                int tmp = q[k] + 5*q[k+1] + 25*q[k+2];
 
342
                                                writeBits ( e, Tables[idx > thres[Res]][tmp].Code,
 
343
                                                                        Tables[idx > thres[Res]][tmp].Length );
 
344
                                                idx = (idx >> 1) + HuffQ2_var[tmp];
 
345
                                        }
 
346
                                        break;
 
347
                                case  3:
 
348
                                case  4:
 
349
                                        Table = HuffQ [0][Res - 1];
 
350
                                        for ( ; k < 36; k += 2 ) {
 
351
                                                int tmp = q[k] + thres[Res]*q[k+1];
 
352
                                                writeBits ( e, Table[tmp].Code, Table[tmp].Length );
 
353
                                        }
 
354
                                        break;
 
355
                                case  5:
 
356
                                case  6:
 
357
                                case  7:
 
358
                                case  8:
 
359
                                        Tables[0] = HuffQ [0][Res - 1];
 
360
                                        Tables[1] = HuffQ [1][Res - 1];
 
361
                                        idx = 2 * thres[Res];
 
362
                                        for ( ; k < 36; k++ ) {
 
363
                                                int tmp = q[k] - (1 << (Res - 2)) + 1;
 
364
                                                writeBits ( e, Tables[idx > thres[Res]][q[k]].Code,
 
365
                                                                        Tables[idx > thres[Res]][q[k]].Length );
 
366
                                                if (tmp < 0) tmp = -tmp;
 
367
                                                idx = (idx >> 1) + tmp;
 
368
                                        }
 
369
                                        break;
 
370
                                default:
 
371
                                        for ( ; k < 36; k++ ) {
 
372
                                                writeBits ( e, HuffQ9up[q[k] >> (Res - 9)].Code,
 
373
                                                                        HuffQ9up[q[k] >> (Res - 9)].Length );
 
374
                                                if (Res != 9)
 
375
                                                        writeBits ( e, q[k] & ((1 << (Res - 9)) - 1), Res - 9);
 
376
                                        }
 
377
                                        break;
 
378
                        }
 
379
 
 
380
                        Res = Res_R[n];
 
381
                } while (q == e->Q[n].L && (q = e->Q[n].R));
 
382
        }
 
383
 
 
384
        e->framesInBlock++;
 
385
        if (e->framesInBlock == (1 << e->frames_per_block_pwr)) {
 
386
                if ((e->block_cnt & ((1 << e->seek_pwr) - 1)) == 0) {
 
387
                        e->seek_table[e->seek_pos] = ftell(e->outputFile);
 
388
                        e->seek_pos++;
 
389
                }
 
390
                e->block_cnt++;
 
391
                writeBlock(e, "AP", MPC_FALSE, 0);
 
392
        }
 
393
}
 
394
 
 
395
#if 0
 
396
 
 
397
typedef struct {
 
398
        int Symbol;
 
399
        unsigned int Count;
 
400
        unsigned int Code;
 
401
        unsigned int Bits;
 
402
} huff_sym_t;
 
403
 
 
404
void _Huffman_MakeTree( huff_sym_t *sym, unsigned int num_symbols);
 
405
void _Huffman_PrintCodes(huff_sym_t * sym, unsigned int num_symbols, int print_type, int offset);
 
406
 
 
407
void print_histo(void)
 
408
{
 
409
        int i, j;
 
410
        huff_sym_t sym[HISTO_NB][HISTO_LEN];
 
411
        unsigned int dist[HISTO_NB];
 
412
        unsigned int size[HISTO_NB];
 
413
        unsigned int cnt[HISTO_NB];
 
414
        unsigned int total_cnt, total_size, full_count = 0, full_size = 0;
 
415
        double optim_size, full_optim = 0;
 
416
 
 
417
        return;
 
418
 
 
419
        memset(dist, 1, sizeof dist);
 
420
        memset(sym, 0, sizeof(huff_sym_t) * HISTO_LEN * HISTO_NB);
 
421
 
 
422
        for(j = 0 ; j < HISTO_NB ; j++) {
 
423
                for(i = 0 ; i < HISTO_LEN; i++) {
 
424
                        sym[j][i].Symbol = i;
 
425
                        sym[j][i].Count = histo[j][i];
 
426
                        if (sym[j][i].Count == 0)
 
427
                                sym[j][i].Count = 1;
 
428
                }
 
429
                _Huffman_MakeTree(sym[j], HISTO_LEN);
 
430
                _Huffman_PrintCodes(sym[j], HISTO_LEN, 3, 0);
 
431
                _Huffman_PrintCodes(sym[j], HISTO_LEN, 0, 0);
 
432
                _Huffman_PrintCodes(sym[j], HISTO_LEN, 1, 0);
 
433
                total_cnt = 0;
 
434
                total_size = 0;
 
435
                optim_size = 0;
 
436
                for( i = 0; i < HISTO_LEN; i++) {
 
437
                        total_cnt += sym[j][i].Count;
 
438
                        total_size += sym[j][i].Count * sym[j][i].Bits;
 
439
                        if (sym[j][i].Count != 0)
 
440
                                optim_size += sym[j][i].Count * __builtin_log2(sym[j][i].Count);
 
441
                }
 
442
                full_count += total_cnt;
 
443
                full_size += total_size;
 
444
                optim_size = total_cnt * __builtin_log2(total_cnt) - optim_size;
 
445
                full_optim += optim_size;
 
446
                size[j] = total_size;
 
447
                cnt[j] = total_cnt;
 
448
                printf("%u count : %u huff : %f bps ", j, total_cnt, (float)total_size / total_cnt);
 
449
                printf("opt : %f bps ", (float)optim_size / total_cnt);
 
450
                printf("loss : %f bps (%f %%)\n", (float)(total_size - optim_size) / total_cnt, (float)(total_size - optim_size) * 100 / optim_size);
 
451
                for( i = 0; i < HISTO_LEN; i++){
 
452
                        printf("%u ", sym[j][i].Bits);
 
453
                }
 
454
 
 
455
                printf("\n\n");
 
456
        }
 
457
        printf("cnt : %u size %f optim %f\n", full_count, (float)full_size / full_count, (float)full_optim / full_count);
 
458
        printf("loss : %f bps (%f %%)\n", (float)(full_size - full_optim) / full_count, (float)(full_size - full_optim) * 100 / full_optim);
 
459
 
 
460
 
 
461
        printf("\n");
 
462
}
 
463
 
 
464
void
 
465
Dump ( const unsigned int* q, const int Res )
 
466
{
 
467
    switch ( Res ) {
 
468
    case  1:
 
469
        for ( k = 0; k < 36; k++, q++ )
 
470
            printf ("%2d%c", *q-1, k==35?'\n':' ');
 
471
        break;
 
472
    case  2:
 
473
        for ( k = 0; k < 36; k++, q++ )
 
474
            printf ("%2d%c", *q-2, k==35?'\n':' ');
 
475
        break;
 
476
    case  3: case  4: case  5: case  6: case  7:
 
477
        if ( Res == 5 )
 
478
            for ( k = 0; k < 36; k++, q++ )
 
479
                printf ("%2d%c", *q-7, k==35?'\n':' ');
 
480
        break;
 
481
    case  8: case  9: case 10: case 11: case 12: case 13: case 14: case 15: case 16: case 17:
 
482
        printf ("%2u: ", Res-1 );
 
483
        for ( k = 0; k < 36; k++, q++ ) {
 
484
            printf ("%6d", *q - (1 << (Res-2)) );
 
485
        }
 
486
        printf ("\n");
 
487
        break;
 
488
    }
 
489
}
 
490
#endif
 
491
 
 
492
/* end of encode_sv7.c */