@framefields/node-audio-delay 2.0.2

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.
@@ -0,0 +1,20 @@
1
+
2
+ > @framefields/node-audio-delay@2.0.2 build /Users/okanaslankan/frameshop/nodes/node-audio-delay
3
+ > tsdown
4
+
5
+ ℹ tsdown v0.19.0 powered by rolldown v1.0.0-beta.59
6
+ ℹ config file: /Users/okanaslankan/frameshop/nodes/node-audio-delay/tsdown.config.ts
7
+ ℹ entry: src/index.ts, src/renderers/index.ts
8
+ ℹ tsconfig: tsconfig.json
9
+ ℹ Build start
10
+ ℹ dist/index.mjs 1.77 kB │ gzip: 0.67 kB
11
+ ℹ dist/renderer.mjs 0.11 kB │ gzip: 0.09 kB
12
+ ℹ dist/renderers-zDTlg6EZ.mjs.map 11.47 kB │ gzip: 3.35 kB
13
+ ℹ dist/renderers-zDTlg6EZ.mjs 8.66 kB │ gzip: 2.44 kB
14
+ ℹ dist/index.mjs.map 2.96 kB │ gzip: 0.96 kB
15
+ ℹ dist/index.d.mts.map 0.34 kB │ gzip: 0.22 kB
16
+ ℹ dist/renderer.d.mts.map 0.12 kB │ gzip: 0.11 kB
17
+ ℹ dist/index.d.mts 1.69 kB │ gzip: 0.53 kB
18
+ ℹ dist/renderer.d.mts 0.29 kB │ gzip: 0.20 kB
19
+ ℹ 9 files, total: 27.41 kB
20
+ ✔ Build complete in 4242ms
package/CHANGELOG.md ADDED
@@ -0,0 +1,23 @@
1
+ # @framefields/node-audio-delay
2
+
3
+ ## 2.0.2
4
+
5
+ ## 2.0.1
6
+
7
+ ## 2.0.0
8
+
9
+ ## 1.4.3
10
+
11
+ ## 1.4.2
12
+
13
+ ## 1.4.1
14
+
15
+ ## 1.4.0
16
+
17
+ ## 1.3.2
18
+
19
+ ## 1.3.1
20
+
21
+ ### Patch Changes
22
+
23
+ - init
package/LICENCE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright 2026 Gatewai Studio
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,38 @@
1
+ import "./renderer.mjs";
2
+ import { z } from "zod";
3
+ import * as _framefields_core0 from "@framefields/core";
4
+
5
+ //#region src/shared/config.d.ts
6
+ declare const delayConfig: {
7
+ schema: z.ZodObject<{
8
+ delayTime: z.ZodDefault<z.ZodNumber>;
9
+ feedback: z.ZodDefault<z.ZodNumber>;
10
+ wet: z.ZodDefault<z.ZodNumber>;
11
+ dry: z.ZodDefault<z.ZodNumber>;
12
+ pingPong: z.ZodDefault<z.ZodBoolean>;
13
+ }, z.core.$strip>;
14
+ };
15
+ declare const DelayNodeConfigSchema: z.ZodObject<{
16
+ delayTime: z.ZodDefault<z.ZodNumber>;
17
+ feedback: z.ZodDefault<z.ZodNumber>;
18
+ wet: z.ZodDefault<z.ZodNumber>;
19
+ dry: z.ZodDefault<z.ZodNumber>;
20
+ pingPong: z.ZodDefault<z.ZodBoolean>;
21
+ }, z.core.$strip>;
22
+ type DelayNodeConfig = z.infer<typeof DelayNodeConfigSchema>;
23
+ declare const DelayResultSchema: z.ZodUnion<readonly [z.ZodObject<{
24
+ selectedOutputIndex: z.ZodLiteral<0>;
25
+ outputs: z.ZodTuple<[z.ZodObject<{
26
+ items: z.ZodTuple<[z.ZodType<_framefields_core0.OutputItem<"Audio">, unknown, z.core.$ZodTypeInternals<_framefields_core0.OutputItem<"Audio">, unknown>>], null>;
27
+ }, z.core.$strip>], null>;
28
+ }, z.core.$strip>, z.ZodObject<{
29
+ selectedOutputIndex: z.ZodLiteral<0>;
30
+ outputs: z.ZodTuple<[z.ZodObject<{
31
+ items: z.ZodTuple<[z.ZodType<_framefields_core0.OutputItem<"Video">, unknown, z.core.$ZodTypeInternals<_framefields_core0.OutputItem<"Video">, unknown>>], null>;
32
+ }, z.core.$strip>], null>;
33
+ }, z.core.$strip>]>;
34
+ type DelayResult = z.infer<typeof DelayResultSchema>;
35
+ declare const DELAY_OUTPUT_TYPE_MAP: Record<string, "Audio" | "Video">;
36
+ //#endregion
37
+ export { DELAY_OUTPUT_TYPE_MAP, DelayNodeConfig, DelayNodeConfigSchema, DelayResult, DelayResultSchema, delayConfig };
38
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/shared/config.ts"],"sourcesContent":[],"mappings":";;;;;cAOa;;;;IAAA,GAAA,cAkCJ,YAAA,CAAA;;;;;cAEI,uBAAqB,CAAA,CAAA;;;;;;;KAEtB,eAAA,GAAkB,CAAA,CAAE,aAAa;cAEhC,mBAAiB,CAAA,CAAA,mBAAA,CAAA,CAAA;EAJjB,mBAAA,cAA0C,CAAA,CAAA,CAAA;;;;;;;;;;KAS3C,WAAA,GAAc,CAAA,CAAE,aAAa;cAE5B,uBAAuB"}
package/dist/index.mjs ADDED
@@ -0,0 +1,40 @@
1
+ import "./renderers-zDTlg6EZ.mjs";
2
+ import { AudioResultSchema, VideoResultSchema, configBuilder } from "@framefields/node-sdk";
3
+ import { z } from "zod";
4
+
5
+ //#region src/shared/config.ts
6
+ const delayConfig = configBuilder().field("delayTime", z.number().min(.001).max(5).default(.25), {
7
+ bindable: true,
8
+ dataTypes: ["Number", "Signal"],
9
+ label: "Delay Time Signal",
10
+ description: "Delay time in seconds (0.001 to 5.0s). Can be modulated by a static number or dynamic signal."
11
+ }).field("feedback", z.number().min(0).max(.95).default(.4), {
12
+ bindable: true,
13
+ dataTypes: ["Number", "Signal"],
14
+ label: "Feedback Signal",
15
+ description: "Amount of delayed signal fed back into delay line (0.0 to 0.95). Can be modulated by a static number or dynamic signal."
16
+ }).field("wet", z.number().min(0).max(1).default(.3), {
17
+ bindable: true,
18
+ dataTypes: ["Number", "Signal"],
19
+ label: "Wet Mix Signal",
20
+ description: "Mix level of the wet delayed signal (0.0 to 1.0). Can be modulated by a static number or dynamic signal."
21
+ }).field("dry", z.number().min(0).max(1).default(1), {
22
+ bindable: true,
23
+ dataTypes: ["Number", "Signal"],
24
+ label: "Dry Mix Signal",
25
+ description: "Mix level of the original dry signal (0.0 to 1.0). Can be modulated by a static number or dynamic signal."
26
+ }).field("pingPong", z.boolean().default(false), {
27
+ bindable: false,
28
+ label: "Ping Pong Mode",
29
+ description: "Alternates echo reflections between left and right channels"
30
+ }).build();
31
+ const DelayNodeConfigSchema = delayConfig.schema;
32
+ const DelayResultSchema = z.union([AudioResultSchema, VideoResultSchema]);
33
+ const DELAY_OUTPUT_TYPE_MAP = {
34
+ Audio: "Audio",
35
+ Video: "Video"
36
+ };
37
+
38
+ //#endregion
39
+ export { DELAY_OUTPUT_TYPE_MAP, DelayNodeConfigSchema, DelayResultSchema, delayConfig };
40
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../src/shared/config.ts"],"sourcesContent":["import {\n\tAudioResultSchema,\n\tconfigBuilder,\n\tVideoResultSchema,\n} from \"@framefields/node-sdk\";\nimport { z } from \"zod\";\n\nexport const delayConfig = configBuilder()\n\t.field(\"delayTime\", z.number().min(0.001).max(5.0).default(0.25), {\n\t\tbindable: true,\n\t\tdataTypes: [\"Number\", \"Signal\"],\n\t\tlabel: \"Delay Time Signal\",\n\t\tdescription:\n\t\t\t\"Delay time in seconds (0.001 to 5.0s). Can be modulated by a static number or dynamic signal.\",\n\t})\n\t.field(\"feedback\", z.number().min(0.0).max(0.95).default(0.4), {\n\t\tbindable: true,\n\t\tdataTypes: [\"Number\", \"Signal\"],\n\t\tlabel: \"Feedback Signal\",\n\t\tdescription:\n\t\t\t\"Amount of delayed signal fed back into delay line (0.0 to 0.95). Can be modulated by a static number or dynamic signal.\",\n\t})\n\t.field(\"wet\", z.number().min(0.0).max(1.0).default(0.3), {\n\t\tbindable: true,\n\t\tdataTypes: [\"Number\", \"Signal\"],\n\t\tlabel: \"Wet Mix Signal\",\n\t\tdescription:\n\t\t\t\"Mix level of the wet delayed signal (0.0 to 1.0). Can be modulated by a static number or dynamic signal.\",\n\t})\n\t.field(\"dry\", z.number().min(0.0).max(1.0).default(1.0), {\n\t\tbindable: true,\n\t\tdataTypes: [\"Number\", \"Signal\"],\n\t\tlabel: \"Dry Mix Signal\",\n\t\tdescription:\n\t\t\t\"Mix level of the original dry signal (0.0 to 1.0). Can be modulated by a static number or dynamic signal.\",\n\t})\n\t.field(\"pingPong\", z.boolean().default(false), {\n\t\tbindable: false,\n\t\tlabel: \"Ping Pong Mode\",\n\t\tdescription: \"Alternates echo reflections between left and right channels\",\n\t})\n\t.build();\n\nexport const DelayNodeConfigSchema = delayConfig.schema;\n\nexport type DelayNodeConfig = z.infer<typeof DelayNodeConfigSchema>;\n\nexport const DelayResultSchema = z.union([\n\tAudioResultSchema,\n\tVideoResultSchema,\n]);\n\nexport type DelayResult = z.infer<typeof DelayResultSchema>;\n\nexport const DELAY_OUTPUT_TYPE_MAP: Record<string, \"Audio\" | \"Video\"> = {\n\tAudio: \"Audio\",\n\tVideo: \"Video\",\n};\n"],"mappings":";;;;;AAOA,MAAa,cAAc,eAAe,CACxC,MAAM,aAAa,EAAE,QAAQ,CAAC,IAAI,KAAM,CAAC,IAAI,EAAI,CAAC,QAAQ,IAAK,EAAE;CACjE,UAAU;CACV,WAAW,CAAC,UAAU,SAAS;CAC/B,OAAO;CACP,aACC;CACD,CAAC,CACD,MAAM,YAAY,EAAE,QAAQ,CAAC,IAAI,EAAI,CAAC,IAAI,IAAK,CAAC,QAAQ,GAAI,EAAE;CAC9D,UAAU;CACV,WAAW,CAAC,UAAU,SAAS;CAC/B,OAAO;CACP,aACC;CACD,CAAC,CACD,MAAM,OAAO,EAAE,QAAQ,CAAC,IAAI,EAAI,CAAC,IAAI,EAAI,CAAC,QAAQ,GAAI,EAAE;CACxD,UAAU;CACV,WAAW,CAAC,UAAU,SAAS;CAC/B,OAAO;CACP,aACC;CACD,CAAC,CACD,MAAM,OAAO,EAAE,QAAQ,CAAC,IAAI,EAAI,CAAC,IAAI,EAAI,CAAC,QAAQ,EAAI,EAAE;CACxD,UAAU;CACV,WAAW,CAAC,UAAU,SAAS;CAC/B,OAAO;CACP,aACC;CACD,CAAC,CACD,MAAM,YAAY,EAAE,SAAS,CAAC,QAAQ,MAAM,EAAE;CAC9C,UAAU;CACV,OAAO;CACP,aAAa;CACb,CAAC,CACD,OAAO;AAET,MAAa,wBAAwB,YAAY;AAIjD,MAAa,oBAAoB,EAAE,MAAM,CACxC,mBACA,kBACA,CAAC;AAIF,MAAa,wBAA2D;CACvE,OAAO;CACP,OAAO;CACP"}
@@ -0,0 +1,7 @@
1
+ import * as _framefields_node_sdk_renderer0 from "@framefields/node-sdk/renderer";
2
+
3
+ //#region src/renderers/index.d.ts
4
+ declare const _default: Readonly<_framefields_node_sdk_renderer0.NodeRendererPlugin>;
5
+ //#endregion
6
+ export { _default as default };
7
+ //# sourceMappingURL=renderer.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"renderer.d.mts","names":[],"sources":["../src/renderers/index.ts"],"sourcesContent":[],"mappings":""}
@@ -0,0 +1,3 @@
1
+ import { t as renderers_default } from "./renderers-zDTlg6EZ.mjs";
2
+
3
+ export { renderers_default as default };
@@ -0,0 +1,229 @@
1
+ import { defineRenderer } from "@framefields/node-sdk/renderer";
2
+ import { WebGPUAudioProcessor } from "@framefields/webgpu-renderers";
3
+
4
+ //#region src/renderers/audio-processor.ts
5
+ const PARAM_ORDER = [
6
+ "delayTime",
7
+ "feedback",
8
+ "wet",
9
+ "dry"
10
+ ];
11
+ const DELAY_SHADER_TEMPLATE = () => `
12
+ struct Uniforms {
13
+ sampleRate : f32,
14
+ delaySec : f32,
15
+ feedback : f32,
16
+ wet : f32,
17
+ dry : f32,
18
+ pingPong : f32,
19
+ bufferLength : f32,
20
+ hasDelayTimeSig : f32,
21
+ hasFeedbackSig : f32,
22
+ hasWetSig : f32,
23
+ hasDrySig : f32,
24
+ baseTime : f32,
25
+ frame : f32,
26
+ numSamples : f32,
27
+ numChannels : f32,
28
+ pad1 : f32,
29
+ };
30
+
31
+ @group(0) @binding(0) var<uniform> u : Uniforms;
32
+ @group(0) @binding(1) var<storage, read> inputChannels : array<f32>;
33
+ @group(0) @binding(2) var<storage, read_write> outputChannels : array<f32>;
34
+ @group(0) @binding(3) var<storage, read_write> state : array<f32>;
35
+ @group(0) @binding(4) var<storage, read> delayTimeSignal : array<f32>;
36
+ @group(0) @binding(5) var<storage, read> feedbackSignal : array<f32>;
37
+ @group(0) @binding(6) var<storage, read> wetSignal : array<f32>;
38
+ @group(0) @binding(7) var<storage, read> drySignal : array<f32>;
39
+
40
+ fn tanh(x: f32) -> f32 {
41
+ let exp2x = exp(2.0f * x);
42
+ return (exp2x - 1.0f) / (exp2x + 1.0f);
43
+ }
44
+
45
+ fn is_nan_or_inf(v: f32) -> bool {
46
+ return (v != v) || (abs(v) > 3.402823466e+38f);
47
+ }
48
+
49
+ @compute @workgroup_size(1)
50
+ fn main(@builtin(global_invocation_id) gid : vec3<u32>) {
51
+ if (gid.x != 0u) { return; }
52
+
53
+ let numSamples = u32(u.numSamples);
54
+ let numChannels = u32(u.numChannels);
55
+ let bufferLength = u32(u.bufferLength);
56
+
57
+ var writeIndex = u32(state[0]);
58
+ if (is_nan_or_inf(state[0])) {
59
+ writeIndex = 0u;
60
+ }
61
+
62
+ for (var index = 0u; index < numSamples; index = index + 1u) {
63
+ // 1. Dynamic Parameter Modulation & Anti-Explosion Clamping
64
+ var effDelaySec = u.delaySec;
65
+ if (u.hasDelayTimeSig > 0.5f) {
66
+ effDelaySec = delayTimeSignal[index];
67
+ }
68
+ effDelaySec = clamp(effDelaySec, 0.001f, 5.0f);
69
+
70
+ var effFeedback = u.feedback;
71
+ if (u.hasFeedbackSig > 0.5f) {
72
+ effFeedback = feedbackSignal[index];
73
+ }
74
+ effFeedback = clamp(effFeedback, 0.0f, 0.95f);
75
+
76
+ var effWet = u.wet;
77
+ if (u.hasWetSig > 0.5f) {
78
+ effWet = wetSignal[index];
79
+ }
80
+ effWet = clamp(effWet, 0.0f, 2.0f);
81
+
82
+ var effDry = u.dry;
83
+ if (u.hasDrySig > 0.5f) {
84
+ effDry = drySignal[index];
85
+ }
86
+ effDry = clamp(effDry, 0.0f, 2.0f);
87
+
88
+ // 2. Safe Dynamic Read Index
89
+ let readOffset = u32(clamp(effDelaySec * u.sampleRate, 1.0f, f32(bufferLength - 1u)));
90
+ let readIndex = (writeIndex + bufferLength - readOffset) % bufferLength;
91
+
92
+ if (numChannels == 1u || u.pingPong == 0.0f) {
93
+ // Standard Delay
94
+ for (var c = 0u; c < numChannels; c = c + 1u) {
95
+ let sampleIndex = c * numSamples + index;
96
+ var inputVal = inputChannels[sampleIndex];
97
+ if (is_nan_or_inf(inputVal)) {
98
+ inputVal = 0.0f;
99
+ }
100
+
101
+ let stateOffset = c * bufferLength + 1u;
102
+ var delayedSample = state[stateOffset + readIndex];
103
+ if (is_nan_or_inf(delayedSample)) {
104
+ delayedSample = 0.0f;
105
+ }
106
+
107
+ var nextStateVal = inputVal + delayedSample * effFeedback;
108
+ if (is_nan_or_inf(nextStateVal)) {
109
+ nextStateVal = 0.0f;
110
+ }
111
+ state[stateOffset + writeIndex] = clamp(nextStateVal, -4.0f, 4.0f);
112
+
113
+ var outVal = effDry * inputVal + effWet * delayedSample;
114
+ if (is_nan_or_inf(outVal)) {
115
+ outVal = 0.0f;
116
+ }
117
+ if (outVal > 1.0f) {
118
+ outVal = 1.0f;
119
+ } else if (outVal < -1.0f) {
120
+ outVal = -1.0f;
121
+ } else if (outVal > 0.9f) {
122
+ outVal = 0.9f + 0.1f * tanh((outVal - 0.9f) / 0.1f);
123
+ } else if (outVal < -0.9f) {
124
+ outVal = -0.9f + 0.1f * tanh((outVal + 0.9f) / 0.1f);
125
+ }
126
+
127
+ outputChannels[sampleIndex] = outVal;
128
+ }
129
+ } else {
130
+ // Stereo Ping-Pong Delay
131
+ var sampleL = inputChannels[index];
132
+ if (is_nan_or_inf(sampleL)) { sampleL = 0.0f; }
133
+
134
+ var sampleR = inputChannels[numSamples + index];
135
+ if (is_nan_or_inf(sampleR)) { sampleR = 0.0f; }
136
+
137
+ var delayedL = state[1u + readIndex];
138
+ if (is_nan_or_inf(delayedL)) { delayedL = 0.0f; }
139
+
140
+ var delayedR = state[bufferLength + 1u + readIndex];
141
+ if (is_nan_or_inf(delayedR)) { delayedR = 0.0f; }
142
+
143
+ // Ping-pong cross-feedback
144
+ var nextL = sampleL + delayedR * effFeedback;
145
+ var nextR = sampleR + delayedL * effFeedback;
146
+ if (is_nan_or_inf(nextL)) { nextL = 0.0f; }
147
+ if (is_nan_or_inf(nextR)) { nextR = 0.0f; }
148
+
149
+ state[1u + writeIndex] = clamp(nextL, -4.0f, 4.0f);
150
+ state[bufferLength + 1u + writeIndex] = clamp(nextR, -4.0f, 4.0f);
151
+
152
+ var outL = effDry * sampleL + effWet * delayedL;
153
+ var outR = effDry * sampleR + effWet * delayedR;
154
+ if (is_nan_or_inf(outL)) { outL = 0.0f; }
155
+ if (is_nan_or_inf(outR)) { outR = 0.0f; }
156
+
157
+ if (outL > 1.0f) { outL = 1.0f; } else if (outL < -1.0f) { outL = -1.0f; }
158
+ else if (outL > 0.9f) { outL = 0.9f + 0.1f * tanh((outL - 0.9f) / 0.1f); }
159
+ else if (outL < -0.9f) { outL = -0.9f + 0.1f * tanh((outL + 0.9f) / 0.1f); }
160
+
161
+ if (outR > 1.0f) { outR = 1.0f; } else if (outR < -1.0f) { outR = -1.0f; }
162
+ else if (outR > 0.9f) { outR = 0.9f + 0.1f * tanh((outR - 0.9f) / 0.1f); }
163
+ else if (outR < -0.9f) { outR = -0.9f + 0.1f * tanh((outR + 0.9f) / 0.1f); }
164
+
165
+ outputChannels[index] = outL;
166
+ outputChannels[numSamples + index] = outR;
167
+ }
168
+
169
+ writeIndex = (writeIndex + 1u) % bufferLength;
170
+ }
171
+
172
+ state[0] = f32(writeIndex);
173
+ }
174
+ `;
175
+ const delayAudioProcessor = async (channels, sampleRate, virtualMedia, ctx) => {
176
+ if (!ctx?.device) throw new Error("GPUDevice is required for WebGPU Audio Delay.");
177
+ const op = virtualMedia.operation || {};
178
+ const inputs = op.inputs || {};
179
+ const numChannels = channels.length;
180
+ if (numChannels === 0) return;
181
+ const numSamples = channels[0].length;
182
+ if (numSamples === 0) return;
183
+ const delaySec = Math.max(.001, Math.min(typeof op.delayTime === "number" ? op.delayTime : .25, 5));
184
+ const feedbackInternal = Math.max(0, Math.min(typeof op.feedback === "number" ? op.feedback : .4, .95));
185
+ const wetInternal = Math.max(0, Math.min(typeof op.wet === "number" ? op.wet : .3, 1));
186
+ const dryInternal = Math.max(0, Math.min(typeof op.dry === "number" ? op.dry : 1, 1));
187
+ const pingPongInternal = typeof op.pingPong === "boolean" ? op.pingPong : false;
188
+ const isHandleConnected = (handleIdKey) => {
189
+ const handleId = op[handleIdKey];
190
+ if (typeof handleId !== "string" || !handleId) return false;
191
+ const input = inputs[handleId];
192
+ return Boolean(input?.connectionValid && input.outputItem && (input.outputItem.type === "Signal" || input.outputItem.type === "Number"));
193
+ };
194
+ const hasDelayTimeSig = isHandleConnected("delayTimeHandleId") ? 1 : 0;
195
+ const hasFeedbackSig = isHandleConnected("feedbackHandleId") ? 1 : 0;
196
+ const hasWetSig = isHandleConnected("wetHandleId") ? 1 : 0;
197
+ const hasDrySig = isHandleConnected("dryHandleId") ? 1 : 0;
198
+ const bufferLength = Math.ceil(5 * sampleRate);
199
+ const nodeId = op.id || "audio-delay";
200
+ const frame = ctx.frame ?? 0;
201
+ const fps = ctx.fps ?? 24;
202
+ const stateFloatCount = numChannels * bufferLength + 1;
203
+ await WebGPUAudioProcessor.process(ctx.device, nodeId, channels, sampleRate, virtualMedia, frame, fps, DELAY_SHADER_TEMPLATE, () => [
204
+ sampleRate,
205
+ delaySec,
206
+ feedbackInternal,
207
+ wetInternal,
208
+ dryInternal,
209
+ pingPongInternal ? 1 : 0,
210
+ bufferLength,
211
+ hasDelayTimeSig,
212
+ hasFeedbackSig,
213
+ hasWetSig,
214
+ hasDrySig,
215
+ 0,
216
+ frame,
217
+ numSamples,
218
+ numChannels,
219
+ 0
220
+ ], 16, stateFloatCount, ctx?.renderId, true, ctx?.elapsedMs, ctx?.durationMs, void 0, void 0, PARAM_ORDER);
221
+ };
222
+
223
+ //#endregion
224
+ //#region src/renderers/index.ts
225
+ var renderers_default = defineRenderer({ audioProcessor: delayAudioProcessor });
226
+
227
+ //#endregion
228
+ export { renderers_default as t };
229
+ //# sourceMappingURL=renderers-zDTlg6EZ.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"renderers-zDTlg6EZ.mjs","names":[],"sources":["../src/renderers/audio-processor.ts","../src/renderers/index.ts"],"sourcesContent":["import type { AudioProcessor } from \"@framefields/node-sdk\";\nimport { WebGPUAudioProcessor } from \"@framefields/webgpu-renderers\";\n\nconst PARAM_ORDER = [\"delayTime\", \"feedback\", \"wet\", \"dry\"];\n\nconst DELAY_SHADER_TEMPLATE = () => `\nstruct Uniforms {\n sampleRate : f32,\n delaySec : f32,\n feedback : f32,\n wet : f32,\n dry : f32,\n pingPong : f32,\n bufferLength : f32,\n hasDelayTimeSig : f32,\n hasFeedbackSig : f32,\n hasWetSig : f32,\n hasDrySig : f32,\n baseTime : f32,\n frame : f32,\n numSamples : f32,\n numChannels : f32,\n pad1 : f32,\n};\n\n@group(0) @binding(0) var<uniform> u : Uniforms;\n@group(0) @binding(1) var<storage, read> inputChannels : array<f32>;\n@group(0) @binding(2) var<storage, read_write> outputChannels : array<f32>;\n@group(0) @binding(3) var<storage, read_write> state : array<f32>;\n@group(0) @binding(4) var<storage, read> delayTimeSignal : array<f32>;\n@group(0) @binding(5) var<storage, read> feedbackSignal : array<f32>;\n@group(0) @binding(6) var<storage, read> wetSignal : array<f32>;\n@group(0) @binding(7) var<storage, read> drySignal : array<f32>;\n\nfn tanh(x: f32) -> f32 {\n let exp2x = exp(2.0f * x);\n return (exp2x - 1.0f) / (exp2x + 1.0f);\n}\n\nfn is_nan_or_inf(v: f32) -> bool {\n return (v != v) || (abs(v) > 3.402823466e+38f);\n}\n\n@compute @workgroup_size(1)\nfn main(@builtin(global_invocation_id) gid : vec3<u32>) {\n if (gid.x != 0u) { return; }\n\n let numSamples = u32(u.numSamples);\n let numChannels = u32(u.numChannels);\n let bufferLength = u32(u.bufferLength);\n\n var writeIndex = u32(state[0]);\n if (is_nan_or_inf(state[0])) {\n writeIndex = 0u;\n }\n\n for (var index = 0u; index < numSamples; index = index + 1u) {\n // 1. Dynamic Parameter Modulation & Anti-Explosion Clamping\n var effDelaySec = u.delaySec;\n if (u.hasDelayTimeSig > 0.5f) {\n effDelaySec = delayTimeSignal[index];\n }\n effDelaySec = clamp(effDelaySec, 0.001f, 5.0f);\n\n var effFeedback = u.feedback;\n if (u.hasFeedbackSig > 0.5f) {\n effFeedback = feedbackSignal[index];\n }\n effFeedback = clamp(effFeedback, 0.0f, 0.95f);\n\n var effWet = u.wet;\n if (u.hasWetSig > 0.5f) {\n effWet = wetSignal[index];\n }\n effWet = clamp(effWet, 0.0f, 2.0f);\n\n var effDry = u.dry;\n if (u.hasDrySig > 0.5f) {\n effDry = drySignal[index];\n }\n effDry = clamp(effDry, 0.0f, 2.0f);\n\n // 2. Safe Dynamic Read Index\n let readOffset = u32(clamp(effDelaySec * u.sampleRate, 1.0f, f32(bufferLength - 1u)));\n let readIndex = (writeIndex + bufferLength - readOffset) % bufferLength;\n\n if (numChannels == 1u || u.pingPong == 0.0f) {\n // Standard Delay\n for (var c = 0u; c < numChannels; c = c + 1u) {\n let sampleIndex = c * numSamples + index;\n var inputVal = inputChannels[sampleIndex];\n if (is_nan_or_inf(inputVal)) {\n inputVal = 0.0f;\n }\n\n let stateOffset = c * bufferLength + 1u;\n var delayedSample = state[stateOffset + readIndex];\n if (is_nan_or_inf(delayedSample)) {\n delayedSample = 0.0f;\n }\n\n var nextStateVal = inputVal + delayedSample * effFeedback;\n if (is_nan_or_inf(nextStateVal)) {\n nextStateVal = 0.0f;\n }\n state[stateOffset + writeIndex] = clamp(nextStateVal, -4.0f, 4.0f);\n\n var outVal = effDry * inputVal + effWet * delayedSample;\n if (is_nan_or_inf(outVal)) {\n outVal = 0.0f;\n }\n if (outVal > 1.0f) {\n outVal = 1.0f;\n } else if (outVal < -1.0f) {\n outVal = -1.0f;\n } else if (outVal > 0.9f) {\n outVal = 0.9f + 0.1f * tanh((outVal - 0.9f) / 0.1f);\n } else if (outVal < -0.9f) {\n outVal = -0.9f + 0.1f * tanh((outVal + 0.9f) / 0.1f);\n }\n\n outputChannels[sampleIndex] = outVal;\n }\n } else {\n // Stereo Ping-Pong Delay\n var sampleL = inputChannels[index];\n if (is_nan_or_inf(sampleL)) { sampleL = 0.0f; }\n\n var sampleR = inputChannels[numSamples + index];\n if (is_nan_or_inf(sampleR)) { sampleR = 0.0f; }\n\n var delayedL = state[1u + readIndex];\n if (is_nan_or_inf(delayedL)) { delayedL = 0.0f; }\n\n var delayedR = state[bufferLength + 1u + readIndex];\n if (is_nan_or_inf(delayedR)) { delayedR = 0.0f; }\n\n // Ping-pong cross-feedback\n var nextL = sampleL + delayedR * effFeedback;\n var nextR = sampleR + delayedL * effFeedback;\n if (is_nan_or_inf(nextL)) { nextL = 0.0f; }\n if (is_nan_or_inf(nextR)) { nextR = 0.0f; }\n\n state[1u + writeIndex] = clamp(nextL, -4.0f, 4.0f);\n state[bufferLength + 1u + writeIndex] = clamp(nextR, -4.0f, 4.0f);\n\n var outL = effDry * sampleL + effWet * delayedL;\n var outR = effDry * sampleR + effWet * delayedR;\n if (is_nan_or_inf(outL)) { outL = 0.0f; }\n if (is_nan_or_inf(outR)) { outR = 0.0f; }\n\n if (outL > 1.0f) { outL = 1.0f; } else if (outL < -1.0f) { outL = -1.0f; }\n else if (outL > 0.9f) { outL = 0.9f + 0.1f * tanh((outL - 0.9f) / 0.1f); }\n else if (outL < -0.9f) { outL = -0.9f + 0.1f * tanh((outL + 0.9f) / 0.1f); }\n\n if (outR > 1.0f) { outR = 1.0f; } else if (outR < -1.0f) { outR = -1.0f; }\n else if (outR > 0.9f) { outR = 0.9f + 0.1f * tanh((outR - 0.9f) / 0.1f); }\n else if (outR < -0.9f) { outR = -0.9f + 0.1f * tanh((outR + 0.9f) / 0.1f); }\n\n outputChannels[index] = outL;\n outputChannels[numSamples + index] = outR;\n }\n\n writeIndex = (writeIndex + 1u) % bufferLength;\n }\n\n state[0] = f32(writeIndex);\n}\n`;\n\nexport const delayAudioProcessor: AudioProcessor = async (\n\tchannels,\n\tsampleRate,\n\tvirtualMedia,\n\tctx,\n) => {\n\tif (!ctx?.device) {\n\t\tthrow new Error(\"GPUDevice is required for WebGPU Audio Delay.\");\n\t}\n\n\tconst op = (virtualMedia.operation as Record<string, unknown>) || {};\n\tconst inputs = (op.inputs as Record<string, any>) || {};\n\n\tconst numChannels = channels.length;\n\tif (numChannels === 0) return;\n\tconst numSamples = channels[0].length;\n\tif (numSamples === 0) return;\n\n\t// Clamp and extract parameters\n\tconst delaySec = Math.max(\n\t\t0.001,\n\t\tMath.min(typeof op.delayTime === \"number\" ? op.delayTime : 0.25, 5.0),\n\t);\n\tconst feedbackInternal = Math.max(\n\t\t0.0,\n\t\tMath.min(typeof op.feedback === \"number\" ? op.feedback : 0.4, 0.95),\n\t);\n\tconst wetInternal = Math.max(\n\t\t0.0,\n\t\tMath.min(typeof op.wet === \"number\" ? op.wet : 0.3, 1.0),\n\t);\n\tconst dryInternal = Math.max(\n\t\t0.0,\n\t\tMath.min(typeof op.dry === \"number\" ? op.dry : 1.0, 1.0),\n\t);\n\tconst pingPongInternal =\n\t\ttypeof op.pingPong === \"boolean\" ? op.pingPong : false;\n\n\tconst isHandleConnected = (handleIdKey: string): boolean => {\n\t\tconst handleId = op[handleIdKey];\n\t\tif (typeof handleId !== \"string\" || !handleId) return false;\n\t\tconst input = inputs[handleId];\n\t\treturn Boolean(\n\t\t\tinput?.connectionValid &&\n\t\t\t\tinput.outputItem &&\n\t\t\t\t(input.outputItem.type === \"Signal\" ||\n\t\t\t\t\tinput.outputItem.type === \"Number\"),\n\t\t);\n\t};\n\n\tconst hasDelayTimeSig = isHandleConnected(\"delayTimeHandleId\") ? 1.0 : 0.0;\n\tconst hasFeedbackSig = isHandleConnected(\"feedbackHandleId\") ? 1.0 : 0.0;\n\tconst hasWetSig = isHandleConnected(\"wetHandleId\") ? 1.0 : 0.0;\n\tconst hasDrySig = isHandleConnected(\"dryHandleId\") ? 1.0 : 0.0;\n\n\t// Allocate max possible delay buffer (5 seconds) to allow smooth dynamic modulation\n\tconst maxDelaySec = 5.0;\n\tconst bufferLength = Math.ceil(maxDelaySec * sampleRate);\n\n\t// 100% WebGPU Compute Path\n\tconst nodeId = (op.id as string) || \"audio-delay\";\n\tconst frame = ctx.frame ?? 0;\n\tconst fps = ctx.fps ?? 24;\n\n\tconst stateFloatCount = numChannels * bufferLength + 1;\n\n\tawait WebGPUAudioProcessor.process(\n\t\tctx.device,\n\t\tnodeId,\n\t\tchannels,\n\t\tsampleRate,\n\t\tvirtualMedia,\n\t\tframe,\n\t\tfps,\n\t\tDELAY_SHADER_TEMPLATE,\n\t\t() => [\n\t\t\tsampleRate,\n\t\t\tdelaySec,\n\t\t\tfeedbackInternal,\n\t\t\twetInternal,\n\t\t\tdryInternal,\n\t\t\tpingPongInternal ? 1.0 : 0.0,\n\t\t\tbufferLength,\n\t\t\thasDelayTimeSig,\n\t\t\thasFeedbackSig,\n\t\t\thasWetSig,\n\t\t\thasDrySig,\n\t\t\t0.0, // baseTime\n\t\t\tframe,\n\t\t\tnumSamples,\n\t\t\tnumChannels,\n\t\t\t0, // padding\n\t\t],\n\t\t16, // Aligned to 16 bytes (16 * 4 = 64 bytes)\n\t\tstateFloatCount, // Persistent Ring Buffer state\n\t\tctx?.renderId,\n\t\ttrue,\n\t\tctx?.elapsedMs,\n\t\tctx?.durationMs,\n\t\tundefined,\n\t\tundefined,\n\t\tPARAM_ORDER,\n\t);\n};\n","import { defineRenderer } from \"@framefields/node-sdk/renderer\";\nimport { delayAudioProcessor } from \"./audio-processor.js\";\n\nexport default defineRenderer({\n\taudioProcessor: delayAudioProcessor,\n});\n"],"mappings":";;;;AAGA,MAAM,cAAc;CAAC;CAAa;CAAY;CAAO;CAAM;AAE3D,MAAM,8BAA8B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqKpC,MAAa,sBAAsC,OAClD,UACA,YACA,cACA,QACI;AACJ,KAAI,CAAC,KAAK,OACT,OAAM,IAAI,MAAM,gDAAgD;CAGjE,MAAM,KAAM,aAAa,aAAyC,EAAE;CACpE,MAAM,SAAU,GAAG,UAAkC,EAAE;CAEvD,MAAM,cAAc,SAAS;AAC7B,KAAI,gBAAgB,EAAG;CACvB,MAAM,aAAa,SAAS,GAAG;AAC/B,KAAI,eAAe,EAAG;CAGtB,MAAM,WAAW,KAAK,IACrB,MACA,KAAK,IAAI,OAAO,GAAG,cAAc,WAAW,GAAG,YAAY,KAAM,EAAI,CACrE;CACD,MAAM,mBAAmB,KAAK,IAC7B,GACA,KAAK,IAAI,OAAO,GAAG,aAAa,WAAW,GAAG,WAAW,IAAK,IAAK,CACnE;CACD,MAAM,cAAc,KAAK,IACxB,GACA,KAAK,IAAI,OAAO,GAAG,QAAQ,WAAW,GAAG,MAAM,IAAK,EAAI,CACxD;CACD,MAAM,cAAc,KAAK,IACxB,GACA,KAAK,IAAI,OAAO,GAAG,QAAQ,WAAW,GAAG,MAAM,GAAK,EAAI,CACxD;CACD,MAAM,mBACL,OAAO,GAAG,aAAa,YAAY,GAAG,WAAW;CAElD,MAAM,qBAAqB,gBAAiC;EAC3D,MAAM,WAAW,GAAG;AACpB,MAAI,OAAO,aAAa,YAAY,CAAC,SAAU,QAAO;EACtD,MAAM,QAAQ,OAAO;AACrB,SAAO,QACN,OAAO,mBACN,MAAM,eACL,MAAM,WAAW,SAAS,YAC1B,MAAM,WAAW,SAAS,UAC5B;;CAGF,MAAM,kBAAkB,kBAAkB,oBAAoB,GAAG,IAAM;CACvE,MAAM,iBAAiB,kBAAkB,mBAAmB,GAAG,IAAM;CACrE,MAAM,YAAY,kBAAkB,cAAc,GAAG,IAAM;CAC3D,MAAM,YAAY,kBAAkB,cAAc,GAAG,IAAM;CAI3D,MAAM,eAAe,KAAK,KADN,IACyB,WAAW;CAGxD,MAAM,SAAU,GAAG,MAAiB;CACpC,MAAM,QAAQ,IAAI,SAAS;CAC3B,MAAM,MAAM,IAAI,OAAO;CAEvB,MAAM,kBAAkB,cAAc,eAAe;AAErD,OAAM,qBAAqB,QAC1B,IAAI,QACJ,QACA,UACA,YACA,cACA,OACA,KACA,6BACM;EACL;EACA;EACA;EACA;EACA;EACA,mBAAmB,IAAM;EACzB;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,EACD,IACA,iBACA,KAAK,UACL,MACA,KAAK,WACL,KAAK,YACL,QACA,QACA,YACA;;;;;AC7QF,wBAAe,eAAe,EAC7B,gBAAgB,qBAChB,CAAC"}
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "@framefields/node-audio-delay",
3
+ "version": "2.0.2",
4
+ "license": "Apache-2.0",
5
+ "private": false,
6
+ "framefields": {
7
+ "type": "AudioDelay",
8
+ "kind": "audio"
9
+ },
10
+ "type": "module",
11
+ "module": "./dist/index.mjs",
12
+ "types": "./dist/index.d.mts",
13
+ "exports": {
14
+ ".": {
15
+ "types": "./dist/index.d.mts",
16
+ "development": "./src/index.ts",
17
+ "import": "./dist/index.mjs",
18
+ "default": "./dist/index.mjs"
19
+ },
20
+ "./renderer": {
21
+ "types": "./dist/renderer.d.mts",
22
+ "development": "./src/renderers/index.ts",
23
+ "import": "./dist/renderer.mjs",
24
+ "default": "./dist/renderer.mjs"
25
+ }
26
+ },
27
+ "dependencies": {
28
+ "zod": "^4.3.6",
29
+ "@framefields/core": "2.0.2",
30
+ "@framefields/webgpu-renderers": "2.0.2",
31
+ "@framefields/node-sdk": "2.0.2"
32
+ },
33
+ "devDependencies": {
34
+ "@types/node": "^24.1.0",
35
+ "tsdown": "^0.19.0",
36
+ "typescript": "^5.8.3",
37
+ "vitest": "^4.1.5",
38
+ "@framefields/tsconfig": "2.0.2"
39
+ },
40
+ "publishConfig": {
41
+ "access": "public"
42
+ },
43
+ "scripts": {
44
+ "build": "tsdown",
45
+ "dev": "tsdown --watch",
46
+ "clean": "rm -rf dist"
47
+ }
48
+ }
package/src/index.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from "./shared/index.js";
2
+ export * from "./renderers/index.js";
@@ -0,0 +1,136 @@
1
+ import type { VirtualMediaData } from "@framefields/core";
2
+ import { ensureDevice } from "@framefields/webgpu-renderers";
3
+ import { describe, expect, it } from "vitest";
4
+ import { delayAudioProcessor } from "./audio-processor.js";
5
+
6
+ const createVirtualMedia = (overrides = {}): VirtualMediaData =>
7
+ ({
8
+ id: "test-delay-media",
9
+ type: "audio",
10
+ operation: {
11
+ delayTime: 0.25,
12
+ feedback: 0.4,
13
+ wet: 0.3,
14
+ dry: 1.0,
15
+ pingPong: false,
16
+ ...overrides,
17
+ },
18
+ }) as unknown as VirtualMediaData;
19
+
20
+ const createChannels = (
21
+ numSamples: number,
22
+ amplitude: number,
23
+ stereo = false,
24
+ ): Float32Array[] => {
25
+ if (stereo) {
26
+ const left = new Float32Array(numSamples).map(
27
+ (_, idx) => Math.sin(idx * 0.05) * amplitude,
28
+ );
29
+ const right = new Float32Array(numSamples).map(
30
+ (_, idx) => Math.cos(idx * 0.05) * amplitude,
31
+ );
32
+ return [left, right];
33
+ }
34
+ const channel = new Float32Array(numSamples).fill(amplitude);
35
+ return [channel];
36
+ };
37
+
38
+ describe("Delay Audio Processor", () => {
39
+ const SAMPLE_RATE = 44100;
40
+
41
+ const runWithDevice = async (fn: (device: GPUDevice) => Promise<void>) => {
42
+ try {
43
+ const device = await ensureDevice();
44
+ await fn(device);
45
+ } catch {
46
+ console.warn("Skipping test due to missing WebGPU device");
47
+ }
48
+ };
49
+
50
+ it("should apply delay on mono audio and alter the signal over time", async () => {
51
+ await runWithDevice(async (device) => {
52
+ const virtualMedia = createVirtualMedia({
53
+ delayTime: 0.01,
54
+ wet: 0.5,
55
+ dry: 1.0,
56
+ });
57
+ const shortChannels = createChannels(1000, 0.5);
58
+ await delayAudioProcessor(shortChannels, SAMPLE_RATE, virtualMedia, {
59
+ device,
60
+ frame: 0,
61
+ fps: 24,
62
+ renderId: "test-delay",
63
+ });
64
+
65
+ expect(shortChannels[0][0]).toBe(0.5); // Still dry-only because buffer is empty
66
+ expect(shortChannels[0][500]).not.toBe(0.5); // Should be mixed since 500 > 441
67
+ expect(Number.isNaN(shortChannels[0][500])).toBe(false);
68
+ expect(Number.isFinite(shortChannels[0][500])).toBe(true);
69
+ });
70
+ });
71
+
72
+ it("should respect dry/wet parameters", async () => {
73
+ await runWithDevice(async (device) => {
74
+ const channels = createChannels(500, 0.5);
75
+ const virtualMedia = createVirtualMedia({
76
+ dry: 0.0,
77
+ wet: 0.0,
78
+ });
79
+
80
+ await delayAudioProcessor(channels, SAMPLE_RATE, virtualMedia, {
81
+ device,
82
+ frame: 0,
83
+ fps: 24,
84
+ renderId: "test-delay-drywet",
85
+ });
86
+
87
+ expect(channels[0][0]).toBe(0);
88
+ expect(channels[0][250]).toBe(0);
89
+ });
90
+ });
91
+
92
+ it("should safely clamp feedback to avoid infinite runaway", async () => {
93
+ await runWithDevice(async (device) => {
94
+ const channels = createChannels(1000, 0.5);
95
+ // Even at feedback 1.5, it should be clamped to 0.95 internally
96
+ const virtualMedia = createVirtualMedia({
97
+ feedback: 1.5,
98
+ });
99
+
100
+ await delayAudioProcessor(channels, SAMPLE_RATE, virtualMedia, {
101
+ device,
102
+ frame: 0,
103
+ fps: 24,
104
+ renderId: "test-delay-clamp",
105
+ });
106
+
107
+ expect(Number.isNaN(channels[0][500])).toBe(false);
108
+ expect(Number.isFinite(channels[0][500])).toBe(true);
109
+ });
110
+ });
111
+
112
+ it("should apply ping-pong delay on stereo channels", async () => {
113
+ await runWithDevice(async (device) => {
114
+ // Ping pong alternates delay feed. Let's create stereo input with signal in left only
115
+ const virtualMedia = createVirtualMedia({
116
+ delayTime: 0.01,
117
+ pingPong: true,
118
+ feedback: 0.5,
119
+ wet: 0.8,
120
+ });
121
+ const left = new Float32Array(1000).fill(1.0);
122
+ const right = new Float32Array(1000).fill(0.0);
123
+ const channels = [left, right];
124
+
125
+ await delayAudioProcessor(channels, SAMPLE_RATE, virtualMedia, {
126
+ device,
127
+ frame: 0,
128
+ fps: 24,
129
+ renderId: "test-delay-pingpong",
130
+ });
131
+
132
+ expect(channels[1][0]).toBe(0.0); // Initially empty delay
133
+ expect(channels[1][900]).not.toBe(0.0); // Right channel should have signal fed from Left delayed echo!
134
+ });
135
+ });
136
+ });
@@ -0,0 +1,274 @@
1
+ import type { AudioProcessor } from "@framefields/node-sdk";
2
+ import { WebGPUAudioProcessor } from "@framefields/webgpu-renderers";
3
+
4
+ const PARAM_ORDER = ["delayTime", "feedback", "wet", "dry"];
5
+
6
+ const DELAY_SHADER_TEMPLATE = () => `
7
+ struct Uniforms {
8
+ sampleRate : f32,
9
+ delaySec : f32,
10
+ feedback : f32,
11
+ wet : f32,
12
+ dry : f32,
13
+ pingPong : f32,
14
+ bufferLength : f32,
15
+ hasDelayTimeSig : f32,
16
+ hasFeedbackSig : f32,
17
+ hasWetSig : f32,
18
+ hasDrySig : f32,
19
+ baseTime : f32,
20
+ frame : f32,
21
+ numSamples : f32,
22
+ numChannels : f32,
23
+ pad1 : f32,
24
+ };
25
+
26
+ @group(0) @binding(0) var<uniform> u : Uniforms;
27
+ @group(0) @binding(1) var<storage, read> inputChannels : array<f32>;
28
+ @group(0) @binding(2) var<storage, read_write> outputChannels : array<f32>;
29
+ @group(0) @binding(3) var<storage, read_write> state : array<f32>;
30
+ @group(0) @binding(4) var<storage, read> delayTimeSignal : array<f32>;
31
+ @group(0) @binding(5) var<storage, read> feedbackSignal : array<f32>;
32
+ @group(0) @binding(6) var<storage, read> wetSignal : array<f32>;
33
+ @group(0) @binding(7) var<storage, read> drySignal : array<f32>;
34
+
35
+ fn tanh(x: f32) -> f32 {
36
+ let exp2x = exp(2.0f * x);
37
+ return (exp2x - 1.0f) / (exp2x + 1.0f);
38
+ }
39
+
40
+ fn is_nan_or_inf(v: f32) -> bool {
41
+ return (v != v) || (abs(v) > 3.402823466e+38f);
42
+ }
43
+
44
+ @compute @workgroup_size(1)
45
+ fn main(@builtin(global_invocation_id) gid : vec3<u32>) {
46
+ if (gid.x != 0u) { return; }
47
+
48
+ let numSamples = u32(u.numSamples);
49
+ let numChannels = u32(u.numChannels);
50
+ let bufferLength = u32(u.bufferLength);
51
+
52
+ var writeIndex = u32(state[0]);
53
+ if (is_nan_or_inf(state[0])) {
54
+ writeIndex = 0u;
55
+ }
56
+
57
+ for (var index = 0u; index < numSamples; index = index + 1u) {
58
+ // 1. Dynamic Parameter Modulation & Anti-Explosion Clamping
59
+ var effDelaySec = u.delaySec;
60
+ if (u.hasDelayTimeSig > 0.5f) {
61
+ effDelaySec = delayTimeSignal[index];
62
+ }
63
+ effDelaySec = clamp(effDelaySec, 0.001f, 5.0f);
64
+
65
+ var effFeedback = u.feedback;
66
+ if (u.hasFeedbackSig > 0.5f) {
67
+ effFeedback = feedbackSignal[index];
68
+ }
69
+ effFeedback = clamp(effFeedback, 0.0f, 0.95f);
70
+
71
+ var effWet = u.wet;
72
+ if (u.hasWetSig > 0.5f) {
73
+ effWet = wetSignal[index];
74
+ }
75
+ effWet = clamp(effWet, 0.0f, 2.0f);
76
+
77
+ var effDry = u.dry;
78
+ if (u.hasDrySig > 0.5f) {
79
+ effDry = drySignal[index];
80
+ }
81
+ effDry = clamp(effDry, 0.0f, 2.0f);
82
+
83
+ // 2. Safe Dynamic Read Index
84
+ let readOffset = u32(clamp(effDelaySec * u.sampleRate, 1.0f, f32(bufferLength - 1u)));
85
+ let readIndex = (writeIndex + bufferLength - readOffset) % bufferLength;
86
+
87
+ if (numChannels == 1u || u.pingPong == 0.0f) {
88
+ // Standard Delay
89
+ for (var c = 0u; c < numChannels; c = c + 1u) {
90
+ let sampleIndex = c * numSamples + index;
91
+ var inputVal = inputChannels[sampleIndex];
92
+ if (is_nan_or_inf(inputVal)) {
93
+ inputVal = 0.0f;
94
+ }
95
+
96
+ let stateOffset = c * bufferLength + 1u;
97
+ var delayedSample = state[stateOffset + readIndex];
98
+ if (is_nan_or_inf(delayedSample)) {
99
+ delayedSample = 0.0f;
100
+ }
101
+
102
+ var nextStateVal = inputVal + delayedSample * effFeedback;
103
+ if (is_nan_or_inf(nextStateVal)) {
104
+ nextStateVal = 0.0f;
105
+ }
106
+ state[stateOffset + writeIndex] = clamp(nextStateVal, -4.0f, 4.0f);
107
+
108
+ var outVal = effDry * inputVal + effWet * delayedSample;
109
+ if (is_nan_or_inf(outVal)) {
110
+ outVal = 0.0f;
111
+ }
112
+ if (outVal > 1.0f) {
113
+ outVal = 1.0f;
114
+ } else if (outVal < -1.0f) {
115
+ outVal = -1.0f;
116
+ } else if (outVal > 0.9f) {
117
+ outVal = 0.9f + 0.1f * tanh((outVal - 0.9f) / 0.1f);
118
+ } else if (outVal < -0.9f) {
119
+ outVal = -0.9f + 0.1f * tanh((outVal + 0.9f) / 0.1f);
120
+ }
121
+
122
+ outputChannels[sampleIndex] = outVal;
123
+ }
124
+ } else {
125
+ // Stereo Ping-Pong Delay
126
+ var sampleL = inputChannels[index];
127
+ if (is_nan_or_inf(sampleL)) { sampleL = 0.0f; }
128
+
129
+ var sampleR = inputChannels[numSamples + index];
130
+ if (is_nan_or_inf(sampleR)) { sampleR = 0.0f; }
131
+
132
+ var delayedL = state[1u + readIndex];
133
+ if (is_nan_or_inf(delayedL)) { delayedL = 0.0f; }
134
+
135
+ var delayedR = state[bufferLength + 1u + readIndex];
136
+ if (is_nan_or_inf(delayedR)) { delayedR = 0.0f; }
137
+
138
+ // Ping-pong cross-feedback
139
+ var nextL = sampleL + delayedR * effFeedback;
140
+ var nextR = sampleR + delayedL * effFeedback;
141
+ if (is_nan_or_inf(nextL)) { nextL = 0.0f; }
142
+ if (is_nan_or_inf(nextR)) { nextR = 0.0f; }
143
+
144
+ state[1u + writeIndex] = clamp(nextL, -4.0f, 4.0f);
145
+ state[bufferLength + 1u + writeIndex] = clamp(nextR, -4.0f, 4.0f);
146
+
147
+ var outL = effDry * sampleL + effWet * delayedL;
148
+ var outR = effDry * sampleR + effWet * delayedR;
149
+ if (is_nan_or_inf(outL)) { outL = 0.0f; }
150
+ if (is_nan_or_inf(outR)) { outR = 0.0f; }
151
+
152
+ if (outL > 1.0f) { outL = 1.0f; } else if (outL < -1.0f) { outL = -1.0f; }
153
+ else if (outL > 0.9f) { outL = 0.9f + 0.1f * tanh((outL - 0.9f) / 0.1f); }
154
+ else if (outL < -0.9f) { outL = -0.9f + 0.1f * tanh((outL + 0.9f) / 0.1f); }
155
+
156
+ if (outR > 1.0f) { outR = 1.0f; } else if (outR < -1.0f) { outR = -1.0f; }
157
+ else if (outR > 0.9f) { outR = 0.9f + 0.1f * tanh((outR - 0.9f) / 0.1f); }
158
+ else if (outR < -0.9f) { outR = -0.9f + 0.1f * tanh((outR + 0.9f) / 0.1f); }
159
+
160
+ outputChannels[index] = outL;
161
+ outputChannels[numSamples + index] = outR;
162
+ }
163
+
164
+ writeIndex = (writeIndex + 1u) % bufferLength;
165
+ }
166
+
167
+ state[0] = f32(writeIndex);
168
+ }
169
+ `;
170
+
171
+ export const delayAudioProcessor: AudioProcessor = async (
172
+ channels,
173
+ sampleRate,
174
+ virtualMedia,
175
+ ctx,
176
+ ) => {
177
+ if (!ctx?.device) {
178
+ throw new Error("GPUDevice is required for WebGPU Audio Delay.");
179
+ }
180
+
181
+ const op = (virtualMedia.operation as Record<string, unknown>) || {};
182
+ const inputs = (op.inputs as Record<string, any>) || {};
183
+
184
+ const numChannels = channels.length;
185
+ if (numChannels === 0) return;
186
+ const numSamples = channels[0].length;
187
+ if (numSamples === 0) return;
188
+
189
+ // Clamp and extract parameters
190
+ const delaySec = Math.max(
191
+ 0.001,
192
+ Math.min(typeof op.delayTime === "number" ? op.delayTime : 0.25, 5.0),
193
+ );
194
+ const feedbackInternal = Math.max(
195
+ 0.0,
196
+ Math.min(typeof op.feedback === "number" ? op.feedback : 0.4, 0.95),
197
+ );
198
+ const wetInternal = Math.max(
199
+ 0.0,
200
+ Math.min(typeof op.wet === "number" ? op.wet : 0.3, 1.0),
201
+ );
202
+ const dryInternal = Math.max(
203
+ 0.0,
204
+ Math.min(typeof op.dry === "number" ? op.dry : 1.0, 1.0),
205
+ );
206
+ const pingPongInternal =
207
+ typeof op.pingPong === "boolean" ? op.pingPong : false;
208
+
209
+ const isHandleConnected = (handleIdKey: string): boolean => {
210
+ const handleId = op[handleIdKey];
211
+ if (typeof handleId !== "string" || !handleId) return false;
212
+ const input = inputs[handleId];
213
+ return Boolean(
214
+ input?.connectionValid &&
215
+ input.outputItem &&
216
+ (input.outputItem.type === "Signal" ||
217
+ input.outputItem.type === "Number"),
218
+ );
219
+ };
220
+
221
+ const hasDelayTimeSig = isHandleConnected("delayTimeHandleId") ? 1.0 : 0.0;
222
+ const hasFeedbackSig = isHandleConnected("feedbackHandleId") ? 1.0 : 0.0;
223
+ const hasWetSig = isHandleConnected("wetHandleId") ? 1.0 : 0.0;
224
+ const hasDrySig = isHandleConnected("dryHandleId") ? 1.0 : 0.0;
225
+
226
+ // Allocate max possible delay buffer (5 seconds) to allow smooth dynamic modulation
227
+ const maxDelaySec = 5.0;
228
+ const bufferLength = Math.ceil(maxDelaySec * sampleRate);
229
+
230
+ // 100% WebGPU Compute Path
231
+ const nodeId = (op.id as string) || "audio-delay";
232
+ const frame = ctx.frame ?? 0;
233
+ const fps = ctx.fps ?? 24;
234
+
235
+ const stateFloatCount = numChannels * bufferLength + 1;
236
+
237
+ await WebGPUAudioProcessor.process(
238
+ ctx.device,
239
+ nodeId,
240
+ channels,
241
+ sampleRate,
242
+ virtualMedia,
243
+ frame,
244
+ fps,
245
+ DELAY_SHADER_TEMPLATE,
246
+ () => [
247
+ sampleRate,
248
+ delaySec,
249
+ feedbackInternal,
250
+ wetInternal,
251
+ dryInternal,
252
+ pingPongInternal ? 1.0 : 0.0,
253
+ bufferLength,
254
+ hasDelayTimeSig,
255
+ hasFeedbackSig,
256
+ hasWetSig,
257
+ hasDrySig,
258
+ 0.0, // baseTime
259
+ frame,
260
+ numSamples,
261
+ numChannels,
262
+ 0, // padding
263
+ ],
264
+ 16, // Aligned to 16 bytes (16 * 4 = 64 bytes)
265
+ stateFloatCount, // Persistent Ring Buffer state
266
+ ctx?.renderId,
267
+ true,
268
+ ctx?.elapsedMs,
269
+ ctx?.durationMs,
270
+ undefined,
271
+ undefined,
272
+ PARAM_ORDER,
273
+ );
274
+ };
@@ -0,0 +1,6 @@
1
+ import { defineRenderer } from "@framefields/node-sdk/renderer";
2
+ import { delayAudioProcessor } from "./audio-processor.js";
3
+
4
+ export default defineRenderer({
5
+ audioProcessor: delayAudioProcessor,
6
+ });
@@ -0,0 +1,58 @@
1
+ import {
2
+ AudioResultSchema,
3
+ configBuilder,
4
+ VideoResultSchema,
5
+ } from "@framefields/node-sdk";
6
+ import { z } from "zod";
7
+
8
+ export const delayConfig = configBuilder()
9
+ .field("delayTime", z.number().min(0.001).max(5.0).default(0.25), {
10
+ bindable: true,
11
+ dataTypes: ["Number", "Signal"],
12
+ label: "Delay Time Signal",
13
+ description:
14
+ "Delay time in seconds (0.001 to 5.0s). Can be modulated by a static number or dynamic signal.",
15
+ })
16
+ .field("feedback", z.number().min(0.0).max(0.95).default(0.4), {
17
+ bindable: true,
18
+ dataTypes: ["Number", "Signal"],
19
+ label: "Feedback Signal",
20
+ description:
21
+ "Amount of delayed signal fed back into delay line (0.0 to 0.95). Can be modulated by a static number or dynamic signal.",
22
+ })
23
+ .field("wet", z.number().min(0.0).max(1.0).default(0.3), {
24
+ bindable: true,
25
+ dataTypes: ["Number", "Signal"],
26
+ label: "Wet Mix Signal",
27
+ description:
28
+ "Mix level of the wet delayed signal (0.0 to 1.0). Can be modulated by a static number or dynamic signal.",
29
+ })
30
+ .field("dry", z.number().min(0.0).max(1.0).default(1.0), {
31
+ bindable: true,
32
+ dataTypes: ["Number", "Signal"],
33
+ label: "Dry Mix Signal",
34
+ description:
35
+ "Mix level of the original dry signal (0.0 to 1.0). Can be modulated by a static number or dynamic signal.",
36
+ })
37
+ .field("pingPong", z.boolean().default(false), {
38
+ bindable: false,
39
+ label: "Ping Pong Mode",
40
+ description: "Alternates echo reflections between left and right channels",
41
+ })
42
+ .build();
43
+
44
+ export const DelayNodeConfigSchema = delayConfig.schema;
45
+
46
+ export type DelayNodeConfig = z.infer<typeof DelayNodeConfigSchema>;
47
+
48
+ export const DelayResultSchema = z.union([
49
+ AudioResultSchema,
50
+ VideoResultSchema,
51
+ ]);
52
+
53
+ export type DelayResult = z.infer<typeof DelayResultSchema>;
54
+
55
+ export const DELAY_OUTPUT_TYPE_MAP: Record<string, "Audio" | "Video"> = {
56
+ Audio: "Audio",
57
+ Video: "Video",
58
+ };
@@ -0,0 +1 @@
1
+ export * from "./config.js";
package/tsconfig.json ADDED
@@ -0,0 +1,13 @@
1
+ {
2
+ "extends": "@framefields/tsconfig/node-library.json",
3
+ "compilerOptions": {
4
+ "baseUrl": ".",
5
+ "paths": {
6
+ "@/*": ["./src/*"]
7
+ },
8
+ "experimentalDecorators": true,
9
+ "emitDecoratorMetadata": true,
10
+ "allowJs": true
11
+ },
12
+ "include": ["src"]
13
+ }
@@ -0,0 +1,13 @@
1
+ import { defineConfig } from "tsdown";
2
+
3
+ export default defineConfig({
4
+ entry: {
5
+ index: "src/index.ts",
6
+ renderer: "src/renderers/index.ts",
7
+ },
8
+ format: ["esm"],
9
+ dts: true,
10
+ clean: true,
11
+ sourcemap: true,
12
+ treeshake: true,
13
+ });