Mercurial > libavcodec.hg
comparison flacenc.c @ 9213:782d31263979 libavcodec
share sample rate and blocksize tables between the FLAC encoder and FLAC
decoder
author | jbr |
---|---|
date | Sat, 21 Mar 2009 01:16:38 +0000 |
parents | c7a8e302b98a |
children | 78b55e071bb9 |
comparison
equal
deleted
inserted
replaced
9212:c7a8e302b98a | 9213:782d31263979 |
---|---|
26 #include "bitstream.h" | 26 #include "bitstream.h" |
27 #include "dsputil.h" | 27 #include "dsputil.h" |
28 #include "golomb.h" | 28 #include "golomb.h" |
29 #include "lpc.h" | 29 #include "lpc.h" |
30 #include "flac.h" | 30 #include "flac.h" |
31 #include "flacdata.h" | |
31 | 32 |
32 #define FLAC_SUBFRAME_CONSTANT 0 | 33 #define FLAC_SUBFRAME_CONSTANT 0 |
33 #define FLAC_SUBFRAME_VERBATIM 1 | 34 #define FLAC_SUBFRAME_VERBATIM 1 |
34 #define FLAC_SUBFRAME_FIXED 8 | 35 #define FLAC_SUBFRAME_FIXED 8 |
35 #define FLAC_SUBFRAME_LPC 32 | 36 #define FLAC_SUBFRAME_LPC 32 |
77 uint8_t crc8; | 78 uint8_t crc8; |
78 int ch_mode; | 79 int ch_mode; |
79 } FlacFrame; | 80 } FlacFrame; |
80 | 81 |
81 typedef struct FlacEncodeContext { | 82 typedef struct FlacEncodeContext { |
83 FLACSTREAMINFO | |
82 PutBitContext pb; | 84 PutBitContext pb; |
83 int channels; | |
84 int samplerate; | |
85 int sr_code[2]; | 85 int sr_code[2]; |
86 int min_framesize; | 86 int min_framesize; |
87 int max_framesize; | |
88 int max_encoded_framesize; | 87 int max_encoded_framesize; |
89 uint32_t frame_count; | 88 uint32_t frame_count; |
90 uint64_t sample_count; | 89 uint64_t sample_count; |
91 uint8_t md5sum[16]; | 90 uint8_t md5sum[16]; |
92 FlacFrame frame; | 91 FlacFrame frame; |
93 CompressionOptions options; | 92 CompressionOptions options; |
94 AVCodecContext *avctx; | 93 AVCodecContext *avctx; |
95 DSPContext dsp; | 94 DSPContext dsp; |
96 struct AVMD5 *md5ctx; | 95 struct AVMD5 *md5ctx; |
97 } FlacEncodeContext; | 96 } FlacEncodeContext; |
98 | |
99 static const int flac_samplerates[16] = { | |
100 0, 0, 0, 0, | |
101 8000, 16000, 22050, 24000, 32000, 44100, 48000, 96000, | |
102 0, 0, 0, 0 | |
103 }; | |
104 | |
105 static const int flac_blocksizes[16] = { | |
106 0, | |
107 192, | |
108 576, 1152, 2304, 4608, | |
109 0, 0, | |
110 256, 512, 1024, 2048, 4096, 8192, 16384, 32768 | |
111 }; | |
112 | 97 |
113 /** | 98 /** |
114 * Writes streaminfo metadata block to byte array | 99 * Writes streaminfo metadata block to byte array |
115 */ | 100 */ |
116 static void write_streaminfo(FlacEncodeContext *s, uint8_t *header) | 101 static void write_streaminfo(FlacEncodeContext *s, uint8_t *header) |
144 int i; | 129 int i; |
145 int target; | 130 int target; |
146 int blocksize; | 131 int blocksize; |
147 | 132 |
148 assert(samplerate > 0); | 133 assert(samplerate > 0); |
149 blocksize = flac_blocksizes[1]; | 134 blocksize = ff_flac_blocksize_table[1]; |
150 target = (samplerate * block_time_ms) / 1000; | 135 target = (samplerate * block_time_ms) / 1000; |
151 for(i=0; i<16; i++) { | 136 for(i=0; i<16; i++) { |
152 if(target >= flac_blocksizes[i] && flac_blocksizes[i] > blocksize) { | 137 if(target >= ff_flac_blocksize_table[i] && ff_flac_blocksize_table[i] > blocksize) { |
153 blocksize = flac_blocksizes[i]; | 138 blocksize = ff_flac_blocksize_table[i]; |
154 } | 139 } |
155 } | 140 } |
156 return blocksize; | 141 return blocksize; |
157 } | 142 } |
158 | 143 |
179 | 164 |
180 /* find samplerate in table */ | 165 /* find samplerate in table */ |
181 if(freq < 1) | 166 if(freq < 1) |
182 return -1; | 167 return -1; |
183 for(i=4; i<12; i++) { | 168 for(i=4; i<12; i++) { |
184 if(freq == flac_samplerates[i]) { | 169 if(freq == ff_flac_sample_rate_table[i]) { |
185 s->samplerate = flac_samplerates[i]; | 170 s->samplerate = ff_flac_sample_rate_table[i]; |
186 s->sr_code[0] = i; | 171 s->sr_code[0] = i; |
187 s->sr_code[1] = 0; | 172 s->sr_code[1] = 0; |
188 break; | 173 break; |
189 } | 174 } |
190 } | 175 } |
390 FlacFrame *frame; | 375 FlacFrame *frame; |
391 | 376 |
392 frame = &s->frame; | 377 frame = &s->frame; |
393 | 378 |
394 for(i=0; i<16; i++) { | 379 for(i=0; i<16; i++) { |
395 if(s->avctx->frame_size == flac_blocksizes[i]) { | 380 if(s->avctx->frame_size == ff_flac_blocksize_table[i]) { |
396 frame->blocksize = flac_blocksizes[i]; | 381 frame->blocksize = ff_flac_blocksize_table[i]; |
397 frame->bs_code[0] = i; | 382 frame->bs_code[0] = i; |
398 frame->bs_code[1] = 0; | 383 frame->bs_code[1] = 0; |
399 break; | 384 break; |
400 } | 385 } |
401 } | 386 } |