From 385234c0b9c487b77b08504097132f31287e12a0 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Sun, 1 Nov 2015 15:35:28 +0100 Subject: [PATCH] Move the audio conversion to a slightly more logical place, and also make it handle no audio without crashing. --- mixer.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/mixer.cpp b/mixer.cpp index 0f8cf90..2e34368 100644 --- a/mixer.cpp +++ b/mixer.cpp @@ -227,12 +227,6 @@ void Mixer::bm_frame(int card_index, uint16_t timecode, return; } - // Convert the audio to stereo fp32 and add it. - size_t num_samples = (audio_frame.len - audio_offset) / 8 / 3; - vector audio; - audio.resize(num_samples * 2); - convert_fixed24_to_fp32(&audio[0], 2, audio_frame.data + audio_offset, 8, num_samples); - int unwrapped_timecode = timecode; int dropped_frames = 0; if (card->last_timecode != -1) { @@ -241,6 +235,12 @@ void Mixer::bm_frame(int card_index, uint16_t timecode, } card->last_timecode = unwrapped_timecode; + // Convert the audio to stereo fp32 and add it. + size_t num_samples = (audio_frame.len >= audio_offset) ? (audio_frame.len - audio_offset) / 8 / 3 : 0; + vector audio; + audio.resize(num_samples * 2); + convert_fixed24_to_fp32(&audio[0], 2, audio_frame.data + audio_offset, 8, num_samples); + // Add the audio. { unique_lock lock(card->audio_mutex); -- 2.39.2