audio_dec_dolby.c
9.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
#include "os_config.h"
#include "c_def.h"
#include "debug.h"
#include "oem.h"
#ifdef DOLBY_AC3_DEC
#include "fifo.h"
#include "regmap.h"
#include "mem_reloc.h"
#include "hw_da_pp.h"
#include "message.h"
#include "audio_com.h"
#include "audio_dec.h"
#include "audio_dec_dolby.h"
#include "app_dac.h"
#include "app_cmd.h"
#include "app_main.h"
#include "xa_type_def.h"
#if 0
#undef AUDIO__OUTPUT_1_CH
#undef AUDIO_OUTPUT_2_CH
#undef AUDIO_OUTPUT_3_CH
#undef AUDIO_OUTPUT_4_CH
#undef AUDIO_OUTPUT_6_CH
#undef AUDIO_OUTPUT_0P1_CH_USED_WIRLESS
#endif
#ifdef AUDIO_HEADPHONE_OUTPUT
#define AUDIO_OUTPUT_2_CH
#else
//#define AUDIO_AC3_OUTPUT_1_CH
//#define AUDIO_OUTPUT_2_CH
//#define AUDIO_OUTPUT_3_CH
#define AUDIO_OUTPUT_4_CH
//#define AUDIO_OUTPUT_6_CH
#endif
//#define AUDIO_OUTPUT_0P1_CH_USED_WIRLESS
/*
"-z:1\0", //Enables/Disables clearing of unused channels at the output
"-lfeout:0\0", //Enable/Disable lfe output
"-ocfg:2\0", //Specifies output channel configuration in the range 0 to 7
"-och:2\0", //Specifies the number of PCM channels to output in the range 1 to 6
"-chmap:0L,1R,2C,3l,4r,5s\0" //Specifies PCM channel placement in the interleaved output buffer with mapping for each channel in the range 0 to 5
*/
#if 1//lib
#if defined AUDIO_OUTPUT_6_CH
#if 0
#define OPTEK_AC3_ARGC 2
//default
//5.1
const char *optek_ac3_argv[OPTEK_AC3_ARGC] =
{
"-z:1\0",
// "-chmap:0L,1R,2C,3l,4r,5s\0"
"-chmap:0L,1R,2C,3s,4l,5r\0",
};
#else
#define OPTEK_AC3_ARGC 5
//5.1
const char *optek_ac3_argv[OPTEK_AC3_ARGC] =
{
"-z:1\0", //Enables/Disables clearing of unused channels at the output
"-lfeout:1\0", //Enable/Disable lfe output
"-ocfg:7\0", //Specifies output channel configuration in the range 0 to 7
// "-ocfg:6\0", //Specifies output channel configuration in the range 0 to 7
"-och:6\0", //Specifies the number of PCM channels to output in the range 1 to 6
// "-chmap:0L,1R,2C,3l,4r,5s\0" //Specifies PCM channel placement in the interleaved output buffer with mapping for each channel in the range 0 to 5
"-chmap:0L,1R,2C,3s,4l,5r\0" //Specifies PCM channel placement in the interleaved output buffer with mapping for each channel in the range 0 to 5
};
#endif
#elif defined AUDIO_OUTPUT_4_CH
#define OPTEK_AC3_ARGC 5
//3.1
const char *optek_ac3_argv[OPTEK_AC3_ARGC] =
{
"-z:1\0", //Enables/Disables clearing of unused channels at the output
"-lfeout:1\0", //Enable/Disable lfe output
"-ocfg:5\0", //Specifies output channel configuration in the range 0 to 7
"-och:4\0", //Specifies the number of PCM channels to output in the range 1 to 6
"-chmap:0L,1R,2C,3s,4l,5r\0" //Specifies PCM channel placement in the interleaved output buffer with mapping for each channel in the range 0 to 5
};
#elif defined AUDIO_OUTPUT_3_CH
#define OPTEK_AC3_ARGC 5
//2.1
const char *optek_ac3_argv[OPTEK_AC3_ARGC] =
{
"-z:1\0", //Enables/Disables clearing of unused channels at the output
"-lfeout:1\0", //Enable/Disable lfe output
"-ocfg:4\0", //Specifies output channel configuration in the range 0 to 7
"-och:3\0", //Specifies the number of PCM channels to output in the range 1 to 6
"-chmap:0L,1R,2s,3l,4r,5C\0" //Specifies PCM channel placement in the interleaved output buffer with mapping for each channel in the range 0 to 5
};
#elif defined AUDIO_OUTPUT_2_CH
#define OPTEK_AC3_ARGC 5
#if 1
//2.0
const char *optek_ac3_argv[OPTEK_AC3_ARGC] =
{
"-z:1\0", //Enables/Disables clearing of unused channels at the output
"-lfeout:0\0", //Enable/Disable lfe output
"-ocfg:7\0", //Specifies output channel configuration in the range 0 to 7
// "-ocfg:2\0", //Specifies output channel configuration in the range 0 to 7
"-och:2\0", //Specifies the number of PCM channels to output in the range 1 to 6
"-chmap:0L,1R,2s,3l,4r,5C\0" //Specifies PCM channel placement in the interleaved output buffer with mapping for each channel in the range 0 to 5
};
#else
//2.0, for testing
const char *optek_ac3_argv[OPTEK_AC3_ARGC] =
{
"-z:1\0", //Enables/Disables clearing of unused channels at the output
"-lfeout:1\0", //Enable/Disable lfe output
"-ocfg:2\0", //Specifies output channel configuration in the range 0 to 7
"-och:2\0", //Specifies the number of PCM channels to output in the range 1 to 6
"-chmap:0L,1R,2s,3C,4l,5r\0" //Specifies PCM channel placement in the interleaved output buffer with mapping for each channel in the range 0 to 5
// "-chmap:0L,1R,2C,3s,4l,5r\0" //Specifies PCM channel placement in the interleaved output buffer with mapping for each channel in the range 0 to 5
// "-chmap:0l,1r,2L,3R,4C,5s\0" //Specifies PCM channel placement in the interleaved output buffer with mapping for each channel in the range 0 to 5
// "-chmap:0C,1s,2L,3R,4l,5r\0" //Specifies PCM channel placement in the interleaved output buffer with mapping for each channel in the range 0 to 5
};
#endif
#else
#error "The output channels of Dolby must be defined"
#endif
XA_ERRORCODE xa_dd_ac3_dec_main_process (WORD32 argc, char *argv[]) __INTERNAL_RAM_TEXT;
//void xa_shift_input_buffer (char *buf, int buf_size, int bytes_consumed) __INTERNAL_RAM_TEXT;
//int xa_spdif_fread(void *buffer, int size, int count, void *fp) __INTERNAL_RAM_TEXT;
#endif
extern unsigned int ui_ocfg;
extern unsigned int ui_stmode;
extern unsigned int ui_dynrng_mode;
extern unsigned int ui_monorep;
extern unsigned int ui_dyn_cut_hi;
extern unsigned int ui_dyn_boost_lo;
void dd_ac3_dec_init( void )
{
//DBG_Printf("%s\n\r", __func__);
#if defined AUDIO_PWM_OUTPUT
#if defined AUDIO_OUTPUT_2_CH
audio_out_mode = AUDIO_OUT_L_R;
da_pp_channel_setting(0);
#elif defined AUDIO_OUTPUT_3_CH
audio_out_mode = AUDIO_OUT_L_R_Sub;
da_pp_channel_setting(1);
#elif defined AUDIO_OUTPUT_4_CH
audio_out_mode = AUDIO_OUT_L_R_Center_Sub;
da_pp_channel_setting(1);
#elif defined AUDIO_OUTPUT_6_CH
audio_out_mode = AUDIO_OUT_L_R_Center_Sub_LS_RS;
//audio_out_mode = AUDIO_OUT_L_R_Sub_Center_LS_RS,
da_pp_channel_setting(2);
#else
audio_out_mode = AUDIO_OUT_L_R;
da_pp_channel_setting(MI2S_OUTPUT_CHANNEL_DEFAULT);
#endif
#else
audio_out_mode = AUDIO_OUT_L_R;
da_pp_channel_setting(MI2S_OUTPUT_CHANNEL_DEFAULT);
#endif
#if 1//downmix lt/Rt mode, must use the code below at released version
DBG_Printf("dd_ac3_dec_init\n");
ui_stmode = 1;
//ui_ocfg = 0;//Ls Rs C mix in L R, Ls Rs C not sound, s not modify
//ui_ocfg = 1;//Ls Rs L R mix in C, Ls Rs L R not sound, s not modify
//ui_ocfg = 2;//Ls Rs C mix in L R, Ls Rs C not sound, s not modify
//ui_ocfg = 3;// Ls mix in L, Rs mix in R, Ls Rs not sound, C s not modify
//ui_ocfg = 4;//C mix in L R, Rs mix in Ls, Rs C not sound, s not modify
//ui_ocfg = 5;//Rs mix in Ls, Rs not sound, L R C s not modify
ui_ocfg = 2;//C mix in L R, C not sound, Ls Rs s not modify
//ui_ocfg = 7;//not mix, L R C Ls Rs s not modify, default
//ui_dynrng_mode = 0;
ui_dynrng_mode = 2;
ui_monorep = 0;
//ui_dyn_cut_hi = 0;
//ui_dyn_boost_lo = 0;
//ui_dyn_cut_hi = 0x007FFFFF;
//ui_dyn_boost_lo = 0x007FFFFF;
#endif
//default
//app_main_data.playing_stream_sample_rate = 48000;
//app_main_data.playing_stream_bitrate = (384000/8);
//uMsgSend (UI_CODEC, UI_DEC_INIT_SUCCESS, 0);
}
void dd_ac3_dec_open( void )
{
}
void dd_ac3_dec_close( void )
{
}
void dd_ac3_dec_fini( void )
{
}
//XA_ERRORCODE xa_dd_ac3_dec_process (void);
void dd_ac3_dec_decode( void )
{
int ret;
#ifdef DD_AC3_DEC_16BIT_OUT
app_main_data.audio_out_24bit= FALSE;
#else
app_main_data.audio_out_24bit= TRUE;
#endif
ret = xa_dd_ac3_dec_main_process(OPTEK_AC3_ARGC, optek_ac3_argv);
//xa_dd_ac3_dec_main_process();
//DBG_Printf("ac3's return :%d\n\r", ret);
// Reached the end of bit stream.
if (wRequestDecodeFrameExit != TRUE)
{
//playing to stream end
uMsgSend (UI_CODEC, UI_DECODE_STREAM_EOF, 0);
}
else
{
//asm("break 1,1");
DBG_Printf("ac3's dec force exit\n\r");
}
}
void app_nav_dec_set_parms_cb (u32 freq, u32 bit_rate)
{
app_main_data.playing_stream_sample_rate = freq;
//app_main_data.playing_stream_chans = chans;
app_main_data.playing_stream_bitrate = (bit_rate/8);
switch (freq)
{
case 44100:
break;
case 48000:
break;
case 32000:
break;
case 88200:
break;
case 96000:
break;
case 64000:
break;
case 176400:
break;
case 192000:
break;
case 128000:
break;
default:
DBG_Assert (FALSE);
break;
}
//waiting for audio pll
//app_nav_sleep(100);
}
#if 0
#define DOBLY_DD_AC3_DECODE dd_ac3_dec_init, \
dd_ac3_dec_open, \
dd_ac3_dec_close, \
decnone_fini, \
dd_ac3_dec_decode
#else
#define DOBLY_DD_AC3_DECODE dd_ac3_dec_init, \
dd_ac3_dec_fini, \
dd_ac3_dec_decode
#endif
const DECODE_DEVICE dd_ac3_decode =
{
DOBLY_DD_AC3_DECODE
};
#endif //DOLBY_AC3_DEC