-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathaudio.cpp
More file actions
231 lines (191 loc) · 6.74 KB
/
audio.cpp
File metadata and controls
231 lines (191 loc) · 6.74 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
/**************************************************************************
* Copyright (C), AirM2M Tech. Co., Ltd.
*
* Name: audio.cpp
* Author: liweiqiang
* Version: V0.1
* Date: 2013/10/21
*
* Description:
* audio.core
*
* History:
* panjun 2015.04.30 Add audio's API according to MTK.
**************************************************************************/
#include "stdafx.h"
#include "lua.hpp"
#include "platform.h"
#include "platform_conf.h"
#include "platform_audio.h"
static int l_audio_play_file(lua_State *L) {
const char *name = luaL_checkstring(L,1);
AudioPlayParam param;
param.isBuffer = FALSE;
param.u.filename = name;
lua_pushboolean(L, platform_audio_play(¶m) == PLATFORM_OK);
return 1;
}
static int l_audio_play_data(lua_State *L) {
PCSTR data;
int l;
AudioPlayParam param;
data = luaL_checklstring(L, 1, (size_t*)&l);
param.isBuffer = TRUE;
param.u.buffer.format = (PlatformAudioFormat)luaL_checkinteger(L, 2);
param.u.buffer.loop = luaL_optinteger(L, 3, 0);
param.u.buffer.data = data;
param.u.buffer.len = l;
lua_pushboolean(L, platform_audio_play(¶m) == PLATFORM_OK);
return 1;
}
static int l_audio_stop(lua_State *L) {
platform_audio_stop();
return 0;
}
/*+\NEW\zhuth\2014.7.25\新增设置音频通道和音量的同步接口*/
static int l_audio_set_channel(lua_State *L) {
UINT32 channel = luaL_checkinteger(L,1);
UINT32 res;
res = platform_audio_set_channel((PlatformAudioChannel)channel);
lua_pushinteger(L, res);
return 1;
}
static int l_audio_set_vol(lua_State *L) {
UINT32 vol = luaL_checkinteger(L,1);
UINT32 res;
/*+\NEW\xiongjunqun\2015.05.28\修改无法切换到听筒模式问题*/
//platform_audio_set_channel(PLATFORM_AUD_CHANNEL_LOUDSPEAKER);
/*-\NEW\xiongjunqun\2015.05.28\修改无法切换到听筒模式问题*/
res = platform_audio_set_vol((PlatformAudioVol)vol);
lua_pushinteger(L, res);
return 1;
}
/*+\NEW\xiongjunqun\2015.05.28\增加通话中调节音量接口*/
static int l_audio_set_sph_vol(lua_State *L) {
UINT32 vol = luaL_checkinteger(L,1);
UINT32 res;
res = platform_audio_set_sph_vol((PlatformAudioVol)vol);
lua_pushinteger(L, res);
return 1;
}
/*-\NEW\xiongjunqun\2015.05.28\增加通话中调节音量接口*/
static int l_audio_speaker_set_vol(lua_State *L) {
UINT32 vol = luaL_checkinteger(L,1);
UINT32 res;
platform_audio_set_channel(PLATFORM_AUD_CHANNEL_LOUDSPEAKER);
res = platform_audio_set_vol((PlatformAudioVol)vol);
lua_pushinteger(L, res);
return 1;
}
static int l_audio_set_mic_vol(lua_State *L) {
UINT32 vol = luaL_checkinteger(L,1);
UINT32 res;
res = platform_audio_set_mic_vol((PlatformMicVol)vol);
lua_pushinteger(L, res);
return 1;
}
static int l_audio_set_loopback(lua_State *L) {
UINT32 flag = luaL_checkinteger(L,1);
UINT32 typ = luaL_checkinteger(L,2);
UINT32 setvol = luaL_checkinteger(L,3);
UINT32 vol = luaL_checkinteger(L,4);
UINT32 res;
res = platform_audio_set_loopback(flag,(PlatformAudioLoopback)typ,setvol,vol);
lua_pushinteger(L, res);
return 1;
}
/*-\NEW\zhuth\2014.7.25\新增设置音频通道和音量的同步接口*/
static int l_audio_record(lua_State *L) {
size_t len = 0;
char* file_name = (char*)luaL_checklstring(L, 1, &len);
int time_sec = luaL_checkinteger(L, 2);
int quality = luaL_optint(L, 3, 0);
int res = platform_audio_record(file_name, time_sec, quality);
lua_pushinteger(L, res);
return 1;
}
static int l_audio_stop_record(lua_State *L) {
int res = platform_audio_stop_record();
lua_pushinteger(L, res);
return 1;
}
#define MIN_OPT_LEVEL 2
// Module function map
const luaL_Reg audiocore_map[] =
{
{"play", l_audio_play_file},
{"playdata", l_audio_play_data},
{"stop", l_audio_stop},
/*+\NEW\zhuth\2014.7.25\新增设置音频通道和音量的同步接口*/
{"setchannel", l_audio_set_channel},
{"setvol", l_audio_set_vol},
/*+\NEW\xiongjunqun\2015.05.28\增加通话中调节音量接口*/
{"setsphvol", l_audio_set_sph_vol},
/*-\NEW\xiongjunqun\2015.05.28\增加通话中调节音量接口*/
{"setspeakervol", l_audio_speaker_set_vol},
{"setmicvol", l_audio_set_mic_vol},
{"setloopback", l_audio_set_loopback},
/*-\NEW\zhuth\2014.7.25\新增设置音频通道和音量的同步接口*/
{"record", l_audio_record},
{"stoprecord", l_audio_stop_record},
{ NULL, NULL }
};
LUALIB_API int luaopen_audiocore( lua_State *L )
{
luaL_register( L, AUXLIB_AUDIOCORE, audiocore_map );
MOD_REG_NUMBER(L, "AMR122", PLATFORM_AUD_AMR122);
MOD_REG_NUMBER(L, "MP3", PLATFORM_AUD_MP3);
MOD_REG_NUMBER(L, "PCM", PLATFORM_AUD_PCM);
MOD_REG_NUMBER(L, "WAV", PLATFORM_AUD_WAV);
MOD_REG_NUMBER(L, "MIDI", PLATFORM_AUD_MIDI);
/*+\NEW\zhuth\2014.7.25\新增设置音频通道和音量的同步接口*/
#define REG_AUD_CHANNEL(CHANNEL) MOD_REG_NUMBER(L, #CHANNEL, PLATFORM_AUD_CHANNEL_##CHANNEL)
REG_AUD_CHANNEL(HANDSET);
REG_AUD_CHANNEL(EARPIECE);
REG_AUD_CHANNEL(LOUDSPEAKER);
REG_AUD_CHANNEL(BLUETOOTH);
REG_AUD_CHANNEL(FM);
REG_AUD_CHANNEL(FM_LP);
REG_AUD_CHANNEL(TV);
REG_AUD_CHANNEL(AUX_HANDSET);
REG_AUD_CHANNEL(AUX_LOUDSPEAKER);
REG_AUD_CHANNEL(AUX_EARPIECE);
REG_AUD_CHANNEL(DUMMY_HANDSET);
REG_AUD_CHANNEL(DUMMY_AUX_HANDSET);
REG_AUD_CHANNEL(DUMMY_LOUDSPEAKER);
REG_AUD_CHANNEL(DUMMY_AUX_LOUDSPEAKER);
#define REG_AUD_VOL(VOL) MOD_REG_NUMBER(L, #VOL, PLATFORM_AUD_##VOL)
REG_AUD_VOL(VOL0);
REG_AUD_VOL(VOL1);
REG_AUD_VOL(VOL2);
REG_AUD_VOL(VOL3);
REG_AUD_VOL(VOL4);
REG_AUD_VOL(VOL5);
REG_AUD_VOL(VOL6);
REG_AUD_VOL(VOL7);
#define REG_MIC_VOL(VOL) MOD_REG_NUMBER(L, #VOL, PLATFORM_##VOL)
REG_MIC_VOL(MIC_VOL0);
REG_MIC_VOL(MIC_VOL1);
REG_MIC_VOL(MIC_VOL2);
REG_MIC_VOL(MIC_VOL3);
REG_MIC_VOL(MIC_VOL4);
REG_MIC_VOL(MIC_VOL5);
REG_MIC_VOL(MIC_VOL6);
REG_MIC_VOL(MIC_VOL7);
REG_MIC_VOL(MIC_VOL8);
REG_MIC_VOL(MIC_VOL9);
REG_MIC_VOL(MIC_VOL10);
REG_MIC_VOL(MIC_VOL11);
REG_MIC_VOL(MIC_VOL12);
REG_MIC_VOL(MIC_VOL13);
REG_MIC_VOL(MIC_VOL14);
REG_MIC_VOL(MIC_VOL15);
#define REG_AUD_LOOPBACK(TYPE) MOD_REG_NUMBER(L, #TYPE, PLATFORM_AUD_##TYPE)
REG_AUD_LOOPBACK(LOOPBACK_HANDSET);
REG_AUD_LOOPBACK(LOOPBACK_EARPIECE);
REG_AUD_LOOPBACK(LOOPBACK_LOUDSPEAKER);
REG_AUD_LOOPBACK(LOOPBACK_AUX_HANDSET);
REG_AUD_LOOPBACK(LOOPBACK_AUX_LOUDSPEAKER);
/*-\NEW\zhuth\2014.7.25\新增设置音频通道和音量的同步接口*/
return 1;
}