36 #define BITSTREAM_WRITER_LE
103 int log2_blocksize[2];
131 #define MAX_CHANNELS 2
132 #define MAX_CODEBOOK_DIM 8
134 #define MAX_FLOOR_CLASS_DIM 4
135 #define NUM_FLOOR_PARTITIONS 8
136 #define MAX_FLOOR_VALUES (MAX_FLOOR_CLASS_DIM*NUM_FLOOR_PARTITIONS+2)
138 #define RESIDUE_SIZE 1600
139 #define RESIDUE_PART_SIZE 32
140 #define NUM_RESIDUE_PARTITIONS (RESIDUE_SIZE/RESIDUE_PART_SIZE)
158 else if (lookup == 2)
159 return dimensions *entries;
177 for (i = 0; i < cb->
nentries; i++) {
184 off = (i / div) % vals;
210 for (j = 0; j < 8; j++)
211 if (rc->
books[i][j] != -1)
219 for (j = 0; j < cb->
nentries; j++) {
224 if (a > rc->
maxes[i][0])
227 if (a > rc->
maxes[i][1])
233 rc->
maxes[i][0] += 0.8;
234 rc->
maxes[i][1] += 0.8;
259 for (book = 0; book < venc->
ncodebooks; book++) {
281 for (i = 0; i < vals; i++)
303 static const int a[] = {0, 1, 2, 2, 3, 3, 4, 4};
311 for (i = 0; i < fc->
nclasses; i++) {
321 for (j = 0; j < books; j++)
336 for (i = 2; i < fc->
values; i++) {
337 static const int a[] = {
338 93, 23,372, 6, 46,186,750, 14, 33, 65,
339 130,260,556, 3, 10, 18, 28, 39, 55, 79,
340 111,158,220,312,464,650,850
342 fc->
list[i].
x = a[i - 2];
364 static const int8_t
a[10][8] = {
365 { -1, -1, -1, -1, -1, -1, -1, -1, },
366 { -1, -1, 16, -1, -1, -1, -1, -1, },
367 { -1, -1, 17, -1, -1, -1, -1, -1, },
368 { -1, -1, 18, -1, -1, -1, -1, -1, },
369 { -1, -1, 19, -1, -1, -1, -1, -1, },
370 { -1, -1, 20, -1, -1, -1, -1, -1, },
371 { -1, -1, 21, -1, -1, -1, -1, -1, },
372 { 22, 23, -1, -1, -1, -1, -1, -1, },
373 { 24, 25, -1, -1, -1, -1, -1, -1, },
374 { 26, 27, 28, -1, -1, -1, -1, -1, },
376 memcpy(rc->
books, a,
sizeof a);
392 for (i = 0; i < venc->
channels; i++)
398 for (i = 0; i < mc->
submaps; i++) {
444 mant = (int)ldexp(frexp(f, &exp), 20);
450 res |= mant | (exp << 21);
474 while (i < cb->nentries) {
476 for (j = 0; j+i < cb->
nentries; j++)
477 if (cb->
lens[j+i] != len)
492 for (i = 0; i < cb->
nentries; i++) {
505 for (i = 1; i < tmp; i++)
514 for (i = 0; i < tmp; i++)
530 for (i = 0; i < fc->
nclasses; i++) {
541 for (j = 0; j < books; j++)
548 for (i = 2; i < fc->
values; i++)
566 for (j = 0; j < 8; j++)
567 tmp |= (rc->
books[i][j] != -1) << j;
578 for (j = 0; j < 8; j++)
579 if (rc->
books[i][j] != -1)
589 int buffer_len = 50000;
597 for (i = 0;
"vorbis"[i]; i++)
611 buffer_len -= hlens[0];
617 for (i = 0;
"vorbis"[i]; i++)
625 buffer_len -= hlens[1];
631 for (i = 0;
"vorbis"[i]; i++)
645 for (i = 0; i < venc->
nfloors; i++)
676 for (j = 0; j < venc->
channels; j++)
679 for (j = 0; j < mc->
submaps; j++) {
688 for (i = 0; i < venc->
nmodes; i++) {
700 len = hlens[0] + hlens[1] + hlens[2];
709 for (i = 0; i < 3; i++) {
710 memcpy(p, buffer + buffer_len, hlens[i]);
712 buffer_len += hlens[i];
726 for (j = begin; j <
end; j++)
727 average += fabs(coeffs[j]);
728 return average / (end - begin);
732 float *coeffs, uint16_t *posts,
int samples)
736 float tot_average = 0.0;
738 for (i = 0; i < fc->
values; i++) {
740 tot_average += averages[i];
742 tot_average /= fc->
values;
745 for (i = 0; i < fc->
values; i++) {
747 float average = averages[i];
750 average = sqrt(tot_average * average) * pow(1.25f, position*0.005f);
751 for (j = 0; j < range - 1; j++)
760 return y0 + (x - x0) * (y1 - y0) / (x1 - x0);
765 float *floor,
int samples)
776 coded[0] = coded[1] = 1;
778 for (i = 2; i < fc->
values; i++) {
784 int highroom = range - predicted;
785 int lowroom = predicted;
786 int room =
FFMIN(highroom, lowroom);
787 if (predicted == posts[i]) {
796 if (posts[i] > predicted) {
797 if (posts[i] - predicted > room)
798 coded[i] = posts[i] - predicted + lowroom;
800 coded[i] = (posts[i] - predicted) << 1;
802 if (predicted - posts[i] > room)
803 coded[i] = predicted - posts[i] + highroom - 1;
805 coded[i] = ((predicted - posts[i]) << 1) - 1;
812 int k, cval = 0, csub = 1<<c->
subclass;
816 for (k = 0; k < c->
dim; k++) {
818 for (l = 0; l < csub; l++) {
820 if (c->
books[l] != -1)
823 if (coded[counter + k] < maxval)
833 for (k = 0; k < c->
dim; k++) {
834 int book = c->
books[cval & (csub-1)];
835 int entry = coded[counter++];
858 for (i = 0; i < book->
nentries; i++) {
864 d -= vec[j] * num[j];
879 int pass, i, j, p, k;
881 int partitions = (rc->
end - rc->
begin) / psize;
882 int channels = (rc->
type == 2) ? 1 : real_ch;
888 for (p = 0; p < partitions; p++) {
889 float max1 = 0.0, max2 = 0.0;
890 int s = rc->
begin + p * psize;
891 for (k = s; k < s + psize; k += 2) {
892 max1 =
FFMAX(max1, fabs(coeffs[ k / real_ch]));
893 max2 =
FFMAX(max2, fabs(coeffs[samples + k / real_ch]));
897 if (max1 < rc->maxes[i][0] && max2 < rc->maxes[i][1])
902 for (pass = 0; pass < 8; pass++) {
904 while (p < partitions) {
906 for (j = 0; j < channels; j++) {
909 for (i = 0; i < classwords; i++) {
911 entry += classes[j][p + i];
916 for (i = 0; i < classwords && p < partitions; i++, p++) {
917 for (j = 0; j < channels; j++) {
918 int nbook = rc->
books[classes[j][p]][
pass];
920 float *
buf = coeffs + samples*j + rc->
begin + p*psize;
924 assert(rc->
type == 0 || rc->
type == 2);
937 int s = rc->
begin + p * psize,
a1, b1;
938 a1 = (s % real_ch) * samples;
940 s = real_ch * samples;
945 *pv++ = coeffs[a2 + b2];
946 if ((a2 += samples) ==
s) {
955 coeffs[a1 + b1] -= *pv++;
956 if ((a1 += samples) == s) {
971 float **audio,
int samples)
974 const float * win = venc->
win[0];
983 for (channel = 0; channel < venc->
channels; channel++)
984 memcpy(venc->
samples + channel * window_len * 2,
985 venc->
saved + channel * window_len,
sizeof(
float) * window_len);
987 for (channel = 0; channel < venc->
channels; channel++)
988 memset(venc->
samples + channel * window_len * 2, 0,
989 sizeof(
float) * window_len);
993 for (channel = 0; channel < venc->
channels; channel++) {
994 float *
offset = venc->
samples + channel*window_len*2 + window_len;
995 for (i = 0; i < samples; i++)
996 offset[i] = audio[channel][i] / n * win[window_len - i - 1];
999 for (channel = 0; channel < venc->
channels; channel++)
1000 memset(venc->
samples + channel * window_len * 2 + window_len,
1001 0,
sizeof(
float) * window_len);
1004 for (channel = 0; channel < venc->
channels; channel++)
1006 venc->
samples + channel * window_len * 2);
1009 for (channel = 0; channel < venc->
channels; channel++) {
1010 float *
offset = venc->
saved + channel * window_len;
1011 for (i = 0; i < samples; i++)
1012 offset[i] = audio[channel][i] / n * win[i];
1025 float **audio = frame ? (
float **)frame->
extended_data : NULL;
1052 if (
mode->blockflag) {
1057 for (i = 0; i < venc->
channels; i++) {
1067 for (i = 0; i < venc->
channels * samples; i++)
1070 for (i = 0; i < mapping->coupling_steps; i++) {
1071 float *mag = venc->
coeffs + mapping->magnitude[i] * samples;
1072 float *ang = venc->
coeffs + mapping->angle[i] * samples;
1074 for (j = 0; j < samples; j++) {
1102 *got_packet_ptr = 1;
1123 for (i = 0; i < venc->
nfloors; i++) {
1172 av_log(avctx,
AV_LOG_ERROR,
"Current FFmpeg Vorbis encoder only supports 2 channels.\n");