@fluex/fluexgl-dsp 0.1.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.
- package/README.md +87 -0
- package/lib/dist/console-codes.d.ts +14 -0
- package/lib/dist/console-codes.d.ts.map +1 -0
- package/lib/dist/console-codes.js +16 -0
- package/lib/dist/core/classes/AudioClip.d.ts +67 -0
- package/lib/dist/core/classes/AudioClip.d.ts.map +1 -0
- package/lib/dist/core/classes/AudioClip.js +410 -0
- package/lib/dist/core/classes/AudioDevice.d.ts +13 -0
- package/lib/dist/core/classes/AudioDevice.d.ts.map +1 -0
- package/lib/dist/core/classes/AudioDevice.js +30 -0
- package/lib/dist/core/classes/Channel.d.ts +30 -0
- package/lib/dist/core/classes/Channel.d.ts.map +1 -0
- package/lib/dist/core/classes/Channel.js +144 -0
- package/lib/dist/core/classes/DpsPipeline.d.ts +60 -0
- package/lib/dist/core/classes/DpsPipeline.d.ts.map +1 -0
- package/lib/dist/core/classes/DpsPipeline.js +115 -0
- package/lib/dist/core/classes/Effector.d.ts +8 -0
- package/lib/dist/core/classes/Effector.d.ts.map +1 -0
- package/lib/dist/core/classes/Effector.js +7 -0
- package/lib/dist/core/classes/Master.d.ts +12 -0
- package/lib/dist/core/classes/Master.d.ts.map +1 -0
- package/lib/dist/core/classes/Master.js +35 -0
- package/lib/dist/core/exports.d.ts +7 -0
- package/lib/dist/core/exports.d.ts.map +1 -0
- package/lib/dist/core/exports.js +6 -0
- package/lib/dist/effects/classes/Chorus.d.ts +19 -0
- package/lib/dist/effects/classes/Chorus.d.ts.map +1 -0
- package/lib/dist/effects/classes/Chorus.js +83 -0
- package/lib/dist/effects/classes/Distortion.d.ts +3 -0
- package/lib/dist/effects/classes/Distortion.d.ts.map +1 -0
- package/lib/dist/effects/classes/Distortion.js +2 -0
- package/lib/dist/effects/classes/Equalizer.d.ts +3 -0
- package/lib/dist/effects/classes/Equalizer.d.ts.map +1 -0
- package/lib/dist/effects/classes/Equalizer.js +2 -0
- package/lib/dist/effects/classes/Filter.d.ts +3 -0
- package/lib/dist/effects/classes/Filter.d.ts.map +1 -0
- package/lib/dist/effects/classes/Filter.js +2 -0
- package/lib/dist/effects/classes/Limiter.d.ts +3 -0
- package/lib/dist/effects/classes/Limiter.d.ts.map +1 -0
- package/lib/dist/effects/classes/Limiter.js +2 -0
- package/lib/dist/effects/classes/Saturation.d.ts +3 -0
- package/lib/dist/effects/classes/Saturation.d.ts.map +1 -0
- package/lib/dist/effects/classes/Saturation.js +2 -0
- package/lib/dist/effects/classes/SoftClip.d.ts +8 -0
- package/lib/dist/effects/classes/SoftClip.d.ts.map +1 -0
- package/lib/dist/effects/classes/SoftClip.js +37 -0
- package/lib/dist/effects/classes/StereoPanner.d.ts +3 -0
- package/lib/dist/effects/classes/StereoPanner.d.ts.map +1 -0
- package/lib/dist/effects/classes/StereoPanner.js +2 -0
- package/lib/dist/effects/classes/compressors/Compressor.d.ts +3 -0
- package/lib/dist/effects/classes/compressors/Compressor.d.ts.map +1 -0
- package/lib/dist/effects/classes/compressors/Compressor.js +2 -0
- package/lib/dist/effects/classes/compressors/MultibandCompressor.d.ts +3 -0
- package/lib/dist/effects/classes/compressors/MultibandCompressor.d.ts.map +1 -0
- package/lib/dist/effects/classes/compressors/MultibandCompressor.js +2 -0
- package/lib/dist/effects/classes/delays/AdvancedDelay.d.ts +3 -0
- package/lib/dist/effects/classes/delays/AdvancedDelay.d.ts.map +1 -0
- package/lib/dist/effects/classes/delays/AdvancedDelay.js +2 -0
- package/lib/dist/effects/classes/delays/MonoDelay.d.ts +3 -0
- package/lib/dist/effects/classes/delays/MonoDelay.d.ts.map +1 -0
- package/lib/dist/effects/classes/delays/MonoDelay.js +2 -0
- package/lib/dist/effects/classes/delays/PingPongDelay.d.ts +3 -0
- package/lib/dist/effects/classes/delays/PingPongDelay.d.ts.map +1 -0
- package/lib/dist/effects/classes/delays/PingPongDelay.js +2 -0
- package/lib/dist/effects/classes/delays/StereoDelay.d.ts +3 -0
- package/lib/dist/effects/classes/delays/StereoDelay.d.ts.map +1 -0
- package/lib/dist/effects/classes/delays/StereoDelay.js +2 -0
- package/lib/dist/effects/classes/reverbs/ChamberReverb.d.ts +3 -0
- package/lib/dist/effects/classes/reverbs/ChamberReverb.d.ts.map +1 -0
- package/lib/dist/effects/classes/reverbs/ChamberReverb.js +2 -0
- package/lib/dist/effects/classes/reverbs/ConvolverReverb.d.ts +3 -0
- package/lib/dist/effects/classes/reverbs/ConvolverReverb.d.ts.map +1 -0
- package/lib/dist/effects/classes/reverbs/ConvolverReverb.js +2 -0
- package/lib/dist/effects/classes/reverbs/GenericReverb.d.ts +3 -0
- package/lib/dist/effects/classes/reverbs/GenericReverb.d.ts.map +1 -0
- package/lib/dist/effects/classes/reverbs/GenericReverb.js +2 -0
- package/lib/dist/effects/classes/reverbs/HallReverb.d.ts +3 -0
- package/lib/dist/effects/classes/reverbs/HallReverb.d.ts.map +1 -0
- package/lib/dist/effects/classes/reverbs/HallReverb.js +2 -0
- package/lib/dist/effects/classes/reverbs/RoomReverb.d.ts +3 -0
- package/lib/dist/effects/classes/reverbs/RoomReverb.d.ts.map +1 -0
- package/lib/dist/effects/classes/reverbs/RoomReverb.js +2 -0
- package/lib/dist/effects/exports.d.ts +20 -0
- package/lib/dist/effects/exports.d.ts.map +1 -0
- package/lib/dist/effects/exports.js +19 -0
- package/lib/dist/index.d.ts +13 -0
- package/lib/dist/index.d.ts.map +1 -0
- package/lib/dist/index.js +28 -0
- package/lib/dist/typings.d.ts +67 -0
- package/lib/dist/typings.d.ts.map +1 -0
- package/lib/dist/typings.js +1 -0
- package/lib/dist/utilities/constants.d.ts +2 -0
- package/lib/dist/utilities/constants.d.ts.map +1 -0
- package/lib/dist/utilities/constants.js +9 -0
- package/lib/dist/utilities/debugger.d.ts +8 -0
- package/lib/dist/utilities/debugger.d.ts.map +1 -0
- package/lib/dist/utilities/debugger.js +49 -0
- package/lib/dist/utilities/helpers.d.ts +41 -0
- package/lib/dist/utilities/helpers.d.ts.map +1 -0
- package/lib/dist/utilities/helpers.js +148 -0
- package/lib/dist/utilities/web-assembly.d.ts +4 -0
- package/lib/dist/utilities/web-assembly.d.ts.map +1 -0
- package/lib/dist/utilities/web-assembly.js +12 -0
- package/lib/src/console-codes.ts +16 -0
- package/lib/src/core/classes/AudioClip.ts +545 -0
- package/lib/src/core/classes/AudioDevice.ts +39 -0
- package/lib/src/core/classes/Channel.ts +199 -0
- package/lib/src/core/classes/DpsPipeline.ts +153 -0
- package/lib/src/core/classes/Effector.ts +11 -0
- package/lib/src/core/classes/Master.ts +50 -0
- package/lib/src/core/exports.ts +6 -0
- package/lib/src/effects/classes/Chorus.ts +109 -0
- package/lib/src/effects/classes/Distortion.ts +1 -0
- package/lib/src/effects/classes/Equalizer.ts +1 -0
- package/lib/src/effects/classes/Filter.ts +1 -0
- package/lib/src/effects/classes/Limiter.ts +1 -0
- package/lib/src/effects/classes/Saturation.ts +1 -0
- package/lib/src/effects/classes/SoftClip.ts +42 -0
- package/lib/src/effects/classes/StereoPanner.ts +1 -0
- package/lib/src/effects/classes/compressors/Compressor.ts +1 -0
- package/lib/src/effects/classes/compressors/MultibandCompressor.ts +1 -0
- package/lib/src/effects/classes/delays/AdvancedDelay.ts +1 -0
- package/lib/src/effects/classes/delays/MonoDelay.ts +1 -0
- package/lib/src/effects/classes/delays/PingPongDelay.ts +1 -0
- package/lib/src/effects/classes/delays/StereoDelay.ts +1 -0
- package/lib/src/effects/classes/reverbs/ChamberReverb.ts +1 -0
- package/lib/src/effects/classes/reverbs/ConvolverReverb.ts +1 -0
- package/lib/src/effects/classes/reverbs/GenericReverb.ts +1 -0
- package/lib/src/effects/classes/reverbs/HallReverb.ts +1 -0
- package/lib/src/effects/classes/reverbs/RoomReverb.ts +1 -0
- package/lib/src/effects/exports.ts +22 -0
- package/lib/src/index.ts +93 -0
- package/lib/src/typings.ts +79 -0
- package/lib/src/utilities/constants.ts +9 -0
- package/lib/src/utilities/debugger.ts +66 -0
- package/lib/src/utilities/helpers.ts +215 -0
- package/lib/src/utilities/web-assembly.ts +14 -0
- package/package.json +50 -0
package/lib/src/index.ts
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FluexGL Audio
|
|
3
|
+
* A javascript digital audio processor library.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { FluexGLAudioDescriptor } from "./typings";
|
|
7
|
+
|
|
8
|
+
export const FluexGLAudio: FluexGLAudioDescriptor = {
|
|
9
|
+
name: "FluexGL Audio",
|
|
10
|
+
author: "Rohan Kanhaisingh",
|
|
11
|
+
version: "0.0.2",
|
|
12
|
+
license: "MIT",
|
|
13
|
+
repository: "https://github.com/rohankanhaisingh/FluexGL-Audio",
|
|
14
|
+
options: {
|
|
15
|
+
maxMasterChannels: 8,
|
|
16
|
+
maxTotalChannels: 128,
|
|
17
|
+
sampleRate: 44000,
|
|
18
|
+
spatialization: "stereo",
|
|
19
|
+
debugger: {
|
|
20
|
+
showErrors: true,
|
|
21
|
+
showInfo: true,
|
|
22
|
+
showWarnings: true,
|
|
23
|
+
breakOnError: true
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export {
|
|
29
|
+
Chorus,
|
|
30
|
+
Distortion,
|
|
31
|
+
Equalizer,
|
|
32
|
+
Filter,
|
|
33
|
+
Limiter,
|
|
34
|
+
Saturation,
|
|
35
|
+
StereoPanner,
|
|
36
|
+
Compressor,
|
|
37
|
+
MultibandCompressor,
|
|
38
|
+
AdvancedDelay,
|
|
39
|
+
MonoDelay,
|
|
40
|
+
PingPongDelay,
|
|
41
|
+
StereoDelay,
|
|
42
|
+
ChamberReverb,
|
|
43
|
+
ConvolverReverb,
|
|
44
|
+
GenericReverb,
|
|
45
|
+
HallReverb,
|
|
46
|
+
RoomReverb,
|
|
47
|
+
SoftClip
|
|
48
|
+
} from "./effects/exports";
|
|
49
|
+
|
|
50
|
+
export {
|
|
51
|
+
AudioDevice,
|
|
52
|
+
Channel,
|
|
53
|
+
Effector,
|
|
54
|
+
Master,
|
|
55
|
+
AudioClip,
|
|
56
|
+
DspPipeline
|
|
57
|
+
} from "./core/exports";
|
|
58
|
+
|
|
59
|
+
export {
|
|
60
|
+
InitializeDspPipeline,
|
|
61
|
+
ResolveAudioOutputDevices,
|
|
62
|
+
ResolveAudioInputDevices,
|
|
63
|
+
ResolveDefaultAudioInputDevice,
|
|
64
|
+
ResolveDefaultAudioOutputDevice,
|
|
65
|
+
LoadAudioSource,
|
|
66
|
+
LoadWorkletOnMasterChannel,
|
|
67
|
+
} from "./utilities/helpers";
|
|
68
|
+
|
|
69
|
+
export {
|
|
70
|
+
SUPPORTED_FILE_TYPES
|
|
71
|
+
} from "./utilities/constants";
|
|
72
|
+
|
|
73
|
+
export {
|
|
74
|
+
hasInitializedWasm,
|
|
75
|
+
} from "./utilities/web-assembly";
|
|
76
|
+
|
|
77
|
+
export type {
|
|
78
|
+
FluexGLAudioDescriptor,
|
|
79
|
+
FluexGLAudioDebuggerOptions,
|
|
80
|
+
FluexGLAudioOptions,
|
|
81
|
+
LoadAudioSourceOptions,
|
|
82
|
+
AudioSourceData,
|
|
83
|
+
ChannelOptions,
|
|
84
|
+
ChannelSpatialization,
|
|
85
|
+
AudioClipEventMap,
|
|
86
|
+
AudioClipEvents,
|
|
87
|
+
AudioClipOnProgressEvent,
|
|
88
|
+
AudioClipAnalyserProperty,
|
|
89
|
+
AudioClipAnalyserType,
|
|
90
|
+
DspPipelineInitializationOptions,
|
|
91
|
+
DspPipelineInitializationState,
|
|
92
|
+
ChorusEffectOptions
|
|
93
|
+
} from "./typings";
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
export type ChannelSpatialization = "mono" | "stereo" | "surround";
|
|
2
|
+
|
|
3
|
+
export type AudioClipAnalyserType = "pre" | "post";
|
|
4
|
+
export type AudioClipAnalyserProperty = "fftSize" | "minDecibels" | "maxDecibels" | "smoothingTimeConstant";
|
|
5
|
+
|
|
6
|
+
export type AudioClipEvents = {
|
|
7
|
+
[K in keyof AudioClipEventMap]: AudioClipEventMap[K][];
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface FluexGLAudioDebuggerOptions {
|
|
11
|
+
breakOnError: boolean;
|
|
12
|
+
showInfo: boolean;
|
|
13
|
+
showErrors: boolean;
|
|
14
|
+
showWarnings: boolean;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface FluexGLAudioOptions {
|
|
18
|
+
maxMasterChannels: number;
|
|
19
|
+
maxTotalChannels: number;
|
|
20
|
+
sampleRate: number;
|
|
21
|
+
spatialization: ChannelSpatialization;
|
|
22
|
+
debugger: FluexGLAudioDebuggerOptions;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface FluexGLAudioDescriptor {
|
|
26
|
+
name: string;
|
|
27
|
+
author: string;
|
|
28
|
+
version: string;
|
|
29
|
+
license: string;
|
|
30
|
+
repository: string;
|
|
31
|
+
options: FluexGLAudioOptions;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface LoadAudioSourceOptions {
|
|
35
|
+
allowForeignFileTypes: boolean;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface AudioSourceData {
|
|
39
|
+
arrayBuffer: ArrayBuffer;
|
|
40
|
+
audioBuffer: AudioBuffer;
|
|
41
|
+
id: string;
|
|
42
|
+
timestamp: number;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface ChannelOptions {
|
|
46
|
+
label: string | null;
|
|
47
|
+
maxAudioNodes: number;
|
|
48
|
+
maxEffects: number;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface AudioClipOnProgressEvent {
|
|
52
|
+
startTime: number;
|
|
53
|
+
offset: number;
|
|
54
|
+
current: number;
|
|
55
|
+
contextTimestamp: number;
|
|
56
|
+
formatted: string;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export interface AudioClipEventMap {
|
|
60
|
+
"progress": (event: AudioClipOnProgressEvent) => void;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export interface DspPipelineInitializationOptions {
|
|
64
|
+
pathToWasm: string;
|
|
65
|
+
pathToWorklet: string;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export interface DspPipelineInitializationState {
|
|
69
|
+
success: boolean;
|
|
70
|
+
workletBlobUrl: string;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export interface ChorusEffectOptions {
|
|
74
|
+
baseDelayMs?: number;
|
|
75
|
+
depthMs?: number;
|
|
76
|
+
rateHz?: number;
|
|
77
|
+
mix?: number;
|
|
78
|
+
feedback?: number;
|
|
79
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { ErrorCodes, WarningCodes } from "../console-codes";
|
|
2
|
+
|
|
3
|
+
import { FluexGLAudio } from "../index";
|
|
4
|
+
|
|
5
|
+
export namespace Debug {
|
|
6
|
+
|
|
7
|
+
export function Log(message: string, additionalDetails?: string[]) {
|
|
8
|
+
|
|
9
|
+
if (!FluexGLAudio.options.debugger.showInfo) return;
|
|
10
|
+
|
|
11
|
+
let outputString: string = `%c[INFO]: %c${message} %c`;
|
|
12
|
+
|
|
13
|
+
additionalDetails && additionalDetails.forEach(function (detail: string) {
|
|
14
|
+
outputString += `\n\u0009 > ${detail}`
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
return console.log(outputString, "color: white;", "color: gray", "color: gray");
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function Success(message: string, additionalDetails?: string[]) {
|
|
21
|
+
|
|
22
|
+
if (!FluexGLAudio.options.debugger.showInfo) return;
|
|
23
|
+
|
|
24
|
+
let outputString: string = `%c[SUCCESS]: %c${message} %c`;
|
|
25
|
+
|
|
26
|
+
additionalDetails && additionalDetails.forEach(function (detail: string) {
|
|
27
|
+
outputString += `\n\u0009 > ${detail}`
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
return console.log(outputString, "color: lime;", "color: white", "color: gray");
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function Warn(message: string, additionalDetails?: string[], warningCode?: WarningCodes) {
|
|
34
|
+
|
|
35
|
+
if (!FluexGLAudio.options.debugger.showWarnings) return;
|
|
36
|
+
|
|
37
|
+
let outputString: string = `%c(${warningCode ? warningCode : "Unknown".toUpperCase()}) %c[WARNING]: %c${message} %c`;
|
|
38
|
+
|
|
39
|
+
(additionalDetails && additionalDetails !== null) && additionalDetails.forEach(function (detail: string) {
|
|
40
|
+
outputString += `\n\u0009 > ${detail}`
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
return console.log(outputString, "color: gray", "color: yellow;", "color: white", "color: white; font-style: italic;");
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function Error(message: string, additionalDetails?: string[], errorCode?: ErrorCodes) {
|
|
47
|
+
|
|
48
|
+
if (!FluexGLAudio.options.debugger.showErrors) return;
|
|
49
|
+
|
|
50
|
+
let outputString: string = `%c(${errorCode ? errorCode : "Unknown".toUpperCase()}) %c[ERROR]: %c${message} %c`;
|
|
51
|
+
|
|
52
|
+
(additionalDetails && additionalDetails !== null) && additionalDetails.forEach(function (detail: string) {
|
|
53
|
+
outputString += `\n\u0009 > ${detail}`
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
console.log(outputString, "color: red", "color: red;", "color: white", "color: white; font-style: italic;");
|
|
57
|
+
|
|
58
|
+
if (FluexGLAudio.options.debugger.breakOnError) {
|
|
59
|
+
|
|
60
|
+
for (let char of message)
|
|
61
|
+
outputString = outputString.replace("%c", "");
|
|
62
|
+
|
|
63
|
+
throw new window.Error(outputString);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import mime from "mime";
|
|
2
|
+
import { v4 } from "uuid";
|
|
3
|
+
|
|
4
|
+
import { AudioDevice } from "../core/classes/AudioDevice";
|
|
5
|
+
import { Master } from "../core/classes/Master";
|
|
6
|
+
|
|
7
|
+
import { Debug } from "./debugger";
|
|
8
|
+
import { SUPPORTED_FILE_TYPES } from "./constants";
|
|
9
|
+
|
|
10
|
+
import { LoadWebAssemblyModule } from "./web-assembly";
|
|
11
|
+
import { ErrorCodes, WarningCodes } from "../console-codes";
|
|
12
|
+
|
|
13
|
+
import { LoadAudioSourceOptions, AudioSourceData, DspPipelineInitializationOptions, DspPipelineInitializationState } from "../typings";
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Initializes the DSP pipeline by requesting audio permissions and initializing the WASM module.
|
|
17
|
+
* Very important to call this function and wait for it to complete before using any audio features.
|
|
18
|
+
*
|
|
19
|
+
* FluexGL DSP cannot be used without calling this function first.
|
|
20
|
+
* @returns
|
|
21
|
+
*/
|
|
22
|
+
export async function InitializeDspPipeline(options: DspPipelineInitializationOptions): Promise<DspPipelineInitializationState | null> {
|
|
23
|
+
Debug.Log("Attempting to initialize DSP pipeline...");
|
|
24
|
+
|
|
25
|
+
const start: number = Date.now();
|
|
26
|
+
let initialized: boolean = true;
|
|
27
|
+
|
|
28
|
+
try {
|
|
29
|
+
|
|
30
|
+
const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
|
|
31
|
+
|
|
32
|
+
Debug.Log(`Found ${stream.getTracks().length} media stream tracks.`);
|
|
33
|
+
|
|
34
|
+
stream.getTracks().forEach(function (track: MediaStreamTrack) {
|
|
35
|
+
track.stop();
|
|
36
|
+
});
|
|
37
|
+
} catch (err) {
|
|
38
|
+
|
|
39
|
+
initialized = false;
|
|
40
|
+
|
|
41
|
+
Debug.Error("Permission to access media devices has not been granted.", [
|
|
42
|
+
"Make sure the user has granted FluentGL permission to access media devices."
|
|
43
|
+
], ErrorCodes.NO_CONTEXT_PERMISSION)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
await LoadWebAssemblyModule(options.pathToWasm);
|
|
47
|
+
|
|
48
|
+
const workletFileRequest = await fetch(options.pathToWorklet);
|
|
49
|
+
const textContent: string = await workletFileRequest.text();
|
|
50
|
+
|
|
51
|
+
const blobUrl: string = ConstructProcessorWorklet(textContent);
|
|
52
|
+
|
|
53
|
+
const end: number = Date.now(),
|
|
54
|
+
difference: number = end - start;
|
|
55
|
+
|
|
56
|
+
Debug.Success(`Succesfully initialized DSP pipeline within ${difference}ms.`);
|
|
57
|
+
|
|
58
|
+
return {
|
|
59
|
+
success: true,
|
|
60
|
+
workletBlobUrl: blobUrl
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Resolves a list of available audio output devices.
|
|
66
|
+
* @returns
|
|
67
|
+
*/
|
|
68
|
+
export async function ResolveAudioOutputDevices(): Promise<AudioDevice[]> {
|
|
69
|
+
|
|
70
|
+
const devices = await navigator.mediaDevices.enumerateDevices();
|
|
71
|
+
|
|
72
|
+
const audioDevices: AudioDevice[] = [];
|
|
73
|
+
|
|
74
|
+
for (let device of devices)
|
|
75
|
+
device.kind === "audiooutput" && audioDevices.push(new AudioDevice(device));
|
|
76
|
+
|
|
77
|
+
return audioDevices;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Resolves a list of available audio input devices.
|
|
82
|
+
* @returns
|
|
83
|
+
*/
|
|
84
|
+
export async function ResolveAudioInputDevices(): Promise<AudioDevice[]> {
|
|
85
|
+
|
|
86
|
+
const devices = await navigator.mediaDevices.enumerateDevices();
|
|
87
|
+
|
|
88
|
+
const audioDevices: AudioDevice[] = [];
|
|
89
|
+
|
|
90
|
+
for (let device of devices)
|
|
91
|
+
device.kind === "audioinput" && audioDevices.push(new AudioDevice(device));
|
|
92
|
+
|
|
93
|
+
return audioDevices;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Resolves the default audio output device.
|
|
98
|
+
* @returns
|
|
99
|
+
*/
|
|
100
|
+
export async function ResolveDefaultAudioOutputDevice(init: DspPipelineInitializationState): Promise<AudioDevice | null> {
|
|
101
|
+
Debug.Log("Attempting to resolve default audio output device...");
|
|
102
|
+
|
|
103
|
+
const audioDeviceInfos: MediaDeviceInfo[] = [];
|
|
104
|
+
const devices = await navigator.mediaDevices.enumerateDevices();
|
|
105
|
+
|
|
106
|
+
for (let device of devices)
|
|
107
|
+
(device.kind === "audiooutput" && device.deviceId == "default")
|
|
108
|
+
&& audioDeviceInfos.push(device);
|
|
109
|
+
|
|
110
|
+
devices.length === 0 && Debug.Warn("No default audio device found.", [], WarningCodes.NO_DEFAULT_AUDIO_DEVICE_FOUND);
|
|
111
|
+
|
|
112
|
+
const defaultAudioDevice = devices.length === 0 ? null : new AudioDevice(audioDeviceInfos[0]);
|
|
113
|
+
|
|
114
|
+
if(!defaultAudioDevice) return null;
|
|
115
|
+
|
|
116
|
+
await LoadWorkletOnMasterChannel(defaultAudioDevice.masterChannel, init.workletBlobUrl);
|
|
117
|
+
|
|
118
|
+
return defaultAudioDevice;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Resolves the default audio input device.
|
|
123
|
+
* @returns
|
|
124
|
+
*/
|
|
125
|
+
export async function ResolveDefaultAudioInputDevice(init: DspPipelineInitializationState): Promise<AudioDevice | null> {
|
|
126
|
+
Debug.Log("Attempting to resolve default audio output device...");
|
|
127
|
+
|
|
128
|
+
const audioDeviceInfos: MediaDeviceInfo[] = [];
|
|
129
|
+
const devices = await navigator.mediaDevices.enumerateDevices();
|
|
130
|
+
|
|
131
|
+
for (let device of devices)
|
|
132
|
+
(device.kind === "audioinput" && device.deviceId == "default")
|
|
133
|
+
&& audioDeviceInfos.push(device);
|
|
134
|
+
|
|
135
|
+
devices.length === 0 && Debug.Warn("No default audio device found.", [], WarningCodes.NO_DEFAULT_AUDIO_DEVICE_FOUND);
|
|
136
|
+
|
|
137
|
+
const defaultAudioDevice = devices.length === 0 ? null : new AudioDevice(audioDeviceInfos[0]);
|
|
138
|
+
|
|
139
|
+
if(!defaultAudioDevice) return null;
|
|
140
|
+
|
|
141
|
+
await LoadWorkletOnMasterChannel(defaultAudioDevice.masterChannel, init.workletBlobUrl);
|
|
142
|
+
|
|
143
|
+
return defaultAudioDevice;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Loads an audio source from a specified path.
|
|
148
|
+
* @param path
|
|
149
|
+
* @param options
|
|
150
|
+
* @returns
|
|
151
|
+
*/
|
|
152
|
+
export async function LoadAudioSource(path: string, options: Partial<LoadAudioSourceOptions> = { allowForeignFileTypes: false }): Promise<AudioSourceData | null> {
|
|
153
|
+
|
|
154
|
+
const extension: string | null = mime.getType(path);
|
|
155
|
+
|
|
156
|
+
if (!extension && !options.allowForeignFileTypes) {
|
|
157
|
+
|
|
158
|
+
Debug.Error("The file type of the specified file could not be identified.", [
|
|
159
|
+
`Set allowForeignFileTypes to true in the properties to allow foreign or unknown file types.`
|
|
160
|
+
], ErrorCodes.NO_FILE_TYPE_FOUND);
|
|
161
|
+
return null;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
if (!SUPPORTED_FILE_TYPES.includes(extension as string)) Debug.Warn("The file type of the specified file is unknown and possibly unknown, but will be used anyways.");
|
|
165
|
+
|
|
166
|
+
const file = await fetch(path, { method: "get" });
|
|
167
|
+
|
|
168
|
+
if (file.status !== 200) {
|
|
169
|
+
|
|
170
|
+
Debug.Error("The specified file could not be loaded.", [
|
|
171
|
+
`Received status code: ${file.status}.`
|
|
172
|
+
], ErrorCodes.PATH_TO_FILE_NOT_FOUND);
|
|
173
|
+
return null;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const tempContext = new AudioContext(),
|
|
177
|
+
arrayBuffer = await file.arrayBuffer(),
|
|
178
|
+
audioBuffer = await tempContext.decodeAudioData(arrayBuffer);
|
|
179
|
+
|
|
180
|
+
// IMPORTANT!
|
|
181
|
+
tempContext.close();
|
|
182
|
+
|
|
183
|
+
return {
|
|
184
|
+
arrayBuffer, audioBuffer,
|
|
185
|
+
id: v4(),
|
|
186
|
+
timestamp: Date.now()
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
export function ConstructProcessorWorklet(code: string): string {
|
|
191
|
+
|
|
192
|
+
const blob = new Blob([code], {
|
|
193
|
+
type: "application/javascript"
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
return URL.createObjectURL(blob);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
export async function LoadWorkletOnMasterChannel(master: Master, workletBlobUrl: string) {
|
|
200
|
+
Debug.Log("Loading worklet modules on master channel...", [ `Channel ID: ${master.id}` ]);
|
|
201
|
+
|
|
202
|
+
const context: AudioContext = master.context,
|
|
203
|
+
start: number = Date.now();
|
|
204
|
+
|
|
205
|
+
await context.audioWorklet.addModule(workletBlobUrl);
|
|
206
|
+
|
|
207
|
+
const end: number = Date.now(),
|
|
208
|
+
difference: number = end - start;
|
|
209
|
+
|
|
210
|
+
Debug.Success("Succesfully loaded audio processor worklets into master channel.", [
|
|
211
|
+
`Executed in ${difference}ms.`,
|
|
212
|
+
]);
|
|
213
|
+
|
|
214
|
+
return true;
|
|
215
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export let hasInitializedWasm: boolean = false;
|
|
2
|
+
export let compiledWebAssemblyModule: WebAssembly.Module | null = null;
|
|
3
|
+
|
|
4
|
+
export async function LoadWebAssemblyModule(path: string): Promise<WebAssembly.Module> {
|
|
5
|
+
|
|
6
|
+
return new Promise(function(resolve, reject) {
|
|
7
|
+
WebAssembly.compileStreaming(fetch(path)).then(function(module: WebAssembly.Module) {
|
|
8
|
+
compiledWebAssemblyModule = module;
|
|
9
|
+
resolve(module);
|
|
10
|
+
}).catch(function(error: Error) {
|
|
11
|
+
reject(error);
|
|
12
|
+
});
|
|
13
|
+
})
|
|
14
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@fluex/fluexgl-dsp",
|
|
3
|
+
"version": "0.1.2",
|
|
4
|
+
"description": "An open-source, web-based DSP library developed alongside FluexGL, designed for creating and manipulating sounds in various contexts.",
|
|
5
|
+
"main": "lib/dist/index.js",
|
|
6
|
+
"types": "lib/dist/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"typecheck": "tsc -p lib/tsconfig.json --noEmit",
|
|
9
|
+
"build": "tsc --build"
|
|
10
|
+
},
|
|
11
|
+
"keywords": [
|
|
12
|
+
"Audio",
|
|
13
|
+
"WebAudio",
|
|
14
|
+
"Advanced",
|
|
15
|
+
"audio",
|
|
16
|
+
"processing",
|
|
17
|
+
"DSP"
|
|
18
|
+
],
|
|
19
|
+
"files": [
|
|
20
|
+
"lib",
|
|
21
|
+
"README.md",
|
|
22
|
+
"LICENSE"
|
|
23
|
+
],
|
|
24
|
+
"author": "Rohan Kanhaisingh",
|
|
25
|
+
"license": "MIT",
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"@types/uuid": "^10.0.0",
|
|
28
|
+
"date-fns": "^4.1.0",
|
|
29
|
+
"mime": "^4.1.0",
|
|
30
|
+
"terser": "^5.44.0",
|
|
31
|
+
"truncate": "^3.0.0",
|
|
32
|
+
"uuid": "^13.0.0"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@types/node": "^24.9.2",
|
|
36
|
+
"concurrently": "^9.2.1"
|
|
37
|
+
},
|
|
38
|
+
"directories": {
|
|
39
|
+
"doc": "docs",
|
|
40
|
+
"lib": "lib"
|
|
41
|
+
},
|
|
42
|
+
"repository": {
|
|
43
|
+
"type": "git",
|
|
44
|
+
"url": "git+https://github.com/rohankanhaisingh/FluexGL-DSP.git"
|
|
45
|
+
},
|
|
46
|
+
"bugs": {
|
|
47
|
+
"url": "https://github.com/rohankanhaisingh/FluexGL-DSP/issues"
|
|
48
|
+
},
|
|
49
|
+
"homepage": "https://github.com/rohankanhaisingh/FluexGL-DSP#readme"
|
|
50
|
+
}
|