|
|
@ -149,9 +149,9 @@ static void ready_codebook(vorbis_enc_codebook * cb) |
|
|
|
|
|
|
|
|
|
|
|
ff_vorbis_len2vlc(cb->lens, cb->codewords, cb->nentries); |
|
|
|
ff_vorbis_len2vlc(cb->lens, cb->codewords, cb->nentries); |
|
|
|
|
|
|
|
|
|
|
|
if (!cb->lookup) |
|
|
|
if (!cb->lookup) { |
|
|
|
cb->pow2 = cb->dimentions = NULL; |
|
|
|
cb->pow2 = cb->dimentions = NULL; |
|
|
|
else { |
|
|
|
} else { |
|
|
|
int vals = cb_lookup_vals(cb->lookup, cb->ndimentions, cb->nentries); |
|
|
|
int vals = cb_lookup_vals(cb->lookup, cb->ndimentions, cb->nentries); |
|
|
|
cb->dimentions = av_malloc(sizeof(float) * cb->nentries * cb->ndimentions); |
|
|
|
cb->dimentions = av_malloc(sizeof(float) * cb->nentries * cb->ndimentions); |
|
|
|
cb->pow2 = av_mallocz(sizeof(float) * cb->nentries); |
|
|
|
cb->pow2 = av_mallocz(sizeof(float) * cb->nentries); |
|
|
@ -188,8 +188,8 @@ static void ready_residue(vorbis_enc_residue * rc, vorbis_enc_context * venc) |
|
|
|
for (j = 0; j < 8; j++) |
|
|
|
for (j = 0; j < 8; j++) |
|
|
|
if (rc->books[i][j] != -1) |
|
|
|
if (rc->books[i][j] != -1) |
|
|
|
break; |
|
|
|
break; |
|
|
|
if (j == 8) |
|
|
|
if (j == 8) // zero
|
|
|
|
continue; // zero
|
|
|
|
continue; |
|
|
|
cb = &venc->codebooks[rc->books[i][j]]; |
|
|
|
cb = &venc->codebooks[rc->books[i][j]]; |
|
|
|
assert(cb->ndimentions >= 2); |
|
|
|
assert(cb->ndimentions >= 2); |
|
|
|
assert(cb->lookup); |
|
|
|
assert(cb->lookup); |
|
|
@ -772,10 +772,12 @@ static void floor_encode(vorbis_enc_context * venc, vorbis_enc_floor * fc, |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
ff_vorbis_floor1_render_list(fc->list, fc->values, posts, coded, fc->multiplier, floor, samples); |
|
|
|
ff_vorbis_floor1_render_list(fc->list, fc->values, posts, coded, |
|
|
|
|
|
|
|
fc->multiplier, floor, samples); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static float * put_vector(vorbis_enc_codebook * book, PutBitContext * pb, float * num) |
|
|
|
static float *put_vector(vorbis_enc_codebook *book, PutBitContext *pb, |
|
|
|
|
|
|
|
float *num) |
|
|
|
{ |
|
|
|
{ |
|
|
|
int i, entry = -1; |
|
|
|
int i, entry = -1; |
|
|
|
float distance = FLT_MAX; |
|
|
|
float distance = FLT_MAX; |
|
|
@ -885,8 +887,8 @@ static void residue_encode(vorbis_enc_context * venc, vorbis_enc_residue * rc, |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static int apply_window_and_mdct(vorbis_enc_context * venc, |
|
|
|
static int apply_window_and_mdct(vorbis_enc_context *venc, signed short *audio, |
|
|
|
signed short * audio, int samples) |
|
|
|
int samples) |
|
|
|
{ |
|
|
|
{ |
|
|
|
int i, j, channel; |
|
|
|
int i, j, channel; |
|
|
|
const float * win = venc->win[0]; |
|
|
|
const float * win = venc->win[0]; |
|
|
@ -897,12 +899,15 @@ static int apply_window_and_mdct(vorbis_enc_context * venc, |
|
|
|
if (!venc->have_saved && !samples) |
|
|
|
if (!venc->have_saved && !samples) |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
|
|
|
|
|
|
|
|
if (venc->have_saved) |
|
|
|
if (venc->have_saved) { |
|
|
|
for (channel = 0; channel < venc->channels; channel++) |
|
|
|
for (channel = 0; channel < venc->channels; channel++) |
|
|
|
memcpy(venc->samples + channel*window_len*2, venc->saved + channel*window_len, sizeof(float)*window_len); |
|
|
|
memcpy(venc->samples + channel * window_len * 2, |
|
|
|
else |
|
|
|
venc->saved + channel * window_len, sizeof(float) * window_len); |
|
|
|
|
|
|
|
} else { |
|
|
|
for (channel = 0; channel < venc->channels; channel++) |
|
|
|
for (channel = 0; channel < venc->channels; channel++) |
|
|
|
memset(venc->samples + channel*window_len*2, 0, sizeof(float)*window_len); |
|
|
|
memset(venc->samples + channel * window_len * 2, 0, |
|
|
|
|
|
|
|
sizeof(float) * window_len); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (samples) { |
|
|
|
if (samples) { |
|
|
|
for (channel = 0; channel < venc->channels; channel++) { |
|
|
|
for (channel = 0; channel < venc->channels; channel++) { |
|
|
@ -913,11 +918,13 @@ static int apply_window_and_mdct(vorbis_enc_context * venc, |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
for (channel = 0; channel < venc->channels; channel++) |
|
|
|
for (channel = 0; channel < venc->channels; channel++) |
|
|
|
memset(venc->samples + channel*window_len*2 + window_len, 0, sizeof(float)*window_len); |
|
|
|
memset(venc->samples + channel * window_len * 2 + window_len, |
|
|
|
|
|
|
|
0, sizeof(float) * window_len); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
for (channel = 0; channel < venc->channels; channel++) |
|
|
|
for (channel = 0; channel < venc->channels; channel++) |
|
|
|
ff_mdct_calc(&venc->mdct[0], venc->coeffs + channel*window_len, venc->samples + channel*window_len*2); |
|
|
|
ff_mdct_calc(&venc->mdct[0], venc->coeffs + channel * window_len, |
|
|
|
|
|
|
|
venc->samples + channel * window_len * 2); |
|
|
|
|
|
|
|
|
|
|
|
if (samples) { |
|
|
|
if (samples) { |
|
|
|
for (channel = 0; channel < venc->channels; channel++) { |
|
|
|
for (channel = 0; channel < venc->channels; channel++) { |
|
|
@ -960,7 +967,9 @@ static av_cold int vorbis_encode_init(AVCodecContext * avccontext) |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static int vorbis_encode_frame(AVCodecContext * avccontext, unsigned char * packets, int buf_size, void *data) |
|
|
|
static int vorbis_encode_frame(AVCodecContext *avccontext, |
|
|
|
|
|
|
|
unsigned char *packets, |
|
|
|
|
|
|
|
int buf_size, void *data) |
|
|
|
{ |
|
|
|
{ |
|
|
|
vorbis_enc_context *venc = avccontext->priv_data; |
|
|
|
vorbis_enc_context *venc = avccontext->priv_data; |
|
|
|
signed short *audio = data; |
|
|
|
signed short *audio = data; |
|
|
@ -1011,7 +1020,8 @@ static int vorbis_encode_frame(AVCodecContext * avccontext, unsigned char * pack |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
residue_encode(venc, &venc->residues[mapping->residue[mapping->mux[0]]], &pb, venc->coeffs, samples, venc->channels); |
|
|
|
residue_encode(venc, &venc->residues[mapping->residue[mapping->mux[0]]], |
|
|
|
|
|
|
|
&pb, venc->coeffs, samples, venc->channels); |
|
|
|
|
|
|
|
|
|
|
|
avccontext->coded_frame->pts = venc->sample_count; |
|
|
|
avccontext->coded_frame->pts = venc->sample_count; |
|
|
|
venc->sample_count += avccontext->frame_size; |
|
|
|
venc->sample_count += avccontext->frame_size; |
|
|
|