# HG changeset patch # User nicodvb # Date 1114425475 0 # Node ID 92772475ed8d2f9ea85d4d30a1e342f35d751cb4 # Parent 1692cd76d52a9094908726a53f74e9130eea53fc toolame now works in vbr mode, too diff -r 1692cd76d52a -r 92772475ed8d libmpcodecs/ae_toolame.c --- a/libmpcodecs/ae_toolame.c Mon Apr 25 09:20:21 2005 +0000 +++ b/libmpcodecs/ae_toolame.c Mon Apr 25 10:37:55 2005 +0000 @@ -17,7 +17,7 @@ static int param_bitrate = 192, param_psy = 3, - param_maxvbr = 192, + param_maxvbr = 0, param_errprot = 0, param_debug = 0; @@ -38,29 +38,31 @@ static int bind_toolame(audio_encoder_t *encoder, muxer_stream_t *mux_a) { + mpae_toolame_ctx *ctx = (mpae_toolame_ctx *) encoder->priv; + mux_a->wf = malloc(sizeof(WAVEFORMATEX)+256); mux_a->wf->wFormatTag = 0x50; mux_a->wf->nChannels = encoder->params.channels; mux_a->wf->nSamplesPerSec = encoder->params.sample_rate; mux_a->wf->nAvgBytesPerSec = 125 * encoder->params.bitrate; - mux_a->h.dwRate = mux_a->wf->nAvgBytesPerSec; - mux_a->h.dwScale = (mux_a->wf->nAvgBytesPerSec * encoder->params.samples_per_frame)/ mux_a->wf->nSamplesPerSec; /* for cbr */ - if((mux_a->wf->nAvgBytesPerSec * encoder->params.samples_per_frame) % mux_a->wf->nSamplesPerSec) + if(ctx->vbr || ((mux_a->wf->nAvgBytesPerSec * encoder->params.samples_per_frame) % mux_a->wf->nSamplesPerSec)) { mux_a->h.dwScale = encoder->params.samples_per_frame; mux_a->h.dwRate = encoder->params.sample_rate; mux_a->h.dwSampleSize = 0; // Blocksize not constant - } - else + } + else { + mux_a->h.dwScale = (mux_a->wf->nAvgBytesPerSec * encoder->params.samples_per_frame)/ mux_a->wf->nSamplesPerSec; /* for cbr */ + mux_a->h.dwRate = mux_a->wf->nAvgBytesPerSec; mux_a->h.dwSampleSize = mux_a->h.dwScale; } mux_a->wf->nBlockAlign = mux_a->h.dwScale; mux_a->h.dwSuggestedBufferSize = (encoder->params.audio_preload*mux_a->wf->nAvgBytesPerSec)/1000; mux_a->h.dwSuggestedBufferSize -= mux_a->h.dwSuggestedBufferSize % mux_a->wf->nBlockAlign; - mux_a->wf->cbSize = 12; + mux_a->wf->cbSize = 0; //12; mux_a->wf->wBitsPerSample = 0; /* does not apply */ ((MPEGLAYER3WAVEFORMAT *) (mux_a->wf))->wID = 1; ((MPEGLAYER3WAVEFORMAT *) (mux_a->wf))->fdwFlags = 2; @@ -81,7 +83,7 @@ static int encode_toolame(audio_encoder_t *encoder, uint8_t *dest, void *src, int len, int max_size) { mpae_toolame_ctx *ctx = (mpae_toolame_ctx *)encoder->priv; - int ret_size = 0, i, nsamples; + int ret_size = 0, r2, i, nsamples; int16_t *buffer; nsamples = len / (2*encoder->params.channels); @@ -93,6 +95,10 @@ } toolame_encode_buffer(ctx->toolame_ctx, ctx->left_pcm, ctx->right_pcm, nsamples, dest, max_size, &ret_size); + r2 = mp_decode_mp3_header(dest); + mp_msg(MSGT_MENCODER, MSGL_V, "\nSIZE: %d, max: %d, r2: %d\n", ret_size, max_size, r2); + if(r2 > 0) + ret_size = r2; return ret_size; } @@ -154,6 +160,7 @@ free(ctx); return 0; } + ctx->vbr = 0; ctx->channels = encoder->params.channels; ctx->srate = encoder->params.sample_rate; @@ -177,12 +184,16 @@ { if(toolame_setVBR(ctx->toolame_ctx, TRUE) != 0) return 0; - if(toolame_setVBRLevel(ctx->toolame_ctx, param_maxvbr) != 0) + if(toolame_setVBRLevel(ctx->toolame_ctx, param_vbr) != 0) return 0; if(toolame_setPadding(ctx->toolame_ctx, FALSE) != 0) return 0; - if(toolame_setVBRUpperBitrate(ctx->toolame_ctx, param_maxvbr) != 0) - return 0; + if(param_maxvbr) + { + if(toolame_setVBRUpperBitrate(ctx->toolame_ctx, param_maxvbr) != 0) + return 0; + } + ctx->vbr = 1; } if(toolame_setVerbosity(ctx->toolame_ctx, param_debug) != 0) diff -r 1692cd76d52a -r 92772475ed8d libmpcodecs/ae_toolame.h --- a/libmpcodecs/ae_toolame.h Mon Apr 25 09:20:21 2005 +0000 +++ b/libmpcodecs/ae_toolame.h Mon Apr 25 10:37:55 2005 +0000 @@ -7,6 +7,7 @@ typedef struct { toolame_options *toolame_ctx; int channels, srate, bitrate; + int vbr; int16_t left_pcm[1152], right_pcm[1152]; } mpae_toolame_ctx;