X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=mixer.cpp;h=2e3436884c515e82f3a56b153d3c8239bf46fa0e;hb=385234c0b9c487b77b08504097132f31287e12a0;hp=0f8cf903d326d87fc41b00ec65b07afa6ce1c8b7;hpb=345b65e8f95fba76164f9ac8e1304138fd984b3d;p=nageru 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);