FixedBlockTests118.inc 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // --- FL's "Use fixed size buffers" for hosted plugins (core/FixedBlock.h) - REA round 118 Part B ---
  2. TEST (fixed_block_calls_the_plugin_with_whole_blocks_only)
  3. {
  4. lynx::FixedBlock fixed (64, 2);
  5. std::vector<int> sizes;
  6. std::vector<float> l (1000), r (1000);
  7. for (int i = 0; i < 1000; ++i)
  8. l[(std::size_t) i] = (float) (i + 1), r[(std::size_t) i] = -(float) (i + 1);
  9. // the host's chunks: variable, some of one sample (LYNX splits at every event)
  10. const int chunks[] = { 1, 7, 64, 3, 200, 1, 1, 90, 633 };
  11. int at = 0;
  12. for (const auto n : chunks)
  13. {
  14. float* io[2] = { l.data() + at, r.data() + at };
  15. fixed.run (io, n, true, [&] (float* const* ch, int count) {
  16. sizes.push_back (count);
  17. for (int i = 0; i < count; ++i)
  18. ch[0][i] *= 2.0f, ch[1][i] *= 2.0f; // a "plugin": +6 dB
  19. });
  20. at += n;
  21. }
  22. CHECK (at == 1000);
  23. CHECK (sizes.size() == 1000 / 64);
  24. CHECK (std::all_of (sizes.begin(), sizes.end(), [] (int s) { return s == 64; }));
  25. CHECK (fixed.latency() == 64);
  26. // output = processed input delayed by exactly one block; silence before it
  27. auto exact = true;
  28. for (int i = 0; i < 1000; ++i)
  29. {
  30. const auto want = i < 64 ? 0.0f : 2.0f * (float) (i - 64 + 1);
  31. exact = exact && l[(std::size_t) i] == want && r[(std::size_t) i] == -want;
  32. }
  33. CHECK (exact);
  34. CHECK (fixed.position() == 1000 % 64);
  35. }
  36. TEST (fixed_block_instrument_mode_and_positions)
  37. {
  38. lynx::FixedBlock fixed (32, 2);
  39. std::vector<float> l (100, 5.0f), r (100, 5.0f);
  40. int calls = 0;
  41. std::vector<int> positions;
  42. for (int at = 0; at < 100; at += 10)
  43. {
  44. positions.push_back (fixed.position()); // where a MIDI event arriving now lands in the block
  45. float* io[2] = { l.data() + at, r.data() + at };
  46. fixed.run (io, 10, false, [&] (float* const* ch, int count) {
  47. ++calls;
  48. auto silent = true;
  49. for (int i = 0; i < count; ++i)
  50. silent = silent && ch[0][i] == 0.0f && ch[1][i] == 0.0f; // no input for instruments
  51. CHECK (silent);
  52. ch[0][0] = 1.0f; // an "instrument": one click at the start of each block
  53. });
  54. }
  55. CHECK (calls == 3);
  56. CHECK ((positions == std::vector<int> { 0, 10, 20, 30 % 32, 40 % 32, 50 % 32, 60 % 32, 70 % 32, 80 % 32, 90 % 32 }));
  57. // clicks come out one block later: samples 32, 64, 96
  58. CHECK (l[31] == 0.0f && l[32] == 1.0f && l[33] == 0.0f && l[64] == 1.0f && l[96] == 1.0f && l[0] == 0.0f);
  59. CHECK (r[32] == 0.0f);
  60. fixed.clear();
  61. CHECK (fixed.position() == 0);
  62. }
  63. TEST (underrun_count_prefers_the_driver)
  64. {
  65. CHECK (lynx::RtStats::underrunCount (3, 2, -1) == 5); // no driver count: LYNX's own estimate
  66. CHECK (lynx::RtStats::underrunCount (3, 2, 0) == 0); // the driver says none
  67. CHECK (lynx::RtStats::underrunCount (0, 0, 7) == 7);
  68. }