| 50 | #define stackAllocate(T, count) static_cast<T*>(alloca(count * sizeof(T))) |
| 51 | |
| 52 | std::optional<size_t> WideSampleSource::Acquire(Buffers &data, size_t bound) |
| 53 | { |
| 54 | assert(bound <= data.BlockSize()); |
| 55 | assert(data.BlockSize() <= data.Remaining()); |
| 56 | assert(AcceptsBuffers(data)); |
| 57 | assert(AcceptsBlockSize(data.BlockSize())); |
| 58 | |
| 59 | if (!mInitialized || mFetched < bound) { |
| 60 | // Need to fill sufficent data in the buffers |
| 61 | // Calculate the number of samples to get |
| 62 | const auto fetch = |
| 63 | limitSampleBufferSize(data.Remaining() - mFetched, Remaining()); |
| 64 | // guarantees write won't overflow |
| 65 | assert(mFetched + fetch <= data.Remaining()); |
| 66 | // Fill the buffers |
| 67 | auto buffers = stackAllocate(float *, mnChannels); |
| 68 | if (mnChannels > 0) |
| 69 | buffers[0] = &data.GetWritePosition(0) + mFetched; |
| 70 | if (mnChannels > 1) |
| 71 | buffers[1] = &data.GetWritePosition(1) + mFetched; |
| 72 | mSequence.GetFloats(0, mnChannels, buffers, mPos, fetch); |
| 73 | mPos += fetch; |
| 74 | mFetched += fetch; |
| 75 | mInitialized = true; |
| 76 | } |
| 77 | assert(data.Remaining() > 0); |
| 78 | auto result = mLastProduced = std::min(bound, |
| 79 | limitSampleBufferSize(data.Remaining(), Remaining())); |
| 80 | // assert post |
| 81 | assert(result <= bound); |
| 82 | assert(result <= data.Remaining()); |
| 83 | assert(result <= Remaining()); |
| 84 | // true because the three terms of the min would be positive |
| 85 | assert(bound == 0 || Remaining() == 0 || result > 0); |
| 86 | return { result }; |
| 87 | } |
| 88 | |
| 89 | bool WideSampleSource::Release() |
| 90 | { |
nothing calls this directly
no test coverage detected