encoder/lame: use std::size_t
This commit is contained in:
parent
4e91d8279b
commit
28e044a36a
|
@ -51,8 +51,8 @@ public:
|
||||||
LameEncoder &operator=(const LameEncoder &) = delete;
|
LameEncoder &operator=(const LameEncoder &) = delete;
|
||||||
|
|
||||||
/* virtual methods from class Encoder */
|
/* virtual methods from class Encoder */
|
||||||
void Write(const void *data, size_t length) override;
|
void Write(std::span<const std::byte> src) override;
|
||||||
size_t Read(void *dest, size_t length) noexcept override;
|
std::span<const std::byte> Read(std::span<std::byte> buffer) noexcept override;
|
||||||
};
|
};
|
||||||
|
|
||||||
class PreparedLameEncoder final : public PreparedEncoder {
|
class PreparedLameEncoder final : public PreparedEncoder {
|
||||||
|
@ -167,17 +167,17 @@ LameEncoder::~LameEncoder() noexcept
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
LameEncoder::Write(const void *data, size_t length)
|
LameEncoder::Write(std::span<const std::byte> src)
|
||||||
{
|
{
|
||||||
const auto *src = (const int16_t*)data;
|
const auto *src = (const int16_t*)data;
|
||||||
|
|
||||||
assert(output_begin == output_end);
|
assert(output_begin == output_end);
|
||||||
|
|
||||||
const unsigned num_frames = length / audio_format.GetFrameSize();
|
const std::size_t num_frames = length / audio_format.GetFrameSize();
|
||||||
const unsigned num_samples = length / audio_format.GetSampleSize();
|
const std::size_t num_samples = length / audio_format.GetSampleSize();
|
||||||
|
|
||||||
/* worst-case formula according to LAME documentation */
|
/* 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);
|
const auto dest = output_buffer.Get(output_buffer_size);
|
||||||
|
|
||||||
/* this is for only 16-bit audio */
|
/* this is for only 16-bit audio */
|
||||||
|
@ -199,7 +199,7 @@ LameEncoder::Read(void *dest, size_t length) noexcept
|
||||||
{
|
{
|
||||||
const auto begin = output_begin;
|
const auto begin = output_begin;
|
||||||
assert(begin <= output_end);
|
assert(begin <= output_end);
|
||||||
const size_t remainning = output_end - begin;
|
const std::size_t remainning = output_end - begin;
|
||||||
if (length > remainning)
|
if (length > remainning)
|
||||||
length = remainning;
|
length = remainning;
|
||||||
|
|
||||||
|
|
|
@ -38,8 +38,8 @@ class TwolameEncoder final : public Encoder {
|
||||||
twolame_options *options;
|
twolame_options *options;
|
||||||
|
|
||||||
unsigned char output_buffer[32768];
|
unsigned char output_buffer[32768];
|
||||||
size_t output_buffer_length = 0;
|
std::size_t output_buffer_length = 0;
|
||||||
size_t output_buffer_position = 0;
|
std::size_t output_buffer_position = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Call libtwolame's flush function when the output_buffer is
|
* 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);
|
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,
|
int bytes_out = twolame_encode_buffer_interleaved(options,
|
||||||
src, num_frames,
|
src, num_frames,
|
||||||
|
@ -202,7 +202,7 @@ TwolameEncoder::Write(const void *data, size_t length)
|
||||||
if (bytes_out < 0)
|
if (bytes_out < 0)
|
||||||
throw std::runtime_error("twolame encoder failed");
|
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;
|
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)
|
if (length > remainning)
|
||||||
length = remainning;
|
length = remainning;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue