comparison libmpcodecs/ad_alaw.c @ 5340:0f12fb7c1c5d

imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
author arpi
date Mon, 25 Mar 2002 21:06:01 +0000
parents
children 28677d779205
comparison
equal deleted inserted replaced
5339:e72d8e3955ea 5340:0f12fb7c1c5d
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <unistd.h>
4
5 #include "config.h"
6 #include "ad_internal.h"
7
8 static ad_info_t info =
9 {
10 "aLaw/uLaw audio decoder",
11 "alaw",
12 AFM_ALAW,
13 "Nick Kurshev",
14 "A'rpi",
15 ""
16 };
17
18 LIBAD_EXTERN(alaw)
19
20 #include "alaw.h"
21
22 static int init(sh_audio_t *sh_audio)
23 {
24 /* aLaw audio codec:*/
25 if(!sh_audio->wf) return 0;
26 sh_audio->channels=sh_audio->wf->nChannels;
27 sh_audio->samplerate=sh_audio->wf->nSamplesPerSec;
28 sh_audio->i_bps=sh_audio->channels*sh_audio->samplerate;
29 return 1;
30 }
31
32 static int preinit(sh_audio_t *sh)
33 {
34 sh->audio_out_minsize=2048;
35 return 1;
36 }
37
38 static void uninit(sh_audio_t *sh)
39 {
40 }
41
42 static int control(sh_audio_t *sh,int cmd,void* arg, ...)
43 {
44 int skip;
45 switch(cmd)
46 {
47 case ADCTRL_SKIP_FRAME:
48 skip=sh->i_bps/16;
49 skip=skip&(~3);
50 demux_read_data(sh->ds,NULL,skip);
51 return CONTROL_TRUE;
52 default:
53 return CONTROL_UNKNOWN;
54 }
55 return CONTROL_UNKNOWN;
56 }
57
58 static int decode_audio(sh_audio_t *sh_audio,unsigned char *buf,int minlen,int maxlen)
59 {
60 int len;
61 int l=demux_read_data(sh_audio->ds,buf,minlen/2);
62 unsigned short *d=(unsigned short *) buf;
63 unsigned char *s=buf;
64 len=2*l;
65 if(sh_audio->format==6){
66 /* aLaw */
67 while(l>0){ --l; d[l]=alaw2short[s[l]]; }
68 } else {
69 /* uLaw */
70 while(l>0){ --l; d[l]=ulaw2short[s[l]]; }
71 }
72 return len;
73 }