Stereo Record

This commit is contained in:
Robin E. R. Davies
2025-02-27 14:17:24 -05:00
parent 229e85d608
commit eb7a7f3a48
6 changed files with 73 additions and 79 deletions
+1 -57
View File
@@ -221,63 +221,7 @@ namespace pipedal
return readSpace_();
}
bool write_packet(size_t bytes, void *data)
{
if (MULTI_WRITER)
{
std::lock_guard writeLock{writeMutex};
if (writeSpace() < bytes + sizeof(bytes))
{
return false;
}
size_t index = this->writePosition;
for (size_t i = 0; i < sizeof(bytes); ++i)
{
buffer[(index++() & ringBufferMask] = ((uint8_t*)(&bytes))[i];
}
for (size_t i = 0; i < bytes; ++i)
{
buffer[(index++) & ringBufferMask] = data[i];
}
{
std::lock_guard lock(mutex);
this->writePosition = (index) & ringBufferMask;
}
if (SEMAPHORE_READER)
{
cvRead.notify_all();
}
return true;
}
else
{
if (writeSpace() < bytes + sizeof(bytes))
{
return false;
}
size_t index = this->writePosition;
for (size_t i = 0; i < sizeof(bytes); ++i)
{
buffer[(index++() & ringBufferMask] = ((uint8_t*)(&bytes))[i];
}
for (size_t i = 0; i < bytes; ++i)
{
buffer[(index++) & ringBufferMask] = data[i];
}
{
std::lock_guard lock(mutex);
this->writePosition = (index) & ringBufferMask;
}
if (SEMAPHORE_READER)
{
cvRead.notify_all();
}
return true;
}
}
bool write(size_t bytes, uint8_t *data)
{
if (MULTI_WRITER)