[FFmpeg-devel] [PATCH] add 32bits output format to the flac decoder
Justin Ruggles
justin.ruggles
Sat Jan 24 21:34:01 CET 2009
Mathieu Velten wrote:
> forgot the patch...
>
> Mathieu Velten
>
> 2008/12/7 Mathieu Velten <matmaul at gmail.com>:
>> with this patch flac decoder outputs SAMPLE_FMT_S32 instead of
>> SAMPLE_FMT_S16 when the bps of the stream is superior to 16 bits.
>>
>> Mathieu Velten
>>
> Index: libavcodec/flac.c
> ===================================================================
> --- libavcodec/flac.c (revision 16028)
> +++ libavcodec/flac.c (working copy)
> @@ -607,7 +607,7 @@
> const uint8_t *buf, int buf_size)
> {
> FLACContext *s = avctx->priv_data;
> - int tmp = 0, i, j = 0, input_buf_size = 0;
> + int tmp = 0, i, j = 0, input_buf_size = 0, shift, offset_per_sample;
> int16_t *samples = data;
> int alloc_data_size= *data_size;
>
> @@ -708,14 +708,31 @@
> }
> }
> #else
> + avctx->bits_per_raw_sample = s->bps;
> +
> + if (s->bps > 16)
> + {
> + offset_per_sample = 2;
> + avctx->sample_fmt = SAMPLE_FMT_S32;
> + shift = 32 - s->bps;
> + }
> + else
> + {
> + offset_per_sample = 1;
> + avctx->sample_fmt = SAMPLE_FMT_S16;
> + shift = 16 - s->bps;
> + }
> +
> #define DECORRELATE(left, right)\
> assert(s->channels == 2);\
> for (i = 0; i < s->blocksize; i++)\
> {\
> int a= s->decoded[0][i];\
> int b= s->decoded[1][i];\
> - *samples++ = ((left) << (24 - s->bps)) >> 8;\
> - *samples++ = ((right) << (24 - s->bps)) >> 8;\
> + *(int32_t *)samples = (left) << shift;\
> + samples += offset_per_sample;\
> + *(int32_t *)samples = (right) << shift;\
> + samples += offset_per_sample;\
> }\
> break;
>
> @@ -725,7 +742,10 @@
> for (j = 0; j < s->blocksize; j++)
> {
> for (i = 0; i < s->channels; i++)
> - *samples++ = (s->decoded[i][j] << (24 - s->bps)) >> 8;
> + {
> + *(int32_t *)samples = s->decoded[i][j] << shift;
> + samples += offset_per_sample;
> + }
> }
> break;
> case LEFT_SIDE:
I think this patch would not work with 16-bit on big-endian systems. Can
someone confirm this? Also, I believe it would write past the end of
the output buffer for 16-bit at the last sample.
Here is an alternative patch based on the way 32-bit is handled in the
MLP decoder.
-Justin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: flac_32bits_2.diff
Type: text/x-diff
Size: 3041 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20090124/8c516e69/attachment.diff>
More information about the ffmpeg-devel
mailing list