@guinetik/gcanvas 1.0.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/.github/workflows/release.yaml +70 -0
- package/.jshintrc +4 -0
- package/.vscode/settings.json +22 -0
- package/CLAUDE.md +310 -0
- package/blackhole.jpg +0 -0
- package/demo.png +0 -0
- package/demos/CNAME +1 -0
- package/demos/animations.html +31 -0
- package/demos/basic.html +38 -0
- package/demos/baskara.html +31 -0
- package/demos/bezier.html +35 -0
- package/demos/beziersignature.html +29 -0
- package/demos/blackhole.html +28 -0
- package/demos/blob.html +35 -0
- package/demos/demos.css +289 -0
- package/demos/easing.html +28 -0
- package/demos/events.html +195 -0
- package/demos/fluent.html +647 -0
- package/demos/fractals.html +36 -0
- package/demos/genart.html +26 -0
- package/demos/gendream.html +26 -0
- package/demos/group.html +36 -0
- package/demos/home.html +587 -0
- package/demos/index.html +364 -0
- package/demos/isometric.html +34 -0
- package/demos/js/animations.js +452 -0
- package/demos/js/basic.js +204 -0
- package/demos/js/baskara.js +751 -0
- package/demos/js/bezier.js +692 -0
- package/demos/js/beziersignature.js +241 -0
- package/demos/js/blackhole/accretiondisk.obj.js +379 -0
- package/demos/js/blackhole/blackhole.obj.js +318 -0
- package/demos/js/blackhole/index.js +409 -0
- package/demos/js/blackhole/particle.js +56 -0
- package/demos/js/blackhole/starfield.obj.js +218 -0
- package/demos/js/blob.js +2263 -0
- package/demos/js/easing.js +477 -0
- package/demos/js/fluent.js +183 -0
- package/demos/js/fractals.js +931 -0
- package/demos/js/fractalworker.js +93 -0
- package/demos/js/genart.js +268 -0
- package/demos/js/gendream.js +209 -0
- package/demos/js/group.js +140 -0
- package/demos/js/info-toggle.js +25 -0
- package/demos/js/isometric.js +863 -0
- package/demos/js/kerr.js +1556 -0
- package/demos/js/lavalamp.js +590 -0
- package/demos/js/layout.js +354 -0
- package/demos/js/mondrian.js +285 -0
- package/demos/js/opacity.js +275 -0
- package/demos/js/painter.js +484 -0
- package/demos/js/particles-showcase.js +514 -0
- package/demos/js/particles.js +299 -0
- package/demos/js/patterns.js +397 -0
- package/demos/js/penrose/artifact.js +69 -0
- package/demos/js/penrose/blackhole.js +121 -0
- package/demos/js/penrose/constants.js +73 -0
- package/demos/js/penrose/game.js +943 -0
- package/demos/js/penrose/lore.js +278 -0
- package/demos/js/penrose/penrosescene.js +892 -0
- package/demos/js/penrose/ship.js +216 -0
- package/demos/js/penrose/sounds.js +211 -0
- package/demos/js/penrose/voidparticle.js +55 -0
- package/demos/js/penrose/voidscene.js +258 -0
- package/demos/js/penrose/voidship.js +144 -0
- package/demos/js/penrose/wormhole.js +46 -0
- package/demos/js/pipeline.js +555 -0
- package/demos/js/scene.js +304 -0
- package/demos/js/scenes.js +320 -0
- package/demos/js/schrodinger.js +410 -0
- package/demos/js/schwarzschild.js +1023 -0
- package/demos/js/shapes.js +628 -0
- package/demos/js/space/alien.js +171 -0
- package/demos/js/space/boom.js +98 -0
- package/demos/js/space/boss.js +353 -0
- package/demos/js/space/buff.js +73 -0
- package/demos/js/space/bullet.js +102 -0
- package/demos/js/space/constants.js +85 -0
- package/demos/js/space/game.js +1884 -0
- package/demos/js/space/hud.js +112 -0
- package/demos/js/space/laserbeam.js +179 -0
- package/demos/js/space/lightning.js +277 -0
- package/demos/js/space/minion.js +192 -0
- package/demos/js/space/missile.js +212 -0
- package/demos/js/space/player.js +430 -0
- package/demos/js/space/powerup.js +90 -0
- package/demos/js/space/starfield.js +58 -0
- package/demos/js/space/starpower.js +90 -0
- package/demos/js/spacetime.js +559 -0
- package/demos/js/svgtween.js +204 -0
- package/demos/js/tde/accretiondisk.js +418 -0
- package/demos/js/tde/blackhole.js +219 -0
- package/demos/js/tde/blackholescene.js +209 -0
- package/demos/js/tde/config.js +59 -0
- package/demos/js/tde/index.js +695 -0
- package/demos/js/tde/jets.js +290 -0
- package/demos/js/tde/lensedstarfield.js +147 -0
- package/demos/js/tde/tdestar.js +317 -0
- package/demos/js/tde/tidalstream.js +356 -0
- package/demos/js/tde_old/blackhole.obj.js +354 -0
- package/demos/js/tde_old/debris.obj.js +791 -0
- package/demos/js/tde_old/flare.obj.js +239 -0
- package/demos/js/tde_old/index.js +448 -0
- package/demos/js/tde_old/star.obj.js +812 -0
- package/demos/js/tiles.js +312 -0
- package/demos/js/tweendemo.js +79 -0
- package/demos/js/visibility.js +102 -0
- package/demos/kerr.html +28 -0
- package/demos/lavalamp.html +27 -0
- package/demos/layouts.html +37 -0
- package/demos/logo.svg +4 -0
- package/demos/loop.html +84 -0
- package/demos/mondrian.html +32 -0
- package/demos/og_image.png +0 -0
- package/demos/opacity.html +36 -0
- package/demos/painter.html +39 -0
- package/demos/particles-showcase.html +28 -0
- package/demos/particles.html +24 -0
- package/demos/patterns.html +33 -0
- package/demos/penrose-game.html +31 -0
- package/demos/pipeline.html +737 -0
- package/demos/scene.html +33 -0
- package/demos/scenes.html +96 -0
- package/demos/schrodinger.html +27 -0
- package/demos/schwarzschild.html +27 -0
- package/demos/shapes.html +16 -0
- package/demos/space.html +85 -0
- package/demos/spacetime.html +27 -0
- package/demos/svgtween.html +29 -0
- package/demos/tde.html +28 -0
- package/demos/tiles.html +28 -0
- package/demos/transforms.html +400 -0
- package/demos/tween.html +45 -0
- package/demos/visibility.html +33 -0
- package/disk_example.png +0 -0
- package/docs/README.md +222 -0
- package/docs/concepts/architecture-overview.md +204 -0
- package/docs/concepts/lifecycle.md +255 -0
- package/docs/concepts/rendering-pipeline.md +279 -0
- package/docs/concepts/tde-zorder.md +106 -0
- package/docs/concepts/two-layer-architecture.md +229 -0
- package/docs/getting-started/first-game.md +354 -0
- package/docs/getting-started/hello-world.md +269 -0
- package/docs/getting-started/installation.md +157 -0
- package/docs/modules/collision/README.md +453 -0
- package/docs/modules/fluent/README.md +1075 -0
- package/docs/modules/game/README.md +303 -0
- package/docs/modules/isometric-camera.md +210 -0
- package/docs/modules/isometric.md +275 -0
- package/docs/modules/painter/README.md +328 -0
- package/docs/modules/particle/README.md +559 -0
- package/docs/modules/shapes/README.md +221 -0
- package/docs/modules/shapes/base/euclidian.md +123 -0
- package/docs/modules/shapes/base/geometry2d.md +204 -0
- package/docs/modules/shapes/base/renderable.md +215 -0
- package/docs/modules/shapes/base/shape.md +262 -0
- package/docs/modules/shapes/base/transformable.md +243 -0
- package/docs/modules/shapes/hierarchy.md +218 -0
- package/docs/modules/state/README.md +577 -0
- package/docs/modules/util/README.md +99 -0
- package/docs/modules/util/camera3d.md +412 -0
- package/docs/modules/util/scene3d.md +395 -0
- package/index.html +17 -0
- package/jsdoc.json +50 -0
- package/package.json +55 -0
- package/readme.md +599 -0
- package/scripts/build-demo.js +69 -0
- package/scripts/bundle4llm.js +276 -0
- package/scripts/clearconsole.js +48 -0
- package/src/collision/collision-system.js +332 -0
- package/src/collision/collision.js +303 -0
- package/src/collision/index.js +10 -0
- package/src/fluent/fluent-game.js +430 -0
- package/src/fluent/fluent-go.js +1060 -0
- package/src/fluent/fluent-layer.js +152 -0
- package/src/fluent/fluent-scene.js +291 -0
- package/src/fluent/index.js +98 -0
- package/src/fluent/sketch.js +380 -0
- package/src/game/game.js +467 -0
- package/src/game/index.js +49 -0
- package/src/game/objects/go.js +220 -0
- package/src/game/objects/imagego.js +30 -0
- package/src/game/objects/index.js +54 -0
- package/src/game/objects/isometric-scene.js +260 -0
- package/src/game/objects/layoutscene.js +549 -0
- package/src/game/objects/scene.js +175 -0
- package/src/game/objects/scene3d.js +118 -0
- package/src/game/objects/text.js +221 -0
- package/src/game/objects/wrapper.js +232 -0
- package/src/game/pipeline.js +243 -0
- package/src/game/ui/button.js +396 -0
- package/src/game/ui/cursor.js +93 -0
- package/src/game/ui/fps.js +91 -0
- package/src/game/ui/index.js +5 -0
- package/src/game/ui/togglebutton.js +93 -0
- package/src/game/ui/tooltip.js +249 -0
- package/src/index.js +25 -0
- package/src/io/events.js +20 -0
- package/src/io/index.js +86 -0
- package/src/io/input.js +70 -0
- package/src/io/keys.js +152 -0
- package/src/io/mouse.js +61 -0
- package/src/io/touch.js +39 -0
- package/src/logger/debugtab.js +138 -0
- package/src/logger/index.js +3 -0
- package/src/logger/loggable.js +47 -0
- package/src/logger/logger.js +113 -0
- package/src/math/complex.js +37 -0
- package/src/math/constants.js +1 -0
- package/src/math/fractal.js +1271 -0
- package/src/math/gr.js +201 -0
- package/src/math/heat.js +202 -0
- package/src/math/index.js +12 -0
- package/src/math/noise.js +433 -0
- package/src/math/orbital.js +191 -0
- package/src/math/patterns.js +1339 -0
- package/src/math/penrose.js +259 -0
- package/src/math/quantum.js +115 -0
- package/src/math/random.js +195 -0
- package/src/math/tensor.js +1009 -0
- package/src/mixins/anchor.js +131 -0
- package/src/mixins/draggable.js +72 -0
- package/src/mixins/index.js +2 -0
- package/src/motion/bezier.js +132 -0
- package/src/motion/bounce.js +58 -0
- package/src/motion/easing.js +349 -0
- package/src/motion/float.js +130 -0
- package/src/motion/follow.js +125 -0
- package/src/motion/hop.js +52 -0
- package/src/motion/index.js +82 -0
- package/src/motion/motion.js +1124 -0
- package/src/motion/orbit.js +49 -0
- package/src/motion/oscillate.js +39 -0
- package/src/motion/parabolic.js +141 -0
- package/src/motion/patrol.js +147 -0
- package/src/motion/pendulum.js +48 -0
- package/src/motion/pulse.js +88 -0
- package/src/motion/shake.js +83 -0
- package/src/motion/spiral.js +144 -0
- package/src/motion/spring.js +150 -0
- package/src/motion/swing.js +47 -0
- package/src/motion/tween.js +92 -0
- package/src/motion/tweenetik.js +139 -0
- package/src/motion/waypoint.js +210 -0
- package/src/painter/index.js +8 -0
- package/src/painter/painter.colors.js +331 -0
- package/src/painter/painter.effects.js +230 -0
- package/src/painter/painter.img.js +229 -0
- package/src/painter/painter.js +295 -0
- package/src/painter/painter.lines.js +189 -0
- package/src/painter/painter.opacity.js +41 -0
- package/src/painter/painter.shapes.js +277 -0
- package/src/painter/painter.text.js +273 -0
- package/src/particle/emitter.js +124 -0
- package/src/particle/index.js +11 -0
- package/src/particle/particle-system.js +322 -0
- package/src/particle/particle.js +71 -0
- package/src/particle/updaters.js +170 -0
- package/src/shapes/arc.js +43 -0
- package/src/shapes/arrow.js +33 -0
- package/src/shapes/bezier.js +42 -0
- package/src/shapes/circle.js +62 -0
- package/src/shapes/clouds.js +56 -0
- package/src/shapes/cone.js +219 -0
- package/src/shapes/cross.js +70 -0
- package/src/shapes/cube.js +244 -0
- package/src/shapes/cylinder.js +254 -0
- package/src/shapes/diamond.js +48 -0
- package/src/shapes/euclidian.js +111 -0
- package/src/shapes/figure.js +115 -0
- package/src/shapes/geometry.js +220 -0
- package/src/shapes/group.js +375 -0
- package/src/shapes/heart.js +42 -0
- package/src/shapes/hexagon.js +26 -0
- package/src/shapes/image.js +192 -0
- package/src/shapes/index.js +111 -0
- package/src/shapes/line.js +29 -0
- package/src/shapes/pattern.js +90 -0
- package/src/shapes/pin.js +44 -0
- package/src/shapes/poly.js +31 -0
- package/src/shapes/prism.js +226 -0
- package/src/shapes/rect.js +35 -0
- package/src/shapes/renderable.js +333 -0
- package/src/shapes/ring.js +26 -0
- package/src/shapes/roundrect.js +95 -0
- package/src/shapes/shape.js +117 -0
- package/src/shapes/slice.js +26 -0
- package/src/shapes/sphere.js +314 -0
- package/src/shapes/sphere3d.js +537 -0
- package/src/shapes/square.js +15 -0
- package/src/shapes/star.js +99 -0
- package/src/shapes/svg.js +408 -0
- package/src/shapes/text.js +553 -0
- package/src/shapes/traceable.js +83 -0
- package/src/shapes/transform.js +357 -0
- package/src/shapes/transformable.js +172 -0
- package/src/shapes/triangle.js +26 -0
- package/src/sound/index.js +17 -0
- package/src/sound/sound.js +473 -0
- package/src/sound/synth.analyzer.js +149 -0
- package/src/sound/synth.effects.js +207 -0
- package/src/sound/synth.envelope.js +59 -0
- package/src/sound/synth.js +229 -0
- package/src/sound/synth.musical.js +160 -0
- package/src/sound/synth.noise.js +85 -0
- package/src/sound/synth.oscillators.js +293 -0
- package/src/state/index.js +10 -0
- package/src/state/state-machine.js +371 -0
- package/src/util/camera3d.js +438 -0
- package/src/util/index.js +6 -0
- package/src/util/isometric-camera.js +235 -0
- package/src/util/layout.js +317 -0
- package/src/util/position.js +147 -0
- package/src/util/tasks.js +47 -0
- package/src/util/zindex.js +287 -0
- package/src/webgl/index.js +9 -0
- package/src/webgl/shaders/sphere-shaders.js +994 -0
- package/src/webgl/webgl-renderer.js +388 -0
- package/tde.png +0 -0
- package/test/math/orbital.test.js +61 -0
- package/test/math/tensor.test.js +114 -0
- package/test/particle/emitter.test.js +204 -0
- package/test/particle/particle-system.test.js +310 -0
- package/test/particle/particle.test.js +116 -0
- package/test/particle/updaters.test.js +386 -0
- package/test/setup.js +120 -0
- package/test/shapes/euclidian.test.js +44 -0
- package/test/shapes/geometry.test.js +86 -0
- package/test/shapes/group.test.js +86 -0
- package/test/shapes/rectangle.test.js +64 -0
- package/test/shapes/transform.test.js +379 -0
- package/test/util/camera3d.test.js +428 -0
- package/test/util/scene3d.test.js +352 -0
- package/types/collision.d.ts +249 -0
- package/types/common.d.ts +155 -0
- package/types/game.d.ts +497 -0
- package/types/index.d.ts +309 -0
- package/types/io.d.ts +188 -0
- package/types/logger.d.ts +127 -0
- package/types/math.d.ts +268 -0
- package/types/mixins.d.ts +92 -0
- package/types/motion.d.ts +678 -0
- package/types/painter.d.ts +378 -0
- package/types/shapes.d.ts +864 -0
- package/types/sound.d.ts +672 -0
- package/types/state.d.ts +251 -0
- package/types/util.d.ts +253 -0
- package/vite.config.js +50 -0
- package/vitest.config.js +13 -0
package/types/sound.d.ts
ADDED
|
@@ -0,0 +1,672 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sound Module - TypeScript Definitions
|
|
3
|
+
* Procedural audio generation for games and creative coding
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
// ==========================================================================
|
|
7
|
+
// Types
|
|
8
|
+
// ==========================================================================
|
|
9
|
+
|
|
10
|
+
export interface SynthOptions {
|
|
11
|
+
/** Master volume (0-1) */
|
|
12
|
+
masterVolume?: number;
|
|
13
|
+
/** Sample rate (default: 44100) */
|
|
14
|
+
sampleRate?: number;
|
|
15
|
+
/** Enable audio analyzer for visualization */
|
|
16
|
+
enableAnalyzer?: boolean;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface ToneOptions {
|
|
20
|
+
/** Oscillator type */
|
|
21
|
+
type?: OscillatorType;
|
|
22
|
+
/** Volume (0-1) */
|
|
23
|
+
volume?: number;
|
|
24
|
+
/** Attack time in seconds */
|
|
25
|
+
attack?: number;
|
|
26
|
+
/** Decay time in seconds */
|
|
27
|
+
decay?: number;
|
|
28
|
+
/** Sustain level (0-1) */
|
|
29
|
+
sustain?: number;
|
|
30
|
+
/** Release time in seconds */
|
|
31
|
+
release?: number;
|
|
32
|
+
/** Detune in cents */
|
|
33
|
+
detune?: number;
|
|
34
|
+
/** Start time (defaults to now) */
|
|
35
|
+
startTime?: number;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface ContinuousOscillatorController {
|
|
39
|
+
osc: OscillatorNode;
|
|
40
|
+
gain: GainNode;
|
|
41
|
+
setFrequency: (freq: number, ramp?: number) => void;
|
|
42
|
+
setVolume: (vol: number, ramp?: number) => void;
|
|
43
|
+
stop: (fadeTime?: number) => void;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface DelayEffect {
|
|
47
|
+
input: GainNode;
|
|
48
|
+
output: GainNode;
|
|
49
|
+
setTime: (time: number) => void;
|
|
50
|
+
setFeedback: (feedback: number) => void;
|
|
51
|
+
setMix: (mix: number) => void;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export interface TremoloEffect {
|
|
55
|
+
input: GainNode;
|
|
56
|
+
output: GainNode;
|
|
57
|
+
lfo: OscillatorNode;
|
|
58
|
+
setRate: (rate: number) => void;
|
|
59
|
+
setDepth: (depth: number) => void;
|
|
60
|
+
stop: () => void;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export interface DroneController {
|
|
64
|
+
stop: (fadeTime?: number) => void;
|
|
65
|
+
setVolume: (volume: number) => void;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export interface EnvelopeOptions {
|
|
69
|
+
attack?: number;
|
|
70
|
+
decay?: number;
|
|
71
|
+
sustain?: number;
|
|
72
|
+
release?: number;
|
|
73
|
+
startTime?: number;
|
|
74
|
+
duration?: number;
|
|
75
|
+
peakVolume?: number;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export interface EnvelopePresets {
|
|
79
|
+
pluck: EnvelopeOptions;
|
|
80
|
+
pad: EnvelopeOptions;
|
|
81
|
+
organ: EnvelopeOptions;
|
|
82
|
+
perc: EnvelopeOptions;
|
|
83
|
+
string: EnvelopeOptions;
|
|
84
|
+
brass: EnvelopeOptions;
|
|
85
|
+
blip: EnvelopeOptions;
|
|
86
|
+
laser: EnvelopeOptions;
|
|
87
|
+
explosion: EnvelopeOptions;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export type ScaleName =
|
|
91
|
+
| "major"
|
|
92
|
+
| "minor"
|
|
93
|
+
| "pentatonic"
|
|
94
|
+
| "pentatonicMinor"
|
|
95
|
+
| "blues"
|
|
96
|
+
| "dorian"
|
|
97
|
+
| "mixolydian"
|
|
98
|
+
| "chromatic"
|
|
99
|
+
| "wholeTone"
|
|
100
|
+
| "diminished";
|
|
101
|
+
|
|
102
|
+
export type ChordType =
|
|
103
|
+
| "major"
|
|
104
|
+
| "minor"
|
|
105
|
+
| "diminished"
|
|
106
|
+
| "augmented"
|
|
107
|
+
| "sus2"
|
|
108
|
+
| "sus4"
|
|
109
|
+
| "major7"
|
|
110
|
+
| "minor7"
|
|
111
|
+
| "dom7"
|
|
112
|
+
| "dim7"
|
|
113
|
+
| "add9"
|
|
114
|
+
| "power";
|
|
115
|
+
|
|
116
|
+
// ==========================================================================
|
|
117
|
+
// SynthEnvelope
|
|
118
|
+
// ==========================================================================
|
|
119
|
+
|
|
120
|
+
export class SynthEnvelope {
|
|
121
|
+
/**
|
|
122
|
+
* Apply ADSR envelope to an AudioParam
|
|
123
|
+
*/
|
|
124
|
+
static applyADSR(param: AudioParam, options?: EnvelopeOptions): void;
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Get envelope presets for common sounds
|
|
128
|
+
*/
|
|
129
|
+
static readonly presets: EnvelopePresets;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// ==========================================================================
|
|
133
|
+
// SynthNoise
|
|
134
|
+
// ==========================================================================
|
|
135
|
+
|
|
136
|
+
export class SynthNoise {
|
|
137
|
+
/**
|
|
138
|
+
* Create white noise buffer source
|
|
139
|
+
*/
|
|
140
|
+
static white(ctx: AudioContext, duration: number): AudioBufferSourceNode;
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Create pink noise buffer source (1/f noise)
|
|
144
|
+
*/
|
|
145
|
+
static pink(ctx: AudioContext, duration: number): AudioBufferSourceNode;
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Create brown noise buffer source (Brownian/random walk)
|
|
149
|
+
*/
|
|
150
|
+
static brown(ctx: AudioContext, duration: number): AudioBufferSourceNode;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// ==========================================================================
|
|
154
|
+
// SynthMusical
|
|
155
|
+
// ==========================================================================
|
|
156
|
+
|
|
157
|
+
export class SynthMusical {
|
|
158
|
+
static readonly NOTE_FREQUENCIES: Record<string, number>;
|
|
159
|
+
static readonly SCALES: Record<ScaleName, number[]>;
|
|
160
|
+
static readonly CHORDS: Record<ChordType, number[]>;
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Convert note name to frequency
|
|
164
|
+
*/
|
|
165
|
+
static noteToFreq(note: string): number;
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Get frequencies for a scale
|
|
169
|
+
*/
|
|
170
|
+
static scale(root: string, scaleName?: ScaleName, octaves?: number): number[];
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Get frequencies for a chord
|
|
174
|
+
*/
|
|
175
|
+
static chord(root: string, chordType?: ChordType): number[];
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Map a value (0-1) to a frequency in a scale
|
|
179
|
+
*/
|
|
180
|
+
static mapToScale(
|
|
181
|
+
value: number,
|
|
182
|
+
root?: string,
|
|
183
|
+
scaleName?: ScaleName,
|
|
184
|
+
octaves?: number
|
|
185
|
+
): number;
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Convert MIDI note number to frequency
|
|
189
|
+
*/
|
|
190
|
+
static midiToFreq(midi: number): number;
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Convert frequency to MIDI note number
|
|
194
|
+
*/
|
|
195
|
+
static freqToMidi(freq: number): number;
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Get a random note from a scale
|
|
199
|
+
*/
|
|
200
|
+
static randomNote(
|
|
201
|
+
root?: string,
|
|
202
|
+
scaleName?: ScaleName,
|
|
203
|
+
octaves?: number
|
|
204
|
+
): number;
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Get frequency with cents offset
|
|
208
|
+
*/
|
|
209
|
+
static detune(freq: number, cents: number): number;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// ==========================================================================
|
|
213
|
+
// SynthAnalyzer
|
|
214
|
+
// ==========================================================================
|
|
215
|
+
|
|
216
|
+
export class SynthAnalyzer {
|
|
217
|
+
/**
|
|
218
|
+
* Initialize the analyzer
|
|
219
|
+
*/
|
|
220
|
+
static init(ctx: AudioContext, source: AudioNode): void;
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Check if analyzer is initialized
|
|
224
|
+
*/
|
|
225
|
+
static readonly isInitialized: boolean;
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Get the analyzer node
|
|
229
|
+
*/
|
|
230
|
+
static readonly node: AnalyserNode | null;
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* Set FFT size (must be power of 2)
|
|
234
|
+
*/
|
|
235
|
+
static setFFTSize(size: number): void;
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Get waveform data (time domain)
|
|
239
|
+
*/
|
|
240
|
+
static getWaveform(): Uint8Array;
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Get frequency data (spectrum)
|
|
244
|
+
*/
|
|
245
|
+
static getFrequency(): Uint8Array;
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Get normalized frequency bands
|
|
249
|
+
*/
|
|
250
|
+
static getBands(bands?: number): number[];
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Get current amplitude (volume level)
|
|
254
|
+
*/
|
|
255
|
+
static getAmplitude(): number;
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* Get peak frequency
|
|
259
|
+
*/
|
|
260
|
+
static getPeakFrequency(): number;
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* Disconnect and cleanup
|
|
264
|
+
*/
|
|
265
|
+
static dispose(): void;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
// ==========================================================================
|
|
269
|
+
// SynthEffects
|
|
270
|
+
// ==========================================================================
|
|
271
|
+
|
|
272
|
+
export class SynthEffects {
|
|
273
|
+
/**
|
|
274
|
+
* Initialize the effects module
|
|
275
|
+
*/
|
|
276
|
+
static init(ctx: AudioContext, output: AudioNode): void;
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* Get the audio context
|
|
280
|
+
*/
|
|
281
|
+
static readonly ctx: AudioContext;
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* Create a filter node
|
|
285
|
+
*/
|
|
286
|
+
static filter(
|
|
287
|
+
type?: BiquadFilterType,
|
|
288
|
+
frequency?: number,
|
|
289
|
+
q?: number
|
|
290
|
+
): BiquadFilterNode;
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* Create a delay effect
|
|
294
|
+
*/
|
|
295
|
+
static delay(time?: number, feedback?: number, mix?: number): DelayEffect;
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* Create a simple reverb using convolution
|
|
299
|
+
*/
|
|
300
|
+
static reverb(duration?: number, decay?: number): ConvolverNode;
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* Create a distortion effect
|
|
304
|
+
*/
|
|
305
|
+
static distortion(amount?: number): WaveShaperNode;
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* Create a tremolo effect
|
|
309
|
+
*/
|
|
310
|
+
static tremolo(rate?: number, depth?: number): TremoloEffect;
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* Create a compressor
|
|
314
|
+
*/
|
|
315
|
+
static compressor(options?: {
|
|
316
|
+
threshold?: number;
|
|
317
|
+
knee?: number;
|
|
318
|
+
ratio?: number;
|
|
319
|
+
attack?: number;
|
|
320
|
+
release?: number;
|
|
321
|
+
}): DynamicsCompressorNode;
|
|
322
|
+
|
|
323
|
+
/**
|
|
324
|
+
* Create a stereo panner
|
|
325
|
+
*/
|
|
326
|
+
static panner(pan?: number): StereoPannerNode;
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* Create a gain node
|
|
330
|
+
*/
|
|
331
|
+
static gain(volume?: number): GainNode;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
// ==========================================================================
|
|
335
|
+
// SynthOscillators
|
|
336
|
+
// ==========================================================================
|
|
337
|
+
|
|
338
|
+
export class SynthOscillators {
|
|
339
|
+
/**
|
|
340
|
+
* Initialize the oscillators module
|
|
341
|
+
*/
|
|
342
|
+
static init(ctx: AudioContext, output: AudioNode): void;
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* Get the audio context
|
|
346
|
+
*/
|
|
347
|
+
static readonly ctx: AudioContext;
|
|
348
|
+
|
|
349
|
+
/**
|
|
350
|
+
* Get current audio time
|
|
351
|
+
*/
|
|
352
|
+
static readonly now: number;
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* Play a simple tone
|
|
356
|
+
*/
|
|
357
|
+
static tone(
|
|
358
|
+
frequency: number,
|
|
359
|
+
duration: number,
|
|
360
|
+
options?: ToneOptions
|
|
361
|
+
): OscillatorNode;
|
|
362
|
+
|
|
363
|
+
/**
|
|
364
|
+
* Create a continuous oscillator (for real-time control)
|
|
365
|
+
*/
|
|
366
|
+
static continuous(options?: {
|
|
367
|
+
type?: OscillatorType;
|
|
368
|
+
frequency?: number;
|
|
369
|
+
volume?: number;
|
|
370
|
+
}): ContinuousOscillatorController;
|
|
371
|
+
|
|
372
|
+
/**
|
|
373
|
+
* FM Synthesis - Frequency modulation for rich timbres
|
|
374
|
+
*/
|
|
375
|
+
static fm(
|
|
376
|
+
carrierFreq: number,
|
|
377
|
+
modFreq: number,
|
|
378
|
+
modDepth: number,
|
|
379
|
+
duration: number,
|
|
380
|
+
options?: { volume?: number; startTime?: number }
|
|
381
|
+
): { carrier: OscillatorNode; modulator: OscillatorNode; outputGain: GainNode };
|
|
382
|
+
|
|
383
|
+
/**
|
|
384
|
+
* Additive synthesis - Combine harmonics
|
|
385
|
+
*/
|
|
386
|
+
static additive(
|
|
387
|
+
fundamental: number,
|
|
388
|
+
harmonics: number[],
|
|
389
|
+
duration: number,
|
|
390
|
+
options?: { volume?: number; startTime?: number }
|
|
391
|
+
): OscillatorNode[];
|
|
392
|
+
|
|
393
|
+
/**
|
|
394
|
+
* Play a frequency sweep
|
|
395
|
+
*/
|
|
396
|
+
static sweep(
|
|
397
|
+
startFreq: number,
|
|
398
|
+
endFreq: number,
|
|
399
|
+
duration: number,
|
|
400
|
+
options?: {
|
|
401
|
+
type?: OscillatorType;
|
|
402
|
+
volume?: number;
|
|
403
|
+
exponential?: boolean;
|
|
404
|
+
startTime?: number;
|
|
405
|
+
}
|
|
406
|
+
): OscillatorNode;
|
|
407
|
+
|
|
408
|
+
/**
|
|
409
|
+
* Create pulse wave with variable duty cycle
|
|
410
|
+
*/
|
|
411
|
+
static pulse(
|
|
412
|
+
frequency: number,
|
|
413
|
+
duration: number,
|
|
414
|
+
dutyCycle?: number,
|
|
415
|
+
options?: { volume?: number; startTime?: number }
|
|
416
|
+
): { osc1: OscillatorNode; osc2: OscillatorNode; output: GainNode };
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
// ==========================================================================
|
|
420
|
+
// Synth (Main Class)
|
|
421
|
+
// ==========================================================================
|
|
422
|
+
|
|
423
|
+
export class Synth {
|
|
424
|
+
/**
|
|
425
|
+
* Initialize the audio system
|
|
426
|
+
*/
|
|
427
|
+
static init(options?: SynthOptions): void;
|
|
428
|
+
|
|
429
|
+
/**
|
|
430
|
+
* Check if audio is initialized
|
|
431
|
+
*/
|
|
432
|
+
static readonly isInitialized: boolean;
|
|
433
|
+
|
|
434
|
+
/**
|
|
435
|
+
* Get the AudioContext
|
|
436
|
+
*/
|
|
437
|
+
static readonly ctx: AudioContext | null;
|
|
438
|
+
|
|
439
|
+
/**
|
|
440
|
+
* Get the master gain node
|
|
441
|
+
*/
|
|
442
|
+
static readonly master: GainNode | null;
|
|
443
|
+
|
|
444
|
+
/**
|
|
445
|
+
* Get oscillator utilities
|
|
446
|
+
*/
|
|
447
|
+
static readonly osc: typeof SynthOscillators;
|
|
448
|
+
|
|
449
|
+
/**
|
|
450
|
+
* Get effects utilities
|
|
451
|
+
*/
|
|
452
|
+
static readonly fx: typeof SynthEffects;
|
|
453
|
+
|
|
454
|
+
/**
|
|
455
|
+
* Get envelope utilities
|
|
456
|
+
*/
|
|
457
|
+
static readonly env: typeof SynthEnvelope;
|
|
458
|
+
|
|
459
|
+
/**
|
|
460
|
+
* Get noise utilities
|
|
461
|
+
*/
|
|
462
|
+
static readonly noise: typeof SynthNoise;
|
|
463
|
+
|
|
464
|
+
/**
|
|
465
|
+
* Get musical utilities
|
|
466
|
+
*/
|
|
467
|
+
static readonly music: typeof SynthMusical;
|
|
468
|
+
|
|
469
|
+
/**
|
|
470
|
+
* Get analyzer utilities
|
|
471
|
+
*/
|
|
472
|
+
static readonly analyzer: typeof SynthAnalyzer;
|
|
473
|
+
|
|
474
|
+
/**
|
|
475
|
+
* Resume audio context (required after user interaction)
|
|
476
|
+
*/
|
|
477
|
+
static resume(): Promise<void>;
|
|
478
|
+
|
|
479
|
+
/**
|
|
480
|
+
* Suspend audio context
|
|
481
|
+
*/
|
|
482
|
+
static suspend(): Promise<void>;
|
|
483
|
+
|
|
484
|
+
/**
|
|
485
|
+
* Get current audio time (for scheduling)
|
|
486
|
+
*/
|
|
487
|
+
static readonly now: number;
|
|
488
|
+
|
|
489
|
+
/**
|
|
490
|
+
* Get audio context state
|
|
491
|
+
*/
|
|
492
|
+
static readonly state: AudioContextState;
|
|
493
|
+
|
|
494
|
+
/**
|
|
495
|
+
* Set master volume
|
|
496
|
+
*/
|
|
497
|
+
static volume: number;
|
|
498
|
+
|
|
499
|
+
/**
|
|
500
|
+
* Create a custom audio node chain
|
|
501
|
+
*/
|
|
502
|
+
static chain(
|
|
503
|
+
...nodes: AudioNode[]
|
|
504
|
+
): { first: AudioNode; last: AudioNode; connectTo: (target: AudioNode) => void };
|
|
505
|
+
|
|
506
|
+
/**
|
|
507
|
+
* Schedule a function to run at a specific audio time
|
|
508
|
+
*/
|
|
509
|
+
static schedule(fn: () => void, time: number): number;
|
|
510
|
+
|
|
511
|
+
/**
|
|
512
|
+
* Close the audio context and cleanup
|
|
513
|
+
*/
|
|
514
|
+
static close(): Promise<void>;
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
// ==========================================================================
|
|
518
|
+
// Sound (Stateless Primitives)
|
|
519
|
+
// ==========================================================================
|
|
520
|
+
|
|
521
|
+
export class Sound {
|
|
522
|
+
/**
|
|
523
|
+
* Generate a beep/blip sound effect
|
|
524
|
+
*/
|
|
525
|
+
static beep(
|
|
526
|
+
frequency?: number,
|
|
527
|
+
duration?: number,
|
|
528
|
+
options?: { volume?: number; type?: OscillatorType }
|
|
529
|
+
): void;
|
|
530
|
+
|
|
531
|
+
/**
|
|
532
|
+
* Generate a click/tick sound
|
|
533
|
+
*/
|
|
534
|
+
static click(volume?: number): void;
|
|
535
|
+
|
|
536
|
+
/**
|
|
537
|
+
* Generate a sweep sound (rising or falling)
|
|
538
|
+
*/
|
|
539
|
+
static sweep(
|
|
540
|
+
startFreq: number,
|
|
541
|
+
endFreq: number,
|
|
542
|
+
duration: number,
|
|
543
|
+
options?: { volume?: number; type?: OscillatorType }
|
|
544
|
+
): void;
|
|
545
|
+
|
|
546
|
+
/**
|
|
547
|
+
* Play a note from scale based on value
|
|
548
|
+
*/
|
|
549
|
+
static fromValue(
|
|
550
|
+
value: number,
|
|
551
|
+
options?: {
|
|
552
|
+
root?: string;
|
|
553
|
+
scale?: ScaleName;
|
|
554
|
+
octaves?: number;
|
|
555
|
+
duration?: number;
|
|
556
|
+
volume?: number;
|
|
557
|
+
type?: OscillatorType;
|
|
558
|
+
}
|
|
559
|
+
): void;
|
|
560
|
+
|
|
561
|
+
/**
|
|
562
|
+
* Collision/impact sound
|
|
563
|
+
*/
|
|
564
|
+
static impact(intensity?: number): void;
|
|
565
|
+
|
|
566
|
+
/**
|
|
567
|
+
* Explosion sound effect
|
|
568
|
+
*/
|
|
569
|
+
static explosion(intensity?: number): void;
|
|
570
|
+
|
|
571
|
+
/**
|
|
572
|
+
* Laser/shoot sound effect
|
|
573
|
+
*/
|
|
574
|
+
static laser(options?: {
|
|
575
|
+
startFreq?: number;
|
|
576
|
+
endFreq?: number;
|
|
577
|
+
duration?: number;
|
|
578
|
+
volume?: number;
|
|
579
|
+
type?: OscillatorType;
|
|
580
|
+
}): void;
|
|
581
|
+
|
|
582
|
+
/**
|
|
583
|
+
* Power-up sound effect
|
|
584
|
+
*/
|
|
585
|
+
static powerUp(options?: {
|
|
586
|
+
startFreq?: number;
|
|
587
|
+
endFreq?: number;
|
|
588
|
+
duration?: number;
|
|
589
|
+
volume?: number;
|
|
590
|
+
}): void;
|
|
591
|
+
|
|
592
|
+
/**
|
|
593
|
+
* Hurt/damage sound effect
|
|
594
|
+
*/
|
|
595
|
+
static hurt(intensity?: number): void;
|
|
596
|
+
|
|
597
|
+
/**
|
|
598
|
+
* Coin/pickup sound effect
|
|
599
|
+
*/
|
|
600
|
+
static coin(options?: { baseFreq?: number; volume?: number }): void;
|
|
601
|
+
|
|
602
|
+
/**
|
|
603
|
+
* Jump sound effect
|
|
604
|
+
*/
|
|
605
|
+
static jump(options?: {
|
|
606
|
+
startFreq?: number;
|
|
607
|
+
endFreq?: number;
|
|
608
|
+
duration?: number;
|
|
609
|
+
volume?: number;
|
|
610
|
+
}): void;
|
|
611
|
+
|
|
612
|
+
/**
|
|
613
|
+
* Menu select/confirm sound
|
|
614
|
+
*/
|
|
615
|
+
static select(options?: { frequency?: number; volume?: number }): void;
|
|
616
|
+
|
|
617
|
+
/**
|
|
618
|
+
* Error/denied sound
|
|
619
|
+
*/
|
|
620
|
+
static error(options?: { volume?: number }): void;
|
|
621
|
+
|
|
622
|
+
/**
|
|
623
|
+
* Ambient drone generator
|
|
624
|
+
*/
|
|
625
|
+
static drone(
|
|
626
|
+
root?: string,
|
|
627
|
+
options?: { volume?: number; richness?: number }
|
|
628
|
+
): DroneController | null;
|
|
629
|
+
|
|
630
|
+
/**
|
|
631
|
+
* Play a musical note
|
|
632
|
+
*/
|
|
633
|
+
static note(
|
|
634
|
+
note: string,
|
|
635
|
+
duration?: number,
|
|
636
|
+
options?: {
|
|
637
|
+
volume?: number;
|
|
638
|
+
type?: OscillatorType;
|
|
639
|
+
envelope?: EnvelopeOptions;
|
|
640
|
+
}
|
|
641
|
+
): void;
|
|
642
|
+
|
|
643
|
+
/**
|
|
644
|
+
* Play a chord
|
|
645
|
+
*/
|
|
646
|
+
static chord(
|
|
647
|
+
root: string,
|
|
648
|
+
chordType?: ChordType,
|
|
649
|
+
duration?: number,
|
|
650
|
+
options?: { volume?: number; type?: OscillatorType; strum?: number }
|
|
651
|
+
): void;
|
|
652
|
+
|
|
653
|
+
/**
|
|
654
|
+
* Play notes in a sequence
|
|
655
|
+
*/
|
|
656
|
+
static sequence(
|
|
657
|
+
notes: string[],
|
|
658
|
+
noteDuration?: number,
|
|
659
|
+
gap?: number,
|
|
660
|
+
options?: { volume?: number; type?: OscillatorType }
|
|
661
|
+
): void;
|
|
662
|
+
|
|
663
|
+
/**
|
|
664
|
+
* Win/victory fanfare
|
|
665
|
+
*/
|
|
666
|
+
static win(): void;
|
|
667
|
+
|
|
668
|
+
/**
|
|
669
|
+
* Lose/game over sound
|
|
670
|
+
*/
|
|
671
|
+
static lose(): void;
|
|
672
|
+
}
|