]> git.sesse.net Git - nageru/blobdiff - mixer.cpp
Move the audio conversion to a slightly more logical place, and also make it handle...
[nageru] / mixer.cpp
index e85710c25c519bfbd261c6ab6cf81cb2014f4796..2e3436884c515e82f3a56b153d3c8239bf46fa0e 100644 (file)
--- a/mixer.cpp
+++ b/mixer.cpp
@@ -80,6 +80,10 @@ Mixer::Mixer(const QSurfaceFormat &format)
        CHECK(init_movit(MOVIT_SHADER_DIR, MOVIT_DEBUG_OFF));
        check_error();
 
+       // Since we allow non-bouncing 4:2:2 YCbCrInputs, effective subpixel precision
+       // will be halved when sampling them, and we need to compensate here.
+       movit_texel_subpixel_precision /= 2.0;
+
        resource_pool.reset(new ResourcePool);
        theme.reset(new Theme("theme.lua", resource_pool.get()));
        output_channel[OUTPUT_LIVE].parent = this;
@@ -223,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) {
@@ -237,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);