FreeCalypso > hg > fc-selenite
comparison src/g23m-aci/aci/ati_audio.c @ 1:d393cd9bb723
src/g23m-*: initial import from Magnetite
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 15 Jul 2018 04:40:46 +0000 |
parents | |
children | 7d5b412ffb6c |
comparison
equal
deleted
inserted
replaced
0:b6a5e36de839 | 1:d393cd9bb723 |
---|---|
1 /* | |
2 * This ATI module and the AT commands implemented therein are a FreeCalypso | |
3 * addition. The purpose of these AT commands is to exercise the audio | |
4 * capabilities of the firmware - by using these commands, you should be | |
5 * able to emit sounds from the speaker or record voice from the microphone | |
6 * without needing to be in a call, and without bringing up GSM at all. | |
7 * | |
8 * Our corrected implementation of the AT@AUL command (originally added | |
9 * by Openmoko) has been moved into this module as well. | |
10 */ | |
11 | |
12 #ifndef ATI_AUDIO_C | |
13 #define ATI_AUDIO_C | |
14 | |
15 #include "aci_all.h" | |
16 | |
17 #include <ctype.h> | |
18 #include <string.h> | |
19 | |
20 #include "aci_cmh.h" | |
21 #include "ati_cmd.h" | |
22 #include "aci_cmd.h" | |
23 #include "aci_io.h" | |
24 #include "aci_cmd.h" | |
25 #include "l4_tim.h" | |
26 #include "line_edit.h" | |
27 #include "aci_lst.h" | |
28 | |
29 #include "pcm.h" | |
30 #include "audio.h" | |
31 #include "aci.h" | |
32 #include "rx.h" | |
33 #include "pwr.h" | |
34 #include "l4_tim.h" | |
35 | |
36 #ifdef GPRS | |
37 #ifdef DTI | |
38 #include "dti.h" | |
39 #include "dti_conn_mng.h" | |
40 #include "dti_cntrl_mng.h" | |
41 #endif /* DTI */ | |
42 #include "gaci.h" | |
43 #include "gaci_cmh.h" | |
44 #include "gaci_cmd.h" | |
45 #endif /* GPRS */ | |
46 | |
47 #include "aci_mem.h" | |
48 #include "aci_prs.h" | |
49 | |
50 #include "ati_int.h" | |
51 | |
52 #ifndef _SIMULATION_ | |
53 #include "ffs/ffs.h" | |
54 #endif | |
55 | |
56 #ifdef FF_ATI_BAT | |
57 | |
58 #include "typedefs.h" | |
59 #include "gdd.h" | |
60 #include "bat.h" | |
61 | |
62 #include "ati_bat.h" | |
63 | |
64 #endif /*FF_ATI_BAT*/ | |
65 | |
66 #include "audio/audio_api.h" | |
67 #include "audio.h" /* Condat */ | |
68 | |
69 #include "fc-target.cfg" | |
70 #include "armio.h" | |
71 | |
72 #if defined(CONFIG_TARGET_DSAMPLE) || defined(CONFIG_TARGET_FCDEV3B) | |
73 /* AT@SPKR - turn loudspeaker amplifier on or off */ | |
74 GLOBAL T_ATI_RSLT atAtSPKR ( char *cl, UBYTE srcId ) | |
75 { | |
76 int state; | |
77 | |
78 TRACE_FUNCTION("atAtSPKR()"); | |
79 | |
80 cl = parse(cl, "D", &state); | |
81 if (!cl) | |
82 return (ATI_FAIL); | |
83 if (state) | |
84 AI_SetBit(1); | |
85 else | |
86 AI_ResetBit(1); | |
87 return (ATI_CMPL); | |
88 } | |
89 | |
90 GLOBAL T_ATI_RSLT queatAtSPKR (char *cl, UBYTE srcId) | |
91 { | |
92 char *me="@SPKR: "; | |
93 int state; | |
94 | |
95 TRACE_FUNCTION("queatAtSPKR()"); | |
96 | |
97 state = AI_ReadBit(1); | |
98 sprintf(g_sa, "%s%d", me, state); | |
99 | |
100 io_sendMessage(srcId, g_sa, ATI_NORMAL_OUTPUT); | |
101 | |
102 return (ATI_CMPL); | |
103 } | |
104 #endif | |
105 | |
106 /* AT@SND - emit sound through Condat API */ | |
107 GLOBAL T_ATI_RSLT atAtSND ( char *cl, UBYTE srcId ) | |
108 { | |
109 UBYTE sound_id = TONES_KEYBEEP; | |
110 | |
111 cl = parse(cl, "x", &sound_id); | |
112 audio_PlaySoundID(AUDIO_SPEAKER, sound_id, 0, AUDIO_PLAY_ONCE); | |
113 return (ATI_CMPL); | |
114 } | |
115 | |
116 static void audio_callback(void *event_from_audio) | |
117 { | |
118 /* do nothing at this time */ | |
119 } | |
120 | |
121 /* | |
122 * PURPOSE : @AUL command (Audio table load) | |
123 */ | |
124 | |
125 static char aul_name[AUDIO_MODE_FILENAME_MAX_SIZE]; | |
126 | |
127 GLOBAL T_ATI_RSLT atAtAUL (char *cl, UBYTE srcId) | |
128 { | |
129 T_AUDIO_MODE_LOAD aul_param; | |
130 T_RV_RETURN return_path; | |
131 | |
132 TRACE_FUNCTION("atAtAUL()"); | |
133 | |
134 cl = parse(cl, "S", (LONG)(sizeof(aul_param.audio_mode_filename)), | |
135 aul_param.audio_mode_filename); | |
136 if (!cl || !aul_param.audio_mode_filename[0]) | |
137 return (ATI_FAIL); | |
138 | |
139 /* Openmoko backward compatibility */ | |
140 if (isdigit(aul_param.audio_mode_filename[0]) && | |
141 !aul_param.audio_mode_filename[1]) | |
142 sprintf(aul_param.audio_mode_filename, "para%c", | |
143 aul_param.audio_mode_filename[0]); | |
144 | |
145 return_path.addr_id = NULL; | |
146 return_path.callback_func = audio_callback; | |
147 if (audio_mode_load(&aul_param, return_path) == AUDIO_OK) { | |
148 strcpy(aul_name, aul_param.audio_mode_filename); | |
149 return (ATI_CMPL); | |
150 } else | |
151 return (ATI_FAIL); | |
152 } | |
153 | |
154 GLOBAL T_ATI_RSLT queatAtAUL (char *cl, UBYTE srcId) | |
155 { | |
156 char *me="@AUL: "; | |
157 | |
158 TRACE_FUNCTION("queatAtAUL()"); | |
159 | |
160 if (aul_name[0]) | |
161 sprintf(g_sa, "%s/aud/%s.cfg", me, aul_name); | |
162 else | |
163 sprintf(g_sa, "%s", me); | |
164 | |
165 io_sendMessage(srcId, g_sa, ATI_NORMAL_OUTPUT); | |
166 | |
167 return (ATI_CMPL); | |
168 } | |
169 | |
170 #ifdef CONFIG_TARGET_FCDEV3B | |
171 /* AT@VPATH - configure digital voice path */ | |
172 GLOBAL T_ATI_RSLT atAtVPATH ( char *cl, UBYTE srcId ) | |
173 { | |
174 int vpath_int; | |
175 T_AUDIO_VOICE_PATH_SETTING vpath; | |
176 T_AUDIO_FULL_ACCESS_WRITE audio_param; | |
177 T_RV_RETURN return_path; | |
178 | |
179 TRACE_FUNCTION("atAtVPATH()"); | |
180 | |
181 cl = parse(cl, "D", &vpath_int); | |
182 if (!cl) | |
183 return (ATI_FAIL); | |
184 vpath = vpath_int; | |
185 audio_param.variable_indentifier = AUDIO_PATH_USED; | |
186 audio_param.data = &vpath; | |
187 | |
188 return_path.addr_id = NULL; | |
189 return_path.callback_func = audio_callback; | |
190 if (audio_full_access_write(&audio_param, return_path) == AUDIO_OK) | |
191 return (ATI_CMPL); | |
192 else | |
193 return (ATI_FAIL); | |
194 } | |
195 | |
196 GLOBAL T_ATI_RSLT queatAtVPATH (char *cl, UBYTE srcId) | |
197 { | |
198 char *me="@VPATH: "; | |
199 T_AUDIO_VOICE_PATH_SETTING vpath; | |
200 T_AUDIO_FULL_ACCESS_READ audio_param; | |
201 | |
202 TRACE_FUNCTION("queatAtVPATH()"); | |
203 | |
204 audio_param.variable_indentifier = AUDIO_PATH_USED; | |
205 audio_param.data = &vpath; | |
206 if (audio_full_access_read(&audio_param) != AUDIO_OK) | |
207 return (ATI_FAIL); | |
208 | |
209 sprintf(g_sa, "%s%d", me, vpath); | |
210 | |
211 io_sendMessage(srcId, g_sa, ATI_NORMAL_OUTPUT); | |
212 | |
213 return (ATI_CMPL); | |
214 } | |
215 #endif | |
216 | |
217 /* AT@E1 - play an E1 format melody */ | |
218 GLOBAL T_ATI_RSLT atAtE1 ( char *cl, UBYTE srcId ) | |
219 { | |
220 T_AUDIO_MELODY_E1_PARAMETER e1_param; | |
221 T_RV_RETURN return_path; | |
222 | |
223 cl = parse(cl, "S", (LONG)(sizeof(e1_param.melody_name)), | |
224 e1_param.melody_name); | |
225 if (!cl || !e1_param.melody_name[0]) | |
226 return (ATI_FAIL); | |
227 e1_param.loopback = AUDIO_MELODY_NO_LOOPBACK; | |
228 e1_param.melody_mode = AUDIO_MELODY_NORMAL_MODE; | |
229 | |
230 return_path.addr_id = NULL; | |
231 return_path.callback_func = audio_callback; | |
232 if (audio_melody_E1_start(&e1_param, return_path) == AUDIO_OK) | |
233 return (ATI_CMPL); | |
234 else | |
235 return (ATI_FAIL); | |
236 } | |
237 | |
238 /* AT@E2 - play an E2 format melody */ | |
239 GLOBAL T_ATI_RSLT atAtE2 ( char *cl, UBYTE srcId ) | |
240 { | |
241 T_AUDIO_MELODY_E2_PARAMETER e2_param; | |
242 T_RV_RETURN return_path; | |
243 | |
244 cl = parse(cl, "S", (LONG)(sizeof(e2_param.melody_E2_name)), | |
245 e2_param.melody_E2_name); | |
246 if (!cl || !e2_param.melody_E2_name[0]) | |
247 return (ATI_FAIL); | |
248 e2_param.E2_loopback = AUDIO_MELODY_NO_LOOPBACK; | |
249 e2_param.melody_E2_mode = AUDIO_MELODY_NORMAL_MODE; | |
250 | |
251 return_path.addr_id = NULL; | |
252 return_path.callback_func = audio_callback; | |
253 if (audio_melody_E2_start(&e2_param, return_path) == AUDIO_OK) | |
254 return (ATI_CMPL); | |
255 else | |
256 return (ATI_FAIL); | |
257 } | |
258 | |
259 /* AT@E2LSI - load melody E2 instrument list file */ | |
260 GLOBAL T_ATI_RSLT atAtE2LSI ( char *cl, UBYTE srcId ) | |
261 { | |
262 T_AUDIO_MELODY_E2_LOAD_FILE_INSTR_PARAMETER e2_lsi_param; | |
263 | |
264 cl = parse(cl, "S", (LONG)(sizeof(e2_lsi_param.melody_E2_file_name)), | |
265 e2_lsi_param.melody_E2_file_name); | |
266 if (!cl || !e2_lsi_param.melody_E2_file_name[0]) | |
267 return (ATI_FAIL); | |
268 | |
269 if (audio_melody_E2_load_file_instruments(&e2_lsi_param) == AUDIO_OK) | |
270 return (ATI_CMPL); | |
271 else | |
272 return (ATI_FAIL); | |
273 } | |
274 | |
275 /* AT@TONE - exercise TONES through RiViera Audio Service API */ | |
276 GLOBAL T_ATI_RSLT atAtTONE ( char *cl, UBYTE srcId ) | |
277 { | |
278 int tone_start[3], tone_stop[3], tone_freq[3], tone_ampl[3]; | |
279 int frame_dur, sequence_dur, period_dur, repetition; | |
280 int i; | |
281 T_AUDIO_TONES_PARAMETER t; | |
282 T_RV_RETURN return_path; | |
283 | |
284 cl = parse(cl, "DDDDDDDDDDDDDDDD", | |
285 &tone_start[0], &tone_stop[0], &tone_freq[0], &tone_ampl[0], | |
286 &tone_start[1], &tone_stop[1], &tone_freq[1], &tone_ampl[1], | |
287 &tone_start[2], &tone_stop[2], &tone_freq[2], &tone_ampl[2], | |
288 &frame_dur, &sequence_dur, &period_dur, &repetition); | |
289 if (!cl) | |
290 return (ATI_FAIL); | |
291 for (i = 0; i < 3; i++) { | |
292 t.tones[i].start_tone = tone_start[i]; | |
293 t.tones[i].stop_tone = tone_stop[i]; | |
294 t.tones[i].frequency_tone = tone_freq[i]; | |
295 t.tones[i].amplitude_tone = -tone_ampl[i]; | |
296 } | |
297 t.frame_duration = frame_dur; | |
298 t.sequence_duration = sequence_dur; | |
299 t.period_duration = period_dur; | |
300 t.repetition = repetition; | |
301 | |
302 return_path.addr_id = NULL; | |
303 return_path.callback_func = audio_callback; | |
304 if (audio_tones_start(&t, return_path) == AUDIO_OK) | |
305 return (ATI_CMPL); | |
306 else | |
307 return (ATI_FAIL); | |
308 } | |
309 | |
310 /* AT@TSTOP - stop tones started with AT@TONE */ | |
311 GLOBAL T_ATI_RSLT atAtTSTOP ( char *cl, UBYTE srcId ) | |
312 { | |
313 T_RV_RETURN return_path; | |
314 | |
315 return_path.addr_id = NULL; | |
316 return_path.callback_func = audio_callback; | |
317 if (audio_tones_stop(return_path) == AUDIO_OK) | |
318 return (ATI_CMPL); | |
319 else | |
320 return (ATI_FAIL); | |
321 } | |
322 | |
323 /* AT@VMP - play back a voice memo recording */ | |
324 GLOBAL T_ATI_RSLT atAtVMP ( char *cl, UBYTE srcId ) | |
325 { | |
326 T_AUDIO_VM_PLAY_PARAMETER play_param; | |
327 T_RV_RETURN return_path; | |
328 | |
329 cl = parse(cl, "S", (LONG)(sizeof(play_param.memo_name)), | |
330 play_param.memo_name); | |
331 if (!cl || !play_param.memo_name[0]) | |
332 return (ATI_FAIL); | |
333 | |
334 return_path.addr_id = NULL; | |
335 return_path.callback_func = audio_callback; | |
336 if (audio_vm_play_start(&play_param, return_path) == AUDIO_OK) | |
337 return (ATI_CMPL); | |
338 else | |
339 return (ATI_FAIL); | |
340 } | |
341 | |
342 /* AT@VMPS - stop VM play started with AT@VMP */ | |
343 GLOBAL T_ATI_RSLT atAtVMPS ( char *cl, UBYTE srcId ) | |
344 { | |
345 T_RV_RETURN return_path; | |
346 | |
347 return_path.addr_id = NULL; | |
348 return_path.callback_func = audio_callback; | |
349 if (audio_vm_play_stop(return_path) == AUDIO_OK) | |
350 return (ATI_CMPL); | |
351 else | |
352 return (ATI_FAIL); | |
353 } | |
354 | |
355 static const T_AUDIO_TONES_PARAMETER recorder_warning_tone = { | |
356 0, 500, 1400, -5, | |
357 0, 500, 0, 0, | |
358 0, 500, 0, 0, | |
359 500, 500, 15000, TONE_INFINITE | |
360 }; | |
361 | |
362 /* AT@VMR - record a voice memo */ | |
363 GLOBAL T_ATI_RSLT atAtVMR ( char *cl, UBYTE srcId ) | |
364 { | |
365 T_AUDIO_VM_RECORD_PARAMETER record_param; | |
366 int duration = 0, compression = 0; | |
367 LONG mic_gain = 0x100, network_gain = 0x100; | |
368 T_RV_RETURN return_path; | |
369 | |
370 cl = parse(cl, "Sddyy", (LONG)(sizeof(record_param.memo_name)), | |
371 record_param.memo_name, &duration, &compression, | |
372 &mic_gain, &network_gain); | |
373 if (!cl || !record_param.memo_name[0] || !duration) | |
374 return (ATI_FAIL); | |
375 record_param.memo_duration = duration; | |
376 record_param.compression_mode = compression; | |
377 record_param.microphone_gain = mic_gain; | |
378 record_param.network_gain = network_gain; | |
379 | |
380 return_path.addr_id = NULL; | |
381 return_path.callback_func = audio_callback; | |
382 if (audio_vm_record_start(&record_param, | |
383 (T_AUDIO_TONES_PARAMETER *) | |
384 &recorder_warning_tone, | |
385 return_path) == AUDIO_OK) | |
386 return (ATI_CMPL); | |
387 else | |
388 return (ATI_FAIL); | |
389 } | |
390 | |
391 /* AT@VMRS - stop VM recording started with AT@VMR */ | |
392 GLOBAL T_ATI_RSLT atAtVMRS ( char *cl, UBYTE srcId ) | |
393 { | |
394 T_RV_RETURN return_path; | |
395 | |
396 return_path.addr_id = NULL; | |
397 return_path.callback_func = audio_callback; | |
398 if (audio_vm_record_stop(return_path) == AUDIO_OK) | |
399 return (ATI_CMPL); | |
400 else | |
401 return (ATI_FAIL); | |
402 } | |
403 | |
404 #endif /* ATI_AUDIO_C */ |