mirror of
https://github.com/portapack-mayhem/mayhem-firmware.git
synced 2024-12-15 04:28:10 +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:
|
public:
|
||||||
AudioThread(
|
AudioThread(
|
||||||
std::string file_path
|
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
|
// Need significant stack for FATFS
|
||||||
thread = chThdCreateFromHeap(NULL, 1024, NORMALPRIO + 10, AudioThread::static_fn, this);
|
thread = chThdCreateFromHeap(NULL, 1024, NORMALPRIO + 10, AudioThread::static_fn, this);
|
||||||
}
|
}
|
||||||
@ -84,8 +88,7 @@ private:
|
|||||||
static constexpr size_t write_size = 4096;
|
static constexpr size_t write_size = 4096;
|
||||||
static constexpr eventmask_t EVT_FIFO_HIGHWATER = 1;
|
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;
|
File file;
|
||||||
static Thread* thread;
|
static Thread* thread;
|
||||||
|
|
||||||
@ -97,15 +100,6 @@ private:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void run() {
|
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;
|
bool success = true;
|
||||||
while( success && !chThdShouldTerminate() ) {
|
while( success && !chThdShouldTerminate() ) {
|
||||||
chEvtWaitAny(EVT_FIFO_HIGHWATER);
|
chEvtWaitAny(EVT_FIFO_HIGHWATER);
|
||||||
@ -125,8 +119,6 @@ private:
|
|||||||
if( !success ) {
|
if( !success ) {
|
||||||
led_tx.on();
|
led_tx.on();
|
||||||
}
|
}
|
||||||
|
|
||||||
file.close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool transfer(StreamOutput& stream, std::array<uint8_t, write_size>* const write_buffer) {
|
bool transfer(StreamOutput& stream, std::array<uint8_t, write_size>* const write_buffer) {
|
||||||
|
Loading…
Reference in New Issue
Block a user