PerfGate190idTests.inc 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. // Round perfgate190id (community slice B12): the big-project performance gate's synthetic projects
  2. // (core/PerfProjects.h). The gate compares measurements across builds, so the projects must be what they promise and
  3. // the same bit for bit every time they are made; and they must play (a project that renders silence measures nothing).
  4. namespace pg190id
  5. {
  6. using namespace lynx;
  7. int clipsOf (const Song& song, ClipKind kind)
  8. {
  9. return (int) std::count_if (song.playlist.begin(), song.playlist.end(), [kind] (const Clip& c) { return c.kind == kind; });
  10. }
  11. // `seconds` of the song from its start, as tools/perfbench renders it (the export song, live quality, one thread)
  12. std::vector<float> render (const Song& song, const perfprojects::Samples& samples, double seconds, int block)
  13. {
  14. std::int64_t ticks = 0;
  15. const auto exportSong = makeExportSong (song, true, 0, ticks);
  16. auto provider = [&samples] (const std::string& p) {
  17. const auto it = samples.find (p);
  18. return it != samples.end() ? it->second : std::shared_ptr<const SampleData> {};
  19. };
  20. auto state = RackState::build (exportSong, nullptr, 44100.0, provider);
  21. RackRenderer renderer;
  22. renderer.prepare (44100.0, 2048);
  23. LiveEventQueue live, midiLive;
  24. const auto total = (int) (seconds * 44100.0) / block * block;
  25. std::vector<float> out ((std::size_t) total * 2);
  26. std::vector<float> l ((std::size_t) block), r ((std::size_t) block);
  27. const auto tps = ticksPerSample (exportSong.bpm, 44100.0);
  28. for (int pos = 0; pos < total; pos += block)
  29. {
  30. renderer.process (state.get(), true, pos * tps, block, l.data(), r.data(), &live, nullptr, &midiLive);
  31. for (int i = 0; i < block; ++i)
  32. out[(std::size_t) (pos + i) * 2] = l[(std::size_t) i], out[(std::size_t) (pos + i) * 2 + 1] = r[(std::size_t) i];
  33. }
  34. return out;
  35. }
  36. } // namespace pg190id
  37. TEST (perfgate_projects_have_the_promised_size)
  38. {
  39. using namespace lynx;
  40. perfprojects::Samples samples;
  41. const auto big = perfprojects::big200 (samples);
  42. CHECK (big.channels.size() == 200);
  43. CHECK (big.mixer.size() == 121); // Master + 120 inserts
  44. CHECK (pg190id::clipsOf (big, ClipKind::pattern) + pg190id::clipsOf (big, ClipKind::audio) == 2000);
  45. CHECK (pg190id::clipsOf (big, ClipKind::automation) == 200);
  46. CHECK (big.automations.size() == 200);
  47. int lynxEffects = 0;
  48. for (const auto& m : big.mixer)
  49. lynxEffects += (int) m.effects.size();
  50. CHECK (lynxEffects == 100 * 2 + 25 + 20 * 3 + 2);
  51. CHECK (samples.size() == 8 + 40); // the samplers' one-shots and the audio channels' loops
  52. const auto automation = perfprojects::automation();
  53. CHECK (automation.automations.size() == 401);
  54. CHECK (pg190id::clipsOf (automation, ClipKind::automation) == 401);
  55. CHECK (automation.automations[0].points.size() == 257); // a point every 16th over 16 bars
  56. perfprojects::Samples streamSamples;
  57. const auto stream = perfprojects::stream (60, streamSamples);
  58. CHECK (stream.channels.size() == 24 && streamSamples.size() == 24);
  59. CHECK (streamSamples.begin()->second->frames() == 60 * 44100);
  60. for (const auto& name : perfprojects::names())
  61. {
  62. Song song;
  63. perfprojects::Samples s;
  64. CHECK (perfprojects::make (name, song, s));
  65. }
  66. Song none;
  67. perfprojects::Samples s;
  68. CHECK (! perfprojects::make ("nothing", none, s));
  69. }
  70. TEST (perfgate_projects_are_the_same_every_time_and_play)
  71. {
  72. using namespace lynx;
  73. for (const auto* name : { "big200", "automation" })
  74. {
  75. Song a, b;
  76. perfprojects::Samples sa, sb;
  77. perfprojects::make (name, a, sa);
  78. perfprojects::make (name, b, sb);
  79. CHECK (a.automations == b.automations);
  80. CHECK (a.playlist.size() == b.playlist.size());
  81. bool sameClips = true;
  82. for (std::size_t i = 0; i < a.playlist.size() && i < b.playlist.size(); ++i)
  83. sameClips = sameClips && a.playlist[i].start == b.playlist[i].start && a.playlist[i].length == b.playlist[i].length
  84. && a.playlist[i].track == b.playlist[i].track && a.playlist[i].kind == b.playlist[i].kind;
  85. CHECK (sameClips);
  86. bool sameMixer = a.mixer.size() == b.mixer.size();
  87. for (std::size_t t = 0; sameMixer && t < a.mixer.size(); ++t)
  88. sameMixer = a.mixer[t].effects == b.mixer[t].effects;
  89. CHECK (sameMixer);
  90. bool sameAudio = sa.size() == sb.size();
  91. for (auto i = sa.begin(), j = sb.begin(); sameAudio && i != sa.end(); ++i, ++j)
  92. sameAudio = i->first == j->first && i->second->left == j->second->left && i->second->right == j->second->right;
  93. CHECK (sameAudio);
  94. const auto x = pg190id::render (a, sa, 0.5, 256), y = pg190id::render (b, sb, 0.5, 256);
  95. CHECK (x == y);
  96. float peak = 0.0f;
  97. bool finite = true;
  98. for (const auto v : x)
  99. peak = std::max (peak, std::abs (v)), finite = finite && std::isfinite (v);
  100. CHECK (finite);
  101. CHECK (peak > 1.0e-3f);
  102. }
  103. }
  104. TEST (perfgate_tempo_scan_reads_only_the_tempo_clips_and_gives_the_same_tempo)
  105. {
  106. // the shifter plan scans the song's tempo every 16th; it now reads only the clips tempoAt can use
  107. // (tempomap::tempoClips): the same tempo everywhere, with automation clips (two overlapping, one muted) and pattern
  108. // Tempo events
  109. using namespace lynx;
  110. auto song = perfprojects::automation(); // (400 automation clips of other targets + one tempo clip)
  111. AutomationTarget tempo;
  112. tempo.kind = AutomationTargetKind::tempo;
  113. const auto second = perfprojects::addAutomation (song, tempo, "Tempo 2", perfprojects::wavePoints (32.0, 0.5, valueFromTempo (118.0), valueFromTempo (140.0), 3));
  114. perfprojects::addAutomationClip (song, second, 38, 8 * 4 * ppq, 8 * 4 * ppq);
  115. perfprojects::addAutomationClip (song, second, 37, 20 * 4 * ppq, 4 * 4 * ppq);
  116. song.playlist.back().muted = true;
  117. PatternEvents lane;
  118. lane.target.kind = AutomationTargetKind::tempo;
  119. lane.events.push_back ({ 0, valueFromTempo (131.0) });
  120. lane.events.push_back ({ 2 * ppq, valueFromTempo (127.0) });
  121. song.patterns[3].events.push_back (lane);
  122. const auto clips = tempomap::tempoClips (song);
  123. CHECK (clips.size() < song.playlist.size() / 4);
  124. bool same = true;
  125. for (double t = 0.0; t <= (double) song.songLength() + ppq; t += ppq / 16.0)
  126. same = same && tempomap::tempoAt (song, t) == tempomap::tempoAtIn (song, clips, t);
  127. CHECK (same);
  128. CHECK (tempomap::active (song));
  129. }
  130. TEST (render_ahead_probe_keeps_four_times_fewer_overruns_for_up_to_five_percent_more_cpu)
  131. {
  132. // owner decision 0.1.30 (round perfgate190id): with 4x fewer overruns or better, up to +5 % CPU keeps render-ahead
  133. // on; the 0.1.28 rule (fewer overruns at up to +2 %) and the CPU-win rule stay as they were
  134. using namespace lynx;
  135. const auto v = [] (double cpuOff, double cpuOn, double overOff, double overOn) {
  136. return RenderAhead::probeVerdict (cpuOff, cpuOn, overOff / 60.0, overOn / 60.0); // (per minute -> per second)
  137. };
  138. // the loaded-machine probes of round perfgate190id: synth100 at 64, 20x fewer at +2.5 % (kept off before)
  139. CHECK (v (2.089, 2.141, 29438.0, 1429.0).keep);
  140. CHECK (v (2.089, 2.141, 29438.0, 1429.0).forOverruns);
  141. // ... and Exoplanet at 64, 10x fewer at +12.8 %: still off
  142. CHECK (! v (1.048, 1.182, 14724.0, 1419.0).keep);
  143. // the edges: exactly 4x and +5 % on; just past either off
  144. CHECK (v (1.0, 1.05, 400.0, 100.0).keep);
  145. CHECK (! v (1.0, 1.0501, 400.0, 100.0).keep);
  146. CHECK (! v (1.0, 1.04, 400.0, 101.0).keep);
  147. // the 0.1.28 rule: 20 % fewer (here 3x) at up to +2 %
  148. CHECK (v (1.0, 1.02, 300.0, 100.0).keep);
  149. CHECK (! v (1.0, 1.03, 300.0, 100.0).keep);
  150. // a CPU win with no more overruns: kept, not "for overruns"
  151. CHECK (v (1.0, 0.85, 100.0, 100.0).keep);
  152. CHECK (! v (1.0, 0.85, 100.0, 100.0).forOverruns);
  153. CHECK (! v (1.0, 0.85, 100.0, 120.0).keep); // (more overruns)
  154. // no overruns with it off: only a CPU win can keep it
  155. CHECK (! v (1.0, 1.0, 0.0, 0.0).keep);
  156. CHECK (v (1.0, 0.8, 0.0, 0.0).keep);
  157. }