comparison vorbis_enc.c @ 3861:b98ea563e9bc libavcodec

Original Commit: r61 | ods15 | 2006-09-25 13:10:56 +0300 (Mon, 25 Sep 2006) | 2 lines step 2, floor_fit, decides on the values to be encoded
author ods15
date Mon, 02 Oct 2006 06:07:49 +0000
parents be0344cea4ea
children ee9379fc77a9
comparison
equal deleted inserted replaced
3860:be0344cea4ea 3861:b98ea563e9bc
639 p += hlens[i]; 639 p += hlens[i];
640 buffer_len += hlens[i]; 640 buffer_len += hlens[i];
641 } 641 }
642 642
643 return p - *out; 643 return p - *out;
644 }
645
646 static void floor_fit(venc_context_t * venc, floor_t * fc, float * coeffs, int * posts, int samples) {
647 int range = 255 / fc->multiplier + 1;
648 int i;
649 for (i = 0; i < fc->values; i++) {
650 int position = fc->list[fc->list[i].sort].x;
651 int begin = fc->list[fc->list[FFMAX(i-1, 0)].sort].x;
652 int end = fc->list[fc->list[FFMIN(i+1, fc->values - 1)].sort].x;
653 int j;
654 float average = 0;
655 begin = (position + begin) / 2;
656 end = (position + end ) / 2;
657
658 assert(end <= samples);
659 for (j = begin; j < end; j++) average += fabs(coeffs[j]);
660 average /= end - begin;
661 average /= 64; // MAGIC!
662 for (j = 0; j < range; j++) if (floor1_inverse_db_table[j * fc->multiplier] > average) break;
663 posts[fc->list[i].sort] = j;
664 }
644 } 665 }
645 666
646 static void floor_encode(venc_context_t * venc, floor_t * fc, PutBitContext * pb, float * floor, int samples) { 667 static void floor_encode(venc_context_t * venc, floor_t * fc, PutBitContext * pb, float * floor, int samples) {
647 int range = 255 / fc->multiplier + 1; 668 int range = 255 / fc->multiplier + 1;
648 int j; 669 int j;
803 mapping_t * mapping; 824 mapping_t * mapping;
804 PutBitContext pb; 825 PutBitContext pb;
805 int i; 826 int i;
806 827
807 if (!window(venc, audio, samples)) return 0; 828 if (!window(venc, audio, samples)) return 0;
829 samples = 1 << (venc->blocksize[0] - 1);
808 830
809 init_put_bits(&pb, packets, buf_size); 831 init_put_bits(&pb, packets, buf_size);
810 832
811 put_bits(&pb, 1, 0); // magic bit 833 put_bits(&pb, 1, 0); // magic bit
812 834
819 put_bits(&pb, 1, 0); 841 put_bits(&pb, 1, 0);
820 } 842 }
821 843
822 for (i = 0; i < venc->channels; i++) { 844 for (i = 0; i < venc->channels; i++) {
823 floor_t * fc = &venc->floors[mapping->floor[mapping->mux[i]]]; 845 floor_t * fc = &venc->floors[mapping->floor[mapping->mux[i]]];
846 int posts[fc->values];
847 floor_fit(venc, fc, &venc->coeffs[i * samples], posts, samples);
824 floor_encode(venc, fc, &pb, &venc->floor[i * samples], samples); 848 floor_encode(venc, fc, &pb, &venc->floor[i * samples], samples);
825 } 849 }
826 850
827 for (i = 0; i < venc->channels; i++) { 851 for (i = 0; i < venc->channels; i++) {
828 int j; 852 int j;