| 87 | } |
| 88 | |
| 89 | void AudioGraph::Buffers::Advance(size_t count) |
| 90 | { |
| 91 | #ifndef NDEBUG |
| 92 | sampleCount oldRemaining = Remaining(); |
| 93 | #endif |
| 94 | // Assert the pre |
| 95 | assert(count <= Remaining()); |
| 96 | |
| 97 | #if 1 |
| 98 | // Bounds checking version not assuming the pre, new in 3.2 |
| 99 | if (mBuffers.empty()) |
| 100 | return; |
| 101 | |
| 102 | // First buffer; defend against excessive count |
| 103 | auto iterP = mPositions.begin(); |
| 104 | auto iterB = mBuffers.begin(); |
| 105 | auto &position = *iterP; |
| 106 | auto data = iterB->data(); |
| 107 | auto end = data + iterB->size(); |
| 108 | // invariant assumed, and preserved |
| 109 | assert(data <= position && position <= end); |
| 110 | count = std::min<size_t>(end - position, count); |
| 111 | position += count; |
| 112 | assert(data <= position && position <= end); |
| 113 | |
| 114 | // other buffers; assuming equal sizes and relative positions (invariants) |
| 115 | for (const auto endB = mBuffers.end(); ++iterB != endB;) { |
| 116 | auto &position = *++iterP; |
| 117 | // invariant assumed, and preserved |
| 118 | assert(iterB->data() <= position); |
| 119 | assert(position <= iterB->data() + iterB->size()); |
| 120 | |
| 121 | position += count; |
| 122 | |
| 123 | assert(iterB->data() <= position); |
| 124 | assert(position <= iterB->data() + iterB->size()); |
| 125 | } |
| 126 | #else |
| 127 | // Version that assumes the precondition, |
| 128 | // which pre-3.2 did without known errors |
| 129 | for (auto &position : mPositions) |
| 130 | position += count; |
| 131 | #endif |
| 132 | // Assert the post |
| 133 | assert(Remaining() == oldRemaining - count); |
| 134 | } |
| 135 | |
| 136 | void AudioGraph::Buffers::Rewind() |
| 137 | { |