diff --git a/iamf/cli/codec/opus_encoder.cc b/iamf/cli/codec/opus_encoder.cc index 42f4deb2..def67fbe 100644 --- a/iamf/cli/codec/opus_encoder.cc +++ b/iamf/cli/codec/opus_encoder.cc @@ -151,11 +151,20 @@ absl::Status OpusEncoder::InitializeEncoder() { opus_error_code, "Failed to initialize Opus encoder.")); // `OPUS_SET_BITRATE` treats this as the bit-rate for the entire substream. - // Configure `libopus` so coupled substreams and mono substreams have the same + // Configure `libopus` so coupled substreams and mono substreams have equally // effective bit-rate per channel. - const auto substream_bitrate = static_cast( - encoder_metadata_.target_bitrate_per_channel() * num_channels_); - opus_encoder_ctl(encoder_, OPUS_SET_BITRATE(substream_bitrate)); + if (num_channels_ > 1) { + opus_encoder_ctl( + encoder_, + OPUS_SET_BITRATE(static_cast( + encoder_metadata_.target_bitrate_per_channel() * num_channels_ * + encoder_metadata_.coupling_rate_adjustment() + + 0.5f))); + } else { + opus_encoder_ctl(encoder_, + OPUS_SET_BITRATE(static_cast( + encoder_metadata_.target_bitrate_per_channel()))); + } return absl::OkStatus(); } diff --git a/iamf/cli/proto/codec_config.proto b/iamf/cli/proto/codec_config.proto index 94036a2b..5eb78b0b 100644 --- a/iamf/cli/proto/codec_config.proto +++ b/iamf/cli/proto/codec_config.proto @@ -40,6 +40,7 @@ message OpusEncoderMetadata { optional int32 target_bitrate_per_channel = 1; optional OpusApplicationFlag application = 2; optional bool use_float_api = 3 [default = true]; + optional float coupling_rate_adjustment = 4 [default = 1.0]; } message OpusDecoderConfig {