Home | History | Annotate | Download | only in soundtrigger

Lines Matching refs:stdev

97 static void stdev_dsp_set_power(struct flounder_sound_trigger_device *stdev,
100 stdev->is_streaming = 0;
101 stdev->streaming_buf_read = 0;
102 stdev->streaming_buf_len = 0;
103 mixer_ctl_set_value(stdev->ctl_dsp, 0, val);
106 static int stdev_init_mixer(struct flounder_sound_trigger_device *stdev)
110 stdev->vad_fd = open(FLOUNDER_VAD_DEV, O_RDWR);
111 if (stdev->vad_fd < 0) {
116 stdev->mixer = mixer_open(FLOUNDER_MIXER_VAD);
117 if (!stdev->mixer)
120 stdev->ctl_dsp = mixer_get_ctl_by_name(stdev->mixer, FLOUNDER_CTRL_DSP);
121 if (!stdev->ctl_dsp)
124 stdev_dsp_set_power(stdev, 0); // Disable DSP at the beginning
129 close(stdev->vad_fd);
130 if (stdev->mixer)
131 mixer_close(stdev->mixer);
135 static void stdev_close_term_sock(struct flounder_sound_trigger_device *stdev)
137 if (stdev->send_sock >=0) {
138 close(stdev->send_sock);
139 stdev->send_sock = -1;
141 if (stdev->term_sock >=0) {
142 close(stdev->term_sock);
143 stdev->term_sock = -1;
147 static void stdev_close_mixer(struct flounder_sound_trigger_device *stdev)
149 if (stdev) {
150 stdev_dsp_set_power(stdev, 0);
151 mixer_close(stdev->mixer);
152 stdev_close_term_sock(stdev);
153 close(stdev->vad_fd);
157 static int vad_load_sound_model(struct flounder_sound_trigger_device *stdev,
169 ret = ioctl(stdev->vad_fd, RT_WRITE_CODEC_DSP_IOCTL, &cmd);
176 stdev)
189 event->common.model = stdev->model_handle;
191 if (stdev->config) {
194 event->num_phrases = stdev->config->num_phrases;
198 memcpy(&event->phrase_extras[i], &stdev->config->phrases[i],
219 // The stdev should be locked when you call this function.
220 static int fetch_streaming_buffer(struct flounder_sound_trigger_device * stdev)
227 cmd.buf = (int*) stdev->streaming_buf;
231 ret = ioctl(stdev->vad_fd, RT_READ_CODEC_DSP_IOCTL, &cmd);
241 stdev->streaming_buf_read = 0;
242 stdev->streaming_buf_len = ret << 1;
253 struct flounder_sound_trigger_device *stdev =
263 pthread_mutex_lock(&stdev->lock);
264 if (stdev->recognition_callback == NULL)
270 stdev_close_term_sock(stdev);
271 stdev->send_sock = exit_sockets[0];
272 stdev->term_sock = exit_sockets[1];
282 fds[1].fd = stdev->term_sock;
284 stdev_dsp_set_power(stdev, 1);
286 pthread_mutex_unlock(&stdev->lock);
290 pthread_mutex_lock(&stdev->lock);
291 if ((err < 0) || (stdev->recognition_callback == NULL)) {
299 pthread_mutex_unlock(&stdev->lock);
307 sound_trigger_event_alloc(stdev);
309 recognition_callback_t callback = stdev->recognition_callback;
310 void *cookie = stdev->recognition_cookie;
312 stdev->is_streaming = 1;
314 stdev->model_handle);
315 pthread_mutex_unlock(&stdev->lock);
319 pthread_mutex_lock(&stdev->lock);
322 if (stdev->config && stdev->config->capture_requested) {
323 fetch_streaming_buffer(stdev);
337 pthread_mutex_unlock(&stdev->lock);
344 stdev->recognition_callback = NULL;
345 stdev_close_term_sock(stdev);
347 if (stdev->config && !stdev->config->capture_requested)
348 stdev_dsp_set_power(stdev, 0);
350 pthread_mutex_unlock(&stdev->lock);
358 struct flounder_sound_trigger_device *stdev =
374 struct flounder_sound_trigger_device *stdev =
379 pthread_mutex_lock(&stdev->lock);
385 if (stdev->model_handle == 1) {
390 ret = vad_load_sound_model(stdev,
396 stdev->model_handle = 1;
397 stdev->sound_model_callback = callback;
398 stdev->sound_model_cookie = cookie;
399 *handle = stdev->model_handle;
402 pthread_mutex_unlock(&stdev->lock);
409 struct flounder_sound_trigger_device *stdev =
414 pthread_mutex_lock(&stdev->lock);
419 if (stdev->model_handle == 0) {
423 stdev->model_handle = 0;
424 free(stdev->config);
425 stdev->config = NULL;
426 if (stdev->recognition_callback != NULL) {
427 stdev->recognition_callback = NULL;
428 if (stdev->send_sock >=0)
429 write(stdev->send_sock, "T", 1);
430 pthread_mutex_unlock(&stdev->lock);
432 pthread_join(stdev->callback_thread, (void **)NULL);
434 pthread_mutex_lock(&stdev->lock);
438 stdev_dsp_set_power(stdev, 0);
440 pthread_mutex_unlock(&stdev->lock);
450 struct flounder_sound_trigger_device *stdev =
455 pthread_mutex_lock(&stdev->lock);
456 if (stdev->model_handle != sound_model_handle) {
460 if (stdev->recognition_callback != NULL) {
465 free(stdev->config);
466 stdev->config = NULL;
468 stdev->config = malloc(sizeof(*config));
469 if (!stdev->config) {
473 memcpy(stdev->config, config, sizeof(*config));
476 stdev_dsp_set_power(stdev, 0);
478 stdev->recognition_callback = callback;
479 stdev->recognition_cookie = cookie;
480 pthread_create(&stdev->callback_thread, (const pthread_attr_t *) NULL,
481 callback_thread_loop, stdev);
483 pthread_mutex_unlock(&stdev->lock);
490 struct flounder_sound_trigger_device *stdev =
495 pthread_mutex_lock(&stdev->lock);
496 if (stdev->model_handle != sound_model_handle) {
500 if (stdev->recognition_callback == NULL) {
504 free(stdev->config);
505 stdev->config = NULL;
506 stdev->recognition_callback = NULL;
507 if (stdev->send_sock >=0)
508 write(stdev->send_sock, "T", 1);
509 pthread_mutex_unlock(&stdev->lock);
511 pthread_join(stdev->callback_thread, (void **)NULL);
513 pthread_mutex_lock(&stdev->lock);
516 stdev_dsp_set_power(stdev, 0);
518 pthread_mutex_unlock(&stdev->lock);
525 struct flounder_sound_trigger_device *stdev = &g_stdev;
528 pthread_mutex_lock(&stdev->lock);
530 if (!stdev->opened) {
531 ALOGE("%s: stdev
535 if (!stdev->is_streaming) {
545 pthread_mutex_unlock(&stdev->lock);
552 struct flounder_sound_trigger_device *stdev = &g_stdev;
561 pthread_mutex_lock(&stdev->lock);
563 if (!stdev->opened) {
564 ALOGE("%s: stdev has not been opened", __func__);
568 if (!stdev->is_streaming) {
574 if (stdev->streaming_buf_read == stdev->streaming_buf_len) {
575 ret = fetch_streaming_buffer(stdev);
579 ret = stdev->streaming_buf_len - stdev->streaming_buf_read;
582 memcpy(buffer, stdev->streaming_buf + stdev->streaming_buf_read, ret);
583 stdev->streaming_buf_read += ret;
588 pthread_mutex_unlock(&stdev->lock);
602 struct flounder_sound_trigger_device *stdev =
606 pthread_mutex_lock(&stdev->lock);
607 if (!stdev->opened) {
612 free(stdev->streaming_buf);
613 stdev_close_mixer(stdev);
614 stdev->model_handle = 0;
615 stdev->send_sock = 0;
616 stdev->term_sock = 0;
617 stdev->opened = false;
620 pthread_mutex_unlock(&stdev->lock);
627 struct flounder_sound_trigger_device *stdev;
633 stdev = &g_stdev;
634 pthread_mutex_lock(&stdev->lock);
636 if (stdev->opened) {
642 stdev->streaming_buf = malloc(FLOUNDER_STREAMING_BUFFER_SIZE);
643 if (!stdev->streaming_buf) {
648 ret = stdev_init_mixer(stdev);
651 free(stdev->streaming_buf);
655 stdev->device.common.tag = HARDWARE_DEVICE_TAG;
656 stdev->device.common.version = SOUND_TRIGGER_DEVICE_API_VERSION_1_0;
657 stdev->device.common.module = (struct hw_module_t *)module;
658 stdev->device.common.close = stdev_close;
659 stdev->device.get_properties = stdev_get_properties;
660 stdev->device.load_sound_model = stdev_load_sound_model;
661 stdev->device.unload_sound_model = stdev_unload_sound_model;
662 stdev->device.start_recognition = stdev_start_recognition;
663 stdev->device.stop_recognition = stdev_stop_recognition;
664 stdev->send_sock = stdev->term_sock = -1;
665 stdev->streaming_buf_read = 0;
666 stdev->streaming_buf_len = 0;
667 stdev->opened = true;
669 *device = &stdev->device.common; /* same address as stdev */
671 pthread_mutex_unlock(&stdev->lock);