34 #define BITSTREAM_WRITER_LE
101 int log2_blocksize[2];
129 #define MAX_CHANNELS 2
130 #define MAX_CODEBOOK_DIM 8
132 #define MAX_FLOOR_CLASS_DIM 4
133 #define NUM_FLOOR_PARTITIONS 8
134 #define MAX_FLOOR_VALUES (MAX_FLOOR_CLASS_DIM*NUM_FLOOR_PARTITIONS+2)
136 #define RESIDUE_SIZE 1600
137 #define RESIDUE_PART_SIZE 32
138 #define NUM_RESIDUE_PARTITIONS (RESIDUE_SIZE/RESIDUE_PART_SIZE)
156 else if (lookup == 2)
157 return dimensions *entries;
175 for (i = 0; i < cb->
nentries; i++) {
182 off = (i / div) % vals;
208 for (j = 0; j < 8; j++)
209 if (rc->
books[i][j] != -1)
217 for (j = 0; j < cb->
nentries; j++) {
222 if (a > rc->
maxes[i][0])
225 if (a > rc->
maxes[i][1])
231 rc->
maxes[i][0] += 0.8;
232 rc->
maxes[i][1] += 0.8;
257 for (book = 0; book < venc->
ncodebooks; book++) {
279 for (i = 0; i < vals; i++)
301 static const int a[] = {0, 1, 2, 2, 3, 3, 4, 4};
309 for (i = 0; i < fc->
nclasses; i++) {
319 for (j = 0; j < books; j++)
334 for (i = 2; i < fc->
values; i++) {
335 static const int a[] = {
336 93, 23,372, 6, 46,186,750, 14, 33, 65,
337 130,260,556, 3, 10, 18, 28, 39, 55, 79,
338 111,158,220,312,464,650,850
340 fc->
list[i].
x = a[i - 2];
362 static const int8_t
a[10][8] = {
363 { -1, -1, -1, -1, -1, -1, -1, -1, },
364 { -1, -1, 16, -1, -1, -1, -1, -1, },
365 { -1, -1, 17, -1, -1, -1, -1, -1, },
366 { -1, -1, 18, -1, -1, -1, -1, -1, },
367 { -1, -1, 19, -1, -1, -1, -1, -1, },
368 { -1, -1, 20, -1, -1, -1, -1, -1, },
369 { -1, -1, 21, -1, -1, -1, -1, -1, },
370 { 22, 23, -1, -1, -1, -1, -1, -1, },
371 { 24, 25, -1, -1, -1, -1, -1, -1, },
372 { 26, 27, 28, -1, -1, -1, -1, -1, },
374 memcpy(rc->
books, a,
sizeof a);
390 for (i = 0; i < venc->
channels; i++)
396 for (i = 0; i < mc->
submaps; i++) {
442 mant = (int)ldexp(frexp(f, &exp), 20);
448 res |= mant | (exp << 21);
472 while (i < cb->nentries) {
474 for (j = 0; j+i < cb->
nentries; j++)
475 if (cb->
lens[j+i] != len)
490 for (i = 0; i < cb->
nentries; i++) {
503 for (i = 1; i < tmp; i++)
512 for (i = 0; i < tmp; i++)
528 for (i = 0; i < fc->
nclasses; i++) {
539 for (j = 0; j < books; j++)
546 for (i = 2; i < fc->
values; i++)
564 for (j = 0; j < 8; j++)
565 tmp |= (rc->
books[i][j] != -1) << j;
576 for (j = 0; j < 8; j++)
577 if (rc->
books[i][j] != -1)
587 int buffer_len =
sizeof buffer;
593 for (i = 0;
"vorbis"[i]; i++)
607 buffer_len -= hlens[0];
613 for (i = 0;
"vorbis"[i]; i++)
621 buffer_len -= hlens[1];
627 for (i = 0;
"vorbis"[i]; i++)
641 for (i = 0; i < venc->
nfloors; i++)
672 for (j = 0; j < venc->
channels; j++)
675 for (j = 0; j < mc->
submaps; j++) {
684 for (i = 0; i < venc->
nmodes; i++) {
696 len = hlens[0] + hlens[1] + hlens[2];
705 for (i = 0; i < 3; i++) {
706 memcpy(p, buffer + buffer_len, hlens[i]);
708 buffer_len += hlens[i];
721 for (j = begin; j <
end; j++)
722 average += fabs(coeffs[j]);
723 return average / (end - begin);
727 float *
coeffs, uint16_t *posts,
int samples)
731 float tot_average = 0.0;
733 for (i = 0; i < fc->
values; i++) {
735 tot_average += averages[i];
737 tot_average /= fc->
values;
740 for (i = 0; i < fc->
values; i++) {
742 float average = averages[i];
745 average = sqrt(tot_average * average) * pow(1.25f, position*0.005f);
746 for (j = 0; j < range - 1; j++)
755 return y0 + (x - x0) * (y1 - y0) / (x1 - x0);
760 float *floor,
int samples)
771 coded[0] = coded[1] = 1;
773 for (i = 2; i < fc->
values; i++) {
779 int highroom = range - predicted;
780 int lowroom = predicted;
781 int room =
FFMIN(highroom, lowroom);
782 if (predicted == posts[i]) {
791 if (posts[i] > predicted) {
792 if (posts[i] - predicted > room)
793 coded[i] = posts[i] - predicted + lowroom;
795 coded[i] = (posts[i] - predicted) << 1;
797 if (predicted - posts[i] > room)
798 coded[i] = predicted - posts[i] + highroom - 1;
800 coded[i] = ((predicted - posts[i]) << 1) - 1;
807 int k, cval = 0, csub = 1<<c->
subclass;
811 for (k = 0; k < c->
dim; k++) {
813 for (l = 0; l < csub; l++) {
815 if (c->
books[l] != -1)
818 if (coded[counter + k] < maxval)
828 for (k = 0; k < c->
dim; k++) {
829 int book = c->
books[cval & (csub-1)];
830 int entry = coded[counter++];
853 for (i = 0; i < book->
nentries; i++) {
859 d -= vec[j] * num[j];
874 int pass, i, j, p, k;
876 int partitions = (rc->
end - rc->
begin) / psize;
877 int channels = (rc->
type == 2) ? 1 : real_ch;
883 for (p = 0; p < partitions; p++) {
884 float max1 = 0.0, max2 = 0.0;
885 int s = rc->
begin + p * psize;
886 for (k = s; k < s + psize; k += 2) {
887 max1 =
FFMAX(max1, fabs(coeffs[ k / real_ch]));
888 max2 =
FFMAX(max2, fabs(coeffs[samples + k / real_ch]));
892 if (max1 < rc->maxes[i][0] && max2 < rc->maxes[i][1])
897 for (pass = 0; pass < 8; pass++) {
899 while (p < partitions) {
901 for (j = 0; j < channels; j++) {
904 for (i = 0; i < classwords; i++) {
906 entry += classes[j][p + i];
911 for (i = 0; i < classwords && p < partitions; i++, p++) {
912 for (j = 0; j < channels; j++) {
913 int nbook = rc->
books[classes[j][p]][
pass];
915 float *
buf = coeffs + samples*j + rc->
begin + p*psize;
919 assert(rc->
type == 0 || rc->
type == 2);
932 int s = rc->
begin + p * psize,
a1, b1;
933 a1 = (s % real_ch) * samples;
935 s = real_ch * samples;
940 *pv++ = coeffs[a2 + b2];
941 if ((a2 += samples) ==
s) {
950 coeffs[a1 + b1] -= *pv++;
951 if ((a1 += samples) == s) {
966 float **audio,
int samples)
969 const float * win = venc->
win[0];
978 for (channel = 0; channel < venc->
channels; channel++)
979 memcpy(venc->
samples + channel * window_len * 2,
980 venc->
saved + channel * window_len,
sizeof(
float) * window_len);
982 for (channel = 0; channel < venc->
channels; channel++)
983 memset(venc->
samples + channel * window_len * 2, 0,
984 sizeof(
float) * window_len);
988 for (channel = 0; channel < venc->
channels; channel++) {
989 float *
offset = venc->
samples + channel*window_len*2 + window_len;
990 for (i = 0; i < samples; i++)
991 offset[i] = audio[channel][i] / n * win[window_len - i - 1];
994 for (channel = 0; channel < venc->
channels; channel++)
995 memset(venc->
samples + channel * window_len * 2 + window_len,
996 0,
sizeof(
float) * window_len);
999 for (channel = 0; channel < venc->
channels; channel++)
1001 venc->
samples + channel * window_len * 2);
1004 for (channel = 0; channel < venc->
channels; channel++) {
1005 float *
offset = venc->
saved + channel * window_len;
1006 for (i = 0; i < samples; i++)
1007 offset[i] = audio[channel][i] / n * win[i];
1020 float **audio = frame ? (
float **)frame->
extended_data : NULL;
1047 if (
mode->blockflag) {
1052 for (i = 0; i < venc->
channels; i++) {
1062 for (i = 0; i < venc->
channels * samples; i++)
1065 for (i = 0; i < mapping->coupling_steps; i++) {
1066 float *mag = venc->
coeffs + mapping->magnitude[i] * samples;
1067 float *ang = venc->
coeffs + mapping->angle[i] * samples;
1069 for (j = 0; j < samples; j++) {
1097 *got_packet_ptr = 1;
1118 for (i = 0; i < venc->
nfloors; i++) {
1167 av_log(avctx,
AV_LOG_ERROR,
"Current FFmpeg Vorbis encoder only supports 2 channels.\n");