summaryrefslogtreecommitdiff
path: root/src/audio/ring_buffer.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/audio/ring_buffer.cc')
-rw-r--r--src/audio/ring_buffer.cc18
1 files changed, 9 insertions, 9 deletions
diff --git a/src/audio/ring_buffer.cc b/src/audio/ring_buffer.cc
index 54dd25b..b3152a0 100644
--- a/src/audio/ring_buffer.cc
+++ b/src/audio/ring_buffer.cc
@@ -51,7 +51,7 @@ int AudioRingBuffer::write(const float* samples, int count) {
const int write = write_pos_.load(std::memory_order_acquire);
// BOUNDS CHECK: Validate write position
- FATAL_CHECK(write < 0 || write >= capacity_,
+ FATAL_CHECK(write >= 0 && write < capacity_,
"write_pos out of bounds! write=%d, capacity=%d\n", write,
capacity_);
@@ -60,7 +60,7 @@ int AudioRingBuffer::write(const float* samples, int count) {
if (to_write <= space_to_end) {
// Write in one chunk
// BOUNDS CHECK
- FATAL_CHECK(write < 0 || write + to_write > capacity_,
+ FATAL_CHECK(write >= 0 && write + to_write <= capacity_,
"BOUNDS ERROR in write(): write=%d, to_write=%d, capacity=%d\n",
write, to_write, capacity_);
memcpy(&buffer_[write], samples, to_write * sizeof(float));
@@ -68,14 +68,14 @@ int AudioRingBuffer::write(const float* samples, int count) {
} else {
// Write in two chunks (wrap around)
// BOUNDS CHECK - first chunk
- FATAL_CHECK(write < 0 || write + space_to_end > capacity_,
+ FATAL_CHECK(write >= 0 && write + space_to_end <= capacity_,
"BOUNDS ERROR in write() chunk1: write=%d, space_to_end=%d, "
"capacity=%d\n",
write, space_to_end, capacity_);
memcpy(&buffer_[write], samples, space_to_end * sizeof(float));
const int remainder = to_write - space_to_end;
// BOUNDS CHECK - second chunk
- FATAL_CHECK(remainder < 0 || remainder > capacity_,
+ FATAL_CHECK(remainder >= 0 && remainder <= capacity_,
"BOUNDS ERROR in write() chunk2: remainder=%d, capacity=%d\n",
remainder, capacity_);
memcpy(&buffer_[0], samples + space_to_end, remainder * sizeof(float));
@@ -96,7 +96,7 @@ int AudioRingBuffer::read(float* samples, int count) {
const int read = read_pos_.load(std::memory_order_acquire);
// BOUNDS CHECK: Validate read position
- FATAL_CHECK(read < 0 || read >= capacity_,
+ FATAL_CHECK(read >= 0 && read < capacity_,
"read_pos out of bounds! read=%d, capacity=%d\n", read,
capacity_);
@@ -105,7 +105,7 @@ int AudioRingBuffer::read(float* samples, int count) {
if (to_read <= space_to_end) {
// Read in one chunk
// BOUNDS CHECK
- FATAL_CHECK(read < 0 || read + to_read > capacity_,
+ FATAL_CHECK(read >= 0 && read + to_read <= capacity_,
"BOUNDS ERROR in read(): read=%d, to_read=%d, capacity=%d\n",
read, to_read, capacity_);
memcpy(samples, &buffer_[read], to_read * sizeof(float));
@@ -113,14 +113,14 @@ int AudioRingBuffer::read(float* samples, int count) {
} else {
// Read in two chunks (wrap around)
// BOUNDS CHECK - first chunk
- FATAL_CHECK(read < 0 || read + space_to_end > capacity_,
+ FATAL_CHECK(read >= 0 && read + space_to_end <= capacity_,
"BOUNDS ERROR in read() chunk1: read=%d, space_to_end=%d, "
"capacity=%d\n",
read, space_to_end, capacity_);
memcpy(samples, &buffer_[read], space_to_end * sizeof(float));
const int remainder = to_read - space_to_end;
// BOUNDS CHECK - second chunk
- FATAL_CHECK(remainder < 0 || remainder > capacity_,
+ FATAL_CHECK(remainder >= 0 && remainder <= capacity_,
"BOUNDS ERROR in read() chunk2: remainder=%d, capacity=%d\n",
remainder, capacity_);
memcpy(samples + space_to_end, &buffer_[0], remainder * sizeof(float));
@@ -169,7 +169,7 @@ void AudioRingBuffer::commit_write(int num_samples) {
const int write = write_pos_.load(std::memory_order_acquire);
// BOUNDS CHECK
- FATAL_CHECK(write < 0 || write + num_samples > capacity_,
+ FATAL_CHECK(write >= 0 && write + num_samples <= capacity_,
"commit_write out of bounds: write=%d, num_samples=%d, "
"capacity=%d\n",
write, num_samples, capacity_);