35 #define BITSTREAM_WRITER_LE
102 int log2_blocksize[2];
130 #define MAX_CHANNELS 2
131 #define MAX_CODEBOOK_DIM 8
133 #define MAX_FLOOR_CLASS_DIM 4
134 #define NUM_FLOOR_PARTITIONS 8
135 #define MAX_FLOOR_VALUES (MAX_FLOOR_CLASS_DIM*NUM_FLOOR_PARTITIONS+2)
137 #define RESIDUE_SIZE 1600
138 #define RESIDUE_PART_SIZE 32
139 #define NUM_RESIDUE_PARTITIONS (RESIDUE_SIZE/RESIDUE_PART_SIZE)
145 assert(entry < cb->nentries);
146 assert(cb->
lens[entry]);
157 else if (lookup == 2)
158 return dimensions *entries;
176 for (i = 0; i < cb->
nentries; i++) {
183 off = (i / div) % vals;
202 assert(rc->
type == 2);
209 for (j = 0; j < 8; j++)
210 if (rc->
books[i][j] != -1)
218 for (j = 0; j < cb->
nentries; j++) {
223 if (a > rc->
maxes[i][0])
226 if (a > rc->
maxes[i][1])
232 rc->
maxes[i][0] += 0.8;
233 rc->
maxes[i][1] += 0.8;
258 for (book = 0; book < venc->
ncodebooks; book++) {
280 for (i = 0; i < vals; i++)
302 static const int a[] = {0, 1, 2, 2, 3, 3, 4, 4};
310 for (i = 0; i < fc->
nclasses; i++) {
320 for (j = 0; j < books; j++)
335 for (i = 2; i < fc->
values; i++) {
336 static const int a[] = {
337 93, 23,372, 6, 46,186,750, 14, 33, 65,
338 130,260,556, 3, 10, 18, 28, 39, 55, 79,
339 111,158,220,312,464,650,850
341 fc->
list[i].
x = a[i - 2];
363 static const int8_t
a[10][8] = {
364 { -1, -1, -1, -1, -1, -1, -1, -1, },
365 { -1, -1, 16, -1, -1, -1, -1, -1, },
366 { -1, -1, 17, -1, -1, -1, -1, -1, },
367 { -1, -1, 18, -1, -1, -1, -1, -1, },
368 { -1, -1, 19, -1, -1, -1, -1, -1, },
369 { -1, -1, 20, -1, -1, -1, -1, -1, },
370 { -1, -1, 21, -1, -1, -1, -1, -1, },
371 { 22, 23, -1, -1, -1, -1, -1, -1, },
372 { 24, 25, -1, -1, -1, -1, -1, -1, },
373 { 26, 27, 28, -1, -1, -1, -1, -1, },
375 memcpy(rc->
books, a,
sizeof a);
391 for (i = 0; i < venc->
channels; i++)
397 for (i = 0; i < mc->
submaps; i++) {
443 mant = (int)ldexp(frexp(f, &exp), 20);
449 res |= mant | (exp << 21);
473 while (i < cb->nentries) {
475 for (j = 0; j+i < cb->
nentries; j++)
476 if (cb->
lens[j+i] != len)
491 for (i = 0; i < cb->
nentries; i++) {
504 for (i = 1; i < tmp; i++)
513 for (i = 0; i < tmp; i++)
529 for (i = 0; i < fc->
nclasses; i++) {
540 for (j = 0; j < books; j++)
547 for (i = 2; i < fc->
values; i++)
565 for (j = 0; j < 8; j++)
566 tmp |= (rc->
books[i][j] != -1) << j;
577 for (j = 0; j < 8; j++)
578 if (rc->
books[i][j] != -1)
588 int buffer_len =
sizeof buffer;
594 for (i = 0;
"vorbis"[i]; i++)
608 buffer_len -= hlens[0];
614 for (i = 0;
"vorbis"[i]; i++)
622 buffer_len -= hlens[1];
628 for (i = 0;
"vorbis"[i]; i++)
642 for (i = 0; i < venc->
nfloors; i++)
673 for (j = 0; j < venc->
channels; j++)
676 for (j = 0; j < mc->
submaps; j++) {
685 for (i = 0; i < venc->
nmodes; i++) {
697 len = hlens[0] + hlens[1] + hlens[2];
706 for (i = 0; i < 3; i++) {
707 memcpy(p, buffer + buffer_len, hlens[i]);
709 buffer_len += hlens[i];
722 for (j = begin; j <
end; j++)
723 average += fabs(coeffs[j]);
724 return average / (end - begin);
732 float tot_average = 0.;
734 for (i = 0; i < fc->
values; i++) {
736 tot_average += averages[i];
738 tot_average /= fc->
values;
741 for (i = 0; i < fc->
values; i++) {
743 float average = averages[i];
746 average = sqrt(tot_average * average) * pow(1.25f, position*0.005f);
747 for (j = 0; j < range - 1; j++)
756 return y0 + (x - x0) * (y1 - y0) / (x1 - x0);
772 coded[0] = coded[1] = 1;
774 for (i = 2; i < fc->
values; i++) {
780 int highroom = range - predicted;
781 int lowroom = predicted;
782 int room =
FFMIN(highroom, lowroom);
783 if (predicted == posts[i]) {
792 if (posts[i] > predicted) {
793 if (posts[i] - predicted > room)
794 coded[i] = posts[i] - predicted + lowroom;
796 coded[i] = (posts[i] - predicted) << 1;
798 if (predicted - posts[i] > room)
799 coded[i] = predicted - posts[i] + highroom - 1;
801 coded[i] = ((predicted - posts[i]) << 1) - 1;
808 int k, cval = 0, csub = 1<<c->
subclass;
812 for (k = 0; k < c->
dim; k++) {
814 for (l = 0; l < csub; l++) {
816 if (c->
books[l] != -1)
819 if (coded[counter + k] < maxval)
829 for (k = 0; k < c->
dim; k++) {
830 int book = c->
books[cval & (csub-1)];
831 int entry = coded[counter++];
854 for (i = 0; i < book->
nentries; i++) {
860 d -= vec[j] * num[j];
875 int pass, i, j, p, k;
877 int partitions = (rc->
end - rc->
begin) / psize;
878 int channels = (rc->
type == 2) ? 1 : real_ch;
882 assert(rc->
type == 2);
883 assert(real_ch == 2);
884 for (p = 0; p < partitions; p++) {
885 float max1 = 0., max2 = 0.;
886 int s = rc->
begin + p * psize;
887 for (k = s; k < s + psize; k += 2) {
888 max1 =
FFMAX(max1, fabs(coeffs[ k / real_ch]));
889 max2 =
FFMAX(max2, fabs(coeffs[samples + k / real_ch]));
893 if (max1 < rc->maxes[i][0] && max2 < rc->maxes[i][1])
898 for (pass = 0; pass < 8; pass++) {
900 while (p < partitions) {
902 for (j = 0; j < channels; j++) {
905 for (i = 0; i < classwords; i++) {
907 entry += classes[j][p + i];
912 for (i = 0; i < classwords && p < partitions; i++, p++) {
913 for (j = 0; j < channels; j++) {
914 int nbook = rc->
books[classes[j][p]][
pass];
916 float *buf = coeffs + samples*j + rc->
begin + p*psize;
920 assert(rc->
type == 0 || rc->
type == 2);
933 int s = rc->
begin + p * psize,
a1, b1;
934 a1 = (s % real_ch) * samples;
941 *pv++ = coeffs[a2 + b2];
942 if ((a2 += samples) == s) {
951 coeffs[a1 + b1] -= *pv++;
952 if ((a1 += samples) == s) {
970 const float * win = venc->
win[0];
979 for (channel = 0; channel < venc->
channels; channel++)
980 memcpy(venc->
samples + channel * window_len * 2,
981 venc->
saved + channel * window_len,
sizeof(
float) * window_len);
983 for (channel = 0; channel < venc->
channels; channel++)
984 memset(venc->
samples + channel * window_len * 2, 0,
985 sizeof(
float) * window_len);
989 for (channel = 0; channel < venc->
channels; channel++) {
990 float *
offset = venc->
samples + channel*window_len*2 + window_len;
992 offset[i] = audio[channel][i] / n * win[window_len - i - 1];
995 for (channel = 0; channel < venc->
channels; channel++)
996 memset(venc->
samples + channel * window_len * 2 + window_len,
997 0,
sizeof(
float) * window_len);
1000 for (channel = 0; channel < venc->
channels; channel++)
1002 venc->
samples + channel * window_len * 2);
1005 for (channel = 0; channel < venc->
channels; channel++) {
1006 float *
offset = venc->
saved + channel * window_len;
1008 offset[i] = audio[channel][i] / n * win[i];
1048 if (
mode->blockflag) {
1053 for (i = 0; i < venc->
channels; i++) {
1066 for (i = 0; i < mapping->coupling_steps; i++) {
1067 float *mag = venc->
coeffs + mapping->magnitude[i] *
samples;
1070 for (j = 0; j <
samples; j++) {
1098 *got_packet_ptr = 1;
1119 for (i = 0; i < venc->
nfloors; i++) {
1157 #if FF_API_OLD_ENCODE_AUDIO
1171 av_log(avccontext,
AV_LOG_ERROR,
"Current FFmpeg Vorbis encoder only supports 2 channels.\n");
1191 #if FF_API_OLD_ENCODE_AUDIO