Skip to content

Commit 1c2cd2f

Browse files
authored
Merge pull request #697 from roderickvd/refactor/decoder-improvements
Decoder builder with additional settings
2 parents 4cc1a57 + a8a8b04 commit 1c2cd2f

26 files changed

+1108
-439
lines changed

CHANGELOG.md

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1919
- Minimal builds without `cpal` audio output are now supported.
2020
See `README.md` for instructions. (#349)
2121
- Added `Sample::is_zero()` method for checking zero samples.
22+
- Added `DecoderBuilder` for improved configuration.
23+
- Using `Decoder::TryFrom` for `File` now automatically wraps in `BufReader` and sets `byte_len`.
24+
`TryFrom<Cursor<T>>` and `TryFrom<BufReader>` are also supported.
2225

2326
### Changed
2427
- Breaking: `OutputStreamBuilder` should now be used to initialize an audio output stream.
@@ -29,9 +32,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2932
- Breaking: In the `Source` trait, the method `current_frame_len()` was renamed to `current_span_len()`.
3033
- Breaking: `Decoder` now outputs `f32` samples.
3134
- Breaking: The term 'frame' was renamed to 'span' in the crate and documentation.
32-
- Breaking: Sources now use `f32` samples. To convert to and from other types of samples use functions from
33-
`dasp_sample` crate. For example `DaspSample::from_sample(sample)`. Remove `integer-decoder` feature.
34-
35+
- Breaking: `LoopedDecoder` now returns `None` if seeking fails during loop reset.
36+
- Breaking: `ReadSeekSource::new()` now takes `Settings`.
37+
- Breaking: Sources now use `f32` samples. To convert to and from other types of samples use
38+
functions from `dasp_sample` crate. For example `DaspSample::from_sample(sample)`.
3539

3640
### Fixed
3741
- `ChannelVolume` no longer clips/overflows when converting from many channels to
@@ -40,12 +44,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
4044
- An issue with `SignalGenerator` that caused it to create increasingly distorted waveforms
4145
over long run times has been corrected. (#201)
4246
- WAV and FLAC decoder duration calculation now calculated once and handles very large files
43-
correctly
44-
- Removed unwrap() calls in MP3, WAV, FLAC and Vorbis format detection for better error handling
47+
correctly.
48+
- Removed unwrap() calls in MP3, WAV, FLAC and Vorbis format detection for better error handling.
49+
- `LoopedDecoder::size_hint` now correctly indicates an infinite stream.
50+
- Symphonia decoder `total_duration` for Vorbis now return the correct value (#696).
51+
- Symphonia decoder for MP4 now seeks correctly (#577).
4552

4653
### Deprecated
4754
- Deprecated `Sample::zero_value()` function in favor of `Sample::ZERO_VALUE` constant
4855

56+
### Removed
57+
- Breaking: Removed `Mp4Type` enum in favor of using MIME type string "audio/mp4" for MP4 format detection with `Decoder::new_mp4` (#612).
58+
4959
# Version 0.20.1 (2024-11-08)
5060

5161
### Fixed

Cargo.lock

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,14 @@ symphonia-all = [
4848
"symphonia-flac",
4949
"symphonia-isomp4",
5050
"symphonia-mp3",
51+
"symphonia-ogg",
5152
"symphonia-vorbis",
5253
"symphonia-wav",
5354
]
5455
symphonia-flac = ["symphonia/flac"]
5556
symphonia-isomp4 = ["symphonia/isomp4"]
5657
symphonia-mp3 = ["symphonia/mp3"]
58+
symphonia-ogg = ["symphonia/ogg"]
5759
symphonia-vorbis = ["symphonia/vorbis"]
5860
symphonia-wav = ["symphonia/wav", "symphonia/pcm", "symphonia/adpcm"]
5961
symphonia-alac = ["symphonia/isomp4", "symphonia/alac"]

examples/automatic_gain_control.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use rodio::source::Source;
22
use rodio::Decoder;
33
use std::error::Error;
44
use std::fs::File;
5-
use std::io::BufReader;
65
use std::sync::atomic::{AtomicBool, Ordering};
76
use std::sync::Arc;
87
use std::thread;
@@ -13,8 +12,8 @@ fn main() -> Result<(), Box<dyn Error>> {
1312
let sink = rodio::Sink::connect_new(&stream_handle.mixer());
1413

1514
// Decode the sound file into a source
16-
let file = BufReader::new(File::open("assets/music.flac")?);
17-
let source = Decoder::new(file)?;
15+
let file = File::open("assets/music.flac")?;
16+
let source = Decoder::try_from(file)?;
1817

1918
// Apply automatic gain control to the source
2019
let agc_source = source.automatic_gain_control(1.0, 4.0, 0.005, 5.0);

examples/callback_on_end.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use std::error::Error;
2-
use std::io::BufReader;
32
use std::sync::atomic::{AtomicU32, Ordering};
43
use std::sync::Arc;
54

@@ -8,7 +7,7 @@ fn main() -> Result<(), Box<dyn Error>> {
87
let sink = rodio::Sink::connect_new(&stream_handle.mixer());
98

109
let file = std::fs::File::open("assets/music.wav")?;
11-
sink.append(rodio::Decoder::new(BufReader::new(file))?);
10+
sink.append(rodio::Decoder::try_from(file)?);
1211

1312
// lets increment a number after `music.wav` has played. We are going to use atomics
1413
// however you could also use a `Mutex` or send a message through a `std::sync::mpsc`.

examples/into_file.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
use rodio::{output_to_wav, Source};
22
use std::error::Error;
3-
use std::io::BufReader;
43

54
/// Converts mp3 file to a wav file.
65
/// This example does not use any audio devices
76
/// and can be used in build configurations without `cpal` feature enabled.
87
fn main() -> Result<(), Box<dyn Error>> {
98
let file = std::fs::File::open("assets/music.mp3")?;
10-
let mut audio = rodio::Decoder::new(BufReader::new(file))?
9+
let mut audio = rodio::Decoder::try_from(file)?
1110
.automatic_gain_control(1.0, 4.0, 0.005, 3.0)
1211
.speed(0.8);
1312

examples/music_flac.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
use std::error::Error;
2-
use std::io::BufReader;
32

43
fn main() -> Result<(), Box<dyn Error>> {
54
let stream_handle = rodio::OutputStreamBuilder::open_default_stream()?;
65
let sink = rodio::Sink::connect_new(&stream_handle.mixer());
76

87
let file = std::fs::File::open("assets/music.flac")?;
9-
sink.append(rodio::Decoder::new(BufReader::new(file))?);
8+
sink.append(rodio::Decoder::try_from(file)?);
109

1110
sink.sleep_until_end();
1211

examples/music_m4a.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
use std::error::Error;
2-
use std::io::BufReader;
32

43
fn main() -> Result<(), Box<dyn Error>> {
54
let stream_handle = rodio::OutputStreamBuilder::open_default_stream()?;
65
let sink = rodio::Sink::connect_new(&stream_handle.mixer());
76

87
let file = std::fs::File::open("assets/music.m4a")?;
9-
sink.append(rodio::Decoder::new(BufReader::new(file))?);
8+
sink.append(rodio::Decoder::try_from(file)?);
109

1110
sink.sleep_until_end();
1211

examples/music_mp3.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
use std::error::Error;
2-
use std::io::BufReader;
32

43
fn main() -> Result<(), Box<dyn Error>> {
54
let stream_handle = rodio::OutputStreamBuilder::open_default_stream()?;
65
let sink = rodio::Sink::connect_new(&stream_handle.mixer());
76

87
let file = std::fs::File::open("assets/music.mp3")?;
9-
sink.append(rodio::Decoder::new(BufReader::new(file))?);
8+
sink.append(rodio::Decoder::try_from(file)?);
109

1110
sink.sleep_until_end();
1211

examples/music_ogg.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
use std::error::Error;
2-
use std::io::BufReader;
32

43
fn main() -> Result<(), Box<dyn Error>> {
54
let stream_handle = rodio::OutputStreamBuilder::open_default_stream()?;
65
let sink = rodio::Sink::connect_new(&stream_handle.mixer());
76

87
let file = std::fs::File::open("assets/music.ogg")?;
9-
sink.append(rodio::Decoder::new(BufReader::new(file))?);
8+
sink.append(rodio::Decoder::try_from(file)?);
109

1110
sink.sleep_until_end();
1211

0 commit comments

Comments
 (0)