6 #include "ad_internal.h"
7 #include "libaf/af_format.h"
8 #include "libaf/reorder_ch.h"
10 static ad_info_t info
=
12 "Uncompressed PCM audio decoder",
21 static int init(sh_audio_t
*sh_audio
)
23 WAVEFORMATEX
*h
=sh_audio
->wf
;
24 sh_audio
->i_bps
=h
->nAvgBytesPerSec
;
25 sh_audio
->channels
=h
->nChannels
;
26 sh_audio
->samplerate
=h
->nSamplesPerSec
;
27 sh_audio
->samplesize
=(h
->wBitsPerSample
+7)/8;
28 sh_audio
->sample_format
=AF_FORMAT_S16_LE
; // default
29 switch(sh_audio
->format
){ /* hardware formats: */
31 case 0x1: // Microsoft PCM
32 case 0xfffe: // Extended
33 switch (sh_audio
->samplesize
) {
34 case 1: sh_audio
->sample_format
=AF_FORMAT_U8
; break;
35 case 2: sh_audio
->sample_format
=AF_FORMAT_S16_LE
; break;
36 case 3: sh_audio
->sample_format
=AF_FORMAT_S24_LE
; break;
37 case 4: sh_audio
->sample_format
=AF_FORMAT_S32_LE
; break;
40 case 0x3: // IEEE float
41 sh_audio
->sample_format
=AF_FORMAT_FLOAT_LE
;
43 case 0x6: sh_audio
->sample_format
=AF_FORMAT_A_LAW
;break;
44 case 0x7: sh_audio
->sample_format
=AF_FORMAT_MU_LAW
;break;
45 case 0x11: sh_audio
->sample_format
=AF_FORMAT_IMA_ADPCM
;break;
46 case 0x50: sh_audio
->sample_format
=AF_FORMAT_MPEG2
;break;
47 /* case 0x2000: sh_audio->sample_format=AFMT_AC3; */
48 case 0x20776172: // 'raw '
49 sh_audio
->sample_format
=AF_FORMAT_S16_BE
;
50 if(sh_audio
->samplesize
==1) sh_audio
->sample_format
=AF_FORMAT_U8
;
52 case 0x736F7774: // 'twos'
53 sh_audio
->sample_format
=AF_FORMAT_S16_BE
;
54 // intended fall-through
55 case 0x74776F73: // 'sowt'
56 if(sh_audio
->samplesize
==1) sh_audio
->sample_format
=AF_FORMAT_S8
;
58 case 0x32336c66: // 'fl32', bigendian float32
59 sh_audio
->sample_format
=AF_FORMAT_FLOAT_BE
;
60 sh_audio
->samplesize
=4;
62 case 0x666c3332: // '23lf', little endian float32, MPlayer internal fourCC
63 sh_audio
->sample_format
=AF_FORMAT_FLOAT_LE
;
64 sh_audio
->samplesize
=4;
66 /* case 0x34366c66: // 'fl64', bigendian float64
67 sh_audio->sample_format=AF_FORMAT_FLOAT_BE;
68 sh_audio->samplesize=8;
70 case 0x666c3634: // '46lf', little endian float64, MPlayer internal fourCC
71 sh_audio->sample_format=AF_FORMAT_FLOAT_LE;
72 sh_audio->samplesize=8;
74 case 0x34326e69: // 'in24', bigendian int24
75 sh_audio
->sample_format
=AF_FORMAT_S24_BE
;
76 sh_audio
->samplesize
=3;
78 case 0x696e3234: // '42ni', little endian int24, MPlayer internal fourCC
79 sh_audio
->sample_format
=AF_FORMAT_S24_LE
;
80 sh_audio
->samplesize
=3;
82 case 0x32336e69: // 'in32', bigendian int32
83 sh_audio
->sample_format
=AF_FORMAT_S32_BE
;
84 sh_audio
->samplesize
=4;
86 case 0x696e3332: // '23ni', little endian int32, MPlayer internal fourCC
87 sh_audio
->sample_format
=AF_FORMAT_S32_LE
;
88 sh_audio
->samplesize
=4;
90 default: if(sh_audio
->samplesize
!=2) sh_audio
->sample_format
=AF_FORMAT_U8
;
92 if (!sh_audio
->samplesize
) // this would cause MPlayer to hang later
93 sh_audio
->samplesize
= 2;
97 static int preinit(sh_audio_t
*sh
)
99 sh
->audio_out_minsize
=2048;
103 static void uninit(sh_audio_t
*sh
)
107 static int control(sh_audio_t
*sh
,int cmd
,void* arg
, ...)
112 case ADCTRL_SKIP_FRAME
:
115 demux_read_data(sh
->ds
,NULL
,skip
);
118 return CONTROL_UNKNOWN
;
121 static int decode_audio(sh_audio_t
*sh_audio
,unsigned char *buf
,int minlen
,int maxlen
)
123 unsigned len
= sh_audio
->channels
*sh_audio
->samplesize
;
124 len
= (minlen
+ len
- 1) / len
* len
;
126 // if someone needs hundreds of channels adjust audio_out_minsize
127 // based on channels in preinit()
129 len
=demux_read_data(sh_audio
->ds
,buf
,len
);
130 if (len
> 0 && sh_audio
->channels
>= 5) {
131 reorder_channel_nch(buf
, AF_CHANNEL_LAYOUT_WAVEEX_DEFAULT
,
132 AF_CHANNEL_LAYOUT_MPLAYER_DEFAULT
,
134 len
/ sh_audio
->samplesize
, sh_audio
->samplesize
);