Skip to content

Commit 56971c5

Browse files
committed
move NeuralAudio implementation to pdnam+; create new MicroNam called pdnam~
1 parent 9882a4b commit 56971c5

8 files changed

Lines changed: 280 additions & 97 deletions

File tree

.gitmodules

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,9 @@
44
[submodule "dep/pd-lib-builder"]
55
path = dep/pd-lib-builder
66
url = https://github.com/pure-data/pd-lib-builder.git
7+
[submodule "dep/json"]
8+
path = dep/json
9+
url = https://github.com/nlohmann/json.git
10+
[submodule "dep/MicroNAM"]
11+
path = dep/MicroNAM
12+
url = https://github.com/jaffco/MicroNAM.git

Makefile

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
1-
lib.name = pdnam~
1+
lib.name = pdnam
22

3-
class.sources = pdnam~.cpp
3+
# pdnam~ only needs its own source (header-only MicroNAM + nlohmann/json)
4+
pdnam~.class.sources = pdnam~.cpp
45

5-
datafiles = \
6-
pdnam~-help.pd \
7-
README.md \
8-
LICENSE
9-
10-
datadirs = data/
11-
12-
common.sources = \
6+
# pdnam+~ needs NeuralAudio implementation
7+
pdnam+~.class.sources = pdnam+~.cpp \
138
dep/NeuralAudio/NeuralAudio/NeuralModel.cpp \
149
dep/NeuralAudio/NeuralAudio/RTNeuralLoader.cpp \
1510
dep/NeuralAudio/deps/RTNeural/RTNeural/RTNeural.cpp \
@@ -18,6 +13,14 @@ common.sources = \
1813
dep/NeuralAudio/deps/NeuralAmpModelerCore/NAM/dsp.cpp \
1914
dep/NeuralAudio/deps/NeuralAmpModelerCore/NAM/wavenet.cpp
2015

16+
datafiles = \
17+
pdnam~-help.pd \
18+
pdnam+~-help.pd \
19+
README.md \
20+
LICENSE
21+
22+
datadirs = data/
23+
2124
# Definitions and flags
2225
cflags = -std=gnu++20 -DNAM_SAMPLE_FLOAT -DDSP_SAMPLE_FLOAT \
2326
-DBUILD_INTERNAL_STATIC_WAVENET -DBUILD_INTERNAL_STATIC_LSTM \
@@ -32,7 +35,8 @@ cflags = -std=gnu++20 -DNAM_SAMPLE_FLOAT -DDSP_SAMPLE_FLOAT \
3235
-Idep/NeuralAudio/deps/RTNeural/modules/json \
3336
-Idep/NeuralAudio/deps/RTNeural-NAM \
3437
-Idep/NeuralAudio/deps/RTNeural-NAM/wavenet \
35-
-Idep/NeuralAudio/deps/RTNeural/modules/xsimd/include
38+
-Idep/NeuralAudio/deps/RTNeural/modules/xsimd/include \
39+
-Idep/MicroNAM -Idep/json/single_include
3640

3741
define forDarwin
3842
cflags += -mmacosx-version-min=10.15

dep/MicroNAM

Submodule MicroNAM added at 83dd7de

dep/json

Submodule json added at 98386eb

pdnam+~-help.pd

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#N canvas 978 285 524 488 10;
2+
#X obj 52 297 dac~;
3+
#X obj 51 18 noise~;
4+
#X obj 51 87 *~;
5+
#X obj 118 39 line~;
6+
#X msg 118 16 1 \, 0 300;
7+
#X obj 119 86 *~;
8+
#X obj 186 38 line~;
9+
#X msg 186 15 1 \, 0 300;
10+
#X obj 182 85 *~;
11+
#X obj 249 37 line~;
12+
#X msg 249 14 1 \, 0 300;
13+
#X obj 52 154 pdnam+~ data/tw40_blues_deluxe_deerinkstudios.json;
14+
#X obj 120 184 pdnam+~ data/BossWN-nano.nam;
15+
#X obj 181 216 pdnam+~ data/Tomato_Preamp_Maximum_Gain.aidax;
16+
#X connect 1 0 2 0;
17+
#X connect 1 0 5 0;
18+
#X connect 1 0 8 0;
19+
#X connect 2 0 11 0;
20+
#X connect 3 0 2 1;
21+
#X connect 4 0 3 0;
22+
#X connect 5 0 12 0;
23+
#X connect 6 0 5 1;
24+
#X connect 7 0 6 0;
25+
#X connect 8 0 13 0;
26+
#X connect 9 0 8 1;
27+
#X connect 10 0 9 0;
28+
#X connect 11 0 0 0;
29+
#X connect 11 0 0 1;
30+
#X connect 12 0 0 0;
31+
#X connect 12 0 0 1;
32+
#X connect 13 0 0 0;
33+
#X connect 13 0 0 1;

