Skip to content

Commit

Permalink
Refactor audio frame handling in Recorder to improve performance and …
Browse files Browse the repository at this point in the history
…clarity
  • Loading branch information
Guy Chronister committed Dec 19, 2024
1 parent 086c092 commit 3239efc
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions neothesia-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ impl Recorder {
// Render audio for this frame (1/60th of a second)
let samples_per_frame = (44100.0 * (1.0/60.0)) as usize;
let mut frame_audio = vec![0.0f32; samples_per_frame * 2]; // Stereo
synth.write(&mut frame_audio).unwrap_or(0);
synth.write(&mut frame_audio[..]).ok(); // Pass slice instead of Vec
self.audio_buffer.extend_from_slice(&frame_audio);
}

Expand Down Expand Up @@ -355,7 +355,7 @@ fn main() {
"./out/video.mp4",
recorder.width as usize,
recorder.height as usize,
Some(44100), // Set audio sample rate
Some(44100.0), // Use f32 for sample rate
Some("medium"),
);

Expand Down Expand Up @@ -389,11 +389,11 @@ fn main() {
} else {
&[]
};
encoder.encode_bgra_with_audio(1920, 1080, &mapping, audio_frame, false);
encoder.encode_frame(1920, 1080, &mapping, Some(audio_frame), false);
}

#[cfg(not(feature = "fluid-synth"))]
encoder.encode_bgra(1920, 1080, &mapping, false);
encoder.encode_frame(1920, 1080, &mapping, None, false);

print!(
"\r Encoded {} frames ({}s, {}%) in {}s",
Expand Down

0 comments on commit 3239efc

Please sign in to comment.