Mercurial > libavcodec.hg
comparison vorbis_enc.c @ 3913:f2204277a928 libavcodec
Original Commit: r114 | ods15 | 2006-10-01 21:38:37 +0200 (Sun, 01 Oct 2006) | 2 lines
blocksize -> log2_blocksize
author | ods15 |
---|---|
date | Mon, 02 Oct 2006 06:09:52 +0000 |
parents | f56e6d3a1d6e |
children | a4f6e6981930 |
comparison
equal
deleted
inserted
replaced
3912:f56e6d3a1d6e | 3913:f2204277a928 |
---|---|
89 } vorbis_mode_t; | 89 } vorbis_mode_t; |
90 | 90 |
91 typedef struct { | 91 typedef struct { |
92 int channels; | 92 int channels; |
93 int sample_rate; | 93 int sample_rate; |
94 int blocksize[2]; // in (1<<n) format | 94 int log2_blocksize[2]; |
95 MDCTContext mdct[2]; | 95 MDCTContext mdct[2]; |
96 const float * win[2]; | 96 const float * win[2]; |
97 int have_saved; | 97 int have_saved; |
98 float * saved; | 98 float * saved; |
99 float * samples; | 99 float * samples; |
720 mapping_t * mc; | 720 mapping_t * mc; |
721 int i, book; | 721 int i, book; |
722 | 722 |
723 venc->channels = avccontext->channels; | 723 venc->channels = avccontext->channels; |
724 venc->sample_rate = avccontext->sample_rate; | 724 venc->sample_rate = avccontext->sample_rate; |
725 venc->blocksize[0] = venc->blocksize[1] = 11; | 725 venc->log2_blocksize[0] = venc->log2_blocksize[1] = 11; |
726 | 726 |
727 venc->ncodebooks = sizeof(cvectors)/sizeof(cvectors[0]); | 727 venc->ncodebooks = sizeof(cvectors)/sizeof(cvectors[0]); |
728 venc->codebooks = av_malloc(sizeof(codebook_t) * venc->ncodebooks); | 728 venc->codebooks = av_malloc(sizeof(codebook_t) * venc->ncodebooks); |
729 | 729 |
730 // codebook 0..14 - floor1 book, values 0..255 | 730 // codebook 0..14 - floor1 book, values 0..255 |
779 books = (1 << c->subclass); | 779 books = (1 << c->subclass); |
780 c->books = av_malloc(sizeof(int) * books); | 780 c->books = av_malloc(sizeof(int) * books); |
781 for (j = 0; j < books; j++) c->books[j] = floor_classes[i].nbooks[j]; | 781 for (j = 0; j < books; j++) c->books[j] = floor_classes[i].nbooks[j]; |
782 } | 782 } |
783 fc->multiplier = 2; | 783 fc->multiplier = 2; |
784 fc->rangebits = venc->blocksize[0] - 1; | 784 fc->rangebits = venc->log2_blocksize[0] - 1; |
785 | 785 |
786 fc->values = 2; | 786 fc->values = 2; |
787 for (i = 0; i < fc->partitions; i++) | 787 for (i = 0; i < fc->partitions; i++) |
788 fc->values += fc->classes[fc->partition_to_class[i]].dim; | 788 fc->values += fc->classes[fc->partition_to_class[i]].dim; |
789 | 789 |
857 // single mode | 857 // single mode |
858 venc->modes[0].blockflag = 0; | 858 venc->modes[0].blockflag = 0; |
859 venc->modes[0].mapping = 0; | 859 venc->modes[0].mapping = 0; |
860 | 860 |
861 venc->have_saved = 0; | 861 venc->have_saved = 0; |
862 venc->saved = av_malloc(sizeof(float) * venc->channels * (1 << venc->blocksize[1]) / 2); | 862 venc->saved = av_malloc(sizeof(float) * venc->channels * (1 << venc->log2_blocksize[1]) / 2); |
863 venc->samples = av_malloc(sizeof(float) * venc->channels * (1 << venc->blocksize[1])); | 863 venc->samples = av_malloc(sizeof(float) * venc->channels * (1 << venc->log2_blocksize[1])); |
864 venc->floor = av_malloc(sizeof(float) * venc->channels * (1 << venc->blocksize[1]) / 2); | 864 venc->floor = av_malloc(sizeof(float) * venc->channels * (1 << venc->log2_blocksize[1]) / 2); |
865 venc->coeffs = av_malloc(sizeof(float) * venc->channels * (1 << venc->blocksize[1]) / 2); | 865 venc->coeffs = av_malloc(sizeof(float) * venc->channels * (1 << venc->log2_blocksize[1]) / 2); |
866 | 866 |
867 venc->win[0] = ff_vorbis_vwin[venc->blocksize[0] - 6]; | 867 venc->win[0] = ff_vorbis_vwin[venc->log2_blocksize[0] - 6]; |
868 venc->win[1] = ff_vorbis_vwin[venc->blocksize[1] - 6]; | 868 venc->win[1] = ff_vorbis_vwin[venc->log2_blocksize[1] - 6]; |
869 | 869 |
870 ff_mdct_init(&venc->mdct[0], venc->blocksize[0], 0); | 870 ff_mdct_init(&venc->mdct[0], venc->log2_blocksize[0], 0); |
871 ff_mdct_init(&venc->mdct[1], venc->blocksize[1], 0); | 871 ff_mdct_init(&venc->mdct[1], venc->log2_blocksize[1], 0); |
872 } | 872 } |
873 | 873 |
874 static void put_float(PutBitContext * pb, float f) { | 874 static void put_float(PutBitContext * pb, float f) { |
875 int exp, mant; | 875 int exp, mant; |
876 uint32_t res = 0; | 876 uint32_t res = 0; |
1005 put_bits(&pb, 8, venc->channels); | 1005 put_bits(&pb, 8, venc->channels); |
1006 put_bits(&pb, 32, venc->sample_rate); | 1006 put_bits(&pb, 32, venc->sample_rate); |
1007 put_bits(&pb, 32, 0); // bitrate | 1007 put_bits(&pb, 32, 0); // bitrate |
1008 put_bits(&pb, 32, 0); // bitrate | 1008 put_bits(&pb, 32, 0); // bitrate |
1009 put_bits(&pb, 32, 0); // bitrate | 1009 put_bits(&pb, 32, 0); // bitrate |
1010 put_bits(&pb, 4, venc->blocksize[0]); | 1010 put_bits(&pb, 4, venc->log2_blocksize[0]); |
1011 put_bits(&pb, 4, venc->blocksize[1]); | 1011 put_bits(&pb, 4, venc->log2_blocksize[1]); |
1012 put_bits(&pb, 1, 1); // framing | 1012 put_bits(&pb, 1, 1); // framing |
1013 | 1013 |
1014 flush_put_bits(&pb); | 1014 flush_put_bits(&pb); |
1015 hlens[0] = (put_bits_count(&pb) + 7) / 8; | 1015 hlens[0] = (put_bits_count(&pb) + 7) / 8; |
1016 buffer_len -= hlens[0]; | 1016 buffer_len -= hlens[0]; |
1309 } | 1309 } |
1310 | 1310 |
1311 static int apply_window_and_mdct(venc_context_t * venc, signed short * audio, int samples) { | 1311 static int apply_window_and_mdct(venc_context_t * venc, signed short * audio, int samples) { |
1312 int i, j, channel; | 1312 int i, j, channel; |
1313 const float * win = venc->win[0]; | 1313 const float * win = venc->win[0]; |
1314 int window_len = 1 << (venc->blocksize[0] - 1); | 1314 int window_len = 1 << (venc->log2_blocksize[0] - 1); |
1315 float n = (float)(1 << venc->blocksize[0]) / 4.; | 1315 float n = (float)(1 << venc->log2_blocksize[0]) / 4.; |
1316 // FIXME use dsp | 1316 // FIXME use dsp |
1317 | 1317 |
1318 if (!venc->have_saved && !samples) return 0; | 1318 if (!venc->have_saved && !samples) return 0; |
1319 | 1319 |
1320 if (venc->have_saved) { | 1320 if (venc->have_saved) { |
1373 else venc->quality = 1.; | 1373 else venc->quality = 1.; |
1374 venc->quality *= venc->quality; | 1374 venc->quality *= venc->quality; |
1375 | 1375 |
1376 avccontext->extradata_size = put_main_header(venc, (uint8_t**)&avccontext->extradata); | 1376 avccontext->extradata_size = put_main_header(venc, (uint8_t**)&avccontext->extradata); |
1377 | 1377 |
1378 avccontext->frame_size = 1 << (venc->blocksize[0] - 1); | 1378 avccontext->frame_size = 1 << (venc->log2_blocksize[0] - 1); |
1379 | 1379 |
1380 avccontext->coded_frame = avcodec_alloc_frame(); | 1380 avccontext->coded_frame = avcodec_alloc_frame(); |
1381 avccontext->coded_frame->key_frame = 1; | 1381 avccontext->coded_frame->key_frame = 1; |
1382 | 1382 |
1383 return 0; | 1383 return 0; |
1392 mapping_t * mapping; | 1392 mapping_t * mapping; |
1393 PutBitContext pb; | 1393 PutBitContext pb; |
1394 int i; | 1394 int i; |
1395 | 1395 |
1396 if (!apply_window_and_mdct(venc, audio, samples)) return 0; | 1396 if (!apply_window_and_mdct(venc, audio, samples)) return 0; |
1397 samples = 1 << (venc->blocksize[0] - 1); | 1397 samples = 1 << (venc->log2_blocksize[0] - 1); |
1398 | 1398 |
1399 init_put_bits(&pb, packets, buf_size); | 1399 init_put_bits(&pb, packets, buf_size); |
1400 | 1400 |
1401 put_bits(&pb, 1, 0); // magic bit | 1401 put_bits(&pb, 1, 0); // magic bit |
1402 | 1402 |