sonicake-pocket-master-mcp 0.11.0 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/convert-worker.js +433 -0
- package/dist/server.js +1961 -77
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -41,7 +41,7 @@ and macOS and Linux have one.
|
|
|
41
41
|
`~/.pocket-master-editor/presets` and reuses them.
|
|
42
42
|
|
|
43
43
|
Tested on firmware V1.3.3. Source, protocol notes and the web editor:
|
|
44
|
-
<https://github.com/fgbona/pocket-master-editor>.
|
|
44
|
+
<https://github.com/fgbona/sonicake-pocket-master-editor>.
|
|
45
45
|
|
|
46
46
|
## License
|
|
47
47
|
|
|
@@ -0,0 +1,433 @@
|
|
|
1
|
+
// src/convert-worker.ts
|
|
2
|
+
import { parentPort, workerData } from "node:worker_threads";
|
|
3
|
+
|
|
4
|
+
// ../../packages/core/src/dump.ts
|
|
5
|
+
var Tag = { VOLUME: 8193, BPM: 8194, STATES: 12289, CHAIN: 12290, EFFECTS: 12291, PARAMS: 12292 };
|
|
6
|
+
var REQUIRED = [Tag.STATES, Tag.CHAIN, Tag.EFFECTS, Tag.PARAMS];
|
|
7
|
+
var MIN_SIZE = /* @__PURE__ */ new Map([
|
|
8
|
+
[Tag.STATES, 4],
|
|
9
|
+
[Tag.CHAIN, 9],
|
|
10
|
+
[Tag.EFFECTS, 40],
|
|
11
|
+
[Tag.PARAMS, 320],
|
|
12
|
+
[Tag.VOLUME, 4],
|
|
13
|
+
[Tag.BPM, 4]
|
|
14
|
+
]);
|
|
15
|
+
|
|
16
|
+
// ../../packages/core/src/globals.ts
|
|
17
|
+
var LEVEL = { min: -20, max: 20 };
|
|
18
|
+
var FLAG = { min: 0, max: 1 };
|
|
19
|
+
var GLOBAL_SETTINGS = {
|
|
20
|
+
masterVolume: { address: [2, 2], min: 0, max: 100 },
|
|
21
|
+
inputLevel: { address: [1, 3], ...LEVEL },
|
|
22
|
+
fxRecLevel: { address: [1, 4], ...LEVEL },
|
|
23
|
+
monitorLevel: { address: [2, 4], ...LEVEL },
|
|
24
|
+
btRecLevel: { address: [5, 4], ...LEVEL },
|
|
25
|
+
mode: { address: [4, 4], ...FLAG },
|
|
26
|
+
reamp: { address: [6, 4], ...FLAG },
|
|
27
|
+
expFsType: { address: [1, 5], min: 0, max: 2 },
|
|
28
|
+
// 0..100: the unit reports 100 at full brightness (SonicMaster's dialog stops at 10).
|
|
29
|
+
backlight: { address: [3, 2], min: 0, max: 100 },
|
|
30
|
+
eco: { address: [4, 2], ...FLAG },
|
|
31
|
+
powerConfirm: { address: [5, 2], ...FLAG },
|
|
32
|
+
battOnly: { address: [6, 2], ...FLAG }
|
|
33
|
+
};
|
|
34
|
+
var OFFSET = {
|
|
35
|
+
masterVolume: 22,
|
|
36
|
+
backlight: 35,
|
|
37
|
+
inputLevel: 40,
|
|
38
|
+
fxRecLevel: 45,
|
|
39
|
+
monitorLevel: 50,
|
|
40
|
+
mode: 60,
|
|
41
|
+
btRecLevel: 65,
|
|
42
|
+
reamp: 70,
|
|
43
|
+
eco: 75,
|
|
44
|
+
expFsType: 80
|
|
45
|
+
};
|
|
46
|
+
var MIN_LENGTH = OFFSET.btRecLevel + 1;
|
|
47
|
+
|
|
48
|
+
// ../../packages/core/src/commands.ts
|
|
49
|
+
var EditCommand = { PRESET_FIELD: 66, CHAIN: 68, MODEL: 71, PARAM: 72, BLOCK_ON: 73, FOOTSWITCH: 77 };
|
|
50
|
+
var ALLOWED_EDITS = new Set(Object.values(EditCommand));
|
|
51
|
+
|
|
52
|
+
// ../../packages/core/src/slots.ts
|
|
53
|
+
var NAME_LENGTH = 10;
|
|
54
|
+
var SAVE_PAYLOAD = 2 + 4 + NAME_LENGTH + 3;
|
|
55
|
+
|
|
56
|
+
// ../../packages/core/src/ir-upload.ts
|
|
57
|
+
var INT24_MAX = (1 << 23) - 1;
|
|
58
|
+
var NAME_OFFSET = 10;
|
|
59
|
+
var NAME_FIELD = 64;
|
|
60
|
+
var SAMPLES_OFFSET = NAME_OFFSET + NAME_FIELD;
|
|
61
|
+
var UploadDomain = { PRESET: 1, PROFILE: 3, IR: 4 };
|
|
62
|
+
var UPLOAD_MAGIC = {
|
|
63
|
+
[UploadDomain.IR]: [[17, 33], [17, 34]],
|
|
64
|
+
[UploadDomain.PROFILE]: [[17, 37], [17, 38]]
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
// ../../packages/core/src/clo/codec.ts
|
|
68
|
+
var NAME_AT = 10;
|
|
69
|
+
var DATA_AT = NAME_AT + 64;
|
|
70
|
+
|
|
71
|
+
// ../../packages/core/src/model-info.ts
|
|
72
|
+
var NOT_IN_MANUAL = "Added after firmware V1.3.0; the manuals do not describe it.";
|
|
73
|
+
var FX = {
|
|
74
|
+
"COMP 1": { basedOn: "Ross Compressor", about: "Compressor with sustain and volume." },
|
|
75
|
+
"COMP 2": { basedOn: "Keeley C4 4-knob compressor", about: "Compressor with sustain, attack, volume and clipping (input sensitivity)." },
|
|
76
|
+
"Touch Wah": { about: "Wide-range envelope filter: the wah follows how hard you play; guitar or bass mode." },
|
|
77
|
+
"Auto Wah": { about: "Wah swept at a set rate, for guitar or bass." },
|
|
78
|
+
Boost: { basedOn: "Xotic EP Booster", about: "Clean boost with +3dB minimum and vintage/flat (Bright) character." },
|
|
79
|
+
"A-Chorus": { basedOn: "Arion SCH-1 Stereo Chorus", about: "Chorus with depth, rate and tone." },
|
|
80
|
+
"B-Chorus": { about: "Vintage-voiced ensemble chorus tuned for bass players." },
|
|
81
|
+
Flanger: { about: "Classic flanger with pre-delay and feedback." },
|
|
82
|
+
Phaser: { basedOn: "MXR M101 Phase 90", about: "Four-stage phaser with one rate control." },
|
|
83
|
+
Vibe: { basedOn: "Voodoo Lab Micro Vibe", about: "Uni-Vibe-style throb with depth and rate." },
|
|
84
|
+
Vibrato: { about: "Pitch vibrato based on a BBD (bucket-brigade) blue vibrato pedal." },
|
|
85
|
+
Tremolo: { basedOn: "Demeter TRM-1 Tremulator", about: "Classic opto tremolo." },
|
|
86
|
+
"Sine Trem": { about: "Sine-wave tremolo with a very wide range." },
|
|
87
|
+
"Bias Trem": { about: "Bias (valve-style) tremolo with an adjustable waveform offset." },
|
|
88
|
+
Octave: { about: "Polyphonic octave: one octave down and one up, mixed with the dry signal." },
|
|
89
|
+
Pitch: { about: "Polyphonic pitch shifter / harmonizer, in semitones." },
|
|
90
|
+
Detune: { about: "Slightly detuned copy (\xB150 cents) mixed with the dry signal, for a chorus-like doubling." },
|
|
91
|
+
"AC G": { about: "Acoustic guitar simulator (AC Sim): Body (low resonance), Top (upper harmonics); Standard, Jumbo, Enhanced (attack) or Piezo pickup character." }
|
|
92
|
+
};
|
|
93
|
+
function without(table, ...names) {
|
|
94
|
+
return Object.fromEntries(Object.entries(table).filter(([name]) => !names.includes(name)));
|
|
95
|
+
}
|
|
96
|
+
var MODEL_INFO = {
|
|
97
|
+
nr: {
|
|
98
|
+
Gate: { basedOn: "ISP Decimator noise gate", about: "Noise gate; THRE sets the trigger level." }
|
|
99
|
+
},
|
|
100
|
+
fx1: without(FX, "Octave", "Pitch", "Detune"),
|
|
101
|
+
fx2: without(FX, "AC G"),
|
|
102
|
+
drv: {
|
|
103
|
+
Scream: { basedOn: "Ibanez TS-808 Tube Screamer", about: "Mid-focused overdrive, often used to tighten high-gain amps." },
|
|
104
|
+
"Butter OD": { about: "Overdrive based on the classic 2-knob yellow overdrive pedal." },
|
|
105
|
+
"JP Dist": { about: "Distortion based on a classic orange three-knob distortion pedal." },
|
|
106
|
+
Shark: { basedOn: "MI Audio Crunch Box", about: "Amp-like high-gain distortion pedal." },
|
|
107
|
+
"Dark Mouse": { basedOn: "ProCo The Rat (early LM308 op-amp version)", about: "Classic hard-clipping distortion with a filter control." },
|
|
108
|
+
"Grey Fuzz": { basedOn: "Sola Sound Tone Bender MkII", about: "Vintage germanium-style fuzz." },
|
|
109
|
+
"Red Fuzz": { basedOn: "Dallas-Arbiter Fuzz Face", about: "Vintage fuzz." },
|
|
110
|
+
"Bass Drive": { about: `Bass overdrive with clean blend and bass/treble. ${NOT_IN_MANUAL}` }
|
|
111
|
+
},
|
|
112
|
+
amp: {
|
|
113
|
+
"TWD Deluxe": { basedOn: "Fender Tweed Deluxe", about: "Small vintage Fender combo; breaks up early." },
|
|
114
|
+
"B-Man N": { basedOn: "Fender '59 Bassman, Normal channel", about: "Vintage Fender, warm clean to crunch." },
|
|
115
|
+
"Dark Twin": { basedOn: "Fender '65 Twin Reverb", about: "Loud, sparkling Fender clean." },
|
|
116
|
+
"Voks 30N": { basedOn: "VOX AC30HW, Normal channel", about: "British class-A chime." },
|
|
117
|
+
"Jazz 120": { basedOn: 'Roland JC-120 "Jazz Chorus" solid-state combo', about: "Very clean, hi-fi solid-state." },
|
|
118
|
+
"Brit 45": { basedOn: "Marshall JTM45, Normal channel", about: "Early Marshall: warm, bluesy crunch." },
|
|
119
|
+
"Brit 50JP": { basedOn: "Marshall JTM50 with jumped channels", about: "Plexi-era Marshall rock crunch; two gain controls." },
|
|
120
|
+
"Brit 800": { basedOn: "Marshall JCM800", about: "Classic 80s Marshall hard rock / metal crunch." },
|
|
121
|
+
"B-Man B": { basedOn: "Fender '59 Bassman, Bright channel", about: "Brighter vintage Fender crunch." },
|
|
122
|
+
"Voks 30TB": { basedOn: "VOX AC30HW, Top Boost channel", about: "Chimey British crunch; Cool/Hot character." },
|
|
123
|
+
"Sol 100 OD": { basedOn: "Soldano SLO-100, Crunch channel", about: "Hot-rodded crunch." },
|
|
124
|
+
"Dizzy VH": { basedOn: "Diezel VH4, channel 3", about: "Modern tight high gain." },
|
|
125
|
+
"Eng 120": { basedOn: "ENGL Savage 120 E610", about: "Aggressive modern German high gain." },
|
|
126
|
+
"Halen 51": { basedOn: "Peavey 5150, Lead channel", about: "Saturated 90s/2000s metal high gain." },
|
|
127
|
+
"Sol 100 LD": { basedOn: "Soldano SLO-100, Overdrive channel", about: "Smooth singing lead high gain." },
|
|
128
|
+
"Calif DualV": { basedOn: "Mesa/Boogie Dual Rectifier, Vintage mode", about: "Rectifier high gain, looser and warmer." },
|
|
129
|
+
"Calif DualM": { basedOn: "Mesa/Boogie Dual Rectifier, Modern mode", about: "Rectifier high gain, tight and scooped: 90s metal." },
|
|
130
|
+
"Eng Power": { basedOn: "ENGL Powerball II E645/2, lead channel (channel 4)", about: "Very high gain, tight modern metal." },
|
|
131
|
+
"Flyman B1+": { basedOn: 'Friedman "Brown Eye" BE-100, HBE channel', about: "Boutique hot-rodded British high gain." },
|
|
132
|
+
"Bog XT": { basedOn: "Bogner Ecstasy (XTC), red channel", about: "Fiery boutique high gain." },
|
|
133
|
+
"A BassVT": { about: `Bass amp with 3-band EQ and selectable mid frequency. ${NOT_IN_MANUAL}` },
|
|
134
|
+
"Voks Bass": { about: `Bass amp with bass and treble. ${NOT_IN_MANUAL}` }
|
|
135
|
+
},
|
|
136
|
+
ir: {
|
|
137
|
+
"TWD 1x8": { basedOn: "Fender Champ 1x8 cabinet", about: "Tiny vintage combo speaker." },
|
|
138
|
+
"TWD-P 1x10": { basedOn: "Fender Princeton 1x10 cabinet", about: "Small vintage combo." },
|
|
139
|
+
"Viblux 1x12": { basedOn: "Fender Vibrolux 1x12 cabinet", about: "Vintage 1x12 combo." },
|
|
140
|
+
"Voks 1x12": { basedOn: "VOX AC15 1x12 cabinet", about: "British 1x12 combo." },
|
|
141
|
+
"TWD 2x12": { basedOn: "custom Fender Tweed 2x10 cabinet", about: "Vintage tweed cabinet." },
|
|
142
|
+
"Double 2x12": { basedOn: "Fender '65 Twin Reverb 2x12 cabinet", about: "Open-back clean 2x12." },
|
|
143
|
+
"Star 2x12": { basedOn: "Mesa/Boogie Lonestar 1x12 cabinet", about: "Boutique combo cabinet." },
|
|
144
|
+
"Jazz 2x12": { basedOn: "Roland JC-120 2x12 cabinet", about: "Clean solid-state combo speakers." },
|
|
145
|
+
"BritGN 2x12": { basedOn: "Marshall 2550 2x12 cabinet", about: "British 2x12." },
|
|
146
|
+
"BritGN 4x12": { basedOn: "Vintage Marshall 4x12 cabinet with Celestion Greenback speakers", about: "Classic British 4x12." },
|
|
147
|
+
"Bog 4x12": { basedOn: "Bogner 4x12 cabinet", about: "Boutique high-gain 4x12." },
|
|
148
|
+
"Dizzy 4x12": { basedOn: "Diezel 4x12 cabinet", about: "Modern high-gain 4x12." },
|
|
149
|
+
"Halen 4x12": { basedOn: "Peavey 6505 4x12 cabinet", about: "Metal 4x12." },
|
|
150
|
+
"Sol 4x12": { basedOn: "Soldano 4x12 cabinet", about: "Hot-rod 4x12." },
|
|
151
|
+
"Dual 4x12": { basedOn: "Mesa/Boogie Rectifier 4x12 cabinet", about: "Tight, deep modern-metal 4x12." }
|
|
152
|
+
},
|
|
153
|
+
eq: {
|
|
154
|
+
"GT EQ 1": { about: "5-band guitar EQ: 125 Hz, 400 Hz, 800 Hz, 1.6 kHz, 4 kHz, and volume." },
|
|
155
|
+
"GT EQ 2": { about: "5-band guitar EQ: 100 Hz, 500 Hz, 1 kHz, 3 kHz, 6 kHz, and volume." },
|
|
156
|
+
"Bass EQ": { about: "5-band bass EQ: 50 Hz, 120 Hz, 400 Hz, 800 Hz, 4.5 kHz, and volume." }
|
|
157
|
+
},
|
|
158
|
+
dly: {
|
|
159
|
+
Pure: { about: "Clean, precise digital delay." },
|
|
160
|
+
Slap: { about: "Classic short slapback echo." },
|
|
161
|
+
Warm: { about: "Warm delay with an analog feel." },
|
|
162
|
+
Mag: { about: "Solid-state tape echo." },
|
|
163
|
+
Tube: { about: "Tube-driven tape echo." },
|
|
164
|
+
Reverse: { about: "Reversed repeats." },
|
|
165
|
+
Analog: { about: "Vintage 1980s rack delay with slightly sample-reduced repeats." },
|
|
166
|
+
Sweep: { about: "Delay whose repeats pass through a sweeping filter." },
|
|
167
|
+
"Ping Pong": { about: "Stereo delay bouncing between left and right." }
|
|
168
|
+
},
|
|
169
|
+
rvb: {
|
|
170
|
+
Air: { about: "Airy reverb with natural decay and high damping." },
|
|
171
|
+
Room: { about: "Room reverb." },
|
|
172
|
+
Hall: { about: "Concert hall reverb." },
|
|
173
|
+
Church: { about: "Large church reverb." },
|
|
174
|
+
"Plate 1": { about: "Large plate reverb." },
|
|
175
|
+
"Plate 2": { about: "Vintage plate reverb with damping." },
|
|
176
|
+
Spring: { about: "Vintage amp spring reverb." },
|
|
177
|
+
Light: { about: "Lush, bright ambient reverb." },
|
|
178
|
+
Ocean: { about: "Huge, deep ambient reverb." },
|
|
179
|
+
Dream: { about: "Lush modulated reverb." }
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
// ../../packages/core/src/clo/nam.ts
|
|
184
|
+
var num = (v, key) => {
|
|
185
|
+
const x = v[key];
|
|
186
|
+
if (typeof x !== "number") throw new Error(`.nam: "${key}" must be a number`);
|
|
187
|
+
return Math.trunc(x);
|
|
188
|
+
};
|
|
189
|
+
var Cursor = class {
|
|
190
|
+
#pos = 0;
|
|
191
|
+
#w;
|
|
192
|
+
constructor(weights) {
|
|
193
|
+
this.#w = weights;
|
|
194
|
+
}
|
|
195
|
+
take(n) {
|
|
196
|
+
if (this.#pos + n > this.#w.length) throw new Error(".nam: fewer weights than the model needs");
|
|
197
|
+
const s = Float64Array.from(this.#w.slice(this.#pos, this.#pos + n));
|
|
198
|
+
this.#pos += n;
|
|
199
|
+
return s;
|
|
200
|
+
}
|
|
201
|
+
/** Conv1d weights: PyTorch flatten [out][in][k], then bias[out]. */
|
|
202
|
+
conv1d(cin, cout, ks, bias) {
|
|
203
|
+
const raw = this.take(cout * cin * ks);
|
|
204
|
+
const kernels = Array.from(
|
|
205
|
+
{ length: ks },
|
|
206
|
+
(_, k) => Array.from({ length: cout }, (_2, o) => Float64Array.from({ length: cin }, (_3, i) => raw[(o * cin + i) * ks + k]))
|
|
207
|
+
);
|
|
208
|
+
return [kernels, bias ? this.take(cout) : new Float64Array(cout)];
|
|
209
|
+
}
|
|
210
|
+
/** Conv1x1: row-major (out, in), then bias[out]. */
|
|
211
|
+
conv1x1(cin, cout, bias) {
|
|
212
|
+
const raw = this.take(cout * cin);
|
|
213
|
+
const m = Array.from({ length: cout }, (_, o) => raw.slice(o * cin, (o + 1) * cin));
|
|
214
|
+
return [m, bias ? this.take(cout) : null];
|
|
215
|
+
}
|
|
216
|
+
get remaining() {
|
|
217
|
+
return this.#w.length - this.#pos;
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
var featureActive = (v) => v !== null && typeof v === "object" && !Array.isArray(v) ? v.active === true : v !== void 0 && v !== null;
|
|
221
|
+
var FILM_KEYS = [
|
|
222
|
+
"conv_pre_film",
|
|
223
|
+
"conv_post_film",
|
|
224
|
+
"input_mixin_pre_film",
|
|
225
|
+
"input_mixin_post_film",
|
|
226
|
+
"activation_pre_film",
|
|
227
|
+
"activation_post_film",
|
|
228
|
+
"layer1x1_post_film",
|
|
229
|
+
"head1x1_post_film",
|
|
230
|
+
"film_params"
|
|
231
|
+
];
|
|
232
|
+
function assertSupported(la) {
|
|
233
|
+
const gating = la.gating_mode;
|
|
234
|
+
if (la.gated === true || Array.isArray(gating) && gating.some((v) => v !== "none")) throw new Error("gated WaveNet captures are not supported");
|
|
235
|
+
if (typeof la.bottleneck === "number" && Math.trunc(la.bottleneck) !== num(la, "channels")) throw new Error("WaveNet bottleneck captures are not supported");
|
|
236
|
+
if (featureActive(la.head1x1) || featureActive(la.head_1x1_config)) throw new Error("WaveNet head 1x1 captures are not supported");
|
|
237
|
+
if (FILM_KEYS.some((k) => featureActive(la[k]))) throw new Error("WaveNet FiLM captures are not supported");
|
|
238
|
+
}
|
|
239
|
+
function parseAct(v) {
|
|
240
|
+
const name = typeof v === "string" ? v : v && typeof v === "object" ? v.type ?? "Tanh" : "Tanh";
|
|
241
|
+
if (name === "Tanh") return { kind: "tanh" };
|
|
242
|
+
if (name === "ReLU") return { kind: "leaky", slope: 0 };
|
|
243
|
+
if (name === "LeakyReLU") {
|
|
244
|
+
const slope = v && typeof v === "object" ? v.negative_slope : void 0;
|
|
245
|
+
return { kind: "leaky", slope: typeof slope === "number" ? slope : 0.01 };
|
|
246
|
+
}
|
|
247
|
+
throw new Error(`unsupported activation "${name}"`);
|
|
248
|
+
}
|
|
249
|
+
function layerActs(cfg, n) {
|
|
250
|
+
const a = cfg.activation;
|
|
251
|
+
if (Array.isArray(a)) return a.map(parseAct);
|
|
252
|
+
return Array.from({ length: n }, () => a !== void 0 && a !== null ? parseAct(a) : { kind: "tanh" });
|
|
253
|
+
}
|
|
254
|
+
function effectiveModel(root) {
|
|
255
|
+
if (root.architecture === "SlimmableContainer") {
|
|
256
|
+
const subs = root.config?.submodels ?? [];
|
|
257
|
+
if (subs.length === 0) throw new Error(".nam: empty SlimmableContainer");
|
|
258
|
+
let best = subs[0];
|
|
259
|
+
let bestVal = typeof best.max_value === "number" ? best.max_value : 0;
|
|
260
|
+
for (const s of subs) {
|
|
261
|
+
const v = typeof s.max_value === "number" ? s.max_value : 0;
|
|
262
|
+
if (v >= bestVal) {
|
|
263
|
+
best = s;
|
|
264
|
+
bestVal = v;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
return effectiveModel(best.model);
|
|
268
|
+
}
|
|
269
|
+
if (root.architecture !== void 0 && root.architecture !== "WaveNet") {
|
|
270
|
+
throw new Error(`only WaveNet captures can be converted for the pedal (this one is ${String(root.architecture)})`);
|
|
271
|
+
}
|
|
272
|
+
const weights = root.weights;
|
|
273
|
+
if (!Array.isArray(weights) || weights.some((w) => typeof w !== "number")) throw new Error(".nam: weights must be a list of numbers");
|
|
274
|
+
if (!root.config || typeof root.config !== "object") throw new Error(".nam: missing config");
|
|
275
|
+
return { config: root.config, weights };
|
|
276
|
+
}
|
|
277
|
+
function parseNam(text) {
|
|
278
|
+
let root;
|
|
279
|
+
try {
|
|
280
|
+
root = JSON.parse(text);
|
|
281
|
+
} catch {
|
|
282
|
+
throw new Error("not a .nam file (invalid JSON)");
|
|
283
|
+
}
|
|
284
|
+
if (!root || typeof root !== "object") throw new Error("not a .nam file");
|
|
285
|
+
const { config, weights } = effectiveModel(root);
|
|
286
|
+
const cur = new Cursor(weights);
|
|
287
|
+
const headScale = typeof config.head_scale === "number" ? config.head_scale : 1;
|
|
288
|
+
const layersCfg = config.layers;
|
|
289
|
+
if (!Array.isArray(layersCfg) || layersCfg.length === 0) throw new Error(".nam: config.layers missing");
|
|
290
|
+
const arrays = layersCfg.map((la) => {
|
|
291
|
+
assertSupported(la);
|
|
292
|
+
const inputSize = num(la, "input_size");
|
|
293
|
+
const conditionSize = num(la, "condition_size");
|
|
294
|
+
const channels = num(la, "channels");
|
|
295
|
+
const dilations = la.dilations.map((d) => Math.trunc(Number(d)));
|
|
296
|
+
const kernels = Array.isArray(la.kernel_sizes) ? la.kernel_sizes.map((k) => Math.trunc(Number(k))) : dilations.map(() => num(la, "kernel_size"));
|
|
297
|
+
const head = la.head;
|
|
298
|
+
const [headOut, headKs, headBias] = head && typeof head === "object" ? [num(head, "out_channels"), num(head, "kernel_size"), head.bias ?? true] : [num(la, "head_size"), 1, la.head_bias ?? false];
|
|
299
|
+
const acts = layerActs(la, dilations.length);
|
|
300
|
+
const [rechannelW] = cur.conv1x1(inputSize, channels, false);
|
|
301
|
+
const layers = dilations.map((dilation, li) => {
|
|
302
|
+
const [convW, convB] = cur.conv1d(channels, channels, kernels[li], true);
|
|
303
|
+
const [mixinW] = cur.conv1x1(conditionSize, channels, false);
|
|
304
|
+
const [outW, outB] = cur.conv1x1(channels, channels, true);
|
|
305
|
+
return { convW, convB, mixinW, outW, outB, dilation, act: acts[li] ?? { kind: "tanh" } };
|
|
306
|
+
});
|
|
307
|
+
const [headW, headB] = cur.conv1d(channels, headOut, headKs, headBias);
|
|
308
|
+
return { rechannelW, layers, headW, headB, channels };
|
|
309
|
+
});
|
|
310
|
+
return { arrays, headScale };
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
// ../../packages/core/src/clo/fft.ts
|
|
314
|
+
var NFFT = 8192;
|
|
315
|
+
var BINS = NFFT / 2 + 1;
|
|
316
|
+
var WELCH_HOP = NFFT / 4;
|
|
317
|
+
|
|
318
|
+
// ../../packages/core/src/clo/fit.ts
|
|
319
|
+
var FIT_LEVELS = [0.1, 0.03, 0.01, 3e-3];
|
|
320
|
+
var LOUD_LEVEL = 1;
|
|
321
|
+
var LAG_WIN = 1 << 18;
|
|
322
|
+
var LAG_FFT_SIZE = 1 << 19;
|
|
323
|
+
|
|
324
|
+
// ../../packages/core/src/clo/wavenet.ts
|
|
325
|
+
function matmulInto(m, x, out) {
|
|
326
|
+
const t = x[0].length;
|
|
327
|
+
for (let r = 0; r < m.length; r++) {
|
|
328
|
+
const mr = m[r];
|
|
329
|
+
const outr = out[r];
|
|
330
|
+
outr.fill(0, 0, t);
|
|
331
|
+
for (let i = 0; i < mr.length; i++) {
|
|
332
|
+
const w = mr[i];
|
|
333
|
+
const xi = x[i];
|
|
334
|
+
for (let j = 0; j < t; j++) outr[j] += w * xi[j];
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
function conv1dInto(x, kernels, b, dil, out) {
|
|
339
|
+
const cout = kernels[0].length;
|
|
340
|
+
const t = x[0].length;
|
|
341
|
+
const k = kernels.length;
|
|
342
|
+
const cin = x.length;
|
|
343
|
+
for (let o = 0; o < cout; o++) out[o].fill(0, 0, t);
|
|
344
|
+
for (let ki = 0; ki < k; ki++) {
|
|
345
|
+
const kernel = kernels[ki];
|
|
346
|
+
const shift = dil * (k - 1 - ki);
|
|
347
|
+
for (let o = 0; o < cout; o++) {
|
|
348
|
+
const kro = kernel[o];
|
|
349
|
+
const outo = out[o];
|
|
350
|
+
for (let tt = shift; tt < t; tt++) {
|
|
351
|
+
const src = tt - shift;
|
|
352
|
+
let acc = 0;
|
|
353
|
+
for (let i = 0; i < cin; i++) acc += kro[i] * x[i][src];
|
|
354
|
+
outo[tt] += acc;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
for (let o = 0; o < cout; o++) {
|
|
359
|
+
const outo = out[o];
|
|
360
|
+
const bo = b[o];
|
|
361
|
+
for (let tt = 0; tt < t; tt++) outo[tt] += bo;
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
function tanh(x) {
|
|
365
|
+
if (x > 20) return 1;
|
|
366
|
+
if (x < -20) return -1;
|
|
367
|
+
const e2 = Math.exp(2 * x);
|
|
368
|
+
return (e2 - 1) / (e2 + 1);
|
|
369
|
+
}
|
|
370
|
+
var activate = (act, v) => act.kind === "tanh" ? tanh(v) : v >= 0 ? v : act.slope * v;
|
|
371
|
+
var rows = (n, t) => Array.from({ length: n }, () => new Float64Array(t));
|
|
372
|
+
function runWavenet(mono, model) {
|
|
373
|
+
const t = mono.length;
|
|
374
|
+
const cond = [mono];
|
|
375
|
+
let head = [];
|
|
376
|
+
let x = [mono];
|
|
377
|
+
for (const la of model.arrays) {
|
|
378
|
+
const ch = la.channels;
|
|
379
|
+
const xx = rows(ch, t);
|
|
380
|
+
matmulInto(la.rechannelW, x, xx);
|
|
381
|
+
const acc = rows(ch, t);
|
|
382
|
+
for (let i = 0; i < head.length && i < acc.length; i++) {
|
|
383
|
+
const ai = acc[i];
|
|
384
|
+
const hi = head[i];
|
|
385
|
+
for (let j = 0; j < t; j++) ai[j] += hi[j];
|
|
386
|
+
}
|
|
387
|
+
const conv = rows(ch, t);
|
|
388
|
+
const mixin = rows(ch, t);
|
|
389
|
+
const post = rows(ch, t);
|
|
390
|
+
const ow = rows(ch, t);
|
|
391
|
+
for (const layer of la.layers) {
|
|
392
|
+
conv1dInto(xx, layer.convW, layer.convB, layer.dilation, conv);
|
|
393
|
+
matmulInto(layer.mixinW, cond, mixin);
|
|
394
|
+
for (let c = 0; c < ch; c++) {
|
|
395
|
+
const cc = conv[c];
|
|
396
|
+
const mm = mixin[c];
|
|
397
|
+
const pc = post[c];
|
|
398
|
+
for (let j = 0; j < t; j++) pc[j] = activate(layer.act, cc[j] + mm[j]);
|
|
399
|
+
}
|
|
400
|
+
for (let c = 0; c < ch; c++) {
|
|
401
|
+
const ac = acc[c];
|
|
402
|
+
const pc = post[c];
|
|
403
|
+
for (let j = 0; j < t; j++) ac[j] += pc[j];
|
|
404
|
+
}
|
|
405
|
+
matmulInto(layer.outW, post, ow);
|
|
406
|
+
for (let c = 0; c < ch; c++) {
|
|
407
|
+
const xc = xx[c];
|
|
408
|
+
const oc = ow[c];
|
|
409
|
+
const bc = layer.outB[c];
|
|
410
|
+
for (let j = 0; j < t; j++) xc[j] += oc[j] + bc;
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
const headOut = rows(la.headW[0].length, t);
|
|
414
|
+
conv1dInto(acc, la.headW, la.headB, 1, headOut);
|
|
415
|
+
x = xx;
|
|
416
|
+
head = headOut;
|
|
417
|
+
}
|
|
418
|
+
const h0 = head[0];
|
|
419
|
+
const out = new Float64Array(t);
|
|
420
|
+
for (let j = 0; j < t; j++) out[j] = model.headScale * h0[j];
|
|
421
|
+
return out;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
// ../../packages/core/src/clo/generate.ts
|
|
425
|
+
var PROBE_LEVELS = [...FIT_LEVELS, LOUD_LEVEL];
|
|
426
|
+
function probeResponse(model, di482, level2) {
|
|
427
|
+
return runWavenet(Float64Array.from(di482, (v) => v * level2), model);
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
// src/convert-worker.ts
|
|
431
|
+
var { namJson, di48, level } = workerData;
|
|
432
|
+
var response = probeResponse(parseNam(namJson), di48, level);
|
|
433
|
+
parentPort?.postMessage(response, [response.buffer]);
|