Home | History | Annotate | Download | only in soundtrigger

Lines Matching refs:stdev

94 static void stdev_dsp_set_power(struct dragon_sound_trigger_device *stdev,
97 stdev->is_streaming = 0;
98 mixer_ctl_set_value(stdev->int_mic_sw, 0, val);
101 static int stdev_init_mixer(struct dragon_sound_trigger_device *stdev)
106 stdev->mixer = mixer_open(DRAGON_MIXER_VAD);
107 if (!stdev->mixer)
110 stdev->int_mic_sw = mixer_get_ctl_by_name(stdev->mixer, DRAGON_MIC_CTRL);
111 if (!stdev->int_mic_sw)
114 stdev->hotword_model = mixer_get_ctl_by_name(stdev->mixer,
116 if (!stdev->hotword_model)
119 stdev_dsp_set_power(stdev, 0); // Disable DSP at the beginning
124 if (stdev->mixer)
125 mixer_close(stdev->mixer);
129 static void stdev_close_term_sock(struct dragon_sound_trigger_device *stdev)
131 if (stdev->send_sock >=0) {
132 close(stdev->send_sock);
133 stdev->send_sock = -1;
135 if (stdev->term_sock >=0) {
136 close(stdev->term_sock);
137 stdev->term_sock = -1;
141 static void stdev_close_mixer(struct dragon_sound_trigger_device *stdev)
143 if (stdev) {
144 stdev_dsp_set_power(stdev, 0);
145 mixer_close(stdev->mixer);
146 stdev_close_term_sock(stdev);
150 static int vad_load_sound_model(struct dragon_sound_trigger_device *stdev,
154 ret = mixer_ctl_set_array(stdev->hotword_model, buf, len);
161 stdev)
174 event->common.model = stdev->model_handle;
176 if (stdev->config) {
179 event->num_phrases = stdev->config->num_phrases;
183 memcpy(&event->phrase_extras[i], &stdev->config->phrases[i],
207 struct dragon_sound_trigger_device *stdev =
218 pthread_mutex_lock(&stdev->lock);
219 if (stdev->recognition_callback == NULL)
225 stdev_close_term_sock(stdev);
226 stdev->send_sock = exit_sockets[0];
227 stdev->term_sock = exit_sockets[1];
229 stdev_dsp_set_power(stdev, 1);
239 stdev->pcm = pcm_open(DRAGON_ST_CARD_NUM, DRAGON_ST_DEV_NUM,
241 if (!stdev->pcm || !pcm_is_ready(stdev->pcm)) {
242 ALOGE("Unable to open PCM device (%s)\n", pcm_get_error(stdev->pcm));
246 err = pcm_start(stdev->pcm);
248 ALOGE("Unable to start PCM device (%s)\n", pcm_get_error(stdev->pcm));
254 fds[0].fd = pcm_get_poll_fd(stdev->pcm);;
260 fds[1].fd = stdev->term_sock;
262 pthread_mutex_unlock(&stdev->lock);
266 pthread_mutex_lock(&stdev->lock);
267 if ((err < 0) || (stdev->recognition_callback == NULL)) {
274 recognition_callback_t callback = stdev->recognition_callback;
275 void *cookie = stdev->recognition_cookie;
278 sound_trigger_event_alloc(stdev);
280 pcm_close(stdev->pcm);
281 stdev->pcm = NULL;
284 stdev->is_streaming = 1;
286 stdev->model_handle);
287 pthread_mutex_unlock(&stdev->lock);
291 pthread_mutex_lock(&stdev->lock);
302 pthread_mutex_unlock(&stdev->lock);
305 if (stdev->pcm) {
306 pcm_close(stdev->pcm);
307 stdev->pcm = NULL;
311 stdev->recognition_callback = NULL;
312 stdev_close_term_sock(stdev);
314 if (stdev->config && !stdev->config->capture_requested)
315 stdev_dsp_set_power(stdev, 0);
317 pthread_mutex_unlock(&stdev->lock);
325 struct dragon_sound_trigger_device *stdev =
341 struct dragon_sound_trigger_device *stdev =
346 pthread_mutex_lock(&stdev->lock);
352 if (stdev->model_handle == 1) {
357 ret = vad_load_sound_model(stdev,
363 stdev->model_handle = 1;
364 stdev->sound_model_callback = callback;
365 stdev->sound_model_cookie = cookie;
366 *handle = stdev->model_handle;
369 pthread_mutex_unlock(&stdev->lock);
376 struct dragon_sound_trigger_device *stdev =
381 pthread_mutex_lock(&stdev->lock);
386 if (stdev->model_handle == 0) {
390 stdev->model_handle = 0;
391 free(stdev->config);
392 stdev->config = NULL;
393 if (stdev->recognition_callback != NULL) {
394 stdev->recognition_callback = NULL;
395 if (stdev->send_sock >=0)
396 write(stdev->send_sock, "T", 1);
397 pthread_mutex_unlock(&stdev->lock);
399 pthread_join(stdev->callback_thread, (void **)NULL);
401 pthread_mutex_lock(&stdev->lock);
405 stdev_dsp_set_power(stdev, 0);
407 pthread_mutex_unlock(&stdev->lock);
417 struct dragon_sound_trigger_device *stdev =
422 pthread_mutex_lock(&stdev->lock);
423 if (stdev->model_handle != sound_model_handle) {
427 if (stdev->recognition_callback != NULL) {
432 free(stdev->config);
433 stdev->config = NULL;
435 stdev->config = malloc(sizeof(*config));
436 if (!stdev->config) {
440 memcpy(stdev->config, config, sizeof(*config));
443 if (stdev->pcm) {
444 pcm_close(stdev->pcm);
445 stdev->pcm = NULL;
448 stdev_dsp_set_power(stdev, 0);
450 stdev->recognition_callback = callback;
451 stdev->recognition_cookie = cookie;
452 pthread_create(&stdev->callback_thread, (const pthread_attr_t *) NULL,
453 callback_thread_loop, stdev);
455 pthread_mutex_unlock(&stdev->lock);
462 struct dragon_sound_trigger_device *stdev =
467 pthread_mutex_lock(&stdev->lock);
468 if (stdev->model_handle != sound_model_handle) {
472 if (stdev->recognition_callback == NULL) {
476 free(stdev->config);
477 stdev->config = NULL;
478 stdev->recognition_callback = NULL;
479 if (stdev->send_sock >=0)
480 write(stdev->send_sock, "T", 1);
481 pthread_mutex_unlock(&stdev->lock);
483 pthread_join(stdev->callback_thread, (void **)NULL);
485 if (stdev->pcm) {
486 pcm_close(stdev->pcm);
487 stdev->pcm = NULL;
490 pthread_mutex_lock(&stdev->lock);
493 stdev_dsp_set_power(stdev, 0);
495 pthread_mutex_unlock(&stdev->lock);
502 struct dragon_sound_trigger_device *stdev = &g_stdev;
505 pthread_mutex_lock(&stdev->lock);
507 if (!stdev->opened) {
508 ALOGE("%s: stdev has not been opened", __func__);
512 if (!stdev->is_streaming) {
517 if (!stdev->pcm) {
527 pthread_mutex_unlock(&stdev->lock);
534 struct dragon_sound_trigger_device *stdev = &g_stdev;
549 pthread_mutex_lock(&stdev->lock);
551 if (!stdev->opened) {
552 ALOGE("%s: stdev has not been opened", __func__);
556 if (!stdev->is_streaming) {
561 if (!stdev->pcm) {
569 frames = pcm_mmap_avail(stdev->pcm);
589 ret = pcm_mmap_begin(stdev->pcm, (void**)&snd_buffer, &offset, &frames);
595 pcm_mmap_commit(stdev->pcm, offset, frames);
600 pthread_mutex_unlock(&stdev->lock);
607 struct dragon_sound_trigger_device *stdev = &g_stdev;
614 if (stdev->pcm) {
615 pcm_close(stdev->pcm);
616 stdev->pcm = NULL;
624 struct dragon_sound_trigger_device *stdev =
628 pthread_mutex_lock(&stdev->lock);
629 if (!stdev->opened) {
634 stdev_close_mixer(stdev);
635 stdev->model_handle = 0;
636 stdev->send_sock = 0;
637 stdev->term_sock = 0;
638 stdev->opened = false;
641 pthread_mutex_unlock(&stdev->lock);
648 struct dragon_sound_trigger_device *stdev;
654 stdev = &g_stdev;
655 pthread_mutex_lock(&stdev->lock);
657 if (stdev->opened) {
663 ret = stdev_init_mixer(stdev);
669 stdev->device.common.tag = HARDWARE_DEVICE_TAG;
670 stdev->device.common.version = SOUND_TRIGGER_DEVICE_API_VERSION_1_0;
671 stdev->device.common.module = (struct hw_module_t *)module;
672 stdev->device.common.close = stdev_close;
673 stdev->device.get_properties = stdev_get_properties;
674 stdev->device.load_sound_model = stdev_load_sound_model;
675 stdev->device.unload_sound_model = stdev_unload_sound_model;
676 stdev->device.start_recognition = stdev_start_recognition;
677 stdev->device.stop_recognition = stdev_stop_recognition;
678 stdev->send_sock = stdev->term_sock = -1;
679 stdev->opened = true;
681 *device = &stdev->device.common; /* same address as stdev */
683 pthread_mutex_unlock(&stdev->lock);