]> 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 8fe4710cbc8e834b4f84f6ca44a67309db7c28a1..3327179c3518e6dc492b794c636d7d24bafde7a7 100644 (file)
@@ -2,12 +2,21 @@
 // with the default settings, feeds some white noise to the inputs and
 // runs a while. Useful for e.g. profiling.
 
-#include <stdio.h>
+#include <assert.h>
+#include <bmusb/bmusb.h>
 #include <stdint.h>
-#include <vector>
+#include <stdio.h>
+#include <algorithm>
 #include <chrono>
+#include <cmath>
+#include <ratio>
+#include <vector>
+
 #include "audio_mixer.h"
 #include "db.h"
+#include "defs.h"
+#include "input_mapping.h"
+#include "resampling_queue.h"
 #include "timebase.h"
 
 #define NUM_BENCHMARK_CARDS 4
@@ -52,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;
@@ -61,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)