encoder/lame: use std::size_t

This commit is contained in:
Max Kellermann 2022-07-12 10:12:39 +02:00
parent 4e91d8279b
commit 28e044a36a
2 changed files with 12 additions and 12 deletions

View File

@ -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<const std::byte> src) override;
std::span<const std::byte> Read(std::span<std::byte> 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<const std::byte> 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;

View File

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