@fluex/fluexgl-dsp 0.1.3 → 0.2.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.
Files changed (109) hide show
  1. package/README.md +86 -86
  2. package/lib/dist/console-codes.d.ts +13 -13
  3. package/lib/dist/console-codes.js +16 -16
  4. package/lib/dist/core/classes/AudioClip.d.ts +67 -62
  5. package/lib/dist/core/classes/AudioClip.d.ts.map +1 -1
  6. package/lib/dist/core/classes/AudioClip.js +406 -386
  7. package/lib/dist/core/classes/AudioDevice.d.ts +12 -12
  8. package/lib/dist/core/classes/AudioDevice.js +30 -30
  9. package/lib/dist/core/classes/Channel.d.ts +41 -29
  10. package/lib/dist/core/classes/Channel.d.ts.map +1 -1
  11. package/lib/dist/core/classes/Channel.js +210 -144
  12. package/lib/dist/core/classes/DpsPipeline.d.ts +59 -59
  13. package/lib/dist/core/classes/DpsPipeline.js +115 -115
  14. package/lib/dist/core/classes/Effector.d.ts +8 -11
  15. package/lib/dist/core/classes/Effector.d.ts.map +1 -1
  16. package/lib/dist/core/classes/Effector.js +8 -20
  17. package/lib/dist/core/classes/Master.d.ts +11 -11
  18. package/lib/dist/core/classes/Master.js +35 -35
  19. package/lib/dist/core/exports.d.ts +6 -6
  20. package/lib/dist/core/exports.js +6 -6
  21. package/lib/dist/effects/classes/Chorus.d.ts +19 -2
  22. package/lib/dist/effects/classes/Chorus.d.ts.map +1 -1
  23. package/lib/dist/effects/classes/Chorus.js +53 -2
  24. package/lib/dist/effects/classes/Distortion.d.ts +6 -2
  25. package/lib/dist/effects/classes/Distortion.d.ts.map +1 -1
  26. package/lib/dist/effects/classes/Distortion.js +9 -2
  27. package/lib/dist/effects/classes/Equalizer.d.ts +2 -2
  28. package/lib/dist/effects/classes/Equalizer.js +2 -2
  29. package/lib/dist/effects/classes/Limiter.d.ts +2 -2
  30. package/lib/dist/effects/classes/Limiter.js +2 -2
  31. package/lib/dist/effects/classes/Saturation.d.ts +2 -2
  32. package/lib/dist/effects/classes/Saturation.d.ts.map +1 -1
  33. package/lib/dist/effects/classes/Saturation.js +2 -2
  34. package/lib/dist/effects/classes/SoftClip.d.ts +12 -7
  35. package/lib/dist/effects/classes/SoftClip.d.ts.map +1 -1
  36. package/lib/dist/effects/classes/SoftClip.js +54 -38
  37. package/lib/dist/effects/classes/StereoPanner.d.ts +3 -2
  38. package/lib/dist/effects/classes/StereoPanner.d.ts.map +1 -1
  39. package/lib/dist/effects/classes/StereoPanner.js +3 -2
  40. package/lib/dist/effects/classes/compressors/Compressor.d.ts +2 -2
  41. package/lib/dist/effects/classes/compressors/Compressor.js +2 -2
  42. package/lib/dist/effects/classes/compressors/MultibandCompressor.d.ts +2 -2
  43. package/lib/dist/effects/classes/compressors/MultibandCompressor.js +2 -2
  44. package/lib/dist/effects/classes/delays/AdvancedDelay.d.ts +2 -2
  45. package/lib/dist/effects/classes/delays/AdvancedDelay.js +2 -2
  46. package/lib/dist/effects/classes/delays/MonoDelay.d.ts +2 -2
  47. package/lib/dist/effects/classes/delays/MonoDelay.js +2 -2
  48. package/lib/dist/effects/classes/delays/PingPongDelay.d.ts +2 -2
  49. package/lib/dist/effects/classes/delays/PingPongDelay.js +2 -2
  50. package/lib/dist/effects/classes/delays/StereoDelay.d.ts +2 -2
  51. package/lib/dist/effects/classes/delays/StereoDelay.js +2 -2
  52. package/lib/dist/effects/classes/filters/LowPassFilter.d.ts +14 -0
  53. package/lib/dist/effects/classes/filters/LowPassFilter.d.ts.map +1 -0
  54. package/lib/dist/effects/classes/filters/LowPassFilter.js +38 -0
  55. package/lib/dist/effects/classes/reverbs/ChamberReverb.d.ts +2 -2
  56. package/lib/dist/effects/classes/reverbs/ChamberReverb.js +2 -2
  57. package/lib/dist/effects/classes/reverbs/ConvolverReverb.d.ts +2 -2
  58. package/lib/dist/effects/classes/reverbs/ConvolverReverb.js +2 -2
  59. package/lib/dist/effects/classes/reverbs/GenericReverb.d.ts +2 -2
  60. package/lib/dist/effects/classes/reverbs/GenericReverb.js +2 -2
  61. package/lib/dist/effects/classes/reverbs/HallReverb.d.ts +2 -2
  62. package/lib/dist/effects/classes/reverbs/HallReverb.js +2 -2
  63. package/lib/dist/effects/classes/reverbs/RoomReverb.d.ts +2 -2
  64. package/lib/dist/effects/classes/reverbs/RoomReverb.js +2 -2
  65. package/lib/dist/effects/exports.d.ts +19 -19
  66. package/lib/dist/effects/exports.d.ts.map +1 -1
  67. package/lib/dist/effects/exports.js +19 -19
  68. package/lib/dist/index.d.ts +12 -12
  69. package/lib/dist/index.d.ts.map +1 -1
  70. package/lib/dist/index.js +28 -28
  71. package/lib/dist/typings.d.ts +97 -59
  72. package/lib/dist/typings.d.ts.map +1 -1
  73. package/lib/dist/typings.js +30 -1
  74. package/lib/dist/utilities/constants.d.ts +1 -1
  75. package/lib/dist/utilities/constants.js +9 -9
  76. package/lib/dist/utilities/debugger.d.ts +7 -7
  77. package/lib/dist/utilities/debugger.js +49 -49
  78. package/lib/dist/utilities/helpers.d.ts +46 -40
  79. package/lib/dist/utilities/helpers.d.ts.map +1 -1
  80. package/lib/dist/utilities/helpers.js +186 -143
  81. package/lib/dist/utilities/web-assembly.d.ts +3 -3
  82. package/lib/dist/utilities/web-assembly.d.ts.map +1 -1
  83. package/lib/dist/utilities/web-assembly.js +12 -12
  84. package/lib/src/console-codes.ts +15 -15
  85. package/lib/src/core/classes/AudioClip.ts +539 -539
  86. package/lib/src/core/classes/AudioDevice.ts +38 -38
  87. package/lib/src/core/classes/Channel.ts +288 -288
  88. package/lib/src/core/classes/DpsPipeline.ts +152 -152
  89. package/lib/src/core/classes/Effector.ts +11 -12
  90. package/lib/src/core/classes/Master.ts +49 -49
  91. package/lib/src/core/exports.ts +5 -5
  92. package/lib/src/effects/classes/Chorus.ts +65 -111
  93. package/lib/src/effects/classes/Distortion.ts +13 -13
  94. package/lib/src/effects/classes/Saturation.ts +2 -2
  95. package/lib/src/effects/classes/SoftClip.ts +60 -44
  96. package/lib/src/effects/classes/StereoPanner.ts +2 -2
  97. package/lib/src/effects/classes/filters/LowPassFilter.ts +54 -0
  98. package/lib/src/effects/exports.ts +23 -22
  99. package/lib/src/index.ts +98 -93
  100. package/lib/src/typings.ts +113 -78
  101. package/lib/src/utilities/constants.ts +8 -8
  102. package/lib/src/utilities/debugger.ts +65 -65
  103. package/lib/src/utilities/helpers.ts +265 -237
  104. package/lib/src/utilities/web-assembly.ts +12 -12
  105. package/package.json +51 -50
  106. package/lib/dist/effects/classes/Filter.d.ts +0 -3
  107. package/lib/dist/effects/classes/Filter.d.ts.map +0 -1
  108. package/lib/dist/effects/classes/Filter.js +0 -2
  109. package/lib/src/effects/classes/Filter.ts +0 -1
