From 78a4a63459af3d474de19a20f9422d1e4f34e9ca Mon Sep 17 00:00:00 2001 From: Paul Ferrand Date: Sun, 5 Jan 2020 00:20:37 +0100 Subject: [PATCH] Change all of channel numbers and number of frames to size_t --- src/sfizz/AudioBuffer.h | 39 ++++++++++++++++++------------------ src/sfizz/AudioSpan.h | 32 ++++++++++++++--------------- src/sfizz/Buffer.h | 2 +- src/sfizz/Config.h | 5 +++-- src/sfizz/HistoricalBuffer.h | 2 +- src/sfizz/OnePoleFilter.h | 8 ++++---- 6 files changed, 44 insertions(+), 44 deletions(-) diff --git a/src/sfizz/AudioBuffer.h b/src/sfizz/AudioBuffer.h index d65e2a2d..a7921d08 100644 --- a/src/sfizz/AudioBuffer.h +++ b/src/sfizz/AudioBuffer.h @@ -42,7 +42,7 @@ namespace sfz * @tparam MaxChannels the maximum number of channels in the buffer * @tparam Alignment the alignment for the buffers */ -template +template class AudioBuffer { public: using value_type = std::remove_cv_t; @@ -50,7 +50,6 @@ public: using const_pointer = const value_type*; using iterator = pointer; using const_iterator = const_pointer; - using size_type = size_t; /** * @brief Construct a new Audio Buffer object @@ -67,7 +66,7 @@ public: * @param numChannels * @param numFrames */ - AudioBuffer(int numChannels, int numFrames) + AudioBuffer(size_t numChannels, size_t numFrames) : numChannels(numChannels) , numFrames(numFrames) { @@ -82,7 +81,7 @@ public: * @return true if the resize worked * @return false otherwise */ - bool resize(size_type newSize) + bool resize(size_t newSize) { bool returnedOK = true; @@ -101,7 +100,7 @@ public: * @param channelIndex * @return iterator */ - iterator channelWriter(int channelIndex) + iterator channelWriter(size_t channelIndex) { ASSERT(channelIndex < numChannels) if (channelIndex < numChannels) @@ -116,7 +115,7 @@ public: * @param channelIndex * @return iterator */ - iterator channelWriterEnd(int channelIndex) + iterator channelWriterEnd(size_t channelIndex) { ASSERT(channelIndex < numChannels) if (channelIndex < numChannels) @@ -131,7 +130,7 @@ public: * @param channelIndex * @return const_iterator */ - const_iterator channelReader(int channelIndex) const + const_iterator channelReader(size_t channelIndex) const { ASSERT(channelIndex < numChannels) if (channelIndex < numChannels) @@ -146,7 +145,7 @@ public: * @param channelIndex * @return const_iterator */ - const_iterator channelReaderEnd(int channelIndex) const + const_iterator channelReaderEnd(size_t channelIndex) const { ASSERT(channelIndex < numChannels) if (channelIndex < numChannels) @@ -161,7 +160,7 @@ public: * @param channelIndex * @return absl::Span */ - absl::Span getSpan(int channelIndex) const + absl::Span getSpan(size_t channelIndex) const { ASSERT(channelIndex < numChannels) if (channelIndex < numChannels) @@ -176,7 +175,7 @@ public: * @param channelIndex * @return absl::Span */ - absl::Span getConstSpan(int channelIndex) const + absl::Span getConstSpan(size_t channelIndex) const { return getSpan(channelIndex); } @@ -194,9 +193,9 @@ public: /** * @brief Get the number of elements in each buffer * - * @return size_type + * @return size_t */ - size_type getNumFrames() const + size_t getNumFrames() const { return numFrames; } @@ -206,7 +205,7 @@ public: * * @return int */ - int getNumChannels() const + size_t getNumChannels() const { return numChannels; } @@ -231,7 +230,7 @@ public: * @param frameIndex * @return Type& */ - Type& getSample(int channelIndex, size_type frameIndex) + Type& getSample(size_t channelIndex, size_t frameIndex) { // Uhoh ASSERT(buffers[channelIndex] != nullptr); @@ -247,7 +246,7 @@ public: * @param frameIndex * @return Type& */ - Type& operator()(int channelIndex, size_type frameIndex) + Type& operator()(size_t channelIndex, size_t frameIndex) { return getSample(channelIndex, frameIndex); } @@ -258,7 +257,7 @@ public: */ void reset() { - for (int i = 0; i < numChannels; ++i) + for (size_t i = 0; i < numChannels; ++i) buffers[i].reset(); numFrames = 0; numChannels = 0; @@ -269,10 +268,10 @@ public: * * @param numChannels */ - void addChannels(int numChannels) + void addChannels(size_t numChannels) { ASSERT(this->numChannels + numChannels <= MaxChannels); - for (int i = 0; i < numChannels; ++i) + for (size_t i = 0; i < numChannels; ++i) addChannel(); } @@ -281,7 +280,7 @@ private: using buffer_ptr = std::unique_ptr; static_assert(MaxChannels > 0, "Need a positive number of channels"); std::array buffers; - int numChannels { 0 }; - size_type numFrames { 0 }; + size_t numChannels { 0 }; + size_t numFrames { 0 }; }; } diff --git a/src/sfizz/AudioSpan.h b/src/sfizz/AudioSpan.h index 0ccfd5e9..0f2feca8 100644 --- a/src/sfizz/AudioSpan.h +++ b/src/sfizz/AudioSpan.h @@ -86,7 +86,7 @@ namespace sfz * @tparam Type the underlying buffer type * @tparam MaxChannels the maximum number of channels. Defaults to sfz::config::numChannels */ -template +template class AudioSpan { public: using size_type = size_t; @@ -102,7 +102,7 @@ public: * @param offset starting offset for the AudioSpan * @param numFrames size of the AudioSpan */ - AudioSpan(const std::array& spans, int numChannels, size_type offset, size_type numFrames) + AudioSpan(const std::array& spans, size_type numChannels, size_type offset, size_type numFrames) : numFrames(numFrames) , numChannels(numChannels) { @@ -169,7 +169,7 @@ public: : numFrames(audioBuffer.getNumFrames()) , numChannels(audioBuffer.getNumChannels()) { - for (int i = 0; i < numChannels; i++) { + for (size_t i = 0; i < numChannels; i++) { this->spans[i] = audioBuffer.channelReader(i); } } @@ -190,7 +190,7 @@ public: : numFrames(audioBuffer.getNumFrames()) , numChannels(audioBuffer.getNumChannels()) { - for (int i = 0; i < numChannels; i++) { + for (size_t i = 0; i < numChannels; i++) { this->spans[i] = audioBuffer.channelWriter(i); } } @@ -205,7 +205,7 @@ public: : numFrames(other.getNumFrames()) , numChannels(other.getNumChannels()) { - for (int i = 0; i < numChannels; i++) { + for (size_t i = 0; i < numChannels; i++) { this->spans[i] = other.getChannel(i); } } @@ -216,7 +216,7 @@ public: * @param channelIndex the channel * @return Type* the raw pointer to the channel */ - Type* getChannel(int channelIndex) + Type* getChannel(size_t channelIndex) { ASSERT(channelIndex < numChannels); if (channelIndex < numChannels) @@ -231,7 +231,7 @@ public: * @param channelIndex the channel * @return absl::Span */ - absl::Span getSpan(int channelIndex) + absl::Span getSpan(size_t channelIndex) { ASSERT(channelIndex < numChannels); if (channelIndex < numChannels) @@ -246,7 +246,7 @@ public: * @param channelIndex the channel * @return absl::Span */ - absl::Span getConstSpan(int channelIndex) + absl::Span getConstSpan(size_t channelIndex) { ASSERT(channelIndex < numChannels); if (channelIndex < numChannels) @@ -265,7 +265,7 @@ public: if (numChannels == 0) return 0.0; Type result = 0.0; - for (int i = 0; i < numChannels; ++i) + for (size_t i = 0; i < numChannels; ++i) result += sfz::meanSquared(getConstSpan(i)); return result / numChannels; } @@ -278,7 +278,7 @@ public: void fill(Type value) noexcept { static_assert(!std::is_const::value, "Can't allow mutating operations on const AudioSpans"); - for (int i = 0; i < numChannels; ++i) + for (size_t i = 0; i < numChannels; ++i) sfz::fill(getSpan(i), value); } @@ -290,7 +290,7 @@ public: void applyGain(absl::Span gain) noexcept { static_assert(!std::is_const::value, "Can't allow mutating operations on const AudioSpans"); - for (int i = 0; i < numChannels; ++i) + for (size_t i = 0; i < numChannels; ++i) sfz::applyGain(gain, getSpan(i)); } @@ -302,7 +302,7 @@ public: void applyGain(Type gain) noexcept { static_assert(!std::is_const::value, "Can't allow mutating operations on const AudioSpans"); - for (int i = 0; i < numChannels; ++i) + for (size_t i = 0; i < numChannels; ++i) sfz::applyGain(gain, getSpan(i)); } @@ -318,7 +318,7 @@ public: static_assert(!std::is_const::value, "Can't allow mutating operations on const AudioSpans"); ASSERT(other.getNumChannels() == numChannels); if (other.getNumChannels() == numChannels) { - for (int i = 0; i < numChannels; ++i) + for (size_t i = 0; i < numChannels; ++i) sfz::add(other.getConstSpan(i), getSpan(i)); } } @@ -335,7 +335,7 @@ public: static_assert(!std::is_const::value, "Can't allow mutating operations on const AudioSpans"); ASSERT(other.getNumChannels() == numChannels); if (other.getNumChannels() == numChannels) { - for (int i = 0; i < numChannels; ++i) + for (size_t i = 0; i < numChannels; ++i) sfz::copy(other.getConstSpan(i), getSpan(i)); } } @@ -355,7 +355,7 @@ public: * * @returns size_type the number of channels in the AudioSpan */ - int getNumChannels() + size_t getNumChannels() { return numChannels; } @@ -413,6 +413,6 @@ private: static_assert(MaxChannels > 0, "Need a positive number of channels"); std::array spans; size_type numFrames { 0 }; - int numChannels { 0 }; + size_type numChannels { 0 }; }; } diff --git a/src/sfizz/Buffer.h b/src/sfizz/Buffer.h index e97843ed..efad39c9 100644 --- a/src/sfizz/Buffer.h +++ b/src/sfizz/Buffer.h @@ -250,7 +250,7 @@ public: // return *this; // } - Type& operator[](int idx) { return *(normalData + idx); } + Type& operator[](size_t idx) { return *(normalData + idx); } constexpr pointer data() const noexcept { return normalData; } constexpr size_type size() const noexcept { return alignedSize; } constexpr bool empty() const noexcept { return alignedSize == 0; } diff --git a/src/sfizz/Config.h b/src/sfizz/Config.h index 3d350c9d..50679e13 100644 --- a/src/sfizz/Config.h +++ b/src/sfizz/Config.h @@ -26,6 +26,7 @@ #ifdef _WIN32 // There's a spurious min/max function in MSVC that makes everything go badly... #define NOMINMAX +#define _SILENCE_CXX17_OLD_ALLOCATOR_MEMBERS_DEPRECATION_WARNING #endif namespace sfz { @@ -41,7 +42,7 @@ namespace config { constexpr int defaultSamplesPerBlock { 1024 }; constexpr int maxBlockSize { 8192 }; constexpr int preloadSize { 8192 }; - constexpr int numChannels { 2 }; + constexpr size_t numChannels { 2 }; constexpr int numBackgroundThreads { 4 }; constexpr int numVoices { 64 }; constexpr int maxVoices { 256 }; @@ -59,7 +60,7 @@ namespace config { constexpr char defineCharacter { '$' }; constexpr Oversampling defaultOversamplingFactor { Oversampling::x1 }; constexpr float A440 { 440.0 }; - constexpr unsigned powerHistoryLength { 16 }; + constexpr size_t powerHistoryLength { 16 }; constexpr float voiceStealingThreshold { 0.00001f }; constexpr int numCCs { 143 }; constexpr int chunkSize { 1024 }; diff --git a/src/sfizz/HistoricalBuffer.h b/src/sfizz/HistoricalBuffer.h index f717250d..09d68a1a 100644 --- a/src/sfizz/HistoricalBuffer.h +++ b/src/sfizz/HistoricalBuffer.h @@ -26,7 +26,7 @@ public: * * @param size */ - void resize(int size) + void resize(size_t size) { buffer.resize(size); fill(absl::MakeSpan(buffer), 0.0); diff --git a/src/sfizz/OnePoleFilter.h b/src/sfizz/OnePoleFilter.h index 9c3afd0f..6c1e3f0f 100644 --- a/src/sfizz/OnePoleFilter.h +++ b/src/sfizz/OnePoleFilter.h @@ -59,7 +59,7 @@ public: Type getGain() const { return gain; } - int processLowpass(absl::Span input, absl::Span lowpass) + size_t processLowpass(absl::Span input, absl::Span lowpass) { auto in = input.begin(); auto out = lowpass.begin(); @@ -73,7 +73,7 @@ public: return size; } - int processHighpass(absl::Span input, absl::Span highpass) + size_t processHighpass(absl::Span input, absl::Span highpass) { auto in = input.begin(); auto out = highpass.begin(); @@ -87,7 +87,7 @@ public: return size; } - int processLowpassVariableGain(absl::Span input, absl::Span lowpass, absl::Span gain) + size_t processLowpassVariableGain(absl::Span input, absl::Span lowpass, absl::Span gain) { auto in = input.begin(); auto out = lowpass.begin(); @@ -104,7 +104,7 @@ public: return size; } - int processHighpassVariableGain(absl::Span input, absl::Span highpass, absl::Span gain) + size_t processHighpassVariableGain(absl::Span input, absl::Span highpass, absl::Span gain) { auto in = input.begin(); auto out = highpass.begin();