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 =
sizeof buffer;
595 for (i = 0;
"vorbis"[i]; i++)
609 buffer_len -= hlens[0];
615 for (i = 0;
"vorbis"[i]; i++)
623 buffer_len -= hlens[1];
629 for (i = 0;
"vorbis"[i]; i++)
643 for (i = 0; i < venc->
nfloors; i++)
674 for (j = 0; j < venc->
channels; j++)
677 for (j = 0; j < mc->
submaps; j++) {
686 for (i = 0; i < venc->
nmodes; i++) {
698 len = hlens[0] + hlens[1] + hlens[2];
707 for (i = 0; i < 3; i++) {
708 memcpy(p, buffer + buffer_len, hlens[i]);
710 buffer_len += hlens[i];
723 for (j = begin; j <
end; j++)
724 average += fabs(coeffs[j]);
725 return average / (end - begin);
729 float *coeffs, uint16_t *posts,
int samples)
733 float tot_average = 0.0;
735 for (i = 0; i < fc->
values; i++) {
737 tot_average += averages[i];
739 tot_average /= fc->
values;
742 for (i = 0; i < fc->
values; i++) {
744 float average = averages[i];
747 average = sqrt(tot_average * average) * pow(1.25f, position*0.005f);
748 for (j = 0; j < range - 1; j++)
757 return y0 + (x - x0) * (y1 - y0) / (x1 - x0);
762 float *floor,
int samples)
773 coded[0] = coded[1] = 1;
775 for (i = 2; i < fc->
values; i++) {
781 int highroom = range - predicted;
782 int lowroom = predicted;
783 int room =
FFMIN(highroom, lowroom);
784 if (predicted == posts[i]) {
793 if (posts[i] > predicted) {
794 if (posts[i] - predicted > room)
795 coded[i] = posts[i] - predicted + lowroom;
797 coded[i] = (posts[i] - predicted) << 1;
799 if (predicted - posts[i] > room)
800 coded[i] = predicted - posts[i] + highroom - 1;
802 coded[i] = ((predicted - posts[i]) << 1) - 1;
809 int k, cval = 0, csub = 1<<c->
subclass;
813 for (k = 0; k < c->
dim; k++) {
815 for (l = 0; l < csub; l++) {
817 if (c->
books[l] != -1)
820 if (coded[counter + k] < maxval)
830 for (k = 0; k < c->
dim; k++) {
831 int book = c->
books[cval & (csub-1)];
832 int entry = coded[counter++];
855 for (i = 0; i < book->
nentries; i++) {
861 d -= vec[j] * num[j];
876 int pass, i, j, p, k;
878 int partitions = (rc->
end - rc->
begin) / psize;
879 int channels = (rc->
type == 2) ? 1 : real_ch;
885 for (p = 0; p < partitions; p++) {
886 float max1 = 0.0, max2 = 0.0;
887 int s = rc->
begin + p * psize;
888 for (k = s; k < s + psize; k += 2) {
889 max1 =
FFMAX(max1, fabs(coeffs[ k / real_ch]));
890 max2 =
FFMAX(max2, fabs(coeffs[samples + k / real_ch]));
894 if (max1 < rc->maxes[i][0] && max2 < rc->maxes[i][1])
899 for (pass = 0; pass < 8; pass++) {
901 while (p < partitions) {
903 for (j = 0; j < channels; j++) {
906 for (i = 0; i < classwords; i++) {
908 entry += classes[j][p + i];
913 for (i = 0; i < classwords && p < partitions; i++, p++) {
914 for (j = 0; j < channels; j++) {
915 int nbook = rc->
books[classes[j][p]][
pass];
917 float *
buf = coeffs + samples*j + rc->
begin + p*psize;
921 assert(rc->
type == 0 || rc->
type == 2);
934 int s = rc->
begin + p * psize,
a1, b1;
935 a1 = (s % real_ch) * samples;
937 s = real_ch * samples;
942 *pv++ = coeffs[a2 + b2];
943 if ((a2 += samples) ==
s) {
952 coeffs[a1 + b1] -= *pv++;
953 if ((a1 += samples) == s) {
968 float **audio,
int samples)
971 const float * win = venc->
win[0];
980 for (channel = 0; channel < venc->
channels; channel++)
981 memcpy(venc->
samples + channel * window_len * 2,
982 venc->
saved + channel * window_len,
sizeof(
float) * window_len);
984 for (channel = 0; channel < venc->
channels; channel++)
985 memset(venc->
samples + channel * window_len * 2, 0,
986 sizeof(
float) * window_len);
990 for (channel = 0; channel < venc->
channels; channel++) {
991 float *
offset = venc->
samples + channel*window_len*2 + window_len;
992 for (i = 0; i < samples; i++)
993 offset[i] = audio[channel][i] / n * win[window_len - i - 1];
996 for (channel = 0; channel < venc->
channels; channel++)
997 memset(venc->
samples + channel * window_len * 2 + window_len,
998 0,
sizeof(
float) * window_len);
1001 for (channel = 0; channel < venc->
channels; channel++)
1003 venc->
samples + channel * window_len * 2);
1006 for (channel = 0; channel < venc->
channels; channel++) {
1007 float *
offset = venc->
saved + channel * window_len;
1008 for (i = 0; i < samples; i++)
1009 offset[i] = audio[channel][i] / n * win[i];
1022 float **audio = frame ? (
float **)frame->
extended_data : NULL;
1049 if (
mode->blockflag) {
1054 for (i = 0; i < venc->
channels; i++) {
1064 for (i = 0; i < venc->
channels * samples; i++)
1067 for (i = 0; i < mapping->coupling_steps; i++) {
1068 float *mag = venc->
coeffs + mapping->magnitude[i] * samples;
1069 float *ang = venc->
coeffs + mapping->angle[i] * samples;
1071 for (j = 0; j < samples; j++) {
1099 *got_packet_ptr = 1;
1120 for (i = 0; i < venc->
nfloors; i++) {
1169 av_log(avctx,
AV_LOG_ERROR,
"Current FFmpeg Vorbis encoder only supports 2 channels.\n");