diff --git a/src/encoder/plugins/LameEncoderPlugin.cxx b/src/encoder/plugins/LameEncoderPlugin.cxx index 597e51536..b28321f81 100644 --- a/src/encoder/plugins/LameEncoderPlugin.cxx +++ b/src/encoder/plugins/LameEncoderPlugin.cxx @@ -31,18 +31,16 @@ #include class LameEncoder final : public Encoder { - const AudioFormat audio_format; - lame_global_flags *const gfp; ReusableArray output_buffer; std::span 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 _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; diff --git a/src/encoder/plugins/TwolameEncoderPlugin.cxx b/src/encoder/plugins/TwolameEncoderPlugin.cxx index 20b6950f4..8bdc50df6 100644 --- a/src/encoder/plugins/TwolameEncoderPlugin.cxx +++ b/src/encoder/plugins/TwolameEncoderPlugin.cxx @@ -32,8 +32,6 @@ #include 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 _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,