]> git.sesse.net Git - nageru/commitdiff
Move the audio conversion to a slightly more logical place, and also make it handle...
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 1 Nov 2015 14:35:28 +0000 (15:35 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 1 Nov 2015 14:35:28 +0000 (15:35 +0100)
mixer.cpp

index 0f8cf903d326d87fc41b00ec65b07afa6ce1c8b7..2e3436884c515e82f3a56b153d3c8239bf46fa0e 100644 (file)
--- 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<float> 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<float> 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<mutex> lock(card->audio_mutex);