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;
170 for (i = 0; i < cb->
nentries; i++) {
177 off = (i / div) % vals;
195 assert(rc->
type == 2);
200 for (j = 0; j < 8; j++)
201 if (rc->
books[i][j] != -1)
209 for (j = 0; j < cb->
nentries; j++) {
214 if (a > rc->
maxes[i][0])
217 if (a > rc->
maxes[i][1])
223 rc->
maxes[i][0] += 0.8;
224 rc->
maxes[i][1] += 0.8;
246 for (book = 0; book < venc->
ncodebooks; book++) {
264 for (i = 0; i < vals; i++)
281 static const int a[] = {0, 1, 2, 2, 3, 3, 4, 4};
287 for (i = 0; i < fc->
nclasses; i++) {
295 for (j = 0; j < books; j++)
308 for (i = 2; i < fc->
values; i++) {
309 static const int a[] = {
310 93, 23,372, 6, 46,186,750, 14, 33, 65,
311 130,260,556, 3, 10, 18, 28, 39, 55, 79,
312 111,158,220,312,464,650,850
314 fc->
list[i].
x = a[i - 2];
331 static const int8_t a[10][8] = {
332 { -1, -1, -1, -1, -1, -1, -1, -1, },
333 { -1, -1, 16, -1, -1, -1, -1, -1, },
334 { -1, -1, 17, -1, -1, -1, -1, -1, },
335 { -1, -1, 18, -1, -1, -1, -1, -1, },
336 { -1, -1, 19, -1, -1, -1, -1, -1, },
337 { -1, -1, 20, -1, -1, -1, -1, -1, },
338 { -1, -1, 21, -1, -1, -1, -1, -1, },
339 { 22, 23, -1, -1, -1, -1, -1, -1, },
340 { 24, 25, -1, -1, -1, -1, -1, -1, },
341 { 26, 27, 28, -1, -1, -1, -1, -1, },
343 memcpy(rc->
books, a,
sizeof a);
354 for (i = 0; i < venc->
channels; i++)
358 for (i = 0; i < mc->
submaps; i++) {
394 mant = (int)ldexp(frexp(f, &exp), 20);
400 res |= mant | (exp << 21);
424 while (i < cb->nentries) {
426 for (j = 0; j+i < cb->
nentries; j++)
427 if (cb->
lens[j+i] != len)
442 for (i = 0; i < cb->
nentries; i++) {
455 for (i = 1; i < tmp; i++)
464 for (i = 0; i < tmp; i++)
480 for (i = 0; i < fc->
nclasses; i++) {
491 for (j = 0; j < books; j++)
498 for (i = 2; i < fc->
values; i++)
516 for (j = 0; j < 8; j++)
517 tmp |= (rc->
books[i][j] != -1) << j;
528 for (j = 0; j < 8; j++)
529 if (rc->
books[i][j] != -1)
539 int buffer_len =
sizeof buffer;
545 for (i = 0;
"vorbis"[i]; i++)
559 buffer_len -= hlens[0];
565 for (i = 0;
"vorbis"[i]; i++)
573 buffer_len -= hlens[1];
579 for (i = 0;
"vorbis"[i]; i++)
593 for (i = 0; i < venc->
nfloors; i++)
624 for (j = 0; j < venc->
channels; j++)
627 for (j = 0; j < mc->
submaps; j++) {
636 for (i = 0; i < venc->
nmodes; i++) {
648 len = hlens[0] + hlens[1] + hlens[2];
655 for (i = 0; i < 3; i++) {
656 memcpy(p, buffer + buffer_len, hlens[i]);
658 buffer_len += hlens[i];
671 for (j = begin; j < end; j++)
672 average += fabs(coeffs[j]);
673 return average / (end - begin);
681 float tot_average = 0.;
683 for (i = 0; i < fc->
values; i++) {
685 tot_average += averages[i];
687 tot_average /= fc->
values;
690 for (i = 0; i < fc->
values; i++) {
692 float average = averages[i];
695 average = sqrt(tot_average * average) * pow(1.25
f, position*0.005
f);
696 for (j = 0; j < range - 1; j++)
705 return y0 + (x - x0) * (y1 - y0) / (x1 - x0);
719 coded[0] = coded[1] = 1;
721 for (i = 2; i < fc->
values; i++) {
727 int highroom = range - predicted;
728 int lowroom = predicted;
729 int room =
FFMIN(highroom, lowroom);
730 if (predicted == posts[i]) {
739 if (posts[i] > predicted) {
740 if (posts[i] - predicted > room)
741 coded[i] = posts[i] - predicted + lowroom;
743 coded[i] = (posts[i] - predicted) << 1;
745 if (predicted - posts[i] > room)
746 coded[i] = predicted - posts[i] + highroom - 1;
748 coded[i] = ((predicted - posts[i]) << 1) - 1;
755 int k, cval = 0, csub = 1<<c->
subclass;
759 for (k = 0; k < c->
dim; k++) {
761 for (l = 0; l < csub; l++) {
763 if (c->
books[l] != -1)
766 if (coded[counter + k] < maxval)
775 for (k = 0; k < c->
dim; k++) {
776 int book = c->
books[cval & (csub-1)];
777 int entry = coded[counter++];
797 for (i = 0; i < book->
nentries; i++) {
803 d -= vec[j] * num[j];
817 int pass, i, j, p, k;
819 int partitions = (rc->
end - rc->
begin) / psize;
820 int channels = (rc->
type == 2) ? 1 : real_ch;
824 assert(rc->
type == 2);
825 assert(real_ch == 2);
826 for (p = 0; p < partitions; p++) {
827 float max1 = 0., max2 = 0.;
828 int s = rc->
begin + p * psize;
829 for (k = s; k < s + psize; k += 2) {
830 max1 =
FFMAX(max1, fabs(coeffs[ k / real_ch]));
831 max2 =
FFMAX(max2, fabs(coeffs[samples + k / real_ch]));
835 if (max1 < rc->maxes[i][0] && max2 < rc->maxes[i][1])
840 for (pass = 0; pass < 8; pass++) {
842 while (p < partitions) {
844 for (j = 0; j < channels; j++) {
847 for (i = 0; i < classwords; i++) {
849 entry += classes[j][p + i];
853 for (i = 0; i < classwords && p < partitions; i++, p++) {
854 for (j = 0; j < channels; j++) {
855 int nbook = rc->
books[classes[j][p]][
pass];
857 float *buf = coeffs + samples*j + rc->
begin + p*psize;
861 assert(rc->
type == 0 || rc->
type == 2);
872 int s = rc->
begin + p * psize,
a1, b1;
873 a1 = (s % real_ch) * samples;
880 *pv++ = coeffs[a2 + b2];
881 if ((a2 += samples) == s) {
888 coeffs[a1 + b1] -= *pv++;
889 if ((a1 += samples) == s) {
906 const float * win = venc->
win[0];
915 for (channel = 0; channel < venc->
channels; channel++)
916 memcpy(venc->
samples + channel * window_len * 2,
917 venc->
saved + channel * window_len,
sizeof(
float) * window_len);
919 for (channel = 0; channel < venc->
channels; channel++)
920 memset(venc->
samples + channel * window_len * 2, 0,
921 sizeof(
float) * window_len);
925 for (channel = 0; channel < venc->
channels; channel++) {
926 float * offset = venc->
samples + channel*window_len*2 + window_len;
929 offset[i] = audio[j] / 32768. / n * win[window_len - i - 1];
932 for (channel = 0; channel < venc->
channels; channel++)
933 memset(venc->
samples + channel * window_len * 2 + window_len,
934 0,
sizeof(
float) * window_len);
937 for (channel = 0; channel < venc->
channels; channel++)
939 venc->
samples + channel * window_len * 2);
942 for (channel = 0; channel < venc->
channels; channel++) {
943 float *offset = venc->
saved + channel * window_len;
946 offset[i] = audio[j] / 32768. / n * win[i];
960 av_log(avccontext,
AV_LOG_ERROR,
"Current Libav Vorbis encoder only supports 2 channels.\n");
983 unsigned char *packets,
984 int buf_size,
void *
data)
987 const signed short *audio =
data;
1004 mode = &venc->
modes[0];
1011 for (i = 0; i < venc->
channels; i++) {
1025 for (j = 0; j <
samples; j++) {
1061 for (i = 0; i < venc->
nfloors; i++) {