Files
pyxis/lib/lxst_audio/encoded_ring_buffer.h
torlando-tech c1af11d75e LXST audio hardware config: ES7210 mic pins, tone helpers, platformio deps
- Add ES7210 I2C address and I2S mic capture pin definitions
- Add ring/hangup tone helpers to Tone library
- Add lxst_audio library scaffold
- Add Codec2 dependency to platformio.ini

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-19 16:41:47 -05:00

40 lines
1.0 KiB
C++

// Copyright (c) 2024 LXST contributors
// SPDX-License-Identifier: MPL-2.0
#pragma once
#include <atomic>
#include <cstdint>
/**
* Lock-free SPSC ring buffer for variable-length encoded audio packets.
*
* Ported from LXST-kt native layer. Each slot has a fixed max size but
* tracks actual length. Lock-free protocol identical to PacketRingBuffer.
*
* Slot layout: [int32 length][uint8 data[maxBytesPerSlot]] x maxSlots
*/
class EncodedRingBuffer {
public:
EncodedRingBuffer(int maxSlots, int maxBytesPerSlot);
~EncodedRingBuffer();
EncodedRingBuffer(const EncodedRingBuffer&) = delete;
EncodedRingBuffer& operator=(const EncodedRingBuffer&) = delete;
bool write(const uint8_t* data, int length);
bool read(uint8_t* dest, int maxLength, int* actualLength);
int availableSlots() const;
void reset();
private:
const int maxSlots_;
const int maxBytesPerSlot_;
const int slotSize_;
uint8_t* buffer_;
std::atomic<int> writeIndex_{0};
std::atomic<int> readIndex_{0};
};