mirror of
https://github.com/eried/portapack-mayhem.git
synced 2025-01-26 06:26:17 -05:00
Marginal attempt to simplify stream write loop.
This commit is contained in:
parent
fc8bb635a6
commit
08f4542954
@ -106,7 +106,8 @@ private:
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
while( !chThdShouldTerminate() ) {
|
bool success = true;
|
||||||
|
while( success && !chThdShouldTerminate() ) {
|
||||||
chEvtWaitAny(EVT_FIFO_HIGHWATER);
|
chEvtWaitAny(EVT_FIFO_HIGHWATER);
|
||||||
|
|
||||||
auto fifo = reinterpret_cast<FIFO<uint8_t>*>(shared_memory.FIFO_HACK);
|
auto fifo = reinterpret_cast<FIFO<uint8_t>*>(shared_memory.FIFO_HACK);
|
||||||
@ -116,25 +117,34 @@ private:
|
|||||||
|
|
||||||
StreamOutput stream { fifo };
|
StreamOutput stream { fifo };
|
||||||
|
|
||||||
while( stream.available() >= write_buffer->size() ) {
|
while( success && (stream.available() >= write_buffer->size()) ) {
|
||||||
led_usb.on();
|
success = transfer(stream, write_buffer.get());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const auto bytes_to_write = stream.read(write_buffer->data(), write_buffer->size());
|
if( !success ) {
|
||||||
|
|
||||||
if( bytes_to_write == write_buffer->size() ) {
|
|
||||||
if( !file.write(write_buffer->data(), write_buffer->size()) ) {
|
|
||||||
led_tx.on();
|
led_tx.on();
|
||||||
break;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
led_usb.off();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool transfer(StreamOutput& stream, std::array<uint8_t, write_size>* const write_buffer) {
|
||||||
|
bool success = false;
|
||||||
|
|
||||||
|
led_usb.on();
|
||||||
|
|
||||||
|
const auto bytes_to_write = stream.read(write_buffer->data(), write_buffer->size());
|
||||||
|
if( bytes_to_write == write_buffer->size() ) {
|
||||||
|
if( file.write(write_buffer->data(), write_buffer->size()) ) {
|
||||||
|
success = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
led_usb.off();
|
||||||
|
|
||||||
|
return success;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif/*__AUDIO_THREAD_H__*/
|
#endif/*__AUDIO_THREAD_H__*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user