[FFmpeg-devel] [PATCH] Lego Mindstorms ADPCM IMA codec

Rafaël Carré rafael.carre
Tue Aug 24 09:47:51 CEST 2010


On Tue, 24 Aug 2010 01:53:02 +0200
Michael Niedermayer <michaelni at gmx.at> wrote:

> On Tue, Aug 03, 2010 at 09:34:32AM +0200, Rafa?l Carr? wrote:
> > Add a new codec since it differs a bit from ADPCM IMA WAV
> > Pretend to support S16 sample format and do the conversion from/to
> > U8, so we can use existing code
> > Still untested on real Lego
> 
> a new encoder should be tested before commit
> we dont want to create invalid files

i tested with the "reference software" i have (bricxcc) and made sure it
gave the same output:

- produce rso file with bricxcc
- decode with ffmpeg
- encode result with ffmpeg -> both rso are identical

but i agree it should be tested on hardware first, so i'll just wait
for someone interested to give follow up to the patch (i can give a
hand of course)

> [...]
> > @@ -482,6 +487,28 @@ static int adpcm_encode_frame(AVCodecContext
> > *avctx, /*    n = (BLKSIZE - 4 * avctx->channels) / (2 * 8 *
> > avctx->channels); */ 
> >      switch(avctx->codec->id) {
> > +    case CODEC_ID_ADPCM_IMA_RSO:
> > +        n = buf_size * 2; /* number of samples (4bits per sample)
> > */ +
> > +        for(i=0; i<n; i++) {
> > +            samples[i] += 1<<15;                            /* s16
> > -> u16 */
> > +            samples[i] = (unsigned short)samples[i] >> 8;   /* u16
> > -> u8  */
> > +        }
> 
> this isnt modifying the input array is it?

oops yes it is,

simple solution would be to add a temp buffer in ADPCMContext,
use malloc()/realloc()/memcpy() at each frame and do the conversion in
this buffer.

not very efficient but given the very small size of typical encoding
(rso files are limited to 64k) that does the job.

> [...]
> > @@ -1034,6 +1065,20 @@ static int adpcm_decode_frame(AVCodecContext
> > *avctx, src += 4*st;
> >          }
> >          break;
> > +    case CODEC_ID_ADPCM_IMA_RSO:
> > +        while(src < buf + buf_size){
> > +            short s;
> > +            s = adpcm_ima_expand_nibble(&c->status[0], *src >>
> > 4    , 3);
> > +            s <<= 8;    /* u8  -> u16 */
> > +            s -= 1<<15; /* u16 -> s16 */
> > +            *samples++ = s;
> 
> the use of short in this code is likely slow on some cpus

int works too

-- 
? Rafa?l Carr? ?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20100824/f7ea4794/attachment.pgp>



More information about the ffmpeg-devel mailing list