FreeCalypso > hg > fc-magnetite
comparison src/g23m-aci/aci/ati_audio.c @ 247:294c26c07561
aci3: started adding Openmoko and FreeCalypso AT commands
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Mon, 24 Jul 2017 06:52:58 +0000 |
parents | |
children | 85b38e37810b |
comparison
equal
deleted
inserted
replaced
246:a33da2d26a31 | 247:294c26c07561 |
---|---|
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 /* AT@SND - emit sound through Condat API */ | |
70 GLOBAL T_ATI_RSLT atAtSND ( char *cl, UBYTE srcId ) | |
71 { | |
72 UBYTE sound_id = TONES_KEYBEEP; | |
73 | |
74 cl = parse(cl, "x", &sound_id); | |
75 audio_PlaySoundID(AUDIO_SPEAKER, sound_id, 0, AUDIO_PLAY_ONCE); | |
76 return (ATI_CMPL); | |
77 } | |
78 | |
79 static void audio_callback(void *event_from_audio) | |
80 { | |
81 /* do nothing at this time */ | |
82 } | |
83 | |
84 /* | |
85 * PURPOSE : @AUL command (Audio table load) | |
86 */ | |
87 | |
88 static char aul_name[AUDIO_MODE_FILENAME_MAX_SIZE]; | |
89 | |
90 GLOBAL T_ATI_RSLT atAtAUL (char *cl, UBYTE srcId) | |
91 { | |
92 T_AUDIO_MODE_LOAD aul_param; | |
93 T_RV_RETURN return_path; | |
94 | |
95 TRACE_FUNCTION("atAtAUL()"); | |
96 | |
97 cl = parse(cl, "S", (LONG)(sizeof(aul_param.audio_mode_filename)), | |
98 aul_param.audio_mode_filename); | |
99 if (!cl || !aul_param.audio_mode_filename[0]) | |
100 return (ATI_FAIL); | |
101 | |
102 /* Openmoko backward compatibility */ | |
103 if (isdigit(aul_param.audio_mode_filename[0]) && | |
104 !aul_param.audio_mode_filename[1]) | |
105 sprintf(aul_param.audio_mode_filename, "para%c", | |
106 aul_param.audio_mode_filename[0]); | |
107 | |
108 return_path.addr_id = NULL; | |
109 return_path.callback_func = audio_callback; | |
110 if (audio_mode_load(&aul_param, return_path) == AUDIO_OK) { | |
111 strcpy(aul_name, aul_param.audio_mode_filename); | |
112 return (ATI_CMPL); | |
113 } else | |
114 return (ATI_FAIL); | |
115 } | |
116 | |
117 GLOBAL T_ATI_RSLT queatAtAUL (char *cl, UBYTE srcId) | |
118 { | |
119 char *me="@AUL: "; | |
120 | |
121 TRACE_FUNCTION("queatAtAUL()"); | |
122 | |
123 if (aul_name[0]) | |
124 sprintf(g_sa, "%s/aud/%s.cfg", me, aul_name); | |
125 else | |
126 sprintf(g_sa, "%s", me); | |
127 | |
128 io_sendMessage(srcId, g_sa, ATI_NORMAL_OUTPUT); | |
129 | |
130 return (ATI_CMPL); | |
131 } | |
132 | |
133 /* AT@E1 - play an E1 format melody */ | |
134 GLOBAL T_ATI_RSLT atAtE1 ( char *cl, UBYTE srcId ) | |
135 { | |
136 T_AUDIO_MELODY_E1_PARAMETER e1_param; | |
137 T_RV_RETURN return_path; | |
138 | |
139 cl = parse(cl, "S", (LONG)(sizeof(e1_param.melody_name)), | |
140 e1_param.melody_name); | |
141 if (!cl || !e1_param.melody_name[0]) | |
142 return (ATI_FAIL); | |
143 e1_param.loopback = AUDIO_MELODY_NO_LOOPBACK; | |
144 e1_param.melody_mode = AUDIO_MELODY_NORMAL_MODE; | |
145 | |
146 return_path.addr_id = NULL; | |
147 return_path.callback_func = audio_callback; | |
148 if (audio_melody_E1_start(&e1_param, return_path) == AUDIO_OK) | |
149 return (ATI_CMPL); | |
150 else | |
151 return (ATI_FAIL); | |
152 } | |
153 | |
154 /* AT@E2 - play an E2 format melody */ | |
155 GLOBAL T_ATI_RSLT atAtE2 ( char *cl, UBYTE srcId ) | |
156 { | |
157 T_AUDIO_MELODY_E2_PARAMETER e2_param; | |
158 T_RV_RETURN return_path; | |
159 | |
160 cl = parse(cl, "S", (LONG)(sizeof(e2_param.melody_E2_name)), | |
161 e2_param.melody_E2_name); | |
162 if (!cl || !e2_param.melody_E2_name[0]) | |
163 return (ATI_FAIL); | |
164 e2_param.E2_loopback = AUDIO_MELODY_NO_LOOPBACK; | |
165 e2_param.melody_E2_mode = AUDIO_MELODY_NORMAL_MODE; | |
166 | |
167 return_path.addr_id = NULL; | |
168 return_path.callback_func = audio_callback; | |
169 if (audio_melody_E2_start(&e2_param, return_path) == AUDIO_OK) | |
170 return (ATI_CMPL); | |
171 else | |
172 return (ATI_FAIL); | |
173 } | |
174 | |
175 /* AT@E2LSI - load melody E2 instrument list file */ | |
176 GLOBAL T_ATI_RSLT atAtE2LSI ( char *cl, UBYTE srcId ) | |
177 { | |
178 T_AUDIO_MELODY_E2_LOAD_FILE_INSTR_PARAMETER e2_lsi_param; | |
179 | |
180 cl = parse(cl, "S", (LONG)(sizeof(e2_lsi_param.melody_E2_file_name)), | |
181 e2_lsi_param.melody_E2_file_name); | |
182 if (!cl || !e2_lsi_param.melody_E2_file_name[0]) | |
183 return (ATI_FAIL); | |
184 | |
185 if (audio_melody_E2_load_file_instruments(&e2_lsi_param) == AUDIO_OK) | |
186 return (ATI_CMPL); | |
187 else | |
188 return (ATI_FAIL); | |
189 } | |
190 | |
191 /* AT@TONE - exercise TONES through RiViera Audio Service API */ | |
192 GLOBAL T_ATI_RSLT atAtTONE ( char *cl, UBYTE srcId ) | |
193 { | |
194 int tone_start[3], tone_stop[3], tone_freq[3], tone_ampl[3]; | |
195 int frame_dur, sequence_dur, period_dur, repetition; | |
196 int i; | |
197 T_AUDIO_TONES_PARAMETER t; | |
198 T_RV_RETURN return_path; | |
199 | |
200 cl = parse(cl, "DDDDDDDDDDDDDDDD", | |
201 &tone_start[0], &tone_stop[0], &tone_freq[0], &tone_ampl[0], | |
202 &tone_start[1], &tone_stop[1], &tone_freq[1], &tone_ampl[1], | |
203 &tone_start[2], &tone_stop[2], &tone_freq[2], &tone_ampl[2], | |
204 &frame_dur, &sequence_dur, &period_dur, &repetition); | |
205 if (!cl) | |
206 return (ATI_FAIL); | |
207 for (i = 0; i < 3; i++) { | |
208 t.tones[i].start_tone = tone_start[i]; | |
209 t.tones[i].stop_tone = tone_stop[i]; | |
210 t.tones[i].frequency_tone = tone_freq[i]; | |
211 t.tones[i].amplitude_tone = -tone_ampl[i]; | |
212 } | |
213 t.frame_duration = frame_dur; | |
214 t.sequence_duration = sequence_dur; | |
215 t.period_duration = period_dur; | |
216 t.repetition = repetition; | |
217 | |
218 return_path.addr_id = NULL; | |
219 return_path.callback_func = audio_callback; | |
220 if (audio_tones_start(&t, return_path) == AUDIO_OK) | |
221 return (ATI_CMPL); | |
222 else | |
223 return (ATI_FAIL); | |
224 } | |
225 | |
226 /* AT@TSTOP - stop tones started with AT@TONE */ | |
227 GLOBAL T_ATI_RSLT atAtTSTOP ( char *cl, UBYTE srcId ) | |
228 { | |
229 T_RV_RETURN return_path; | |
230 | |
231 return_path.addr_id = NULL; | |
232 return_path.callback_func = audio_callback; | |
233 if (audio_tones_stop(return_path) == AUDIO_OK) | |
234 return (ATI_CMPL); | |
235 else | |
236 return (ATI_FAIL); | |
237 } | |
238 | |
239 /* AT@VMP - play back a voice memo recording */ | |
240 GLOBAL T_ATI_RSLT atAtVMP ( char *cl, UBYTE srcId ) | |
241 { | |
242 T_AUDIO_VM_PLAY_PARAMETER play_param; | |
243 T_RV_RETURN return_path; | |
244 | |
245 cl = parse(cl, "S", (LONG)(sizeof(play_param.memo_name)), | |
246 play_param.memo_name); | |
247 if (!cl || !play_param.memo_name[0]) | |
248 return (ATI_FAIL); | |
249 | |
250 return_path.addr_id = NULL; | |
251 return_path.callback_func = audio_callback; | |
252 if (audio_vm_play_start(&play_param, return_path) == AUDIO_OK) | |
253 return (ATI_CMPL); | |
254 else | |
255 return (ATI_FAIL); | |
256 } | |
257 | |
258 /* AT@VMPS - stop VM play started with AT@VMP */ | |
259 GLOBAL T_ATI_RSLT atAtVMPS ( char *cl, UBYTE srcId ) | |
260 { | |
261 T_RV_RETURN return_path; | |
262 | |
263 return_path.addr_id = NULL; | |
264 return_path.callback_func = audio_callback; | |
265 if (audio_vm_play_stop(return_path) == AUDIO_OK) | |
266 return (ATI_CMPL); | |
267 else | |
268 return (ATI_FAIL); | |
269 } | |
270 | |
271 static const T_AUDIO_TONES_PARAMETER recorder_warning_tone = { | |
272 0, 500, 1400, -5, | |
273 0, 500, 0, 0, | |
274 0, 500, 0, 0, | |
275 500, 500, 15000, TONE_INFINITE | |
276 }; | |
277 | |
278 /* AT@VMR - record a voice memo */ | |
279 GLOBAL T_ATI_RSLT atAtVMR ( char *cl, UBYTE srcId ) | |
280 { | |
281 T_AUDIO_VM_RECORD_PARAMETER record_param; | |
282 int duration = 0, compression = 0; | |
283 LONG mic_gain = 0x100, network_gain = 0x100; | |
284 T_RV_RETURN return_path; | |
285 | |
286 cl = parse(cl, "Sddyy", (LONG)(sizeof(record_param.memo_name)), | |
287 record_param.memo_name, &duration, &compression, | |
288 &mic_gain, &network_gain); | |
289 if (!cl || !record_param.memo_name[0] || !duration) | |
290 return (ATI_FAIL); | |
291 record_param.memo_duration = duration; | |
292 record_param.compression_mode = compression; | |
293 record_param.microphone_gain = mic_gain; | |
294 record_param.network_gain = network_gain; | |
295 | |
296 return_path.addr_id = NULL; | |
297 return_path.callback_func = audio_callback; | |
298 if (audio_vm_record_start(&record_param, | |
299 (T_AUDIO_TONES_PARAMETER *) | |
300 &recorder_warning_tone, | |
301 return_path) == AUDIO_OK) | |
302 return (ATI_CMPL); | |
303 else | |
304 return (ATI_FAIL); | |
305 } | |
306 | |
307 /* AT@VMRS - stop VM recording started with AT@VMR */ | |
308 GLOBAL T_ATI_RSLT atAtVMRS ( char *cl, UBYTE srcId ) | |
309 { | |
310 T_RV_RETURN return_path; | |
311 | |
312 return_path.addr_id = NULL; | |
313 return_path.callback_func = audio_callback; | |
314 if (audio_vm_record_stop(return_path) == AUDIO_OK) | |
315 return (ATI_CMPL); | |
316 else | |
317 return (ATI_FAIL); | |
318 } | |
319 | |
320 #endif /* ATI_AUDIO_C */ |