fdelayrender.cpp 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // Renders FL's Fruity Delay 2 / Fruity Delay 3 engines (core/FruityDelay) on a raw stereo float file, for comparing
  2. // with the plugins (REA_rodada52). The Delay 3 set-up follows FL's wrapper: state, then the sample rate twice.
  3. // usage: fdelayrender d2|d3 <state.bin> <in.f32> <out.f32> <sampleRate> <bpm> <block> [settle]
  4. #include "core/FruityDelay.h"
  5. #include <algorithm>
  6. #include <cstdio>
  7. #include <cstdlib>
  8. #include <cstring>
  9. #include <vector>
  10. using namespace lynx::fldelay;
  11. static std::vector<std::uint8_t> readAll (const char* path)
  12. {
  13. std::vector<std::uint8_t> v;
  14. if (auto* f = std::fopen (path, "rb"))
  15. {
  16. std::uint8_t b[65536];
  17. std::size_t n;
  18. while ((n = std::fread (b, 1, sizeof b, f)) > 0)
  19. v.insert (v.end(), b, b + n);
  20. std::fclose (f);
  21. }
  22. return v;
  23. }
  24. int main (int argc, char** argv)
  25. {
  26. if (argc < 8)
  27. {
  28. std::fprintf (stderr, "usage: fdelayrender d2|d3 state.bin in.f32 out.f32 sampleRate bpm block [settle]\n");
  29. return 2;
  30. }
  31. const auto state = readAll (argv[2]);
  32. const auto in = readAll (argv[3]);
  33. const double rate = std::atof (argv[5]), bpm = std::atof (argv[6]);
  34. const int block = std::max (1, std::atoi (argv[7]));
  35. const bool settle = argc > 8 && std::strcmp (argv[8], "settle") == 0;
  36. const std::size_t n = in.size() / 8;
  37. std::vector<float> l (n), r (n);
  38. for (std::size_t i = 0; i < n; ++i)
  39. {
  40. std::memcpy (&l[i], &in[8 * i], 4);
  41. std::memcpy (&r[i], &in[8 * i + 4], 4);
  42. }
  43. if (std::strcmp (argv[1], "d3") == 0)
  44. {
  45. const auto s = parseDelay3 (state);
  46. if (! s)
  47. return 3;
  48. Delay3Engine e (rate);
  49. e.setTempo (bpm);
  50. for (int i = 0; i < delay3Controls; ++i)
  51. e.setParameter (i, delay3EngineValue (i, s->v[(std::size_t) i]));
  52. e.setSampleRate (rate);
  53. e.setSampleRate (rate);
  54. if (settle)
  55. e.settle();
  56. for (std::size_t s0 = 0; s0 < n; s0 += (std::size_t) block)
  57. e.process (&l[s0], &r[s0], (int) std::min ((std::size_t) block, n - s0));
  58. }
  59. else
  60. {
  61. const auto s = parseDelay2 (state);
  62. if (! s)
  63. return 3;
  64. Delay2Engine e (*s, rate, bpm, block, settle);
  65. for (std::size_t s0 = 0; s0 < n; s0 += (std::size_t) block)
  66. e.process (&l[s0], &r[s0], (int) std::min ((std::size_t) block, n - s0));
  67. }
  68. if (auto* f = std::fopen (argv[4], "wb"))
  69. {
  70. for (std::size_t i = 0; i < n; ++i)
  71. {
  72. std::fwrite (&l[i], 4, 1, f);
  73. std::fwrite (&r[i], 4, 1, f);
  74. }
  75. std::fclose (f);
  76. }
  77. return 0;
  78. }