|
| 1 | +// Tests for WaveNet Factory |
| 2 | + |
| 3 | +#include <cassert> |
| 4 | +#include <cmath> |
| 5 | +#include <memory> |
| 6 | +#include <vector> |
| 7 | + |
| 8 | +#include "json.hpp" |
| 9 | + |
| 10 | +#include "NAM/get_dsp.h" |
| 11 | +#include "NAM/wavenet.h" |
| 12 | + |
| 13 | +namespace test_wavenet |
| 14 | +{ |
| 15 | +namespace test_factory |
| 16 | +{ |
| 17 | +/// Asserts that the model is instantiated correctly when no "head" key is provided. |
| 18 | +/// The deprecated "head" key is optional; when absent, with_head should be false. |
| 19 | +void test_factory_without_head_key() |
| 20 | +{ |
| 21 | + // Minimal WaveNet config - deliberately omits the "head" key entirely. |
| 22 | + // Same structure as wavenet.nam but without "head" in config. |
| 23 | + const std::string configStr = R"({ |
| 24 | + "version": "0.5.4", |
| 25 | + "metadata": {}, |
| 26 | + "architecture": "WaveNet", |
| 27 | + "config": { |
| 28 | + "layers": [{ |
| 29 | + "input_size": 1, |
| 30 | + "condition_size": 1, |
| 31 | + "head_size": 1, |
| 32 | + "channels": 1, |
| 33 | + "kernel_size": 1, |
| 34 | + "dilations": [1], |
| 35 | + "activation": "ReLU", |
| 36 | + "gated": false, |
| 37 | + "head_bias": false |
| 38 | + }], |
| 39 | + "head_scale": 1.0 |
| 40 | + }, |
| 41 | + "weights": [1.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0, 1.0], |
| 42 | + "sample_rate": 48000 |
| 43 | + })"; |
| 44 | + |
| 45 | + nlohmann::json j = nlohmann::json::parse(configStr); |
| 46 | + |
| 47 | + // Verify the config does not contain "head" key |
| 48 | + assert(j["config"].find("head") == j["config"].end()); |
| 49 | + |
| 50 | + // Load model via get_dsp - exercises Factory path |
| 51 | + std::unique_ptr<nam::DSP> dsp = nam::get_dsp(j); |
| 52 | + assert(dsp != nullptr); |
| 53 | + |
| 54 | + // Process audio to verify model works correctly |
| 55 | + const int numFrames = 4; |
| 56 | + const int maxBufferSize = 64; |
| 57 | + dsp->Reset(48000.0, maxBufferSize); |
| 58 | + |
| 59 | + std::vector<NAM_SAMPLE> input(numFrames, 1.0f); |
| 60 | + std::vector<NAM_SAMPLE> output(numFrames, 0.0f); |
| 61 | + NAM_SAMPLE* inputPtrs[] = {input.data()}; |
| 62 | + NAM_SAMPLE* outputPtrs[] = {output.data()}; |
| 63 | + |
| 64 | + dsp->process(inputPtrs, outputPtrs, numFrames); |
| 65 | + |
| 66 | + assert(static_cast<int>(output.size()) == numFrames); |
| 67 | + for (int i = 0; i < numFrames; i++) |
| 68 | + { |
| 69 | + assert(std::isfinite(output[i])); |
| 70 | + } |
| 71 | +} |
| 72 | +}; // namespace test_factory |
| 73 | +}; // namespace test_wavenet |
0 commit comments