[FFmpeg-devel] [PATCH] ffmpeg.c Added Audio Gain feature for the audio codecs
Michael Niedermayer
michaelni at gmx.at
Fri Sep 9 04:51:34 CEST 2011
On Thu, Sep 08, 2011 at 07:41:22PM +0000, Chiranjeevi Melam wrote:
> Hi ,
> Attached is the patch in ffmpeg.c & avcodec.h. Added Audio Gain Feature for the audio codecs (the range is between -24 to +24).
> Thanks,
> Chiru
>
[...]
> @@ -844,6 +851,32 @@ need_realloc:
> exit_program(1);
> }
>
> + if(enc->audio_gain !=0){
> + int16_t *pAudio;
> + int32_t gain_sample;
> +
> + av_fast_malloc(&dup_buf, &allocated_dup_buf_size, size);
> + if (!dup_buf){
> + fprintf(stderr, "Out of memory in do_audio_out\n");
> + exit_program(1);
> + }
indention looks bad
> + memcpy(dup_buf, buf, size);
> + dup_size = size;
> + pAudio = (int16_t *)buf;
> + int16_t ratio = (int16_t)(2048 * (pow(10.0, enc->audio_gain/20.0)));
> +
> + for(int i=0;i<(size / sizeof(int16_t));i++){
> + gain_sample = (int32_t)((*pAudio) * ratio) ;
> + gain_sample = gain_sample >> 11;
> + if (gain_sample < SHRT_MIN)
> + gain_sample = SHRT_MIN;
> + if (gain_sample > SHRT_MAX)
> + gain_sample = SHRT_MAX;
> + *pAudio = (int16_t) gain_sample;
> + pAudio++;
> + }
> + }
this should probably be rather put in a audio filter
[...]
> diff --git a/ffmpeg_base/libavcodec/avcodec.h b/ffmpeg/libavcodec/avcodec.h
> index fd9579e..5fe693c 100755
> --- a/ffmpeg_base/libavcodec/avcodec.h
> +++ b/ffmpeg/libavcodec/avcodec.h
> @@ -2781,6 +2781,7 @@ typedef struct AVCodecContext {
> */
> int (*execute2)(struct AVCodecContext *c, int (*func)(struct AVCodecContext *c2, void *arg, int jobnr, int threadnr), void *arg2, int *ret, int count);
>
> + int audio_gain;
> #if FF_API_X264_GLOBAL_OPTS
adding a field in the middle of AVCodecContext breaks ABI
also newly added fields should be documented
either way, why do you add this field to AVCodecContext instead of
keeping it within ffmpeg.c ?
OptionsContext seems like a better places
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
When the tyrant has disposed of foreign enemies by conquest or treaty, and
there is nothing more to fear from them, then he is always stirring up
some war or other, in order that the people may require a leader. -- Plato
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20110909/15030166/attachment.asc>
More information about the ffmpeg-devel
mailing list