Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions src/utility/Mic_Class.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -593,7 +592,6 @@ if (_cfg.pin_bck < 0 || _cfg.pin_ws < 0) {
continue;
}
}
self->_is_recording = true;

for (;;)
{
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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);
}
Expand Down
3 changes: 1 addition & 2 deletions src/utility/Mic_Class.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions src/utility/Speaker_Class.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -930,20 +930,24 @@ namespace m5
_task_running = true;
#if defined (SDL_h_)
_task_handle = SDL_CreateThread(reinterpret_cast<SDL_ThreadFunction>(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;
Expand Down
Loading