6 #include "ad_internal.h"
7 #include "libaf/af_format.h"
9 static ad_info_t info
=
11 "Uncompressed PCM audio decoder",
20 static int init(sh_audio_t
*sh_audio
)
22 WAVEFORMATEX
*h
=sh_audio
->wf
;
23 sh_audio
->i_bps
=h
->nAvgBytesPerSec
;
24 sh_audio
->channels
=h
->nChannels
;
25 sh_audio
->samplerate
=h
->nSamplesPerSec
;
26 sh_audio
->samplesize
=(h
->wBitsPerSample
+7)/8;
27 sh_audio
->sample_format
=AF_FORMAT_S16_LE
; // default
28 switch(sh_audio
->format
){ /* hardware formats: */
30 case 0x1: // Microsoft PCM
31 case 0xfffe: // Extended
32 switch (sh_audio
->samplesize
) {
33 case 1: sh_audio
->sample_format
=AF_FORMAT_U8
; break;
34 case 2: sh_audio
->sample_format
=AF_FORMAT_S16_LE
; break;
35 case 3: sh_audio
->sample_format
=AF_FORMAT_S24_LE
; break;
36 case 4: sh_audio
->sample_format
=AF_FORMAT_S32_LE
; break;
39 case 0x3: // IEEE float
40 sh_audio
->sample_format
=AF_FORMAT_FLOAT_LE
;
42 case 0x6: sh_audio
->sample_format
=AF_FORMAT_A_LAW
;break;
43 case 0x7: sh_audio
->sample_format
=AF_FORMAT_MU_LAW
;break;
44 case 0x11: sh_audio
->sample_format
=AF_FORMAT_IMA_ADPCM
;break;
45 case 0x50: sh_audio
->sample_format
=AF_FORMAT_MPEG2
;break;
46 /* case 0x2000: sh_audio->sample_format=AFMT_AC3; */
47 case 0x20776172: // 'raw '
48 sh_audio
->sample_format
=AF_FORMAT_S16_BE
;
49 if(sh_audio
->samplesize
==1) sh_audio
->sample_format
=AF_FORMAT_U8
;
51 case 0x736F7774: // 'twos'
52 sh_audio
->sample_format
=AF_FORMAT_S16_BE
;
53 // intended fall-through
54 case 0x74776F73: // 'swot'
55 if(sh_audio
->samplesize
==1) sh_audio
->sample_format
=AF_FORMAT_S8
;
57 case 0x32336c66: // 'fl32', bigendian float32
58 sh_audio
->sample_format
=AF_FORMAT_FLOAT_BE
;
59 sh_audio
->samplesize
=4;
61 case 0x666c3332: // '23lf', little endian float32, MPlayer internal fourCC
62 sh_audio
->sample_format
=AF_FORMAT_FLOAT_LE
;
63 sh_audio
->samplesize
=4;
65 /* case 0x34366c66: // 'fl64', bigendian float64
66 sh_audio->sample_format=AF_FORMAT_FLOAT_BE;
67 sh_audio->samplesize=8;
69 case 0x666c3634: // '46lf', little endian float64, MPlayer internal fourCC
70 sh_audio->sample_format=AF_FORMAT_FLOAT_LE;
71 sh_audio->samplesize=8;
73 case 0x34326e69: // 'in24', bigendian int24
74 sh_audio
->sample_format
=AF_FORMAT_S24_BE
;
75 sh_audio
->samplesize
=3;
77 case 0x696e3234: // '42ni', little endian int24, MPlayer internal fourCC
78 sh_audio
->sample_format
=AF_FORMAT_S24_LE
;
79 sh_audio
->samplesize
=3;
81 case 0x32336e69: // 'in32', bigendian int32
82 sh_audio
->sample_format
=AF_FORMAT_S32_BE
;
83 sh_audio
->samplesize
=4;
85 case 0x696e3332: // '23ni', little endian int32, MPlayer internal fourCC
86 sh_audio
->sample_format
=AF_FORMAT_S32_LE
;
87 sh_audio
->samplesize
=4;
89 default: if(sh_audio
->samplesize
!=2) sh_audio
->sample_format
=AF_FORMAT_U8
;
91 if (!sh_audio
->samplesize
) // this would cause MPlayer to hang later
92 sh_audio
->samplesize
= 2;
96 static int preinit(sh_audio_t
*sh
)
98 sh
->audio_out_minsize
=2048;
102 static void uninit(sh_audio_t
*sh
)
106 static int control(sh_audio_t
*sh
,int cmd
,void* arg
, ...)
111 case ADCTRL_SKIP_FRAME
:
114 demux_read_data(sh
->ds
,NULL
,skip
);
117 return CONTROL_UNKNOWN
;
120 static int decode_audio(sh_audio_t
*sh_audio
,unsigned char *buf
,int minlen
,int maxlen
)
122 unsigned len
= sh_audio
->channels
*sh_audio
->samplesize
;
123 len
= maxlen
- maxlen
% len
; // sample align
124 len
=demux_read_data(sh_audio
->ds
,buf
,len
);