4
0

threeoscrender.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // Renders a 3x Osc state with LYNX's engine exactly like our round-47 reference model drives it (verification harness,
  2. // REA_rodada47): threeoscrender <state.bin> <out.f32> <length> <rate> [blk=N] [maxpoly=N] [tick=N] [ppq=N] [tempo=X]
  3. // [seed=N] [custom=wave.f32 | wav=file.wav] [note=start,key,finalVol,finalPan,pitchOffset,release ...]. The state is
  4. // normalised first (version 14, its own snapshot). Writes interleaved stereo float32.
  5. #include <cstdio>
  6. #include <cstdlib>
  7. #include <fstream>
  8. #include <iterator>
  9. #include <string>
  10. #include <vector>
  11. #include "core/ThreeOsc.h"
  12. int main (int argc, char** argv)
  13. {
  14. if (argc < 5)
  15. {
  16. std::fprintf (stderr, "usage: threeoscrender state.bin out.f32 length rate [blk=N] [maxpoly=N] [tick=N] [ppq=N] [tempo=X] [seed=N] "
  17. "[custom=wave.f32|wav=file.wav] [note=s,k,fv,fp,po,off ...]\n");
  18. return 2;
  19. }
  20. std::ifstream in (argv[1], std::ios::binary);
  21. const std::vector<std::uint8_t> raw ((std::istreambuf_iterator<char> (in)), std::istreambuf_iterator<char>());
  22. const auto state = lynx::threeOscNormalisedState (raw, {});
  23. const int length = std::atoi (argv[3]);
  24. const double rate = std::atof (argv[4]);
  25. lynx::threeosc::RefOptions opt;
  26. std::vector<lynx::threeosc::RefNote> notes;
  27. std::vector<float> custom;
  28. for (int i = 5; i < argc; ++i)
  29. {
  30. const std::string a = argv[i];
  31. if (a.rfind ("blk=", 0) == 0)
  32. opt.block = std::atoi (a.c_str() + 4);
  33. else if (a.rfind ("maxpoly=", 0) == 0)
  34. opt.maxPoly = std::atoi (a.c_str() + 8);
  35. else if (a.rfind ("tick=", 0) == 0)
  36. opt.tick = std::atoi (a.c_str() + 5);
  37. else if (a.rfind ("ppq=", 0) == 0)
  38. opt.ppq = std::atoi (a.c_str() + 4);
  39. else if (a.rfind ("tempo=", 0) == 0)
  40. opt.tempo = std::atof (a.c_str() + 6);
  41. else if (a.rfind ("seed=", 0) == 0)
  42. opt.seed = (std::uint32_t) std::strtoul (a.c_str() + 5, nullptr, 10);
  43. else if (a.rfind ("custom=", 0) == 0)
  44. {
  45. std::ifstream w (a.substr (7), std::ios::binary);
  46. custom.assign (16384, 0.0f);
  47. w.read (reinterpret_cast<char*> (custom.data()), 16384 * 4);
  48. }
  49. else if (a.rfind ("wav=", 0) == 0)
  50. custom = lynx::threeOscCustomWave (a.substr (4));
  51. else if (a.rfind ("note=", 0) == 0)
  52. {
  53. lynx::threeosc::RefNote n;
  54. if (std::sscanf (a.c_str() + 5, "%d,%d,%lf,%lf,%lf,%d", &n.start, &n.key, &n.finalVol, &n.finalPan, &n.pitchOffset, &n.release) >= 5)
  55. notes.push_back (n);
  56. }
  57. }
  58. const auto out = lynx::threeosc::renderReference (state, notes, rate, length, opt, custom);
  59. if (out.empty())
  60. {
  61. std::fprintf (stderr, "state not usable\n");
  62. return 1;
  63. }
  64. std::FILE* f = std::fopen (argv[2], "wb");
  65. if (f == nullptr)
  66. return 1;
  67. std::fwrite (out.data(), sizeof (float), out.size(), f);
  68. std::fclose (f);
  69. return 0;
  70. }