bassdrumrender.cpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // Renders a BassDrum state with LYNX's engine exactly like our round-43 reference model drives it (verification
  2. // harness, REA_rodada43 §2.10): bassdrumrender <state.bin> <out.f32> <length> <rate> <BassDrum folder> [blk=N] [nonoise]
  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/BassDrum.h"
  11. int main (int argc, char** argv)
  12. {
  13. if (argc < 6)
  14. {
  15. std::fprintf (stderr, "usage: bassdrumrender state.bin out.f32 length rate folder [blk=N] [nonoise] [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;
  23. bool noise = true;
  24. std::vector<lynx::bassdrum::RefNote> notes;
  25. for (int i = 6; 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 == "nonoise")
  31. noise = false;
  32. else if (a.rfind ("note=", 0) == 0)
  33. {
  34. lynx::bassdrum::RefNote n;
  35. 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,
  36. &n.release)
  37. >= 6)
  38. notes.push_back (n);
  39. }
  40. }
  41. const auto out = lynx::bassdrum::renderReference (state, notes, rate, length, argv[5], blk, noise);
  42. if (out.empty())
  43. {
  44. std::fprintf (stderr, "state or table not usable\n");
  45. return 1;
  46. }
  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. }