diff options
Diffstat (limited to 'src/audio/ring_buffer.h')
| -rw-r--r-- | src/audio/ring_buffer.h | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/src/audio/ring_buffer.h b/src/audio/ring_buffer.h index 6375161..b19c1ea 100644 --- a/src/audio/ring_buffer.h +++ b/src/audio/ring_buffer.h @@ -14,8 +14,10 @@ #define RING_BUFFER_LOOKAHEAD_MS 400 #define RING_BUFFER_SAMPLE_RATE 32000 #define RING_BUFFER_CHANNELS 2 -#define RING_BUFFER_CAPACITY_SAMPLES \ - ((RING_BUFFER_LOOKAHEAD_MS * RING_BUFFER_SAMPLE_RATE * RING_BUFFER_CHANNELS) / 1000) +#define RING_BUFFER_CAPACITY_SAMPLES \ + ((RING_BUFFER_LOOKAHEAD_MS * RING_BUFFER_SAMPLE_RATE * \ + RING_BUFFER_CHANNELS) / \ + 1000) class AudioRingBuffer { public: @@ -32,20 +34,22 @@ class AudioRingBuffer { int read(float* samples, int count); // Query buffer state - int available_write() const; // Samples that can be written - int available_read() const; // Samples that can be read + int available_write() const; // Samples that can be written + int available_read() const; // Samples that can be read // Get total samples consumed (for timing) - int64_t get_total_read() const { return total_read_.load(std::memory_order_acquire); } + int64_t get_total_read() const { + return total_read_.load(std::memory_order_acquire); + } // Clear buffer (for seeking) void clear(); private: float buffer_[RING_BUFFER_CAPACITY_SAMPLES]; - int capacity_; // Total capacity in samples + int capacity_; // Total capacity in samples - std::atomic<int> write_pos_; // Write position (0 to capacity-1) - std::atomic<int> read_pos_; // Read position (0 to capacity-1) - std::atomic<int64_t> total_read_; // Total samples read (for playback time) + std::atomic<int> write_pos_; // Write position (0 to capacity-1) + std::atomic<int> read_pos_; // Read position (0 to capacity-1) + std::atomic<int64_t> total_read_; // Total samples read (for playback time) }; |
