From 28e044a36a9eb6eeb133602478858cabb4fdd06e Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 12 Jul 2022 10:12:39 +0200 Subject: [PATCH] encoder/lame: use std::size_t --- src/encoder/plugins/LameEncoderPlugin.cxx | 14 +++++++------- src/encoder/plugins/TwolameEncoderPlugin.cxx | 10 +++++----- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/encoder/plugins/LameEncoderPlugin.cxx b/src/encoder/plugins/LameEncoderPlugin.cxx index 7bfd87801..e4b38cad6 100644 --- a/src/encoder/plugins/LameEncoderPlugin.cxx +++ b/src/encoder/plugins/LameEncoderPlugin.cxx @@ -51,8 +51,8 @@ public: LameEncoder &operator=(const LameEncoder &) = delete; /* virtual methods from class Encoder */ - void Write(const void *data, size_t length) override; - size_t Read(void *dest, size_t length) noexcept override; + void Write(std::span src) override; + std::span Read(std::span buffer) noexcept override; }; class PreparedLameEncoder final : public PreparedEncoder { @@ -167,17 +167,17 @@ LameEncoder::~LameEncoder() noexcept } void -LameEncoder::Write(const void *data, size_t length) +LameEncoder::Write(std::span src) { const auto *src = (const int16_t*)data; assert(output_begin == output_end); - const unsigned num_frames = length / audio_format.GetFrameSize(); - const unsigned num_samples = length / audio_format.GetSampleSize(); + const std::size_t num_frames = length / audio_format.GetFrameSize(); + const std::size_t num_samples = length / audio_format.GetSampleSize(); /* worst-case formula according to LAME documentation */ - const size_t output_buffer_size = 5 * num_samples / 4 + 7200; + const std::size_t output_buffer_size = 5 * num_samples / 4 + 7200; const auto dest = output_buffer.Get(output_buffer_size); /* this is for only 16-bit audio */ @@ -199,7 +199,7 @@ LameEncoder::Read(void *dest, size_t length) noexcept { const auto begin = output_begin; assert(begin <= output_end); - const size_t remainning = output_end - begin; + const std::size_t remainning = output_end - begin; if (length > remainning) length = remainning; diff --git a/src/encoder/plugins/TwolameEncoderPlugin.cxx b/src/encoder/plugins/TwolameEncoderPlugin.cxx index bd24c041e..5ca2dd756 100644 --- a/src/encoder/plugins/TwolameEncoderPlugin.cxx +++ b/src/encoder/plugins/TwolameEncoderPlugin.cxx @@ -38,8 +38,8 @@ class TwolameEncoder final : public Encoder { twolame_options *options; unsigned char output_buffer[32768]; - size_t output_buffer_length = 0; - size_t output_buffer_position = 0; + std::size_t output_buffer_length = 0; + std::size_t output_buffer_position = 0; /** * Call libtwolame's flush function when the output_buffer is @@ -193,7 +193,7 @@ TwolameEncoder::Write(const void *data, size_t length) assert(output_buffer_position == output_buffer_length); - const unsigned num_frames = length / audio_format.GetFrameSize(); + const std::size_t num_frames = length / audio_format.GetFrameSize(); int bytes_out = twolame_encode_buffer_interleaved(options, src, num_frames, @@ -202,7 +202,7 @@ TwolameEncoder::Write(const void *data, size_t length) if (bytes_out < 0) throw std::runtime_error("twolame encoder failed"); - output_buffer_length = (size_t)bytes_out; + output_buffer_length = (std::size_t)bytes_out; output_buffer_position = 0; } @@ -223,7 +223,7 @@ TwolameEncoder::Read(void *dest, size_t length) noexcept } - const size_t remainning = output_buffer_length - output_buffer_position; + const std::size_t remainning = output_buffer_length - output_buffer_position; if (length > remainning) length = remainning;