@waveform-playlist/playout 10.0.0 → 10.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +21 -0
- package/dist/index.d.mts +5 -37
- package/dist/index.d.ts +5 -37
- package/dist/index.js +18 -103
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +9 -86
- package/dist/index.mjs.map +1 -1
- package/package.json +13 -13
package/dist/index.mjs
CHANGED
|
@@ -19,6 +19,15 @@ import {
|
|
|
19
19
|
} from "tone";
|
|
20
20
|
|
|
21
21
|
// src/fades.ts
|
|
22
|
+
import {
|
|
23
|
+
linearCurve,
|
|
24
|
+
exponentialCurve,
|
|
25
|
+
sCurveCurve,
|
|
26
|
+
logarithmicCurve,
|
|
27
|
+
generateCurve,
|
|
28
|
+
applyFadeIn,
|
|
29
|
+
applyFadeOut
|
|
30
|
+
} from "@waveform-playlist/core";
|
|
22
31
|
var hasWarned = false;
|
|
23
32
|
function getUnderlyingAudioParam(signal) {
|
|
24
33
|
const param = signal._param;
|
|
@@ -30,92 +39,6 @@ function getUnderlyingAudioParam(signal) {
|
|
|
30
39
|
}
|
|
31
40
|
return param;
|
|
32
41
|
}
|
|
33
|
-
function linearCurve(length, fadeIn) {
|
|
34
|
-
const curve = new Float32Array(length);
|
|
35
|
-
const scale = length - 1;
|
|
36
|
-
for (let i = 0; i < length; i++) {
|
|
37
|
-
const x = i / scale;
|
|
38
|
-
curve[i] = fadeIn ? x : 1 - x;
|
|
39
|
-
}
|
|
40
|
-
return curve;
|
|
41
|
-
}
|
|
42
|
-
function exponentialCurve(length, fadeIn) {
|
|
43
|
-
const curve = new Float32Array(length);
|
|
44
|
-
const scale = length - 1;
|
|
45
|
-
for (let i = 0; i < length; i++) {
|
|
46
|
-
const x = i / scale;
|
|
47
|
-
const index = fadeIn ? i : length - 1 - i;
|
|
48
|
-
curve[index] = Math.exp(2 * x - 1) / Math.E;
|
|
49
|
-
}
|
|
50
|
-
return curve;
|
|
51
|
-
}
|
|
52
|
-
function sCurveCurve(length, fadeIn) {
|
|
53
|
-
const curve = new Float32Array(length);
|
|
54
|
-
const phase = fadeIn ? Math.PI / 2 : -Math.PI / 2;
|
|
55
|
-
for (let i = 0; i < length; i++) {
|
|
56
|
-
curve[i] = Math.sin(Math.PI * i / length - phase) / 2 + 0.5;
|
|
57
|
-
}
|
|
58
|
-
return curve;
|
|
59
|
-
}
|
|
60
|
-
function logarithmicCurve(length, fadeIn, base = 10) {
|
|
61
|
-
const curve = new Float32Array(length);
|
|
62
|
-
for (let i = 0; i < length; i++) {
|
|
63
|
-
const index = fadeIn ? i : length - 1 - i;
|
|
64
|
-
const x = i / length;
|
|
65
|
-
curve[index] = Math.log(1 + base * x) / Math.log(1 + base);
|
|
66
|
-
}
|
|
67
|
-
return curve;
|
|
68
|
-
}
|
|
69
|
-
function generateCurve(type, length, fadeIn) {
|
|
70
|
-
switch (type) {
|
|
71
|
-
case "linear":
|
|
72
|
-
return linearCurve(length, fadeIn);
|
|
73
|
-
case "exponential":
|
|
74
|
-
return exponentialCurve(length, fadeIn);
|
|
75
|
-
case "sCurve":
|
|
76
|
-
return sCurveCurve(length, fadeIn);
|
|
77
|
-
case "logarithmic":
|
|
78
|
-
return logarithmicCurve(length, fadeIn);
|
|
79
|
-
default:
|
|
80
|
-
return linearCurve(length, fadeIn);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
function applyFadeIn(param, startTime, duration, type = "linear", startValue = 0, endValue = 1) {
|
|
84
|
-
if (duration <= 0) return;
|
|
85
|
-
if (type === "linear") {
|
|
86
|
-
param.setValueAtTime(startValue, startTime);
|
|
87
|
-
param.linearRampToValueAtTime(endValue, startTime + duration);
|
|
88
|
-
} else if (type === "exponential") {
|
|
89
|
-
param.setValueAtTime(Math.max(startValue, 1e-3), startTime);
|
|
90
|
-
param.exponentialRampToValueAtTime(Math.max(endValue, 1e-3), startTime + duration);
|
|
91
|
-
} else {
|
|
92
|
-
const curve = generateCurve(type, 1e4, true);
|
|
93
|
-
const scaledCurve = new Float32Array(curve.length);
|
|
94
|
-
const range = endValue - startValue;
|
|
95
|
-
for (let i = 0; i < curve.length; i++) {
|
|
96
|
-
scaledCurve[i] = startValue + curve[i] * range;
|
|
97
|
-
}
|
|
98
|
-
param.setValueCurveAtTime(scaledCurve, startTime, duration);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
function applyFadeOut(param, startTime, duration, type = "linear", startValue = 1, endValue = 0) {
|
|
102
|
-
if (duration <= 0) return;
|
|
103
|
-
if (type === "linear") {
|
|
104
|
-
param.setValueAtTime(startValue, startTime);
|
|
105
|
-
param.linearRampToValueAtTime(endValue, startTime + duration);
|
|
106
|
-
} else if (type === "exponential") {
|
|
107
|
-
param.setValueAtTime(Math.max(startValue, 1e-3), startTime);
|
|
108
|
-
param.exponentialRampToValueAtTime(Math.max(endValue, 1e-3), startTime + duration);
|
|
109
|
-
} else {
|
|
110
|
-
const curve = generateCurve(type, 1e4, false);
|
|
111
|
-
const scaledCurve = new Float32Array(curve.length);
|
|
112
|
-
const range = startValue - endValue;
|
|
113
|
-
for (let i = 0; i < curve.length; i++) {
|
|
114
|
-
scaledCurve[i] = endValue + curve[i] * range;
|
|
115
|
-
}
|
|
116
|
-
param.setValueCurveAtTime(scaledCurve, startTime, duration);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
42
|
|
|
120
43
|
// src/ToneTrack.ts
|
|
121
44
|
var ToneTrack = class {
|