annotate vorbis_enc.c @ 3821:5fdb0fa900cd libavcodec

Original Commit: r15 | ods15 | 2006-09-22 12:26:42 +0300 (Fri, 22 Sep 2006) | 2 lines bug fix in main header function, 0 -> i
author ods15
date Mon, 02 Oct 2006 05:55:39 +0000
parents 3cfdf99da951
children a7f46bc1fea0
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
3810
a8bebf3e9cb7 Original Commit: r4 | ods15 | 2006-09-16 15:36:03 +0300 (Sat, 16 Sep 2006) | 3 lines
ods15
parents: 3809
diff changeset
30 #define ALT_BITSTREAM_READER_LE
a8bebf3e9cb7 Original Commit: r4 | ods15 | 2006-09-16 15:36:03 +0300 (Sat, 16 Sep 2006) | 3 lines
ods15
parents: 3809
diff changeset
31 #include "bitstream.h"
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 #define VORBIS_FRAME_SIZE 64
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
34
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
35 #define BUFFER_SIZE (1024*64)
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
36
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
37 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
38 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
39 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
40 } 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
41
a8bebf3e9cb7 Original Commit: r4 | ods15 | 2006-09-16 15:36:03 +0300 (Sat, 16 Sep 2006) | 3 lines
ods15
parents: 3809
diff changeset
42 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
43 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
44 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
45 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
46 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
47 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
48 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
49 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
50 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
51 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
52 } 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
53
a8bebf3e9cb7 Original Commit: r4 | ods15 | 2006-09-16 15:36:03 +0300 (Sat, 16 Sep 2006) | 3 lines
ods15
parents: 3809
diff changeset
54 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
55 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
56 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
57 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
58 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
59 } 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
60
464eca766731 Original Commit: r8 | ods15 | 2006-09-17 09:43:38 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3813
diff changeset
61 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
62 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
63 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
64 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
65 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
66 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
67 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
68 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
69 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
70 } 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
71
95b70f8bc29e Original Commit: r7 | ods15 | 2006-09-17 08:50:47 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3812
diff changeset
72 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
73 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
74 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
75 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
76 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
77 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
78 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
79 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
80 } 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
81
95b70f8bc29e Original Commit: r7 | ods15 | 2006-09-17 08:50:47 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3812
diff changeset
82 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
83 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
84 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
85 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
86 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
87 } 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
88
95b70f8bc29e Original Commit: r7 | ods15 | 2006-09-17 08:50:47 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3812
diff changeset
89 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
90 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
91 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
92 } 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
93
3ca15f0d4882 Original Commit: r11 | ods15 | 2006-09-17 19:41:28 +0300 (Sun, 17 Sep 2006) | 4 lines
ods15
parents: 3816
diff changeset
94 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
95 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
96 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
97 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
98
3810
a8bebf3e9cb7 Original Commit: r4 | ods15 | 2006-09-16 15:36:03 +0300 (Sat, 16 Sep 2006) | 3 lines
ods15
parents: 3809
diff changeset
99 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
100 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
101
95b70f8bc29e Original Commit: r7 | ods15 | 2006-09-17 08:50:47 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3812
diff changeset
102 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
103 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
104
95b70f8bc29e Original Commit: r7 | ods15 | 2006-09-17 08:50:47 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3812
diff changeset
105 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
106 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
107
95b70f8bc29e Original Commit: r7 | ods15 | 2006-09-17 08:50:47 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3812
diff changeset
108 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
109 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
110
3ca15f0d4882 Original Commit: r11 | ods15 | 2006-09-17 19:41:28 +0300 (Sun, 17 Sep 2006) | 4 lines
ods15
parents: 3816
diff changeset
111 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
112 vorbis_mode_t * modes;
3808
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
113 } venc_context_t;
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
114
3818
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
115 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
116 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
117 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
118 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
119 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
120 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
121 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
122 }
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
123 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
124 } 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
125 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
126 }
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
127
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
128 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
129 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
130 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
131
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
132 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
133 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
134 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
135 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
136 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
137 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
138 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
139 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
140 }
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
141 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
142
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
143 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
144 else {
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
145 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
146 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
147 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
148 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
149 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
150 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
151 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
152 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
153 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
154 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
155
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
156 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
157 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
158 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
159 }
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
160 }
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
161 }
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
162
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
163 }
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 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
166 codebook_t * cb;
3820
3cfdf99da951 Original Commit: r14 | ods15 | 2006-09-22 12:26:17 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3819
diff changeset
167 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
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 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
170 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
171 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
172
3820
3cfdf99da951 Original Commit: r14 | ods15 | 2006-09-22 12:26:17 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3819
diff changeset
173 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
174 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
175
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
176 // 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
177 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
178 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
179 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
180 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
181 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
182 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
183 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
184 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
185 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
186 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
187 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
188
3819
92063e9b6728 Original Commit: r13 | ods15 | 2006-09-22 09:29:38 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3818
diff changeset
189 // codebook 2 - residue classbook, values 0..0, 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
190 cb = &venc->codebooks[1];
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
191 cb->nentries = 1;
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
192 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
193 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
194 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
195 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
196 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
197 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
198 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
199 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
200 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
201
3820
3cfdf99da951 Original Commit: r14 | ods15 | 2006-09-22 12:26:17 +0300 (Fri, 22 Sep 2006) | 2 lines
ods15
parents: 3819
diff changeset
202 // 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
203 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
204 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
205 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
206 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
207 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
208 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
209 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
210 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
211 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
212 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
213 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
214 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
215 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
216 }
3818
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
217
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
218 }
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
219
3811
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
220 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
221 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
222 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
223 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
224 }
a8bebf3e9cb7 Original Commit: r4 | ods15 | 2006-09-16 15:36:03 +0300 (Sat, 16 Sep 2006) | 3 lines
ods15
parents: 3809
diff changeset
225
3811
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
226 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
227 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
228 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
229 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
230 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
231 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
232 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
233 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
234 }
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
235
3810
a8bebf3e9cb7 Original Commit: r4 | ods15 | 2006-09-16 15:36:03 +0300 (Sat, 16 Sep 2006) | 3 lines
ods15
parents: 3809
diff changeset
236 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
237 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
238 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
239
a8bebf3e9cb7 Original Commit: r4 | ods15 | 2006-09-16 15:36:03 +0300 (Sat, 16 Sep 2006) | 3 lines
ods15
parents: 3809
diff changeset
240 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
241 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
242 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
243
a8bebf3e9cb7 Original Commit: r4 | ods15 | 2006-09-16 15:36:03 +0300 (Sat, 16 Sep 2006) | 3 lines
ods15
parents: 3809
diff changeset
244 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
245 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
246
a8bebf3e9cb7 Original Commit: r4 | ods15 | 2006-09-16 15:36:03 +0300 (Sat, 16 Sep 2006) | 3 lines
ods15
parents: 3809
diff changeset
247 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
248 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
249 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
250 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
251 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
252 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
253 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
254 for (j = 0; j+i < cb->nentries; j++) if (cb->entries[j+i].len != len) break;
a8bebf3e9cb7 Original Commit: r4 | ods15 | 2006-09-16 15:36:03 +0300 (Sat, 16 Sep 2006) | 3 lines
ods15
parents: 3809
diff changeset
255 put_bits(pb, 5, j);
a8bebf3e9cb7 Original Commit: r4 | ods15 | 2006-09-16 15:36:03 +0300 (Sat, 16 Sep 2006) | 3 lines
ods15
parents: 3809
diff changeset
256 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
257 len++;
a8bebf3e9cb7 Original Commit: r4 | ods15 | 2006-09-16 15:36:03 +0300 (Sat, 16 Sep 2006) | 3 lines
ods15
parents: 3809
diff changeset
258 }
a8bebf3e9cb7 Original Commit: r4 | ods15 | 2006-09-16 15:36:03 +0300 (Sat, 16 Sep 2006) | 3 lines
ods15
parents: 3809
diff changeset
259 } else {
a8bebf3e9cb7 Original Commit: r4 | ods15 | 2006-09-16 15:36:03 +0300 (Sat, 16 Sep 2006) | 3 lines
ods15
parents: 3809
diff changeset
260 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
261 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
262 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
263 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
264
a8bebf3e9cb7 Original Commit: r4 | ods15 | 2006-09-16 15:36:03 +0300 (Sat, 16 Sep 2006) | 3 lines
ods15
parents: 3809
diff changeset
265 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
266 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
267 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
268 }
a8bebf3e9cb7 Original Commit: r4 | ods15 | 2006-09-16 15:36:03 +0300 (Sat, 16 Sep 2006) | 3 lines
ods15
parents: 3809
diff changeset
269 }
a8bebf3e9cb7 Original Commit: r4 | ods15 | 2006-09-16 15:36:03 +0300 (Sat, 16 Sep 2006) | 3 lines
ods15
parents: 3809
diff changeset
270
a8bebf3e9cb7 Original Commit: r4 | ods15 | 2006-09-16 15:36:03 +0300 (Sat, 16 Sep 2006) | 3 lines
ods15
parents: 3809
diff changeset
271 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
272 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
273 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
274 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
275
a8bebf3e9cb7 Original Commit: r4 | ods15 | 2006-09-16 15:36:03 +0300 (Sat, 16 Sep 2006) | 3 lines
ods15
parents: 3809
diff changeset
276 for (i = 1; i < tmp; i++) bits = FFMIN(bits, ilog(cb->quantlist[i]));
a8bebf3e9cb7 Original Commit: r4 | ods15 | 2006-09-16 15:36:03 +0300 (Sat, 16 Sep 2006) | 3 lines
ods15
parents: 3809
diff changeset
277
3811
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
278 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
279 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
280
3811
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
281 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
282 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
283
3811
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
284 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
285 }
a8bebf3e9cb7 Original Commit: r4 | ods15 | 2006-09-16 15:36:03 +0300 (Sat, 16 Sep 2006) | 3 lines
ods15
parents: 3809
diff changeset
286 }
a8bebf3e9cb7 Original Commit: r4 | ods15 | 2006-09-16 15:36:03 +0300 (Sat, 16 Sep 2006) | 3 lines
ods15
parents: 3809
diff changeset
287
3814
464eca766731 Original Commit: r8 | ods15 | 2006-09-17 09:43:38 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3813
diff changeset
288 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
289 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
290
464eca766731 Original Commit: r8 | ods15 | 2006-09-17 09:43:38 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3813
diff changeset
291 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
292
464eca766731 Original Commit: r8 | ods15 | 2006-09-17 09:43:38 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3813
diff changeset
293 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
294
464eca766731 Original Commit: r8 | ods15 | 2006-09-17 09:43:38 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3813
diff changeset
295 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
296
464eca766731 Original Commit: r8 | ods15 | 2006-09-17 09:43:38 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3813
diff changeset
297 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
298 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
299
464eca766731 Original Commit: r8 | ods15 | 2006-09-17 09:43:38 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3813
diff changeset
300 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
301 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
302
464eca766731 Original Commit: r8 | ods15 | 2006-09-17 09:43:38 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3813
diff changeset
303 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
304
464eca766731 Original Commit: r8 | ods15 | 2006-09-17 09:43:38 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3813
diff changeset
305 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
306
464eca766731 Original Commit: r8 | ods15 | 2006-09-17 09:43:38 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3813
diff changeset
307 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
308 }
464eca766731 Original Commit: r8 | ods15 | 2006-09-17 09:43:38 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3813
diff changeset
309
464eca766731 Original Commit: r8 | ods15 | 2006-09-17 09:43:38 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3813
diff changeset
310 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
311 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
312
464eca766731 Original Commit: r8 | ods15 | 2006-09-17 09:43:38 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3813
diff changeset
313 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
314 }
95b70f8bc29e Original Commit: r7 | ods15 | 2006-09-17 08:50:47 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3812
diff changeset
315
3814
464eca766731 Original Commit: r8 | ods15 | 2006-09-17 09:43:38 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3813
diff changeset
316 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
317 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
318
3fa081422f78 Original Commit: r9 | ods15 | 2006-09-17 18:56:41 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3814
diff changeset
319 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
320
3fa081422f78 Original Commit: r9 | ods15 | 2006-09-17 18:56:41 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3814
diff changeset
321 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
322 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
323 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
324 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
325 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
326
3fa081422f78 Original Commit: r9 | ods15 | 2006-09-17 18:56:41 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3814
diff changeset
327 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
328 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
329 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
330
3fa081422f78 Original Commit: r9 | ods15 | 2006-09-17 18:56:41 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3814
diff changeset
331 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
332 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
333
3fa081422f78 Original Commit: r9 | ods15 | 2006-09-17 18:56:41 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3814
diff changeset
334 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
335 }
3fa081422f78 Original Commit: r9 | ods15 | 2006-09-17 18:56:41 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3814
diff changeset
336
3fa081422f78 Original Commit: r9 | ods15 | 2006-09-17 18:56:41 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3814
diff changeset
337 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
338 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
339 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
340 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
341 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
342 }
3813
95b70f8bc29e Original Commit: r7 | ods15 | 2006-09-17 08:50:47 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3812
diff changeset
343 }
95b70f8bc29e Original Commit: r7 | ods15 | 2006-09-17 08:50:47 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3812
diff changeset
344
3811
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
345 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
346 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
347 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
348 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
349 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
350 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
351
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
352 // 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
353 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
354 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
355 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
356 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
357 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
358 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
359 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
360 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
361 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
362 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
363 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
364 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
365
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
366 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
367 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
368 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
369 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
370
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
371 // 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
372 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
373 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
374 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
375 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
376 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
377 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
378
3811
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
379 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
380 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
381 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
382 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
383
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
384 // 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
385 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
386 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
387 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
388
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
389 // codebooks
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_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
391 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
392
3813
95b70f8bc29e Original Commit: r7 | ods15 | 2006-09-17 08:50:47 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3812
diff changeset
393 // 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
394 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
395 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
396
95b70f8bc29e Original Commit: r7 | ods15 | 2006-09-17 08:50:47 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3812
diff changeset
397 // floors
95b70f8bc29e Original Commit: r7 | ods15 | 2006-09-17 08:50:47 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3812
diff changeset
398 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
399 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
400
95b70f8bc29e Original Commit: r7 | ods15 | 2006-09-17 08:50:47 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3812
diff changeset
401 // residues
95b70f8bc29e Original Commit: r7 | ods15 | 2006-09-17 08:50:47 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3812
diff changeset
402 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
403 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
404
95b70f8bc29e Original Commit: r7 | ods15 | 2006-09-17 08:50:47 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3812
diff changeset
405 // mappings
95b70f8bc29e Original Commit: r7 | ods15 | 2006-09-17 08:50:47 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3812
diff changeset
406 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
407 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
408 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
409 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
410 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
411
6eba53afa0b0 Original Commit: r10 | ods15 | 2006-09-17 19:37:17 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3815
diff changeset
412 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
413 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
414
6eba53afa0b0 Original Commit: r10 | ods15 | 2006-09-17 19:37:17 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3815
diff changeset
415 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
416
6eba53afa0b0 Original Commit: r10 | ods15 | 2006-09-17 19:37:17 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3815
diff changeset
417 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
418
6eba53afa0b0 Original Commit: r10 | ods15 | 2006-09-17 19:37:17 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3815
diff changeset
419 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
420
6eba53afa0b0 Original Commit: r10 | ods15 | 2006-09-17 19:37:17 +0300 (Sun, 17 Sep 2006) | 2 lines
ods15
parents: 3815
diff changeset
421 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
422 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
423 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
424 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
425 }
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 }
3811
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
427
3817
3ca15f0d4882 Original Commit: r11 | ods15 | 2006-09-17 19:41:28 +0300 (Sun, 17 Sep 2006) | 4 lines
ods15
parents: 3816
diff changeset
428 // modes
3ca15f0d4882 Original Commit: r11 | ods15 | 2006-09-17 19:41:28 +0300 (Sun, 17 Sep 2006) | 4 lines
ods15
parents: 3816
diff changeset
429 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
430 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
431 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
432 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
433 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
434 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
435 }
3ca15f0d4882 Original Commit: r11 | ods15 | 2006-09-17 19:41:28 +0300 (Sun, 17 Sep 2006) | 4 lines
ods15
parents: 3816
diff changeset
436
3811
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
437 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
438 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
439
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
440 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
441 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
442
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
443 *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
444 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
445 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
446 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
447 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
448 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
449 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
450 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
451 }
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
452
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
453 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
454 }
a8bebf3e9cb7 Original Commit: r4 | ods15 | 2006-09-16 15:36:03 +0300 (Sat, 16 Sep 2006) | 3 lines
ods15
parents: 3809
diff changeset
455
3809
500d86b68542 Original Commit: r3 | ods15 | 2006-09-16 11:49:07 +0300 (Sat, 16 Sep 2006) | 2 lines
ods15
parents: 3808
diff changeset
456 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
457 {
3808
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
458 venc_context_t * venc = avccontext->priv_data;
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
459
3818
6a737f2d852e Original Commit: r12 | ods15 | 2006-09-22 09:28:30 +0300 (Fri, 22 Sep 2006) | 5 lines
ods15
parents: 3817
diff changeset
460 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
461
3808
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
462 //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
463 //if(avccontext->cutoff > 0) cfreq = avccontext->cutoff / 1000.0;
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
464
3811
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
465 avccontext->extradata_size = put_main_header(venc, (uint8_t**)&avccontext->extradata);
3808
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
466
3809
500d86b68542 Original Commit: r3 | ods15 | 2006-09-16 11:49:07 +0300 (Sat, 16 Sep 2006) | 2 lines
ods15
parents: 3808
diff changeset
467 avccontext->frame_size = VORBIS_FRAME_SIZE;
3808
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
468
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
469 avccontext->coded_frame = avcodec_alloc_frame();
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
470 avccontext->coded_frame->key_frame = 1;
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
471
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
472 return 0;
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
473 }
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
474
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
475
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
476 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
477 {
3811
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
478 #if 0
3808
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
479 venc_context_t * venc = avccontext->priv_data;
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
480 signed short * audio = data;
3811
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
481 int samples = data ? VORBIS_FRAME_SIZE : 0;
3808
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
482
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
483 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
484 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
485 #endif
9f6acced986e Original Commit: r5 | ods15 | 2006-09-16 17:29:04 +0300 (Sat, 16 Sep 2006) | 4 lines
ods15
parents: 3810
diff changeset
486 return 0;
3808
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
487 }
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
488
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
489
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
490 static int vorbis_encode_close(AVCodecContext * avccontext)
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
491 {
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
492 venc_context_t * venc = avccontext->priv_data;
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
493
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
494 av_freep(&avccontext->coded_frame);
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
495 av_freep(&avccontext->extradata);
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
496
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
497 return 0 ;
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
498 }
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
499
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
500 AVCodec oggvorbis_encoder = {
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
501 "vorbis",
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
502 CODEC_TYPE_AUDIO,
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
503 CODEC_ID_VORBIS,
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
504 sizeof(venc_context_t),
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
505 vorbis_encode_init,
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
506 vorbis_encode_frame,
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
507 vorbis_encode_close,
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
508 .capabilities= CODEC_CAP_DELAY,
5551768b5a4f skeleton for vorbis_enc.c
ods15
parents:
diff changeset
509 };