diff --git a/src/utility/Mic_Class.cpp b/src/utility/Mic_Class.cpp index f5cf740..60432bb 100644 --- a/src/utility/Mic_Class.cpp +++ b/src/utility/Mic_Class.cpp @@ -584,7 +584,6 @@ if (_cfg.pin_bck < 0 || _cfg.pin_ws < 0) { dst_remain = current_rec->length; if (dst_remain == 0) { - self->_is_recording = false; ulTaskNotifyTake( pdTRUE, portMAX_DELAY ); src_idx = ~0u; src_len = 0; @@ -593,7 +592,6 @@ if (_cfg.pin_bck < 0 || _cfg.pin_ws < 0) { continue; } } - self->_is_recording = true; for (;;) { @@ -702,7 +700,6 @@ if (_cfg.pin_bck < 0 || _cfg.pin_ws < 0) { } } } - self->_is_recording = false; _i2s_stop(self->_cfg.i2s_port); self->_task_handle = nullptr; @@ -736,13 +733,16 @@ if (_cfg.pin_bck < 0 || _cfg.pin_ws < 0) { #if portNUM_PROCESSORS > 1 if (_cfg.task_pinned_core < portNUM_PROCESSORS) { - xTaskCreatePinnedToCore(mic_task, "mic_task", stack_size, this, _cfg.task_priority, &_task_handle, _cfg.task_pinned_core); + res = (pdPASS == xTaskCreatePinnedToCore(mic_task, "mic_task", stack_size, this, _cfg.task_priority, &_task_handle, _cfg.task_pinned_core)); } else #endif { - xTaskCreate(mic_task, "mic_task", stack_size, this, _cfg.task_priority, &_task_handle); + res = (pdPASS == xTaskCreate(mic_task, "mic_task", stack_size, this, _cfg.task_priority, &_task_handle)); } + // end() takes the driver and the callback back down; it still sees the + // class as running, which is what lets it do that. + if (!res) { end(); } } return res; @@ -758,6 +758,10 @@ if (_cfg.pin_bck < 0 || _cfg.pin_ws < 0) { do { vTaskDelay(1); } while (_task_handle); } + // an unfinished request would otherwise keep isRecording() reporting a recording. + _rec_info[0] = recording_info_t(); + _rec_info[1] = recording_info_t(); + if (_cb_set_enabled) { _cb_set_enabled(_cb_set_enabled_args, false); } _i2s_driver_uninstall(_cfg.i2s_port); } diff --git a/src/utility/Mic_Class.hpp b/src/utility/Mic_Class.hpp index b784410..8af605a 100644 --- a/src/utility/Mic_Class.hpp +++ b/src/utility/Mic_Class.hpp @@ -114,7 +114,7 @@ namespace m5 /// now in recording or not. /// @return 0=not recording / 1=recording (There's room in the queue) / 2=recording (There's no room in the queue.) - size_t isRecording(void) const { return _is_recording ? ((bool)_rec_info[0].length) + ((bool)_rec_info[1].length) : 0; } + size_t isRecording(void) const volatile { return ((bool)_rec_info[0].length) + ((bool)_rec_info[1].length); } /// set recording sampling rate. /// @param sample_rate the sampling rate (Hz) @@ -186,7 +186,6 @@ namespace m5 int32_t _offset = 0; volatile bool _task_running = false; - volatile bool _is_recording = false; #if defined (SDL_h_) SDL_Thread* _task_handle = nullptr; #else diff --git a/src/utility/Speaker_Class.cpp b/src/utility/Speaker_Class.cpp index bc5c951..49d4727 100644 --- a/src/utility/Speaker_Class.cpp +++ b/src/utility/Speaker_Class.cpp @@ -930,20 +930,24 @@ namespace m5 _task_running = true; #if defined (SDL_h_) _task_handle = SDL_CreateThread(reinterpret_cast(spk_task), "spk_task", this); + res = (_task_handle != nullptr); #else size_t stack_size = 1280 + (_cfg.dma_buf_len * sizeof(uint32_t)); #if portNUM_PROCESSORS > 1 if (_cfg.task_pinned_core < portNUM_PROCESSORS) { - xTaskCreatePinnedToCore(spk_task, "spk_task", stack_size, this, _cfg.task_priority, &_task_handle, _cfg.task_pinned_core); + res = (pdPASS == xTaskCreatePinnedToCore(spk_task, "spk_task", stack_size, this, _cfg.task_priority, &_task_handle, _cfg.task_pinned_core)); } else #endif { - xTaskCreate(spk_task, "spk_task", stack_size, this, _cfg.task_priority, &_task_handle); + res = (pdPASS == xTaskCreate(spk_task, "spk_task", stack_size, this, _cfg.task_priority, &_task_handle)); } #endif + // end() takes the driver and the callback back down; it still sees the + // class as running, which is what lets it do that. + if (!res) { end(); } } return res;