4
0

simsynthrender.cpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // Renders a SimSynth state with LYNX's engine exactly like the round-64 EXEC harness drives the DLL (verification
  2. // harness, REA_rodada64 §7): simsynthrender <state.bin> <out.f32> <length> <rate> [blk=N]
  3. // [note=start,key,finalVol,finalPan(int −64…64),pitchCents(int),release[,fcut,fres] ...]. Writes interleaved stereo float32 and prints
  4. // the random-table index after the set-up.
  5. #include <cstdio>
  6. #include <cstdlib>
  7. #include <fstream>
  8. #include <iterator>
  9. #include <string>
  10. #include <vector>
  11. #include "core/SimSynth.h"
  12. int main (int argc, char** argv)
  13. {
  14. if (argc < 5)
  15. {
  16. std::fprintf (stderr, "usage: simsynthrender state.bin out.f32 length rate [blk=N] [note=s,k,fv,fp,pc,off[,fcut,fres] ...]\n");
  17. return 2;
  18. }
  19. std::ifstream in (argv[1], std::ios::binary);
  20. const std::vector<std::uint8_t> state ((std::istreambuf_iterator<char> (in)), std::istreambuf_iterator<char>());
  21. const int length = std::atoi (argv[3]);
  22. const double rate = std::atof (argv[4]);
  23. int blk = 512;
  24. std::vector<lynx::simsynth::RefNote> notes;
  25. for (int i = 5; i < argc; ++i)
  26. {
  27. const std::string a = argv[i];
  28. if (a.rfind ("blk=", 0) == 0)
  29. blk = std::atoi (a.c_str() + 4);
  30. else if (a.rfind ("note=", 0) == 0)
  31. {
  32. lynx::simsynth::RefNote n;
  33. if (std::sscanf (a.c_str() + 5, "%d,%d,%f,%d,%d,%d,%f,%f", &n.start, &n.key, &n.finalVol, &n.finalPan, &n.pitchCents,
  34. &n.release, &n.fcut, &n.fres)
  35. >= 6)
  36. notes.push_back (n);
  37. }
  38. }
  39. std::vector<std::int64_t> counters;
  40. const auto out = lynx::simsynth::renderReference (state, notes, rate, length, blk, &counters);
  41. if (out.empty())
  42. {
  43. std::fprintf (stderr, "state not usable\n");
  44. return 1;
  45. }
  46. std::printf ("ridx %lld chorus %lld created %lld loaded %lld\n", (long long) counters[0], (long long) counters[1], (long long) counters[2], (long long) counters[3]);
  47. std::FILE* f = std::fopen (argv[2], "wb");
  48. if (f == nullptr)
  49. return 1;
  50. std::fwrite (out.data(), sizeof (float), out.size(), f);
  51. std::fclose (f);
  52. return 0;
  53. }