encoder/lame: eliminate the audio_format field
This commit is contained in:
parent
c266fb7758
commit
3e2de560ca
@ -31,18 +31,16 @@
|
||||
#include <stdexcept>
|
||||
|
||||
class LameEncoder final : public Encoder {
|
||||
const AudioFormat audio_format;
|
||||
|
||||
lame_global_flags *const gfp;
|
||||
|
||||
ReusableArray<std::byte, 32768> output_buffer;
|
||||
std::span<const std::byte> output{};
|
||||
|
||||
public:
|
||||
LameEncoder(const AudioFormat _audio_format,
|
||||
lame_global_flags *_gfp) noexcept
|
||||
:Encoder(false),
|
||||
audio_format(_audio_format), gfp(_gfp) {}
|
||||
static constexpr unsigned CHANNELS = 2;
|
||||
|
||||
explicit LameEncoder(lame_global_flags *_gfp) noexcept
|
||||
:Encoder(false), gfp(_gfp) {}
|
||||
|
||||
~LameEncoder() noexcept override;
|
||||
|
||||
@ -144,7 +142,7 @@ Encoder *
|
||||
PreparedLameEncoder::Open(AudioFormat &audio_format)
|
||||
{
|
||||
audio_format.format = SampleFormat::S16;
|
||||
audio_format.channels = 2;
|
||||
audio_format.channels = LameEncoder::CHANNELS;
|
||||
|
||||
auto gfp = lame_init();
|
||||
if (gfp == nullptr)
|
||||
@ -157,7 +155,7 @@ PreparedLameEncoder::Open(AudioFormat &audio_format)
|
||||
throw;
|
||||
}
|
||||
|
||||
return new LameEncoder(audio_format, gfp);
|
||||
return new LameEncoder(gfp);
|
||||
}
|
||||
|
||||
LameEncoder::~LameEncoder() noexcept
|
||||
@ -173,7 +171,7 @@ LameEncoder::Write(std::span<const std::byte> _src)
|
||||
assert(output.empty());
|
||||
|
||||
const std::size_t num_samples = src.size();
|
||||
const std::size_t num_frames = num_samples / audio_format.channels;
|
||||
const std::size_t num_frames = num_samples / CHANNELS;
|
||||
|
||||
/* worst-case formula according to LAME documentation */
|
||||
const std::size_t output_buffer_size = 5 * num_samples / 4 + 7200;
|
||||
|
@ -32,8 +32,6 @@
|
||||
#include <stdexcept>
|
||||
|
||||
class TwolameEncoder final : public Encoder {
|
||||
const AudioFormat audio_format;
|
||||
|
||||
twolame_options *options;
|
||||
|
||||
std::byte output_buffer[32768];
|
||||
@ -46,10 +44,10 @@ class TwolameEncoder final : public Encoder {
|
||||
bool flush = false;
|
||||
|
||||
public:
|
||||
TwolameEncoder(const AudioFormat _audio_format,
|
||||
twolame_options *_options)
|
||||
:Encoder(false),
|
||||
audio_format(_audio_format), options(_options) {}
|
||||
static constexpr unsigned CHANNELS = 2;
|
||||
|
||||
explicit TwolameEncoder(twolame_options *_options) noexcept
|
||||
:Encoder(false), options(_options) {}
|
||||
~TwolameEncoder() noexcept override;
|
||||
|
||||
TwolameEncoder(const TwolameEncoder &) = delete;
|
||||
@ -162,7 +160,7 @@ Encoder *
|
||||
PreparedTwolameEncoder::Open(AudioFormat &audio_format)
|
||||
{
|
||||
audio_format.format = SampleFormat::S16;
|
||||
audio_format.channels = 2;
|
||||
audio_format.channels = TwolameEncoder::CHANNELS;
|
||||
|
||||
auto options = twolame_init();
|
||||
if (options == nullptr)
|
||||
@ -176,7 +174,7 @@ PreparedTwolameEncoder::Open(AudioFormat &audio_format)
|
||||
throw;
|
||||
}
|
||||
|
||||
return new TwolameEncoder(audio_format, options);
|
||||
return new TwolameEncoder(options);
|
||||
}
|
||||
|
||||
TwolameEncoder::~TwolameEncoder() noexcept
|
||||
@ -191,7 +189,7 @@ TwolameEncoder::Write(std::span<const std::byte> _src)
|
||||
|
||||
assert(fill == 0);
|
||||
|
||||
const std::size_t num_frames = src.size() / audio_format.channels;
|
||||
const std::size_t num_frames = src.size() / CHANNELS;
|
||||
|
||||
int bytes_out = twolame_encode_buffer_interleaved(options,
|
||||
src.data(), num_frames,
|
||||
|
Loading…
Reference in New Issue
Block a user