audiora 1.0.1 → 1.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/CHANGELOG.md +14 -0
- package/README.md +7 -0
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +138 -0
- package/dist/index.d.ts +138 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/package.json +25 -6
- package/docs/API.md +0 -345
- package/src/Audiora.ts +0 -296
- package/src/core/AudioEngine.ts +0 -108
- package/src/core/ImageProcessor.ts +0 -180
- package/src/core/Scanner.ts +0 -183
- package/src/core/Scheduler.ts +0 -105
- package/src/core/State.ts +0 -86
- package/src/core/Synthesizer.ts +0 -196
- package/src/core/constants.ts +0 -70
- package/src/core/presets.ts +0 -166
- package/src/core/types.ts +0 -54
- package/src/core/utils.ts +0 -47
- package/src/core/wav.ts +0 -60
- package/src/index.ts +0 -9
- package/src/ui/Renderer.ts +0 -145
- package/src/ui/Tweener.ts +0 -71
package/src/ui/Renderer.ts
DELETED
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
import { AudioEngine } from "../core/AudioEngine";
|
|
2
|
-
import { ImageProcessor, BlockGrid } from "../core/ImageProcessor";
|
|
3
|
-
import { Sequencer } from "../core/Scanner";
|
|
4
|
-
|
|
5
|
-
export class Renderer {
|
|
6
|
-
private waveBuf: Uint8Array<ArrayBuffer> | null = null;
|
|
7
|
-
private drawT: number = 0;
|
|
8
|
-
private renderRaf: number | null = null;
|
|
9
|
-
|
|
10
|
-
private waveCanvas: HTMLCanvasElement;
|
|
11
|
-
private mapCanvas: HTMLCanvasElement;
|
|
12
|
-
|
|
13
|
-
constructor(
|
|
14
|
-
waveCanvas: HTMLCanvasElement,
|
|
15
|
-
mapCanvas: HTMLCanvasElement,
|
|
16
|
-
private readonly engine: AudioEngine,
|
|
17
|
-
private readonly imageProcessor: ImageProcessor,
|
|
18
|
-
private readonly grid: BlockGrid,
|
|
19
|
-
private readonly seq: Sequencer
|
|
20
|
-
) {
|
|
21
|
-
this.waveCanvas = waveCanvas;
|
|
22
|
-
this.mapCanvas = mapCanvas;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
public start(): void {
|
|
26
|
-
this.resizeCanvases();
|
|
27
|
-
this.renderFrame();
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
public stop(): void {
|
|
31
|
-
if (this.renderRaf) {
|
|
32
|
-
cancelAnimationFrame(this.renderRaf);
|
|
33
|
-
this.renderRaf = null;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
public resizeCanvases(): void {
|
|
38
|
-
const dpr = window.devicePixelRatio || 1;
|
|
39
|
-
[this.waveCanvas, this.mapCanvas].forEach((el) => {
|
|
40
|
-
if (!el) return;
|
|
41
|
-
const r = el.getBoundingClientRect();
|
|
42
|
-
el.width = Math.floor(r.width * dpr);
|
|
43
|
-
el.height = Math.floor(r.height * dpr);
|
|
44
|
-
el.getContext("2d")!.setTransform(dpr, 0, 0, dpr, 0, 0);
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
private renderFrame = (): void => {
|
|
49
|
-
this.renderRaf = requestAnimationFrame(this.renderFrame);
|
|
50
|
-
const now = performance.now();
|
|
51
|
-
if (now - this.drawT < 1000 / 60) return;
|
|
52
|
-
this.drawT = now;
|
|
53
|
-
|
|
54
|
-
const waveSize = this.canvasCssSize(this.waveCanvas);
|
|
55
|
-
const mapSize = this.canvasCssSize(this.mapCanvas);
|
|
56
|
-
this.drawWave(waveSize.w, waveSize.h);
|
|
57
|
-
this.drawMap(mapSize.w, mapSize.h);
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
private canvasCssSize(el: HTMLCanvasElement): { w: number; h: number } {
|
|
61
|
-
const r = el.getBoundingClientRect();
|
|
62
|
-
return { w: r.width, h: r.height };
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
private drawWave(W: number, H: number): void {
|
|
66
|
-
const ctx = this.waveCanvas.getContext("2d")!;
|
|
67
|
-
|
|
68
|
-
ctx.fillStyle = "#0d0d14";
|
|
69
|
-
ctx.fillRect(0, 0, W, H);
|
|
70
|
-
|
|
71
|
-
ctx.strokeStyle = "rgba(255,255,255,0.03)";
|
|
72
|
-
ctx.lineWidth = 1;
|
|
73
|
-
for (let x = 0; x < W; x += 40) {
|
|
74
|
-
ctx.beginPath();
|
|
75
|
-
ctx.moveTo(x + 0.5, 0);
|
|
76
|
-
ctx.lineTo(x + 0.5, H);
|
|
77
|
-
ctx.stroke();
|
|
78
|
-
}
|
|
79
|
-
for (let y = 0; y < H; y += 40) {
|
|
80
|
-
ctx.beginPath();
|
|
81
|
-
ctx.moveTo(0, y + 0.5);
|
|
82
|
-
ctx.lineTo(W, y + 0.5);
|
|
83
|
-
ctx.stroke();
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
if (this.engine.analyser) {
|
|
87
|
-
if (!this.waveBuf || this.waveBuf.length !== this.engine.analyser.fftSize) {
|
|
88
|
-
this.waveBuf = new Uint8Array(this.engine.analyser.fftSize);
|
|
89
|
-
}
|
|
90
|
-
this.engine.analyser.getByteTimeDomainData(this.waveBuf);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
const len = this.waveBuf?.length ?? 1024;
|
|
94
|
-
ctx.beginPath();
|
|
95
|
-
ctx.strokeStyle = "#ffffff";
|
|
96
|
-
ctx.lineWidth = 2;
|
|
97
|
-
for (let i = 0; i < len; i++) {
|
|
98
|
-
const v = this.waveBuf ? this.waveBuf[i] / 128.0 : 1.0;
|
|
99
|
-
const x = (i / (len - 1)) * W;
|
|
100
|
-
i === 0 ? ctx.moveTo(x, (v * H) / 2) : ctx.lineTo(x, (v * H) / 2);
|
|
101
|
-
}
|
|
102
|
-
ctx.stroke();
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
private drawMap(W: number, H: number): void {
|
|
106
|
-
const ctx = this.mapCanvas.getContext("2d")!;
|
|
107
|
-
ctx.clearRect(0, 0, W, H);
|
|
108
|
-
|
|
109
|
-
const src = this.imageProcessor.canvas;
|
|
110
|
-
if (!src) return;
|
|
111
|
-
|
|
112
|
-
const sc = Math.min(W / src.width, H / src.height);
|
|
113
|
-
const dw = src.width * sc;
|
|
114
|
-
const dh = src.height * sc;
|
|
115
|
-
const dx = (W - dw) / 2;
|
|
116
|
-
const dy = (H - dh) / 2;
|
|
117
|
-
|
|
118
|
-
ctx.save();
|
|
119
|
-
ctx.imageSmoothingEnabled = true;
|
|
120
|
-
ctx.drawImage(src, 0, 0, src.width, src.height, dx, dy, dw, dh);
|
|
121
|
-
|
|
122
|
-
if (!this.seq.active && this.seq.activateAt > 0 && this.engine.ctx &&
|
|
123
|
-
this.engine.ctx.currentTime >= this.seq.activateAt) {
|
|
124
|
-
this.seq.active = true;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
if (this.seq.active && this.grid.cols > 0 && this.grid.list.length > 0) {
|
|
128
|
-
const lt = 1;
|
|
129
|
-
this.seq.renderX = this.seq.renderX + (this.seq.visX - this.seq.renderX) * lt;
|
|
130
|
-
this.seq.renderY = this.seq.renderY + (this.seq.visY - this.seq.renderY) * lt;
|
|
131
|
-
const cw = dw / this.grid.cols;
|
|
132
|
-
const ch = dh / this.grid.rows;
|
|
133
|
-
const lw = Math.max(1.5, Math.min(cw, ch) * 0.06);
|
|
134
|
-
const cx_ = dx + this.seq.renderX * cw;
|
|
135
|
-
const cy_ = dy + this.seq.renderY * ch;
|
|
136
|
-
const rw = cw - 1;
|
|
137
|
-
const rh = ch - 1;
|
|
138
|
-
const light = this.seq.lastL > 50;
|
|
139
|
-
ctx.strokeStyle = light ? "rgba(30,30,30,0.85)" : "rgba(220,220,220,0.85)";
|
|
140
|
-
ctx.lineWidth = lw;
|
|
141
|
-
ctx.strokeRect(cx_ + 0.5, cy_ + 0.5, rw, rh);
|
|
142
|
-
}
|
|
143
|
-
ctx.restore();
|
|
144
|
-
}
|
|
145
|
-
}
|
package/src/ui/Tweener.ts
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import { PresetData } from "../core/types";
|
|
2
|
-
import { State } from "../core/State";
|
|
3
|
-
import { AudioEngine } from "../core/AudioEngine";
|
|
4
|
-
import { TWEEN_KEYS, TWEEN_MS } from "../core/constants";
|
|
5
|
-
import { easeInOut } from "../core/utils";
|
|
6
|
-
|
|
7
|
-
export type TweenTickHandler = (key: string, value: number) => void;
|
|
8
|
-
|
|
9
|
-
export class Tweener {
|
|
10
|
-
private raf: number | null = null;
|
|
11
|
-
|
|
12
|
-
constructor(
|
|
13
|
-
private readonly state: State,
|
|
14
|
-
private readonly engine: AudioEngine,
|
|
15
|
-
private readonly onTick?: TweenTickHandler
|
|
16
|
-
) {}
|
|
17
|
-
|
|
18
|
-
public tweenTo(target: Partial<PresetData>): void {
|
|
19
|
-
if (this.raf) {
|
|
20
|
-
cancelAnimationFrame(this.raf);
|
|
21
|
-
this.raf = null;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const from: Record<string, number> = {};
|
|
25
|
-
TWEEN_KEYS.forEach((k) => {
|
|
26
|
-
const tVal = (target as Record<string, unknown>)[k];
|
|
27
|
-
if (typeof tVal === "number" && isFinite(tVal)) {
|
|
28
|
-
const current = this.state.getNumeric(k);
|
|
29
|
-
from[k] = isFinite(current) ? current : tVal;
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
const t0 = performance.now();
|
|
34
|
-
|
|
35
|
-
const tick = (): void => {
|
|
36
|
-
const t = Math.min((performance.now() - t0) / TWEEN_MS, 1);
|
|
37
|
-
const e = easeInOut(t);
|
|
38
|
-
|
|
39
|
-
TWEEN_KEYS.forEach((k) => {
|
|
40
|
-
if (from[k] === undefined) return;
|
|
41
|
-
const targetVal = (target as Record<string, unknown>)[k] as number;
|
|
42
|
-
const newVal = from[k] + (targetVal - from[k]) * e;
|
|
43
|
-
this.state.setNumeric(k, newVal);
|
|
44
|
-
this.onTick?.(k, newVal);
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
if (isFinite(this.state.volume) && this.engine.master) {
|
|
48
|
-
this.engine.master.gain.value = Math.pow(this.state.volume, 2);
|
|
49
|
-
}
|
|
50
|
-
if (isFinite(this.state.reverb_mix) && this.engine.wet) {
|
|
51
|
-
this.engine.wet.gain.value = this.state.reverb_mix;
|
|
52
|
-
this.engine.dry!.gain.value = this.engine.dryVal(this.state.reverb_mix);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
if (t < 1) {
|
|
56
|
-
this.raf = requestAnimationFrame(tick);
|
|
57
|
-
} else if (from.reverb_time !== undefined) {
|
|
58
|
-
this.engine.updateReverbBuffer(this.state);
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
this.raf = requestAnimationFrame(tick);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
public cancel(): void {
|
|
66
|
-
if (this.raf) {
|
|
67
|
-
cancelAnimationFrame(this.raf);
|
|
68
|
-
this.raf = null;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|