* Real Audio 1.0 (14.4K)
* Copyright (c) 2003 the ffmpeg project
*
- * This library is free software; you can redistribute it and/or
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
+ * version 2.1 of the License, or (at your option) any later version.
*
- * This library is distributed in the hope that it will be useful,
+ * FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "avcodec.h"
#include "ra144.h"
-#define DATABLOCK1 20 /* size of 14.4 input block in bytes */
-#define DATACHUNK1 1440 /* size of 14.4 input chunk in bytes */
-#define AUDIOBLOCK 160 /* size of output block in 16-bit words (320 bytes) */
-#define AUDIOBUFFER 12288 /* size of output buffer in 16-bit words (24576 bytes) */
+#define DATABLOCK1 20 /* size of 14.4 input block in bytes */
+#define DATACHUNK1 1440 /* size of 14.4 input chunk in bytes */
+#define AUDIOBLOCK 160 /* size of output block in 16-bit words (320 bytes) */
+#define AUDIOBUFFER 12288 /* size of output buffer in 16-bit words (24576 bytes) */
/* consts */
-#define NBLOCKS 4 /* number of segments within a block */
-#define BLOCKSIZE 40 /* (quarter) block size in 16-bit words (80 bytes) */
-#define HALFBLOCK 20 /* BLOCKSIZE/2 */
-#define BUFFERSIZE 146 /* for do_output */
+#define NBLOCKS 4 /* number of segments within a block */
+#define BLOCKSIZE 40 /* (quarter) block size in 16-bit words (80 bytes) */
+#define HALFBLOCK 20 /* BLOCKSIZE/2 */
+#define BUFFERSIZE 146 /* for do_output */
/* internal globals */
typedef struct {
- unsigned int resetflag, val, oldval;
- unsigned int unpacked[28]; /* buffer for unpacked input */
- unsigned int *iptr; /* pointer to current input (from unpacked) */
- unsigned int gval;
- unsigned short *gsp;
- unsigned int gbuf1[8];
- unsigned short gbuf2[120];
- signed short output_buffer[40];
- unsigned int *decptr; /* decoder ptr */
- signed short *decsp;
-
- /* the swapped buffers */
- unsigned int swapb1a[10];
- unsigned int swapb2a[10];
- unsigned int swapb1b[10];
- unsigned int swapb2b[10];
- unsigned int *swapbuf1;
- unsigned int *swapbuf2;
- unsigned int *swapbuf1alt;
- unsigned int *swapbuf2alt;
-
- unsigned int buffer[5];
- unsigned short int buffer_2[148];
- unsigned short int buffer_a[40];
- unsigned short int buffer_b[40];
- unsigned short int buffer_c[40];
- unsigned short int buffer_d[40];
-
- unsigned short int work[50];
- unsigned short *sptr;
-
- int buffer1[10];
- int buffer2[10];
-
- signed short wavtable1[2304];
- unsigned short wavtable2[2304];
+ unsigned int resetflag, val, oldval;
+ unsigned int unpacked[28]; /* buffer for unpacked input */
+ unsigned int *iptr; /* pointer to current input (from unpacked) */
+ unsigned int gval;
+ unsigned short *gsp;
+ unsigned int gbuf1[8];
+ unsigned short gbuf2[120];
+ signed short output_buffer[40];
+ unsigned int *decptr; /* decoder ptr */
+ signed short *decsp;
+
+ /* the swapped buffers */
+ unsigned int swapb1a[10];
+ unsigned int swapb2a[10];
+ unsigned int swapb1b[10];
+ unsigned int swapb2b[10];
+ unsigned int *swapbuf1;
+ unsigned int *swapbuf2;
+ unsigned int *swapbuf1alt;
+ unsigned int *swapbuf2alt;
+
+ unsigned int buffer[5];
+ unsigned short int buffer_2[148];
+ unsigned short int buffer_a[40];
+ unsigned short int buffer_b[40];
+ unsigned short int buffer_c[40];
+ unsigned short int buffer_d[40];
+
+ unsigned short int work[50];
+ unsigned short *sptr;
+
+ int buffer1[10];
+ int buffer2[10];
+
+ signed short wavtable1[2304];
+ unsigned short wavtable2[2304];
} Real144_internal;
static int ra144_decode_init(AVCodecContext * avctx)
{
- Real144_internal *glob=avctx->priv_data;
+ Real144_internal *glob=avctx->priv_data;
- memset(glob,0,sizeof(Real144_internal));
- glob->resetflag=1;
- glob->swapbuf1=glob->swapb1a;
- glob->swapbuf2=glob->swapb2a;
- glob->swapbuf1alt=glob->swapb1b;
- glob->swapbuf2alt=glob->swapb2b;
+ memset(glob,0,sizeof(Real144_internal));
+ glob->resetflag=1;
+ glob->swapbuf1=glob->swapb1a;
+ glob->swapbuf2=glob->swapb2a;
+ glob->swapbuf1alt=glob->swapb1b;
+ glob->swapbuf2alt=glob->swapb2b;
- memcpy(glob->wavtable1,wavtable1,sizeof(wavtable1));
- memcpy(glob->wavtable2,wavtable2,sizeof(wavtable2));
+ memcpy(glob->wavtable1,wavtable1,sizeof(wavtable1));
+ memcpy(glob->wavtable2,wavtable2,sizeof(wavtable2));
- return 0;
+ return 0;
}
static void final(Real144_internal *glob, short *i1, short *i2, void *out, int *statbuf, int len);
int *b1,*b2;
int x,y;
int *ptr,*tmp;
-
+
b1=buffer;
b2=a2;
-
+
for (x=0;x<10;x++) {
b1[x]=(*a1)<<4;
b1=b2;
b2=tmp;
a1++;
- }
+ }
ptr=a2+10;
while (ptr>a2) (*a2++)>>=4;
}
/* do quarter-block output */
-static void do_output_subblock(Real144_internal *glob, int x)
+static void do_output_subblock(Real144_internal *glob, unsigned int x)
{
int a,b,c,d,e,f,g;
static void add_wav(Real144_internal *glob, int n, int f, int m1, int m2, int m3, short *s1, short *s2, short *s3, short *dest)
{
int a,b,c;
- int x;
short *ptr,*ptr2;
ptr=glob->wavtable1+n*9;
ptr2=glob->wavtable2+n*9;
if (f!=0) {
- a=((*ptr)*m1)>>((*ptr2)+1);
+ a=((*ptr)*m1)>>((*ptr2)+1);
} else {
a=0;
}
*(output++)=ptr[x];
*(output++)=ptr[x+2];
*(output++)=ptr[x+3];
- *(output++)=ptr[x+1];
+ *(output++)=ptr[x+1];
}
}
{
int *c;
int x;
- int d;
unsigned int res;
int b;
/* Uncompress one block (20 bytes -> 160*2 bytes) */
static int ra144_decode_frame(AVCodecContext * avctx,
- void *data, int *data_size,
+ void *vdata, int *data_size,
uint8_t * buf, int buf_size)
{
unsigned int a,b,c;
- long s;
signed short *shptr;
unsigned int *lptr,*temp;
const short **dptr;
- void *datao;
+ int16_t *datao;
+ int16_t *data = vdata;
Real144_internal *glob=avctx->priv_data;
+ if(buf_size==0)
+ return 0;
+
datao = data;
unpack_input(buf,glob->unpacked);
-
+
glob->iptr=glob->unpacked;
glob->val=decodetable[0][(*(glob->iptr++))<<1];
glob->resetflag=0;
shptr=glob->output_buffer;
- while (shptr<glob->output_buffer+BLOCKSIZE) {
- s=*(shptr++)<<2;
- *((int16_t *)data)=s;
- if (s>32767) *((int16_t *)data)=32767;
- if (s<-32767) *((int16_t *)data)=-32768;
- ((int16_t *)data)++;
- }
+ while (shptr<glob->output_buffer+BLOCKSIZE)
+ *data++=av_clip_int16(*(shptr++)<<2);
b+=30;
}
temp=glob->swapbuf2alt;
glob->swapbuf2alt=glob->swapbuf2;
glob->swapbuf2=temp;
- *data_size=data-datao;
+ *data_size=(data-datao)*sizeof(*data);
return 20;
}