codec-cfg does not depend on codecs.conf.h, it is used to generate it.
[mplayer/glamo.git] / libmpcodecs / ad_alaw.c
blob0085b12f85a333092dab3914c8076e3b65a8a144
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <unistd.h>
5 #include "config.h"
6 #include "ad_internal.h"
8 static ad_info_t info =
10 "aLaw/uLaw audio decoder",
11 "alaw",
12 "Nick Kurshev",
13 "A'rpi",
17 LIBAD_EXTERN(alaw)
19 #include "native/alaw.h"
21 static int init(sh_audio_t *sh_audio)
23 /* aLaw audio codec:*/
24 if(!sh_audio->wf) return 0;
25 sh_audio->channels=sh_audio->wf->nChannels;
26 sh_audio->samplerate=sh_audio->wf->nSamplesPerSec;
27 sh_audio->i_bps=sh_audio->channels*sh_audio->samplerate;
28 sh_audio->samplesize=2;
29 return 1;
32 static int preinit(sh_audio_t *sh)
34 sh->audio_out_minsize=2048;
35 sh->ds->ss_div = 1; // 1 samples/packet
36 sh->ds->ss_mul = sh->wf->nChannels; // bytes/packet
37 return 1;
40 static void uninit(sh_audio_t *sh)
44 static int control(sh_audio_t *sh,int cmd,void* arg, ...)
46 int skip;
47 switch(cmd)
49 case ADCTRL_SKIP_FRAME:
50 skip=sh->i_bps/16;
51 skip=skip&(~3);
52 demux_read_data(sh->ds,NULL,skip);
53 return CONTROL_TRUE;
54 default:
55 return CONTROL_UNKNOWN;
57 return CONTROL_UNKNOWN;
60 static int decode_audio(sh_audio_t *sh_audio,unsigned char *buf,int minlen,int maxlen)
62 int len;
63 int l=demux_read_data(sh_audio->ds,buf,minlen/2);
64 unsigned short *d=(unsigned short *) buf;
65 unsigned char *s=buf;
66 len=2*l;
67 if(sh_audio->format==6 || sh_audio->format==0x77616C61){
68 /* aLaw */
69 while(l>0){ --l; d[l]=alaw2short[s[l]]; }
70 } else {
71 /* uLaw */
72 while(l>0){ --l; d[l]=ulaw2short[s[l]]; }
74 return len;