Skip to content

Commit 892c8d4

Browse files
committed
Fix broken resampling in MediaElement, support more media types
1 parent 7d10ff7 commit 892c8d4

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

Cargo.toml

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ rust-version = "1.70"
1616
arc-swap = "1.6"
1717
arrayvec = "0.7"
1818
cpal = { version = "0.15.0", optional = true }
19-
creek = "1.0"
19+
creek = "1.1"
2020
crossbeam-channel = "0.5"
2121
cubeb = { version = "0.10.0", optional = true }
2222
dasp_sample = "0.11"
@@ -54,12 +54,9 @@ mp3 = ["symphonia/mp3", "creek/decode-mp3"]
5454
ogg = ["symphonia/ogg", "symphonia/vorbis", "creek/decode-ogg", "creek/decode-vorbis"]
5555
flac = ["symphonia/flac", "creek/decode-flac"]
5656
wav = ["symphonia/wav", "symphonia/pcm", "creek/decode-wav", "creek/decode-pcm"]
57-
# TODO(m4a): Add "creek/decode-aac" after <https://github.com/MeadowlarkDAW/creek/pull/22> has been merged
58-
aac = ["symphonia/aac"]
59-
# TODO(m4a): Add "creek/decode-isomp4" after <https://github.com/MeadowlarkDAW/creek/pull/22> has been merged
60-
m4a = ["aac", "symphonia/isomp4"]
61-
# TODO(alac): Add "creek/decode-alac" and "creek/decode-isomp4" after <https://github.com/MeadowlarkDAW/creek/pull/22> has been merged
62-
alac = ["symphonia/alac", "symphonia/isomp4"]
57+
aac = ["symphonia/aac", "creek/decode-aac"]
58+
m4a = ["aac", "symphonia/isomp4", "creek/decode-isomp4"]
59+
alac = ["symphonia/alac", "symphonia/isomp4", "creek/decode-alac", "creek/decode-isomp4"]
6360
cpal = ["dep:cpal"]
6461
cubeb = ["dep:cubeb"]
6562
cpal-jack = ["cpal", "cpal/jack"]

src/media_element.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use crate::{AtomicF64, AudioBuffer, RENDER_QUANTUM_SIZE};
1111
/// Real time safe audio stream
1212
pub(crate) struct RTSStream {
1313
stream: ReadDiskStream<SymphoniaDecoder>,
14+
number_of_channels: usize,
1415
current_time: Arc<AtomicF64>,
1516
receiver: Receiver<MediaElementAction>,
1617
loop_: Arc<AtomicBool>,
@@ -54,6 +55,7 @@ impl MediaElement {
5455
0, // The frame in the file to start reading from.
5556
Default::default(), // Use default read stream options.
5657
)?;
58+
let number_of_channels = read_disk_stream.info().num_channels as usize;
5759

5860
// Cache the start of the file into cache with index `0`.
5961
let _ = read_disk_stream.cache(0, 0);
@@ -79,6 +81,7 @@ impl MediaElement {
7981

8082
let rts_stream = RTSStream {
8183
stream: read_disk_stream,
84+
number_of_channels,
8285
current_time: Arc::clone(&current_time),
8386
receiver,
8487
loop_: Arc::clone(&loop_),
@@ -161,7 +164,10 @@ impl Iterator for RTSStream {
161164
}
162165

163166
if self.paused.load(Ordering::SeqCst) {
164-
let silence = AudioBuffer::from(vec![vec![0.; RENDER_QUANTUM_SIZE]], sample_rate);
167+
let silence = AudioBuffer::from(
168+
vec![vec![0.; RENDER_QUANTUM_SIZE]; self.number_of_channels],
169+
sample_rate,
170+
);
165171
return Some(Ok(silence));
166172
}
167173

0 commit comments

Comments
 (0)