From: Steinar H. Gunderson Date: Sun, 1 Nov 2015 14:35:28 +0000 (+0100) Subject: Move the audio conversion to a slightly more logical place, and also make it handle... X-Git-Tag: 1.0.0~187 X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=385234c0b9c487b77b08504097132f31287e12a0;p=nageru Move the audio conversion to a slightly more logical place, and also make it handle no audio without crashing. --- 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);