poizonerender.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // Renders a PoiZone state with LYNX's engine exactly like our round-44 reference model drives it (verification harness,
  2. // REA_rodada44 §7): poizonerender <state.bin> <out.f32> <length> <rate> [blk=N] [bpm=X] [maxpoly=N] [panlaw]
  3. // [note=start,key,initVol,finalVol,finalPan,pitchCents,release ...]. Writes interleaved stereo float32.
  4. #include <cstdio>
  5. #include <cstdlib>
  6. #include <fstream>
  7. #include <iterator>
  8. #include <string>
  9. #include <vector>
  10. #include "core/PoiZone.h"
  11. int main (int argc, char** argv)
  12. {
  13. if (argc < 5)
  14. {
  15. std::fprintf (stderr, "usage: poizonerender state.bin out.f32 length rate [blk=N] [bpm=X] [maxpoly=N] [panlaw] [note=s,k,iv,fv,fp,pc,off ...]\n");
  16. return 2;
  17. }
  18. std::ifstream in (argv[1], std::ios::binary);
  19. const std::vector<std::uint8_t> state ((std::istreambuf_iterator<char> (in)), std::istreambuf_iterator<char>());
  20. const int length = std::atoi (argv[3]);
  21. const double rate = std::atof (argv[4]);
  22. int blk = 512, maxPoly = 0;
  23. double bpm = 120.0;
  24. bool panLaw = false;
  25. std::vector<lynx::poizone::RefNote> notes;
  26. for (int i = 5; i < argc; ++i)
  27. {
  28. const std::string a = argv[i];
  29. if (a.rfind ("blk=", 0) == 0)
  30. blk = std::atoi (a.c_str() + 4);
  31. else if (a.rfind ("bpm=", 0) == 0)
  32. bpm = std::atof (a.c_str() + 4);
  33. else if (a.rfind ("maxpoly=", 0) == 0)
  34. maxPoly = std::atoi (a.c_str() + 8);
  35. else if (a == "panlaw")
  36. panLaw = true;
  37. else if (a.rfind ("note=", 0) == 0)
  38. {
  39. lynx::poizone::RefNote n;
  40. if (std::sscanf (a.c_str() + 5, "%d,%d,%lf,%lf,%lf,%lf,%d", &n.start, &n.key, &n.initVol, &n.finalVol, &n.finalPan, &n.pitchCents,
  41. &n.release)
  42. >= 6)
  43. notes.push_back (n);
  44. }
  45. }
  46. const auto out = lynx::poizone::renderReference (state, notes, rate, length, blk, bpm, maxPoly, panLaw);
  47. if (out.empty())
  48. {
  49. std::fprintf (stderr, "state not usable\n");
  50. return 1;
  51. }
  52. std::FILE* f = std::fopen (argv[2], "wb");
  53. if (f == nullptr)
  54. return 1;
  55. std::fwrite (out.data(), sizeof (float), out.size(), f);
  56. std::fclose (f);
  57. return 0;
  58. }