Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

Remove Windows-specific audio playback code paths

Richie McIlroy1527fecd5c8c
diff --git a/crates/editor/src/audio.rs b/crates/editor/src/audio.rs
index 20c53de31..0376d6d82 100644
--- a/crates/editor/src/audio.rs
+++ b/crates/editor/src/audio.rs
@@ -180,12 +180,14 @@ impl AudioRenderer {
let channels: usize = 2;
if self.cursor.timescale != 1.0 {
+ self.elapsed_samples += samples;
return None;
};
let tracks = &self.data[self.cursor.clip_index as usize].tracks;
if tracks.is_empty() {
+ self.elapsed_samples += samples;
return None;
}
@@ -444,7 +446,6 @@ impl AudioResampler {
}
}
-#[cfg(target_os = "windows")]
pub struct PrerenderedAudioBuffer<T: FromSampleBytes> {
samples: Vec<T>,
read_position: usize,
@@ -452,7 +453,6 @@ pub struct PrerenderedAudioBuffer<T: FromSampleBytes> {
channels: usize,
}
-#[cfg(target_os = "windows")]
impl<T: FromSampleBytes> PrerenderedAudioBuffer<T> {
pub fn new(
segments: Vec<AudioSegment>,
@@ -464,7 +464,7 @@ impl<T: FromSampleBytes> PrerenderedAudioBuffer<T> {
duration_secs = duration_secs,
sample_rate = output_info.sample_rate,
channels = output_info.channels,
- "Pre-rendering audio for Windows playback"
+ "Pre-rendering audio for playback"
);
let mut renderer = AudioRenderer::new(segments);
@@ -481,20 +481,29 @@ impl<T: FromSampleBytes> PrerenderedAudioBuffer<T> {
renderer.set_playhead(0.0, project);
let mut rendered_source_samples = 0usize;
+ let output_chunk_samples = (chunk_size as f64 * output_info.sample_rate as f64
+ / AudioData::SAMPLE_RATE as f64) as usize
+ * output_info.channels;
+
while rendered_source_samples < total_source_samples {
let frame_opt = renderer.render_frame(chunk_size, project);
- let resampled = match frame_opt {
- Some(frame) => resampler.queue_and_process_frame(&frame),
- None => match resampler.flush_frame() {
- Some(data) => data,
- None => break,
- },
- };
-
- if !resampled.is_empty() {
- for chunk in resampled.chunks(bytes_per_sample) {
- samples.push(T::from_bytes(chunk));
+ match frame_opt {
+ Some(frame) => {
+ let resampled = resampler.queue_and_process_frame(&frame);
+ for chunk in resampled.chunks(bytes_per_sample) {
+ samples.push(T::from_bytes(chunk));
+ }
+ }
+ None => {
+ if let Some(flushed) = resampler.flush_frame() {
+ for chunk in flushed.chunks(bytes_per_sample) {
+ samples.push(T::from_bytes(chunk));
+ }
+ }
+ for _ in 0..output_chunk_samples {
+ samples.push(T::EQUILIBRIUM);
+ }
}
}
diff --git a/crates/editor/src/playback.rs b/crates/editor/src/playback.rs
index 33352d737..4e76a9390 100644
--- a/crates/editor/src/playback.rs
+++ b/crates/editor/src/playback.rs
@@ -344,7 +344,6 @@ impl Playback {
project: self.project.clone(),
fps,
playhead_rx: audio_playhead_rx,
- #[cfg(target_os = "windows")]
duration_secs: duration,
}
.spawn();
@@ -696,7 +695,6 @@ struct AudioPlayback {
project: watch::Receiver<ProjectConfiguration>,
fps: u32,
playhead_rx: watch::Receiver<f64>,
- #[cfg(target_os = "windows")]
duration_secs: f64,
}
@@ -729,46 +727,27 @@ impl AudioPlayback {
}
};
- #[cfg(target_os = "windows")]
let duration_secs = self.duration_secs;
let result = match supported_config.sample_format() {
- #[cfg(target_os = "windows")]
SampleFormat::I16 => {
self.create_stream_prerendered::<i16>(device, supported_config, duration_secs)
}
- #[cfg(target_os = "windows")]
SampleFormat::I32 => {
self.create_stream_prerendered::<i32>(device, supported_config, duration_secs)
}
- #[cfg(target_os = "windows")]
SampleFormat::F32 => {
self.create_stream_prerendered::<f32>(device, supported_config, duration_secs)
}
- #[cfg(target_os = "windows")]
SampleFormat::I64 => {
self.create_stream_prerendered::<i64>(device, supported_config, duration_secs)
}
- #[cfg(target_os = "windows")]
SampleFormat::U8 => {
self.create_stream_prerendered::<u8>(device, supported_config, duration_secs)
}
- #[cfg(target_os = "windows")]
SampleFormat::F64 => {
self.create_stream_prerendered::<f64>(device, supported_config, duration_secs)
}
- #[cfg(not(target_os = "windows"))]
- SampleFormat::I16 => self.create_stream::<i16>(device, supported_config),
- #[cfg(not(target_os = "windows"))]
- SampleFormat::I32 => self.create_stream::<i32>(device, supported_config),
- #[cfg(not(target_os = "windows"))]
- SampleFormat::F32 => self.create_stream::<f32>(device, supported_config),
- #[cfg(not(target_os = "windows"))]
- SampleFormat::I64 => self.create_stream::<i64>(device, supported_config),
- #[cfg(not(target_os = "windows"))]
- SampleFormat::U8 => self.create_stream::<u8>(device, supported_config),
- #[cfg(not(target_os = "windows"))]
- SampleFormat::F64 => self.create_stream::<f64>(device, supported_config),
format => {
error!(
"Unsupported sample format {:?} for simplified volume adjustment, skipping audio playback.",
@@ -803,6 +782,7 @@ impl AudioPlayback {
}
#[cfg(not(target_os = "windows"))]
+ #[allow(dead_code)]
fn create_stream<T>(
self,
device: cpal::Device,
@@ -1094,7 +1074,6 @@ impl AudioPlayback {
}))
}
- #[cfg(target_os = "windows")]
fn create_stream_prerendered<T>(
self,
device: cpal::Device,
@@ -1128,7 +1107,7 @@ impl AudioPlayback {
duration_secs = duration_secs,
start_playhead = playhead,
sample_rate = sample_rate,
- "Creating pre-rendered audio stream for Windows"
+ "Creating pre-rendered audio stream"
);
let project_snapshot = project.borrow().clone();