+ mixer->set_input_mapping(mapping);
+}
+
+void do_test(const char *filename)
+{
+ AudioMixer mixer(NUM_BENCHMARK_CARDS);
+ mixer.set_audio_level_callback(callback);
+ init_mapping(&mixer);
+
+ reset_lcgrand();
+
+ vector<float> output;
+ for (unsigned i = 0; i < NUM_TEST_FRAMES; ++i) {
+ vector<float> frame_output = process_frame(i, &mixer);
+ output.insert(output.end(), frame_output.begin(), frame_output.end());
+ }
+
+ FILE *fp = fopen(filename, "rb");
+ if (fp == nullptr) {
+ fprintf(stderr, "%s not found, writing new reference.\n", filename);
+ fp = fopen(filename, "wb");
+ fwrite(&output[0], output.size() * sizeof(float), 1, fp);
+ fclose(fp);
+ return;
+ }
+
+ vector<float> ref;
+ ref.resize(output.size());
+ fread(&ref[0], output.size() * sizeof(float), 1, fp);
+ fclose(fp);
+
+ float max_err = 0.0f, sum_sq_err = 0.0f;
+ for (unsigned i = 0; i < output.size(); ++i) {
+ float err = output[i] - ref[i];
+ max_err = max(max_err, fabs(err));
+ sum_sq_err += err * err;
+ }
+
+ printf("Largest error: %.6f (%+.1f dB)\n", max_err, to_db(max_err));
+ printf("RMS error: %+.1f dB\n", to_db(sqrt(sum_sq_err) / output.size()));
+}
+
+void do_benchmark()
+{
+ AudioMixer mixer(NUM_BENCHMARK_CARDS);
+ mixer.set_audio_level_callback(callback);
+ init_mapping(&mixer);