| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- // Reference render of a JSFX script by the upstream ysfx library (pristine JoepVanlier/ysfx 5c3452fe), for LYNX's
- // --selftest (round 190pj). The input and the slider schedule match lynx::jsfx::selfTest's reference part exactly.
- // Build it against a pristine ysfx checkout (not LYNX's copy, so the reference is the library's own output):
- // cmake -S ysfx -B b -DYSFX_PLUGIN=OFF -DYSFX_GFX=OFF && cmake --build b
- // g++ -std=c++17 -O2 -Iysfx/include tools/jsfx_ref.cpp b/libysfx.a -lpthread -ldl -o jsfx_ref
- // ./jsfx_ref resources/jsfx/chokehold/Clipper/soft_clipper.jsfx src/engine/JsfxReference.h
- // usage: jsfx_ref <script.jsfx> <out.h>
- #include <ysfx.h>
- #include <cmath>
- #include <cstdint>
- #include <cstdio>
- #include <cstring>
- #include <vector>
- static void input (std::vector<float>& l, std::vector<float>& r, int frames, std::uint32_t& lcg, long start)
- {
- for (int i = 0; i < frames; ++i)
- {
- const double n = (double) (start + i);
- lcg = lcg * 1664525u + 1013904223u;
- const double noise = (double) (lcg >> 8) / 16777216.0 * 0.2 - 0.1;
- l[i] = (float) (0.6 * std::sin (2.0 * M_PI * 220.0 * n / 48000.0) + 0.3 * std::sin (2.0 * M_PI * 3317.0 * n / 48000.0));
- r[i] = (float) (0.5 * std::sin (2.0 * M_PI * 440.0 * n / 48000.0 + 0.3) + noise);
- }
- }
- int main (int argc, char** argv)
- {
- if (argc < 3) return 2;
- ysfx_config_t* config = ysfx_config_new();
- ysfx_t* fx = ysfx_new (config);
- ysfx_config_free (config);
- if (! ysfx_load_file (fx, argv[1], 0) || ! ysfx_compile (fx, ysfx_compile_no_gfx)) { std::fprintf (stderr, "compile failed\n"); return 1; }
- ysfx_set_sample_rate (fx, 48000.0);
- ysfx_set_block_size (fx, 4096);
- ysfx_init (fx);
- ysfx_time_info_t info {};
- info.tempo = 120.0; info.time_signature[0] = 4; info.time_signature[1] = 4; info.playback_state = ysfx_playback_stopped;
- const int block = 512, blocks = 64;
- std::vector<float> l (block), r (block);
- std::uint32_t lcg = 12345u;
- std::uint64_t hash = 14695981039346656037ull;
- FILE* out = std::fopen (argv[2], "w");
- std::fprintf (out, "#pragma once\n\n// Generated by the round 190pj reference tool from upstream ysfx (JoepVanlier/ysfx 5c3452fe): %s, 48 kHz,\n"
- "// 64 blocks of 512 frames, slider2 = 12 from block 32; every 61st frame (left, right) and an FNV-1a hash of all of it.\n"
- "// The input is lynx::jsfx's test signal (engine/JsfxFormat.cpp). Do not edit by hand.\n\nnamespace lynx::jsfxref\n{\n"
- "inline constexpr float softClipper[][2] = {\n", "chokehold/Clipper/soft_clipper.jsfx");
- long frame = 0;
- for (int b = 0; b < blocks; ++b)
- {
- if (b == 32) ysfx_slider_set_value (fx, 1, 12.0, true);
- input (l, r, block, lcg, frame);
- ysfx_set_time_info (fx, &info);
- const float* ins[2] = { l.data(), r.data() };
- float* outs[2] = { l.data(), r.data() };
- ysfx_process_float (fx, ins, outs, 2, 2, (uint32_t) block);
- for (int i = 0; i < block; ++i, ++frame)
- {
- for (const float v : { l[i], r[i] })
- {
- std::uint32_t bits; std::memcpy (&bits, &v, 4);
- for (int k = 0; k < 4; ++k) { hash ^= (bits >> (8 * k)) & 0xff; hash *= 1099511628211ull; }
- }
- if (frame % 61 == 0) std::fprintf (out, " { %a, %a },\n", (double) l[i], (double) r[i]);
- }
- }
- std::fprintf (out, "};\ninline constexpr unsigned long long softClipperHash = 0x%016llxull;\n} // namespace lynx::jsfxref\n", (unsigned long long) hash);
- std::fclose (out);
- ysfx_free (fx);
- std::printf ("hash %016llx frames %ld\n", (unsigned long long) hash, frame);
- return 0;
- }
|