]> git.sesse.net Git - nageru/blobdiff - benchmark_audio_mixer.cpp
Fix an issue where the mixer lagging too much behind CEF would cause us to display...
[nageru] / benchmark_audio_mixer.cpp
index 4b8f84a93ef0458dffa25d8806a54564afa2400e..3327179c3518e6dc492b794c636d7d24bafde7a7 100644 (file)
@@ -61,6 +61,10 @@ void callback(float level_lufs, float peak_db,
 
 vector<float> process_frame(unsigned frame_num, AudioMixer *mixer)
 {
+       duration<int64_t, ratio<NUM_SAMPLES, OUTPUT_FREQUENCY>> frame_duration(frame_num);
+       steady_clock::time_point ts = steady_clock::time_point::min() +
+               duration_cast<steady_clock::duration>(frame_duration);
+
        // Feed the inputs.
        for (unsigned card_index = 0; card_index < NUM_BENCHMARK_CARDS; ++card_index) {
                bmusb::AudioFormat audio_format;
@@ -70,12 +74,11 @@ vector<float> process_frame(unsigned frame_num, AudioMixer *mixer)
                unsigned num_samples = NUM_SAMPLES + (lcgrand() % 9) - 5;
                bool ok = mixer->add_audio(DeviceSpec{InputSourceType::CAPTURE_CARD, card_index},
                        card_index == 3 ? samples24 : samples16, num_samples, audio_format,
-                       NUM_SAMPLES * TIMEBASE / OUTPUT_FREQUENCY);
+                       NUM_SAMPLES * TIMEBASE / OUTPUT_FREQUENCY, ts);
                assert(ok);
        }
 
-       double pts = double(frame_num) * NUM_SAMPLES / OUTPUT_FREQUENCY;
-       return mixer->get_output(pts, NUM_SAMPLES, ResamplingQueue::ADJUST_RATE);
+       return mixer->get_output(ts, NUM_SAMPLES, ResamplingQueue::ADJUST_RATE);
 }
 
 void init_mapping(AudioMixer *mixer)