Move AudioThread con/destruction to proper places.

This commit is contained in:
Jared Boone 2016-04-06 11:43:47 -07:00
parent 08f4542954
commit feeb5bff6f

View File

@ -59,8 +59,12 @@ class AudioThread {
public:
AudioThread(
std::string file_path
) : file_path { std::move(file_path) }
) : write_buffer { std::make_unique<std::array<uint8_t, write_size>>() }
{
if( !file.open_for_append(file_path) ) {
return;
}
// Need significant stack for FATFS
thread = chThdCreateFromHeap(NULL, 1024, NORMALPRIO + 10, AudioThread::static_fn, this);
}
@ -84,8 +88,7 @@ private:
static constexpr size_t write_size = 4096;
static constexpr eventmask_t EVT_FIFO_HIGHWATER = 1;
const std::string file_path;
std::unique_ptr<std::array<uint8_t, write_size>> write_buffer;
File file;
static Thread* thread;
@ -97,15 +100,6 @@ private:
}
void run() {
auto write_buffer = std::make_unique<std::array<uint8_t, write_size>>();
if( !write_buffer ) {
return;
}
if( !file.open_for_append(file_path) ) {
return;
}
bool success = true;
while( success && !chThdShouldTerminate() ) {
chEvtWaitAny(EVT_FIFO_HIGHWATER);
@ -125,8 +119,6 @@ private:
if( !success ) {
led_tx.on();
}
file.close();
}
bool transfer(StreamOutput& stream, std::array<uint8_t, write_size>* const write_buffer) {