15 #include "../include/tscope5/audio_internal.h"
16 #include "../include/tscope5/timer_internal.h"
17 #include "../include/tscope5/system_internal.h"
19 #include <allegro5/allegro_acodec.h>
45 ts5_log(TS5_LOGLEVEL_6,
"%s: ts5_check_audio\n", calling_function);
69 ts5_log(TS5_LOGLEVEL_1,
"%s: Installing Tscope5 audio\n",
72 if (!al_install_audio()) {
73 ts5_fatal(
"%s: could not install Tscope5 audio\n",
77 if (!al_init_acodec_addon()) {
78 ts5_fatal(
"%s: could not install Tscope5 audio codec addon\n",
82 ALLEGRO_CHANNEL_CONF channels = 0;
84 if (_ts5_status.audio.channels==TS5_MONO) {
85 channels=ALLEGRO_CHANNEL_CONF_1;
87 else if (_ts5_status.audio.channels==TS5_STEREO) {
88 channels=ALLEGRO_CHANNEL_CONF_2;
91 ts5_fatal(
"%s: unknown channel configuration requested\n",
108 _ts5_data.audio.voice = al_create_voice(_ts5_status.audio.samplerate,
109 ALLEGRO_AUDIO_DEPTH_INT16, channels);
111 if (!_ts5_data.audio.voice) {
112 ts5_fatal(
"%s: could not create voice\n", calling_function);
115 _ts5_data.audio.mixer = al_create_mixer(_ts5_status.audio.samplerate,
116 ALLEGRO_AUDIO_DEPTH_FLOAT32, channels);
118 if (!_ts5_data.audio.mixer) {
119 ts5_fatal(
"%s: could not create mixer\n", calling_function);
122 if (!al_attach_mixer_to_voice(_ts5_data.audio.mixer,
123 _ts5_data.audio.voice)) {
124 ts5_fatal(
"%s: could not attach mixer to voice\n",
142 ts5_log(TS5_LOGLEVEL_1,
"Uninstalling Tscope5 audio\n");
150 _ts5_data.audio.mixer = NULL;
151 _ts5_data.audio.voice = NULL;
171 ts5_log(TS5_LOGLEVEL_6,
"%s: ts5_check_audio_recorder\n", calling_function);
190 ts5_log(TS5_LOGLEVEL_6,
"%s: ts5_check_audio_recorder2\n", calling_function);
192 ts5_fatal(
"%s: %s %s\n", calling_function,
193 "audio recorder not running,",
194 "add a call to ts5_start_audio_recorder()");
214 ts5_log(TS5_LOGLEVEL_6,
"%s: ts5_check_audio_recorder3(%p)\n",
215 calling_function, sample);
218 ts5_fatal(
"%s: sample pointer is null\n", calling_function);
221 if (!sample->isbuffer) {
222 ts5_fatal(
"%s: %s %p %s\n", calling_function,
223 "audio sample", sample,
224 "is not a recording buffer");
251 ts5_log(TS5_LOGLEVEL_1,
"%s: Installing Tscope5 audio recorder\n",
255 unsigned int samplerate = _ts5_status.audio.samplerate;
256 unsigned int samples = 4094;
257 size_t fragment_count = 10.0 * samplerate / samples;
259 _ts5_data.audio.recorder =
260 al_create_audio_recorder(fragment_count,
263 ALLEGRO_AUDIO_DEPTH_INT16,
264 _ts5_status.audio.channels);
266 if(!_ts5_data.audio.recorder) {
267 ts5_fatal(
"%s: could create audio recorder\n",
272 _ts5_data.audio.recorder_queue = al_create_event_queue();
273 if(!_ts5_data.audio.recorder_queue) {
274 ts5_fatal(
"%s: could not create audio recorder event cue\n",
277 al_register_event_source(_ts5_data.audio.recorder_queue,
278 al_get_audio_recorder_event_source(_ts5_data.audio.recorder));
294 ts5_log(TS5_LOGLEVEL_1,
"Uninstalling Tscope5 audio recorder\n");
296 al_unregister_event_source(_ts5_data.audio.recorder_queue,
297 al_get_audio_recorder_event_source(_ts5_data.audio.recorder));
299 al_destroy_event_queue(_ts5_data.audio.recorder_queue);
301 al_destroy_audio_recorder(_ts5_data.audio.recorder);
321 ts5_log(TS5_LOGLEVEL_6,
"%s: ts5_check_voicekey\n", calling_function);
358 ts5_log(TS5_LOGLEVEL_1,
"%s: Installing Tscope5 voice key\n",
362 al_init_user_event_source(
363 &_ts5_data.timer.voicekey_response_event_source);
366 al_register_event_source(_ts5_data.timer.response_queue,
367 &_ts5_data.timer.voicekey_response_event_source);
369 _ts5_status.timer.voicekey.num_buttons = 1;
370 _ts5_status.timer.voicekey.num_defined_buttons = 0;
371 _ts5_status.timer.voicekey.num_active_buttons = 0;
373 _ts5_status.timer.voicekey.treshold = 0.5;
374 _ts5_status.timer.voicekey.rise_delay = 0.2;
375 _ts5_status.timer.voicekey.drop_delay = 0.2;
377 _ts5_status.timer.voicekey.button_press_defined =
378 (
int *)al_malloc(
sizeof(
int)
379 * _ts5_status.timer.voicekey.num_buttons);
381 _ts5_status.timer.voicekey.button_press_active =
382 (
int *)al_malloc(
sizeof(
int)
383 * _ts5_status.timer.voicekey.num_buttons);
385 _ts5_status.timer.voicekey.button_release_defined =
386 (
int *)al_malloc(
sizeof(
int)
387 * _ts5_status.timer.voicekey.num_buttons);
389 _ts5_status.timer.voicekey.button_release_active =
390 (
int *)al_malloc(
sizeof(
int)
391 * _ts5_status.timer.voicekey.num_buttons);
394 for (i=0; i<_ts5_status.timer.voicekey.num_buttons; i++) {
395 _ts5_status.timer.voicekey.button_press_defined[i] = 0;
396 _ts5_status.timer.voicekey.button_press_active[i] = 0;
397 _ts5_status.timer.voicekey.button_release_defined[i] = 0;
398 _ts5_status.timer.voicekey.button_release_active[i] = 0;
415 ts5_log(TS5_LOGLEVEL_1,
"Uninstalling Tscope5 voice key\n");
417 _ts5_status.timer.voicekey.num_buttons = 0;
418 _ts5_status.timer.voicekey.num_defined_buttons = 0;
419 _ts5_status.timer.voicekey.num_active_buttons = 0;
421 al_free(_ts5_status.timer.voicekey.button_press_defined);
422 _ts5_status.timer.voicekey.button_press_defined = NULL;
424 al_free(_ts5_status.timer.voicekey.button_press_active);
425 _ts5_status.timer.voicekey.button_press_active = NULL;
427 al_free(_ts5_status.timer.voicekey.button_release_defined);
428 _ts5_status.timer.voicekey.button_release_defined = NULL;
430 al_free(_ts5_status.timer.voicekey.button_release_active);
431 _ts5_status.timer.voicekey.button_release_active = NULL;
433 _ts5_status.timer.voicekey_is_response_device = 0;
436 al_unregister_event_source(_ts5_data.timer.response_queue,
437 &_ts5_data.timer.voicekey_response_event_source);
440 al_destroy_user_event_source(
441 &_ts5_data.timer.voicekey_response_event_source);
int _ts5_is_tscope5_installed
Is Tscope5 installed?
int _ts5_is_timer_installed
Is the timer subsystem installed?
int _ts5_is_audio_installed
Is the audio subsystem installed?
void ts5_uninstall_audio_recorder()
Uninstall the audio recoder subsystem.
int _ts5_is_audio_recorder_recording
Is the audio recorder recording?
void ts5_check_audio_recorder(char *calling_function)
Do some checks at the start of each audio recorder function.
int _ts5_is_audio_recorder_installed
Is the audio recorder subsystem installed?
void ts5_install_voicekey(char *calling_function)
Install the voicekey subsystem.
void ts5_install_timer(char *calling_function)
Install the timer subsystem.
void ts5_log(const unsigned int level, const char *format,...)
Send info to a logging window.
void ts5_install_tscope5(char *calling_function)
Install Tscope5.
void ts5_install_audio_recorder(char *calling_function)
Install the audio recorder subsystem.
int _ts5_is_voicekey_installed
Is the voicekey subsystem installed?
void ts5_check_voicekey(char *calling_function)
Do some checks at the start of each voicekey function.
void ts5_check_audio_recorder2(char *calling_function)
Do some checks at the start of each audio recorder function.
void ts5_install_audio(char *calling_function)
Install the audio subsystem.
void ts5_fatal(const char *format,...)
Exit safely with an error message.
void ts5_check_audio_recorder3(char *calling_function, TS5_SAMPLE *sample)
Do some checks at the start of each audio recorder function.
void ts5_uninstall_audio()
Uninstall the audio subsystem.
void ts5_uninstall_voicekey()
Uninstall the voicekey subsystem.
void ts5_check_audio(char *calling_function)
Do some checks at the start of each audio function.