FreeCalypso > hg > fc-tourmaline
comparison src/g23m-aci/aci/ati_audio.c @ 1:fa8dc04885d8
src/g23m-*: import from Magnetite
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 16 Oct 2020 06:25:50 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
0:4e78acac3d88 | 1:fa8dc04885d8 |
---|---|
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.h" | |
70 #include "armio.h" | |
71 | |
72 #if GPIO1_SPEAKER_CTRL | |
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_MCSI_MODEM | |
171 extern UBYTE aci_digital_voice_autoswitch; | |
172 | |
173 /* AT@VPATH - configure digital voice path */ | |
174 GLOBAL T_ATI_RSLT atAtVPATH ( char *cl, UBYTE srcId ) | |
175 { | |
176 int vpath_int; | |
177 T_AUDIO_VOICE_PATH_SETTING vpath; | |
178 T_AUDIO_FULL_ACCESS_WRITE audio_param; | |
179 T_RV_RETURN return_path; | |
180 | |
181 TRACE_FUNCTION("atAtVPATH()"); | |
182 | |
183 cl = parse(cl, "D", &vpath_int); | |
184 if (!cl) | |
185 return (ATI_FAIL); | |
186 vpath = vpath_int; | |
187 audio_param.variable_indentifier = AUDIO_PATH_USED; | |
188 audio_param.data = &vpath; | |
189 | |
190 return_path.addr_id = NULL; | |
191 return_path.callback_func = audio_callback; | |
192 if (audio_full_access_write(&audio_param, return_path) == AUDIO_OK) | |
193 return (ATI_CMPL); | |
194 else | |
195 return (ATI_FAIL); | |
196 } | |
197 | |
198 GLOBAL T_ATI_RSLT queatAtVPATH (char *cl, UBYTE srcId) | |
199 { | |
200 char *me="@VPATH: "; | |
201 T_AUDIO_VOICE_PATH_SETTING vpath; | |
202 T_AUDIO_FULL_ACCESS_READ audio_param; | |
203 | |
204 TRACE_FUNCTION("queatAtVPATH()"); | |
205 | |
206 audio_param.variable_indentifier = AUDIO_PATH_USED; | |
207 audio_param.data = &vpath; | |
208 if (audio_full_access_read(&audio_param) != AUDIO_OK) | |
209 return (ATI_FAIL); | |
210 | |
211 sprintf(g_sa, "%s%d", me, vpath); | |
212 | |
213 io_sendMessage(srcId, g_sa, ATI_NORMAL_OUTPUT); | |
214 | |
215 return (ATI_CMPL); | |
216 } | |
217 | |
218 /* AT@VSEL - configure digital voice path automatic operation */ | |
219 GLOBAL T_ATI_RSLT atAtVSEL ( char *cl, UBYTE srcId ) | |
220 { | |
221 int vsel_int; | |
222 | |
223 TRACE_FUNCTION("atAtVSEL()"); | |
224 | |
225 cl = parse(cl, "D", &vsel_int); | |
226 if (!cl) | |
227 return (ATI_FAIL); | |
228 if (vsel_int != 0 && vsel_int != 1) | |
229 return (ATI_FAIL); | |
230 aci_digital_voice_autoswitch = vsel_int; | |
231 return (ATI_CMPL); | |
232 } | |
233 | |
234 GLOBAL T_ATI_RSLT queatAtVSEL (char *cl, UBYTE srcId) | |
235 { | |
236 char *me="@VSEL: "; | |
237 | |
238 TRACE_FUNCTION("queatAtVSEL()"); | |
239 | |
240 sprintf(g_sa, "%s%u", me, aci_digital_voice_autoswitch); | |
241 io_sendMessage(srcId, g_sa, ATI_NORMAL_OUTPUT); | |
242 return (ATI_CMPL); | |
243 } | |
244 #endif | |
245 | |
246 static char melody_E1_name[AUDIO_PATH_NAME_MAX_SIZE]; | |
247 | |
248 /* AT@E1 - play an E1 format melody */ | |
249 GLOBAL T_ATI_RSLT atAtE1 ( char *cl, UBYTE srcId ) | |
250 { | |
251 T_AUDIO_MELODY_E1_PARAMETER e1_param; | |
252 int loopback = 0; | |
253 T_RV_RETURN return_path; | |
254 | |
255 cl = parse(cl, "Sd", (LONG)(sizeof(e1_param.melody_name)), | |
256 e1_param.melody_name, &loopback); | |
257 if (!cl || !e1_param.melody_name[0]) | |
258 return (ATI_FAIL); | |
259 e1_param.loopback = loopback; | |
260 e1_param.melody_mode = AUDIO_MELODY_NORMAL_MODE; | |
261 | |
262 return_path.addr_id = NULL; | |
263 return_path.callback_func = audio_callback; | |
264 if (audio_melody_E1_start(&e1_param, return_path) == AUDIO_OK) { | |
265 strcpy(melody_E1_name, e1_param.melody_name); | |
266 return (ATI_CMPL); | |
267 } else | |
268 return (ATI_FAIL); | |
269 } | |
270 | |
271 /* AT@E1STOP - stop melody started with AT@E1 */ | |
272 GLOBAL T_ATI_RSLT atAtE1STOP ( char *cl, UBYTE srcId ) | |
273 { | |
274 T_AUDIO_MELODY_E1_STOP_PARAMETER e1stop_param; | |
275 T_RV_RETURN return_path; | |
276 | |
277 if (!melody_E1_name[0]) | |
278 return (ATI_FAIL); | |
279 strcpy(e1stop_param.melody_name, melody_E1_name); | |
280 | |
281 return_path.addr_id = NULL; | |
282 return_path.callback_func = audio_callback; | |
283 if (audio_melody_E1_stop(&e1stop_param, return_path) == AUDIO_OK) | |
284 return (ATI_CMPL); | |
285 else | |
286 return (ATI_FAIL); | |
287 } | |
288 | |
289 static char melody_E2_name[AUDIO_PATH_NAME_MAX_SIZE]; | |
290 | |
291 /* AT@E2 - play an E2 format melody */ | |
292 GLOBAL T_ATI_RSLT atAtE2 ( char *cl, UBYTE srcId ) | |
293 { | |
294 T_AUDIO_MELODY_E2_PARAMETER e2_param; | |
295 int loopback = 0; | |
296 T_RV_RETURN return_path; | |
297 | |
298 cl = parse(cl, "Sd", (LONG)(sizeof(e2_param.melody_E2_name)), | |
299 e2_param.melody_E2_name, &loopback); | |
300 if (!cl || !e2_param.melody_E2_name[0]) | |
301 return (ATI_FAIL); | |
302 e2_param.E2_loopback = loopback; | |
303 e2_param.melody_E2_mode = AUDIO_MELODY_NORMAL_MODE; | |
304 | |
305 return_path.addr_id = NULL; | |
306 return_path.callback_func = audio_callback; | |
307 if (audio_melody_E2_start(&e2_param, return_path) == AUDIO_OK) { | |
308 strcpy(melody_E2_name, e2_param.melody_E2_name); | |
309 return (ATI_CMPL); | |
310 } else | |
311 return (ATI_FAIL); | |
312 } | |
313 | |
314 /* AT@E2LSI - load melody E2 instrument list file */ | |
315 GLOBAL T_ATI_RSLT atAtE2LSI ( char *cl, UBYTE srcId ) | |
316 { | |
317 T_AUDIO_MELODY_E2_LOAD_FILE_INSTR_PARAMETER e2_lsi_param; | |
318 | |
319 cl = parse(cl, "S", (LONG)(sizeof(e2_lsi_param.melody_E2_file_name)), | |
320 e2_lsi_param.melody_E2_file_name); | |
321 if (!cl || !e2_lsi_param.melody_E2_file_name[0]) | |
322 return (ATI_FAIL); | |
323 | |
324 if (audio_melody_E2_load_file_instruments(&e2_lsi_param) == AUDIO_OK) | |
325 return (ATI_CMPL); | |
326 else | |
327 return (ATI_FAIL); | |
328 } | |
329 | |
330 /* AT@E2STOP - stop melody started with AT@E2 */ | |
331 GLOBAL T_ATI_RSLT atAtE2STOP ( char *cl, UBYTE srcId ) | |
332 { | |
333 T_AUDIO_MELODY_E2_STOP_PARAMETER e2stop_param; | |
334 T_RV_RETURN return_path; | |
335 | |
336 if (!melody_E2_name[0]) | |
337 return (ATI_FAIL); | |
338 strcpy(e2stop_param.melody_E2_name, melody_E2_name); | |
339 | |
340 return_path.addr_id = NULL; | |
341 return_path.callback_func = audio_callback; | |
342 if (audio_melody_E2_stop(&e2stop_param, return_path) == AUDIO_OK) | |
343 return (ATI_CMPL); | |
344 else | |
345 return (ATI_FAIL); | |
346 } | |
347 | |
348 /* AT@TONE - exercise TONES through RiViera Audio Service API */ | |
349 GLOBAL T_ATI_RSLT atAtTONE ( char *cl, UBYTE srcId ) | |
350 { | |
351 int tone_start[3], tone_stop[3], tone_freq[3], tone_ampl[3]; | |
352 int frame_dur, sequence_dur, period_dur, repetition; | |
353 int i; | |
354 T_AUDIO_TONES_PARAMETER t; | |
355 T_RV_RETURN return_path; | |
356 | |
357 cl = parse(cl, "DDDDDDDDDDDDDDDD", | |
358 &tone_start[0], &tone_stop[0], &tone_freq[0], &tone_ampl[0], | |
359 &tone_start[1], &tone_stop[1], &tone_freq[1], &tone_ampl[1], | |
360 &tone_start[2], &tone_stop[2], &tone_freq[2], &tone_ampl[2], | |
361 &frame_dur, &sequence_dur, &period_dur, &repetition); | |
362 if (!cl) | |
363 return (ATI_FAIL); | |
364 for (i = 0; i < 3; i++) { | |
365 t.tones[i].start_tone = tone_start[i]; | |
366 t.tones[i].stop_tone = tone_stop[i]; | |
367 t.tones[i].frequency_tone = tone_freq[i]; | |
368 t.tones[i].amplitude_tone = -tone_ampl[i]; | |
369 } | |
370 t.frame_duration = frame_dur; | |
371 t.sequence_duration = sequence_dur; | |
372 t.period_duration = period_dur; | |
373 t.repetition = repetition; | |
374 | |
375 return_path.addr_id = NULL; | |
376 return_path.callback_func = audio_callback; | |
377 if (audio_tones_start(&t, return_path) == AUDIO_OK) | |
378 return (ATI_CMPL); | |
379 else | |
380 return (ATI_FAIL); | |
381 } | |
382 | |
383 /* AT@TSTOP - stop tones started with AT@TONE */ | |
384 GLOBAL T_ATI_RSLT atAtTSTOP ( char *cl, UBYTE srcId ) | |
385 { | |
386 T_RV_RETURN return_path; | |
387 | |
388 return_path.addr_id = NULL; | |
389 return_path.callback_func = audio_callback; | |
390 if (audio_tones_stop(return_path) == AUDIO_OK) | |
391 return (ATI_CMPL); | |
392 else | |
393 return (ATI_FAIL); | |
394 } | |
395 | |
396 /* AT@VMP - play back a voice memo recording */ | |
397 GLOBAL T_ATI_RSLT atAtVMP ( char *cl, UBYTE srcId ) | |
398 { | |
399 T_AUDIO_VM_PLAY_PARAMETER play_param; | |
400 T_RV_RETURN return_path; | |
401 | |
402 cl = parse(cl, "S", (LONG)(sizeof(play_param.memo_name)), | |
403 play_param.memo_name); | |
404 if (!cl || !play_param.memo_name[0]) | |
405 return (ATI_FAIL); | |
406 | |
407 return_path.addr_id = NULL; | |
408 return_path.callback_func = audio_callback; | |
409 if (audio_vm_play_start(&play_param, return_path) == AUDIO_OK) | |
410 return (ATI_CMPL); | |
411 else | |
412 return (ATI_FAIL); | |
413 } | |
414 | |
415 /* AT@VMPS - stop VM play started with AT@VMP */ | |
416 GLOBAL T_ATI_RSLT atAtVMPS ( char *cl, UBYTE srcId ) | |
417 { | |
418 T_RV_RETURN return_path; | |
419 | |
420 return_path.addr_id = NULL; | |
421 return_path.callback_func = audio_callback; | |
422 if (audio_vm_play_stop(return_path) == AUDIO_OK) | |
423 return (ATI_CMPL); | |
424 else | |
425 return (ATI_FAIL); | |
426 } | |
427 | |
428 static const T_AUDIO_TONES_PARAMETER recorder_warning_tone = { | |
429 0, 500, 1400, -5, | |
430 0, 500, 0, 0, | |
431 0, 500, 0, 0, | |
432 500, 500, 15000, TONE_INFINITE | |
433 }; | |
434 | |
435 /* AT@VMR - record a voice memo */ | |
436 GLOBAL T_ATI_RSLT atAtVMR ( char *cl, UBYTE srcId ) | |
437 { | |
438 T_AUDIO_VM_RECORD_PARAMETER record_param; | |
439 int duration = 0, compression = 0; | |
440 LONG mic_gain = 0x100, network_gain = 0x100; | |
441 T_RV_RETURN return_path; | |
442 | |
443 cl = parse(cl, "Sddyy", (LONG)(sizeof(record_param.memo_name)), | |
444 record_param.memo_name, &duration, &compression, | |
445 &mic_gain, &network_gain); | |
446 if (!cl || !record_param.memo_name[0] || !duration) | |
447 return (ATI_FAIL); | |
448 record_param.memo_duration = duration; | |
449 record_param.compression_mode = compression; | |
450 record_param.microphone_gain = mic_gain; | |
451 record_param.network_gain = network_gain; | |
452 | |
453 return_path.addr_id = NULL; | |
454 return_path.callback_func = audio_callback; | |
455 if (audio_vm_record_start(&record_param, | |
456 (T_AUDIO_TONES_PARAMETER *) | |
457 &recorder_warning_tone, | |
458 return_path) == AUDIO_OK) | |
459 return (ATI_CMPL); | |
460 else | |
461 return (ATI_FAIL); | |
462 } | |
463 | |
464 /* AT@VMRS - stop VM recording started with AT@VMR */ | |
465 GLOBAL T_ATI_RSLT atAtVMRS ( char *cl, UBYTE srcId ) | |
466 { | |
467 T_RV_RETURN return_path; | |
468 | |
469 return_path.addr_id = NULL; | |
470 return_path.callback_func = audio_callback; | |
471 if (audio_vm_record_stop(return_path) == AUDIO_OK) | |
472 return (ATI_CMPL); | |
473 else | |
474 return (ATI_FAIL); | |
475 } | |
476 | |
477 #endif /* ATI_AUDIO_C */ |