annotate vorbis_enc.c @ 3835:40acb836a6d3 libavcodec

Original Commit: r31 | ods15 | 2006-09-22 18:33:17 +0300 (Fri, 22 Sep 2006) | 2 lines use my own bitpacker
author ods15
date Mon, 02 Oct 2006 05:56:10 +0000
parents e99820d52041
children ff31b13b57df
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3808
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
1 /*
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
2 * copyright (c) 2006 Oded Shimon <ods15@ods15.dyndns.org>
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
3 *
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
4 * This library is free software; you can redistribute it and/or
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
5 * modify it under the terms of the GNU Lesser General Public
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
6 * License as published by the Free Software Foundation; either
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
7 * version 2 of the License, or (at your option) any later version.
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
8 *
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
9 * This library is distributed in the hope that it will be useful,
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
12 * Lesser General Public License for more details.
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
13 *
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
14 * You should have received a copy of the GNU Lesser General Public
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
15 * License along with this library; if not, write to the Free Software
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
17 */
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
18
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
19 /**
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
20 * @file vorbis_enc.c
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
21 * Native Vorbis encoder.
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
22 * @author Oded Shimon <ods15@ods15.dyndns.org>
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
23 */
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
24
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
25 #include "avcodec.h"
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
26
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
27 #undef NDEBUG
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
28 #include <assert.h>
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
29
3835
40acb836a6d3 Original Commit: r31 | ods15 | 2006-09-22 18:33:17 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3834
diff changeset
30 //#define ALT_BITSTREAM_WRITER
40acb836a6d3 Original Commit: r31 | ods15 | 2006-09-22 18:33:17 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3834
diff changeset
31 //#include "bitstream.h"
3810
a8bebf3e9cb7 Original Commit: r4 | ods15 | 2006-09-16 15:36:03 +0300 (Sat, 16 Sep 2006) | 3 lines
ods15
parents: 3809
diff changeset
32
3808
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
33 typedef struct {
3810
a8bebf3e9cb7 Original Commit: r4 | ods15 | 2006-09-16 15:36:03 +0300 (Sat, 16 Sep 2006) | 3 lines
ods15
parents: 3809
diff changeset
34 int len;
a8bebf3e9cb7 Original Commit: r4 | ods15 | 2006-09-16 15:36:03 +0300 (Sat, 16 Sep 2006) | 3 lines
ods15
parents: 3809
diff changeset
35 uint32_t codeword;
3818
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
36 } cb_entry_t;
3810
a8bebf3e9cb7 Original Commit: r4 | ods15 | 2006-09-16 15:36:03 +0300 (Sat, 16 Sep 2006) | 3 lines
ods15
parents: 3809
diff changeset
37
a8bebf3e9cb7 Original Commit: r4 | ods15 | 2006-09-16 15:36:03 +0300 (Sat, 16 Sep 2006) | 3 lines
ods15
parents: 3809
diff changeset
38 typedef struct {
a8bebf3e9cb7 Original Commit: r4 | ods15 | 2006-09-16 15:36:03 +0300 (Sat, 16 Sep 2006) | 3 lines
ods15
parents: 3809
diff changeset
39 int nentries;
3818
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
40 cb_entry_t * entries;
3810
a8bebf3e9cb7 Original Commit: r4 | ods15 | 2006-09-16 15:36:03 +0300 (Sat, 16 Sep 2006) | 3 lines
ods15
parents: 3809
diff changeset
41 int ndimentions;
a8bebf3e9cb7 Original Commit: r4 | ods15 | 2006-09-16 15:36:03 +0300 (Sat, 16 Sep 2006) | 3 lines
ods15
parents: 3809
diff changeset
42 float min;
a8bebf3e9cb7 Original Commit: r4 | ods15 | 2006-09-16 15:36:03 +0300 (Sat, 16 Sep 2006) | 3 lines
ods15
parents: 3809
diff changeset
43 float delta;
a8bebf3e9cb7 Original Commit: r4 | ods15 | 2006-09-16 15:36:03 +0300 (Sat, 16 Sep 2006) | 3 lines
ods15
parents: 3809
diff changeset
44 int seq_p;
a8bebf3e9cb7 Original Commit: r4 | ods15 | 2006-09-16 15:36:03 +0300 (Sat, 16 Sep 2006) | 3 lines
ods15
parents: 3809
diff changeset
45 int lookup;
a8bebf3e9cb7 Original Commit: r4 | ods15 | 2006-09-16 15:36:03 +0300 (Sat, 16 Sep 2006) | 3 lines
ods15
parents: 3809
diff changeset
46 int * quantlist;
3818
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
47 float * dimentions;
3810
a8bebf3e9cb7 Original Commit: r4 | ods15 | 2006-09-16 15:36:03 +0300 (Sat, 16 Sep 2006) | 3 lines
ods15
parents: 3809
diff changeset
48 } codebook_t;
a8bebf3e9cb7 Original Commit: r4 | ods15 | 2006-09-16 15:36:03 +0300 (Sat, 16 Sep 2006) | 3 lines
ods15
parents: 3809
diff changeset
49
a8bebf3e9cb7 Original Commit: r4 | ods15 | 2006-09-16 15:36:03 +0300 (Sat, 16 Sep 2006) | 3 lines
ods15
parents: 3809
diff changeset
50 typedef struct {
3814
464eca766731 Original Commit: r8 | ods15 | 2006-09-17 09:43:38 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3813
diff changeset
51 int dim;
464eca766731 Original Commit: r8 | ods15 | 2006-09-17 09:43:38 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3813
diff changeset
52 int subclass;
464eca766731 Original Commit: r8 | ods15 | 2006-09-17 09:43:38 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3813
diff changeset
53 int masterbook;
464eca766731 Original Commit: r8 | ods15 | 2006-09-17 09:43:38 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3813
diff changeset
54 int * books;
464eca766731 Original Commit: r8 | ods15 | 2006-09-17 09:43:38 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3813
diff changeset
55 } floor_class_t;
464eca766731 Original Commit: r8 | ods15 | 2006-09-17 09:43:38 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3813
diff changeset
56
464eca766731 Original Commit: r8 | ods15 | 2006-09-17 09:43:38 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3813
diff changeset
57 typedef struct {
464eca766731 Original Commit: r8 | ods15 | 2006-09-17 09:43:38 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3813
diff changeset
58 int partitions;
464eca766731 Original Commit: r8 | ods15 | 2006-09-17 09:43:38 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3813
diff changeset
59 int * partition_to_class;
464eca766731 Original Commit: r8 | ods15 | 2006-09-17 09:43:38 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3813
diff changeset
60 int nclasses;
464eca766731 Original Commit: r8 | ods15 | 2006-09-17 09:43:38 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3813
diff changeset
61 floor_class_t * classes;
464eca766731 Original Commit: r8 | ods15 | 2006-09-17 09:43:38 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3813
diff changeset
62 int multiplier;
464eca766731 Original Commit: r8 | ods15 | 2006-09-17 09:43:38 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3813
diff changeset
63 int rangebits;
464eca766731 Original Commit: r8 | ods15 | 2006-09-17 09:43:38 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3813
diff changeset
64 int values;
464eca766731 Original Commit: r8 | ods15 | 2006-09-17 09:43:38 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3813
diff changeset
65 struct { int x; } * list;
3813
95b70f8bc29e Original Commit: r7 | ods15 | 2006-09-17 08:50:47 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3812
diff changeset
66 } floor_t;
95b70f8bc29e Original Commit: r7 | ods15 | 2006-09-17 08:50:47 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3812
diff changeset
67
95b70f8bc29e Original Commit: r7 | ods15 | 2006-09-17 08:50:47 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3812
diff changeset
68 typedef struct {
3815
3fa081422f78 Original Commit: r9 | ods15 | 2006-09-17 18:56:41 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3814
diff changeset
69 int type;
3fa081422f78 Original Commit: r9 | ods15 | 2006-09-17 18:56:41 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3814
diff changeset
70 int begin;
3fa081422f78 Original Commit: r9 | ods15 | 2006-09-17 18:56:41 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3814
diff changeset
71 int end;
3fa081422f78 Original Commit: r9 | ods15 | 2006-09-17 18:56:41 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3814
diff changeset
72 int partition_size;
3fa081422f78 Original Commit: r9 | ods15 | 2006-09-17 18:56:41 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3814
diff changeset
73 int classifications;
3fa081422f78 Original Commit: r9 | ods15 | 2006-09-17 18:56:41 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3814
diff changeset
74 int classbook;
3fa081422f78 Original Commit: r9 | ods15 | 2006-09-17 18:56:41 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3814
diff changeset
75 int (*books)[8];
3813
95b70f8bc29e Original Commit: r7 | ods15 | 2006-09-17 08:50:47 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3812
diff changeset
76 } residue_t;
95b70f8bc29e Original Commit: r7 | ods15 | 2006-09-17 08:50:47 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3812
diff changeset
77
95b70f8bc29e Original Commit: r7 | ods15 | 2006-09-17 08:50:47 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3812
diff changeset
78 typedef struct {
3816
6eba53afa0b0 Original Commit: r10 | ods15 | 2006-09-17 19:37:17 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3815
diff changeset
79 int submaps;
6eba53afa0b0 Original Commit: r10 | ods15 | 2006-09-17 19:37:17 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3815
diff changeset
80 int * mux;
6eba53afa0b0 Original Commit: r10 | ods15 | 2006-09-17 19:37:17 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3815
diff changeset
81 int * floor;
6eba53afa0b0 Original Commit: r10 | ods15 | 2006-09-17 19:37:17 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3815
diff changeset
82 int * residue;
3813
95b70f8bc29e Original Commit: r7 | ods15 | 2006-09-17 08:50:47 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3812
diff changeset
83 } mapping_t;
95b70f8bc29e Original Commit: r7 | ods15 | 2006-09-17 08:50:47 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3812
diff changeset
84
95b70f8bc29e Original Commit: r7 | ods15 | 2006-09-17 08:50:47 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3812
diff changeset
85 typedef struct {
3817
3ca15f0d4882 Original Commit: r11 | ods15 | 2006-09-17 19:41:28 +0300 (Sun, 17 Sep 2006) | 4 lines
ods15
parents: 3816
diff changeset
86 int blockflag;
3ca15f0d4882 Original Commit: r11 | ods15 | 2006-09-17 19:41:28 +0300 (Sun, 17 Sep 2006) | 4 lines
ods15
parents: 3816
diff changeset
87 int mapping;
3ca15f0d4882 Original Commit: r11 | ods15 | 2006-09-17 19:41:28 +0300 (Sun, 17 Sep 2006) | 4 lines
ods15
parents: 3816
diff changeset
88 } vorbis_mode_t;
3ca15f0d4882 Original Commit: r11 | ods15 | 2006-09-17 19:41:28 +0300 (Sun, 17 Sep 2006) | 4 lines
ods15
parents: 3816
diff changeset
89
3ca15f0d4882 Original Commit: r11 | ods15 | 2006-09-17 19:41:28 +0300 (Sun, 17 Sep 2006) | 4 lines
ods15
parents: 3816
diff changeset
90 typedef struct {
3811
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
91 int channels;
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
92 int sample_rate;
3818
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
93 int blocksize[2]; // in (1<<n) format
3811
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
94
3810
a8bebf3e9cb7 Original Commit: r4 | ods15 | 2006-09-16 15:36:03 +0300 (Sat, 16 Sep 2006) | 3 lines
ods15
parents: 3809
diff changeset
95 int ncodebooks;
a8bebf3e9cb7 Original Commit: r4 | ods15 | 2006-09-16 15:36:03 +0300 (Sat, 16 Sep 2006) | 3 lines
ods15
parents: 3809
diff changeset
96 codebook_t * codebooks;
3813
95b70f8bc29e Original Commit: r7 | ods15 | 2006-09-17 08:50:47 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3812
diff changeset
97
95b70f8bc29e Original Commit: r7 | ods15 | 2006-09-17 08:50:47 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3812
diff changeset
98 int nfloors;
95b70f8bc29e Original Commit: r7 | ods15 | 2006-09-17 08:50:47 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3812
diff changeset
99 floor_t * floors;
95b70f8bc29e Original Commit: r7 | ods15 | 2006-09-17 08:50:47 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3812
diff changeset
100
95b70f8bc29e Original Commit: r7 | ods15 | 2006-09-17 08:50:47 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3812
diff changeset
101 int nresidues;
95b70f8bc29e Original Commit: r7 | ods15 | 2006-09-17 08:50:47 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3812
diff changeset
102 residue_t * residues;
95b70f8bc29e Original Commit: r7 | ods15 | 2006-09-17 08:50:47 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3812
diff changeset
103
95b70f8bc29e Original Commit: r7 | ods15 | 2006-09-17 08:50:47 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3812
diff changeset
104 int nmappings;
95b70f8bc29e Original Commit: r7 | ods15 | 2006-09-17 08:50:47 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3812
diff changeset
105 mapping_t * mappings;
3817
3ca15f0d4882 Original Commit: r11 | ods15 | 2006-09-17 19:41:28 +0300 (Sun, 17 Sep 2006) | 4 lines
ods15
parents: 3816
diff changeset
106
3ca15f0d4882 Original Commit: r11 | ods15 | 2006-09-17 19:41:28 +0300 (Sun, 17 Sep 2006) | 4 lines
ods15
parents: 3816
diff changeset
107 int nmodes;
3ca15f0d4882 Original Commit: r11 | ods15 | 2006-09-17 19:41:28 +0300 (Sun, 17 Sep 2006) | 4 lines
ods15
parents: 3816
diff changeset
108 vorbis_mode_t * modes;
3808
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
109 } venc_context_t;
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
110
3835
40acb836a6d3 Original Commit: r31 | ods15 | 2006-09-22 18:33:17 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3834
diff changeset
111 typedef struct {
40acb836a6d3 Original Commit: r31 | ods15 | 2006-09-22 18:33:17 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3834
diff changeset
112 int total;
40acb836a6d3 Original Commit: r31 | ods15 | 2006-09-22 18:33:17 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3834
diff changeset
113 int total_pos;
40acb836a6d3 Original Commit: r31 | ods15 | 2006-09-22 18:33:17 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3834
diff changeset
114 int pos;
40acb836a6d3 Original Commit: r31 | ods15 | 2006-09-22 18:33:17 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3834
diff changeset
115 uint8_t * buf_ptr;
40acb836a6d3 Original Commit: r31 | ods15 | 2006-09-22 18:33:17 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3834
diff changeset
116 } PutBitContext;
40acb836a6d3 Original Commit: r31 | ods15 | 2006-09-22 18:33:17 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3834
diff changeset
117
40acb836a6d3 Original Commit: r31 | ods15 | 2006-09-22 18:33:17 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3834
diff changeset
118 static inline void init_put_bits(PutBitContext * pb, uint8_t * buf, int buffer_len) {
40acb836a6d3 Original Commit: r31 | ods15 | 2006-09-22 18:33:17 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3834
diff changeset
119 pb->total = buffer_len * 8;
40acb836a6d3 Original Commit: r31 | ods15 | 2006-09-22 18:33:17 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3834
diff changeset
120 pb->total_pos = 0;
40acb836a6d3 Original Commit: r31 | ods15 | 2006-09-22 18:33:17 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3834
diff changeset
121 pb->pos = 0;
40acb836a6d3 Original Commit: r31 | ods15 | 2006-09-22 18:33:17 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3834
diff changeset
122 pb->buf_ptr = buf;
40acb836a6d3 Original Commit: r31 | ods15 | 2006-09-22 18:33:17 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3834
diff changeset
123 }
40acb836a6d3 Original Commit: r31 | ods15 | 2006-09-22 18:33:17 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3834
diff changeset
124
40acb836a6d3 Original Commit: r31 | ods15 | 2006-09-22 18:33:17 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3834
diff changeset
125 static void put_bits(PutBitContext * pb, int bits, uint64_t val) {
40acb836a6d3 Original Commit: r31 | ods15 | 2006-09-22 18:33:17 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3834
diff changeset
126 if ((pb->total_pos += bits) >= pb->total) return;
40acb836a6d3 Original Commit: r31 | ods15 | 2006-09-22 18:33:17 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3834
diff changeset
127 if (!bits) return;
40acb836a6d3 Original Commit: r31 | ods15 | 2006-09-22 18:33:17 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3834
diff changeset
128 if (pb->pos) {
40acb836a6d3 Original Commit: r31 | ods15 | 2006-09-22 18:33:17 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3834
diff changeset
129 if (pb->pos > bits) {
40acb836a6d3 Original Commit: r31 | ods15 | 2006-09-22 18:33:17 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3834
diff changeset
130 *pb->buf_ptr |= val << (8 - pb->pos);
40acb836a6d3 Original Commit: r31 | ods15 | 2006-09-22 18:33:17 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3834
diff changeset
131 pb->pos -= bits;
40acb836a6d3 Original Commit: r31 | ods15 | 2006-09-22 18:33:17 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3834
diff changeset
132 bits = 0;
40acb836a6d3 Original Commit: r31 | ods15 | 2006-09-22 18:33:17 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3834
diff changeset
133 } else {
40acb836a6d3 Original Commit: r31 | ods15 | 2006-09-22 18:33:17 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3834
diff changeset
134 *pb->buf_ptr++ |= (val << (8 - pb->pos)) & 0xFF;
40acb836a6d3 Original Commit: r31 | ods15 | 2006-09-22 18:33:17 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3834
diff changeset
135 val >>= pb->pos;
40acb836a6d3 Original Commit: r31 | ods15 | 2006-09-22 18:33:17 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3834
diff changeset
136 bits -= pb->pos;
40acb836a6d3 Original Commit: r31 | ods15 | 2006-09-22 18:33:17 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3834
diff changeset
137 pb->pos = 0;
40acb836a6d3 Original Commit: r31 | ods15 | 2006-09-22 18:33:17 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3834
diff changeset
138 }
40acb836a6d3 Original Commit: r31 | ods15 | 2006-09-22 18:33:17 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3834
diff changeset
139 }
40acb836a6d3 Original Commit: r31 | ods15 | 2006-09-22 18:33:17 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3834
diff changeset
140 for (; bits >= 8; bits -= 8) {
40acb836a6d3 Original Commit: r31 | ods15 | 2006-09-22 18:33:17 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3834
diff changeset
141 *pb->buf_ptr++ = val & 0xFF;
40acb836a6d3 Original Commit: r31 | ods15 | 2006-09-22 18:33:17 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3834
diff changeset
142 val >>= 8;
40acb836a6d3 Original Commit: r31 | ods15 | 2006-09-22 18:33:17 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3834
diff changeset
143 }
40acb836a6d3 Original Commit: r31 | ods15 | 2006-09-22 18:33:17 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3834
diff changeset
144 if (bits) {
40acb836a6d3 Original Commit: r31 | ods15 | 2006-09-22 18:33:17 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3834
diff changeset
145 *pb->buf_ptr = val;
40acb836a6d3 Original Commit: r31 | ods15 | 2006-09-22 18:33:17 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3834
diff changeset
146 pb->pos = 8 - bits;
40acb836a6d3 Original Commit: r31 | ods15 | 2006-09-22 18:33:17 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3834
diff changeset
147 }
40acb836a6d3 Original Commit: r31 | ods15 | 2006-09-22 18:33:17 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3834
diff changeset
148 }
40acb836a6d3 Original Commit: r31 | ods15 | 2006-09-22 18:33:17 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3834
diff changeset
149
40acb836a6d3 Original Commit: r31 | ods15 | 2006-09-22 18:33:17 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3834
diff changeset
150 static inline void flush_put_bits(PutBitContext * pb) {
40acb836a6d3 Original Commit: r31 | ods15 | 2006-09-22 18:33:17 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3834
diff changeset
151 }
40acb836a6d3 Original Commit: r31 | ods15 | 2006-09-22 18:33:17 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3834
diff changeset
152
40acb836a6d3 Original Commit: r31 | ods15 | 2006-09-22 18:33:17 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3834
diff changeset
153 static inline int put_bits_count(PutBitContext * pb) {
40acb836a6d3 Original Commit: r31 | ods15 | 2006-09-22 18:33:17 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3834
diff changeset
154 return pb->total_pos;
40acb836a6d3 Original Commit: r31 | ods15 | 2006-09-22 18:33:17 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3834
diff changeset
155 }
40acb836a6d3 Original Commit: r31 | ods15 | 2006-09-22 18:33:17 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3834
diff changeset
156
3818
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
157 static int cb_lookup_vals(int lookup, int dimentions, int entries) {
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
158 if (lookup == 1) {
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
159 int tmp, i;
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
160 for (tmp = 0; ; tmp++) {
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
161 int n = 1;
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
162 for (i = 0; i < dimentions; i++) n *= tmp;
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
163 if (n > entries) break;
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
164 }
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
165 return tmp - 1;
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
166 } else if (lookup == 2) return dimentions * entries;
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
167 return 0;
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
168 }
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
169
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
170 static void ready_codebook(codebook_t * cb) {
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
171 int h[33] = { 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 };
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
172 int i;
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
173
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
174 for (i = 0; i < cb->nentries; i++) {
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
175 cb_entry_t * e = &cb->entries[i];
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
176 int j = 0;
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
177 if (h[0]) h[0] = 0;
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
178 else for (j = e->len; !h[j]; j--) assert(j);
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
179 e->codeword = h[j];
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
180 h[j] = 0;
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
181 for (j++; j <= e->len; j++) h[j] = e->codeword | (1 << (j - 1));
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
182 }
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
183 for (i = 0; i < 33; i++) assert(!h[i]);
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
184
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
185 if (!cb->lookup) cb->dimentions = NULL;
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
186 else {
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
187 int vals = cb_lookup_vals(cb->lookup, cb->ndimentions, cb->nentries);
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
188 cb->dimentions = av_malloc(sizeof(float) * cb->nentries * cb->ndimentions);
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
189 for (i = 0; i < cb->nentries; i++) {
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
190 float last = 0;
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
191 int j;
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
192 int div = 1;
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
193 for (j = 0; j < cb->ndimentions; j++) {
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
194 int off;
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
195 if (cb->lookup == 1) off = (i / div) % vals; // lookup type 1
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
196 else off = i * cb->ndimentions + j; // lookup type 2
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
197
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
198 cb->dimentions[i * cb->ndimentions + j] = last + cb->min + cb->quantlist[off] * cb->delta;
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
199 if (cb->seq_p) last = cb->dimentions[i * cb->ndimentions + j];
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
200 div *= vals;
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
201 }
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
202 }
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
203 }
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
204
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
205 }
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
206
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
207 static void create_vorbis_context(venc_context_t * venc, AVCodecContext * avccontext) {
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
208 codebook_t * cb;
3825
9983437a00a1 Original Commit: r19 | ods15 | 2006-09-22 12:54:18 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3824
diff changeset
209 floor_t * fc;
3828
f9c449155a0e Original Commit: r22 | ods15 | 2006-09-22 13:49:56 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3827
diff changeset
210 residue_t * rc;
3829
e8e340cbc7f2 Original Commit: r23 | ods15 | 2006-09-22 13:55:48 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3828
diff changeset
211 mapping_t * mc;
3820
3cfdf99da951 Original Commit: r14 | ods15 | 2006-09-22 12:26:17 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3819
diff changeset
212 int i, book;
3818
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
213
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
214 venc->channels = avccontext->channels;
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
215 venc->sample_rate = avccontext->sample_rate;
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
216 venc->blocksize[0] = venc->blocksize[1] = 8;
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
217
3820
3cfdf99da951 Original Commit: r14 | ods15 | 2006-09-22 12:26:17 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3819
diff changeset
218 venc->ncodebooks = 10;
3818
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
219 venc->codebooks = av_malloc(sizeof(codebook_t) * venc->ncodebooks);
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
220
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
221 // codebook 1 - floor1 book, values 0..255
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
222 cb = &venc->codebooks[0];
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
223 cb->nentries = 256;
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
224 cb->entries = av_malloc(sizeof(cb_entry_t) * cb->nentries);
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
225 for (i = 0; i < cb->nentries; i++) cb->entries[i].len = 8;
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
226 cb->ndimentions = 0;
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
227 cb->min = 0.;
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
228 cb->delta = 0.;
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
229 cb->seq_p = 0;
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
230 cb->lookup = 0;
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
231 cb->quantlist = NULL;
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
232 ready_codebook(cb);
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
233
3822
a7f46bc1fea0 Original Commit: r16 | ods15 | 2006-09-22 12:27:17 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3821
diff changeset
234 // codebook 2 - residue classbook, values 0..1, dimentions 200
3818
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
235 cb = &venc->codebooks[1];
3822
a7f46bc1fea0 Original Commit: r16 | ods15 | 2006-09-22 12:27:17 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3821
diff changeset
236 cb->nentries = 2;
3818
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
237 cb->entries = av_malloc(sizeof(cb_entry_t) * cb->nentries);
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
238 for (i = 0; i < cb->nentries; i++) cb->entries[i].len = 1;
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
239 cb->ndimentions = 200;
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
240 cb->min = 0.;
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
241 cb->delta = 0.;
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
242 cb->seq_p = 0;
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
243 cb->lookup = 0;
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
244 cb->quantlist = NULL;
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
245 ready_codebook(cb);
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
246
3820
3cfdf99da951 Original Commit: r14 | ods15 | 2006-09-22 12:26:17 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3819
diff changeset
247 // codebook 3..10 - vector, for the residue, values -32767..32767, dimentions 1
3cfdf99da951 Original Commit: r14 | ods15 | 2006-09-22 12:26:17 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3819
diff changeset
248 for (book = 0; book < 8; book++) {
3cfdf99da951 Original Commit: r14 | ods15 | 2006-09-22 12:26:17 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3819
diff changeset
249 cb = &venc->codebooks[2 + book];
3cfdf99da951 Original Commit: r14 | ods15 | 2006-09-22 12:26:17 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3819
diff changeset
250 cb->nentries = 5;
3cfdf99da951 Original Commit: r14 | ods15 | 2006-09-22 12:26:17 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3819
diff changeset
251 cb->entries = av_malloc(sizeof(cb_entry_t) * cb->nentries);
3cfdf99da951 Original Commit: r14 | ods15 | 2006-09-22 12:26:17 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3819
diff changeset
252 for (i = 0; i < cb->nentries; i++) cb->entries[i].len = i == 2 ? 1 : 3;
3cfdf99da951 Original Commit: r14 | ods15 | 2006-09-22 12:26:17 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3819
diff changeset
253 cb->ndimentions = 1;
3cfdf99da951 Original Commit: r14 | ods15 | 2006-09-22 12:26:17 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3819
diff changeset
254 cb->delta = 1 << ((7 - book) * 2);
3cfdf99da951 Original Commit: r14 | ods15 | 2006-09-22 12:26:17 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3819
diff changeset
255 cb->min = -cb->delta*2;
3cfdf99da951 Original Commit: r14 | ods15 | 2006-09-22 12:26:17 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3819
diff changeset
256 cb->seq_p = 0;
3cfdf99da951 Original Commit: r14 | ods15 | 2006-09-22 12:26:17 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3819
diff changeset
257 cb->lookup = 2;
3cfdf99da951 Original Commit: r14 | ods15 | 2006-09-22 12:26:17 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3819
diff changeset
258 cb->quantlist = av_malloc(sizeof(int) * cb_lookup_vals(cb->lookup, cb->ndimentions, cb->nentries));
3cfdf99da951 Original Commit: r14 | ods15 | 2006-09-22 12:26:17 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3819
diff changeset
259 for (i = 0; i < cb->nentries; i++) cb->quantlist[i] = i;
3cfdf99da951 Original Commit: r14 | ods15 | 2006-09-22 12:26:17 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3819
diff changeset
260 ready_codebook(cb);
3cfdf99da951 Original Commit: r14 | ods15 | 2006-09-22 12:26:17 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3819
diff changeset
261 }
3818
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
262
3825
9983437a00a1 Original Commit: r19 | ods15 | 2006-09-22 12:54:18 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3824
diff changeset
263 venc->nfloors = 1;
9983437a00a1 Original Commit: r19 | ods15 | 2006-09-22 12:54:18 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3824
diff changeset
264 venc->floors = av_malloc(sizeof(floor_t) * venc->nfloors);
3826
c583e895f980 Original Commit: r20 | ods15 | 2006-09-22 13:12:48 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3825
diff changeset
265
c583e895f980 Original Commit: r20 | ods15 | 2006-09-22 13:12:48 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3825
diff changeset
266 // just 1 floor
3825
9983437a00a1 Original Commit: r19 | ods15 | 2006-09-22 12:54:18 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3824
diff changeset
267 fc = &venc->floors[0];
9983437a00a1 Original Commit: r19 | ods15 | 2006-09-22 12:54:18 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3824
diff changeset
268 fc->partitions = 1;
9983437a00a1 Original Commit: r19 | ods15 | 2006-09-22 12:54:18 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3824
diff changeset
269 fc->partition_to_class = av_malloc(sizeof(int) * fc->partitions);
3832
3d159e4cde5a Original Commit: r26 | ods15 | 2006-09-22 14:18:22 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3831
diff changeset
270 for (i = 0; i < fc->partitions; i++) fc->partition_to_class[i] = 0;
3825
9983437a00a1 Original Commit: r19 | ods15 | 2006-09-22 12:54:18 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3824
diff changeset
271 fc->nclasses = 1;
9983437a00a1 Original Commit: r19 | ods15 | 2006-09-22 12:54:18 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3824
diff changeset
272 fc->classes = av_malloc(sizeof(floor_class_t) * fc->nclasses);
9983437a00a1 Original Commit: r19 | ods15 | 2006-09-22 12:54:18 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3824
diff changeset
273 for (i = 0; i < fc->nclasses; i++) {
9983437a00a1 Original Commit: r19 | ods15 | 2006-09-22 12:54:18 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3824
diff changeset
274 floor_class_t * c = &fc->classes[i];
9983437a00a1 Original Commit: r19 | ods15 | 2006-09-22 12:54:18 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3824
diff changeset
275 int j, books;
9983437a00a1 Original Commit: r19 | ods15 | 2006-09-22 12:54:18 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3824
diff changeset
276 c->dim = 1;
9983437a00a1 Original Commit: r19 | ods15 | 2006-09-22 12:54:18 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3824
diff changeset
277 c->subclass = 0;
9983437a00a1 Original Commit: r19 | ods15 | 2006-09-22 12:54:18 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3824
diff changeset
278 c->masterbook = 0;
9983437a00a1 Original Commit: r19 | ods15 | 2006-09-22 12:54:18 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3824
diff changeset
279 books = (1 << c->subclass);
9983437a00a1 Original Commit: r19 | ods15 | 2006-09-22 12:54:18 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3824
diff changeset
280 c->books = av_malloc(sizeof(int) * books);
9983437a00a1 Original Commit: r19 | ods15 | 2006-09-22 12:54:18 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3824
diff changeset
281 for (j = 0; j < books; j++) c->books[j] = 0;
9983437a00a1 Original Commit: r19 | ods15 | 2006-09-22 12:54:18 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3824
diff changeset
282 }
9983437a00a1 Original Commit: r19 | ods15 | 2006-09-22 12:54:18 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3824
diff changeset
283 fc->multiplier = 1;
9983437a00a1 Original Commit: r19 | ods15 | 2006-09-22 12:54:18 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3824
diff changeset
284 fc->rangebits = venc->blocksize[0];
9983437a00a1 Original Commit: r19 | ods15 | 2006-09-22 12:54:18 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3824
diff changeset
285
9983437a00a1 Original Commit: r19 | ods15 | 2006-09-22 12:54:18 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3824
diff changeset
286 fc->values = 2;
9983437a00a1 Original Commit: r19 | ods15 | 2006-09-22 12:54:18 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3824
diff changeset
287 for (i = 0; i < fc->partitions; i++)
9983437a00a1 Original Commit: r19 | ods15 | 2006-09-22 12:54:18 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3824
diff changeset
288 fc->values += fc->classes[fc->partition_to_class[i]].dim;
9983437a00a1 Original Commit: r19 | ods15 | 2006-09-22 12:54:18 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3824
diff changeset
289
9983437a00a1 Original Commit: r19 | ods15 | 2006-09-22 12:54:18 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3824
diff changeset
290 fc->list = av_malloc(sizeof(*fc->list) * fc->values);
9983437a00a1 Original Commit: r19 | ods15 | 2006-09-22 12:54:18 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3824
diff changeset
291 fc->list[0].x = 0;
9983437a00a1 Original Commit: r19 | ods15 | 2006-09-22 12:54:18 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3824
diff changeset
292 fc->list[1].x = 1 << fc->rangebits;
9983437a00a1 Original Commit: r19 | ods15 | 2006-09-22 12:54:18 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3824
diff changeset
293 for (i = 2; i < fc->values; i++) fc->list[i].x = i * 5;
3827
91f130d6c3f4 Original Commit: r21 | ods15 | 2006-09-22 13:40:31 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3826
diff changeset
294
91f130d6c3f4 Original Commit: r21 | ods15 | 2006-09-22 13:40:31 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3826
diff changeset
295 venc->nresidues = 1;
91f130d6c3f4 Original Commit: r21 | ods15 | 2006-09-22 13:40:31 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3826
diff changeset
296 venc->residues = av_malloc(sizeof(residue_t) * venc->nresidues);
91f130d6c3f4 Original Commit: r21 | ods15 | 2006-09-22 13:40:31 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3826
diff changeset
297
3828
f9c449155a0e Original Commit: r22 | ods15 | 2006-09-22 13:49:56 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3827
diff changeset
298 // single residue
f9c449155a0e Original Commit: r22 | ods15 | 2006-09-22 13:49:56 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3827
diff changeset
299 rc = &venc->residues[0];
f9c449155a0e Original Commit: r22 | ods15 | 2006-09-22 13:49:56 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3827
diff changeset
300 rc->type = 0;
f9c449155a0e Original Commit: r22 | ods15 | 2006-09-22 13:49:56 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3827
diff changeset
301 rc->begin = 0;
f9c449155a0e Original Commit: r22 | ods15 | 2006-09-22 13:49:56 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3827
diff changeset
302 rc->end = 1 << venc->blocksize[0];
f9c449155a0e Original Commit: r22 | ods15 | 2006-09-22 13:49:56 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3827
diff changeset
303 rc->partition_size = 64;
f9c449155a0e Original Commit: r22 | ods15 | 2006-09-22 13:49:56 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3827
diff changeset
304 rc->classifications = 1;
f9c449155a0e Original Commit: r22 | ods15 | 2006-09-22 13:49:56 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3827
diff changeset
305 rc->classbook = 1;
f9c449155a0e Original Commit: r22 | ods15 | 2006-09-22 13:49:56 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3827
diff changeset
306 rc->books = av_malloc(sizeof(int[8]) * rc->classifications);
f9c449155a0e Original Commit: r22 | ods15 | 2006-09-22 13:49:56 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3827
diff changeset
307 for (i = 0; i < 8; i++) rc->books[0][i] = 2 + i;
f9c449155a0e Original Commit: r22 | ods15 | 2006-09-22 13:49:56 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3827
diff changeset
308
3827
91f130d6c3f4 Original Commit: r21 | ods15 | 2006-09-22 13:40:31 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3826
diff changeset
309 venc->nmappings = 1;
91f130d6c3f4 Original Commit: r21 | ods15 | 2006-09-22 13:40:31 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3826
diff changeset
310 venc->mappings = av_malloc(sizeof(mapping_t) * venc->nmappings);
91f130d6c3f4 Original Commit: r21 | ods15 | 2006-09-22 13:40:31 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3826
diff changeset
311
3829
e8e340cbc7f2 Original Commit: r23 | ods15 | 2006-09-22 13:55:48 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3828
diff changeset
312 // single mapping
e8e340cbc7f2 Original Commit: r23 | ods15 | 2006-09-22 13:55:48 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3828
diff changeset
313 mc = &venc->mappings[0];
e8e340cbc7f2 Original Commit: r23 | ods15 | 2006-09-22 13:55:48 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3828
diff changeset
314 mc->submaps = 1;
e8e340cbc7f2 Original Commit: r23 | ods15 | 2006-09-22 13:55:48 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3828
diff changeset
315 mc->mux = av_malloc(sizeof(int) * venc->channels);
e8e340cbc7f2 Original Commit: r23 | ods15 | 2006-09-22 13:55:48 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3828
diff changeset
316 for (i = 0; i < venc->channels; i++) mc->mux[i] = 0;
e8e340cbc7f2 Original Commit: r23 | ods15 | 2006-09-22 13:55:48 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3828
diff changeset
317 mc->floor = av_malloc(sizeof(int) * mc->submaps);
e8e340cbc7f2 Original Commit: r23 | ods15 | 2006-09-22 13:55:48 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3828
diff changeset
318 mc->residue = av_malloc(sizeof(int) * mc->submaps);
e8e340cbc7f2 Original Commit: r23 | ods15 | 2006-09-22 13:55:48 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3828
diff changeset
319 for (i = 0; i < mc->submaps; i++) {
e8e340cbc7f2 Original Commit: r23 | ods15 | 2006-09-22 13:55:48 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3828
diff changeset
320 mc->floor[i] = 0;
e8e340cbc7f2 Original Commit: r23 | ods15 | 2006-09-22 13:55:48 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3828
diff changeset
321 mc->residue[i] = 0;
e8e340cbc7f2 Original Commit: r23 | ods15 | 2006-09-22 13:55:48 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3828
diff changeset
322 }
e8e340cbc7f2 Original Commit: r23 | ods15 | 2006-09-22 13:55:48 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3828
diff changeset
323
3827
91f130d6c3f4 Original Commit: r21 | ods15 | 2006-09-22 13:40:31 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3826
diff changeset
324 venc->nmodes = 1;
91f130d6c3f4 Original Commit: r21 | ods15 | 2006-09-22 13:40:31 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3826
diff changeset
325 venc->modes = av_malloc(sizeof(vorbis_mode_t) * venc->nmodes);
3830
477ee30c6fc6 Original Commit: r24 | ods15 | 2006-09-22 13:57:09 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3829
diff changeset
326
477ee30c6fc6 Original Commit: r24 | ods15 | 2006-09-22 13:57:09 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3829
diff changeset
327 // single mode
477ee30c6fc6 Original Commit: r24 | ods15 | 2006-09-22 13:57:09 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3829
diff changeset
328 venc->modes[0].blockflag = 0;
477ee30c6fc6 Original Commit: r24 | ods15 | 2006-09-22 13:57:09 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3829
diff changeset
329 venc->modes[0].mapping = 0;
3818
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
330 }
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
331
3811
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
332 static inline int ilog(unsigned int a) {
3810
a8bebf3e9cb7 Original Commit: r4 | ods15 | 2006-09-16 15:36:03 +0300 (Sat, 16 Sep 2006) | 3 lines
ods15
parents: 3809
diff changeset
333 int i;
3811
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
334 for (i = 0; a >> i; i++);
3810
a8bebf3e9cb7 Original Commit: r4 | ods15 | 2006-09-16 15:36:03 +0300 (Sat, 16 Sep 2006) | 3 lines
ods15
parents: 3809
diff changeset
335 return i;
a8bebf3e9cb7 Original Commit: r4 | ods15 | 2006-09-16 15:36:03 +0300 (Sat, 16 Sep 2006) | 3 lines
ods15
parents: 3809
diff changeset
336 }
a8bebf3e9cb7 Original Commit: r4 | ods15 | 2006-09-16 15:36:03 +0300 (Sat, 16 Sep 2006) | 3 lines
ods15
parents: 3809
diff changeset
337
3811
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
338 static void put_float(PutBitContext * pb, float f) {
3812
52ff3a5d161e Original Commit: r6 | ods15 | 2006-09-16 20:36:31 +0300 (Sat, 16 Sep 2006) | 2 lines
ods15
parents: 3811
diff changeset
339 int exp, mant;
52ff3a5d161e Original Commit: r6 | ods15 | 2006-09-16 20:36:31 +0300 (Sat, 16 Sep 2006) | 2 lines
ods15
parents: 3811
diff changeset
340 uint32_t res = 0;
52ff3a5d161e Original Commit: r6 | ods15 | 2006-09-16 20:36:31 +0300 (Sat, 16 Sep 2006) | 2 lines
ods15
parents: 3811
diff changeset
341 mant = (int)ldexp(frexp(f, &exp), 20);
52ff3a5d161e Original Commit: r6 | ods15 | 2006-09-16 20:36:31 +0300 (Sat, 16 Sep 2006) | 2 lines
ods15
parents: 3811
diff changeset
342 exp += 788 - 20;
52ff3a5d161e Original Commit: r6 | ods15 | 2006-09-16 20:36:31 +0300 (Sat, 16 Sep 2006) | 2 lines
ods15
parents: 3811
diff changeset
343 if (mant < 0) { res |= (1 << 31); mant = -mant; }
52ff3a5d161e Original Commit: r6 | ods15 | 2006-09-16 20:36:31 +0300 (Sat, 16 Sep 2006) | 2 lines
ods15
parents: 3811
diff changeset
344 res |= mant | (exp << 21);
52ff3a5d161e Original Commit: r6 | ods15 | 2006-09-16 20:36:31 +0300 (Sat, 16 Sep 2006) | 2 lines
ods15
parents: 3811
diff changeset
345 put_bits(pb, 32, res);
3811
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
346 }
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
347
3810
a8bebf3e9cb7 Original Commit: r4 | ods15 | 2006-09-16 15:36:03 +0300 (Sat, 16 Sep 2006) | 3 lines
ods15
parents: 3809
diff changeset
348 static void put_codebook_header(PutBitContext * pb, codebook_t * cb) {
a8bebf3e9cb7 Original Commit: r4 | ods15 | 2006-09-16 15:36:03 +0300 (Sat, 16 Sep 2006) | 3 lines
ods15
parents: 3809
diff changeset
349 int i;
a8bebf3e9cb7 Original Commit: r4 | ods15 | 2006-09-16 15:36:03 +0300 (Sat, 16 Sep 2006) | 3 lines
ods15
parents: 3809
diff changeset
350 int ordered = 0;
a8bebf3e9cb7 Original Commit: r4 | ods15 | 2006-09-16 15:36:03 +0300 (Sat, 16 Sep 2006) | 3 lines
ods15
parents: 3809
diff changeset
351
a8bebf3e9cb7 Original Commit: r4 | ods15 | 2006-09-16 15:36:03 +0300 (Sat, 16 Sep 2006) | 3 lines
ods15
parents: 3809
diff changeset
352 put_bits(pb, 24, 0x564342); //magic
a8bebf3e9cb7 Original Commit: r4 | ods15 | 2006-09-16 15:36:03 +0300 (Sat, 16 Sep 2006) | 3 lines
ods15
parents: 3809
diff changeset
353 put_bits(pb, 16, cb->ndimentions);
a8bebf3e9cb7 Original Commit: r4 | ods15 | 2006-09-16 15:36:03 +0300 (Sat, 16 Sep 2006) | 3 lines
ods15
parents: 3809
diff changeset
354 put_bits(pb, 24, cb->nentries);
a8bebf3e9cb7 Original Commit: r4 | ods15 | 2006-09-16 15:36:03 +0300 (Sat, 16 Sep 2006) | 3 lines
ods15
parents: 3809
diff changeset
355
a8bebf3e9cb7 Original Commit: r4 | ods15 | 2006-09-16 15:36:03 +0300 (Sat, 16 Sep 2006) | 3 lines
ods15
parents: 3809
diff changeset
356 for (i = 1; i < cb->nentries; i++) if (cb->entries[i].len < cb->entries[i-1].len) break;
3811
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
357 if (i == cb->nentries) ordered = 1;
3810
a8bebf3e9cb7 Original Commit: r4 | ods15 | 2006-09-16 15:36:03 +0300 (Sat, 16 Sep 2006) | 3 lines
ods15
parents: 3809
diff changeset
358
a8bebf3e9cb7 Original Commit: r4 | ods15 | 2006-09-16 15:36:03 +0300 (Sat, 16 Sep 2006) | 3 lines
ods15
parents: 3809
diff changeset
359 put_bits(pb, 1, ordered);
a8bebf3e9cb7 Original Commit: r4 | ods15 | 2006-09-16 15:36:03 +0300 (Sat, 16 Sep 2006) | 3 lines
ods15
parents: 3809
diff changeset
360 if (ordered) {
a8bebf3e9cb7 Original Commit: r4 | ods15 | 2006-09-16 15:36:03 +0300 (Sat, 16 Sep 2006) | 3 lines
ods15
parents: 3809
diff changeset
361 int len = cb->entries[0].len;
a8bebf3e9cb7 Original Commit: r4 | ods15 | 2006-09-16 15:36:03 +0300 (Sat, 16 Sep 2006) | 3 lines
ods15
parents: 3809
diff changeset
362 put_bits(pb, 5, len);
a8bebf3e9cb7 Original Commit: r4 | ods15 | 2006-09-16 15:36:03 +0300 (Sat, 16 Sep 2006) | 3 lines
ods15
parents: 3809
diff changeset
363 i = 0;
a8bebf3e9cb7 Original Commit: r4 | ods15 | 2006-09-16 15:36:03 +0300 (Sat, 16 Sep 2006) | 3 lines
ods15
parents: 3809
diff changeset
364 while (i < cb->nentries) {
3811
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
365 int j;
3810
a8bebf3e9cb7 Original Commit: r4 | ods15 | 2006-09-16 15:36:03 +0300 (Sat, 16 Sep 2006) | 3 lines
ods15
parents: 3809
diff changeset
366 for (j = 0; j+i < cb->nentries; j++) if (cb->entries[j+i].len != len) break;
3823
41ad23b61a2c Original Commit: r17 | ods15 | 2006-09-22 12:28:28 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3822
diff changeset
367 put_bits(pb, ilog(cb->nentries - i), j);
3810
a8bebf3e9cb7 Original Commit: r4 | ods15 | 2006-09-16 15:36:03 +0300 (Sat, 16 Sep 2006) | 3 lines
ods15
parents: 3809
diff changeset
368 i += j;
a8bebf3e9cb7 Original Commit: r4 | ods15 | 2006-09-16 15:36:03 +0300 (Sat, 16 Sep 2006) | 3 lines
ods15
parents: 3809
diff changeset
369 len++;
a8bebf3e9cb7 Original Commit: r4 | ods15 | 2006-09-16 15:36:03 +0300 (Sat, 16 Sep 2006) | 3 lines
ods15
parents: 3809
diff changeset
370 }
a8bebf3e9cb7 Original Commit: r4 | ods15 | 2006-09-16 15:36:03 +0300 (Sat, 16 Sep 2006) | 3 lines
ods15
parents: 3809
diff changeset
371 } else {
a8bebf3e9cb7 Original Commit: r4 | ods15 | 2006-09-16 15:36:03 +0300 (Sat, 16 Sep 2006) | 3 lines
ods15
parents: 3809
diff changeset
372 int sparse = 0;
a8bebf3e9cb7 Original Commit: r4 | ods15 | 2006-09-16 15:36:03 +0300 (Sat, 16 Sep 2006) | 3 lines
ods15
parents: 3809
diff changeset
373 for (i = 0; i < cb->nentries; i++) if (!cb->entries[i].len) break;
3811
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
374 if (i != cb->nentries) sparse = 1;
3810
a8bebf3e9cb7 Original Commit: r4 | ods15 | 2006-09-16 15:36:03 +0300 (Sat, 16 Sep 2006) | 3 lines
ods15
parents: 3809
diff changeset
375 put_bits(pb, 1, sparse);
a8bebf3e9cb7 Original Commit: r4 | ods15 | 2006-09-16 15:36:03 +0300 (Sat, 16 Sep 2006) | 3 lines
ods15
parents: 3809
diff changeset
376
a8bebf3e9cb7 Original Commit: r4 | ods15 | 2006-09-16 15:36:03 +0300 (Sat, 16 Sep 2006) | 3 lines
ods15
parents: 3809
diff changeset
377 for (i = 0; i < cb->nentries; i++) {
a8bebf3e9cb7 Original Commit: r4 | ods15 | 2006-09-16 15:36:03 +0300 (Sat, 16 Sep 2006) | 3 lines
ods15
parents: 3809
diff changeset
378 if (sparse) put_bits(pb, 1, !!cb->entries[i].len);
a8bebf3e9cb7 Original Commit: r4 | ods15 | 2006-09-16 15:36:03 +0300 (Sat, 16 Sep 2006) | 3 lines
ods15
parents: 3809
diff changeset
379 if (cb->entries[i].len) put_bits(pb, 5, cb->entries[i].len);
a8bebf3e9cb7 Original Commit: r4 | ods15 | 2006-09-16 15:36:03 +0300 (Sat, 16 Sep 2006) | 3 lines
ods15
parents: 3809
diff changeset
380 }
a8bebf3e9cb7 Original Commit: r4 | ods15 | 2006-09-16 15:36:03 +0300 (Sat, 16 Sep 2006) | 3 lines
ods15
parents: 3809
diff changeset
381 }
a8bebf3e9cb7 Original Commit: r4 | ods15 | 2006-09-16 15:36:03 +0300 (Sat, 16 Sep 2006) | 3 lines
ods15
parents: 3809
diff changeset
382
a8bebf3e9cb7 Original Commit: r4 | ods15 | 2006-09-16 15:36:03 +0300 (Sat, 16 Sep 2006) | 3 lines
ods15
parents: 3809
diff changeset
383 put_bits(pb, 4, cb->lookup);
a8bebf3e9cb7 Original Commit: r4 | ods15 | 2006-09-16 15:36:03 +0300 (Sat, 16 Sep 2006) | 3 lines
ods15
parents: 3809
diff changeset
384 if (cb->lookup) {
3818
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
385 int tmp = cb_lookup_vals(cb->lookup, cb->ndimentions, cb->nentries);
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
386 int bits = ilog(cb->quantlist[0]);
3810
a8bebf3e9cb7 Original Commit: r4 | ods15 | 2006-09-16 15:36:03 +0300 (Sat, 16 Sep 2006) | 3 lines
ods15
parents: 3809
diff changeset
387
3823
41ad23b61a2c Original Commit: r17 | ods15 | 2006-09-22 12:28:28 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3822
diff changeset
388 for (i = 1; i < tmp; i++) bits = FFMAX(bits, ilog(cb->quantlist[i]));
3810
a8bebf3e9cb7 Original Commit: r4 | ods15 | 2006-09-16 15:36:03 +0300 (Sat, 16 Sep 2006) | 3 lines
ods15
parents: 3809
diff changeset
389
3811
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
390 put_float(pb, cb->min);
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
391 put_float(pb, cb->delta);
3810
a8bebf3e9cb7 Original Commit: r4 | ods15 | 2006-09-16 15:36:03 +0300 (Sat, 16 Sep 2006) | 3 lines
ods15
parents: 3809
diff changeset
392
3811
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
393 put_bits(pb, 4, bits - 1);
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
394 put_bits(pb, 1, cb->seq_p);
3810
a8bebf3e9cb7 Original Commit: r4 | ods15 | 2006-09-16 15:36:03 +0300 (Sat, 16 Sep 2006) | 3 lines
ods15
parents: 3809
diff changeset
395
3811
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
396 for (i = 0; i < tmp; i++) put_bits(pb, bits, cb->quantlist[i]);
3810
a8bebf3e9cb7 Original Commit: r4 | ods15 | 2006-09-16 15:36:03 +0300 (Sat, 16 Sep 2006) | 3 lines
ods15
parents: 3809
diff changeset
397 }
a8bebf3e9cb7 Original Commit: r4 | ods15 | 2006-09-16 15:36:03 +0300 (Sat, 16 Sep 2006) | 3 lines
ods15
parents: 3809
diff changeset
398 }
a8bebf3e9cb7 Original Commit: r4 | ods15 | 2006-09-16 15:36:03 +0300 (Sat, 16 Sep 2006) | 3 lines
ods15
parents: 3809
diff changeset
399
3814
464eca766731 Original Commit: r8 | ods15 | 2006-09-17 09:43:38 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3813
diff changeset
400 static void put_floor_header(PutBitContext * pb, floor_t * fc) {
464eca766731 Original Commit: r8 | ods15 | 2006-09-17 09:43:38 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3813
diff changeset
401 int i;
464eca766731 Original Commit: r8 | ods15 | 2006-09-17 09:43:38 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3813
diff changeset
402
464eca766731 Original Commit: r8 | ods15 | 2006-09-17 09:43:38 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3813
diff changeset
403 put_bits(pb, 16, 1); // type, only floor1 is supported
464eca766731 Original Commit: r8 | ods15 | 2006-09-17 09:43:38 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3813
diff changeset
404
464eca766731 Original Commit: r8 | ods15 | 2006-09-17 09:43:38 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3813
diff changeset
405 put_bits(pb, 5, fc->partitions);
464eca766731 Original Commit: r8 | ods15 | 2006-09-17 09:43:38 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3813
diff changeset
406
464eca766731 Original Commit: r8 | ods15 | 2006-09-17 09:43:38 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3813
diff changeset
407 for (i = 0; i < fc->partitions; i++) put_bits(pb, 4, fc->partition_to_class[i]);
464eca766731 Original Commit: r8 | ods15 | 2006-09-17 09:43:38 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3813
diff changeset
408
464eca766731 Original Commit: r8 | ods15 | 2006-09-17 09:43:38 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3813
diff changeset
409 for (i = 0; i < fc->nclasses; i++) {
464eca766731 Original Commit: r8 | ods15 | 2006-09-17 09:43:38 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3813
diff changeset
410 int j, books;
464eca766731 Original Commit: r8 | ods15 | 2006-09-17 09:43:38 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3813
diff changeset
411
464eca766731 Original Commit: r8 | ods15 | 2006-09-17 09:43:38 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3813
diff changeset
412 put_bits(pb, 3, fc->classes[i].dim - 1);
464eca766731 Original Commit: r8 | ods15 | 2006-09-17 09:43:38 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3813
diff changeset
413 put_bits(pb, 2, fc->classes[i].subclass);
464eca766731 Original Commit: r8 | ods15 | 2006-09-17 09:43:38 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3813
diff changeset
414
464eca766731 Original Commit: r8 | ods15 | 2006-09-17 09:43:38 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3813
diff changeset
415 if (fc->classes[i].subclass) put_bits(pb, 8, fc->classes[i].masterbook);
464eca766731 Original Commit: r8 | ods15 | 2006-09-17 09:43:38 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3813
diff changeset
416
464eca766731 Original Commit: r8 | ods15 | 2006-09-17 09:43:38 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3813
diff changeset
417 books = (1 << fc->classes[i].subclass);
464eca766731 Original Commit: r8 | ods15 | 2006-09-17 09:43:38 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3813
diff changeset
418
464eca766731 Original Commit: r8 | ods15 | 2006-09-17 09:43:38 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3813
diff changeset
419 for (j = 0; j < books; j++) put_bits(pb, 8, fc->classes[i].books[j] + 1);
464eca766731 Original Commit: r8 | ods15 | 2006-09-17 09:43:38 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3813
diff changeset
420 }
464eca766731 Original Commit: r8 | ods15 | 2006-09-17 09:43:38 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3813
diff changeset
421
464eca766731 Original Commit: r8 | ods15 | 2006-09-17 09:43:38 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3813
diff changeset
422 put_bits(pb, 2, fc->multiplier - 1);
464eca766731 Original Commit: r8 | ods15 | 2006-09-17 09:43:38 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3813
diff changeset
423 put_bits(pb, 4, fc->rangebits);
464eca766731 Original Commit: r8 | ods15 | 2006-09-17 09:43:38 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3813
diff changeset
424
464eca766731 Original Commit: r8 | ods15 | 2006-09-17 09:43:38 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3813
diff changeset
425 for (i = 2; i < fc->values; i++) put_bits(pb, fc->rangebits, fc->list[i].x);
3813
95b70f8bc29e Original Commit: r7 | ods15 | 2006-09-17 08:50:47 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3812
diff changeset
426 }
95b70f8bc29e Original Commit: r7 | ods15 | 2006-09-17 08:50:47 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3812
diff changeset
427
3814
464eca766731 Original Commit: r8 | ods15 | 2006-09-17 09:43:38 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3813
diff changeset
428 static void put_residue_header(PutBitContext * pb, residue_t * rc) {
3815
3fa081422f78 Original Commit: r9 | ods15 | 2006-09-17 18:56:41 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3814
diff changeset
429 int i;
3fa081422f78 Original Commit: r9 | ods15 | 2006-09-17 18:56:41 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3814
diff changeset
430
3fa081422f78 Original Commit: r9 | ods15 | 2006-09-17 18:56:41 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3814
diff changeset
431 put_bits(pb, 16, rc->type);
3fa081422f78 Original Commit: r9 | ods15 | 2006-09-17 18:56:41 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3814
diff changeset
432
3fa081422f78 Original Commit: r9 | ods15 | 2006-09-17 18:56:41 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3814
diff changeset
433 put_bits(pb, 24, rc->begin);
3fa081422f78 Original Commit: r9 | ods15 | 2006-09-17 18:56:41 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3814
diff changeset
434 put_bits(pb, 24, rc->end);
3fa081422f78 Original Commit: r9 | ods15 | 2006-09-17 18:56:41 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3814
diff changeset
435 put_bits(pb, 24, rc->partition_size - 1);
3fa081422f78 Original Commit: r9 | ods15 | 2006-09-17 18:56:41 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3814
diff changeset
436 put_bits(pb, 6, rc->classifications);
3fa081422f78 Original Commit: r9 | ods15 | 2006-09-17 18:56:41 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3814
diff changeset
437 put_bits(pb, 8, rc->classbook);
3fa081422f78 Original Commit: r9 | ods15 | 2006-09-17 18:56:41 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3814
diff changeset
438
3fa081422f78 Original Commit: r9 | ods15 | 2006-09-17 18:56:41 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3814
diff changeset
439 for (i = 0; i < rc->classifications; i++) {
3fa081422f78 Original Commit: r9 | ods15 | 2006-09-17 18:56:41 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3814
diff changeset
440 int j, tmp = 0;
3fa081422f78 Original Commit: r9 | ods15 | 2006-09-17 18:56:41 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3814
diff changeset
441 for (j = 0; j < 8; j++) tmp |= (!!rc->books[i][j]) << j;
3fa081422f78 Original Commit: r9 | ods15 | 2006-09-17 18:56:41 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3814
diff changeset
442
3fa081422f78 Original Commit: r9 | ods15 | 2006-09-17 18:56:41 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3814
diff changeset
443 put_bits(pb, 3, tmp & 7);
3fa081422f78 Original Commit: r9 | ods15 | 2006-09-17 18:56:41 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3814
diff changeset
444 put_bits(pb, 1, tmp > 7);
3fa081422f78 Original Commit: r9 | ods15 | 2006-09-17 18:56:41 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3814
diff changeset
445
3fa081422f78 Original Commit: r9 | ods15 | 2006-09-17 18:56:41 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3814
diff changeset
446 if (tmp > 7) put_bits(pb, 5, tmp >> 3);
3fa081422f78 Original Commit: r9 | ods15 | 2006-09-17 18:56:41 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3814
diff changeset
447 }
3fa081422f78 Original Commit: r9 | ods15 | 2006-09-17 18:56:41 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3814
diff changeset
448
3fa081422f78 Original Commit: r9 | ods15 | 2006-09-17 18:56:41 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3814
diff changeset
449 for (i = 0; i < rc->classifications; i++) {
3fa081422f78 Original Commit: r9 | ods15 | 2006-09-17 18:56:41 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3814
diff changeset
450 int j;
3fa081422f78 Original Commit: r9 | ods15 | 2006-09-17 18:56:41 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3814
diff changeset
451 for (j = 0; j < 8; j++)
3fa081422f78 Original Commit: r9 | ods15 | 2006-09-17 18:56:41 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3814
diff changeset
452 if (rc->books[i][j])
3fa081422f78 Original Commit: r9 | ods15 | 2006-09-17 18:56:41 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3814
diff changeset
453 put_bits(pb, 8, rc->books[i][j]);
3fa081422f78 Original Commit: r9 | ods15 | 2006-09-17 18:56:41 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3814
diff changeset
454 }
3813
95b70f8bc29e Original Commit: r7 | ods15 | 2006-09-17 08:50:47 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3812
diff changeset
455 }
95b70f8bc29e Original Commit: r7 | ods15 | 2006-09-17 08:50:47 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3812
diff changeset
456
3811
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
457 static int put_main_header(venc_context_t * venc, uint8_t ** out) {
3810
a8bebf3e9cb7 Original Commit: r4 | ods15 | 2006-09-16 15:36:03 +0300 (Sat, 16 Sep 2006) | 3 lines
ods15
parents: 3809
diff changeset
458 int i;
3811
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
459 PutBitContext pb;
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
460 uint8_t buffer[50000] = {0}, * p = buffer;
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
461 int buffer_len = sizeof buffer;
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
462 int len, hlens[3];
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
463
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
464 // identification header
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
465 init_put_bits(&pb, p, buffer_len);
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
466 put_bits(&pb, 8, 1); //magic
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
467 for (i = 0; "vorbis"[i]; i++) put_bits(&pb, 8, "vorbis"[i]);
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
468 put_bits(&pb, 32, 0); // version
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
469 put_bits(&pb, 8, venc->channels);
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
470 put_bits(&pb, 32, venc->sample_rate);
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
471 put_bits(&pb, 32, 0); // bitrate
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
472 put_bits(&pb, 32, 0); // bitrate
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
473 put_bits(&pb, 32, 0); // bitrate
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
474 put_bits(&pb, 4, venc->blocksize[0]);
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
475 put_bits(&pb, 4, venc->blocksize[1]);
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
476 put_bits(&pb, 1, 1); // framing
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
477
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
478 flush_put_bits(&pb);
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
479 hlens[0] = (put_bits_count(&pb) + 7) / 8;
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
480 buffer_len -= hlens[0];
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
481 p += hlens[0];
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
482
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
483 // comment header
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
484 init_put_bits(&pb, p, buffer_len);
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
485 put_bits(&pb, 8, 3); //magic
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
486 for (i = 0; "vorbis"[i]; i++) put_bits(&pb, 8, "vorbis"[i]);
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
487 put_bits(&pb, 32, 0); // vendor length TODO
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
488 put_bits(&pb, 32, 0); // amount of comments
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
489 put_bits(&pb, 1, 1); // framing
3810
a8bebf3e9cb7 Original Commit: r4 | ods15 | 2006-09-16 15:36:03 +0300 (Sat, 16 Sep 2006) | 3 lines
ods15
parents: 3809
diff changeset
490
3811
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
491 flush_put_bits(&pb);
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
492 hlens[1] = (put_bits_count(&pb) + 7) / 8;
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
493 buffer_len -= hlens[1];
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
494 p += hlens[1];
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
495
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
496 // setup header
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
497 init_put_bits(&pb, p, buffer_len);
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
498 put_bits(&pb, 8, 5); //magic
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
499 for (i = 0; "vorbis"[i]; i++) put_bits(&pb, 8, "vorbis"[i]);
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
500
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
501 // codebooks
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
502 put_bits(&pb, 8, venc->ncodebooks - 1);
3821
5fdb0fa900cd Original Commit: r15 | ods15 | 2006-09-22 12:26:42 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3820
diff changeset
503 for (i = 0; i < venc->ncodebooks; i++) put_codebook_header(&pb, &venc->codebooks[i]);
3811
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
504
3813
95b70f8bc29e Original Commit: r7 | ods15 | 2006-09-17 08:50:47 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3812
diff changeset
505 // time domain, reserved, zero
95b70f8bc29e Original Commit: r7 | ods15 | 2006-09-17 08:50:47 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3812
diff changeset
506 put_bits(&pb, 6, 0);
95b70f8bc29e Original Commit: r7 | ods15 | 2006-09-17 08:50:47 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3812
diff changeset
507 put_bits(&pb, 16, 0);
95b70f8bc29e Original Commit: r7 | ods15 | 2006-09-17 08:50:47 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3812
diff changeset
508
95b70f8bc29e Original Commit: r7 | ods15 | 2006-09-17 08:50:47 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3812
diff changeset
509 // floors
95b70f8bc29e Original Commit: r7 | ods15 | 2006-09-17 08:50:47 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3812
diff changeset
510 put_bits(&pb, 6, venc->nfloors - 1);
3821
5fdb0fa900cd Original Commit: r15 | ods15 | 2006-09-22 12:26:42 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3820
diff changeset
511 for (i = 0; i < venc->nfloors; i++) put_floor_header(&pb, &venc->floors[i]);
3813
95b70f8bc29e Original Commit: r7 | ods15 | 2006-09-17 08:50:47 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3812
diff changeset
512
95b70f8bc29e Original Commit: r7 | ods15 | 2006-09-17 08:50:47 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3812
diff changeset
513 // residues
95b70f8bc29e Original Commit: r7 | ods15 | 2006-09-17 08:50:47 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3812
diff changeset
514 put_bits(&pb, 6, venc->nresidues - 1);
3821
5fdb0fa900cd Original Commit: r15 | ods15 | 2006-09-22 12:26:42 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3820
diff changeset
515 for (i = 0; i < venc->nresidues; i++) put_residue_header(&pb, &venc->residues[i]);
3813
95b70f8bc29e Original Commit: r7 | ods15 | 2006-09-17 08:50:47 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3812
diff changeset
516
95b70f8bc29e Original Commit: r7 | ods15 | 2006-09-17 08:50:47 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3812
diff changeset
517 // mappings
95b70f8bc29e Original Commit: r7 | ods15 | 2006-09-17 08:50:47 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3812
diff changeset
518 put_bits(&pb, 6, venc->nmappings - 1);
95b70f8bc29e Original Commit: r7 | ods15 | 2006-09-17 08:50:47 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3812
diff changeset
519 for (i = 0; i < venc->nmappings; i++) {
3816
6eba53afa0b0 Original Commit: r10 | ods15 | 2006-09-17 19:37:17 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3815
diff changeset
520 mapping_t * mc = &venc->mappings[i];
6eba53afa0b0 Original Commit: r10 | ods15 | 2006-09-17 19:37:17 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3815
diff changeset
521 int j;
6eba53afa0b0 Original Commit: r10 | ods15 | 2006-09-17 19:37:17 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3815
diff changeset
522 put_bits(&pb, 16, 0); // mapping type
6eba53afa0b0 Original Commit: r10 | ods15 | 2006-09-17 19:37:17 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3815
diff changeset
523
6eba53afa0b0 Original Commit: r10 | ods15 | 2006-09-17 19:37:17 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3815
diff changeset
524 put_bits(&pb, 1, mc->submaps > 1);
6eba53afa0b0 Original Commit: r10 | ods15 | 2006-09-17 19:37:17 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3815
diff changeset
525 if (mc->submaps > 1) put_bits(&pb, 4, mc->submaps - 1);
6eba53afa0b0 Original Commit: r10 | ods15 | 2006-09-17 19:37:17 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3815
diff changeset
526
6eba53afa0b0 Original Commit: r10 | ods15 | 2006-09-17 19:37:17 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3815
diff changeset
527 put_bits(&pb, 1, 0); // channel coupling
6eba53afa0b0 Original Commit: r10 | ods15 | 2006-09-17 19:37:17 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3815
diff changeset
528
6eba53afa0b0 Original Commit: r10 | ods15 | 2006-09-17 19:37:17 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3815
diff changeset
529 put_bits(&pb, 2, 0); // reserved
6eba53afa0b0 Original Commit: r10 | ods15 | 2006-09-17 19:37:17 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3815
diff changeset
530
6eba53afa0b0 Original Commit: r10 | ods15 | 2006-09-17 19:37:17 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3815
diff changeset
531 if (mc->submaps > 1) for (j = 0; j < venc->channels; j++) put_bits(&pb, 4, mc->mux[j]);
6eba53afa0b0 Original Commit: r10 | ods15 | 2006-09-17 19:37:17 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3815
diff changeset
532
6eba53afa0b0 Original Commit: r10 | ods15 | 2006-09-17 19:37:17 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3815
diff changeset
533 for (j = 0; j < mc->submaps; j++) {
6eba53afa0b0 Original Commit: r10 | ods15 | 2006-09-17 19:37:17 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3815
diff changeset
534 put_bits(&pb, 8, 0); // reserved time configuration
6eba53afa0b0 Original Commit: r10 | ods15 | 2006-09-17 19:37:17 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3815
diff changeset
535 put_bits(&pb, 8, mc->floor[j]);
6eba53afa0b0 Original Commit: r10 | ods15 | 2006-09-17 19:37:17 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3815
diff changeset
536 put_bits(&pb, 8, mc->residue[j]);
6eba53afa0b0 Original Commit: r10 | ods15 | 2006-09-17 19:37:17 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3815
diff changeset
537 }
3813
95b70f8bc29e Original Commit: r7 | ods15 | 2006-09-17 08:50:47 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3812
diff changeset
538 }
3811
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
539
3817
3ca15f0d4882 Original Commit: r11 | ods15 | 2006-09-17 19:41:28 +0300 (Sun, 17 Sep 2006) | 4 lines
ods15
parents: 3816
diff changeset
540 // modes
3ca15f0d4882 Original Commit: r11 | ods15 | 2006-09-17 19:41:28 +0300 (Sun, 17 Sep 2006) | 4 lines
ods15
parents: 3816
diff changeset
541 put_bits(&pb, 6, venc->nmodes - 1);
3ca15f0d4882 Original Commit: r11 | ods15 | 2006-09-17 19:41:28 +0300 (Sun, 17 Sep 2006) | 4 lines
ods15
parents: 3816
diff changeset
542 for (i = 0; i < venc->nmodes; i++) {
3ca15f0d4882 Original Commit: r11 | ods15 | 2006-09-17 19:41:28 +0300 (Sun, 17 Sep 2006) | 4 lines
ods15
parents: 3816
diff changeset
543 put_bits(&pb, 1, venc->modes[i].blockflag);
3ca15f0d4882 Original Commit: r11 | ods15 | 2006-09-17 19:41:28 +0300 (Sun, 17 Sep 2006) | 4 lines
ods15
parents: 3816
diff changeset
544 put_bits(&pb, 16, 0); // reserved window type
3ca15f0d4882 Original Commit: r11 | ods15 | 2006-09-17 19:41:28 +0300 (Sun, 17 Sep 2006) | 4 lines
ods15
parents: 3816
diff changeset
545 put_bits(&pb, 16, 0); // reserved transform type
3ca15f0d4882 Original Commit: r11 | ods15 | 2006-09-17 19:41:28 +0300 (Sun, 17 Sep 2006) | 4 lines
ods15
parents: 3816
diff changeset
546 put_bits(&pb, 8, venc->modes[i].mapping);
3ca15f0d4882 Original Commit: r11 | ods15 | 2006-09-17 19:41:28 +0300 (Sun, 17 Sep 2006) | 4 lines
ods15
parents: 3816
diff changeset
547 }
3ca15f0d4882 Original Commit: r11 | ods15 | 2006-09-17 19:41:28 +0300 (Sun, 17 Sep 2006) | 4 lines
ods15
parents: 3816
diff changeset
548
3811
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
549 flush_put_bits(&pb);
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
550 hlens[2] = (put_bits_count(&pb) + 7) / 8;
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
551
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
552 len = hlens[0] + hlens[1] + hlens[2];
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
553 p = *out = av_mallocz(64 + len + len/255);
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
554
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
555 *p++ = 2;
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
556 p += av_xiphlacing(p, hlens[0]);
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
557 p += av_xiphlacing(p, hlens[1]);
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
558 buffer_len = 0;
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
559 for (i = 0; i < 3; i++) {
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
560 memcpy(p, buffer + buffer_len, hlens[i]);
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
561 p += hlens[i];
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
562 buffer_len += hlens[i];
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
563 }
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
564
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
565 return p - *out;
3810
a8bebf3e9cb7 Original Commit: r4 | ods15 | 2006-09-16 15:36:03 +0300 (Sat, 16 Sep 2006) | 3 lines
ods15
parents: 3809
diff changeset
566 }
a8bebf3e9cb7 Original Commit: r4 | ods15 | 2006-09-16 15:36:03 +0300 (Sat, 16 Sep 2006) | 3 lines
ods15
parents: 3809
diff changeset
567
3809
500d86b68542 Original Commit: r3 | ods15 | 2006-09-16 11:49:07 +0300 (Sat, 16 Sep 2006) | 2 lines
ods15
parents: 3808
diff changeset
568 static int vorbis_encode_init(AVCodecContext * avccontext)
500d86b68542 Original Commit: r3 | ods15 | 2006-09-16 11:49:07 +0300 (Sat, 16 Sep 2006) | 2 lines
ods15
parents: 3808
diff changeset
569 {
3808
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
570 venc_context_t * venc = avccontext->priv_data;
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
571
3818
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
572 create_vorbis_context(venc, avccontext);
3811
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
573
3808
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
574 //if (avccontext->flags & CODEC_FLAG_QSCALE) avccontext->global_quality / (float)FF_QP2LAMBDA); else avccontext->bit_rate;
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
575 //if(avccontext->cutoff > 0) cfreq = avccontext->cutoff / 1000.0;
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
576
3811
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
577 avccontext->extradata_size = put_main_header(venc, (uint8_t**)&avccontext->extradata);
3808
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
578
3833
d4c01d85fb46 Original Commit: r27 | ods15 | 2006-09-22 14:19:51 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3832
diff changeset
579 avccontext->frame_size = 1 << venc->blocksize[0];
3808
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
580
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
581 avccontext->coded_frame = avcodec_alloc_frame();
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
582 avccontext->coded_frame->key_frame = 1;
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
583
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
584 return 0;
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
585 }
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
586
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
587
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
588 static int vorbis_encode_frame(AVCodecContext * avccontext, unsigned char * packets, int buf_size, void *data)
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
589 {
3811
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
590 #if 0
3808
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
591 venc_context_t * venc = avccontext->priv_data;
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
592 signed short * audio = data;
3833
d4c01d85fb46 Original Commit: r27 | ods15 | 2006-09-22 14:19:51 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3832
diff changeset
593 int samples = data ? avccontext->frame_size : 0;
3808
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
594
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
595 avccontext->coded_frame->pts = av_rescale_q(op2->granulepos, (AVRational){1, avccontext->sample_rate}, avccontext->time_base);
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
596 memcpy(packets, compressed_frame, l);
3811
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
597 #endif
3824
61d312116e71 Original Commit: r18 | ods15 | 2006-09-22 12:29:26 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3823
diff changeset
598 return data ? 50 : 0;
3808
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
599 }
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
600
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
601
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
602 static int vorbis_encode_close(AVCodecContext * avccontext)
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
603 {
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
604 venc_context_t * venc = avccontext->priv_data;
3831
7d27ba61600e Original Commit: r25 | ods15 | 2006-09-22 14:06:04 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3830
diff changeset
605 int i;
7d27ba61600e Original Commit: r25 | ods15 | 2006-09-22 14:06:04 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3830
diff changeset
606
7d27ba61600e Original Commit: r25 | ods15 | 2006-09-22 14:06:04 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3830
diff changeset
607 if (venc->codebooks) for (i = 0; i < venc->ncodebooks; i++) {
7d27ba61600e Original Commit: r25 | ods15 | 2006-09-22 14:06:04 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3830
diff changeset
608 av_freep(&venc->codebooks[i].entries);
7d27ba61600e Original Commit: r25 | ods15 | 2006-09-22 14:06:04 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3830
diff changeset
609 av_freep(&venc->codebooks[i].quantlist);
7d27ba61600e Original Commit: r25 | ods15 | 2006-09-22 14:06:04 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3830
diff changeset
610 av_freep(&venc->codebooks[i].dimentions);
7d27ba61600e Original Commit: r25 | ods15 | 2006-09-22 14:06:04 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3830
diff changeset
611 }
7d27ba61600e Original Commit: r25 | ods15 | 2006-09-22 14:06:04 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3830
diff changeset
612 av_freep(&venc->codebooks);
7d27ba61600e Original Commit: r25 | ods15 | 2006-09-22 14:06:04 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3830
diff changeset
613
7d27ba61600e Original Commit: r25 | ods15 | 2006-09-22 14:06:04 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3830
diff changeset
614 if (venc->floors) for (i = 0; i < venc->nfloors; i++) {
7d27ba61600e Original Commit: r25 | ods15 | 2006-09-22 14:06:04 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3830
diff changeset
615 int j;
7d27ba61600e Original Commit: r25 | ods15 | 2006-09-22 14:06:04 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3830
diff changeset
616 av_freep(&venc->floors[i].classes);
7d27ba61600e Original Commit: r25 | ods15 | 2006-09-22 14:06:04 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3830
diff changeset
617 if (venc->floors[i].classes)
7d27ba61600e Original Commit: r25 | ods15 | 2006-09-22 14:06:04 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3830
diff changeset
618 for (j = 0; j < venc->floors[i].nclasses; j++)
7d27ba61600e Original Commit: r25 | ods15 | 2006-09-22 14:06:04 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3830
diff changeset
619 av_freep(&venc->floors[i].classes[j].books);
7d27ba61600e Original Commit: r25 | ods15 | 2006-09-22 14:06:04 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3830
diff changeset
620 av_freep(&venc->floors[i].partition_to_class);
7d27ba61600e Original Commit: r25 | ods15 | 2006-09-22 14:06:04 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3830
diff changeset
621 av_freep(&venc->floors[i].list);
7d27ba61600e Original Commit: r25 | ods15 | 2006-09-22 14:06:04 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3830
diff changeset
622 }
7d27ba61600e Original Commit: r25 | ods15 | 2006-09-22 14:06:04 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3830
diff changeset
623 av_freep(&venc->floors);
7d27ba61600e Original Commit: r25 | ods15 | 2006-09-22 14:06:04 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3830
diff changeset
624
7d27ba61600e Original Commit: r25 | ods15 | 2006-09-22 14:06:04 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3830
diff changeset
625 if (venc->residues) for (i = 0; i < venc->nresidues; i++) {
7d27ba61600e Original Commit: r25 | ods15 | 2006-09-22 14:06:04 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3830
diff changeset
626 av_freep(&venc->residues[i].books);
7d27ba61600e Original Commit: r25 | ods15 | 2006-09-22 14:06:04 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3830
diff changeset
627 }
7d27ba61600e Original Commit: r25 | ods15 | 2006-09-22 14:06:04 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3830
diff changeset
628 av_freep(&venc->residues);
7d27ba61600e Original Commit: r25 | ods15 | 2006-09-22 14:06:04 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3830
diff changeset
629
7d27ba61600e Original Commit: r25 | ods15 | 2006-09-22 14:06:04 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3830
diff changeset
630 if (venc->mappings) for (i = 0; i < venc->nmappings; i++) {
7d27ba61600e Original Commit: r25 | ods15 | 2006-09-22 14:06:04 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3830
diff changeset
631 av_freep(&venc->mappings[i].mux);
7d27ba61600e Original Commit: r25 | ods15 | 2006-09-22 14:06:04 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3830
diff changeset
632 av_freep(&venc->mappings[i].floor);
7d27ba61600e Original Commit: r25 | ods15 | 2006-09-22 14:06:04 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3830
diff changeset
633 av_freep(&venc->mappings[i].residue);
7d27ba61600e Original Commit: r25 | ods15 | 2006-09-22 14:06:04 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3830
diff changeset
634 }
7d27ba61600e Original Commit: r25 | ods15 | 2006-09-22 14:06:04 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3830
diff changeset
635 av_freep(&venc->mappings);
7d27ba61600e Original Commit: r25 | ods15 | 2006-09-22 14:06:04 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3830
diff changeset
636
7d27ba61600e Original Commit: r25 | ods15 | 2006-09-22 14:06:04 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3830
diff changeset
637 av_freep(&venc->modes);
3808
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
638
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
639 av_freep(&avccontext->coded_frame);
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
640 av_freep(&avccontext->extradata);
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
641
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
642 return 0 ;
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
643 }
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
644
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
645 AVCodec oggvorbis_encoder = {
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
646 "vorbis",
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
647 CODEC_TYPE_AUDIO,
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
648 CODEC_ID_VORBIS,
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
649 sizeof(venc_context_t),
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
650 vorbis_encode_init,
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
651 vorbis_encode_frame,
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
652 vorbis_encode_close,
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
653 .capabilities= CODEC_CAP_DELAY,
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
654 };