Change all of channel numbers and number of frames

to size_t
This commit is contained in:
Paul Ferrand 2020-01-05 00:20:37 +01:00
parent 7243e7aaa0
commit 78a4a63459
6 changed files with 44 additions and 44 deletions

View file

@ -42,7 +42,7 @@ namespace sfz
* @tparam MaxChannels the maximum number of channels in the buffer
* @tparam Alignment the alignment for the buffers
*/
template <class Type, int MaxChannels = sfz::config::numChannels, unsigned int Alignment = SIMDConfig::defaultAlignment>
template <class Type, size_t MaxChannels = sfz::config::numChannels, unsigned int Alignment = SIMDConfig::defaultAlignment>
class AudioBuffer {
public:
using value_type = std::remove_cv_t<Type>;
@ -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<value_type>
*/
absl::Span<value_type> getSpan(int channelIndex) const
absl::Span<value_type> getSpan(size_t channelIndex) const
{
ASSERT(channelIndex < numChannels)
if (channelIndex < numChannels)
@ -176,7 +175,7 @@ public:
* @param channelIndex
* @return absl::Span<const value_type>
*/
absl::Span<const value_type> getConstSpan(int channelIndex) const
absl::Span<const value_type> 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<buffer_type>;
static_assert(MaxChannels > 0, "Need a positive number of channels");
std::array<buffer_ptr, MaxChannels> buffers;
int numChannels { 0 };
size_type numFrames { 0 };
size_t numChannels { 0 };
size_t numFrames { 0 };
};
}

View file

@ -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 <class Type, int MaxChannels = sfz::config::numChannels>
template <class Type, size_t MaxChannels = sfz::config::numChannels>
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<Type*, MaxChannels>& spans, int numChannels, size_type offset, size_type numFrames)
AudioSpan(const std::array<Type*, MaxChannels>& 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<Type>
*/
absl::Span<Type> getSpan(int channelIndex)
absl::Span<Type> getSpan(size_t channelIndex)
{
ASSERT(channelIndex < numChannels);
if (channelIndex < numChannels)
@ -246,7 +246,7 @@ public:
* @param channelIndex the channel
* @return absl::Span<const Type>
*/
absl::Span<const Type> getConstSpan(int channelIndex)
absl::Span<const Type> 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<Type>(getConstSpan(i));
return result / numChannels;
}
@ -278,7 +278,7 @@ public:
void fill(Type value) noexcept
{
static_assert(!std::is_const<Type>::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<Type>(getSpan(i), value);
}
@ -290,7 +290,7 @@ public:
void applyGain(absl::Span<const Type> gain) noexcept
{
static_assert(!std::is_const<Type>::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<Type>(gain, getSpan(i));
}
@ -302,7 +302,7 @@ public:
void applyGain(Type gain) noexcept
{
static_assert(!std::is_const<Type>::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<Type>(gain, getSpan(i));
}
@ -318,7 +318,7 @@ public:
static_assert(!std::is_const<Type>::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<Type>(other.getConstSpan(i), getSpan(i));
}
}
@ -335,7 +335,7 @@ public:
static_assert(!std::is_const<Type>::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<Type>(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<Type*, MaxChannels> spans;
size_type numFrames { 0 };
int numChannels { 0 };
size_type numChannels { 0 };
};
}

View file

@ -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; }

View file

@ -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 };

View file

@ -26,7 +26,7 @@ public:
*
* @param size
*/
void resize(int size)
void resize(size_t size)
{
buffer.resize(size);
fill<ValueType>(absl::MakeSpan(buffer), 0.0);

View file

@ -59,7 +59,7 @@ public:
Type getGain() const { return gain; }
int processLowpass(absl::Span<const Type> input, absl::Span<Type> lowpass)
size_t processLowpass(absl::Span<const Type> input, absl::Span<Type> lowpass)
{
auto in = input.begin();
auto out = lowpass.begin();
@ -73,7 +73,7 @@ public:
return size;
}
int processHighpass(absl::Span<const Type> input, absl::Span<Type> highpass)
size_t processHighpass(absl::Span<const Type> input, absl::Span<Type> highpass)
{
auto in = input.begin();
auto out = highpass.begin();
@ -87,7 +87,7 @@ public:
return size;
}
int processLowpassVariableGain(absl::Span<const Type> input, absl::Span<Type> lowpass, absl::Span<const Type> gain)
size_t processLowpassVariableGain(absl::Span<const Type> input, absl::Span<Type> lowpass, absl::Span<const Type> gain)
{
auto in = input.begin();
auto out = lowpass.begin();
@ -104,7 +104,7 @@ public:
return size;
}
int processHighpassVariableGain(absl::Span<const Type> input, absl::Span<Type> highpass, absl::Span<const Type> gain)
size_t processHighpassVariableGain(absl::Span<const Type> input, absl::Span<Type> highpass, absl::Span<const Type> gain)
{
auto in = input.begin();
auto out = highpass.begin();