Complete standalone Vorbis feature and option validation

This commit is contained in:
Dylan M. Taylor committed 2026-11-14 18:12:40 -05:00
1 parent 8ae42d1aeb
commit 9efb0a1575
3 files changed
+17 -1

No files matched your search

+1 -1
View File
@@ -24,7 +24,7 @@ decode-native = ["aac-decode", "alac-decode", "opus-decode", "ac3-decode", "mpa-
symphonia = ["decode-native", "dep:symphonia"]
# Every encoder: the lossless file writers and the AAC, ALAC, AC-3/E-AC-3, MP3 and Opus encoders.
# All but Opus are also file formats of `encode` and `FileEncoder`.
encode = ["lossless-encode", "aac-encode", "alac-encode", "ac3-encode", "eac3-encode", "mp3-encode", "opus-encode"]
encode = ["lossless-encode", "aac-encode", "alac-encode", "ac3-encode", "eac3-encode", "mp3-encode", "opus-encode", "vorbis-encode"]
# Encode WAV/BWF/RF64, AIFF/AIFF-C and FLAC files.
lossless-encode = ["pcm-encode", "flac-encode"]
# Encode WAV/BWF/RF64 and AIFF/AIFF-C files.
+15
View File
@@ -232,6 +232,15 @@ impl<W: Write + Seek> std::fmt::Debug for FileEncoder<W> {
// The writers differ in size with the features built; the coded one is boxed for its encoder.
#[allow(clippy::large_enum_variant)]
#[cfg(any(
feature = "pcm-encode",
feature = "flac-encode",
feature = "aac-encode",
feature = "alac-encode",
feature = "mp3-encode",
feature = "ac3-encode",
feature = "eac3-encode"
))]
enum Writer<W: Write + Seek> {
#[cfg(feature = "pcm-encode")]
Wav(wav::Writer<W>),
@@ -390,6 +399,12 @@ impl EncodeOptions {
/// The constant bit rate such a file would be written at ([`FileEncoder::bitrate`]), or the
/// error [`EncodeOptions::check`] returns.
pub fn bitrate(&self, sample_rate: u32, channels: u16) -> Result<Option<u32>> {
#[cfg(feature = "vorbis-encode")]
if self.format == EncodeFormat::Ogg {
// Vorbis is whole-buffer only and VBR has no constant output bitrate.
encode(&AudioBuffer::new(sample_rate, channels, 0), self)?;
return Ok(None);
}
// The encoder a file would get, on a sink that is thrown away: what it accepts and the
// rate it settles on are then the writer's by construction.
Ok(FileEncoder::new(std::io::Cursor::new(Vec::new()), self, sample_rate, channels)?.bitrate())
+1
View File
@@ -71,6 +71,7 @@ pub fn encode(_buf: &AudioBuffer, _kbps: u32) -> Result<Vec<u8>> {
#[cfg(all(test, not(target_arch = "wasm32")))]
mod tests {
#![allow(clippy::unwrap_used)]
use super::*;
#[test]