dx10render.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // Renders a Fruity DX10 state with LYNX's engine exactly like our round-42 reference model drives it (verification
  2. // harness, REA_rodada42): dx10render <state.bin> <out.f32> <length> <rate> [blk=N] [maxpoly=N] [tick=N] [ppq=N] [tempo=X]
  3. // [note=start,key,initVol,finalVol,finalPan,pitchOffset,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/Dx10.h"
  11. int main (int argc, char** argv)
  12. {
  13. if (argc < 5)
  14. {
  15. std::fprintf (stderr, "usage: dx10render state.bin out.f32 length rate [blk=N] [maxpoly=N] [tick=N] [ppq=N] [tempo=X] [note=s,k,iv,fv,fp,po,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. lynx::dx10::RefOptions opt;
  23. std::vector<lynx::dx10::RefNote> notes;
  24. for (int i = 5; i < argc; ++i)
  25. {
  26. const std::string a = argv[i];
  27. if (a.rfind ("blk=", 0) == 0)
  28. opt.block = std::atoi (a.c_str() + 4);
  29. else if (a.rfind ("maxpoly=", 0) == 0)
  30. opt.maxPoly = std::atoi (a.c_str() + 8);
  31. else if (a.rfind ("tick=", 0) == 0)
  32. opt.tick = std::atoi (a.c_str() + 5);
  33. else if (a.rfind ("ppq=", 0) == 0)
  34. opt.ppq = std::atoi (a.c_str() + 4);
  35. else if (a.rfind ("tempo=", 0) == 0)
  36. opt.tempo = std::atof (a.c_str() + 6);
  37. else if (a.rfind ("note=", 0) == 0)
  38. {
  39. lynx::dx10::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.pitchOffset,
  41. &n.release)
  42. >= 6)
  43. notes.push_back (n);
  44. }
  45. }
  46. const auto out = lynx::dx10::renderReference (state, notes, rate, length, opt);
  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. }