4
0

oggdecode.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // oggdecode: decodes Ogg-in-WAV / Ogg Vorbis files as FL Studio does (src/core/OggVorbis.h) and prints, per file,
  2. // the FNV-1a 64 hash of the planar float32 samples, the frame count, the channels and the sample rate.
  3. // Usage: oggdecode [-o out.f32] file... (-o writes the first file's planar float32 samples)
  4. #include <cstdint>
  5. #include <cstdio>
  6. #include <cstring>
  7. #include <fstream>
  8. #include <iterator>
  9. #include <string>
  10. #include <vector>
  11. #include "core/OggVorbis.h"
  12. int main (int argc, char** argv)
  13. {
  14. std::string outPath;
  15. int first = 1;
  16. if (argc > 2 && std::strcmp (argv[1], "-o") == 0)
  17. outPath = argv[2], first = 3;
  18. for (int a = first; a < argc; ++a)
  19. {
  20. std::ifstream in (argv[a], std::ios::binary);
  21. const std::vector<std::uint8_t> bytes { std::istreambuf_iterator<char> (in), {} };
  22. lynx::oggvorbis::Decoded d;
  23. if (! lynx::oggvorbis::decode (bytes.data(), bytes.size(), d))
  24. {
  25. std::printf ("FAIL | %s\n", argv[a]);
  26. continue;
  27. }
  28. std::uint64_t h = 1469598103934665603ULL;
  29. for (const auto& ch : d.data)
  30. {
  31. const auto* p = reinterpret_cast<const std::uint8_t*> (ch.data());
  32. for (std::size_t i = 0; i < ch.size() * sizeof (float); ++i)
  33. h = (h ^ p[i]) * 1099511628211ULL;
  34. }
  35. std::printf ("H %016llx %zu %d %d | %s\n", (unsigned long long) h, d.data[0].size(), d.channels, d.sampleRate, argv[a]);
  36. if (! outPath.empty() && a == first)
  37. {
  38. std::ofstream out (outPath, std::ios::binary);
  39. for (const auto& ch : d.data)
  40. out.write (reinterpret_cast<const char*> (ch.data()), (std::streamsize) (ch.size() * sizeof (float)));
  41. }
  42. }
  43. return 0;
  44. }