pdnam+~.cpp

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
// PDNAM
2+
// Copyright (C) 2026 Wasted Audio
3+
//
4+
// SPDX-License-Identifier: MIT
5+
6+
#include "m_pd.h"
7+
#include "g_canvas.h"
8+
#include "NeuralAudio/NeuralModel.h"
9+
#include <iostream>
10+
#include <string>
11+
#include <filesystem>
12+
13+
static t_class *pdnam_plus_tilde_class;
14+
15+
typedef struct _pdnam_plus_tilde {
16+
t_object x_obj;
17+
t_sample f;
18+
NeuralAudio::NeuralModel* model;
19+
t_symbol* model_path;
20+
} t_pdnam_plus_tilde;
21+
22+
static void pdnam_plus_tilde_load(t_pdnam_plus_tilde *x)
23+
{
24+
if (x->model) {
25+
delete x->model;
26+
x->model = nullptr;
27+
}
28+
29+
if (x->model_path == &s_) return;
30+
31+
// Resolve relative path
32+
char buf[MAXPDSTRING];
33+
canvas_makefilename(canvas_getcurrent(), x->model_path->s_name, buf, MAXPDSTRING);
34+
std::filesystem::path path(buf);
35+
36+
if (!std::filesystem::exists(path) || !std::filesystem::is_regular_file(path)) {
37+
pd_error(x, "pdnam+~: model file not found: %s", buf);
38+
return;
39+
}
40+
41+
// Set load mode
42+
NeuralAudio::EModelLoadMode mode = NeuralAudio::EModelLoadMode::Internal;
43+
44+
NeuralAudio::NeuralModel::SetWaveNetLoadMode(mode);
45+
NeuralAudio::NeuralModel::SetLSTMLoadMode(mode);
46+
47+
x->model = NeuralAudio::NeuralModel::CreateFromFile(path);
48+
if (x->model) {
49+
post("pdnam+~: loaded model %s", x->model_path->s_name);
50+
} else {
51+
pd_error(x, "pdnam+~: failed to load model %s", x->model_path->s_name);
52+
}
53+
}
54+
55+
void *pdnam_plus_tilde_new(t_symbol *s, int argc, t_atom *argv)
56+
{
57+
t_pdnam_plus_tilde *x = (t_pdnam_plus_tilde *)pd_new(pdnam_plus_tilde_class);
58+
59+
x->model = nullptr;
60+
x->model_path = &s_;
61+
62+
if (argc >= 1 && argv[0].a_type == A_SYMBOL) {
63+
x->model_path = atom_getsymbol(&argv[0]);
64+
}
65+
66+
pdnam_plus_tilde_load(x);
67+
68+
outlet_new(&x->x_obj, &s_signal);
69+
70+
return (void *)x;
71+
}
72+
73+
t_int *pdnam_plus_tilde_perform(t_int *w)
74+
{
75+
t_pdnam_plus_tilde *x = (t_pdnam_plus_tilde *)(w[1]);
76+
t_sample *in = (t_sample *)(w[2]);
77+
t_sample *out = (t_sample *)(w[3]);
78+
int n = (int)(w[4]);
79+
80+
if (x->model) {
81+
x->model->Process(in, out, n);
82+
} else {
83+
while (n--) {
84+
*out++ = *in++;
85+
}
86+
}
87+
88+
return (w+5);
89+
}
90+
91+
void pdnam_plus_tilde_dsp(t_pdnam_plus_tilde *x, t_signal **sp)
92+
{
93+
dsp_add(pdnam_plus_tilde_perform, 4, x,
94+
sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n);
95+
}
96+
97+
void pdnam_plus_tilde_free(t_pdnam_plus_tilde *x)
98+
{
99+
if (x->model) delete x->model;
100+
}
101+
102+
extern "C" void setup_pdnam0x2b_tilde(void) {
103+
pdnam_plus_tilde_class = class_new(gensym("pdnam+~"),
104+
(t_newmethod)pdnam_plus_tilde_new,
105+
(t_method)pdnam_plus_tilde_free, sizeof(t_pdnam_plus_tilde),
106+
CLASS_DEFAULT, A_GIMME, 0);
107+
108+
class_addmethod(pdnam_plus_tilde_class,
109+
(t_method)pdnam_plus_tilde_dsp, gensym("dsp"), A_CANT, 0);
110+
CLASS_MAINSIGNALIN(pdnam_plus_tilde_class, t_pdnam_plus_tilde, f);
111+
}

pdnam~-help.pd

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,13 @@
1-
#N canvas 978 285 524 488 10;
2-
#X obj 51 297 dac~;
1+
#N canvas 1122 221 524 488 10;
2+
#X obj 52 297 dac~;
33
#X obj 51 18 noise~;
4-
#X obj 51 87 *~;
5-
#X obj 118 39 line~;
6-
#X msg 118 16 1 \, 0 300;
7-
#X obj 119 86 *~;
8-
#X obj 186 38 line~;
9-
#X msg 186 15 1 \, 0 300;
10-
#X obj 182 85 *~;
11-
#X obj 249 37 line~;
12-
#X msg 249 14 1 \, 0 300;
13-
#X obj 51 155 pdnam~ data/tw40_blues_deluxe_deerinkstudios.json;
14-
#X obj 120 184 pdnam~ data/BossWN-nano.nam;
15-
#X obj 181 216 pdnam~ data/Tomato_Preamp_Maximum_Gain.aidax;
4+
#X obj 50 86 *~;
5+
#X obj 117 38 line~;
6+
#X msg 117 15 1 \, 0 300;
7+
#X obj 51 184 pdnam~ data/BossWN-nano.nam;
168
#X connect 1 0 2 0;
17-
#X connect 1 0 5 0;
18-
#X connect 1 0 8 0;
19-
#X connect 2 0 11 0;
9+
#X connect 2 0 5 0;
2010
#X connect 3 0 2 1;
2111
#X connect 4 0 3 0;
22-
#X connect 5 0 12 0;
23-
#X connect 6 0 5 1;
24-
#X connect 7 0 6 0;
25-
#X connect 8 0 13 0;
26-
#X connect 9 0 8 1;
27-
#X connect 10 0 9 0;
28-
#X connect 11 0 0 0;
29-
#X connect 11 0 0 1;
30-
#X connect 12 0 0 0;
31-
#X connect 12 0 0 1;
32-
#X connect 13 0 0 0;
33-
#X connect 13 0 0 1;
12+
#X connect 5 0 0 0;
13+
#X connect 5 0 0 1;

0 commit comments

Comments
 (0)