comparison flacdec.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 2acf888276af
children d6b9123556fb
comparison
equal deleted inserted replaced
9212:c7a8e302b98a 9213:782d31263979
40 #include "internal.h" 40 #include "internal.h"
41 #include "bitstream.h" 41 #include "bitstream.h"
42 #include "bytestream.h" 42 #include "bytestream.h"
43 #include "golomb.h" 43 #include "golomb.h"
44 #include "flac.h" 44 #include "flac.h"
45 #include "flacdata.h"
45 46
46 #undef NDEBUG 47 #undef NDEBUG
47 #include <assert.h> 48 #include <assert.h>
48 49
49 typedef struct FLACContext { 50 typedef struct FLACContext {
64 unsigned int bitstream_size; 65 unsigned int bitstream_size;
65 unsigned int bitstream_index; 66 unsigned int bitstream_index;
66 unsigned int allocated_bitstream_size; 67 unsigned int allocated_bitstream_size;
67 } FLACContext; 68 } FLACContext;
68 69
69 static const int sample_rate_table[] =
70 { 0,
71 88200, 176400, 192000,
72 8000, 16000, 22050, 24000, 32000, 44100, 48000, 96000,
73 0, 0, 0, 0 };
74
75 static const int sample_size_table[] = 70 static const int sample_size_table[] =
76 { 0, 8, 12, 0, 16, 20, 24, 0 }; 71 { 0, 8, 12, 0, 16, 20, 24, 0 };
77
78 static const int blocksize_table[] = {
79 0, 192, 576<<0, 576<<1, 576<<2, 576<<3, 0, 0,
80 256<<0, 256<<1, 256<<2, 256<<3, 256<<4, 256<<5, 256<<6, 256<<7
81 };
82 72
83 static int64_t get_utf8(GetBitContext *gb) 73 static int64_t get_utf8(GetBitContext *gb)
84 { 74 {
85 int64_t val; 75 int64_t val;
86 GET_UTF8(val, get_bits(gb, 8), return -1;) 76 GET_UTF8(val, get_bits(gb, 8), return -1;)
545 } else if (blocksize_code == 6) 535 } else if (blocksize_code == 6)
546 blocksize = get_bits(&s->gb, 8)+1; 536 blocksize = get_bits(&s->gb, 8)+1;
547 else if (blocksize_code == 7) 537 else if (blocksize_code == 7)
548 blocksize = get_bits(&s->gb, 16)+1; 538 blocksize = get_bits(&s->gb, 16)+1;
549 else 539 else
550 blocksize = blocksize_table[blocksize_code]; 540 blocksize = ff_flac_blocksize_table[blocksize_code];
551 541
552 if (blocksize > s->max_blocksize) { 542 if (blocksize > s->max_blocksize) {
553 av_log(s->avctx, AV_LOG_ERROR, "blocksize %d > %d\n", blocksize, 543 av_log(s->avctx, AV_LOG_ERROR, "blocksize %d > %d\n", blocksize,
554 s->max_blocksize); 544 s->max_blocksize);
555 return -1; 545 return -1;
559 return -1; 549 return -1;
560 550
561 if (sample_rate_code == 0) 551 if (sample_rate_code == 0)
562 samplerate= s->samplerate; 552 samplerate= s->samplerate;
563 else if (sample_rate_code < 12) 553 else if (sample_rate_code < 12)
564 samplerate = sample_rate_table[sample_rate_code]; 554 samplerate = ff_flac_sample_rate_table[sample_rate_code];
565 else if (sample_rate_code == 12) 555 else if (sample_rate_code == 12)
566 samplerate = get_bits(&s->gb, 8) * 1000; 556 samplerate = get_bits(&s->gb, 8) * 1000;
567 else if (sample_rate_code == 13) 557 else if (sample_rate_code == 13)
568 samplerate = get_bits(&s->gb, 16); 558 samplerate = get_bits(&s->gb, 16);
569 else if (sample_rate_code == 14) 559 else if (sample_rate_code == 14)