annotate src/flac/libflac/stream_encoder.c @ 1218:cc4e03df48a3

Make things not crash.
author William Pitcock <nenolod@atheme-project.org>
date Sun, 08 Jul 2007 22:25:12 -0500
parents 454ad11020ec
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
715
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1 /* libFLAC - Free Lossless Audio Codec library
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2 * Copyright (C) 2000,2001,2002,2003,2004,2005,2006,2007 Josh Coalson
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3 *
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4 * Redistribution and use in source and binary forms, with or without
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
5 * modification, are permitted provided that the following conditions
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
6 * are met:
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
7 *
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
8 * - Redistributions of source code must retain the above copyright
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
9 * notice, this list of conditions and the following disclaimer.
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
10 *
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
11 * - Redistributions in binary form must reproduce the above copyright
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
12 * notice, this list of conditions and the following disclaimer in the
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
13 * documentation and/or other materials provided with the distribution.
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
14 *
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
15 * - Neither the name of the Xiph.org Foundation nor the names of its
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
16 * contributors may be used to endorse or promote products derived from
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
17 * this software without specific prior written permission.
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
18 *
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
24 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
25 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
26 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
27 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
28 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
29 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
30 */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
31
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
32 #if HAVE_CONFIG_H
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
33 # include <config.h>
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
34 #endif
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
35
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
36 #if defined _MSC_VER || defined __MINGW32__
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
37 #include <io.h> /* for _setmode() */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
38 #include <fcntl.h> /* for _O_BINARY */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
39 #endif
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
40 #if defined __CYGWIN__ || defined __EMX__
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
41 #include <io.h> /* for setmode(), O_BINARY */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
42 #include <fcntl.h> /* for _O_BINARY */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
43 #endif
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
44 #include <limits.h>
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
45 #include <stdio.h>
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
46 #include <stdlib.h> /* for malloc() */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
47 #include <string.h> /* for memcpy() */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
48 #include <sys/types.h> /* for off_t */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
49 #if defined _MSC_VER || defined __BORLANDC__ || defined __MINGW32__
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
50 #if _MSC_VER <= 1600 || defined __BORLANDC__ /* @@@ [2G limit] */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
51 #define fseeko fseek
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
52 #define ftello ftell
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
53 #endif
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
54 #endif
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
55 #include "FLAC/assert.h"
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
56 #include "FLAC/stream_decoder.h"
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
57 #include "protected/stream_encoder.h"
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
58 #include "private/bitwriter.h"
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
59 #include "private/bitmath.h"
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
60 #include "private/crc.h"
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
61 #include "private/cpu.h"
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
62 #include "private/fixed.h"
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
63 #include "private/format.h"
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
64 #include "private/lpc.h"
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
65 #include "private/md5.h"
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
66 #include "private/memory.h"
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
67 #if FLAC__HAS_OGG
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
68 #include "private/ogg_helper.h"
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
69 #include "private/ogg_mapping.h"
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
70 #endif
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
71 #include "private/stream_encoder_framing.h"
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
72 #include "private/window.h"
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
73
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
74 #ifdef min
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
75 #undef min
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
76 #endif
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
77 #define min(x,y) ((x)<(y)?(x):(y))
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
78
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
79 #ifdef max
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
80 #undef max
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
81 #endif
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
82 #define max(x,y) ((x)>(y)?(x):(y))
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
83
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
84 /* Exact Rice codeword length calculation is off by default. The simple
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
85 * (and fast) estimation (of how many bits a residual value will be
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
86 * encoded with) in this encoder is very good, almost always yielding
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
87 * compression within 0.1% of exact calculation.
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
88 */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
89 #undef EXACT_RICE_BITS_CALCULATION
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
90 /* Rice parameter searching is off by default. The simple (and fast)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
91 * parameter estimation in this encoder is very good, almost always
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
92 * yielding compression within 0.1% of the optimal parameters.
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
93 */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
94 #undef ENABLE_RICE_PARAMETER_SEARCH
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
95
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
96
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
97 typedef struct {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
98 FLAC__int32 *data[FLAC__MAX_CHANNELS];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
99 unsigned size; /* of each data[] in samples */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
100 unsigned tail;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
101 } verify_input_fifo;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
102
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
103 typedef struct {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
104 const FLAC__byte *data;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
105 unsigned capacity;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
106 unsigned bytes;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
107 } verify_output;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
108
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
109 typedef enum {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
110 ENCODER_IN_MAGIC = 0,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
111 ENCODER_IN_METADATA = 1,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
112 ENCODER_IN_AUDIO = 2
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
113 } EncoderStateHint;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
114
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
115 static struct CompressionLevels {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
116 FLAC__bool do_mid_side_stereo;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
117 FLAC__bool loose_mid_side_stereo;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
118 unsigned max_lpc_order;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
119 unsigned qlp_coeff_precision;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
120 FLAC__bool do_qlp_coeff_prec_search;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
121 FLAC__bool do_escape_coding;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
122 FLAC__bool do_exhaustive_model_search;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
123 unsigned min_residual_partition_order;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
124 unsigned max_residual_partition_order;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
125 unsigned rice_parameter_search_dist;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
126 } compression_levels_[] = {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
127 { false, false, 0, 0, false, false, false, 0, 3, 0 },
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
128 { true , true , 0, 0, false, false, false, 0, 3, 0 },
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
129 { true , false, 0, 0, false, false, false, 0, 3, 0 },
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
130 { false, false, 6, 0, false, false, false, 0, 4, 0 },
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
131 { true , true , 8, 0, false, false, false, 0, 4, 0 },
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
132 { true , false, 8, 0, false, false, false, 0, 5, 0 },
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
133 { true , false, 8, 0, false, false, false, 0, 6, 0 },
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
134 { true , false, 8, 0, false, false, true , 0, 6, 0 },
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
135 { true , false, 12, 0, false, false, true , 0, 6, 0 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
136 };
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
137
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
138
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
139 /***********************************************************************
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
140 *
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
141 * Private class method prototypes
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
142 *
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
143 ***********************************************************************/
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
144
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
145 static void set_defaults_(FLAC__StreamEncoder *encoder);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
146 static void free_(FLAC__StreamEncoder *encoder);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
147 static FLAC__bool resize_buffers_(FLAC__StreamEncoder *encoder, unsigned new_blocksize);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
148 static FLAC__bool write_bitbuffer_(FLAC__StreamEncoder *encoder, unsigned samples, FLAC__bool is_last_block);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
149 static FLAC__StreamEncoderWriteStatus write_frame_(FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, FLAC__bool is_last_block);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
150 static void update_metadata_(const FLAC__StreamEncoder *encoder);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
151 #if FLAC__HAS_OGG
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
152 static void update_ogg_metadata_(FLAC__StreamEncoder *encoder);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
153 #endif
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
154 static FLAC__bool process_frame_(FLAC__StreamEncoder *encoder, FLAC__bool is_fractional_block, FLAC__bool is_last_block);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
155 static FLAC__bool process_subframes_(FLAC__StreamEncoder *encoder, FLAC__bool is_fractional_block);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
156
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
157 static FLAC__bool process_subframe_(
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
158 FLAC__StreamEncoder *encoder,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
159 unsigned min_partition_order,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
160 unsigned max_partition_order,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
161 const FLAC__FrameHeader *frame_header,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
162 unsigned subframe_bps,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
163 const FLAC__int32 integer_signal[],
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
164 #ifndef FLAC__INTEGER_ONLY_LIBRARY
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
165 const FLAC__real real_signal[],
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
166 #endif
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
167 FLAC__Subframe *subframe[2],
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
168 FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents[2],
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
169 FLAC__int32 *residual[2],
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
170 unsigned *best_subframe,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
171 unsigned *best_bits
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
172 );
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
173
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
174 static FLAC__bool add_subframe_(
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
175 FLAC__StreamEncoder *encoder,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
176 unsigned blocksize,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
177 unsigned subframe_bps,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
178 const FLAC__Subframe *subframe,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
179 FLAC__BitWriter *frame
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
180 );
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
181
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
182 static unsigned evaluate_constant_subframe_(
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
183 FLAC__StreamEncoder *encoder,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
184 const FLAC__int32 signal,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
185 unsigned blocksize,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
186 unsigned subframe_bps,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
187 FLAC__Subframe *subframe
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
188 );
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
189
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
190 static unsigned evaluate_fixed_subframe_(
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
191 FLAC__StreamEncoder *encoder,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
192 const FLAC__int32 signal[],
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
193 FLAC__int32 residual[],
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
194 FLAC__uint64 abs_residual_partition_sums[],
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
195 unsigned raw_bits_per_partition[],
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
196 unsigned blocksize,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
197 unsigned subframe_bps,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
198 unsigned order,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
199 unsigned rice_parameter,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
200 unsigned min_partition_order,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
201 unsigned max_partition_order,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
202 FLAC__bool do_escape_coding,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
203 unsigned rice_parameter_search_dist,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
204 FLAC__Subframe *subframe,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
205 FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
206 );
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
207
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
208 #ifndef FLAC__INTEGER_ONLY_LIBRARY
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
209 static unsigned evaluate_lpc_subframe_(
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
210 FLAC__StreamEncoder *encoder,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
211 const FLAC__int32 signal[],
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
212 FLAC__int32 residual[],
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
213 FLAC__uint64 abs_residual_partition_sums[],
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
214 unsigned raw_bits_per_partition[],
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
215 const FLAC__real lp_coeff[],
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
216 unsigned blocksize,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
217 unsigned subframe_bps,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
218 unsigned order,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
219 unsigned qlp_coeff_precision,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
220 unsigned rice_parameter,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
221 unsigned min_partition_order,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
222 unsigned max_partition_order,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
223 FLAC__bool do_escape_coding,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
224 unsigned rice_parameter_search_dist,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
225 FLAC__Subframe *subframe,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
226 FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
227 );
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
228 #endif
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
229
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
230 static unsigned evaluate_verbatim_subframe_(
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
231 FLAC__StreamEncoder *encoder,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
232 const FLAC__int32 signal[],
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
233 unsigned blocksize,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
234 unsigned subframe_bps,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
235 FLAC__Subframe *subframe
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
236 );
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
237
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
238 static unsigned find_best_partition_order_(
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
239 struct FLAC__StreamEncoderPrivate *private_,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
240 const FLAC__int32 residual[],
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
241 FLAC__uint64 abs_residual_partition_sums[],
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
242 unsigned raw_bits_per_partition[],
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
243 unsigned residual_samples,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
244 unsigned predictor_order,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
245 unsigned rice_parameter,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
246 unsigned min_partition_order,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
247 unsigned max_partition_order,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
248 FLAC__bool do_escape_coding,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
249 unsigned rice_parameter_search_dist,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
250 FLAC__EntropyCodingMethod_PartitionedRice *best_partitioned_rice
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
251 );
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
252
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
253 static void precompute_partition_info_sums_(
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
254 const FLAC__int32 residual[],
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
255 FLAC__uint64 abs_residual_partition_sums[],
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
256 unsigned residual_samples,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
257 unsigned predictor_order,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
258 unsigned min_partition_order,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
259 unsigned max_partition_order
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
260 );
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
261
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
262 static void precompute_partition_info_escapes_(
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
263 const FLAC__int32 residual[],
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
264 unsigned raw_bits_per_partition[],
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
265 unsigned residual_samples,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
266 unsigned predictor_order,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
267 unsigned min_partition_order,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
268 unsigned max_partition_order
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
269 );
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
270
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
271 static FLAC__bool set_partitioned_rice_(
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
272 #ifdef EXACT_RICE_BITS_CALCULATION
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
273 const FLAC__int32 residual[],
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
274 #endif
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
275 const FLAC__uint64 abs_residual_partition_sums[],
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
276 const unsigned raw_bits_per_partition[],
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
277 const unsigned residual_samples,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
278 const unsigned predictor_order,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
279 const unsigned suggested_rice_parameter,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
280 const unsigned rice_parameter_search_dist,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
281 const unsigned partition_order,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
282 const FLAC__bool search_for_escapes,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
283 FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
284 unsigned *bits
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
285 );
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
286
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
287 static unsigned get_wasted_bits_(FLAC__int32 signal[], unsigned samples);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
288
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
289 /* verify-related routines: */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
290 static void append_to_verify_fifo_(
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
291 verify_input_fifo *fifo,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
292 const FLAC__int32 * const input[],
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
293 unsigned input_offset,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
294 unsigned channels,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
295 unsigned wide_samples
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
296 );
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
297
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
298 static void append_to_verify_fifo_interleaved_(
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
299 verify_input_fifo *fifo,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
300 const FLAC__int32 input[],
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
301 unsigned input_offset,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
302 unsigned channels,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
303 unsigned wide_samples
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
304 );
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
305
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
306 static FLAC__StreamDecoderReadStatus verify_read_callback_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
307 static FLAC__StreamDecoderWriteStatus verify_write_callback_(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
308 static void verify_metadata_callback_(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
309 static void verify_error_callback_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
310
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
311 static FLAC__StreamEncoderReadStatus file_read_callback_(const FLAC__StreamEncoder *encoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
312 static FLAC__StreamEncoderSeekStatus file_seek_callback_(const FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
313 static FLAC__StreamEncoderTellStatus file_tell_callback_(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
314 static FLAC__StreamEncoderWriteStatus file_write_callback_(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, unsigned current_frame, void *client_data);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
315 static FILE *get_binary_stdout_(void);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
316
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
317
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
318 /***********************************************************************
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
319 *
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
320 * Private class data
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
321 *
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
322 ***********************************************************************/
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
323
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
324 typedef struct FLAC__StreamEncoderPrivate {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
325 unsigned input_capacity; /* current size (in samples) of the signal and residual buffers */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
326 FLAC__int32 *integer_signal[FLAC__MAX_CHANNELS]; /* the integer version of the input signal */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
327 FLAC__int32 *integer_signal_mid_side[2]; /* the integer version of the mid-side input signal (stereo only) */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
328 #ifndef FLAC__INTEGER_ONLY_LIBRARY
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
329 FLAC__real *real_signal[FLAC__MAX_CHANNELS]; /* the floating-point version of the input signal */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
330 FLAC__real *real_signal_mid_side[2]; /* the floating-point version of the mid-side input signal (stereo only) */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
331 FLAC__real *window[FLAC__MAX_APODIZATION_FUNCTIONS]; /* the pre-computed floating-point window for each apodization function */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
332 FLAC__real *windowed_signal; /* the real_signal[] * current window[] */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
333 #endif
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
334 unsigned subframe_bps[FLAC__MAX_CHANNELS]; /* the effective bits per sample of the input signal (stream bps - wasted bits) */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
335 unsigned subframe_bps_mid_side[2]; /* the effective bits per sample of the mid-side input signal (stream bps - wasted bits + 0/1) */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
336 FLAC__int32 *residual_workspace[FLAC__MAX_CHANNELS][2]; /* each channel has a candidate and best workspace where the subframe residual signals will be stored */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
337 FLAC__int32 *residual_workspace_mid_side[2][2];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
338 FLAC__Subframe subframe_workspace[FLAC__MAX_CHANNELS][2];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
339 FLAC__Subframe subframe_workspace_mid_side[2][2];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
340 FLAC__Subframe *subframe_workspace_ptr[FLAC__MAX_CHANNELS][2];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
341 FLAC__Subframe *subframe_workspace_ptr_mid_side[2][2];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
342 FLAC__EntropyCodingMethod_PartitionedRiceContents partitioned_rice_contents_workspace[FLAC__MAX_CHANNELS][2];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
343 FLAC__EntropyCodingMethod_PartitionedRiceContents partitioned_rice_contents_workspace_mid_side[FLAC__MAX_CHANNELS][2];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
344 FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents_workspace_ptr[FLAC__MAX_CHANNELS][2];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
345 FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents_workspace_ptr_mid_side[FLAC__MAX_CHANNELS][2];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
346 unsigned best_subframe[FLAC__MAX_CHANNELS]; /* index (0 or 1) into 2nd dimension of the above workspaces */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
347 unsigned best_subframe_mid_side[2];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
348 unsigned best_subframe_bits[FLAC__MAX_CHANNELS]; /* size in bits of the best subframe for each channel */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
349 unsigned best_subframe_bits_mid_side[2];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
350 FLAC__uint64 *abs_residual_partition_sums; /* workspace where the sum of abs(candidate residual) for each partition is stored */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
351 unsigned *raw_bits_per_partition; /* workspace where the sum of silog2(candidate residual) for each partition is stored */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
352 FLAC__BitWriter *frame; /* the current frame being worked on */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
353 unsigned loose_mid_side_stereo_frames; /* rounded number of frames the encoder will use before trying both independent and mid/side frames again */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
354 unsigned loose_mid_side_stereo_frame_count; /* number of frames using the current channel assignment */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
355 FLAC__ChannelAssignment last_channel_assignment;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
356 FLAC__StreamMetadata streaminfo; /* scratchpad for STREAMINFO as it is built */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
357 FLAC__StreamMetadata_SeekTable *seek_table; /* pointer into encoder->protected_->metadata_ where the seek table is */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
358 unsigned current_sample_number;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
359 unsigned current_frame_number;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
360 struct FLAC__MD5Context md5context;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
361 FLAC__CPUInfo cpuinfo;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
362 #ifndef FLAC__INTEGER_ONLY_LIBRARY
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
363 unsigned (*local_fixed_compute_best_predictor)(const FLAC__int32 data[], unsigned data_len, FLAC__float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
364 #else
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
365 unsigned (*local_fixed_compute_best_predictor)(const FLAC__int32 data[], unsigned data_len, FLAC__fixedpoint residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
366 #endif
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
367 #ifndef FLAC__INTEGER_ONLY_LIBRARY
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
368 void (*local_lpc_compute_autocorrelation)(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
369 void (*local_lpc_compute_residual_from_qlp_coefficients)(const FLAC__int32 *data, unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 residual[]);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
370 void (*local_lpc_compute_residual_from_qlp_coefficients_64bit)(const FLAC__int32 *data, unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 residual[]);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
371 void (*local_lpc_compute_residual_from_qlp_coefficients_16bit)(const FLAC__int32 *data, unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 residual[]);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
372 #endif
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
373 FLAC__bool use_wide_by_block; /* use slow 64-bit versions of some functions because of the block size */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
374 FLAC__bool use_wide_by_partition; /* use slow 64-bit versions of some functions because of the min partition order and blocksize */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
375 FLAC__bool use_wide_by_order; /* use slow 64-bit versions of some functions because of the lpc order */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
376 FLAC__bool disable_constant_subframes;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
377 FLAC__bool disable_fixed_subframes;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
378 FLAC__bool disable_verbatim_subframes;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
379 #if FLAC__HAS_OGG
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
380 FLAC__bool is_ogg;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
381 #endif
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
382 FLAC__StreamEncoderReadCallback read_callback; /* currently only needed for Ogg FLAC */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
383 FLAC__StreamEncoderSeekCallback seek_callback;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
384 FLAC__StreamEncoderTellCallback tell_callback;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
385 FLAC__StreamEncoderWriteCallback write_callback;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
386 FLAC__StreamEncoderMetadataCallback metadata_callback;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
387 FLAC__StreamEncoderProgressCallback progress_callback;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
388 void *client_data;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
389 unsigned first_seekpoint_to_check;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
390 FILE *file; /* only used when encoding to a file */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
391 FLAC__uint64 bytes_written;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
392 FLAC__uint64 samples_written;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
393 unsigned frames_written;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
394 unsigned total_frames_estimate;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
395 /* unaligned (original) pointers to allocated data */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
396 FLAC__int32 *integer_signal_unaligned[FLAC__MAX_CHANNELS];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
397 FLAC__int32 *integer_signal_mid_side_unaligned[2];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
398 #ifndef FLAC__INTEGER_ONLY_LIBRARY
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
399 FLAC__real *real_signal_unaligned[FLAC__MAX_CHANNELS];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
400 FLAC__real *real_signal_mid_side_unaligned[2];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
401 FLAC__real *window_unaligned[FLAC__MAX_APODIZATION_FUNCTIONS];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
402 FLAC__real *windowed_signal_unaligned;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
403 #endif
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
404 FLAC__int32 *residual_workspace_unaligned[FLAC__MAX_CHANNELS][2];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
405 FLAC__int32 *residual_workspace_mid_side_unaligned[2][2];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
406 FLAC__uint64 *abs_residual_partition_sums_unaligned;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
407 unsigned *raw_bits_per_partition_unaligned;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
408 /*
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
409 * These fields have been moved here from private function local
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
410 * declarations merely to save stack space during encoding.
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
411 */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
412 #ifndef FLAC__INTEGER_ONLY_LIBRARY
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
413 FLAC__real lp_coeff[FLAC__MAX_LPC_ORDER][FLAC__MAX_LPC_ORDER]; /* from process_subframe_() */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
414 #endif
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
415 FLAC__EntropyCodingMethod_PartitionedRiceContents partitioned_rice_contents_extra[2]; /* from find_best_partition_order_() */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
416 /*
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
417 * The data for the verify section
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
418 */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
419 struct {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
420 FLAC__StreamDecoder *decoder;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
421 EncoderStateHint state_hint;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
422 FLAC__bool needs_magic_hack;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
423 verify_input_fifo input_fifo;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
424 verify_output output;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
425 struct {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
426 FLAC__uint64 absolute_sample;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
427 unsigned frame_number;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
428 unsigned channel;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
429 unsigned sample;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
430 FLAC__int32 expected;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
431 FLAC__int32 got;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
432 } error_stats;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
433 } verify;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
434 FLAC__bool is_being_deleted; /* if true, call to ..._finish() from ..._delete() will not call the callbacks */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
435 } FLAC__StreamEncoderPrivate;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
436
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
437 /***********************************************************************
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
438 *
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
439 * Public static class data
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
440 *
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
441 ***********************************************************************/
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
442
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
443 FLAC_API const char * const FLAC__StreamEncoderStateString[] = {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
444 "FLAC__STREAM_ENCODER_OK",
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
445 "FLAC__STREAM_ENCODER_UNINITIALIZED",
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
446 "FLAC__STREAM_ENCODER_OGG_ERROR",
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
447 "FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR",
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
448 "FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA",
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
449 "FLAC__STREAM_ENCODER_CLIENT_ERROR",
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
450 "FLAC__STREAM_ENCODER_IO_ERROR",
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
451 "FLAC__STREAM_ENCODER_FRAMING_ERROR",
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
452 "FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR"
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
453 };
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
454
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
455 FLAC_API const char * const FLAC__StreamEncoderInitStatusString[] = {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
456 "FLAC__STREAM_ENCODER_INIT_STATUS_OK",
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
457 "FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR",
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
458 "FLAC__STREAM_ENCODER_INIT_STATUS_UNSUPPORTED_CONTAINER",
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
459 "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_CALLBACKS",
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
460 "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_NUMBER_OF_CHANNELS",
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
461 "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BITS_PER_SAMPLE",
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
462 "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_SAMPLE_RATE",
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
463 "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BLOCK_SIZE",
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
464 "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_MAX_LPC_ORDER",
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
465 "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_QLP_COEFF_PRECISION",
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
466 "FLAC__STREAM_ENCODER_INIT_STATUS_BLOCK_SIZE_TOO_SMALL_FOR_LPC_ORDER",
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
467 "FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE",
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
468 "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA",
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
469 "FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED"
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
470 };
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
471
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
472 FLAC_API const char * const FLAC__treamEncoderReadStatusString[] = {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
473 "FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE",
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
474 "FLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM",
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
475 "FLAC__STREAM_ENCODER_READ_STATUS_ABORT",
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
476 "FLAC__STREAM_ENCODER_READ_STATUS_UNSUPPORTED"
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
477 };
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
478
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
479 FLAC_API const char * const FLAC__StreamEncoderWriteStatusString[] = {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
480 "FLAC__STREAM_ENCODER_WRITE_STATUS_OK",
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
481 "FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR"
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
482 };
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
483
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
484 FLAC_API const char * const FLAC__StreamEncoderSeekStatusString[] = {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
485 "FLAC__STREAM_ENCODER_SEEK_STATUS_OK",
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
486 "FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR",
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
487 "FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED"
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
488 };
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
489
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
490 FLAC_API const char * const FLAC__StreamEncoderTellStatusString[] = {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
491 "FLAC__STREAM_ENCODER_TELL_STATUS_OK",
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
492 "FLAC__STREAM_ENCODER_TELL_STATUS_ERROR",
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
493 "FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED"
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
494 };
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
495
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
496 /* Number of samples that will be overread to watch for end of stream. By
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
497 * 'overread', we mean that the FLAC__stream_encoder_process*() calls will
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
498 * always try to read blocksize+1 samples before encoding a block, so that
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
499 * even if the stream has a total sample count that is an integral multiple
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
500 * of the blocksize, we will still notice when we are encoding the last
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
501 * block. This is needed, for example, to correctly set the end-of-stream
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
502 * marker in Ogg FLAC.
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
503 *
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
504 * WATCHOUT: some parts of the code assert that OVERREAD_ == 1 and there's
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
505 * not really any reason to change it.
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
506 */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
507 static const unsigned OVERREAD_ = 1;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
508
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
509 /***********************************************************************
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
510 *
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
511 * Class constructor/destructor
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
512 *
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
513 */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
514 FLAC_API FLAC__StreamEncoder *FLAC__stream_encoder_new(void)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
515 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
516 FLAC__StreamEncoder *encoder;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
517 unsigned i;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
518
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
519 FLAC__ASSERT(sizeof(int) >= 4); /* we want to die right away if this is not true */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
520
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
521 encoder = (FLAC__StreamEncoder*)calloc(1, sizeof(FLAC__StreamEncoder));
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
522 if(encoder == 0) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
523 return 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
524 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
525
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
526 encoder->protected_ = (FLAC__StreamEncoderProtected*)calloc(1, sizeof(FLAC__StreamEncoderProtected));
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
527 if(encoder->protected_ == 0) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
528 free(encoder);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
529 return 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
530 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
531
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
532 encoder->private_ = (FLAC__StreamEncoderPrivate*)calloc(1, sizeof(FLAC__StreamEncoderPrivate));
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
533 if(encoder->private_ == 0) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
534 free(encoder->protected_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
535 free(encoder);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
536 return 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
537 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
538
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
539 encoder->private_->frame = FLAC__bitwriter_new();
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
540 if(encoder->private_->frame == 0) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
541 free(encoder->private_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
542 free(encoder->protected_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
543 free(encoder);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
544 return 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
545 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
546
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
547 encoder->private_->file = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
548
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
549 set_defaults_(encoder);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
550
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
551 encoder->private_->is_being_deleted = false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
552
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
553 for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
554 encoder->private_->subframe_workspace_ptr[i][0] = &encoder->private_->subframe_workspace[i][0];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
555 encoder->private_->subframe_workspace_ptr[i][1] = &encoder->private_->subframe_workspace[i][1];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
556 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
557 for(i = 0; i < 2; i++) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
558 encoder->private_->subframe_workspace_ptr_mid_side[i][0] = &encoder->private_->subframe_workspace_mid_side[i][0];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
559 encoder->private_->subframe_workspace_ptr_mid_side[i][1] = &encoder->private_->subframe_workspace_mid_side[i][1];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
560 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
561 for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
562 encoder->private_->partitioned_rice_contents_workspace_ptr[i][0] = &encoder->private_->partitioned_rice_contents_workspace[i][0];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
563 encoder->private_->partitioned_rice_contents_workspace_ptr[i][1] = &encoder->private_->partitioned_rice_contents_workspace[i][1];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
564 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
565 for(i = 0; i < 2; i++) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
566 encoder->private_->partitioned_rice_contents_workspace_ptr_mid_side[i][0] = &encoder->private_->partitioned_rice_contents_workspace_mid_side[i][0];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
567 encoder->private_->partitioned_rice_contents_workspace_ptr_mid_side[i][1] = &encoder->private_->partitioned_rice_contents_workspace_mid_side[i][1];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
568 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
569
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
570 for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
571 FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_workspace[i][0]);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
572 FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_workspace[i][1]);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
573 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
574 for(i = 0; i < 2; i++) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
575 FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_workspace_mid_side[i][0]);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
576 FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_workspace_mid_side[i][1]);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
577 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
578 for(i = 0; i < 2; i++)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
579 FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_extra[i]);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
580
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
581 encoder->protected_->state = FLAC__STREAM_ENCODER_UNINITIALIZED;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
582
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
583 return encoder;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
584 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
585
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
586 FLAC_API void FLAC__stream_encoder_delete(FLAC__StreamEncoder *encoder)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
587 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
588 unsigned i;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
589
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
590 FLAC__ASSERT(0 != encoder);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
591 FLAC__ASSERT(0 != encoder->protected_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
592 FLAC__ASSERT(0 != encoder->private_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
593 FLAC__ASSERT(0 != encoder->private_->frame);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
594
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
595 encoder->private_->is_being_deleted = true;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
596
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
597 (void)FLAC__stream_encoder_finish(encoder);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
598
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
599 if(0 != encoder->private_->verify.decoder)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
600 FLAC__stream_decoder_delete(encoder->private_->verify.decoder);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
601
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
602 for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
603 FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_workspace[i][0]);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
604 FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_workspace[i][1]);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
605 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
606 for(i = 0; i < 2; i++) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
607 FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_workspace_mid_side[i][0]);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
608 FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_workspace_mid_side[i][1]);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
609 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
610 for(i = 0; i < 2; i++)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
611 FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_extra[i]);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
612
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
613 FLAC__bitwriter_delete(encoder->private_->frame);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
614 free(encoder->private_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
615 free(encoder->protected_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
616 free(encoder);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
617 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
618
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
619 /***********************************************************************
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
620 *
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
621 * Public class methods
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
622 *
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
623 ***********************************************************************/
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
624
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
625 static FLAC__StreamEncoderInitStatus init_stream_internal_(
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
626 FLAC__StreamEncoder *encoder,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
627 FLAC__StreamEncoderReadCallback read_callback,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
628 FLAC__StreamEncoderWriteCallback write_callback,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
629 FLAC__StreamEncoderSeekCallback seek_callback,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
630 FLAC__StreamEncoderTellCallback tell_callback,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
631 FLAC__StreamEncoderMetadataCallback metadata_callback,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
632 void *client_data,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
633 FLAC__bool is_ogg
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
634 )
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
635 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
636 unsigned i;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
637 FLAC__bool metadata_has_seektable, metadata_has_vorbis_comment, metadata_picture_has_type1, metadata_picture_has_type2;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
638
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
639 FLAC__ASSERT(0 != encoder);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
640
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
641 if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
642 return FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
643
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
644 #if !FLAC__HAS_OGG
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
645 if(is_ogg)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
646 return FLAC__STREAM_ENCODER_INIT_STATUS_UNSUPPORTED_CONTAINER;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
647 #endif
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
648
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
649 if(0 == write_callback || (seek_callback && 0 == tell_callback))
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
650 return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_CALLBACKS;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
651
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
652 if(encoder->protected_->channels == 0 || encoder->protected_->channels > FLAC__MAX_CHANNELS)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
653 return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_NUMBER_OF_CHANNELS;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
654
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
655 if(encoder->protected_->channels != 2) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
656 encoder->protected_->do_mid_side_stereo = false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
657 encoder->protected_->loose_mid_side_stereo = false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
658 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
659 else if(!encoder->protected_->do_mid_side_stereo)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
660 encoder->protected_->loose_mid_side_stereo = false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
661
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
662 if(encoder->protected_->bits_per_sample >= 32)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
663 encoder->protected_->do_mid_side_stereo = false; /* since we currenty do 32-bit math, the side channel would have 33 bps and overflow */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
664
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
665 if(encoder->protected_->bits_per_sample < FLAC__MIN_BITS_PER_SAMPLE || encoder->protected_->bits_per_sample > FLAC__REFERENCE_CODEC_MAX_BITS_PER_SAMPLE)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
666 return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BITS_PER_SAMPLE;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
667
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
668 if(!FLAC__format_sample_rate_is_valid(encoder->protected_->sample_rate))
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
669 return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_SAMPLE_RATE;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
670
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
671 if(encoder->protected_->blocksize == 0) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
672 if(encoder->protected_->max_lpc_order == 0)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
673 encoder->protected_->blocksize = 1152;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
674 else
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
675 encoder->protected_->blocksize = 4096;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
676 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
677
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
678 if(encoder->protected_->blocksize < FLAC__MIN_BLOCK_SIZE || encoder->protected_->blocksize > FLAC__MAX_BLOCK_SIZE)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
679 return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BLOCK_SIZE;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
680
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
681 if(encoder->protected_->max_lpc_order > FLAC__MAX_LPC_ORDER)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
682 return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_MAX_LPC_ORDER;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
683
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
684 if(encoder->protected_->blocksize < encoder->protected_->max_lpc_order)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
685 return FLAC__STREAM_ENCODER_INIT_STATUS_BLOCK_SIZE_TOO_SMALL_FOR_LPC_ORDER;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
686
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
687 if(encoder->protected_->qlp_coeff_precision == 0) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
688 if(encoder->protected_->bits_per_sample < 16) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
689 /* @@@ need some data about how to set this here w.r.t. blocksize and sample rate */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
690 /* @@@ until then we'll make a guess */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
691 encoder->protected_->qlp_coeff_precision = max(FLAC__MIN_QLP_COEFF_PRECISION, 2 + encoder->protected_->bits_per_sample / 2);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
692 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
693 else if(encoder->protected_->bits_per_sample == 16) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
694 if(encoder->protected_->blocksize <= 192)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
695 encoder->protected_->qlp_coeff_precision = 7;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
696 else if(encoder->protected_->blocksize <= 384)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
697 encoder->protected_->qlp_coeff_precision = 8;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
698 else if(encoder->protected_->blocksize <= 576)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
699 encoder->protected_->qlp_coeff_precision = 9;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
700 else if(encoder->protected_->blocksize <= 1152)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
701 encoder->protected_->qlp_coeff_precision = 10;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
702 else if(encoder->protected_->blocksize <= 2304)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
703 encoder->protected_->qlp_coeff_precision = 11;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
704 else if(encoder->protected_->blocksize <= 4608)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
705 encoder->protected_->qlp_coeff_precision = 12;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
706 else
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
707 encoder->protected_->qlp_coeff_precision = 13;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
708 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
709 else {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
710 if(encoder->protected_->blocksize <= 384)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
711 encoder->protected_->qlp_coeff_precision = FLAC__MAX_QLP_COEFF_PRECISION-2;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
712 else if(encoder->protected_->blocksize <= 1152)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
713 encoder->protected_->qlp_coeff_precision = FLAC__MAX_QLP_COEFF_PRECISION-1;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
714 else
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
715 encoder->protected_->qlp_coeff_precision = FLAC__MAX_QLP_COEFF_PRECISION;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
716 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
717 FLAC__ASSERT(encoder->protected_->qlp_coeff_precision <= FLAC__MAX_QLP_COEFF_PRECISION);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
718 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
719 else if(encoder->protected_->qlp_coeff_precision < FLAC__MIN_QLP_COEFF_PRECISION || encoder->protected_->qlp_coeff_precision > FLAC__MAX_QLP_COEFF_PRECISION)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
720 return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_QLP_COEFF_PRECISION;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
721
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
722 if(encoder->protected_->streamable_subset) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
723 if(
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
724 encoder->protected_->blocksize != 192 &&
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
725 encoder->protected_->blocksize != 576 &&
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
726 encoder->protected_->blocksize != 1152 &&
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
727 encoder->protected_->blocksize != 2304 &&
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
728 encoder->protected_->blocksize != 4608 &&
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
729 encoder->protected_->blocksize != 256 &&
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
730 encoder->protected_->blocksize != 512 &&
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
731 encoder->protected_->blocksize != 1024 &&
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
732 encoder->protected_->blocksize != 2048 &&
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
733 encoder->protected_->blocksize != 4096 &&
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
734 encoder->protected_->blocksize != 8192 &&
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
735 encoder->protected_->blocksize != 16384
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
736 )
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
737 return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
738 if(
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
739 encoder->protected_->sample_rate != 8000 &&
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
740 encoder->protected_->sample_rate != 16000 &&
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
741 encoder->protected_->sample_rate != 22050 &&
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
742 encoder->protected_->sample_rate != 24000 &&
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
743 encoder->protected_->sample_rate != 32000 &&
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
744 encoder->protected_->sample_rate != 44100 &&
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
745 encoder->protected_->sample_rate != 48000 &&
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
746 encoder->protected_->sample_rate != 96000
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
747 )
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
748 return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
749 if(
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
750 encoder->protected_->bits_per_sample != 8 &&
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
751 encoder->protected_->bits_per_sample != 12 &&
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
752 encoder->protected_->bits_per_sample != 16 &&
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
753 encoder->protected_->bits_per_sample != 20 &&
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
754 encoder->protected_->bits_per_sample != 24
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
755 )
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
756 return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
757 if(encoder->protected_->max_residual_partition_order > FLAC__SUBSET_MAX_RICE_PARTITION_ORDER)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
758 return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
759 if(
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
760 encoder->protected_->sample_rate <= 48000 &&
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
761 (
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
762 encoder->protected_->blocksize > FLAC__SUBSET_MAX_BLOCK_SIZE_48000HZ ||
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
763 encoder->protected_->max_lpc_order > FLAC__SUBSET_MAX_LPC_ORDER_48000HZ
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
764 )
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
765 ) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
766 return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
767 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
768 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
769
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
770 if(encoder->protected_->max_residual_partition_order >= (1u << FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN))
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
771 encoder->protected_->max_residual_partition_order = (1u << FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN) - 1;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
772 if(encoder->protected_->min_residual_partition_order >= encoder->protected_->max_residual_partition_order)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
773 encoder->protected_->min_residual_partition_order = encoder->protected_->max_residual_partition_order;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
774
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
775 #if FLAC__HAS_OGG
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
776 /* reorder metadata if necessary to ensure that any VORBIS_COMMENT is the first, according to the mapping spec */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
777 if(is_ogg && 0 != encoder->protected_->metadata && encoder->protected_->num_metadata_blocks > 1) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
778 unsigned i;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
779 for(i = 1; i < encoder->protected_->num_metadata_blocks; i++) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
780 if(0 != encoder->protected_->metadata[i] && encoder->protected_->metadata[i]->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
781 FLAC__StreamMetadata *vc = encoder->protected_->metadata[i];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
782 for( ; i > 0; i--)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
783 encoder->protected_->metadata[i] = encoder->protected_->metadata[i-1];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
784 encoder->protected_->metadata[0] = vc;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
785 break;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
786 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
787 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
788 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
789 #endif
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
790 /* keep track of any SEEKTABLE block */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
791 if(0 != encoder->protected_->metadata && encoder->protected_->num_metadata_blocks > 0) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
792 unsigned i;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
793 for(i = 0; i < encoder->protected_->num_metadata_blocks; i++) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
794 if(0 != encoder->protected_->metadata[i] && encoder->protected_->metadata[i]->type == FLAC__METADATA_TYPE_SEEKTABLE) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
795 encoder->private_->seek_table = &encoder->protected_->metadata[i]->data.seek_table;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
796 break; /* take only the first one */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
797 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
798 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
799 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
800
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
801 /* validate metadata */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
802 if(0 == encoder->protected_->metadata && encoder->protected_->num_metadata_blocks > 0)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
803 return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
804 metadata_has_seektable = false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
805 metadata_has_vorbis_comment = false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
806 metadata_picture_has_type1 = false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
807 metadata_picture_has_type2 = false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
808 for(i = 0; i < encoder->protected_->num_metadata_blocks; i++) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
809 const FLAC__StreamMetadata *m = encoder->protected_->metadata[i];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
810 if(m->type == FLAC__METADATA_TYPE_STREAMINFO)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
811 return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
812 else if(m->type == FLAC__METADATA_TYPE_SEEKTABLE) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
813 if(metadata_has_seektable) /* only one is allowed */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
814 return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
815 metadata_has_seektable = true;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
816 if(!FLAC__format_seektable_is_legal(&m->data.seek_table))
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
817 return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
818 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
819 else if(m->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
820 if(metadata_has_vorbis_comment) /* only one is allowed */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
821 return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
822 metadata_has_vorbis_comment = true;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
823 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
824 else if(m->type == FLAC__METADATA_TYPE_CUESHEET) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
825 if(!FLAC__format_cuesheet_is_legal(&m->data.cue_sheet, m->data.cue_sheet.is_cd, /*violation=*/0))
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
826 return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
827 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
828 else if(m->type == FLAC__METADATA_TYPE_PICTURE) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
829 if(!FLAC__format_picture_is_legal(&m->data.picture, /*violation=*/0))
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
830 return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
831 if(m->data.picture.type == FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON_STANDARD) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
832 if(metadata_picture_has_type1) /* there should only be 1 per stream */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
833 return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
834 metadata_picture_has_type1 = true;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
835 /* standard icon must be 32x32 pixel PNG */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
836 if(
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
837 m->data.picture.type == FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON_STANDARD &&
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
838 (
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
839 (strcmp(m->data.picture.mime_type, "image/png") && strcmp(m->data.picture.mime_type, "-->")) ||
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
840 m->data.picture.width != 32 ||
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
841 m->data.picture.height != 32
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
842 )
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
843 )
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
844 return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
845 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
846 else if(m->data.picture.type == FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
847 if(metadata_picture_has_type2) /* there should only be 1 per stream */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
848 return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
849 metadata_picture_has_type2 = true;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
850 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
851 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
852 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
853
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
854 encoder->private_->input_capacity = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
855 for(i = 0; i < encoder->protected_->channels; i++) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
856 encoder->private_->integer_signal_unaligned[i] = encoder->private_->integer_signal[i] = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
857 #ifndef FLAC__INTEGER_ONLY_LIBRARY
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
858 encoder->private_->real_signal_unaligned[i] = encoder->private_->real_signal[i] = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
859 #endif
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
860 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
861 for(i = 0; i < 2; i++) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
862 encoder->private_->integer_signal_mid_side_unaligned[i] = encoder->private_->integer_signal_mid_side[i] = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
863 #ifndef FLAC__INTEGER_ONLY_LIBRARY
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
864 encoder->private_->real_signal_mid_side_unaligned[i] = encoder->private_->real_signal_mid_side[i] = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
865 #endif
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
866 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
867 #ifndef FLAC__INTEGER_ONLY_LIBRARY
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
868 for(i = 0; i < encoder->protected_->num_apodizations; i++)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
869 encoder->private_->window_unaligned[i] = encoder->private_->window[i] = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
870 encoder->private_->windowed_signal_unaligned = encoder->private_->windowed_signal = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
871 #endif
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
872 for(i = 0; i < encoder->protected_->channels; i++) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
873 encoder->private_->residual_workspace_unaligned[i][0] = encoder->private_->residual_workspace[i][0] = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
874 encoder->private_->residual_workspace_unaligned[i][1] = encoder->private_->residual_workspace[i][1] = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
875 encoder->private_->best_subframe[i] = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
876 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
877 for(i = 0; i < 2; i++) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
878 encoder->private_->residual_workspace_mid_side_unaligned[i][0] = encoder->private_->residual_workspace_mid_side[i][0] = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
879 encoder->private_->residual_workspace_mid_side_unaligned[i][1] = encoder->private_->residual_workspace_mid_side[i][1] = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
880 encoder->private_->best_subframe_mid_side[i] = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
881 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
882 encoder->private_->abs_residual_partition_sums_unaligned = encoder->private_->abs_residual_partition_sums = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
883 encoder->private_->raw_bits_per_partition_unaligned = encoder->private_->raw_bits_per_partition = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
884 #ifndef FLAC__INTEGER_ONLY_LIBRARY
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
885 encoder->private_->loose_mid_side_stereo_frames = (unsigned)((FLAC__double)encoder->protected_->sample_rate * 0.4 / (FLAC__double)encoder->protected_->blocksize + 0.5);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
886 #else
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
887 /* 26214 is the approximate fixed-point equivalent to 0.4 (0.4 * 2^16) */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
888 /* sample rate can be up to 655350 Hz, and thus use 20 bits, so we do the multiply&divide by hand */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
889 FLAC__ASSERT(FLAC__MAX_SAMPLE_RATE <= 655350);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
890 FLAC__ASSERT(FLAC__MAX_BLOCK_SIZE <= 65535);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
891 FLAC__ASSERT(encoder->protected_->sample_rate <= 655350);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
892 FLAC__ASSERT(encoder->protected_->blocksize <= 65535);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
893 encoder->private_->loose_mid_side_stereo_frames = (unsigned)FLAC__fixedpoint_trunc((((FLAC__uint64)(encoder->protected_->sample_rate) * (FLAC__uint64)(26214)) << 16) / (encoder->protected_->blocksize<<16) + FLAC__FP_ONE_HALF);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
894 #endif
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
895 if(encoder->private_->loose_mid_side_stereo_frames == 0)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
896 encoder->private_->loose_mid_side_stereo_frames = 1;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
897 encoder->private_->loose_mid_side_stereo_frame_count = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
898 encoder->private_->current_sample_number = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
899 encoder->private_->current_frame_number = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
900
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
901 encoder->private_->use_wide_by_block = (encoder->protected_->bits_per_sample + FLAC__bitmath_ilog2(encoder->protected_->blocksize)+1 > 30);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
902 encoder->private_->use_wide_by_order = (encoder->protected_->bits_per_sample + FLAC__bitmath_ilog2(max(encoder->protected_->max_lpc_order, FLAC__MAX_FIXED_ORDER))+1 > 30); /*@@@ need to use this? */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
903 encoder->private_->use_wide_by_partition = (false); /*@@@ need to set this */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
904
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
905 /*
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
906 * get the CPU info and set the function pointers
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
907 */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
908 FLAC__cpu_info(&encoder->private_->cpuinfo);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
909 /* first default to the non-asm routines */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
910 #ifndef FLAC__INTEGER_ONLY_LIBRARY
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
911 encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
912 #endif
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
913 encoder->private_->local_fixed_compute_best_predictor = FLAC__fixed_compute_best_predictor;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
914 #ifndef FLAC__INTEGER_ONLY_LIBRARY
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
915 encoder->private_->local_lpc_compute_residual_from_qlp_coefficients = FLAC__lpc_compute_residual_from_qlp_coefficients;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
916 encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_64bit = FLAC__lpc_compute_residual_from_qlp_coefficients_wide;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
917 encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bit = FLAC__lpc_compute_residual_from_qlp_coefficients;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
918 #endif
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
919 /* now override with asm where appropriate */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
920 #ifndef FLAC__INTEGER_ONLY_LIBRARY
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
921 # ifndef FLAC__NO_ASM
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
922 if(encoder->private_->cpuinfo.use_asm) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
923 # ifdef FLAC__CPU_IA32
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
924 FLAC__ASSERT(encoder->private_->cpuinfo.type == FLAC__CPUINFO_TYPE_IA32);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
925 # ifdef FLAC__HAS_NASM
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
926 # ifdef FLAC__SSE_OS
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
927 if(encoder->private_->cpuinfo.data.ia32.sse) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
928 if(encoder->protected_->max_lpc_order < 4)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
929 encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_4;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
930 else if(encoder->protected_->max_lpc_order < 8)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
931 encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_8;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
932 else if(encoder->protected_->max_lpc_order < 12)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
933 encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_12;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
934 else
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
935 encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
936 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
937 else
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
938 # endif /* FLAC__SSE_OS */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
939 if(encoder->private_->cpuinfo.data.ia32._3dnow)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
940 encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32_3dnow;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
941 else
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
942 encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
943 if(encoder->private_->cpuinfo.data.ia32.mmx) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
944 encoder->private_->local_lpc_compute_residual_from_qlp_coefficients = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
945 encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bit = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32_mmx;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
946 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
947 else {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
948 encoder->private_->local_lpc_compute_residual_from_qlp_coefficients = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
949 encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bit = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
950 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
951 if(encoder->private_->cpuinfo.data.ia32.mmx && encoder->private_->cpuinfo.data.ia32.cmov)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
952 encoder->private_->local_fixed_compute_best_predictor = FLAC__fixed_compute_best_predictor_asm_ia32_mmx_cmov;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
953 # endif /* FLAC__HAS_NASM */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
954 # endif /* FLAC__CPU_IA32 */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
955 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
956 # endif /* !FLAC__NO_ASM */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
957 #endif /* !FLAC__INTEGER_ONLY_LIBRARY */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
958 /* finally override based on wide-ness if necessary */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
959 if(encoder->private_->use_wide_by_block) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
960 encoder->private_->local_fixed_compute_best_predictor = FLAC__fixed_compute_best_predictor_wide;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
961 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
962
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
963 /* set state to OK; from here on, errors are fatal and we'll override the state then */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
964 encoder->protected_->state = FLAC__STREAM_ENCODER_OK;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
965
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
966 #if FLAC__HAS_OGG
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
967 encoder->private_->is_ogg = is_ogg;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
968 if(is_ogg && !FLAC__ogg_encoder_aspect_init(&encoder->protected_->ogg_encoder_aspect)) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
969 encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
970 return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
971 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
972 #endif
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
973
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
974 encoder->private_->read_callback = read_callback;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
975 encoder->private_->write_callback = write_callback;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
976 encoder->private_->seek_callback = seek_callback;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
977 encoder->private_->tell_callback = tell_callback;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
978 encoder->private_->metadata_callback = metadata_callback;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
979 encoder->private_->client_data = client_data;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
980
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
981 if(!resize_buffers_(encoder, encoder->protected_->blocksize)) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
982 /* the above function sets the state for us in case of an error */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
983 return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
984 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
985
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
986 if(!FLAC__bitwriter_init(encoder->private_->frame)) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
987 encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
988 return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
989 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
990
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
991 /*
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
992 * Set up the verify stuff if necessary
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
993 */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
994 if(encoder->protected_->verify) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
995 /*
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
996 * First, set up the fifo which will hold the
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
997 * original signal to compare against
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
998 */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
999 encoder->private_->verify.input_fifo.size = encoder->protected_->blocksize+OVERREAD_;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1000 for(i = 0; i < encoder->protected_->channels; i++) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1001 if(0 == (encoder->private_->verify.input_fifo.data[i] = (FLAC__int32*)malloc(sizeof(FLAC__int32) * encoder->private_->verify.input_fifo.size))) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1002 encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1003 return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1004 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1005 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1006 encoder->private_->verify.input_fifo.tail = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1007
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1008 /*
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1009 * Now set up a stream decoder for verification
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1010 */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1011 encoder->private_->verify.decoder = FLAC__stream_decoder_new();
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1012 if(0 == encoder->private_->verify.decoder) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1013 encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1014 return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1015 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1016
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1017 if(FLAC__stream_decoder_init_stream(encoder->private_->verify.decoder, verify_read_callback_, /*seek_callback=*/0, /*tell_callback=*/0, /*length_callback=*/0, /*eof_callback=*/0, verify_write_callback_, verify_metadata_callback_, verify_error_callback_, /*client_data=*/encoder) != FLAC__STREAM_DECODER_INIT_STATUS_OK) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1018 encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1019 return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1020 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1021 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1022 encoder->private_->verify.error_stats.absolute_sample = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1023 encoder->private_->verify.error_stats.frame_number = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1024 encoder->private_->verify.error_stats.channel = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1025 encoder->private_->verify.error_stats.sample = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1026 encoder->private_->verify.error_stats.expected = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1027 encoder->private_->verify.error_stats.got = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1028
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1029 /*
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1030 * These must be done before we write any metadata, because that
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1031 * calls the write_callback, which uses these values.
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1032 */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1033 encoder->private_->first_seekpoint_to_check = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1034 encoder->private_->samples_written = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1035 encoder->protected_->streaminfo_offset = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1036 encoder->protected_->seektable_offset = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1037 encoder->protected_->audio_offset = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1038
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1039 /*
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1040 * write the stream header
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1041 */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1042 if(encoder->protected_->verify)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1043 encoder->private_->verify.state_hint = ENCODER_IN_MAGIC;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1044 if(!FLAC__bitwriter_write_raw_uint32(encoder->private_->frame, FLAC__STREAM_SYNC, FLAC__STREAM_SYNC_LEN)) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1045 encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1046 return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1047 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1048 if(!write_bitbuffer_(encoder, 0, /*is_last_block=*/false)) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1049 /* the above function sets the state for us in case of an error */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1050 return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1051 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1052
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1053 /*
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1054 * write the STREAMINFO metadata block
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1055 */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1056 if(encoder->protected_->verify)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1057 encoder->private_->verify.state_hint = ENCODER_IN_METADATA;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1058 encoder->private_->streaminfo.type = FLAC__METADATA_TYPE_STREAMINFO;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1059 encoder->private_->streaminfo.is_last = false; /* we will have at a minimum a VORBIS_COMMENT afterwards */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1060 encoder->private_->streaminfo.length = FLAC__STREAM_METADATA_STREAMINFO_LENGTH;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1061 encoder->private_->streaminfo.data.stream_info.min_blocksize = encoder->protected_->blocksize; /* this encoder uses the same blocksize for the whole stream */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1062 encoder->private_->streaminfo.data.stream_info.max_blocksize = encoder->protected_->blocksize;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1063 encoder->private_->streaminfo.data.stream_info.min_framesize = 0; /* we don't know this yet; have to fill it in later */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1064 encoder->private_->streaminfo.data.stream_info.max_framesize = 0; /* we don't know this yet; have to fill it in later */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1065 encoder->private_->streaminfo.data.stream_info.sample_rate = encoder->protected_->sample_rate;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1066 encoder->private_->streaminfo.data.stream_info.channels = encoder->protected_->channels;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1067 encoder->private_->streaminfo.data.stream_info.bits_per_sample = encoder->protected_->bits_per_sample;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1068 encoder->private_->streaminfo.data.stream_info.total_samples = encoder->protected_->total_samples_estimate; /* we will replace this later with the real total */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1069 memset(encoder->private_->streaminfo.data.stream_info.md5sum, 0, 16); /* we don't know this yet; have to fill it in later */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1070 FLAC__MD5Init(&encoder->private_->md5context);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1071 if(!FLAC__add_metadata_block(&encoder->private_->streaminfo, encoder->private_->frame)) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1072 encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1073 return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1074 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1075 if(!write_bitbuffer_(encoder, 0, /*is_last_block=*/false)) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1076 /* the above function sets the state for us in case of an error */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1077 return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1078 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1079
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1080 /*
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1081 * Now that the STREAMINFO block is written, we can init this to an
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1082 * absurdly-high value...
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1083 */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1084 encoder->private_->streaminfo.data.stream_info.min_framesize = (1u << FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN) - 1;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1085 /* ... and clear this to 0 */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1086 encoder->private_->streaminfo.data.stream_info.total_samples = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1087
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1088 /*
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1089 * Check to see if the supplied metadata contains a VORBIS_COMMENT;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1090 * if not, we will write an empty one (FLAC__add_metadata_block()
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1091 * automatically supplies the vendor string).
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1092 *
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1093 * WATCHOUT: the Ogg FLAC mapping requires us to write this block after
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1094 * the STREAMINFO. (In the case that metadata_has_vorbis_comment is
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1095 * true it will have already insured that the metadata list is properly
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1096 * ordered.)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1097 */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1098 if(!metadata_has_vorbis_comment) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1099 FLAC__StreamMetadata vorbis_comment;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1100 vorbis_comment.type = FLAC__METADATA_TYPE_VORBIS_COMMENT;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1101 vorbis_comment.is_last = (encoder->protected_->num_metadata_blocks == 0);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1102 vorbis_comment.length = 4 + 4; /* MAGIC NUMBER */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1103 vorbis_comment.data.vorbis_comment.vendor_string.length = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1104 vorbis_comment.data.vorbis_comment.vendor_string.entry = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1105 vorbis_comment.data.vorbis_comment.num_comments = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1106 vorbis_comment.data.vorbis_comment.comments = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1107 if(!FLAC__add_metadata_block(&vorbis_comment, encoder->private_->frame)) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1108 encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1109 return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1110 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1111 if(!write_bitbuffer_(encoder, 0, /*is_last_block=*/false)) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1112 /* the above function sets the state for us in case of an error */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1113 return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1114 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1115 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1116
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1117 /*
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1118 * write the user's metadata blocks
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1119 */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1120 for(i = 0; i < encoder->protected_->num_metadata_blocks; i++) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1121 encoder->protected_->metadata[i]->is_last = (i == encoder->protected_->num_metadata_blocks - 1);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1122 if(!FLAC__add_metadata_block(encoder->protected_->metadata[i], encoder->private_->frame)) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1123 encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1124 return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1125 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1126 if(!write_bitbuffer_(encoder, 0, /*is_last_block=*/false)) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1127 /* the above function sets the state for us in case of an error */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1128 return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1129 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1130 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1131
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1132 /* now that all the metadata is written, we save the stream offset */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1133 if(encoder->private_->tell_callback && encoder->private_->tell_callback(encoder, &encoder->protected_->audio_offset, encoder->private_->client_data) == FLAC__STREAM_ENCODER_TELL_STATUS_ERROR) { /* FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED just means we didn't get the offset; no error */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1134 encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1135 return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1136 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1137
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1138 if(encoder->protected_->verify)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1139 encoder->private_->verify.state_hint = ENCODER_IN_AUDIO;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1140
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1141 return FLAC__STREAM_ENCODER_INIT_STATUS_OK;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1142 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1143
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1144 FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_stream(
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1145 FLAC__StreamEncoder *encoder,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1146 FLAC__StreamEncoderWriteCallback write_callback,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1147 FLAC__StreamEncoderSeekCallback seek_callback,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1148 FLAC__StreamEncoderTellCallback tell_callback,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1149 FLAC__StreamEncoderMetadataCallback metadata_callback,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1150 void *client_data
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1151 )
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1152 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1153 return init_stream_internal_(
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1154 encoder,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1155 /*read_callback=*/0,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1156 write_callback,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1157 seek_callback,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1158 tell_callback,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1159 metadata_callback,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1160 client_data,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1161 /*is_ogg=*/false
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1162 );
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1163 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1164
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1165 FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_stream(
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1166 FLAC__StreamEncoder *encoder,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1167 FLAC__StreamEncoderReadCallback read_callback,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1168 FLAC__StreamEncoderWriteCallback write_callback,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1169 FLAC__StreamEncoderSeekCallback seek_callback,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1170 FLAC__StreamEncoderTellCallback tell_callback,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1171 FLAC__StreamEncoderMetadataCallback metadata_callback,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1172 void *client_data
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1173 )
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1174 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1175 return init_stream_internal_(
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1176 encoder,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1177 read_callback,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1178 write_callback,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1179 seek_callback,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1180 tell_callback,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1181 metadata_callback,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1182 client_data,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1183 /*is_ogg=*/true
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1184 );
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1185 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1186
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1187 static FLAC__StreamEncoderInitStatus init_FILE_internal_(
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1188 FLAC__StreamEncoder *encoder,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1189 FILE *file,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1190 FLAC__StreamEncoderProgressCallback progress_callback,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1191 void *client_data,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1192 FLAC__bool is_ogg
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1193 )
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1194 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1195 FLAC__StreamEncoderInitStatus init_status;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1196
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1197 FLAC__ASSERT(0 != encoder);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1198 FLAC__ASSERT(0 != file);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1199
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1200 if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1201 return FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1202
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1203 /* double protection */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1204 if(file == 0) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1205 encoder->protected_->state = FLAC__STREAM_ENCODER_IO_ERROR;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1206 return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1207 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1208
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1209 /*
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1210 * To make sure that our file does not go unclosed after an error, we
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1211 * must assign the FILE pointer before any further error can occur in
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1212 * this routine.
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1213 */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1214 if(file == stdout)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1215 file = get_binary_stdout_(); /* just to be safe */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1216
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1217 encoder->private_->file = file;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1218
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1219 encoder->private_->progress_callback = progress_callback;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1220 encoder->private_->bytes_written = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1221 encoder->private_->samples_written = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1222 encoder->private_->frames_written = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1223
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1224 init_status = init_stream_internal_(
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1225 encoder,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1226 encoder->private_->file == stdout? 0 : is_ogg? file_read_callback_ : 0,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1227 file_write_callback_,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1228 encoder->private_->file == stdout? 0 : file_seek_callback_,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1229 encoder->private_->file == stdout? 0 : file_tell_callback_,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1230 /*metadata_callback=*/0,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1231 client_data,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1232 is_ogg
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1233 );
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1234 if(init_status != FLAC__STREAM_ENCODER_INIT_STATUS_OK) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1235 /* the above function sets the state for us in case of an error */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1236 return init_status;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1237 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1238
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1239 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1240 unsigned blocksize = FLAC__stream_encoder_get_blocksize(encoder);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1241
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1242 FLAC__ASSERT(blocksize != 0);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1243 encoder->private_->total_frames_estimate = (unsigned)((FLAC__stream_encoder_get_total_samples_estimate(encoder) + blocksize - 1) / blocksize);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1244 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1245
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1246 return init_status;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1247 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1248
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1249 FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_FILE(
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1250 FLAC__StreamEncoder *encoder,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1251 FILE *file,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1252 FLAC__StreamEncoderProgressCallback progress_callback,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1253 void *client_data
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1254 )
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1255 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1256 return init_FILE_internal_(encoder, file, progress_callback, client_data, /*is_ogg=*/false);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1257 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1258
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1259 FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_FILE(
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1260 FLAC__StreamEncoder *encoder,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1261 FILE *file,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1262 FLAC__StreamEncoderProgressCallback progress_callback,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1263 void *client_data
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1264 )
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1265 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1266 return init_FILE_internal_(encoder, file, progress_callback, client_data, /*is_ogg=*/true);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1267 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1268
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1269 static FLAC__StreamEncoderInitStatus init_file_internal_(
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1270 FLAC__StreamEncoder *encoder,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1271 const char *filename,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1272 FLAC__StreamEncoderProgressCallback progress_callback,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1273 void *client_data,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1274 FLAC__bool is_ogg
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1275 )
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1276 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1277 FILE *file;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1278
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1279 FLAC__ASSERT(0 != encoder);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1280
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1281 /*
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1282 * To make sure that our file does not go unclosed after an error, we
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1283 * have to do the same entrance checks here that are later performed
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1284 * in FLAC__stream_encoder_init_FILE() before the FILE* is assigned.
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1285 */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1286 if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1287 return FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1288
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1289 file = filename? fopen(filename, "w+b") : stdout;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1290
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1291 if(file == 0) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1292 encoder->protected_->state = FLAC__STREAM_ENCODER_IO_ERROR;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1293 return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1294 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1295
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1296 return init_FILE_internal_(encoder, file, progress_callback, client_data, is_ogg);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1297 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1298
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1299 FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_file(
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1300 FLAC__StreamEncoder *encoder,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1301 const char *filename,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1302 FLAC__StreamEncoderProgressCallback progress_callback,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1303 void *client_data
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1304 )
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1305 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1306 return init_file_internal_(encoder, filename, progress_callback, client_data, /*is_ogg=*/false);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1307 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1308
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1309 FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_file(
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1310 FLAC__StreamEncoder *encoder,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1311 const char *filename,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1312 FLAC__StreamEncoderProgressCallback progress_callback,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1313 void *client_data
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1314 )
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1315 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1316 return init_file_internal_(encoder, filename, progress_callback, client_data, /*is_ogg=*/true);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1317 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1318
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1319 FLAC_API FLAC__bool FLAC__stream_encoder_finish(FLAC__StreamEncoder *encoder)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1320 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1321 FLAC__bool error = false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1322
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1323 FLAC__ASSERT(0 != encoder);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1324 FLAC__ASSERT(0 != encoder->private_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1325 FLAC__ASSERT(0 != encoder->protected_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1326
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1327 if(encoder->protected_->state == FLAC__STREAM_ENCODER_UNINITIALIZED)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1328 return true;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1329
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1330 if(encoder->protected_->state == FLAC__STREAM_ENCODER_OK && !encoder->private_->is_being_deleted) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1331 if(encoder->private_->current_sample_number != 0) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1332 const FLAC__bool is_fractional_block = encoder->protected_->blocksize != encoder->private_->current_sample_number;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1333 encoder->protected_->blocksize = encoder->private_->current_sample_number;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1334 if(!process_frame_(encoder, is_fractional_block, /*is_last_block=*/true))
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1335 error = true;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1336 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1337 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1338
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1339 FLAC__MD5Final(encoder->private_->streaminfo.data.stream_info.md5sum, &encoder->private_->md5context);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1340
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1341 if(!encoder->private_->is_being_deleted) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1342 if(encoder->protected_->state == FLAC__STREAM_ENCODER_OK) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1343 if(encoder->private_->seek_callback) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1344 #if FLAC__HAS_OGG
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1345 if(encoder->private_->is_ogg)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1346 update_ogg_metadata_(encoder);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1347 else
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1348 #endif
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1349 update_metadata_(encoder);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1350
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1351 /* check if an error occurred while updating metadata */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1352 if(encoder->protected_->state != FLAC__STREAM_ENCODER_OK)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1353 error = true;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1354 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1355 if(encoder->private_->metadata_callback)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1356 encoder->private_->metadata_callback(encoder, &encoder->private_->streaminfo, encoder->private_->client_data);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1357 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1358
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1359 if(encoder->protected_->verify && 0 != encoder->private_->verify.decoder && !FLAC__stream_decoder_finish(encoder->private_->verify.decoder)) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1360 if(!error)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1361 encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1362 error = true;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1363 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1364 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1365
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1366 if(0 != encoder->private_->file) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1367 if(encoder->private_->file != stdout)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1368 fclose(encoder->private_->file);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1369 encoder->private_->file = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1370 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1371
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1372 #if FLAC__HAS_OGG
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1373 if(encoder->private_->is_ogg)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1374 FLAC__ogg_encoder_aspect_finish(&encoder->protected_->ogg_encoder_aspect);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1375 #endif
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1376
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1377 free_(encoder);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1378 set_defaults_(encoder);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1379
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1380 if(!error)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1381 encoder->protected_->state = FLAC__STREAM_ENCODER_UNINITIALIZED;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1382
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1383 return !error;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1384 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1385
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1386 FLAC_API FLAC__bool FLAC__stream_encoder_set_ogg_serial_number(FLAC__StreamEncoder *encoder, long value)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1387 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1388 FLAC__ASSERT(0 != encoder);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1389 FLAC__ASSERT(0 != encoder->private_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1390 FLAC__ASSERT(0 != encoder->protected_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1391 if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1392 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1393 #if FLAC__HAS_OGG
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1394 /* can't check encoder->private_->is_ogg since that's not set until init time */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1395 FLAC__ogg_encoder_aspect_set_serial_number(&encoder->protected_->ogg_encoder_aspect, value);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1396 return true;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1397 #else
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1398 (void)value;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1399 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1400 #endif
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1401 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1402
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1403 FLAC_API FLAC__bool FLAC__stream_encoder_set_verify(FLAC__StreamEncoder *encoder, FLAC__bool value)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1404 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1405 FLAC__ASSERT(0 != encoder);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1406 FLAC__ASSERT(0 != encoder->private_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1407 FLAC__ASSERT(0 != encoder->protected_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1408 if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1409 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1410 #ifndef FLAC__MANDATORY_VERIFY_WHILE_ENCODING
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1411 encoder->protected_->verify = value;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1412 #endif
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1413 return true;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1414 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1415
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1416 FLAC_API FLAC__bool FLAC__stream_encoder_set_streamable_subset(FLAC__StreamEncoder *encoder, FLAC__bool value)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1417 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1418 FLAC__ASSERT(0 != encoder);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1419 FLAC__ASSERT(0 != encoder->private_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1420 FLAC__ASSERT(0 != encoder->protected_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1421 if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1422 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1423 encoder->protected_->streamable_subset = value;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1424 return true;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1425 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1426
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1427 FLAC_API FLAC__bool FLAC__stream_encoder_set_channels(FLAC__StreamEncoder *encoder, unsigned value)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1428 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1429 FLAC__ASSERT(0 != encoder);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1430 FLAC__ASSERT(0 != encoder->private_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1431 FLAC__ASSERT(0 != encoder->protected_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1432 if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1433 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1434 encoder->protected_->channels = value;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1435 return true;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1436 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1437
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1438 FLAC_API FLAC__bool FLAC__stream_encoder_set_bits_per_sample(FLAC__StreamEncoder *encoder, unsigned value)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1439 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1440 FLAC__ASSERT(0 != encoder);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1441 FLAC__ASSERT(0 != encoder->private_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1442 FLAC__ASSERT(0 != encoder->protected_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1443 if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1444 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1445 encoder->protected_->bits_per_sample = value;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1446 return true;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1447 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1448
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1449 FLAC_API FLAC__bool FLAC__stream_encoder_set_sample_rate(FLAC__StreamEncoder *encoder, unsigned value)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1450 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1451 FLAC__ASSERT(0 != encoder);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1452 FLAC__ASSERT(0 != encoder->private_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1453 FLAC__ASSERT(0 != encoder->protected_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1454 if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1455 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1456 encoder->protected_->sample_rate = value;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1457 return true;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1458 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1459
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1460 FLAC_API FLAC__bool FLAC__stream_encoder_set_compression_level(FLAC__StreamEncoder *encoder, unsigned value)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1461 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1462 FLAC__bool ok = true;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1463 FLAC__ASSERT(0 != encoder);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1464 FLAC__ASSERT(0 != encoder->private_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1465 FLAC__ASSERT(0 != encoder->protected_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1466 if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1467 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1468 if(value >= sizeof(compression_levels_)/sizeof(compression_levels_[0]))
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1469 value = sizeof(compression_levels_)/sizeof(compression_levels_[0]) - 1;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1470 ok &= FLAC__stream_encoder_set_do_mid_side_stereo (encoder, compression_levels_[value].do_mid_side_stereo);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1471 ok &= FLAC__stream_encoder_set_loose_mid_side_stereo (encoder, compression_levels_[value].loose_mid_side_stereo);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1472 #if 0
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1473 /* was: */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1474 ok &= FLAC__stream_encoder_set_apodization (encoder, compression_levels_[value].apodization);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1475 /* but it's too hard to specify the string in a locale-specific way */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1476 #else
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1477 encoder->protected_->num_apodizations = 1;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1478 encoder->protected_->apodizations[0].type = FLAC__APODIZATION_TUKEY;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1479 encoder->protected_->apodizations[0].parameters.tukey.p = 0.5;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1480 #endif
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1481 ok &= FLAC__stream_encoder_set_max_lpc_order (encoder, compression_levels_[value].max_lpc_order);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1482 ok &= FLAC__stream_encoder_set_qlp_coeff_precision (encoder, compression_levels_[value].qlp_coeff_precision);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1483 ok &= FLAC__stream_encoder_set_do_qlp_coeff_prec_search (encoder, compression_levels_[value].do_qlp_coeff_prec_search);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1484 ok &= FLAC__stream_encoder_set_do_escape_coding (encoder, compression_levels_[value].do_escape_coding);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1485 ok &= FLAC__stream_encoder_set_do_exhaustive_model_search (encoder, compression_levels_[value].do_exhaustive_model_search);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1486 ok &= FLAC__stream_encoder_set_min_residual_partition_order(encoder, compression_levels_[value].min_residual_partition_order);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1487 ok &= FLAC__stream_encoder_set_max_residual_partition_order(encoder, compression_levels_[value].max_residual_partition_order);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1488 ok &= FLAC__stream_encoder_set_rice_parameter_search_dist (encoder, compression_levels_[value].rice_parameter_search_dist);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1489 return ok;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1490 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1491
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1492 FLAC_API FLAC__bool FLAC__stream_encoder_set_blocksize(FLAC__StreamEncoder *encoder, unsigned value)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1493 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1494 FLAC__ASSERT(0 != encoder);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1495 FLAC__ASSERT(0 != encoder->private_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1496 FLAC__ASSERT(0 != encoder->protected_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1497 if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1498 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1499 encoder->protected_->blocksize = value;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1500 return true;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1501 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1502
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1503 FLAC_API FLAC__bool FLAC__stream_encoder_set_do_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1504 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1505 FLAC__ASSERT(0 != encoder);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1506 FLAC__ASSERT(0 != encoder->private_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1507 FLAC__ASSERT(0 != encoder->protected_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1508 if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1509 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1510 encoder->protected_->do_mid_side_stereo = value;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1511 return true;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1512 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1513
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1514 FLAC_API FLAC__bool FLAC__stream_encoder_set_loose_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1515 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1516 FLAC__ASSERT(0 != encoder);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1517 FLAC__ASSERT(0 != encoder->private_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1518 FLAC__ASSERT(0 != encoder->protected_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1519 if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1520 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1521 encoder->protected_->loose_mid_side_stereo = value;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1522 return true;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1523 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1524
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1525 FLAC_API FLAC__bool FLAC__stream_encoder_set_apodization(FLAC__StreamEncoder *encoder, const char *specification)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1526 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1527 FLAC__ASSERT(0 != encoder);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1528 FLAC__ASSERT(0 != encoder->private_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1529 FLAC__ASSERT(0 != encoder->protected_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1530 FLAC__ASSERT(0 != specification);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1531 if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1532 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1533 #ifdef FLAC__INTEGER_ONLY_LIBRARY
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1534 (void)specification; /* silently ignore since we haven't integerized; will always use a rectangular window */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1535 #else
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1536 encoder->protected_->num_apodizations = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1537 while(1) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1538 const char *s = strchr(specification, ';');
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1539 const size_t n = s? (size_t)(s - specification) : strlen(specification);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1540 if (n==8 && 0 == strncmp("bartlett" , specification, n))
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1541 encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_BARTLETT;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1542 else if(n==13 && 0 == strncmp("bartlett_hann", specification, n))
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1543 encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_BARTLETT_HANN;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1544 else if(n==8 && 0 == strncmp("blackman" , specification, n))
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1545 encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_BLACKMAN;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1546 else if(n==26 && 0 == strncmp("blackman_harris_4term_92db", specification, n))
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1547 encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_BLACKMAN_HARRIS_4TERM_92DB_SIDELOBE;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1548 else if(n==6 && 0 == strncmp("connes" , specification, n))
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1549 encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_CONNES;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1550 else if(n==7 && 0 == strncmp("flattop" , specification, n))
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1551 encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_FLATTOP;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1552 else if(n>7 && 0 == strncmp("gauss(" , specification, 6)) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1553 FLAC__real stddev = (FLAC__real)strtod(specification+6, 0);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1554 if (stddev > 0.0 && stddev <= 0.5) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1555 encoder->protected_->apodizations[encoder->protected_->num_apodizations].parameters.gauss.stddev = stddev;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1556 encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_GAUSS;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1557 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1558 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1559 else if(n==7 && 0 == strncmp("hamming" , specification, n))
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1560 encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_HAMMING;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1561 else if(n==4 && 0 == strncmp("hann" , specification, n))
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1562 encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_HANN;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1563 else if(n==13 && 0 == strncmp("kaiser_bessel", specification, n))
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1564 encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_KAISER_BESSEL;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1565 else if(n==7 && 0 == strncmp("nuttall" , specification, n))
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1566 encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_NUTTALL;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1567 else if(n==9 && 0 == strncmp("rectangle" , specification, n))
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1568 encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_RECTANGLE;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1569 else if(n==8 && 0 == strncmp("triangle" , specification, n))
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1570 encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_TRIANGLE;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1571 else if(n>7 && 0 == strncmp("tukey(" , specification, 6)) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1572 FLAC__real p = (FLAC__real)strtod(specification+6, 0);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1573 if (p >= 0.0 && p <= 1.0) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1574 encoder->protected_->apodizations[encoder->protected_->num_apodizations].parameters.tukey.p = p;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1575 encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_TUKEY;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1576 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1577 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1578 else if(n==5 && 0 == strncmp("welch" , specification, n))
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1579 encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_WELCH;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1580 if (encoder->protected_->num_apodizations == 32)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1581 break;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1582 if (s)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1583 specification = s+1;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1584 else
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1585 break;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1586 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1587 if(encoder->protected_->num_apodizations == 0) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1588 encoder->protected_->num_apodizations = 1;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1589 encoder->protected_->apodizations[0].type = FLAC__APODIZATION_TUKEY;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1590 encoder->protected_->apodizations[0].parameters.tukey.p = 0.5;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1591 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1592 #endif
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1593 return true;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1594 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1595
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1596 FLAC_API FLAC__bool FLAC__stream_encoder_set_max_lpc_order(FLAC__StreamEncoder *encoder, unsigned value)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1597 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1598 FLAC__ASSERT(0 != encoder);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1599 FLAC__ASSERT(0 != encoder->private_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1600 FLAC__ASSERT(0 != encoder->protected_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1601 if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1602 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1603 encoder->protected_->max_lpc_order = value;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1604 return true;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1605 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1606
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1607 FLAC_API FLAC__bool FLAC__stream_encoder_set_qlp_coeff_precision(FLAC__StreamEncoder *encoder, unsigned value)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1608 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1609 FLAC__ASSERT(0 != encoder);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1610 FLAC__ASSERT(0 != encoder->private_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1611 FLAC__ASSERT(0 != encoder->protected_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1612 if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1613 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1614 encoder->protected_->qlp_coeff_precision = value;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1615 return true;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1616 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1617
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1618 FLAC_API FLAC__bool FLAC__stream_encoder_set_do_qlp_coeff_prec_search(FLAC__StreamEncoder *encoder, FLAC__bool value)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1619 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1620 FLAC__ASSERT(0 != encoder);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1621 FLAC__ASSERT(0 != encoder->private_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1622 FLAC__ASSERT(0 != encoder->protected_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1623 if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1624 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1625 encoder->protected_->do_qlp_coeff_prec_search = value;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1626 return true;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1627 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1628
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1629 FLAC_API FLAC__bool FLAC__stream_encoder_set_do_escape_coding(FLAC__StreamEncoder *encoder, FLAC__bool value)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1630 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1631 FLAC__ASSERT(0 != encoder);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1632 FLAC__ASSERT(0 != encoder->private_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1633 FLAC__ASSERT(0 != encoder->protected_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1634 if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1635 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1636 #if 0
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1637 /*@@@ deprecated: */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1638 encoder->protected_->do_escape_coding = value;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1639 #else
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1640 (void)value;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1641 #endif
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1642 return true;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1643 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1644
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1645 FLAC_API FLAC__bool FLAC__stream_encoder_set_do_exhaustive_model_search(FLAC__StreamEncoder *encoder, FLAC__bool value)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1646 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1647 FLAC__ASSERT(0 != encoder);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1648 FLAC__ASSERT(0 != encoder->private_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1649 FLAC__ASSERT(0 != encoder->protected_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1650 if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1651 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1652 encoder->protected_->do_exhaustive_model_search = value;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1653 return true;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1654 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1655
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1656 FLAC_API FLAC__bool FLAC__stream_encoder_set_min_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1657 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1658 FLAC__ASSERT(0 != encoder);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1659 FLAC__ASSERT(0 != encoder->private_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1660 FLAC__ASSERT(0 != encoder->protected_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1661 if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1662 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1663 encoder->protected_->min_residual_partition_order = value;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1664 return true;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1665 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1666
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1667 FLAC_API FLAC__bool FLAC__stream_encoder_set_max_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1668 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1669 FLAC__ASSERT(0 != encoder);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1670 FLAC__ASSERT(0 != encoder->private_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1671 FLAC__ASSERT(0 != encoder->protected_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1672 if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1673 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1674 encoder->protected_->max_residual_partition_order = value;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1675 return true;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1676 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1677
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1678 FLAC_API FLAC__bool FLAC__stream_encoder_set_rice_parameter_search_dist(FLAC__StreamEncoder *encoder, unsigned value)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1679 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1680 FLAC__ASSERT(0 != encoder);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1681 FLAC__ASSERT(0 != encoder->private_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1682 FLAC__ASSERT(0 != encoder->protected_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1683 if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1684 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1685 #if 0
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1686 /*@@@ deprecated: */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1687 encoder->protected_->rice_parameter_search_dist = value;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1688 #else
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1689 (void)value;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1690 #endif
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1691 return true;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1692 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1693
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1694 FLAC_API FLAC__bool FLAC__stream_encoder_set_total_samples_estimate(FLAC__StreamEncoder *encoder, FLAC__uint64 value)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1695 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1696 FLAC__ASSERT(0 != encoder);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1697 FLAC__ASSERT(0 != encoder->private_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1698 FLAC__ASSERT(0 != encoder->protected_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1699 if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1700 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1701 encoder->protected_->total_samples_estimate = value;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1702 return true;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1703 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1704
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1705 FLAC_API FLAC__bool FLAC__stream_encoder_set_metadata(FLAC__StreamEncoder *encoder, FLAC__StreamMetadata **metadata, unsigned num_blocks)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1706 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1707 FLAC__ASSERT(0 != encoder);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1708 FLAC__ASSERT(0 != encoder->private_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1709 FLAC__ASSERT(0 != encoder->protected_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1710 if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1711 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1712 if(0 == metadata)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1713 num_blocks = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1714 if(0 == num_blocks)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1715 metadata = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1716 /* realloc() does not do exactly what we want so... */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1717 if(encoder->protected_->metadata) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1718 free(encoder->protected_->metadata);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1719 encoder->protected_->metadata = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1720 encoder->protected_->num_metadata_blocks = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1721 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1722 if(num_blocks) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1723 FLAC__StreamMetadata **m;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1724 if(0 == (m = (FLAC__StreamMetadata**)malloc(sizeof(m[0]) * num_blocks)))
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1725 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1726 memcpy(m, metadata, sizeof(m[0]) * num_blocks);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1727 encoder->protected_->metadata = m;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1728 encoder->protected_->num_metadata_blocks = num_blocks;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1729 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1730 #if FLAC__HAS_OGG
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1731 if(!FLAC__ogg_encoder_aspect_set_num_metadata(&encoder->protected_->ogg_encoder_aspect, num_blocks))
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1732 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1733 #endif
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1734 return true;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1735 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1736
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1737 /*
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1738 * These three functions are not static, but not publically exposed in
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1739 * include/FLAC/ either. They are used by the test suite.
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1740 */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1741 FLAC_API FLAC__bool FLAC__stream_encoder_disable_constant_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1742 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1743 FLAC__ASSERT(0 != encoder);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1744 FLAC__ASSERT(0 != encoder->private_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1745 FLAC__ASSERT(0 != encoder->protected_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1746 if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1747 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1748 encoder->private_->disable_constant_subframes = value;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1749 return true;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1750 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1751
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1752 FLAC_API FLAC__bool FLAC__stream_encoder_disable_fixed_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1753 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1754 FLAC__ASSERT(0 != encoder);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1755 FLAC__ASSERT(0 != encoder->private_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1756 FLAC__ASSERT(0 != encoder->protected_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1757 if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1758 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1759 encoder->private_->disable_fixed_subframes = value;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1760 return true;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1761 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1762
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1763 FLAC_API FLAC__bool FLAC__stream_encoder_disable_verbatim_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1764 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1765 FLAC__ASSERT(0 != encoder);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1766 FLAC__ASSERT(0 != encoder->private_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1767 FLAC__ASSERT(0 != encoder->protected_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1768 if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1769 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1770 encoder->private_->disable_verbatim_subframes = value;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1771 return true;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1772 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1773
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1774 FLAC_API FLAC__StreamEncoderState FLAC__stream_encoder_get_state(const FLAC__StreamEncoder *encoder)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1775 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1776 FLAC__ASSERT(0 != encoder);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1777 FLAC__ASSERT(0 != encoder->private_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1778 FLAC__ASSERT(0 != encoder->protected_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1779 return encoder->protected_->state;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1780 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1781
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1782 FLAC_API FLAC__StreamDecoderState FLAC__stream_encoder_get_verify_decoder_state(const FLAC__StreamEncoder *encoder)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1783 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1784 FLAC__ASSERT(0 != encoder);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1785 FLAC__ASSERT(0 != encoder->private_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1786 FLAC__ASSERT(0 != encoder->protected_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1787 if(encoder->protected_->verify)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1788 return FLAC__stream_decoder_get_state(encoder->private_->verify.decoder);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1789 else
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1790 return FLAC__STREAM_DECODER_UNINITIALIZED;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1791 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1792
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1793 FLAC_API const char *FLAC__stream_encoder_get_resolved_state_string(const FLAC__StreamEncoder *encoder)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1794 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1795 FLAC__ASSERT(0 != encoder);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1796 FLAC__ASSERT(0 != encoder->private_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1797 FLAC__ASSERT(0 != encoder->protected_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1798 if(encoder->protected_->state != FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1799 return FLAC__StreamEncoderStateString[encoder->protected_->state];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1800 else
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1801 return FLAC__stream_decoder_get_resolved_state_string(encoder->private_->verify.decoder);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1802 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1803
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1804 FLAC_API void FLAC__stream_encoder_get_verify_decoder_error_stats(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_sample, unsigned *frame_number, unsigned *channel, unsigned *sample, FLAC__int32 *expected, FLAC__int32 *got)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1805 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1806 FLAC__ASSERT(0 != encoder);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1807 FLAC__ASSERT(0 != encoder->private_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1808 FLAC__ASSERT(0 != encoder->protected_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1809 if(0 != absolute_sample)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1810 *absolute_sample = encoder->private_->verify.error_stats.absolute_sample;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1811 if(0 != frame_number)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1812 *frame_number = encoder->private_->verify.error_stats.frame_number;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1813 if(0 != channel)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1814 *channel = encoder->private_->verify.error_stats.channel;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1815 if(0 != sample)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1816 *sample = encoder->private_->verify.error_stats.sample;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1817 if(0 != expected)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1818 *expected = encoder->private_->verify.error_stats.expected;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1819 if(0 != got)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1820 *got = encoder->private_->verify.error_stats.got;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1821 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1822
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1823 FLAC_API FLAC__bool FLAC__stream_encoder_get_verify(const FLAC__StreamEncoder *encoder)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1824 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1825 FLAC__ASSERT(0 != encoder);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1826 FLAC__ASSERT(0 != encoder->private_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1827 FLAC__ASSERT(0 != encoder->protected_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1828 return encoder->protected_->verify;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1829 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1830
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1831 FLAC_API FLAC__bool FLAC__stream_encoder_get_streamable_subset(const FLAC__StreamEncoder *encoder)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1832 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1833 FLAC__ASSERT(0 != encoder);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1834 FLAC__ASSERT(0 != encoder->private_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1835 FLAC__ASSERT(0 != encoder->protected_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1836 return encoder->protected_->streamable_subset;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1837 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1838
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1839 FLAC_API unsigned FLAC__stream_encoder_get_channels(const FLAC__StreamEncoder *encoder)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1840 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1841 FLAC__ASSERT(0 != encoder);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1842 FLAC__ASSERT(0 != encoder->private_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1843 FLAC__ASSERT(0 != encoder->protected_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1844 return encoder->protected_->channels;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1845 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1846
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1847 FLAC_API unsigned FLAC__stream_encoder_get_bits_per_sample(const FLAC__StreamEncoder *encoder)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1848 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1849 FLAC__ASSERT(0 != encoder);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1850 FLAC__ASSERT(0 != encoder->private_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1851 FLAC__ASSERT(0 != encoder->protected_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1852 return encoder->protected_->bits_per_sample;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1853 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1854
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1855 FLAC_API unsigned FLAC__stream_encoder_get_sample_rate(const FLAC__StreamEncoder *encoder)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1856 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1857 FLAC__ASSERT(0 != encoder);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1858 FLAC__ASSERT(0 != encoder->private_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1859 FLAC__ASSERT(0 != encoder->protected_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1860 return encoder->protected_->sample_rate;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1861 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1862
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1863 FLAC_API unsigned FLAC__stream_encoder_get_blocksize(const FLAC__StreamEncoder *encoder)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1864 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1865 FLAC__ASSERT(0 != encoder);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1866 FLAC__ASSERT(0 != encoder->private_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1867 FLAC__ASSERT(0 != encoder->protected_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1868 return encoder->protected_->blocksize;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1869 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1870
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1871 FLAC_API FLAC__bool FLAC__stream_encoder_get_do_mid_side_stereo(const FLAC__StreamEncoder *encoder)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1872 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1873 FLAC__ASSERT(0 != encoder);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1874 FLAC__ASSERT(0 != encoder->private_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1875 FLAC__ASSERT(0 != encoder->protected_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1876 return encoder->protected_->do_mid_side_stereo;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1877 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1878
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1879 FLAC_API FLAC__bool FLAC__stream_encoder_get_loose_mid_side_stereo(const FLAC__StreamEncoder *encoder)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1880 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1881 FLAC__ASSERT(0 != encoder);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1882 FLAC__ASSERT(0 != encoder->private_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1883 FLAC__ASSERT(0 != encoder->protected_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1884 return encoder->protected_->loose_mid_side_stereo;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1885 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1886
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1887 FLAC_API unsigned FLAC__stream_encoder_get_max_lpc_order(const FLAC__StreamEncoder *encoder)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1888 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1889 FLAC__ASSERT(0 != encoder);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1890 FLAC__ASSERT(0 != encoder->private_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1891 FLAC__ASSERT(0 != encoder->protected_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1892 return encoder->protected_->max_lpc_order;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1893 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1894
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1895 FLAC_API unsigned FLAC__stream_encoder_get_qlp_coeff_precision(const FLAC__StreamEncoder *encoder)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1896 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1897 FLAC__ASSERT(0 != encoder);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1898 FLAC__ASSERT(0 != encoder->private_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1899 FLAC__ASSERT(0 != encoder->protected_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1900 return encoder->protected_->qlp_coeff_precision;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1901 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1902
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1903 FLAC_API FLAC__bool FLAC__stream_encoder_get_do_qlp_coeff_prec_search(const FLAC__StreamEncoder *encoder)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1904 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1905 FLAC__ASSERT(0 != encoder);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1906 FLAC__ASSERT(0 != encoder->private_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1907 FLAC__ASSERT(0 != encoder->protected_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1908 return encoder->protected_->do_qlp_coeff_prec_search;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1909 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1910
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1911 FLAC_API FLAC__bool FLAC__stream_encoder_get_do_escape_coding(const FLAC__StreamEncoder *encoder)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1912 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1913 FLAC__ASSERT(0 != encoder);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1914 FLAC__ASSERT(0 != encoder->private_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1915 FLAC__ASSERT(0 != encoder->protected_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1916 return encoder->protected_->do_escape_coding;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1917 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1918
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1919 FLAC_API FLAC__bool FLAC__stream_encoder_get_do_exhaustive_model_search(const FLAC__StreamEncoder *encoder)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1920 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1921 FLAC__ASSERT(0 != encoder);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1922 FLAC__ASSERT(0 != encoder->private_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1923 FLAC__ASSERT(0 != encoder->protected_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1924 return encoder->protected_->do_exhaustive_model_search;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1925 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1926
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1927 FLAC_API unsigned FLAC__stream_encoder_get_min_residual_partition_order(const FLAC__StreamEncoder *encoder)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1928 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1929 FLAC__ASSERT(0 != encoder);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1930 FLAC__ASSERT(0 != encoder->private_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1931 FLAC__ASSERT(0 != encoder->protected_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1932 return encoder->protected_->min_residual_partition_order;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1933 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1934
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1935 FLAC_API unsigned FLAC__stream_encoder_get_max_residual_partition_order(const FLAC__StreamEncoder *encoder)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1936 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1937 FLAC__ASSERT(0 != encoder);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1938 FLAC__ASSERT(0 != encoder->private_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1939 FLAC__ASSERT(0 != encoder->protected_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1940 return encoder->protected_->max_residual_partition_order;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1941 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1942
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1943 FLAC_API unsigned FLAC__stream_encoder_get_rice_parameter_search_dist(const FLAC__StreamEncoder *encoder)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1944 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1945 FLAC__ASSERT(0 != encoder);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1946 FLAC__ASSERT(0 != encoder->private_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1947 FLAC__ASSERT(0 != encoder->protected_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1948 return encoder->protected_->rice_parameter_search_dist;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1949 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1950
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1951 FLAC_API FLAC__uint64 FLAC__stream_encoder_get_total_samples_estimate(const FLAC__StreamEncoder *encoder)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1952 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1953 FLAC__ASSERT(0 != encoder);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1954 FLAC__ASSERT(0 != encoder->private_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1955 FLAC__ASSERT(0 != encoder->protected_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1956 return encoder->protected_->total_samples_estimate;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1957 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1958
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1959 FLAC_API FLAC__bool FLAC__stream_encoder_process(FLAC__StreamEncoder *encoder, const FLAC__int32 * const buffer[], unsigned samples)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1960 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1961 unsigned i, j, channel;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1962 FLAC__int32 x, mid, side;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1963 const unsigned channels = encoder->protected_->channels, blocksize = encoder->protected_->blocksize;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1964
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1965 FLAC__ASSERT(0 != encoder);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1966 FLAC__ASSERT(0 != encoder->private_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1967 FLAC__ASSERT(0 != encoder->protected_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1968 FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1969
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1970 j = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1971 /*
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1972 * we have several flavors of the same basic loop, optimized for
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1973 * different conditions:
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1974 */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1975 if(encoder->protected_->max_lpc_order > 0) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1976 if(encoder->protected_->do_mid_side_stereo && channels == 2) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1977 /*
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1978 * stereo coding: unroll channel loop
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1979 * with LPC: calculate floating point version of signal
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1980 */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1981 do {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1982 if(encoder->protected_->verify)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1983 append_to_verify_fifo_(&encoder->private_->verify.input_fifo, buffer, j, channels, min(blocksize+1-encoder->private_->current_sample_number, samples-j));
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1984
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1985 /* "i <= blocksize" to overread 1 sample; see comment in OVERREAD_ decl */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1986 for(i = encoder->private_->current_sample_number; i <= blocksize && j < samples; i++, j++) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1987 x = mid = side = buffer[0][j];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1988 encoder->private_->integer_signal[0][i] = x;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1989 #ifndef FLAC__INTEGER_ONLY_LIBRARY
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1990 encoder->private_->real_signal[0][i] = (FLAC__real)x;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1991 #endif
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1992 x = buffer[1][j];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1993 encoder->private_->integer_signal[1][i] = x;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1994 #ifndef FLAC__INTEGER_ONLY_LIBRARY
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1995 encoder->private_->real_signal[1][i] = (FLAC__real)x;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1996 #endif
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1997 mid += x;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1998 side -= x;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1999 mid >>= 1; /* NOTE: not the same as 'mid = (buffer[0][j] + buffer[1][j]) / 2' ! */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2000 encoder->private_->integer_signal_mid_side[1][i] = side;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2001 encoder->private_->integer_signal_mid_side[0][i] = mid;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2002 #ifndef FLAC__INTEGER_ONLY_LIBRARY
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2003 encoder->private_->real_signal_mid_side[1][i] = (FLAC__real)side;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2004 encoder->private_->real_signal_mid_side[0][i] = (FLAC__real)mid;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2005 #endif
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2006 encoder->private_->current_sample_number++;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2007 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2008 /* we only process if we have a full block + 1 extra sample; final block is always handled by FLAC__stream_encoder_finish() */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2009 if(i > blocksize) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2010 if(!process_frame_(encoder, /*is_fractional_block=*/false, /*is_last_block=*/false))
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2011 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2012 /* move unprocessed overread samples to beginnings of arrays */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2013 FLAC__ASSERT(i == blocksize+OVERREAD_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2014 FLAC__ASSERT(OVERREAD_ == 1); /* assert we only overread 1 sample which simplifies the rest of the code below */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2015 i--;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2016 encoder->private_->integer_signal[0][0] = encoder->private_->integer_signal[0][i];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2017 encoder->private_->integer_signal[1][0] = encoder->private_->integer_signal[1][i];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2018 encoder->private_->integer_signal_mid_side[0][0] = encoder->private_->integer_signal_mid_side[0][i];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2019 encoder->private_->integer_signal_mid_side[1][0] = encoder->private_->integer_signal_mid_side[1][i];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2020 #ifndef FLAC__INTEGER_ONLY_LIBRARY
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2021 encoder->private_->real_signal[0][0] = encoder->private_->real_signal[0][i];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2022 encoder->private_->real_signal[1][0] = encoder->private_->real_signal[1][i];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2023 encoder->private_->real_signal_mid_side[0][0] = encoder->private_->real_signal_mid_side[0][i];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2024 encoder->private_->real_signal_mid_side[1][0] = encoder->private_->real_signal_mid_side[1][i];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2025 #endif
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2026 encoder->private_->current_sample_number = 1;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2027 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2028 } while(j < samples);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2029 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2030 else {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2031 /*
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2032 * independent channel coding: buffer each channel in inner loop
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2033 * with LPC: calculate floating point version of signal
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2034 */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2035 do {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2036 if(encoder->protected_->verify)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2037 append_to_verify_fifo_(&encoder->private_->verify.input_fifo, buffer, j, channels, min(blocksize+1-encoder->private_->current_sample_number, samples-j));
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2038
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2039 /* "i <= blocksize" to overread 1 sample; see comment in OVERREAD_ decl */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2040 for(i = encoder->private_->current_sample_number; i <= blocksize && j < samples; i++, j++) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2041 for(channel = 0; channel < channels; channel++) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2042 x = buffer[channel][j];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2043 encoder->private_->integer_signal[channel][i] = x;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2044 #ifndef FLAC__INTEGER_ONLY_LIBRARY
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2045 encoder->private_->real_signal[channel][i] = (FLAC__real)x;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2046 #endif
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2047 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2048 encoder->private_->current_sample_number++;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2049 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2050 /* we only process if we have a full block + 1 extra sample; final block is always handled by FLAC__stream_encoder_finish() */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2051 if(i > blocksize) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2052 if(!process_frame_(encoder, /*is_fractional_block=*/false, /*is_last_block=*/false))
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2053 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2054 /* move unprocessed overread samples to beginnings of arrays */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2055 FLAC__ASSERT(i == blocksize+OVERREAD_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2056 FLAC__ASSERT(OVERREAD_ == 1); /* assert we only overread 1 sample which simplifies the rest of the code below */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2057 i--;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2058 for(channel = 0; channel < channels; channel++) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2059 encoder->private_->integer_signal[channel][0] = encoder->private_->integer_signal[channel][i];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2060 #ifndef FLAC__INTEGER_ONLY_LIBRARY
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2061 encoder->private_->real_signal[channel][0] = encoder->private_->real_signal[channel][i];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2062 #endif
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2063 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2064 encoder->private_->current_sample_number = 1;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2065 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2066 } while(j < samples);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2067 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2068 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2069 else {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2070 if(encoder->protected_->do_mid_side_stereo && channels == 2) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2071 /*
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2072 * stereo coding: unroll channel loop
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2073 * without LPC: no need to calculate floating point version of signal
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2074 */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2075 do {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2076 if(encoder->protected_->verify)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2077 append_to_verify_fifo_(&encoder->private_->verify.input_fifo, buffer, j, channels, min(blocksize+1-encoder->private_->current_sample_number, samples-j));
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2078
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2079 /* "i <= blocksize" to overread 1 sample; see comment in OVERREAD_ decl */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2080 for(i = encoder->private_->current_sample_number; i <= blocksize && j < samples; i++, j++) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2081 encoder->private_->integer_signal[0][i] = mid = side = buffer[0][j];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2082 x = buffer[1][j];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2083 encoder->private_->integer_signal[1][i] = x;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2084 mid += x;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2085 side -= x;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2086 mid >>= 1; /* NOTE: not the same as 'mid = (buffer[0][j] + buffer[1][j]) / 2' ! */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2087 encoder->private_->integer_signal_mid_side[1][i] = side;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2088 encoder->private_->integer_signal_mid_side[0][i] = mid;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2089 encoder->private_->current_sample_number++;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2090 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2091 /* we only process if we have a full block + 1 extra sample; final block is always handled by FLAC__stream_encoder_finish() */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2092 if(i > blocksize) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2093 if(!process_frame_(encoder, /*is_fractional_block=*/false, /*is_last_block=*/false))
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2094 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2095 /* move unprocessed overread samples to beginnings of arrays */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2096 FLAC__ASSERT(i == blocksize+OVERREAD_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2097 FLAC__ASSERT(OVERREAD_ == 1); /* assert we only overread 1 sample which simplifies the rest of the code below */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2098 i--;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2099 encoder->private_->integer_signal[0][0] = encoder->private_->integer_signal[0][i];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2100 encoder->private_->integer_signal[1][0] = encoder->private_->integer_signal[1][i];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2101 encoder->private_->integer_signal_mid_side[0][0] = encoder->private_->integer_signal_mid_side[0][i];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2102 encoder->private_->integer_signal_mid_side[1][0] = encoder->private_->integer_signal_mid_side[1][i];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2103 encoder->private_->current_sample_number = 1;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2104 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2105 } while(j < samples);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2106 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2107 else {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2108 /*
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2109 * independent channel coding: buffer each channel in inner loop
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2110 * without LPC: no need to calculate floating point version of signal
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2111 */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2112 do {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2113 if(encoder->protected_->verify)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2114 append_to_verify_fifo_(&encoder->private_->verify.input_fifo, buffer, j, channels, min(blocksize+1-encoder->private_->current_sample_number, samples-j));
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2115
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2116 /* "i <= blocksize" to overread 1 sample; see comment in OVERREAD_ decl */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2117 for(i = encoder->private_->current_sample_number; i <= blocksize && j < samples; i++, j++) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2118 for(channel = 0; channel < channels; channel++)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2119 encoder->private_->integer_signal[channel][i] = buffer[channel][j];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2120 encoder->private_->current_sample_number++;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2121 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2122 /* we only process if we have a full block + 1 extra sample; final block is always handled by FLAC__stream_encoder_finish() */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2123 if(i > blocksize) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2124 if(!process_frame_(encoder, /*is_fractional_block=*/false, /*is_last_block=*/false))
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2125 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2126 /* move unprocessed overread samples to beginnings of arrays */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2127 FLAC__ASSERT(i == blocksize+OVERREAD_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2128 FLAC__ASSERT(OVERREAD_ == 1); /* assert we only overread 1 sample which simplifies the rest of the code below */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2129 i--;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2130 for(channel = 0; channel < channels; channel++)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2131 encoder->private_->integer_signal[channel][0] = encoder->private_->integer_signal[channel][i];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2132 encoder->private_->current_sample_number = 1;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2133 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2134 } while(j < samples);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2135 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2136 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2137
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2138 return true;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2139 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2140
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2141 FLAC_API FLAC__bool FLAC__stream_encoder_process_interleaved(FLAC__StreamEncoder *encoder, const FLAC__int32 buffer[], unsigned samples)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2142 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2143 unsigned i, j, k, channel;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2144 FLAC__int32 x, mid, side;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2145 const unsigned channels = encoder->protected_->channels, blocksize = encoder->protected_->blocksize;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2146
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2147 FLAC__ASSERT(0 != encoder);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2148 FLAC__ASSERT(0 != encoder->private_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2149 FLAC__ASSERT(0 != encoder->protected_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2150 FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2151
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2152 j = k = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2153 /*
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2154 * we have several flavors of the same basic loop, optimized for
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2155 * different conditions:
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2156 */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2157 if(encoder->protected_->max_lpc_order > 0) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2158 if(encoder->protected_->do_mid_side_stereo && channels == 2) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2159 /*
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2160 * stereo coding: unroll channel loop
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2161 * with LPC: calculate floating point version of signal
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2162 */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2163 do {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2164 if(encoder->protected_->verify)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2165 append_to_verify_fifo_interleaved_(&encoder->private_->verify.input_fifo, buffer, j, channels, min(blocksize+1-encoder->private_->current_sample_number, samples-j));
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2166
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2167 /* "i <= blocksize" to overread 1 sample; see comment in OVERREAD_ decl */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2168 for(i = encoder->private_->current_sample_number; i <= blocksize && j < samples; i++, j++) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2169 x = mid = side = buffer[k++];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2170 encoder->private_->integer_signal[0][i] = x;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2171 #ifndef FLAC__INTEGER_ONLY_LIBRARY
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2172 encoder->private_->real_signal[0][i] = (FLAC__real)x;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2173 #endif
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2174 x = buffer[k++];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2175 encoder->private_->integer_signal[1][i] = x;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2176 #ifndef FLAC__INTEGER_ONLY_LIBRARY
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2177 encoder->private_->real_signal[1][i] = (FLAC__real)x;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2178 #endif
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2179 mid += x;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2180 side -= x;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2181 mid >>= 1; /* NOTE: not the same as 'mid = (left + right) / 2' ! */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2182 encoder->private_->integer_signal_mid_side[1][i] = side;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2183 encoder->private_->integer_signal_mid_side[0][i] = mid;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2184 #ifndef FLAC__INTEGER_ONLY_LIBRARY
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2185 encoder->private_->real_signal_mid_side[1][i] = (FLAC__real)side;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2186 encoder->private_->real_signal_mid_side[0][i] = (FLAC__real)mid;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2187 #endif
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2188 encoder->private_->current_sample_number++;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2189 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2190 /* we only process if we have a full block + 1 extra sample; final block is always handled by FLAC__stream_encoder_finish() */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2191 if(i > blocksize) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2192 if(!process_frame_(encoder, /*is_fractional_block=*/false, /*is_last_block=*/false))
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2193 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2194 /* move unprocessed overread samples to beginnings of arrays */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2195 FLAC__ASSERT(i == blocksize+OVERREAD_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2196 FLAC__ASSERT(OVERREAD_ == 1); /* assert we only overread 1 sample which simplifies the rest of the code below */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2197 i--;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2198 encoder->private_->integer_signal[0][0] = encoder->private_->integer_signal[0][i];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2199 encoder->private_->integer_signal[1][0] = encoder->private_->integer_signal[1][i];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2200 encoder->private_->integer_signal_mid_side[0][0] = encoder->private_->integer_signal_mid_side[0][i];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2201 encoder->private_->integer_signal_mid_side[1][0] = encoder->private_->integer_signal_mid_side[1][i];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2202 #ifndef FLAC__INTEGER_ONLY_LIBRARY
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2203 encoder->private_->real_signal[0][0] = encoder->private_->real_signal[0][i];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2204 encoder->private_->real_signal[1][0] = encoder->private_->real_signal[1][i];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2205 encoder->private_->real_signal_mid_side[0][0] = encoder->private_->real_signal_mid_side[0][i];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2206 encoder->private_->real_signal_mid_side[1][0] = encoder->private_->real_signal_mid_side[1][i];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2207 #endif
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2208 encoder->private_->current_sample_number = 1;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2209 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2210 } while(j < samples);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2211 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2212 else {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2213 /*
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2214 * independent channel coding: buffer each channel in inner loop
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2215 * with LPC: calculate floating point version of signal
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2216 */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2217 do {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2218 if(encoder->protected_->verify)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2219 append_to_verify_fifo_interleaved_(&encoder->private_->verify.input_fifo, buffer, j, channels, min(blocksize+1-encoder->private_->current_sample_number, samples-j));
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2220
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2221 /* "i <= blocksize" to overread 1 sample; see comment in OVERREAD_ decl */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2222 for(i = encoder->private_->current_sample_number; i <= blocksize && j < samples; i++, j++) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2223 for(channel = 0; channel < channels; channel++) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2224 x = buffer[k++];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2225 encoder->private_->integer_signal[channel][i] = x;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2226 #ifndef FLAC__INTEGER_ONLY_LIBRARY
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2227 encoder->private_->real_signal[channel][i] = (FLAC__real)x;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2228 #endif
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2229 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2230 encoder->private_->current_sample_number++;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2231 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2232 /* we only process if we have a full block + 1 extra sample; final block is always handled by FLAC__stream_encoder_finish() */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2233 if(i > blocksize) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2234 if(!process_frame_(encoder, /*is_fractional_block=*/false, /*is_last_block=*/false))
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2235 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2236 /* move unprocessed overread samples to beginnings of arrays */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2237 FLAC__ASSERT(i == blocksize+OVERREAD_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2238 FLAC__ASSERT(OVERREAD_ == 1); /* assert we only overread 1 sample which simplifies the rest of the code below */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2239 i--;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2240 for(channel = 0; channel < channels; channel++) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2241 encoder->private_->integer_signal[channel][0] = encoder->private_->integer_signal[channel][i];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2242 #ifndef FLAC__INTEGER_ONLY_LIBRARY
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2243 encoder->private_->real_signal[channel][0] = encoder->private_->real_signal[channel][i];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2244 #endif
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2245 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2246 encoder->private_->current_sample_number = 1;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2247 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2248 } while(j < samples);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2249 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2250 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2251 else {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2252 if(encoder->protected_->do_mid_side_stereo && channels == 2) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2253 /*
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2254 * stereo coding: unroll channel loop
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2255 * without LPC: no need to calculate floating point version of signal
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2256 */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2257 do {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2258 if(encoder->protected_->verify)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2259 append_to_verify_fifo_interleaved_(&encoder->private_->verify.input_fifo, buffer, j, channels, min(blocksize+1-encoder->private_->current_sample_number, samples-j));
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2260
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2261 /* "i <= blocksize" to overread 1 sample; see comment in OVERREAD_ decl */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2262 for(i = encoder->private_->current_sample_number; i <= blocksize && j < samples; i++, j++) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2263 encoder->private_->integer_signal[0][i] = mid = side = buffer[k++];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2264 x = buffer[k++];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2265 encoder->private_->integer_signal[1][i] = x;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2266 mid += x;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2267 side -= x;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2268 mid >>= 1; /* NOTE: not the same as 'mid = (left + right) / 2' ! */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2269 encoder->private_->integer_signal_mid_side[1][i] = side;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2270 encoder->private_->integer_signal_mid_side[0][i] = mid;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2271 encoder->private_->current_sample_number++;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2272 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2273 /* we only process if we have a full block + 1 extra sample; final block is always handled by FLAC__stream_encoder_finish() */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2274 if(i > blocksize) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2275 if(!process_frame_(encoder, /*is_fractional_block=*/false, /*is_last_block=*/false))
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2276 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2277 /* move unprocessed overread samples to beginnings of arrays */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2278 FLAC__ASSERT(i == blocksize+OVERREAD_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2279 FLAC__ASSERT(OVERREAD_ == 1); /* assert we only overread 1 sample which simplifies the rest of the code below */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2280 i--;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2281 encoder->private_->integer_signal[0][0] = encoder->private_->integer_signal[0][i];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2282 encoder->private_->integer_signal[1][0] = encoder->private_->integer_signal[1][i];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2283 encoder->private_->integer_signal_mid_side[0][0] = encoder->private_->integer_signal_mid_side[0][i];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2284 encoder->private_->integer_signal_mid_side[1][0] = encoder->private_->integer_signal_mid_side[1][i];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2285 encoder->private_->current_sample_number = 1;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2286 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2287 } while(j < samples);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2288 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2289 else {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2290 /*
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2291 * independent channel coding: buffer each channel in inner loop
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2292 * without LPC: no need to calculate floating point version of signal
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2293 */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2294 do {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2295 if(encoder->protected_->verify)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2296 append_to_verify_fifo_interleaved_(&encoder->private_->verify.input_fifo, buffer, j, channels, min(blocksize+1-encoder->private_->current_sample_number, samples-j));
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2297
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2298 /* "i <= blocksize" to overread 1 sample; see comment in OVERREAD_ decl */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2299 for(i = encoder->private_->current_sample_number; i <= blocksize && j < samples; i++, j++) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2300 for(channel = 0; channel < channels; channel++)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2301 encoder->private_->integer_signal[channel][i] = buffer[k++];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2302 encoder->private_->current_sample_number++;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2303 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2304 /* we only process if we have a full block + 1 extra sample; final block is always handled by FLAC__stream_encoder_finish() */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2305 if(i > blocksize) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2306 if(!process_frame_(encoder, /*is_fractional_block=*/false, /*is_last_block=*/false))
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2307 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2308 /* move unprocessed overread samples to beginnings of arrays */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2309 FLAC__ASSERT(i == blocksize+OVERREAD_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2310 FLAC__ASSERT(OVERREAD_ == 1); /* assert we only overread 1 sample which simplifies the rest of the code below */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2311 i--;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2312 for(channel = 0; channel < channels; channel++)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2313 encoder->private_->integer_signal[channel][0] = encoder->private_->integer_signal[channel][i];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2314 encoder->private_->current_sample_number = 1;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2315 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2316 } while(j < samples);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2317 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2318 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2319
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2320 return true;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2321 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2322
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2323 /***********************************************************************
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2324 *
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2325 * Private class methods
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2326 *
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2327 ***********************************************************************/
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2328
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2329 void set_defaults_(FLAC__StreamEncoder *encoder)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2330 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2331 FLAC__ASSERT(0 != encoder);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2332
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2333 #ifdef FLAC__MANDATORY_VERIFY_WHILE_ENCODING
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2334 encoder->protected_->verify = true;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2335 #else
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2336 encoder->protected_->verify = false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2337 #endif
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2338 encoder->protected_->streamable_subset = true;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2339 encoder->protected_->do_mid_side_stereo = false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2340 encoder->protected_->loose_mid_side_stereo = false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2341 encoder->protected_->channels = 2;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2342 encoder->protected_->bits_per_sample = 16;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2343 encoder->protected_->sample_rate = 44100;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2344 encoder->protected_->blocksize = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2345 #ifndef FLAC__INTEGER_ONLY_LIBRARY
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2346 encoder->protected_->num_apodizations = 1;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2347 encoder->protected_->apodizations[0].type = FLAC__APODIZATION_TUKEY;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2348 encoder->protected_->apodizations[0].parameters.tukey.p = 0.5;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2349 #endif
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2350 encoder->protected_->max_lpc_order = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2351 encoder->protected_->qlp_coeff_precision = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2352 encoder->protected_->do_qlp_coeff_prec_search = false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2353 encoder->protected_->do_exhaustive_model_search = false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2354 encoder->protected_->do_escape_coding = false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2355 encoder->protected_->min_residual_partition_order = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2356 encoder->protected_->max_residual_partition_order = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2357 encoder->protected_->rice_parameter_search_dist = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2358 encoder->protected_->total_samples_estimate = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2359 encoder->protected_->metadata = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2360 encoder->protected_->num_metadata_blocks = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2361
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2362 encoder->private_->seek_table = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2363 encoder->private_->disable_constant_subframes = false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2364 encoder->private_->disable_fixed_subframes = false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2365 encoder->private_->disable_verbatim_subframes = false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2366 #if FLAC__HAS_OGG
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2367 encoder->private_->is_ogg = false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2368 #endif
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2369 encoder->private_->read_callback = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2370 encoder->private_->write_callback = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2371 encoder->private_->seek_callback = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2372 encoder->private_->tell_callback = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2373 encoder->private_->metadata_callback = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2374 encoder->private_->progress_callback = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2375 encoder->private_->client_data = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2376
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2377 #if FLAC__HAS_OGG
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2378 FLAC__ogg_encoder_aspect_set_defaults(&encoder->protected_->ogg_encoder_aspect);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2379 #endif
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2380 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2381
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2382 void free_(FLAC__StreamEncoder *encoder)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2383 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2384 unsigned i, channel;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2385
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2386 FLAC__ASSERT(0 != encoder);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2387 if(encoder->protected_->metadata) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2388 free(encoder->protected_->metadata);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2389 encoder->protected_->metadata = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2390 encoder->protected_->num_metadata_blocks = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2391 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2392 for(i = 0; i < encoder->protected_->channels; i++) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2393 if(0 != encoder->private_->integer_signal_unaligned[i]) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2394 free(encoder->private_->integer_signal_unaligned[i]);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2395 encoder->private_->integer_signal_unaligned[i] = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2396 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2397 #ifndef FLAC__INTEGER_ONLY_LIBRARY
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2398 if(0 != encoder->private_->real_signal_unaligned[i]) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2399 free(encoder->private_->real_signal_unaligned[i]);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2400 encoder->private_->real_signal_unaligned[i] = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2401 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2402 #endif
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2403 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2404 for(i = 0; i < 2; i++) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2405 if(0 != encoder->private_->integer_signal_mid_side_unaligned[i]) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2406 free(encoder->private_->integer_signal_mid_side_unaligned[i]);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2407 encoder->private_->integer_signal_mid_side_unaligned[i] = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2408 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2409 #ifndef FLAC__INTEGER_ONLY_LIBRARY
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2410 if(0 != encoder->private_->real_signal_mid_side_unaligned[i]) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2411 free(encoder->private_->real_signal_mid_side_unaligned[i]);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2412 encoder->private_->real_signal_mid_side_unaligned[i] = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2413 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2414 #endif
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2415 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2416 #ifndef FLAC__INTEGER_ONLY_LIBRARY
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2417 for(i = 0; i < encoder->protected_->num_apodizations; i++) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2418 if(0 != encoder->private_->window_unaligned[i]) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2419 free(encoder->private_->window_unaligned[i]);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2420 encoder->private_->window_unaligned[i] = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2421 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2422 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2423 if(0 != encoder->private_->windowed_signal_unaligned) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2424 free(encoder->private_->windowed_signal_unaligned);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2425 encoder->private_->windowed_signal_unaligned = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2426 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2427 #endif
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2428 for(channel = 0; channel < encoder->protected_->channels; channel++) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2429 for(i = 0; i < 2; i++) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2430 if(0 != encoder->private_->residual_workspace_unaligned[channel][i]) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2431 free(encoder->private_->residual_workspace_unaligned[channel][i]);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2432 encoder->private_->residual_workspace_unaligned[channel][i] = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2433 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2434 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2435 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2436 for(channel = 0; channel < 2; channel++) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2437 for(i = 0; i < 2; i++) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2438 if(0 != encoder->private_->residual_workspace_mid_side_unaligned[channel][i]) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2439 free(encoder->private_->residual_workspace_mid_side_unaligned[channel][i]);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2440 encoder->private_->residual_workspace_mid_side_unaligned[channel][i] = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2441 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2442 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2443 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2444 if(0 != encoder->private_->abs_residual_partition_sums_unaligned) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2445 free(encoder->private_->abs_residual_partition_sums_unaligned);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2446 encoder->private_->abs_residual_partition_sums_unaligned = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2447 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2448 if(0 != encoder->private_->raw_bits_per_partition_unaligned) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2449 free(encoder->private_->raw_bits_per_partition_unaligned);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2450 encoder->private_->raw_bits_per_partition_unaligned = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2451 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2452 if(encoder->protected_->verify) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2453 for(i = 0; i < encoder->protected_->channels; i++) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2454 if(0 != encoder->private_->verify.input_fifo.data[i]) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2455 free(encoder->private_->verify.input_fifo.data[i]);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2456 encoder->private_->verify.input_fifo.data[i] = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2457 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2458 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2459 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2460 FLAC__bitwriter_free(encoder->private_->frame);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2461 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2462
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2463 FLAC__bool resize_buffers_(FLAC__StreamEncoder *encoder, unsigned new_blocksize)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2464 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2465 FLAC__bool ok;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2466 unsigned i, channel;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2467
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2468 FLAC__ASSERT(new_blocksize > 0);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2469 FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2470 FLAC__ASSERT(encoder->private_->current_sample_number == 0);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2471
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2472 /* To avoid excessive malloc'ing, we only grow the buffer; no shrinking. */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2473 if(new_blocksize <= encoder->private_->input_capacity)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2474 return true;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2475
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2476 ok = true;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2477
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2478 /* WATCHOUT: FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32_mmx()
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2479 * requires that the input arrays (in our case the integer signals)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2480 * have a buffer of up to 3 zeroes in front (at negative indices) for
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2481 * alignment purposes; we use 4 in front to keep the data well-aligned.
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2482 */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2483
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2484 for(i = 0; ok && i < encoder->protected_->channels; i++) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2485 ok = ok && FLAC__memory_alloc_aligned_int32_array(new_blocksize+4+OVERREAD_, &encoder->private_->integer_signal_unaligned[i], &encoder->private_->integer_signal[i]);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2486 memset(encoder->private_->integer_signal[i], 0, sizeof(FLAC__int32)*4);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2487 encoder->private_->integer_signal[i] += 4;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2488 #ifndef FLAC__INTEGER_ONLY_LIBRARY
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2489 if(encoder->protected_->max_lpc_order > 0)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2490 ok = ok && FLAC__memory_alloc_aligned_real_array(new_blocksize+OVERREAD_, &encoder->private_->real_signal_unaligned[i], &encoder->private_->real_signal[i]);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2491 #endif
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2492 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2493 for(i = 0; ok && i < 2; i++) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2494 ok = ok && FLAC__memory_alloc_aligned_int32_array(new_blocksize+4+OVERREAD_, &encoder->private_->integer_signal_mid_side_unaligned[i], &encoder->private_->integer_signal_mid_side[i]);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2495 memset(encoder->private_->integer_signal_mid_side[i], 0, sizeof(FLAC__int32)*4);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2496 encoder->private_->integer_signal_mid_side[i] += 4;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2497 #ifndef FLAC__INTEGER_ONLY_LIBRARY
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2498 if(encoder->protected_->max_lpc_order > 0)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2499 ok = ok && FLAC__memory_alloc_aligned_real_array(new_blocksize+OVERREAD_, &encoder->private_->real_signal_mid_side_unaligned[i], &encoder->private_->real_signal_mid_side[i]);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2500 #endif
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2501 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2502 #ifndef FLAC__INTEGER_ONLY_LIBRARY
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2503 if(ok && encoder->protected_->max_lpc_order > 0) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2504 for(i = 0; ok && i < encoder->protected_->num_apodizations; i++)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2505 ok = ok && FLAC__memory_alloc_aligned_real_array(new_blocksize, &encoder->private_->window_unaligned[i], &encoder->private_->window[i]);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2506 ok = ok && FLAC__memory_alloc_aligned_real_array(new_blocksize, &encoder->private_->windowed_signal_unaligned, &encoder->private_->windowed_signal);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2507 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2508 #endif
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2509 for(channel = 0; ok && channel < encoder->protected_->channels; channel++) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2510 for(i = 0; ok && i < 2; i++) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2511 ok = ok && FLAC__memory_alloc_aligned_int32_array(new_blocksize, &encoder->private_->residual_workspace_unaligned[channel][i], &encoder->private_->residual_workspace[channel][i]);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2512 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2513 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2514 for(channel = 0; ok && channel < 2; channel++) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2515 for(i = 0; ok && i < 2; i++) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2516 ok = ok && FLAC__memory_alloc_aligned_int32_array(new_blocksize, &encoder->private_->residual_workspace_mid_side_unaligned[channel][i], &encoder->private_->residual_workspace_mid_side[channel][i]);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2517 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2518 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2519 /* the *2 is an approximation to the series 1 + 1/2 + 1/4 + ... that sums tree occupies in a flat array */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2520 /*@@@ new_blocksize*2 is too pessimistic, but to fix, we need smarter logic because a smaller new_blocksize can actually increase the # of partitions; would require moving this out into a separate function, then checking its capacity against the need of the current blocksize&min/max_partition_order (and maybe predictor order) */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2521 ok = ok && FLAC__memory_alloc_aligned_uint64_array(new_blocksize * 2, &encoder->private_->abs_residual_partition_sums_unaligned, &encoder->private_->abs_residual_partition_sums);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2522 if(encoder->protected_->do_escape_coding)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2523 ok = ok && FLAC__memory_alloc_aligned_unsigned_array(new_blocksize * 2, &encoder->private_->raw_bits_per_partition_unaligned, &encoder->private_->raw_bits_per_partition);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2524
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2525 /* now adjust the windows if the blocksize has changed */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2526 #ifndef FLAC__INTEGER_ONLY_LIBRARY
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2527 if(ok && new_blocksize != encoder->private_->input_capacity && encoder->protected_->max_lpc_order > 0) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2528 for(i = 0; ok && i < encoder->protected_->num_apodizations; i++) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2529 switch(encoder->protected_->apodizations[i].type) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2530 case FLAC__APODIZATION_BARTLETT:
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2531 FLAC__window_bartlett(encoder->private_->window[i], new_blocksize);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2532 break;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2533 case FLAC__APODIZATION_BARTLETT_HANN:
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2534 FLAC__window_bartlett_hann(encoder->private_->window[i], new_blocksize);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2535 break;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2536 case FLAC__APODIZATION_BLACKMAN:
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2537 FLAC__window_blackman(encoder->private_->window[i], new_blocksize);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2538 break;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2539 case FLAC__APODIZATION_BLACKMAN_HARRIS_4TERM_92DB_SIDELOBE:
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2540 FLAC__window_blackman_harris_4term_92db_sidelobe(encoder->private_->window[i], new_blocksize);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2541 break;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2542 case FLAC__APODIZATION_CONNES:
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2543 FLAC__window_connes(encoder->private_->window[i], new_blocksize);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2544 break;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2545 case FLAC__APODIZATION_FLATTOP:
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2546 FLAC__window_flattop(encoder->private_->window[i], new_blocksize);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2547 break;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2548 case FLAC__APODIZATION_GAUSS:
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2549 FLAC__window_gauss(encoder->private_->window[i], new_blocksize, encoder->protected_->apodizations[i].parameters.gauss.stddev);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2550 break;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2551 case FLAC__APODIZATION_HAMMING:
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2552 FLAC__window_hamming(encoder->private_->window[i], new_blocksize);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2553 break;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2554 case FLAC__APODIZATION_HANN:
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2555 FLAC__window_hann(encoder->private_->window[i], new_blocksize);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2556 break;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2557 case FLAC__APODIZATION_KAISER_BESSEL:
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2558 FLAC__window_kaiser_bessel(encoder->private_->window[i], new_blocksize);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2559 break;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2560 case FLAC__APODIZATION_NUTTALL:
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2561 FLAC__window_nuttall(encoder->private_->window[i], new_blocksize);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2562 break;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2563 case FLAC__APODIZATION_RECTANGLE:
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2564 FLAC__window_rectangle(encoder->private_->window[i], new_blocksize);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2565 break;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2566 case FLAC__APODIZATION_TRIANGLE:
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2567 FLAC__window_triangle(encoder->private_->window[i], new_blocksize);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2568 break;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2569 case FLAC__APODIZATION_TUKEY:
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2570 FLAC__window_tukey(encoder->private_->window[i], new_blocksize, encoder->protected_->apodizations[i].parameters.tukey.p);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2571 break;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2572 case FLAC__APODIZATION_WELCH:
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2573 FLAC__window_welch(encoder->private_->window[i], new_blocksize);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2574 break;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2575 default:
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2576 FLAC__ASSERT(0);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2577 /* double protection */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2578 FLAC__window_hann(encoder->private_->window[i], new_blocksize);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2579 break;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2580 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2581 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2582 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2583 #endif
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2584
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2585 if(ok)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2586 encoder->private_->input_capacity = new_blocksize;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2587 else
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2588 encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2589
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2590 return ok;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2591 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2592
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2593 FLAC__bool write_bitbuffer_(FLAC__StreamEncoder *encoder, unsigned samples, FLAC__bool is_last_block)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2594 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2595 const FLAC__byte *buffer;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2596 size_t bytes;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2597
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2598 FLAC__ASSERT(FLAC__bitwriter_is_byte_aligned(encoder->private_->frame));
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2599
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2600 if(!FLAC__bitwriter_get_buffer(encoder->private_->frame, &buffer, &bytes)) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2601 encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2602 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2603 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2604
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2605 if(encoder->protected_->verify) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2606 encoder->private_->verify.output.data = buffer;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2607 encoder->private_->verify.output.bytes = bytes;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2608 if(encoder->private_->verify.state_hint == ENCODER_IN_MAGIC) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2609 encoder->private_->verify.needs_magic_hack = true;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2610 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2611 else {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2612 if(!FLAC__stream_decoder_process_single(encoder->private_->verify.decoder)) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2613 FLAC__bitwriter_release_buffer(encoder->private_->frame);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2614 FLAC__bitwriter_clear(encoder->private_->frame);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2615 if(encoder->protected_->state != FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2616 encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2617 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2618 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2619 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2620 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2621
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2622 if(write_frame_(encoder, buffer, bytes, samples, is_last_block) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2623 FLAC__bitwriter_release_buffer(encoder->private_->frame);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2624 FLAC__bitwriter_clear(encoder->private_->frame);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2625 encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2626 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2627 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2628
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2629 FLAC__bitwriter_release_buffer(encoder->private_->frame);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2630 FLAC__bitwriter_clear(encoder->private_->frame);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2631
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2632 if(samples > 0) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2633 encoder->private_->streaminfo.data.stream_info.min_framesize = min(bytes, encoder->private_->streaminfo.data.stream_info.min_framesize);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2634 encoder->private_->streaminfo.data.stream_info.max_framesize = max(bytes, encoder->private_->streaminfo.data.stream_info.max_framesize);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2635 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2636
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2637 return true;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2638 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2639
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2640 FLAC__StreamEncoderWriteStatus write_frame_(FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, FLAC__bool is_last_block)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2641 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2642 FLAC__StreamEncoderWriteStatus status;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2643 FLAC__uint64 output_position = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2644
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2645 /* FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED just means we didn't get the offset; no error */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2646 if(encoder->private_->tell_callback && encoder->private_->tell_callback(encoder, &output_position, encoder->private_->client_data) == FLAC__STREAM_ENCODER_TELL_STATUS_ERROR) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2647 encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2648 return FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2649 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2650
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2651 /*
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2652 * Watch for the STREAMINFO block and first SEEKTABLE block to go by and store their offsets.
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2653 */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2654 if(samples == 0) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2655 FLAC__MetadataType type = (buffer[0] & 0x7f);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2656 if(type == FLAC__METADATA_TYPE_STREAMINFO)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2657 encoder->protected_->streaminfo_offset = output_position;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2658 else if(type == FLAC__METADATA_TYPE_SEEKTABLE && encoder->protected_->seektable_offset == 0)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2659 encoder->protected_->seektable_offset = output_position;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2660 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2661
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2662 /*
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2663 * Mark the current seek point if hit (if audio_offset == 0 that
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2664 * means we're still writing metadata and haven't hit the first
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2665 * frame yet)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2666 */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2667 if(0 != encoder->private_->seek_table && encoder->protected_->audio_offset > 0 && encoder->private_->seek_table->num_points > 0) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2668 const unsigned blocksize = FLAC__stream_encoder_get_blocksize(encoder);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2669 const FLAC__uint64 frame_first_sample = encoder->private_->samples_written;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2670 const FLAC__uint64 frame_last_sample = frame_first_sample + (FLAC__uint64)blocksize - 1;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2671 FLAC__uint64 test_sample;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2672 unsigned i;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2673 for(i = encoder->private_->first_seekpoint_to_check; i < encoder->private_->seek_table->num_points; i++) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2674 test_sample = encoder->private_->seek_table->points[i].sample_number;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2675 if(test_sample > frame_last_sample) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2676 break;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2677 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2678 else if(test_sample >= frame_first_sample) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2679 encoder->private_->seek_table->points[i].sample_number = frame_first_sample;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2680 encoder->private_->seek_table->points[i].stream_offset = output_position - encoder->protected_->audio_offset;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2681 encoder->private_->seek_table->points[i].frame_samples = blocksize;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2682 encoder->private_->first_seekpoint_to_check++;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2683 /* DO NOT: "break;" and here's why:
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2684 * The seektable template may contain more than one target
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2685 * sample for any given frame; we will keep looping, generating
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2686 * duplicate seekpoints for them, and we'll clean it up later,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2687 * just before writing the seektable back to the metadata.
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2688 */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2689 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2690 else {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2691 encoder->private_->first_seekpoint_to_check++;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2692 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2693 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2694 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2695
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2696 #if FLAC__HAS_OGG
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2697 if(encoder->private_->is_ogg) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2698 status = FLAC__ogg_encoder_aspect_write_callback_wrapper(
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2699 &encoder->protected_->ogg_encoder_aspect,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2700 buffer,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2701 bytes,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2702 samples,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2703 encoder->private_->current_frame_number,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2704 is_last_block,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2705 (FLAC__OggEncoderAspectWriteCallbackProxy)encoder->private_->write_callback,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2706 encoder,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2707 encoder->private_->client_data
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2708 );
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2709 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2710 else
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2711 #endif
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2712 status = encoder->private_->write_callback(encoder, buffer, bytes, samples, encoder->private_->current_frame_number, encoder->private_->client_data);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2713
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2714 if(status == FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2715 encoder->private_->bytes_written += bytes;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2716 encoder->private_->samples_written += samples;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2717 /* we keep a high watermark on the number of frames written because
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2718 * when the encoder goes back to write metadata, 'current_frame'
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2719 * will drop back to 0.
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2720 */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2721 encoder->private_->frames_written = max(encoder->private_->frames_written, encoder->private_->current_frame_number+1);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2722 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2723 else
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2724 encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2725
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2726 return status;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2727 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2728
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2729 /* Gets called when the encoding process has finished so that we can update the STREAMINFO and SEEKTABLE blocks. */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2730 void update_metadata_(const FLAC__StreamEncoder *encoder)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2731 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2732 FLAC__byte b[max(6, FLAC__STREAM_METADATA_SEEKPOINT_LENGTH)];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2733 const FLAC__StreamMetadata *metadata = &encoder->private_->streaminfo;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2734 const FLAC__uint64 samples = metadata->data.stream_info.total_samples;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2735 const unsigned min_framesize = metadata->data.stream_info.min_framesize;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2736 const unsigned max_framesize = metadata->data.stream_info.max_framesize;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2737 const unsigned bps = metadata->data.stream_info.bits_per_sample;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2738 FLAC__StreamEncoderSeekStatus seek_status;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2739
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2740 FLAC__ASSERT(metadata->type == FLAC__METADATA_TYPE_STREAMINFO);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2741
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2742 /* All this is based on intimate knowledge of the stream header
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2743 * layout, but a change to the header format that would break this
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2744 * would also break all streams encoded in the previous format.
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2745 */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2746
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2747 /*
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2748 * Write MD5 signature
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2749 */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2750 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2751 const unsigned md5_offset =
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2752 FLAC__STREAM_METADATA_HEADER_LENGTH +
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2753 (
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2754 FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2755 FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN +
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2756 FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN +
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2757 FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN +
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2758 FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN +
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2759 FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN +
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2760 FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN +
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2761 FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2762 ) / 8;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2763
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2764 if((seek_status = encoder->private_->seek_callback(encoder, encoder->protected_->streaminfo_offset + md5_offset, encoder->private_->client_data)) != FLAC__STREAM_ENCODER_SEEK_STATUS_OK) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2765 if(seek_status == FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2766 encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2767 return;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2768 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2769 if(encoder->private_->write_callback(encoder, metadata->data.stream_info.md5sum, 16, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2770 encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2771 return;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2772 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2773 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2774
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2775 /*
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2776 * Write total samples
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2777 */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2778 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2779 const unsigned total_samples_byte_offset =
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2780 FLAC__STREAM_METADATA_HEADER_LENGTH +
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2781 (
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2782 FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2783 FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN +
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2784 FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN +
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2785 FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN +
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2786 FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN +
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2787 FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN +
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2788 FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2789 - 4
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2790 ) / 8;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2791
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2792 b[0] = ((FLAC__byte)(bps-1) << 4) | (FLAC__byte)((samples >> 32) & 0x0F);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2793 b[1] = (FLAC__byte)((samples >> 24) & 0xFF);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2794 b[2] = (FLAC__byte)((samples >> 16) & 0xFF);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2795 b[3] = (FLAC__byte)((samples >> 8) & 0xFF);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2796 b[4] = (FLAC__byte)(samples & 0xFF);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2797 if((seek_status = encoder->private_->seek_callback(encoder, encoder->protected_->streaminfo_offset + total_samples_byte_offset, encoder->private_->client_data)) != FLAC__STREAM_ENCODER_SEEK_STATUS_OK) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2798 if(seek_status == FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2799 encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2800 return;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2801 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2802 if(encoder->private_->write_callback(encoder, b, 5, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2803 encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2804 return;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2805 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2806 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2807
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2808 /*
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2809 * Write min/max framesize
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2810 */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2811 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2812 const unsigned min_framesize_offset =
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2813 FLAC__STREAM_METADATA_HEADER_LENGTH +
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2814 (
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2815 FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2816 FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2817 ) / 8;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2818
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2819 b[0] = (FLAC__byte)((min_framesize >> 16) & 0xFF);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2820 b[1] = (FLAC__byte)((min_framesize >> 8) & 0xFF);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2821 b[2] = (FLAC__byte)(min_framesize & 0xFF);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2822 b[3] = (FLAC__byte)((max_framesize >> 16) & 0xFF);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2823 b[4] = (FLAC__byte)((max_framesize >> 8) & 0xFF);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2824 b[5] = (FLAC__byte)(max_framesize & 0xFF);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2825 if((seek_status = encoder->private_->seek_callback(encoder, encoder->protected_->streaminfo_offset + min_framesize_offset, encoder->private_->client_data)) != FLAC__STREAM_ENCODER_SEEK_STATUS_OK) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2826 if(seek_status == FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2827 encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2828 return;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2829 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2830 if(encoder->private_->write_callback(encoder, b, 6, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2831 encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2832 return;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2833 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2834 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2835
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2836 /*
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2837 * Write seektable
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2838 */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2839 if(0 != encoder->private_->seek_table && encoder->private_->seek_table->num_points > 0 && encoder->protected_->seektable_offset > 0) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2840 unsigned i;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2841
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2842 FLAC__format_seektable_sort(encoder->private_->seek_table);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2843
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2844 FLAC__ASSERT(FLAC__format_seektable_is_legal(encoder->private_->seek_table));
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2845
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2846 if((seek_status = encoder->private_->seek_callback(encoder, encoder->protected_->seektable_offset + FLAC__STREAM_METADATA_HEADER_LENGTH, encoder->private_->client_data)) != FLAC__STREAM_ENCODER_SEEK_STATUS_OK) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2847 if(seek_status == FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2848 encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2849 return;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2850 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2851
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2852 for(i = 0; i < encoder->private_->seek_table->num_points; i++) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2853 FLAC__uint64 xx;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2854 unsigned x;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2855 xx = encoder->private_->seek_table->points[i].sample_number;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2856 b[7] = (FLAC__byte)xx; xx >>= 8;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2857 b[6] = (FLAC__byte)xx; xx >>= 8;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2858 b[5] = (FLAC__byte)xx; xx >>= 8;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2859 b[4] = (FLAC__byte)xx; xx >>= 8;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2860 b[3] = (FLAC__byte)xx; xx >>= 8;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2861 b[2] = (FLAC__byte)xx; xx >>= 8;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2862 b[1] = (FLAC__byte)xx; xx >>= 8;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2863 b[0] = (FLAC__byte)xx; xx >>= 8;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2864 xx = encoder->private_->seek_table->points[i].stream_offset;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2865 b[15] = (FLAC__byte)xx; xx >>= 8;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2866 b[14] = (FLAC__byte)xx; xx >>= 8;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2867 b[13] = (FLAC__byte)xx; xx >>= 8;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2868 b[12] = (FLAC__byte)xx; xx >>= 8;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2869 b[11] = (FLAC__byte)xx; xx >>= 8;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2870 b[10] = (FLAC__byte)xx; xx >>= 8;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2871 b[9] = (FLAC__byte)xx; xx >>= 8;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2872 b[8] = (FLAC__byte)xx; xx >>= 8;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2873 x = encoder->private_->seek_table->points[i].frame_samples;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2874 b[17] = (FLAC__byte)x; x >>= 8;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2875 b[16] = (FLAC__byte)x; x >>= 8;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2876 if(encoder->private_->write_callback(encoder, b, 18, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2877 encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2878 return;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2879 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2880 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2881 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2882 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2883
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2884 #if FLAC__HAS_OGG
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2885 /* Gets called when the encoding process has finished so that we can update the STREAMINFO and SEEKTABLE blocks. */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2886 void update_ogg_metadata_(FLAC__StreamEncoder *encoder)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2887 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2888 /* the # of bytes in the 1st packet that precede the STREAMINFO */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2889 static const unsigned FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH =
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2890 FLAC__OGG_MAPPING_PACKET_TYPE_LENGTH +
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2891 FLAC__OGG_MAPPING_MAGIC_LENGTH +
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2892 FLAC__OGG_MAPPING_VERSION_MAJOR_LENGTH +
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2893 FLAC__OGG_MAPPING_VERSION_MINOR_LENGTH +
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2894 FLAC__OGG_MAPPING_NUM_HEADERS_LENGTH +
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2895 FLAC__STREAM_SYNC_LENGTH
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2896 ;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2897 FLAC__byte b[max(6, FLAC__STREAM_METADATA_SEEKPOINT_LENGTH)];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2898 const FLAC__StreamMetadata *metadata = &encoder->private_->streaminfo;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2899 const FLAC__uint64 samples = metadata->data.stream_info.total_samples;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2900 const unsigned min_framesize = metadata->data.stream_info.min_framesize;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2901 const unsigned max_framesize = metadata->data.stream_info.max_framesize;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2902 ogg_page page;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2903
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2904 FLAC__ASSERT(metadata->type == FLAC__METADATA_TYPE_STREAMINFO);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2905 FLAC__ASSERT(0 != encoder->private_->seek_callback);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2906
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2907 /* Pre-check that client supports seeking, since we don't want the
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2908 * ogg_helper code to ever have to deal with this condition.
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2909 */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2910 if(encoder->private_->seek_callback(encoder, 0, encoder->private_->client_data) == FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2911 return;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2912
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2913 /* All this is based on intimate knowledge of the stream header
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2914 * layout, but a change to the header format that would break this
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2915 * would also break all streams encoded in the previous format.
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2916 */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2917
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2918 /**
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2919 ** Write STREAMINFO stats
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2920 **/
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2921 simple_ogg_page__init(&page);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2922 if(!simple_ogg_page__get_at(encoder, encoder->protected_->streaminfo_offset, &page, encoder->private_->seek_callback, encoder->private_->read_callback, encoder->private_->client_data)) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2923 simple_ogg_page__clear(&page);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2924 return; /* state already set */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2925 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2926
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2927 /*
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2928 * Write MD5 signature
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2929 */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2930 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2931 const unsigned md5_offset =
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2932 FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH +
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2933 FLAC__STREAM_METADATA_HEADER_LENGTH +
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2934 (
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2935 FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2936 FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN +
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2937 FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN +
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2938 FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN +
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2939 FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN +
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2940 FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN +
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2941 FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN +
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2942 FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2943 ) / 8;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2944
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2945 if(md5_offset + 16 > (unsigned)page.body_len) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2946 encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2947 simple_ogg_page__clear(&page);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2948 return;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2949 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2950 memcpy(page.body + md5_offset, metadata->data.stream_info.md5sum, 16);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2951 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2952
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2953 /*
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2954 * Write total samples
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2955 */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2956 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2957 const unsigned total_samples_byte_offset =
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2958 FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH +
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2959 FLAC__STREAM_METADATA_HEADER_LENGTH +
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2960 (
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2961 FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2962 FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN +
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2963 FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN +
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2964 FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN +
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2965 FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN +
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2966 FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN +
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2967 FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2968 - 4
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2969 ) / 8;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2970
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2971 if(total_samples_byte_offset + 5 > (unsigned)page.body_len) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2972 encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2973 simple_ogg_page__clear(&page);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2974 return;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2975 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2976 b[0] = (FLAC__byte)page.body[total_samples_byte_offset] & 0xF0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2977 b[0] |= (FLAC__byte)((samples >> 32) & 0x0F);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2978 b[1] = (FLAC__byte)((samples >> 24) & 0xFF);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2979 b[2] = (FLAC__byte)((samples >> 16) & 0xFF);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2980 b[3] = (FLAC__byte)((samples >> 8) & 0xFF);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2981 b[4] = (FLAC__byte)(samples & 0xFF);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2982 memcpy(page.body + total_samples_byte_offset, b, 5);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2983 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2984
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2985 /*
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2986 * Write min/max framesize
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2987 */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2988 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2989 const unsigned min_framesize_offset =
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2990 FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH +
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2991 FLAC__STREAM_METADATA_HEADER_LENGTH +
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2992 (
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2993 FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2994 FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2995 ) / 8;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2996
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2997 if(min_framesize_offset + 6 > (unsigned)page.body_len) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2998 encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2999 simple_ogg_page__clear(&page);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3000 return;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3001 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3002 b[0] = (FLAC__byte)((min_framesize >> 16) & 0xFF);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3003 b[1] = (FLAC__byte)((min_framesize >> 8) & 0xFF);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3004 b[2] = (FLAC__byte)(min_framesize & 0xFF);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3005 b[3] = (FLAC__byte)((max_framesize >> 16) & 0xFF);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3006 b[4] = (FLAC__byte)((max_framesize >> 8) & 0xFF);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3007 b[5] = (FLAC__byte)(max_framesize & 0xFF);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3008 memcpy(page.body + min_framesize_offset, b, 6);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3009 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3010 if(!simple_ogg_page__set_at(encoder, encoder->protected_->streaminfo_offset, &page, encoder->private_->seek_callback, encoder->private_->write_callback, encoder->private_->client_data)) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3011 simple_ogg_page__clear(&page);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3012 return; /* state already set */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3013 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3014 simple_ogg_page__clear(&page);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3015
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3016 /*
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3017 * Write seektable
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3018 */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3019 if(0 != encoder->private_->seek_table && encoder->private_->seek_table->num_points > 0 && encoder->protected_->seektable_offset > 0) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3020 unsigned i;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3021 FLAC__byte *p;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3022
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3023 FLAC__format_seektable_sort(encoder->private_->seek_table);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3024
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3025 FLAC__ASSERT(FLAC__format_seektable_is_legal(encoder->private_->seek_table));
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3026
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3027 simple_ogg_page__init(&page);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3028 if(!simple_ogg_page__get_at(encoder, encoder->protected_->seektable_offset, &page, encoder->private_->seek_callback, encoder->private_->read_callback, encoder->private_->client_data)) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3029 simple_ogg_page__clear(&page);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3030 return; /* state already set */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3031 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3032
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3033 if((FLAC__STREAM_METADATA_HEADER_LENGTH + 18*encoder->private_->seek_table->num_points) != (unsigned)page.body_len) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3034 encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3035 simple_ogg_page__clear(&page);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3036 return;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3037 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3038
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3039 for(i = 0, p = page.body + FLAC__STREAM_METADATA_HEADER_LENGTH; i < encoder->private_->seek_table->num_points; i++, p += 18) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3040 FLAC__uint64 xx;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3041 unsigned x;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3042 xx = encoder->private_->seek_table->points[i].sample_number;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3043 b[7] = (FLAC__byte)xx; xx >>= 8;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3044 b[6] = (FLAC__byte)xx; xx >>= 8;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3045 b[5] = (FLAC__byte)xx; xx >>= 8;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3046 b[4] = (FLAC__byte)xx; xx >>= 8;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3047 b[3] = (FLAC__byte)xx; xx >>= 8;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3048 b[2] = (FLAC__byte)xx; xx >>= 8;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3049 b[1] = (FLAC__byte)xx; xx >>= 8;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3050 b[0] = (FLAC__byte)xx; xx >>= 8;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3051 xx = encoder->private_->seek_table->points[i].stream_offset;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3052 b[15] = (FLAC__byte)xx; xx >>= 8;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3053 b[14] = (FLAC__byte)xx; xx >>= 8;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3054 b[13] = (FLAC__byte)xx; xx >>= 8;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3055 b[12] = (FLAC__byte)xx; xx >>= 8;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3056 b[11] = (FLAC__byte)xx; xx >>= 8;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3057 b[10] = (FLAC__byte)xx; xx >>= 8;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3058 b[9] = (FLAC__byte)xx; xx >>= 8;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3059 b[8] = (FLAC__byte)xx; xx >>= 8;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3060 x = encoder->private_->seek_table->points[i].frame_samples;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3061 b[17] = (FLAC__byte)x; x >>= 8;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3062 b[16] = (FLAC__byte)x; x >>= 8;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3063 memcpy(p, b, 18);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3064 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3065
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3066 if(!simple_ogg_page__set_at(encoder, encoder->protected_->seektable_offset, &page, encoder->private_->seek_callback, encoder->private_->write_callback, encoder->private_->client_data)) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3067 simple_ogg_page__clear(&page);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3068 return; /* state already set */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3069 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3070 simple_ogg_page__clear(&page);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3071 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3072 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3073 #endif
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3074
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3075 FLAC__bool process_frame_(FLAC__StreamEncoder *encoder, FLAC__bool is_fractional_block, FLAC__bool is_last_block)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3076 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3077 FLAC__uint16 crc;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3078 FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3079
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3080 /*
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3081 * Accumulate raw signal to the MD5 signature
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3082 */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3083 if(!FLAC__MD5Accumulate(&encoder->private_->md5context, (const FLAC__int32 * const *)encoder->private_->integer_signal, encoder->protected_->channels, encoder->protected_->blocksize, (encoder->protected_->bits_per_sample+7) / 8)) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3084 encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3085 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3086 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3087
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3088 /*
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3089 * Process the frame header and subframes into the frame bitbuffer
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3090 */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3091 if(!process_subframes_(encoder, is_fractional_block)) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3092 /* the above function sets the state for us in case of an error */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3093 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3094 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3095
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3096 /*
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3097 * Zero-pad the frame to a byte_boundary
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3098 */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3099 if(!FLAC__bitwriter_zero_pad_to_byte_boundary(encoder->private_->frame)) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3100 encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3101 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3102 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3103
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3104 /*
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3105 * CRC-16 the whole thing
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3106 */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3107 FLAC__ASSERT(FLAC__bitwriter_is_byte_aligned(encoder->private_->frame));
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3108 if(
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3109 !FLAC__bitwriter_get_write_crc16(encoder->private_->frame, &crc) ||
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3110 !FLAC__bitwriter_write_raw_uint32(encoder->private_->frame, crc, FLAC__FRAME_FOOTER_CRC_LEN)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3111 ) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3112 encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3113 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3114 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3115
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3116 /*
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3117 * Write it
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3118 */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3119 if(!write_bitbuffer_(encoder, encoder->protected_->blocksize, is_last_block)) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3120 /* the above function sets the state for us in case of an error */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3121 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3122 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3123
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3124 /*
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3125 * Get ready for the next frame
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3126 */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3127 encoder->private_->current_sample_number = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3128 encoder->private_->current_frame_number++;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3129 encoder->private_->streaminfo.data.stream_info.total_samples += (FLAC__uint64)encoder->protected_->blocksize;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3130
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3131 return true;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3132 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3133
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3134 FLAC__bool process_subframes_(FLAC__StreamEncoder *encoder, FLAC__bool is_fractional_block)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3135 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3136 FLAC__FrameHeader frame_header;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3137 unsigned channel, min_partition_order = encoder->protected_->min_residual_partition_order, max_partition_order;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3138 FLAC__bool do_independent, do_mid_side;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3139
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3140 /*
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3141 * Calculate the min,max Rice partition orders
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3142 */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3143 if(is_fractional_block) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3144 max_partition_order = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3145 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3146 else {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3147 max_partition_order = FLAC__format_get_max_rice_partition_order_from_blocksize(encoder->protected_->blocksize);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3148 max_partition_order = min(max_partition_order, encoder->protected_->max_residual_partition_order);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3149 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3150 min_partition_order = min(min_partition_order, max_partition_order);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3151
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3152 /*
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3153 * Setup the frame
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3154 */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3155 frame_header.blocksize = encoder->protected_->blocksize;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3156 frame_header.sample_rate = encoder->protected_->sample_rate;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3157 frame_header.channels = encoder->protected_->channels;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3158 frame_header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT; /* the default unless the encoder determines otherwise */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3159 frame_header.bits_per_sample = encoder->protected_->bits_per_sample;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3160 frame_header.number_type = FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3161 frame_header.number.frame_number = encoder->private_->current_frame_number;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3162
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3163 /*
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3164 * Figure out what channel assignments to try
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3165 */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3166 if(encoder->protected_->do_mid_side_stereo) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3167 if(encoder->protected_->loose_mid_side_stereo) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3168 if(encoder->private_->loose_mid_side_stereo_frame_count == 0) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3169 do_independent = true;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3170 do_mid_side = true;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3171 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3172 else {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3173 do_independent = (encoder->private_->last_channel_assignment == FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3174 do_mid_side = !do_independent;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3175 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3176 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3177 else {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3178 do_independent = true;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3179 do_mid_side = true;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3180 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3181 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3182 else {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3183 do_independent = true;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3184 do_mid_side = false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3185 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3186
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3187 FLAC__ASSERT(do_independent || do_mid_side);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3188
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3189 /*
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3190 * Check for wasted bits; set effective bps for each subframe
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3191 */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3192 if(do_independent) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3193 for(channel = 0; channel < encoder->protected_->channels; channel++) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3194 const unsigned w = get_wasted_bits_(encoder->private_->integer_signal[channel], encoder->protected_->blocksize);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3195 encoder->private_->subframe_workspace[channel][0].wasted_bits = encoder->private_->subframe_workspace[channel][1].wasted_bits = w;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3196 encoder->private_->subframe_bps[channel] = encoder->protected_->bits_per_sample - w;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3197 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3198 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3199 if(do_mid_side) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3200 FLAC__ASSERT(encoder->protected_->channels == 2);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3201 for(channel = 0; channel < 2; channel++) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3202 const unsigned w = get_wasted_bits_(encoder->private_->integer_signal_mid_side[channel], encoder->protected_->blocksize);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3203 encoder->private_->subframe_workspace_mid_side[channel][0].wasted_bits = encoder->private_->subframe_workspace_mid_side[channel][1].wasted_bits = w;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3204 encoder->private_->subframe_bps_mid_side[channel] = encoder->protected_->bits_per_sample - w + (channel==0? 0:1);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3205 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3206 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3207
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3208 /*
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3209 * First do a normal encoding pass of each independent channel
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3210 */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3211 if(do_independent) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3212 for(channel = 0; channel < encoder->protected_->channels; channel++) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3213 if(!
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3214 process_subframe_(
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3215 encoder,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3216 min_partition_order,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3217 max_partition_order,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3218 &frame_header,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3219 encoder->private_->subframe_bps[channel],
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3220 encoder->private_->integer_signal[channel],
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3221 #ifndef FLAC__INTEGER_ONLY_LIBRARY
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3222 encoder->private_->real_signal[channel],
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3223 #endif
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3224 encoder->private_->subframe_workspace_ptr[channel],
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3225 encoder->private_->partitioned_rice_contents_workspace_ptr[channel],
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3226 encoder->private_->residual_workspace[channel],
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3227 encoder->private_->best_subframe+channel,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3228 encoder->private_->best_subframe_bits+channel
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3229 )
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3230 )
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3231 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3232 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3233 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3234
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3235 /*
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3236 * Now do mid and side channels if requested
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3237 */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3238 if(do_mid_side) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3239 FLAC__ASSERT(encoder->protected_->channels == 2);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3240
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3241 for(channel = 0; channel < 2; channel++) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3242 if(!
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3243 process_subframe_(
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3244 encoder,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3245 min_partition_order,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3246 max_partition_order,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3247 &frame_header,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3248 encoder->private_->subframe_bps_mid_side[channel],
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3249 encoder->private_->integer_signal_mid_side[channel],
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3250 #ifndef FLAC__INTEGER_ONLY_LIBRARY
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3251 encoder->private_->real_signal_mid_side[channel],
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3252 #endif
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3253 encoder->private_->subframe_workspace_ptr_mid_side[channel],
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3254 encoder->private_->partitioned_rice_contents_workspace_ptr_mid_side[channel],
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3255 encoder->private_->residual_workspace_mid_side[channel],
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3256 encoder->private_->best_subframe_mid_side+channel,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3257 encoder->private_->best_subframe_bits_mid_side+channel
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3258 )
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3259 )
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3260 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3261 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3262 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3263
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3264 /*
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3265 * Compose the frame bitbuffer
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3266 */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3267 if(do_mid_side) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3268 unsigned left_bps = 0, right_bps = 0; /* initialized only to prevent superfluous compiler warning */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3269 FLAC__Subframe *left_subframe = 0, *right_subframe = 0; /* initialized only to prevent superfluous compiler warning */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3270 FLAC__ChannelAssignment channel_assignment;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3271
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3272 FLAC__ASSERT(encoder->protected_->channels == 2);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3273
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3274 if(encoder->protected_->loose_mid_side_stereo && encoder->private_->loose_mid_side_stereo_frame_count > 0) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3275 channel_assignment = (encoder->private_->last_channel_assignment == FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT? FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT : FLAC__CHANNEL_ASSIGNMENT_MID_SIDE);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3276 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3277 else {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3278 unsigned bits[4]; /* WATCHOUT - indexed by FLAC__ChannelAssignment */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3279 unsigned min_bits;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3280 int ca;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3281
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3282 FLAC__ASSERT(FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT == 0);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3283 FLAC__ASSERT(FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE == 1);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3284 FLAC__ASSERT(FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE == 2);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3285 FLAC__ASSERT(FLAC__CHANNEL_ASSIGNMENT_MID_SIDE == 3);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3286 FLAC__ASSERT(do_independent && do_mid_side);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3287
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3288 /* We have to figure out which channel assignent results in the smallest frame */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3289 bits[FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT] = encoder->private_->best_subframe_bits [0] + encoder->private_->best_subframe_bits [1];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3290 bits[FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE ] = encoder->private_->best_subframe_bits [0] + encoder->private_->best_subframe_bits_mid_side[1];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3291 bits[FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE ] = encoder->private_->best_subframe_bits [1] + encoder->private_->best_subframe_bits_mid_side[1];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3292 bits[FLAC__CHANNEL_ASSIGNMENT_MID_SIDE ] = encoder->private_->best_subframe_bits_mid_side[0] + encoder->private_->best_subframe_bits_mid_side[1];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3293
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3294 channel_assignment = FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3295 min_bits = bits[channel_assignment];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3296 for(ca = 1; ca <= 3; ca++) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3297 if(bits[ca] < min_bits) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3298 min_bits = bits[ca];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3299 channel_assignment = (FLAC__ChannelAssignment)ca;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3300 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3301 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3302 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3303
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3304 frame_header.channel_assignment = channel_assignment;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3305
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3306 if(!FLAC__frame_add_header(&frame_header, encoder->private_->frame)) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3307 encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3308 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3309 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3310
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3311 switch(channel_assignment) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3312 case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3313 left_subframe = &encoder->private_->subframe_workspace [0][encoder->private_->best_subframe [0]];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3314 right_subframe = &encoder->private_->subframe_workspace [1][encoder->private_->best_subframe [1]];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3315 break;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3316 case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3317 left_subframe = &encoder->private_->subframe_workspace [0][encoder->private_->best_subframe [0]];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3318 right_subframe = &encoder->private_->subframe_workspace_mid_side[1][encoder->private_->best_subframe_mid_side[1]];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3319 break;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3320 case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3321 left_subframe = &encoder->private_->subframe_workspace_mid_side[1][encoder->private_->best_subframe_mid_side[1]];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3322 right_subframe = &encoder->private_->subframe_workspace [1][encoder->private_->best_subframe [1]];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3323 break;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3324 case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3325 left_subframe = &encoder->private_->subframe_workspace_mid_side[0][encoder->private_->best_subframe_mid_side[0]];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3326 right_subframe = &encoder->private_->subframe_workspace_mid_side[1][encoder->private_->best_subframe_mid_side[1]];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3327 break;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3328 default:
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3329 FLAC__ASSERT(0);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3330 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3331
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3332 switch(channel_assignment) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3333 case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3334 left_bps = encoder->private_->subframe_bps [0];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3335 right_bps = encoder->private_->subframe_bps [1];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3336 break;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3337 case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3338 left_bps = encoder->private_->subframe_bps [0];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3339 right_bps = encoder->private_->subframe_bps_mid_side[1];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3340 break;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3341 case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3342 left_bps = encoder->private_->subframe_bps_mid_side[1];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3343 right_bps = encoder->private_->subframe_bps [1];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3344 break;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3345 case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3346 left_bps = encoder->private_->subframe_bps_mid_side[0];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3347 right_bps = encoder->private_->subframe_bps_mid_side[1];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3348 break;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3349 default:
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3350 FLAC__ASSERT(0);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3351 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3352
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3353 /* note that encoder_add_subframe_ sets the state for us in case of an error */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3354 if(!add_subframe_(encoder, frame_header.blocksize, left_bps , left_subframe , encoder->private_->frame))
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3355 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3356 if(!add_subframe_(encoder, frame_header.blocksize, right_bps, right_subframe, encoder->private_->frame))
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3357 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3358 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3359 else {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3360 if(!FLAC__frame_add_header(&frame_header, encoder->private_->frame)) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3361 encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3362 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3363 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3364
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3365 for(channel = 0; channel < encoder->protected_->channels; channel++) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3366 if(!add_subframe_(encoder, frame_header.blocksize, encoder->private_->subframe_bps[channel], &encoder->private_->subframe_workspace[channel][encoder->private_->best_subframe[channel]], encoder->private_->frame)) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3367 /* the above function sets the state for us in case of an error */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3368 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3369 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3370 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3371 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3372
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3373 if(encoder->protected_->loose_mid_side_stereo) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3374 encoder->private_->loose_mid_side_stereo_frame_count++;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3375 if(encoder->private_->loose_mid_side_stereo_frame_count >= encoder->private_->loose_mid_side_stereo_frames)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3376 encoder->private_->loose_mid_side_stereo_frame_count = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3377 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3378
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3379 encoder->private_->last_channel_assignment = frame_header.channel_assignment;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3380
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3381 return true;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3382 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3383
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3384 FLAC__bool process_subframe_(
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3385 FLAC__StreamEncoder *encoder,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3386 unsigned min_partition_order,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3387 unsigned max_partition_order,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3388 const FLAC__FrameHeader *frame_header,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3389 unsigned subframe_bps,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3390 const FLAC__int32 integer_signal[],
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3391 #ifndef FLAC__INTEGER_ONLY_LIBRARY
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3392 const FLAC__real real_signal[],
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3393 #endif
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3394 FLAC__Subframe *subframe[2],
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3395 FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents[2],
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3396 FLAC__int32 *residual[2],
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3397 unsigned *best_subframe,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3398 unsigned *best_bits
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3399 )
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3400 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3401 #ifndef FLAC__INTEGER_ONLY_LIBRARY
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3402 FLAC__float fixed_residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3403 #else
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3404 FLAC__fixedpoint fixed_residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3405 #endif
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3406 #ifndef FLAC__INTEGER_ONLY_LIBRARY
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3407 FLAC__double lpc_residual_bits_per_sample;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3408 FLAC__real autoc[FLAC__MAX_LPC_ORDER+1]; /* WATCHOUT: the size is important even though encoder->protected_->max_lpc_order might be less; some asm routines need all the space */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3409 FLAC__double lpc_error[FLAC__MAX_LPC_ORDER];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3410 unsigned min_lpc_order, max_lpc_order, lpc_order;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3411 unsigned min_qlp_coeff_precision, max_qlp_coeff_precision, qlp_coeff_precision;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3412 #endif
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3413 unsigned min_fixed_order, max_fixed_order, guess_fixed_order, fixed_order;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3414 unsigned rice_parameter;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3415 unsigned _candidate_bits, _best_bits;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3416 unsigned _best_subframe;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3417
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3418 FLAC__ASSERT(frame_header->blocksize > 0);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3419
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3420 /* verbatim subframe is the baseline against which we measure other compressed subframes */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3421 _best_subframe = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3422 if(encoder->private_->disable_verbatim_subframes && frame_header->blocksize >= FLAC__MAX_FIXED_ORDER)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3423 _best_bits = UINT_MAX;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3424 else
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3425 _best_bits = evaluate_verbatim_subframe_(encoder, integer_signal, frame_header->blocksize, subframe_bps, subframe[_best_subframe]);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3426
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3427 if(frame_header->blocksize >= FLAC__MAX_FIXED_ORDER) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3428 unsigned signal_is_constant = false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3429 guess_fixed_order = encoder->private_->local_fixed_compute_best_predictor(integer_signal+FLAC__MAX_FIXED_ORDER, frame_header->blocksize-FLAC__MAX_FIXED_ORDER, fixed_residual_bits_per_sample);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3430 /* check for constant subframe */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3431 if(
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3432 !encoder->private_->disable_constant_subframes &&
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3433 #ifndef FLAC__INTEGER_ONLY_LIBRARY
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3434 fixed_residual_bits_per_sample[1] == 0.0
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3435 #else
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3436 fixed_residual_bits_per_sample[1] == FLAC__FP_ZERO
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3437 #endif
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3438 ) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3439 /* the above means it's possible all samples are the same value; now double-check it: */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3440 unsigned i;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3441 signal_is_constant = true;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3442 for(i = 1; i < frame_header->blocksize; i++) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3443 if(integer_signal[0] != integer_signal[i]) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3444 signal_is_constant = false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3445 break;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3446 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3447 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3448 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3449 if(signal_is_constant) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3450 _candidate_bits = evaluate_constant_subframe_(encoder, integer_signal[0], frame_header->blocksize, subframe_bps, subframe[!_best_subframe]);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3451 if(_candidate_bits < _best_bits) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3452 _best_subframe = !_best_subframe;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3453 _best_bits = _candidate_bits;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3454 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3455 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3456 else {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3457 if(!encoder->private_->disable_fixed_subframes || (encoder->protected_->max_lpc_order == 0 && _best_bits == UINT_MAX)) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3458 /* encode fixed */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3459 if(encoder->protected_->do_exhaustive_model_search) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3460 min_fixed_order = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3461 max_fixed_order = FLAC__MAX_FIXED_ORDER;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3462 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3463 else {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3464 min_fixed_order = max_fixed_order = guess_fixed_order;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3465 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3466 if(max_fixed_order >= frame_header->blocksize)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3467 max_fixed_order = frame_header->blocksize - 1;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3468 for(fixed_order = min_fixed_order; fixed_order <= max_fixed_order; fixed_order++) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3469 #ifndef FLAC__INTEGER_ONLY_LIBRARY
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3470 if(fixed_residual_bits_per_sample[fixed_order] >= (FLAC__float)subframe_bps)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3471 continue; /* don't even try */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3472 rice_parameter = (fixed_residual_bits_per_sample[fixed_order] > 0.0)? (unsigned)(fixed_residual_bits_per_sample[fixed_order]+0.5) : 0; /* 0.5 is for rounding */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3473 #else
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3474 if(FLAC__fixedpoint_trunc(fixed_residual_bits_per_sample[fixed_order]) >= (int)subframe_bps)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3475 continue; /* don't even try */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3476 rice_parameter = (fixed_residual_bits_per_sample[fixed_order] > FLAC__FP_ZERO)? (unsigned)FLAC__fixedpoint_trunc(fixed_residual_bits_per_sample[fixed_order]+FLAC__FP_ONE_HALF) : 0; /* 0.5 is for rounding */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3477 #endif
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3478 rice_parameter++; /* to account for the signed->unsigned conversion during rice coding */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3479 if(rice_parameter >= FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3480 #ifdef DEBUG_VERBOSE
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3481 fprintf(stderr, "clipping rice_parameter (%u -> %u) @0\n", rice_parameter, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER - 1);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3482 #endif
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3483 rice_parameter = FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER - 1;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3484 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3485 _candidate_bits =
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3486 evaluate_fixed_subframe_(
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3487 encoder,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3488 integer_signal,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3489 residual[!_best_subframe],
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3490 encoder->private_->abs_residual_partition_sums,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3491 encoder->private_->raw_bits_per_partition,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3492 frame_header->blocksize,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3493 subframe_bps,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3494 fixed_order,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3495 rice_parameter,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3496 min_partition_order,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3497 max_partition_order,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3498 encoder->protected_->do_escape_coding,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3499 encoder->protected_->rice_parameter_search_dist,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3500 subframe[!_best_subframe],
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3501 partitioned_rice_contents[!_best_subframe]
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3502 );
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3503 if(_candidate_bits < _best_bits) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3504 _best_subframe = !_best_subframe;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3505 _best_bits = _candidate_bits;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3506 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3507 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3508 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3509
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3510 #ifndef FLAC__INTEGER_ONLY_LIBRARY
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3511 /* encode lpc */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3512 if(encoder->protected_->max_lpc_order > 0) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3513 if(encoder->protected_->max_lpc_order >= frame_header->blocksize)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3514 max_lpc_order = frame_header->blocksize-1;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3515 else
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3516 max_lpc_order = encoder->protected_->max_lpc_order;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3517 if(max_lpc_order > 0) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3518 unsigned a;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3519 for (a = 0; a < encoder->protected_->num_apodizations; a++) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3520 FLAC__lpc_window_data(real_signal, encoder->private_->window[a], encoder->private_->windowed_signal, frame_header->blocksize);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3521 encoder->private_->local_lpc_compute_autocorrelation(encoder->private_->windowed_signal, frame_header->blocksize, max_lpc_order+1, autoc);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3522 /* if autoc[0] == 0.0, the signal is constant and we usually won't get here, but it can happen */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3523 if(autoc[0] != 0.0) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3524 FLAC__lpc_compute_lp_coefficients(autoc, &max_lpc_order, encoder->private_->lp_coeff, lpc_error);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3525 if(encoder->protected_->do_exhaustive_model_search) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3526 min_lpc_order = 1;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3527 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3528 else {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3529 const unsigned guess_lpc_order =
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3530 FLAC__lpc_compute_best_order(
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3531 lpc_error,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3532 max_lpc_order,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3533 frame_header->blocksize,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3534 subframe_bps + (
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3535 encoder->protected_->do_qlp_coeff_prec_search?
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3536 FLAC__MIN_QLP_COEFF_PRECISION : /* have to guess; use the min possible size to avoid accidentally favoring lower orders */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3537 encoder->protected_->qlp_coeff_precision
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3538 )
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3539 );
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3540 min_lpc_order = max_lpc_order = guess_lpc_order;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3541 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3542 if(max_lpc_order >= frame_header->blocksize)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3543 max_lpc_order = frame_header->blocksize - 1;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3544 for(lpc_order = min_lpc_order; lpc_order <= max_lpc_order; lpc_order++) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3545 lpc_residual_bits_per_sample = FLAC__lpc_compute_expected_bits_per_residual_sample(lpc_error[lpc_order-1], frame_header->blocksize-lpc_order);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3546 if(lpc_residual_bits_per_sample >= (FLAC__double)subframe_bps)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3547 continue; /* don't even try */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3548 rice_parameter = (lpc_residual_bits_per_sample > 0.0)? (unsigned)(lpc_residual_bits_per_sample+0.5) : 0; /* 0.5 is for rounding */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3549 rice_parameter++; /* to account for the signed->unsigned conversion during rice coding */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3550 if(rice_parameter >= FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3551 #ifdef DEBUG_VERBOSE
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3552 fprintf(stderr, "clipping rice_parameter (%u -> %u) @1\n", rice_parameter, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER - 1);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3553 #endif
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3554 rice_parameter = FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER - 1;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3555 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3556 if(encoder->protected_->do_qlp_coeff_prec_search) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3557 min_qlp_coeff_precision = FLAC__MIN_QLP_COEFF_PRECISION;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3558 /* try to ensure a 32-bit datapath throughout for 16bps(+1bps for side channel) or less */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3559 if(subframe_bps <= 17) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3560 max_qlp_coeff_precision = min(32 - subframe_bps - lpc_order, FLAC__MAX_QLP_COEFF_PRECISION);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3561 max_qlp_coeff_precision = max(max_qlp_coeff_precision, min_qlp_coeff_precision);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3562 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3563 else
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3564 max_qlp_coeff_precision = FLAC__MAX_QLP_COEFF_PRECISION;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3565 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3566 else {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3567 min_qlp_coeff_precision = max_qlp_coeff_precision = encoder->protected_->qlp_coeff_precision;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3568 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3569 for(qlp_coeff_precision = min_qlp_coeff_precision; qlp_coeff_precision <= max_qlp_coeff_precision; qlp_coeff_precision++) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3570 _candidate_bits =
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3571 evaluate_lpc_subframe_(
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3572 encoder,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3573 integer_signal,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3574 residual[!_best_subframe],
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3575 encoder->private_->abs_residual_partition_sums,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3576 encoder->private_->raw_bits_per_partition,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3577 encoder->private_->lp_coeff[lpc_order-1],
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3578 frame_header->blocksize,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3579 subframe_bps,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3580 lpc_order,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3581 qlp_coeff_precision,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3582 rice_parameter,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3583 min_partition_order,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3584 max_partition_order,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3585 encoder->protected_->do_escape_coding,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3586 encoder->protected_->rice_parameter_search_dist,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3587 subframe[!_best_subframe],
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3588 partitioned_rice_contents[!_best_subframe]
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3589 );
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3590 if(_candidate_bits > 0) { /* if == 0, there was a problem quantizing the lpcoeffs */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3591 if(_candidate_bits < _best_bits) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3592 _best_subframe = !_best_subframe;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3593 _best_bits = _candidate_bits;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3594 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3595 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3596 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3597 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3598 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3599 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3600 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3601 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3602 #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3603 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3604 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3605
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3606 /* under rare circumstances this can happen when all but lpc subframe types are disabled: */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3607 if(_best_bits == UINT_MAX) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3608 FLAC__ASSERT(_best_subframe == 0);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3609 _best_bits = evaluate_verbatim_subframe_(encoder, integer_signal, frame_header->blocksize, subframe_bps, subframe[_best_subframe]);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3610 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3611
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3612 *best_subframe = _best_subframe;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3613 *best_bits = _best_bits;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3614
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3615 return true;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3616 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3617
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3618 FLAC__bool add_subframe_(
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3619 FLAC__StreamEncoder *encoder,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3620 unsigned blocksize,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3621 unsigned subframe_bps,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3622 const FLAC__Subframe *subframe,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3623 FLAC__BitWriter *frame
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3624 )
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3625 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3626 switch(subframe->type) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3627 case FLAC__SUBFRAME_TYPE_CONSTANT:
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3628 if(!FLAC__subframe_add_constant(&(subframe->data.constant), subframe_bps, subframe->wasted_bits, frame)) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3629 encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3630 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3631 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3632 break;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3633 case FLAC__SUBFRAME_TYPE_FIXED:
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3634 if(!FLAC__subframe_add_fixed(&(subframe->data.fixed), blocksize - subframe->data.fixed.order, subframe_bps, subframe->wasted_bits, frame)) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3635 encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3636 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3637 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3638 break;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3639 case FLAC__SUBFRAME_TYPE_LPC:
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3640 if(!FLAC__subframe_add_lpc(&(subframe->data.lpc), blocksize - subframe->data.lpc.order, subframe_bps, subframe->wasted_bits, frame)) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3641 encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3642 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3643 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3644 break;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3645 case FLAC__SUBFRAME_TYPE_VERBATIM:
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3646 if(!FLAC__subframe_add_verbatim(&(subframe->data.verbatim), blocksize, subframe_bps, subframe->wasted_bits, frame)) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3647 encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3648 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3649 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3650 break;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3651 default:
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3652 FLAC__ASSERT(0);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3653 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3654
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3655 return true;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3656 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3657
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3658 #define SPOTCHECK_ESTIMATE 0
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3659 #if SPOTCHECK_ESTIMATE
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3660 static void spotcheck_subframe_estimate_(
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3661 FLAC__StreamEncoder *encoder,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3662 unsigned blocksize,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3663 unsigned subframe_bps,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3664 const FLAC__Subframe *subframe,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3665 unsigned estimate
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3666 )
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3667 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3668 FLAC__bool ret;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3669 FLAC__BitWriter *frame = FLAC__bitwriter_new();
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3670 if(frame == 0) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3671 fprintf(stderr, "EST: can't allocate frame\n");
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3672 return;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3673 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3674 if(!FLAC__bitwriter_init(frame)) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3675 fprintf(stderr, "EST: can't init frame\n");
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3676 return;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3677 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3678 ret = add_subframe_(encoder, blocksize, subframe_bps, subframe, frame);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3679 FLAC__ASSERT(ret);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3680 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3681 const unsigned actual = FLAC__bitwriter_get_input_bits_unconsumed(frame);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3682 if(estimate != actual)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3683 fprintf(stderr, "EST: bad, frame#%u sub#%%d type=%8s est=%u, actual=%u, delta=%d\n", encoder->private_->current_frame_number, FLAC__SubframeTypeString[subframe->type], estimate, actual, (int)actual-(int)estimate);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3684 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3685 FLAC__bitwriter_delete(frame);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3686 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3687 #endif
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3688
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3689 unsigned evaluate_constant_subframe_(
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3690 FLAC__StreamEncoder *encoder,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3691 const FLAC__int32 signal,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3692 unsigned blocksize,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3693 unsigned subframe_bps,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3694 FLAC__Subframe *subframe
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3695 )
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3696 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3697 unsigned estimate;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3698 subframe->type = FLAC__SUBFRAME_TYPE_CONSTANT;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3699 subframe->data.constant.value = signal;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3700
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3701 estimate = FLAC__SUBFRAME_ZERO_PAD_LEN + FLAC__SUBFRAME_TYPE_LEN + FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN + subframe->wasted_bits + subframe_bps;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3702
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3703 #if SPOTCHECK_ESTIMATE
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3704 spotcheck_subframe_estimate_(encoder, blocksize, subframe_bps, subframe, estimate);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3705 #else
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3706 (void)encoder, (void)blocksize;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3707 #endif
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3708
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3709 return estimate;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3710 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3711
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3712 unsigned evaluate_fixed_subframe_(
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3713 FLAC__StreamEncoder *encoder,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3714 const FLAC__int32 signal[],
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3715 FLAC__int32 residual[],
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3716 FLAC__uint64 abs_residual_partition_sums[],
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3717 unsigned raw_bits_per_partition[],
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3718 unsigned blocksize,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3719 unsigned subframe_bps,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3720 unsigned order,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3721 unsigned rice_parameter,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3722 unsigned min_partition_order,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3723 unsigned max_partition_order,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3724 FLAC__bool do_escape_coding,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3725 unsigned rice_parameter_search_dist,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3726 FLAC__Subframe *subframe,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3727 FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3728 )
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3729 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3730 unsigned i, residual_bits, estimate;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3731 const unsigned residual_samples = blocksize - order;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3732
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3733 FLAC__fixed_compute_residual(signal+order, residual_samples, order, residual);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3734
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3735 subframe->type = FLAC__SUBFRAME_TYPE_FIXED;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3736
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3737 subframe->data.fixed.entropy_coding_method.type = FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3738 subframe->data.fixed.entropy_coding_method.data.partitioned_rice.contents = partitioned_rice_contents;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3739 subframe->data.fixed.residual = residual;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3740
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3741 residual_bits =
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3742 find_best_partition_order_(
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3743 encoder->private_,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3744 residual,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3745 abs_residual_partition_sums,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3746 raw_bits_per_partition,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3747 residual_samples,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3748 order,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3749 rice_parameter,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3750 min_partition_order,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3751 max_partition_order,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3752 do_escape_coding,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3753 rice_parameter_search_dist,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3754 &subframe->data.fixed.entropy_coding_method.data.partitioned_rice
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3755 );
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3756
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3757 subframe->data.fixed.order = order;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3758 for(i = 0; i < order; i++)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3759 subframe->data.fixed.warmup[i] = signal[i];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3760
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3761 estimate = FLAC__SUBFRAME_ZERO_PAD_LEN + FLAC__SUBFRAME_TYPE_LEN + FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN + subframe->wasted_bits + (order * subframe_bps) + residual_bits;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3762
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3763 #if SPOTCHECK_ESTIMATE
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3764 spotcheck_subframe_estimate_(encoder, blocksize, subframe_bps, subframe, estimate);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3765 #endif
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3766
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3767 return estimate;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3768 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3769
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3770 #ifndef FLAC__INTEGER_ONLY_LIBRARY
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3771 unsigned evaluate_lpc_subframe_(
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3772 FLAC__StreamEncoder *encoder,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3773 const FLAC__int32 signal[],
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3774 FLAC__int32 residual[],
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3775 FLAC__uint64 abs_residual_partition_sums[],
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3776 unsigned raw_bits_per_partition[],
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3777 const FLAC__real lp_coeff[],
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3778 unsigned blocksize,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3779 unsigned subframe_bps,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3780 unsigned order,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3781 unsigned qlp_coeff_precision,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3782 unsigned rice_parameter,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3783 unsigned min_partition_order,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3784 unsigned max_partition_order,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3785 FLAC__bool do_escape_coding,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3786 unsigned rice_parameter_search_dist,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3787 FLAC__Subframe *subframe,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3788 FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3789 )
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3790 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3791 FLAC__int32 qlp_coeff[FLAC__MAX_LPC_ORDER];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3792 unsigned i, residual_bits, estimate;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3793 int quantization, ret;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3794 const unsigned residual_samples = blocksize - order;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3795
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3796 /* try to keep qlp coeff precision such that only 32-bit math is required for decode of <=16bps streams */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3797 if(subframe_bps <= 16) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3798 FLAC__ASSERT(order > 0);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3799 FLAC__ASSERT(order <= FLAC__MAX_LPC_ORDER);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3800 qlp_coeff_precision = min(qlp_coeff_precision, 32 - subframe_bps - FLAC__bitmath_ilog2(order));
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3801 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3802
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3803 ret = FLAC__lpc_quantize_coefficients(lp_coeff, order, qlp_coeff_precision, qlp_coeff, &quantization);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3804 if(ret != 0)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3805 return 0; /* this is a hack to indicate to the caller that we can't do lp at this order on this subframe */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3806
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3807 if(subframe_bps + qlp_coeff_precision + FLAC__bitmath_ilog2(order) <= 32)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3808 if(subframe_bps <= 16 && qlp_coeff_precision <= 16)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3809 encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bit(signal+order, residual_samples, qlp_coeff, order, quantization, residual);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3810 else
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3811 encoder->private_->local_lpc_compute_residual_from_qlp_coefficients(signal+order, residual_samples, qlp_coeff, order, quantization, residual);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3812 else
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3813 encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_64bit(signal+order, residual_samples, qlp_coeff, order, quantization, residual);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3814
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3815 subframe->type = FLAC__SUBFRAME_TYPE_LPC;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3816
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3817 subframe->data.lpc.entropy_coding_method.type = FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3818 subframe->data.lpc.entropy_coding_method.data.partitioned_rice.contents = partitioned_rice_contents;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3819 subframe->data.lpc.residual = residual;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3820
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3821 residual_bits =
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3822 find_best_partition_order_(
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3823 encoder->private_,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3824 residual,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3825 abs_residual_partition_sums,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3826 raw_bits_per_partition,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3827 residual_samples,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3828 order,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3829 rice_parameter,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3830 min_partition_order,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3831 max_partition_order,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3832 do_escape_coding,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3833 rice_parameter_search_dist,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3834 &subframe->data.lpc.entropy_coding_method.data.partitioned_rice
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3835 );
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3836
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3837 subframe->data.lpc.order = order;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3838 subframe->data.lpc.qlp_coeff_precision = qlp_coeff_precision;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3839 subframe->data.lpc.quantization_level = quantization;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3840 memcpy(subframe->data.lpc.qlp_coeff, qlp_coeff, sizeof(FLAC__int32)*FLAC__MAX_LPC_ORDER);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3841 for(i = 0; i < order; i++)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3842 subframe->data.lpc.warmup[i] = signal[i];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3843
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3844 estimate = FLAC__SUBFRAME_ZERO_PAD_LEN + FLAC__SUBFRAME_TYPE_LEN + FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN + subframe->wasted_bits + FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN + FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN + (order * (qlp_coeff_precision + subframe_bps)) + residual_bits;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3845
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3846 #if SPOTCHECK_ESTIMATE
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3847 spotcheck_subframe_estimate_(encoder, blocksize, subframe_bps, subframe, estimate);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3848 #endif
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3849
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3850 return estimate;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3851 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3852 #endif
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3853
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3854 unsigned evaluate_verbatim_subframe_(
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3855 FLAC__StreamEncoder *encoder,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3856 const FLAC__int32 signal[],
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3857 unsigned blocksize,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3858 unsigned subframe_bps,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3859 FLAC__Subframe *subframe
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3860 )
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3861 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3862 unsigned estimate;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3863
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3864 subframe->type = FLAC__SUBFRAME_TYPE_VERBATIM;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3865
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3866 subframe->data.verbatim.data = signal;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3867
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3868 estimate = FLAC__SUBFRAME_ZERO_PAD_LEN + FLAC__SUBFRAME_TYPE_LEN + FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN + subframe->wasted_bits + (blocksize * subframe_bps);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3869
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3870 #if SPOTCHECK_ESTIMATE
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3871 spotcheck_subframe_estimate_(encoder, blocksize, subframe_bps, subframe, estimate);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3872 #else
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3873 (void)encoder;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3874 #endif
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3875
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3876 return estimate;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3877 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3878
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3879 unsigned find_best_partition_order_(
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3880 FLAC__StreamEncoderPrivate *private_,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3881 const FLAC__int32 residual[],
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3882 FLAC__uint64 abs_residual_partition_sums[],
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3883 unsigned raw_bits_per_partition[],
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3884 unsigned residual_samples,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3885 unsigned predictor_order,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3886 unsigned rice_parameter,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3887 unsigned min_partition_order,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3888 unsigned max_partition_order,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3889 FLAC__bool do_escape_coding,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3890 unsigned rice_parameter_search_dist,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3891 FLAC__EntropyCodingMethod_PartitionedRice *best_partitioned_rice
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3892 )
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3893 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3894 unsigned residual_bits, best_residual_bits = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3895 unsigned best_parameters_index = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3896 const unsigned blocksize = residual_samples + predictor_order;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3897
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3898 max_partition_order = FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_and_predictor_order(max_partition_order, blocksize, predictor_order);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3899 min_partition_order = min(min_partition_order, max_partition_order);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3900
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3901 precompute_partition_info_sums_(residual, abs_residual_partition_sums, residual_samples, predictor_order, min_partition_order, max_partition_order);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3902
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3903 if(do_escape_coding)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3904 precompute_partition_info_escapes_(residual, raw_bits_per_partition, residual_samples, predictor_order, min_partition_order, max_partition_order);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3905
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3906 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3907 int partition_order;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3908 unsigned sum;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3909
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3910 for(partition_order = (int)max_partition_order, sum = 0; partition_order >= (int)min_partition_order; partition_order--) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3911 if(!
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3912 set_partitioned_rice_(
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3913 #ifdef EXACT_RICE_BITS_CALCULATION
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3914 residual,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3915 #endif
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3916 abs_residual_partition_sums+sum,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3917 raw_bits_per_partition+sum,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3918 residual_samples,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3919 predictor_order,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3920 rice_parameter,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3921 rice_parameter_search_dist,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3922 (unsigned)partition_order,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3923 do_escape_coding,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3924 &private_->partitioned_rice_contents_extra[!best_parameters_index],
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3925 &residual_bits
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3926 )
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3927 )
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3928 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3929 FLAC__ASSERT(best_residual_bits != 0);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3930 break;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3931 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3932 sum += 1u << partition_order;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3933 if(best_residual_bits == 0 || residual_bits < best_residual_bits) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3934 best_residual_bits = residual_bits;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3935 best_parameters_index = !best_parameters_index;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3936 best_partitioned_rice->order = partition_order;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3937 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3938 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3939 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3940
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3941 /*
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3942 * We are allowed to de-const the pointer based on our special knowledge;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3943 * it is const to the outside world.
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3944 */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3945 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3946 FLAC__EntropyCodingMethod_PartitionedRiceContents* best_partitioned_rice_contents = (FLAC__EntropyCodingMethod_PartitionedRiceContents*)best_partitioned_rice->contents;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3947 FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(best_partitioned_rice_contents, max(6, best_partitioned_rice->order));
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3948 memcpy(best_partitioned_rice_contents->parameters, private_->partitioned_rice_contents_extra[best_parameters_index].parameters, sizeof(unsigned)*(1<<(best_partitioned_rice->order)));
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3949 memcpy(best_partitioned_rice_contents->raw_bits, private_->partitioned_rice_contents_extra[best_parameters_index].raw_bits, sizeof(unsigned)*(1<<(best_partitioned_rice->order)));
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3950 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3951
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3952 return best_residual_bits;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3953 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3954
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3955 void precompute_partition_info_sums_(
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3956 const FLAC__int32 residual[],
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3957 FLAC__uint64 abs_residual_partition_sums[],
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3958 unsigned residual_samples,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3959 unsigned predictor_order,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3960 unsigned min_partition_order,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3961 unsigned max_partition_order
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3962 )
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3963 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3964 int partition_order;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3965 unsigned from_partition, to_partition = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3966 const unsigned blocksize = residual_samples + predictor_order;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3967
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3968 /* first do max_partition_order */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3969 for(partition_order = (int)max_partition_order; partition_order >= 0; partition_order--) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3970 FLAC__uint64 abs_residual_partition_sum; /* OPT: can reasonably be FLAC__uint32 for bps <= 17 and maybe higher */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3971 unsigned partition, partition_sample, partition_samples, residual_sample;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3972 const unsigned partitions = 1u << partition_order;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3973 const unsigned default_partition_samples = blocksize >> partition_order;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3974
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3975 FLAC__ASSERT(default_partition_samples > predictor_order);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3976
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3977 for(partition = residual_sample = 0; partition < partitions; partition++) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3978 partition_samples = default_partition_samples;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3979 if(partition == 0)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3980 partition_samples -= predictor_order;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3981 abs_residual_partition_sum = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3982 for(partition_sample = 0; partition_sample < partition_samples; partition_sample++, residual_sample++) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3983 #if defined _MSC_VER && _MSC_VER <= 1200
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3984 /* OPT: abs() may be faster for some compilers */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3985 abs_residual_partition_sum += abs(residual[residual_sample]); /* abs(INT_MIN) is undefined, but if the residual is INT_MIN we have bigger problems */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3986 #else
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3987 const FLAC__int32 r = residual[residual_sample];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3988 if(r < 0)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3989 abs_residual_partition_sum -= r;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3990 else
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3991 abs_residual_partition_sum += r;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3992 #endif
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3993 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3994 abs_residual_partition_sums[partition] = abs_residual_partition_sum;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3995 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3996 to_partition = partitions;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3997 break;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3998 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3999
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4000 /* now merge partitions for lower orders */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4001 for(from_partition = 0, --partition_order; partition_order >= (int)min_partition_order; partition_order--) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4002 FLAC__uint64 s;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4003 unsigned i;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4004 const unsigned partitions = 1u << partition_order;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4005 for(i = 0; i < partitions; i++) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4006 s = abs_residual_partition_sums[from_partition];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4007 from_partition++;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4008 abs_residual_partition_sums[to_partition] = s + abs_residual_partition_sums[from_partition];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4009 from_partition++;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4010 to_partition++;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4011 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4012 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4013 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4014
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4015 void precompute_partition_info_escapes_(
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4016 const FLAC__int32 residual[],
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4017 unsigned raw_bits_per_partition[],
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4018 unsigned residual_samples,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4019 unsigned predictor_order,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4020 unsigned min_partition_order,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4021 unsigned max_partition_order
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4022 )
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4023 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4024 int partition_order;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4025 unsigned from_partition, to_partition = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4026 const unsigned blocksize = residual_samples + predictor_order;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4027
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4028 /* first do max_partition_order */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4029 for(partition_order = (int)max_partition_order; partition_order >= 0; partition_order--) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4030 FLAC__int32 r;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4031 FLAC__uint32 rmax;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4032 unsigned partition, partition_sample, partition_samples, residual_sample;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4033 const unsigned partitions = 1u << partition_order;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4034 const unsigned default_partition_samples = blocksize >> partition_order;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4035
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4036 FLAC__ASSERT(default_partition_samples > predictor_order);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4037
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4038 for(partition = residual_sample = 0; partition < partitions; partition++) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4039 partition_samples = default_partition_samples;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4040 if(partition == 0)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4041 partition_samples -= predictor_order;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4042 rmax = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4043 for(partition_sample = 0; partition_sample < partition_samples; partition_sample++) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4044 r = residual[residual_sample++];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4045 if(r < 0)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4046 rmax |= ~r;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4047 else
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4048 rmax |= r;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4049 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4050 /* now we know all residual values are in the range [-rmax-1,rmax] */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4051 raw_bits_per_partition[partition] = rmax? FLAC__bitmath_ilog2(rmax) + 2 : 1;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4052 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4053 to_partition = partitions;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4054 break; /*@@@ yuck, should remove the 'for' loop instead */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4055 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4056
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4057 /* now merge partitions for lower orders */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4058 for(from_partition = 0, --partition_order; partition_order >= (int)min_partition_order; partition_order--) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4059 unsigned m;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4060 unsigned i;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4061 const unsigned partitions = 1u << partition_order;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4062 for(i = 0; i < partitions; i++) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4063 m = raw_bits_per_partition[from_partition];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4064 from_partition++;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4065 raw_bits_per_partition[to_partition] = max(m, raw_bits_per_partition[from_partition]);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4066 from_partition++;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4067 to_partition++;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4068 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4069 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4070 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4071
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4072 #ifdef EXACT_RICE_BITS_CALCULATION
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4073 static __inline unsigned count_rice_bits_in_partition_(
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4074 const unsigned rice_parameter,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4075 const unsigned partition_samples,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4076 const FLAC__int32 *residual
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4077 )
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4078 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4079 unsigned i, partition_bits =
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4080 FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN +
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4081 (1+rice_parameter) * partition_samples /* 1 for unary stop bit + rice_parameter for the binary portion */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4082 ;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4083 for(i = 0; i < partition_samples; i++)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4084 partition_bits += ( (FLAC__uint32)((residual[i]<<1)^(residual[i]>>31)) >> rice_parameter );
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4085 return partition_bits;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4086 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4087 #else
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4088 static __inline unsigned count_rice_bits_in_partition_(
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4089 const unsigned rice_parameter,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4090 const unsigned partition_samples,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4091 const FLAC__uint64 abs_residual_partition_sum
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4092 )
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4093 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4094 return
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4095 FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN +
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4096 (1+rice_parameter) * partition_samples + /* 1 for unary stop bit + rice_parameter for the binary portion */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4097 (
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4098 rice_parameter?
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4099 (unsigned)(abs_residual_partition_sum >> (rice_parameter-1)) /* rice_parameter-1 because the real coder sign-folds instead of using a sign bit */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4100 : (unsigned)(abs_residual_partition_sum << 1) /* can't shift by negative number, so reverse */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4101 )
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4102 - (partition_samples >> 1)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4103 /* -(partition_samples>>1) to subtract out extra contributions to the abs_residual_partition_sum.
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4104 * The actual number of bits used is closer to the sum for all i in the partition of abs(residual[i])>>(rice_parameter-1)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4105 * By using the abs_residual_partition sum, we also add in bits in the LSBs that would normally be shifted out.
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4106 * So the subtraction term tries to guess how many extra bits were contributed.
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4107 * If the LSBs are randomly distributed, this should average to 0.5 extra bits per sample.
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4108 */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4109 ;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4110 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4111 #endif
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4112
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4113 FLAC__bool set_partitioned_rice_(
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4114 #ifdef EXACT_RICE_BITS_CALCULATION
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4115 const FLAC__int32 residual[],
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4116 #endif
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4117 const FLAC__uint64 abs_residual_partition_sums[],
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4118 const unsigned raw_bits_per_partition[],
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4119 const unsigned residual_samples,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4120 const unsigned predictor_order,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4121 const unsigned suggested_rice_parameter,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4122 const unsigned rice_parameter_search_dist,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4123 const unsigned partition_order,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4124 const FLAC__bool search_for_escapes,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4125 FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4126 unsigned *bits
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4127 )
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4128 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4129 unsigned rice_parameter, partition_bits;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4130 unsigned best_partition_bits, best_rice_parameter = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4131 unsigned bits_ = FLAC__ENTROPY_CODING_METHOD_TYPE_LEN + FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4132 unsigned *parameters, *raw_bits;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4133 #ifdef ENABLE_RICE_PARAMETER_SEARCH
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4134 unsigned min_rice_parameter, max_rice_parameter;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4135 #else
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4136 (void)rice_parameter_search_dist;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4137 #endif
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4138
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4139 FLAC__ASSERT(suggested_rice_parameter < FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4140
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4141 FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(partitioned_rice_contents, max(6, partition_order));
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4142 parameters = partitioned_rice_contents->parameters;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4143 raw_bits = partitioned_rice_contents->raw_bits;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4144
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4145 if(partition_order == 0) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4146 best_partition_bits = 0xffffffff;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4147 #ifdef ENABLE_RICE_PARAMETER_SEARCH
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4148 if(rice_parameter_search_dist) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4149 if(suggested_rice_parameter < rice_parameter_search_dist)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4150 min_rice_parameter = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4151 else
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4152 min_rice_parameter = suggested_rice_parameter - rice_parameter_search_dist;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4153 max_rice_parameter = suggested_rice_parameter + rice_parameter_search_dist;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4154 if(max_rice_parameter >= FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4155 #ifdef DEBUG_VERBOSE
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4156 fprintf(stderr, "clipping rice_parameter (%u -> %u) @5\n", max_rice_parameter, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER - 1);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4157 #endif
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4158 max_rice_parameter = FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER - 1;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4159 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4160 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4161 else
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4162 min_rice_parameter = max_rice_parameter = suggested_rice_parameter;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4163
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4164 for(rice_parameter = min_rice_parameter; rice_parameter <= max_rice_parameter; rice_parameter++) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4165 #else
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4166 rice_parameter = suggested_rice_parameter;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4167 #endif
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4168 #ifdef EXACT_RICE_BITS_CALCULATION
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4169 partition_bits = count_rice_bits_in_partition_(rice_parameter, residual_samples, residual);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4170 #else
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4171 partition_bits = count_rice_bits_in_partition_(rice_parameter, residual_samples, abs_residual_partition_sums[0]);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4172 #endif
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4173 if(partition_bits < best_partition_bits) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4174 best_rice_parameter = rice_parameter;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4175 best_partition_bits = partition_bits;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4176 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4177 #ifdef ENABLE_RICE_PARAMETER_SEARCH
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4178 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4179 #endif
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4180 if(search_for_escapes) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4181 partition_bits = FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN + FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN + raw_bits_per_partition[0] * residual_samples;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4182 if(partition_bits <= best_partition_bits) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4183 raw_bits[0] = raw_bits_per_partition[0];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4184 best_rice_parameter = FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4185 best_partition_bits = partition_bits;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4186 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4187 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4188 parameters[0] = best_rice_parameter;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4189 bits_ += best_partition_bits;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4190 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4191 else {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4192 unsigned partition, residual_sample;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4193 unsigned partition_samples;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4194 FLAC__uint64 mean, k;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4195 const unsigned partitions = 1u << partition_order;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4196 for(partition = residual_sample = 0; partition < partitions; partition++) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4197 partition_samples = (residual_samples+predictor_order) >> partition_order;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4198 if(partition == 0) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4199 if(partition_samples <= predictor_order)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4200 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4201 else
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4202 partition_samples -= predictor_order;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4203 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4204 mean = abs_residual_partition_sums[partition];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4205 /* we are basically calculating the size in bits of the
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4206 * average residual magnitude in the partition:
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4207 * rice_parameter = floor(log2(mean/partition_samples))
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4208 * 'mean' is not a good name for the variable, it is
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4209 * actually the sum of magnitudes of all residual values
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4210 * in the partition, so the actual mean is
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4211 * mean/partition_samples
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4212 */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4213 for(rice_parameter = 0, k = partition_samples; k < mean; rice_parameter++, k <<= 1)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4214 ;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4215 if(rice_parameter >= FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4216 #ifdef DEBUG_VERBOSE
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4217 fprintf(stderr, "clipping rice_parameter (%u -> %u) @6\n", rice_parameter, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER - 1);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4218 #endif
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4219 rice_parameter = FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER - 1;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4220 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4221
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4222 best_partition_bits = 0xffffffff;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4223 #ifdef ENABLE_RICE_PARAMETER_SEARCH
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4224 if(rice_parameter_search_dist) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4225 if(rice_parameter < rice_parameter_search_dist)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4226 min_rice_parameter = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4227 else
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4228 min_rice_parameter = rice_parameter - rice_parameter_search_dist;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4229 max_rice_parameter = rice_parameter + rice_parameter_search_dist;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4230 if(max_rice_parameter >= FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4231 #ifdef DEBUG_VERBOSE
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4232 fprintf(stderr, "clipping rice_parameter (%u -> %u) @7\n", max_rice_parameter, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER - 1);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4233 #endif
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4234 max_rice_parameter = FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER - 1;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4235 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4236 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4237 else
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4238 min_rice_parameter = max_rice_parameter = rice_parameter;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4239
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4240 for(rice_parameter = min_rice_parameter; rice_parameter <= max_rice_parameter; rice_parameter++) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4241 #endif
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4242 #ifdef EXACT_RICE_BITS_CALCULATION
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4243 partition_bits = count_rice_bits_in_partition_(rice_parameter, partition_samples, residual+residual_sample);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4244 #else
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4245 partition_bits = count_rice_bits_in_partition_(rice_parameter, partition_samples, abs_residual_partition_sums[partition]);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4246 #endif
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4247 if(partition_bits < best_partition_bits) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4248 best_rice_parameter = rice_parameter;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4249 best_partition_bits = partition_bits;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4250 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4251 #ifdef ENABLE_RICE_PARAMETER_SEARCH
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4252 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4253 #endif
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4254 if(search_for_escapes) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4255 partition_bits = FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN + FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN + raw_bits_per_partition[partition] * partition_samples;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4256 if(partition_bits <= best_partition_bits) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4257 raw_bits[partition] = raw_bits_per_partition[partition];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4258 best_rice_parameter = FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4259 best_partition_bits = partition_bits;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4260 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4261 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4262 parameters[partition] = best_rice_parameter;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4263 bits_ += best_partition_bits;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4264 residual_sample += partition_samples;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4265 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4266 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4267
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4268 *bits = bits_;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4269 return true;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4270 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4271
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4272 unsigned get_wasted_bits_(FLAC__int32 signal[], unsigned samples)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4273 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4274 unsigned i, shift;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4275 FLAC__int32 x = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4276
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4277 for(i = 0; i < samples && !(x&1); i++)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4278 x |= signal[i];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4279
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4280 if(x == 0) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4281 shift = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4282 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4283 else {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4284 for(shift = 0; !(x&1); shift++)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4285 x >>= 1;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4286 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4287
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4288 if(shift > 0) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4289 for(i = 0; i < samples; i++)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4290 signal[i] >>= shift;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4291 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4292
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4293 return shift;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4294 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4295
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4296 void append_to_verify_fifo_(verify_input_fifo *fifo, const FLAC__int32 * const input[], unsigned input_offset, unsigned channels, unsigned wide_samples)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4297 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4298 unsigned channel;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4299
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4300 for(channel = 0; channel < channels; channel++)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4301 memcpy(&fifo->data[channel][fifo->tail], &input[channel][input_offset], sizeof(FLAC__int32) * wide_samples);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4302
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4303 fifo->tail += wide_samples;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4304
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4305 FLAC__ASSERT(fifo->tail <= fifo->size);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4306 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4307
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4308 void append_to_verify_fifo_interleaved_(verify_input_fifo *fifo, const FLAC__int32 input[], unsigned input_offset, unsigned channels, unsigned wide_samples)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4309 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4310 unsigned channel;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4311 unsigned sample, wide_sample;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4312 unsigned tail = fifo->tail;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4313
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4314 sample = input_offset * channels;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4315 for(wide_sample = 0; wide_sample < wide_samples; wide_sample++) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4316 for(channel = 0; channel < channels; channel++)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4317 fifo->data[channel][tail] = input[sample++];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4318 tail++;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4319 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4320 fifo->tail = tail;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4321
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4322 FLAC__ASSERT(fifo->tail <= fifo->size);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4323 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4324
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4325 FLAC__StreamDecoderReadStatus verify_read_callback_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4326 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4327 FLAC__StreamEncoder *encoder = (FLAC__StreamEncoder*)client_data;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4328 const size_t encoded_bytes = encoder->private_->verify.output.bytes;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4329 (void)decoder;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4330
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4331 if(encoder->private_->verify.needs_magic_hack) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4332 FLAC__ASSERT(*bytes >= FLAC__STREAM_SYNC_LENGTH);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4333 *bytes = FLAC__STREAM_SYNC_LENGTH;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4334 memcpy(buffer, FLAC__STREAM_SYNC_STRING, *bytes);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4335 encoder->private_->verify.needs_magic_hack = false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4336 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4337 else {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4338 if(encoded_bytes == 0) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4339 /*
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4340 * If we get here, a FIFO underflow has occurred,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4341 * which means there is a bug somewhere.
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4342 */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4343 FLAC__ASSERT(0);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4344 return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4345 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4346 else if(encoded_bytes < *bytes)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4347 *bytes = encoded_bytes;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4348 memcpy(buffer, encoder->private_->verify.output.data, *bytes);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4349 encoder->private_->verify.output.data += *bytes;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4350 encoder->private_->verify.output.bytes -= *bytes;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4351 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4352
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4353 return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4354 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4355
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4356 FLAC__StreamDecoderWriteStatus verify_write_callback_(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4357 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4358 FLAC__StreamEncoder *encoder = (FLAC__StreamEncoder *)client_data;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4359 unsigned channel;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4360 const unsigned channels = frame->header.channels;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4361 const unsigned blocksize = frame->header.blocksize;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4362 const unsigned bytes_per_block = sizeof(FLAC__int32) * blocksize;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4363
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4364 (void)decoder;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4365
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4366 for(channel = 0; channel < channels; channel++) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4367 if(0 != memcmp(buffer[channel], encoder->private_->verify.input_fifo.data[channel], bytes_per_block)) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4368 unsigned i, sample = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4369 FLAC__int32 expect = 0, got = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4370
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4371 for(i = 0; i < blocksize; i++) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4372 if(buffer[channel][i] != encoder->private_->verify.input_fifo.data[channel][i]) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4373 sample = i;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4374 expect = (FLAC__int32)encoder->private_->verify.input_fifo.data[channel][i];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4375 got = (FLAC__int32)buffer[channel][i];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4376 break;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4377 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4378 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4379 FLAC__ASSERT(i < blocksize);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4380 FLAC__ASSERT(frame->header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4381 encoder->private_->verify.error_stats.absolute_sample = frame->header.number.sample_number + sample;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4382 encoder->private_->verify.error_stats.frame_number = (unsigned)(frame->header.number.sample_number / blocksize);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4383 encoder->private_->verify.error_stats.channel = channel;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4384 encoder->private_->verify.error_stats.sample = sample;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4385 encoder->private_->verify.error_stats.expected = expect;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4386 encoder->private_->verify.error_stats.got = got;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4387 encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4388 return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4389 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4390 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4391 /* dequeue the frame from the fifo */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4392 encoder->private_->verify.input_fifo.tail -= blocksize;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4393 FLAC__ASSERT(encoder->private_->verify.input_fifo.tail <= OVERREAD_);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4394 for(channel = 0; channel < channels; channel++)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4395 memmove(&encoder->private_->verify.input_fifo.data[channel][0], &encoder->private_->verify.input_fifo.data[channel][blocksize], encoder->private_->verify.input_fifo.tail * sizeof(encoder->private_->verify.input_fifo.data[0][0]));
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4396 return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4397 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4398
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4399 void verify_metadata_callback_(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4400 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4401 (void)decoder, (void)metadata, (void)client_data;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4402 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4403
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4404 void verify_error_callback_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4405 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4406 FLAC__StreamEncoder *encoder = (FLAC__StreamEncoder*)client_data;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4407 (void)decoder, (void)status;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4408 encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4409 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4410
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4411 FLAC__StreamEncoderReadStatus file_read_callback_(const FLAC__StreamEncoder *encoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4412 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4413 (void)client_data;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4414
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4415 *bytes = fread(buffer, 1, *bytes, encoder->private_->file);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4416 if (*bytes == 0) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4417 if (feof(encoder->private_->file))
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4418 return FLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4419 else if (ferror(encoder->private_->file))
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4420 return FLAC__STREAM_ENCODER_READ_STATUS_ABORT;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4421 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4422 return FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4423 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4424
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4425 FLAC__StreamEncoderSeekStatus file_seek_callback_(const FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4426 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4427 (void)client_data;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4428
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4429 if(fseeko(encoder->private_->file, (off_t)absolute_byte_offset, SEEK_SET) < 0)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4430 return FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4431 else
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4432 return FLAC__STREAM_ENCODER_SEEK_STATUS_OK;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4433 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4434
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4435 FLAC__StreamEncoderTellStatus file_tell_callback_(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4436 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4437 off_t offset;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4438
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4439 (void)client_data;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4440
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4441 offset = ftello(encoder->private_->file);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4442
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4443 if(offset < 0) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4444 return FLAC__STREAM_ENCODER_TELL_STATUS_ERROR;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4445 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4446 else {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4447 *absolute_byte_offset = (FLAC__uint64)offset;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4448 return FLAC__STREAM_ENCODER_TELL_STATUS_OK;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4449 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4450 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4451
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4452 #ifdef FLAC__VALGRIND_TESTING
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4453 static size_t local__fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4454 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4455 size_t ret = fwrite(ptr, size, nmemb, stream);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4456 if(!ferror(stream))
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4457 fflush(stream);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4458 return ret;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4459 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4460 #else
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4461 #define local__fwrite fwrite
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4462 #endif
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4463
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4464 FLAC__StreamEncoderWriteStatus file_write_callback_(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, unsigned current_frame, void *client_data)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4465 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4466 (void)client_data, (void)current_frame;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4467
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4468 if(local__fwrite(buffer, sizeof(FLAC__byte), bytes, encoder->private_->file) == bytes) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4469 FLAC__bool call_it = 0 != encoder->private_->progress_callback && (
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4470 #if FLAC__HAS_OGG
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4471 /* We would like to be able to use 'samples > 0' in the
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4472 * clause here but currently because of the nature of our
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4473 * Ogg writing implementation, 'samples' is always 0 (see
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4474 * ogg_encoder_aspect.c). The downside is extra progress
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4475 * callbacks.
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4476 */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4477 encoder->private_->is_ogg? true :
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4478 #endif
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4479 samples > 0
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4480 );
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4481 if(call_it) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4482 /* NOTE: We have to add +bytes, +samples, and +1 to the stats
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4483 * because at this point in the callback chain, the stats
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4484 * have not been updated. Only after we return and control
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4485 * gets back to write_frame_() are the stats updated
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4486 */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4487 encoder->private_->progress_callback(encoder, encoder->private_->bytes_written+bytes, encoder->private_->samples_written+samples, encoder->private_->frames_written+(samples?1:0), encoder->private_->total_frames_estimate, encoder->private_->client_data);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4488 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4489 return FLAC__STREAM_ENCODER_WRITE_STATUS_OK;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4490 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4491 else
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4492 return FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4493 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4494
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4495 /*
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4496 * This will forcibly set stdout to binary mode (for OSes that require it)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4497 */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4498 FILE *get_binary_stdout_(void)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4499 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4500 /* if something breaks here it is probably due to the presence or
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4501 * absence of an underscore before the identifiers 'setmode',
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4502 * 'fileno', and/or 'O_BINARY'; check your system header files.
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4503 */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4504 #if defined _MSC_VER || defined __MINGW32__
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4505 _setmode(_fileno(stdout), _O_BINARY);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4506 #elif defined __CYGWIN__
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4507 /* almost certainly not needed for any modern Cygwin, but let's be safe... */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4508 setmode(_fileno(stdout), _O_BINARY);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4509 #elif defined __EMX__
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4510 setmode(fileno(stdout), O_BINARY);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4511 #endif
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4512
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4513 return stdout;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4514 }