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)
144 assert(entry < cb->nentries);
145 assert(cb->
lens[entry]);
153 else if (lookup == 2)
154 return dimentions *entries;
172 for (i = 0; i < cb->
nentries; i++) {
179 off = (i / div) % vals;
198 assert(rc->
type == 2);
205 for (j = 0; j < 8; j++)
206 if (rc->
books[i][j] != -1)
214 for (j = 0; j < cb->
nentries; j++) {
219 if (a > rc->
maxes[i][0])
222 if (a > rc->
maxes[i][1])
228 rc->
maxes[i][0] += 0.8;
229 rc->
maxes[i][1] += 0.8;
254 for (book = 0; book < venc->
ncodebooks; book++) {
276 for (i = 0; i < vals; i++)
298 static const int a[] = {0, 1, 2, 2, 3, 3, 4, 4};
306 for (i = 0; i < fc->
nclasses; i++) {
316 for (j = 0; j < books; j++)
331 for (i = 2; i < fc->
values; i++) {
332 static const int a[] = {
333 93, 23,372, 6, 46,186,750, 14, 33, 65,
334 130,260,556, 3, 10, 18, 28, 39, 55, 79,
335 111,158,220,312,464,650,850
337 fc->
list[i].
x = a[i - 2];
359 static const int8_t a[10][8] = {
360 { -1, -1, -1, -1, -1, -1, -1, -1, },
361 { -1, -1, 16, -1, -1, -1, -1, -1, },
362 { -1, -1, 17, -1, -1, -1, -1, -1, },
363 { -1, -1, 18, -1, -1, -1, -1, -1, },
364 { -1, -1, 19, -1, -1, -1, -1, -1, },
365 { -1, -1, 20, -1, -1, -1, -1, -1, },
366 { -1, -1, 21, -1, -1, -1, -1, -1, },
367 { 22, 23, -1, -1, -1, -1, -1, -1, },
368 { 24, 25, -1, -1, -1, -1, -1, -1, },
369 { 26, 27, 28, -1, -1, -1, -1, -1, },
371 memcpy(rc->
books, a,
sizeof a);
387 for (i = 0; i < venc->
channels; i++)
393 for (i = 0; i < mc->
submaps; i++) {
439 mant = (int)ldexp(frexp(f, &exp), 20);
445 res |= mant | (exp << 21);
469 while (i < cb->nentries) {
471 for (j = 0; j+i < cb->
nentries; j++)
472 if (cb->
lens[j+i] != len)
487 for (i = 0; i < cb->
nentries; i++) {
500 for (i = 1; i < tmp; i++)
509 for (i = 0; i < tmp; i++)
525 for (i = 0; i < fc->
nclasses; i++) {
536 for (j = 0; j < books; j++)
543 for (i = 2; i < fc->
values; i++)
561 for (j = 0; j < 8; j++)
562 tmp |= (rc->
books[i][j] != -1) << j;
573 for (j = 0; j < 8; j++)
574 if (rc->
books[i][j] != -1)
584 int buffer_len =
sizeof buffer;
590 for (i = 0;
"vorbis"[i]; i++)
604 buffer_len -= hlens[0];
610 for (i = 0;
"vorbis"[i]; i++)
618 buffer_len -= hlens[1];
624 for (i = 0;
"vorbis"[i]; i++)
638 for (i = 0; i < venc->
nfloors; i++)
669 for (j = 0; j < venc->
channels; j++)
672 for (j = 0; j < mc->
submaps; j++) {
681 for (i = 0; i < venc->
nmodes; i++) {
693 len = hlens[0] + hlens[1] + hlens[2];
702 for (i = 0; i < 3; i++) {
703 memcpy(p, buffer + buffer_len, hlens[i]);
705 buffer_len += hlens[i];
718 for (j = begin; j < end; j++)
719 average += fabs(coeffs[j]);
720 return average / (end - begin);
728 float tot_average = 0.;
730 for (i = 0; i < fc->
values; i++) {
732 tot_average += averages[i];
734 tot_average /= fc->
values;
737 for (i = 0; i < fc->
values; i++) {
739 float average = averages[i];
742 average = sqrt(tot_average * average) * pow(1.25
f, position*0.005
f);
743 for (j = 0; j < range - 1; j++)
752 return y0 + (x - x0) * (y1 - y0) / (x1 - x0);
766 coded[0] = coded[1] = 1;
768 for (i = 2; i < fc->
values; i++) {
774 int highroom = range - predicted;
775 int lowroom = predicted;
776 int room =
FFMIN(highroom, lowroom);
777 if (predicted == posts[i]) {
786 if (posts[i] > predicted) {
787 if (posts[i] - predicted > room)
788 coded[i] = posts[i] - predicted + lowroom;
790 coded[i] = (posts[i] - predicted) << 1;
792 if (predicted - posts[i] > room)
793 coded[i] = predicted - posts[i] + highroom - 1;
795 coded[i] = ((predicted - posts[i]) << 1) - 1;
802 int k, cval = 0, csub = 1<<c->
subclass;
806 for (k = 0; k < c->
dim; k++) {
808 for (l = 0; l < csub; l++) {
810 if (c->
books[l] != -1)
813 if (coded[counter + k] < maxval)
822 for (k = 0; k < c->
dim; k++) {
823 int book = c->
books[cval & (csub-1)];
824 int entry = coded[counter++];
844 for (i = 0; i < book->
nentries; i++) {
850 d -= vec[j] * num[j];
864 int pass, i, j, p, k;
866 int partitions = (rc->
end - rc->
begin) / psize;
867 int channels = (rc->
type == 2) ? 1 : real_ch;
871 assert(rc->
type == 2);
872 assert(real_ch == 2);
873 for (p = 0; p < partitions; p++) {
874 float max1 = 0., max2 = 0.;
875 int s = rc->
begin + p * psize;
876 for (k = s; k < s + psize; k += 2) {
877 max1 =
FFMAX(max1, fabs(coeffs[ k / real_ch]));
878 max2 =
FFMAX(max2, fabs(coeffs[samples + k / real_ch]));
882 if (max1 < rc->maxes[i][0] && max2 < rc->maxes[i][1])
887 for (pass = 0; pass < 8; pass++) {
889 while (p < partitions) {
891 for (j = 0; j < channels; j++) {
894 for (i = 0; i < classwords; i++) {
896 entry += classes[j][p + i];
900 for (i = 0; i < classwords && p < partitions; i++, p++) {
901 for (j = 0; j < channels; j++) {
902 int nbook = rc->
books[classes[j][p]][
pass];
904 float *buf = coeffs + samples*j + rc->
begin + p*psize;
908 assert(rc->
type == 0 || rc->
type == 2);
919 int s = rc->
begin + p * psize,
a1, b1;
920 a1 = (s % real_ch) * samples;
927 *pv++ = coeffs[a2 + b2];
928 if ((a2 += samples) == s) {
935 coeffs[a1 + b1] -= *pv++;
936 if ((a1 += samples) == s) {
953 const float * win = venc->
win[0];
962 for (channel = 0; channel < venc->
channels; channel++)
963 memcpy(venc->
samples + channel * window_len * 2,
964 venc->
saved + channel * window_len,
sizeof(
float) * window_len);
966 for (channel = 0; channel < venc->
channels; channel++)
967 memset(venc->
samples + channel * window_len * 2, 0,
968 sizeof(
float) * window_len);
972 for (channel = 0; channel < venc->
channels; channel++) {
973 float * offset = venc->
samples + channel*window_len*2 + window_len;
976 offset[i] = audio[j] / 32768. / n * win[window_len - i - 1];
979 for (channel = 0; channel < venc->
channels; channel++)
980 memset(venc->
samples + channel * window_len * 2 + window_len,
981 0,
sizeof(
float) * window_len);
984 for (channel = 0; channel < venc->
channels; channel++)
986 venc->
samples + channel * window_len * 2);
989 for (channel = 0; channel < venc->
channels; channel++) {
990 float *offset = venc->
saved + channel * window_len;
993 offset[i] = audio[j] / 32768. / n * win[i];
1004 unsigned char *packets,
1005 int buf_size,
void *
data)
1008 const signed short *audio =
data;
1025 mode = &venc->
modes[0];
1032 for (i = 0; i < venc->
channels; i++) {
1046 for (j = 0; j <
samples; j++) {
1082 for (i = 0; i < venc->
nfloors; i++) {
1132 av_log(avccontext,
AV_LOG_ERROR,
"Current Libav Vorbis encoder only supports 2 channels.\n");