[FFmpeg-devel] [RFC] LPCM 24 bits support

Lars Täuber lars.taeuber
Sat Apr 19 10:11:56 CEST 2008


On Sat, 19 Apr 2008 02:15:16 +0200 Michael Niedermayer <michaelni at gmx.at> wrote:
> On Fri, Apr 18, 2008 at 11:24:03PM +0200, Lars T?uber wrote:
> > On Fri, 18 Apr 2008 22:52:40 +0200 Michael Niedermayer <michaelni at gmx.at> wrote:
> > > On Fri, Apr 18, 2008 at 09:37:12PM +0200, Lars T?uber wrote:
> > > > On Fri, 18 Apr 2008 22:08:24 +0200 Michael Niedermayer <michaelni at gmx.at> wrote:
> > > > > On Fri, Apr 18, 2008 at 09:05:23PM +0200, Lars T?uber wrote:
> > > > > > On Fri, 18 Apr 2008 15:39:43 +0200 Michael Niedermayer <michaelni at gmx.at> wrote:
> > > > > > > On Thu, Apr 17, 2008 at 10:13:40PM +0200, Lars T?uber wrote:
[...]
> > diff -pur ffmpeg/libavcodec/pcm.c ffmpeg.1/libavcodec/pcm.c
> > --- ffmpeg/libavcodec/pcm.c	2008-04-18 20:22:18.000000000 +0200
> > +++ ffmpeg.1/libavcodec/pcm.c	2008-04-18 23:19:20.000000000 +0200
> > @@ -492,6 +498,41 @@ static int pcm_decode_frame(AVCodecConte
> >              *samples++ = s->table[*src++];
> >          }
> >          break;
> > +    case CODEC_ID_PCM_DVD: {
> > +            int audio24[8*2], *ap;
> > +            const uint8_t *src_LSB;
> > +
> > +            if (avctx->channels > 8) {
> > +                av_log(avctx, AV_LOG_ERROR, "PCM_DVD channels out of bounds\n");
> > +                return -1;
> > +            }
> 
> > +            n = buf_size / (avctx->channels * 2 * avctx->bits_per_sample / 8);
> > +            while (n--) {
> > +                ap = audio24;
> > +                src_LSB = src + avctx->channels * 2 * 2;
> > +
> > +                switch (avctx->bits_per_sample) {
> > +                    case 20:
> > +                        for (c=0; c < avctx->channels; c++, src+=4, src_LSB++ ) {
> > +                            *ap++ = src[0]<<16 | src[1]<<8 | (*src_LSB & 0xf0);
> > +                            *ap++ = src[2]<<16 | src[3]<<8 | (*src_LSB & 0x0f)<<4;
> > +                        }
> > +                        break;
> > +                    case 24:
> > +                        for (c=0; c < 2*avctx->channels; c++, src+=2, src_LSB++ )
> > +                            *ap++ = src[0]<<16 | src[1]<<8 | *src_LSB;
> > +                        break;
> > +                    default:
> > +                        av_log(avctx, AV_LOG_ERROR, "PCM_DVD unsupported sample depth\n");
> > +                        return -1;
> > +                }
> > +                src = src_LSB;
> > +
> > +                for (c=0; c < avctx->channels*2; c++)
> > +                    *samples++ = audio24[c] >> 8;
> 
> following is simpler and faster:
> 
> if(avctx->bits_per_sample != 20 && avctx->bits_per_sample != 24){
>     av_log(avctx, AV_LOG_ERROR, "PCM_DVD unsupported sample depth\n");
>     return -1;
> }
> n = buf_size / (avctx->channels * 2 * avctx->bits_per_sample / 8);
> while (n--) {
>     for (c=0; c < 2*avctx->channels; c++)
>         *samples++ = bytestream_get_be16(&src);
>     src+= avctx->channels * (avctx->bits_per_sample-16) / 4;
> }

Yes of course, but as I stated earlier:
> On Thu, 17 Apr 2008 21:10:07 +0100 M?ns Rullg?rd <mans at mansr.com> wrote:
>> What's the point in saving 24 bits per sample to a temporary buffer,
>> only to discard the low 8 bits later?
> 
> I'd like to work on a patch that makes ffmpeg support more than 16 bit for audio after this has been accepted.
> For instance to convert 24bit pcm_dvd to 24bit flac. But I don't know how to do this right now.
> Is this overhead acceptable till then?

Otherwise I will change it to your version.
OR:
Is it allowed to sent commented out code or ifdefed-out-code for a wide-sample-version in addition to the working 16bit version?

Lars




More information about the ffmpeg-devel mailing list