mirror of
https://github.com/portapack-mayhem/mayhem-firmware.git
synced 2024-12-13 19:54:39 +00:00
Move AudioThread con/destruction to proper places.
This commit is contained in:
parent
08f4542954
commit
feeb5bff6f
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user