@@ -1,153 +1,153 @@
1
- import { v4 } from "uuid";
2
-
3
- import { AudioDevice } from "./AudioDevice";
4
- import { Debug } from "../../utilities/debugger";
5
- import { LoadWebAssemblyModule } from "../../utilities/web-assembly";
6
- import { ConstructProcessorWorklet, LoadWorkletOnMasterChannel } from "../../utilities/helpers";
7
-
8
- import { ErrorCodes, WarningCodes } from "../../console-codes";
9
- import { DspPipelineInitializationOptions } from "../../typings";
10
-
11
- /**
12
- * Represents the digital signal processing (DSP) pipeline responsible for initializing
13
- * WebAssembly modules, AudioWorklet processors, and resolving audio output devices.
14
- */
15
- export class DspPipeline {
16
-
17
- /**
18
- * The path to the WebAssembly module file.
19
- */
20
- public pathToWasm: string | null = null;
21
-
22
- /**
23
- * The path to the AudioWorklet processor script.
24
- */
25
- public pathToWorklet: string | null = null;
26
-
27
- /**
28
- * Unique identifier of this DSP pipeline instance.
29
- */
30
- public id: string = v4();
31
-
32
- /**
33
- * Indicates whether the DSP pipeline has been successfully initialized.
34
- */
35
- public hasInitialized: boolean = false;
36
-
37
- /**
38
- * The generated blob URL containing the AudioWorklet processor code.
39
- */
40
- private blobUrl: string | null = null;
41
-
42
- /**
43
- * Creates a new instance of the {@link DspPipeline} class.
44
- *
45
- * @param options - Initialization options for the DSP pipeline.
46
- * Must include valid paths to the WebAssembly and AudioWorklet files.
47
- */
48
- constructor(options: DspPipelineInitializationOptions) {
49
- this.pathToWasm = options.pathToWasm;
50
- this.pathToWorklet = options.pathToWorklet;
51
- }
52
-
53
- /**
54
- * Initializes the DSP pipeline.
55
- * This is a convenience wrapper around {@link InitializeDpsPipeline}.
56
- *
57
- * @returns A promise resolving to `true` if the initialization succeeded, otherwise `false`.
58
- */
59
- public async Init(): Promise<boolean> {
60
- return await this.InitializeDpsPipeline();
61
- }
62
-
63
- /**
64
- * Performs the full initialization of the DSP pipeline.
65
- * Loads the WebAssembly module, constructs the AudioWorklet blob URL,
66
- * and ensures audio access permissions are granted.
67
- *
68
- * @returns A promise resolving to `true` when initialization completes successfully, otherwise `false`.
69
- */
70
- public async InitializeDpsPipeline(): Promise<boolean> {
71
- Debug.Log("Attempting to initialize DSP pipeline...");
72
-
73
- const start: number = Date.now();
74
-
75
- if (!this.pathToWasm || !this.pathToWorklet) {
76
- Debug.Error("Could not initialize DSP pipeline, because the path to the WASM, or the worklet file has not been defined.");
77
- return false;
78
- }
79
-
80
- try {
81
- const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
82
- Debug.Log(`Found ${stream.getTracks().length} media stream tracks.`);
83
-
84
- // Stop all tracks immediately after verification
85
- stream.getTracks().forEach((track: MediaStreamTrack) => {
86
- track.stop();
87
- });
88
- } catch (err) {
89
- Debug.Error(
90
- "Permission to access media devices has not been granted.",
91
- ["Make sure the user has granted FluentGL permission to access media devices."],
92
- ErrorCodes.NO_CONTEXT_PERMISSION
93
- );
94
- return false;
95
- }
96
-
97
- await LoadWebAssemblyModule(this.pathToWasm);
98
-
99
- const workletFileRequest = await fetch(this.pathToWorklet);
100
- const textContent: string = await workletFileRequest.text();
101
-
102
- this.blobUrl = ConstructProcessorWorklet(textContent);
103
-
104
- const end: number = Date.now();
105
- const difference: number = end - start;
106
-
107
- Debug.Success(`Successfully initialized DSP pipeline within ${difference}ms.`);
108
-
109
- return (this.hasInitialized = true);
110
- }
111
-
112
- /**
113
- * Resolves and initializes the system’s default audio output device.
114
- * This method can only be called after the DSP pipeline has been initialized.
115
- *
116
- * @returns A promise that resolves with the default {@link AudioDevice} instance,
117
- * or `null` if no default device was found or initialization failed.
118
- */
119
- public async ResolveDefaultAudioOutputDevice() {
120
- Debug.Log("Attempting to resolve default audio output device...");
121
-
122
- if (!this.hasInitialized || !this.blobUrl) {
123
- Debug.Error(
124
- "Could not resolve default audio output device, because the required blob URL has not been created.",
125
- ["Call await .InitializeDpsPipeline() before resolving default audio output device."]
126
- );
127
- return null;
128
- }
129
-
130
- const audioDeviceInfos: MediaDeviceInfo[] = [];
131
- const devices = await navigator.mediaDevices.enumerateDevices();
132
-
133
- for (let device of devices)
134
- (device.kind === "audiooutput" && device.deviceId === "default") &&
135
- audioDeviceInfos.push(device);
136
-
137
- devices.length === 0 &&
138
- Debug.Warn("No default audio device found.", [], WarningCodes.NO_DEFAULT_AUDIO_DEVICE_FOUND);
139
-
140
- const defaultAudioDevice =
141
- devices.length === 0 ? null : new AudioDevice(audioDeviceInfos[0]);
142
-
143
- if (!defaultAudioDevice) return null;
144
-
145
- await LoadWorkletOnMasterChannel(defaultAudioDevice.masterChannel, this.blobUrl);
146
-
147
- return defaultAudioDevice;
148
- }
149
-
150
- public TellMeWhatTheFuckThisWholeLibraryActuallyDoes() {
151
- return `I wanted to create a web based game and implement advanced audio, but javascript is slow so that's why this library uses Web Assembly. You dont have to use it, unless you know what the fuck you're doing. If you do, god bless you.`
152
- }
1
+ import { v4 } from "uuid";
2
+
3
+ import { AudioDevice } from "./AudioDevice";
4
+ import { Debug } from "../../utilities/debugger";
5
+ import { LoadWebAssemblyModule } from "../../utilities/web-assembly";
6
+ import { ConstructProcessorWorklet, LoadWorkletOnMasterChannel } from "../../utilities/helpers";
7
+
8
+ import { ErrorCodes, WarningCodes } from "../../console-codes";
9
+ import { DspPipelineInitializationOptions } from "../../typings";
10
+
11
+ /**
12
+ * Represents the digital signal processing (DSP) pipeline responsible for initializing
13
+ * WebAssembly modules, AudioWorklet processors, and resolving audio output devices.
14
+ */
15
+ export class DspPipeline {
16
+
17
+ /**
18
+ * The path to the WebAssembly module file.
19
+ */
20
+ public pathToWasm: string | null = null;
21
+
22
+ /**
23
+ * The path to the AudioWorklet processor script.
24
+ */
25
+ public pathToWorklet: string | null = null;
26
+
27
+ /**
28
+ * Unique identifier of this DSP pipeline instance.
29
+ */
30
+ public id: string = v4();
31
+
32
+ /**
33
+ * Indicates whether the DSP pipeline has been successfully initialized.
34
+ */
35
+ public hasInitialized: boolean = false;
36
+
37
+ /**
38
+ * The generated blob URL containing the AudioWorklet processor code.
39
+ */
40
+ private blobUrl: string | null = null;
41
+
42
+ /**
43
+ * Creates a new instance of the {@link DspPipeline} class.
44
+ *
45
+ * @param options - Initialization options for the DSP pipeline.
46
+ * Must include valid paths to the WebAssembly and AudioWorklet files.
47
+ */
48
+ constructor(options: DspPipelineInitializationOptions) {
49
+ this.pathToWasm = options.pathToWasm;
50
+ this.pathToWorklet = options.pathToWorklet;
51
+ }
52
+
53
+ /**
54
+ * Initializes the DSP pipeline.
55
+ * This is a convenience wrapper around {@link InitializeDpsPipeline}.
56
+ *
57
+ * @returns A promise resolving to `true` if the initialization succeeded, otherwise `false`.
58
+ */
59
+ public async Init(): Promise<boolean> {
60
+ return await this.InitializeDpsPipeline();
61
+ }
62
+
63
+ /**
64
+ * Performs the full initialization of the DSP pipeline.
65
+ * Loads the WebAssembly module, constructs the AudioWorklet blob URL,
66
+ * and ensures audio access permissions are granted.
67
+ *
68
+ * @returns A promise resolving to `true` when initialization completes successfully, otherwise `false`.
69
+ */
70
+ public async InitializeDpsPipeline(): Promise<boolean> {
71
+ Debug.Log("Attempting to initialize DSP pipeline...");
72
+
73
+ const start: number = Date.now();
74
+
75
+ if (!this.pathToWasm || !this.pathToWorklet) {
76
+ Debug.Error("Could not initialize DSP pipeline, because the path to the WASM, or the worklet file has not been defined.");
77
+ return false;
78
+ }
79
+
80
+ try {
81
+ const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
82
+ Debug.Log(`Found ${stream.getTracks().length} media stream tracks.`);
83
+
84
+ // Stop all tracks immediately after verification
85
+ stream.getTracks().forEach((track: MediaStreamTrack) => {
86
+ track.stop();
87
+ });
88
+ } catch (err) {
89
+ Debug.Error(
90
+ "Permission to access media devices has not been granted.",
91
+ ["Make sure the user has granted FluentGL permission to access media devices."],
92
+ ErrorCodes.NO_CONTEXT_PERMISSION
93
+ );
94
+ return false;
95
+ }
96
+
97
+ await LoadWebAssemblyModule(this.pathToWasm);
98
+
99
+ const workletFileRequest = await fetch(this.pathToWorklet);
100
+ const textContent: string = await workletFileRequest.text();
101
+
102
+ this.blobUrl = ConstructProcessorWorklet(textContent);
103
+
104
+ const end: number = Date.now();
105
+ const difference: number = end - start;
106
+
107
+ Debug.Success(`Successfully initialized DSP pipeline within ${difference}ms.`);
108
+
109
+ return (this.hasInitialized = true);
110
+ }
111
+
112
+ /**
113
+ * Resolves and initializes the system’s default audio output device.
114
+ * This method can only be called after the DSP pipeline has been initialized.
115
+ *
116
+ * @returns A promise that resolves with the default {@link AudioDevice} instance,
117
+ * or `null` if no default device was found or initialization failed.
118
+ */
119
+ public async ResolveDefaultAudioOutputDevice() {
120
+ Debug.Log("Attempting to resolve default audio output device...");
121
+
122
+ if (!this.hasInitialized || !this.blobUrl) {
123
+ Debug.Error(
124
+ "Could not resolve default audio output device, because the required blob URL has not been created.",
125
+ ["Call await .InitializeDpsPipeline() before resolving default audio output device."]
126
+ );
127
+ return null;
128
+ }
129
+
130
+ const audioDeviceInfos: MediaDeviceInfo[] = [];
131
+ const devices = await navigator.mediaDevices.enumerateDevices();
132
+
133
+ for (let device of devices)
134
+ (device.kind === "audiooutput" && device.deviceId === "default") &&
135
+ audioDeviceInfos.push(device);
136
+
137
+ devices.length === 0 &&
138
+ Debug.Warn("No default audio device found.", [], WarningCodes.NO_DEFAULT_AUDIO_DEVICE_FOUND);
139
+
140
+ const defaultAudioDevice =
141
+ devices.length === 0 ? null : new AudioDevice(audioDeviceInfos[0]);
142
+
143
+ if (!defaultAudioDevice) return null;
144
+
145
+ await LoadWorkletOnMasterChannel(defaultAudioDevice.masterChannel, this.blobUrl);
146
+
147
+ return defaultAudioDevice;
148
+ }
149
+
150
+ public TellMeWhatTheFuckThisWholeLibraryActuallyDoes() {
151
+ return `I wanted to create a web based game and implement advanced audio, but javascript is slow so that's why this library uses Web Assembly. You dont have to use it, unless you know what the fuck you're doing. If you do, god bless you.`
152
+ }
153
153
  }
@@ -1,13 +1,12 @@
1
- import { v4 } from "uuid";
2
-
3
- export abstract class Effector {
4
-
5
- public id: string = v4();
6
- public label: string | null = null;
7
- public audioWorkletNode: AudioWorkletNode | null = null;
8
- public parentialContext: AudioContext | null = null;
9
-
10
- static name: string = "Effector";
11
-
12
- public abstract InitializeOnAttachment(parentialContext: AudioContext): Promise<void>;
1
+ import { v4 } from "uuid";
2
+
3
+ export abstract class Effector {
4
+
5
+ public id: string = v4();
6
+ public label: string | null = null;
7
+ public name: string = "Effector";
8
+ public audioWorkletNode: AudioWorkletNode | null = null;
9
+ public parentialContext: AudioContext | null = null;
10
+
11
+ public abstract InitializeOnAttachment(parentialContext: AudioContext): Promise<void>;
13
12
  }
@@ -1,50 +1,50 @@
1
- import { v4 } from "uuid";
2
-
3
- import { Channel } from "./Channel";
4
-
5
- import { Debug } from "../../utilities/debugger";
6
-
7
- export class Master {
8
-
9
- public id: string = v4();
10
- public channels: Channel[] = [];
11
- public context: AudioContext = new AudioContext();
12
-
13
- public gainNode: GainNode = this.context.createGain();
14
- public analyserNode: AnalyserNode = this.context.createAnalyser();
15
-
16
- constructor() {
17
-
18
- this.gainNode.connect(this.analyserNode);
19
- this.analyserNode.connect(this.context.destination);
20
- }
21
-
22
- public AttachChannel(channel: Channel): void {
23
-
24
- if(this.channels.includes(channel)) return Debug.Error("Could not attach the channel because it is already part of this master channel.",[
25
- "Call .DetachChannel([channel Channel]) before attaching the channel."
26
- ]);
27
-
28
- channel.InitializeChannelOnMasterAttachment(this);
29
-
30
- this.channels.push(channel);
31
- return;
32
- }
33
-
34
- public DetachChannel(channel: Channel): void {
35
-
36
- if(!this.channels.includes(channel)) return Debug.Error("Could not detach the channel because it is not part of this master channel.", [
37
- "Call .AttachChannel([channel Channel]) before detaching the channel."
38
- ]);
39
-
40
- const self = this;
41
-
42
- this.channels.forEach(function(_channel: Channel, index: number) {
43
- if(channel.id === _channel.id) {
44
-
45
- self.channels.splice(index, 1);
46
- return;
47
- }
48
- });
49
- }
1
+ import { v4 } from "uuid";
2
+
3
+ import { Channel } from "./Channel";
4
+
5
+ import { Debug } from "../../utilities/debugger";
6
+
7
+ export class Master {
8
+
9
+ public id: string = v4();
10
+ public channels: Channel[] = [];
11
+ public context: AudioContext = new AudioContext();
12
+
13
+ public gainNode: GainNode = this.context.createGain();
14
+ public analyserNode: AnalyserNode = this.context.createAnalyser();
15
+
16
+ constructor() {
17
+
18
+ this.gainNode.connect(this.analyserNode);
19
+ this.analyserNode.connect(this.context.destination);
20
+ }
21
+
22
+ public AttachChannel(channel: Channel): void {
23
+
24
+ if(this.channels.includes(channel)) return Debug.Error("Could not attach the channel because it is already part of this master channel.",[
25
+ "Call .DetachChannel([channel Channel]) before attaching the channel."
26
+ ]);
27
+
28
+ channel.InitializeChannelOnMasterAttachment(this);
29
+
30
+ this.channels.push(channel);
31
+ return;
32
+ }
33
+
34
+ public DetachChannel(channel: Channel): void {
35
+
36
+ if(!this.channels.includes(channel)) return Debug.Error("Could not detach the channel because it is not part of this master channel.", [
37
+ "Call .AttachChannel([channel Channel]) before detaching the channel."
38
+ ]);
39
+
40
+ const self = this;
41
+
42
+ this.channels.forEach(function(_channel: Channel, index: number) {
43
+ if(channel.id === _channel.id) {
44
+
45
+ self.channels.splice(index, 1);
46
+ return;
47
+ }
48
+ });
49
+ }
50
50
  }
@@ -1,6 +1,6 @@
1
- export { AudioDevice } from "./classes/AudioDevice";
2
- export { Channel } from "./classes/Channel";
3
- export { Effector } from "./classes/Effector";
4
- export { Master } from "./classes/Master";
5
- export { AudioClip } from "./classes/AudioClip";
1
+ export { AudioDevice } from "./classes/AudioDevice";
2
+ export { Channel } from "./classes/Channel";
3
+ export { Effector } from "./classes/Effector";
4
+ export { Master } from "./classes/Master";
5
+ export { AudioClip } from "./classes/AudioClip";
6
6
  export { DspPipeline } from "./classes/DpsPipeline";
@@ -1,112 +1,66 @@
1
- import { compiledWebAssemblyModule } from "../../utilities/web-assembly";
2
- import { Effector } from "../../core/classes/Effector";
3
- import { Debug } from "../../utilities/debugger";
4
- import { ChorusEffectOptions } from "../../typings";
5
-
6
- export class Chorus extends Effector {
7
-
8
- public label: string | null = "Chorus";
9
- static name: string = "Chorus";
10
-
11
- public baseDelayMs: number = 15;
12
- public depthMs: number = 8;
13
- public rateHz: number = 1.5;
14
- public mix: number = 0.5;
15
- public feedback: number = 0.2;
16
-
17
- public options: ChorusEffectOptions = {};
18
-
19
- private sampleRate: number = 0;
20
-
21
- constructor(options?: ChorusEffectOptions) {
22
- super();
23
-
24
- this.options = {
25
- baseDelayMs: this.baseDelayMs,
26
- depthMs: this.depthMs,
27
- rateHz: this.rateHz,
28
- mix: this.mix,
29
- feedback: this.mix,
30
- ...options
31
- }
32
- }
33
-
34
- public async InitializeOnAttachment(parentialContext: AudioContext): Promise<void> {
35
-
36
- if (!compiledWebAssemblyModule) return Debug.Error("Could not initialize effector because the nessecary WASM file has not been specified.", [
37
- `Effector type: Chorus`
38
- ]);
39
-
40
- this.sampleRate = parentialContext.sampleRate;
41
-
42
- this.audioWorkletNode = new AudioWorkletNode(parentialContext, "ChorusProcessor", {
43
- numberOfInputs: 1,
44
- numberOfOutputs: 1,
45
- outputChannelCount: [2],
46
- parameterData: {
47
- ...this.options,
48
- sampleRate: this.sampleRate
49
- },
50
- processorOptions: {
51
- module: compiledWebAssemblyModule
52
- }
53
- });
54
-
55
- this.parentialContext = parentialContext;
56
- }
57
-
58
- public SetBaseDelayMs(value: number) {
59
-
60
- this.baseDelayMs = value;
61
- this.options.baseDelayMs = value;
62
-
63
- this.audioWorkletNode?.port.postMessage({
64
- type: "set-base-delay-ms",
65
- value
66
- });
67
- }
68
-
69
- public SetDepthMs(value: number) {
70
-
71
- this.depthMs = value;
72
- this.options.depthMs = value;
73
-
74
- this.audioWorkletNode?.port.postMessage({
75
- type: "set-depth-ms",
76
- value
77
- });
78
- }
79
-
80
- public SetRateHz(value: number) {
81
-
82
- this.rateHz = value;
83
- this.options.rateHz = value;
84
-
85
- this.audioWorkletNode?.port.postMessage({
86
- type: "set-rate-hz",
87
- value
88
- });
89
- }
90
-
91
- public SetMix(value: number) {
92
-
93
- this.mix = value;
94
- this.options.mix = value;
95
-
96
- this.audioWorkletNode?.port.postMessage({
97
- type: "set-mix",
98
- value
99
- });
100
- }
101
-
102
- public SetFeedback(value: number) {
103
-
104
- this.feedback = value;
105
- this.options.feedback = value;
106
-
107
- this.audioWorkletNode?.port.postMessage({
108
- type: "set-mix",
109
- value
110
- });
111
- }
1
+ import { SendMessageToWorklet, CreateAudioWorkletNode } from "../../utilities/helpers";
2
+ import { Effector } from "../../core/classes/Effector";
3
+ import { ChorusEffectOptions, ChorusMessageCommandId, AudioWorkletProcessorNames } from "../../typings";
4
+
5
+ export class Chorus extends Effector {
6
+
7
+ public label: string | null = "Chorus";
8
+ public name: string = "Chorus";
9
+
10
+ public baseDelayMs: number = 15;
11
+ public depthMs: number = 8;
12
+ public rateHz: number = 1.5;
13
+ public mix: number = 0.5;
14
+ public feedback: number = 0.2;
15
+
16
+ constructor({ baseDelayMs, depthMs, rateHz, mix, feedback }: Partial<ChorusEffectOptions>) {
17
+ super();
18
+
19
+ this.baseDelayMs = baseDelayMs ?? this.baseDelayMs;
20
+ this.depthMs = depthMs ?? this.depthMs;
21
+ this.rateHz = rateHz ?? this.rateHz;
22
+ this.mix = mix ?? this.mix;
23
+ this.feedback = feedback ?? this.feedback;
24
+ }
25
+
26
+ public async InitializeOnAttachment(parentialContext: AudioContext): Promise<void> {
27
+
28
+ this.parentialContext = parentialContext;
29
+ this.audioWorkletNode = CreateAudioWorkletNode<ChorusEffectOptions>(parentialContext, AudioWorkletProcessorNames.Chorus, this.ReturnOptionsAsObject());
30
+ }
31
+
32
+ public ReturnOptionsAsObject(): ChorusEffectOptions {
33
+ return {
34
+ baseDelayMs: this.baseDelayMs,
35
+ depthMs: this.depthMs,
36
+ rateHz: this.rateHz,
37
+ mix: this.mix,
38
+ feedback: this.feedback,
39
+ }
40
+ }
41
+
42
+ public SetBaseDelayMs(value: number): boolean {
43
+ this.baseDelayMs = value;
44
+ return SendMessageToWorklet<ChorusMessageCommandId, number>(this.audioWorkletNode, ChorusMessageCommandId.SetBaseDelayMs, value);
45
+ }
46
+
47
+ public SetDepthMs(value: number) {
48
+ this.depthMs = value;
49
+ return SendMessageToWorklet<ChorusMessageCommandId, number>(this.audioWorkletNode, ChorusMessageCommandId.SetDepthMs, value);
50
+ }
51
+
52
+ public SetRateHz(value: number) {
53
+ this.rateHz = value;
54
+ return SendMessageToWorklet<ChorusMessageCommandId, number>(this.audioWorkletNode, ChorusMessageCommandId.SetRateHz, value);
55
+ }
56
+
57
+ public SetMix(value: number) {
58
+ this.mix = value;
59
+ return SendMessageToWorklet<ChorusMessageCommandId, number>(this.audioWorkletNode, ChorusMessageCommandId.SetMix, value);
60
+ }
61
+
62
+ public SetFeedback(value: number) {
63
+ this.feedback = value;
64
+ return SendMessageToWorklet<ChorusMessageCommandId, number>(this.audioWorkletNode, ChorusMessageCommandId.SetFeedback, value);
65
+ }
112
66
  }
@@ -1,14 +1,14 @@
1
- import { Effector } from "../../core/classes/Effector";
2
-
3
- export class Distortion extends Effector {
4
-
5
- static name: string = "Distortion";
6
-
7
- constructor() {
8
- super();
9
- }
10
-
11
- public async InitializeOnAttachment(parentialContext: AudioContext): Promise<void> {
12
-
13
- }
1
+ import { Effector } from "../../core/classes/Effector";
2
+
3
+ export class Distortion extends Effector {
4
+
5
+ public name: string = "Distortion";
6
+
7
+ constructor() {
8
+ super();
9
+ }
10
+
11
+ public async InitializeOnAttachment(parentialContext: AudioContext): Promise<void> {
12
+
13
+ }
14
14
  }
@@ -1,3 +1,3 @@
1
- export class Saturation {
2
-
1
+ export class Saturation {
2
+
3
3
  }