@primitiv/audio 0.19.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.txt +190 -0
- package/README.md +9 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.ts +188 -0
- package/dist/index.mjs +1 -0
- package/package.json +54 -0
package/LICENSE.txt
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to the Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by the Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding any notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
Copyright 2026 Thomas Piquet (THP Software)
|
|
179
|
+
|
|
180
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
181
|
+
you may not use this file except in compliance with the License.
|
|
182
|
+
You may obtain a copy of the License at
|
|
183
|
+
|
|
184
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
185
|
+
|
|
186
|
+
Unless required by applicable law or agreed to in writing, software
|
|
187
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
188
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
189
|
+
See the License for the specific language governing permissions and
|
|
190
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# @primitiv/audio
|
|
2
|
+
|
|
3
|
+
> **Internal package** - This is an internal module of the [Primitiv Engine](https://primitivengine.com/).
|
|
4
|
+
|
|
5
|
+
For documentation, examples, and guides, visit **[primitivengine.com](https://primitivengine.com/)**.
|
|
6
|
+
|
|
7
|
+
## 📄 License
|
|
8
|
+
|
|
9
|
+
Apache-2.0 - See [LICENSE.txt](./LICENSE.txt).
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var g=Object.defineProperty;var N=Object.getOwnPropertyDescriptor;var T=Object.getOwnPropertyNames;var S=Object.prototype.hasOwnProperty;var w=(l,e)=>{for(var t in e)g(l,t,{get:e[t],enumerable:!0})},I=(l,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of T(e))!S.call(l,n)&&n!==t&&g(l,n,{get:()=>e[n],enumerable:!(i=N(e,n))||i.enumerable});return l};var C=l=>I(g({},"__esModule",{value:!0}),l);var V={};w(V,{AudioEngine:()=>v,ManagedSource:()=>p,RetroTones:()=>f,SoundBank:()=>h,SpatialProcessor:()=>m});module.exports=C(V);var x=require("@primitiv/logger");var A=require("@primitiv/logger"),y=A.Logger.create("audio:soundbank"),h=class{sounds=new Map;nameToId=new Map;audioContext;constructor(e){this.audioContext=e}async loadFromData(e,t,i){try{let n=await this.audioContext.decodeAudioData(i.buffer);this.store(e,t,n)}catch(n){throw y.error(`Failed to decode sound "${t}" (${e})`,n),n}}async loadFromUrl(e,t,i){try{let a=await(await fetch(i)).arrayBuffer(),s=await this.audioContext.decodeAudioData(a);this.store(e,t,s)}catch(n){throw y.error(`Failed to load sound "${t}" from URL ${i}`,n),n}}store(e,t,i){this.sounds.set(e,i),this.nameToId.set(t,e)}get(e){if(typeof e=="number")return this.sounds.get(e);let t=this.nameToId.get(e);return t!==void 0?this.sounds.get(t):void 0}has(e){return this.get(e)!==void 0}clear(){this.sounds.clear(),this.nameToId.clear()}getAll(){let e=[],t=new Map;for(let[i,n]of this.nameToId)t.set(n,i);for(let[i,n]of this.sounds)e.push({soundId:i,name:t.get(i)??`Sound ${i}`,duration:n.duration});return e}};var p=class{instanceId;soundId;name;source;gainNode;pannerNode;lowpassNode;highpassNode;reverbSend;audioContext;destination;t=!1;n=!1;e=1;s=1;i=null;position;onEnded;constructor(e,t,i,n,a,s={}){this.audioContext=e,this.instanceId=t,this.soundId=i,this.name=s.name??"",this.destination=a,this.e=s.volume??1,this.position=s.position,this.source=e.createBufferSource(),this.source.buffer=n,this.source.loop=s.loop??!1,this.source.playbackRate.value=s.pitch??1,this.gainNode=e.createGain();let c=s.fadeIn??0;c>0?(this.gainNode.gain.setValueAtTime(0,e.currentTime),this.gainNode.gain.linearRampToValueAtTime(this.e,e.currentTime+c)):this.gainNode.gain.value=this.e,s.position&&(this.pannerNode=e.createStereoPanner()),this.source.connect(this.gainNode),this.pannerNode?(this.gainNode.connect(this.pannerNode),this.pannerNode.connect(this.destination)):this.gainNode.connect(this.destination),s.reverbNode&&(this.reverbSend=e.createGain(),this.reverbSend.gain.value=s.reverb??0,this.gainNode.connect(this.reverbSend),this.reverbSend.connect(s.reverbNode)),s.lowpass&&this.setLowpass(s.lowpass),s.highpass&&this.setHighpass(s.highpass),this.source.onended=()=>{this.n||(this.t=!0,this.onEnded?.())}}start(e=0){this.source.start(0,e)}stop(e=0){this.t||(e>0?(this.gainNode.gain.linearRampToValueAtTime(0,this.audioContext.currentTime+e),this.i=setTimeout(()=>this.internalStop(),e*1e3)):this.internalStop())}internalStop(){this.i!==null&&(clearTimeout(this.i),this.i=null);try{this.source.stop()}catch{}this.t=!0,this.onEnded?.()}setVolume(e,t=0){this.e=e,this.updateTotalVolume(t)}setSpatialVolume(e){this.s=e,this.updateTotalVolume()}updateTotalVolume(e=0){let t=this.e*this.s;e>0?this.gainNode.gain.linearRampToValueAtTime(t,this.audioContext.currentTime+e):this.gainNode.gain.setValueAtTime(t,this.audioContext.currentTime)}setPan(e){this.pannerNode&&this.pannerNode.pan.setValueAtTime(e,this.audioContext.currentTime)}setPitch(e){this.source.playbackRate.setValueAtTime(e,this.audioContext.currentTime)}setLowpass(e){e<=0?this.lowpassNode=void 0:(this.lowpassNode||(this.lowpassNode=this.audioContext.createBiquadFilter(),this.lowpassNode.type="lowpass"),this.lowpassNode.frequency.setValueAtTime(e,this.audioContext.currentTime)),this.updateChain()}setHighpass(e){e<=0?this.highpassNode=void 0:(this.highpassNode||(this.highpassNode=this.audioContext.createBiquadFilter(),this.highpassNode.type="highpass"),this.highpassNode.frequency.setValueAtTime(e,this.audioContext.currentTime)),this.updateChain()}updateChain(){this.source.disconnect(),this.lowpassNode&&this.lowpassNode.disconnect(),this.highpassNode&&this.highpassNode.disconnect();let e=this.source;this.lowpassNode&&(e.connect(this.lowpassNode),e=this.lowpassNode),this.highpassNode&&(e.connect(this.highpassNode),e=this.highpassNode),e.connect(this.gainNode),this.reverbSend&&this.gainNode.connect(this.reverbSend)}setReverb(e){this.reverbSend&&this.reverbSend.gain.setTargetAtTime(e,this.audioContext.currentTime,.1)}isPlaying(){return!this.t&&!this.n}};var m=class{config={listenerX:0,listenerY:0,maxDistance:200,referenceDistance:20,rolloffFactor:1,panSpread:1};configure(e){e.maxDistance!==void 0&&(this.config.maxDistance=e.maxDistance),e.referenceDistance!==void 0&&(this.config.referenceDistance=e.referenceDistance),e.rolloffFactor!==void 0&&(this.config.rolloffFactor=e.rolloffFactor),e.panSpread!==void 0&&(this.config.panSpread=e.panSpread)}setListenerPosition(e,t){this.config.listenerX=e,this.config.listenerY=t}getConfig(){return this.config}calculate2D(e,t){let{listenerX:i,listenerY:n,maxDistance:a,referenceDistance:s,panSpread:c}=this.config,r=e-i,o=t-n,u=Math.sqrt(r*r+o*o),d;u<=s?d=1:u>=a?d=0:d=1-(u-s)/(a-s);let b=0;return a>0&&c>0&&(b=r/a*c,b=Math.max(-1,Math.min(1,b))),{pan:b,distanceVolume:d}}};var f=class{static playStartSound(e,t){let i=e.currentTime,n=[261.63,329.63,392,523.25],a=.06,s=.07;n.forEach((c,r)=>{let o=i+r*s,u=e.createOscillator(),d=e.createGain();u.type="square",u.frequency.setValueAtTime(c,o),d.gain.setValueAtTime(0,o),d.gain.linearRampToValueAtTime(.2,o+.005),d.gain.setValueAtTime(.2,o+a-.01),d.gain.linearRampToValueAtTime(0,o+a),u.connect(d),d.connect(t),u.start(o),u.stop(o+a)})}static noteToFrequency(e){let t=/^([A-G])([#b]?)(\d)$/i,i=e.match(t);if(!i)return null;let[,n,a,s]=i,c=parseInt(s,10),o={C:0,D:2,E:4,F:5,G:7,A:9,B:11}[n.toUpperCase()];a==="#"?o+=1:a==="b"&&(o-=1);let u=o+(c+1)*12;return 440*Math.pow(2,(u-49)/12)}};var B=x.Logger.create("audio:engine"),v=class{ctx=null;masterGain=null;reverbBus=null;soundBank=null;spatial=new m;instances=new Map;nextInstanceId=1;onAudioEvent=null;initialize(){if(this.ctx)return!0;try{return this.ctx=new(window.AudioContext||window.webkitAudioContext),this.masterGain=this.ctx.createGain(),this.masterGain.connect(this.ctx.destination),this.ctx.state==="suspended"&&this.ctx.resume(),this.reverbBus=this.ctx.createConvolver(),this.reverbBus.buffer=this.createImpulseResponse(2,2),this.reverbBus.connect(this.masterGain),this.soundBank=new h(this.ctx),!0}catch(e){return B.error("Failed to initialize",e),!1}}createImpulseResponse(e,t){if(!this.ctx)throw new Error("Context not initialized");let i=this.ctx.sampleRate,n=i*e,a=this.ctx.createBuffer(2,n,i);for(let s=0;s<2;s++){let c=a.getChannelData(s);for(let r=0;r<n;r++){let o=Math.pow(1-r/n,t);c[r]=(Math.random()*2-1)*o}}return a}getLoader(){return this.soundBank}setMasterVolume(e){this.masterGain&&(this.masterGain.gain.value=Math.max(0,Math.min(1,e)))}getMasterVolume(){return this.masterGain?.gain.value??1}play(e,t={}){if(!this.ctx||!this.masterGain||!this.soundBank)return null;let i=this.soundBank.get(e);if(!i)return null;let n=t.instanceId??this.nextInstanceId++,a=typeof e=="number"?e:-1,s=new p(this.ctx,n,a,i,this.masterGain,{...t,name:t.name??(typeof e=="string"?e:""),reverbNode:this.reverbBus||void 0});if(t.position){let{pan:c,distanceVolume:r}=this.spatial.calculate2D(t.position.x,t.position.y);s.setSpatialVolume(r),s.setPan(c)}return s.onEnded=()=>{this.onAudioEvent?.({type:"playback-ended",instanceId:n,soundId:a}),this.instances.delete(n)},this.instances.set(n,s),s.start(),this.onAudioEvent?.({type:"playback-started",instanceId:n,soundId:a}),{instanceId:n}}stop(e){if(typeof e=="number"){let t=this.instances.get(e);if(t)return t.stop(),1}else{let t=0;for(let i of this.instances.values())(e==="all"||i.name===e)&&(i.stop(),t++);return t}return 0}stopAll(){let e=this.instances.size;return this.instances.forEach(t=>t.stop()),this.instances.clear(),e}fadeOut(e,t){if(e==="all"){let i=this.instances.size;return this.instances.forEach(n=>n.stop(t)),i}if(typeof e=="number"){let i=this.instances.get(e);if(i)return i.stop(t),1}return 0}pause(e){return 0}resume(e){return 0}setListenerPosition(e,t){this.spatial.setListenerPosition(e,t);for(let i of this.instances.values())if(i.position){let{pan:n,distanceVolume:a}=this.spatial.calculate2D(i.position.x,i.position.y);i.setPan(n),i.setSpatialVolume(a)}}configureSpatial(e){this.spatial.configure(e)}setEffects(e,t){let i=this.instances.get(e);i&&(t.lowpass!==void 0&&i.setLowpass(t.lowpass),t.highpass!==void 0&&i.setHighpass(t.highpass),t.reverb!==void 0&&i.setReverb(t.reverb),t.pitch!==void 0&&i.setPitch(t.pitch),t.volume!==void 0&&i.setVolume(t.volume))}stopBySoundId(e){let t=0;for(let i of this.instances.values())i.soundId===e&&(i.stop(),t++);return t}fadeOutBySoundId(e,t){let i=0;for(let n of this.instances.values())n.soundId===e&&(n.stop(t),i++);return i}pauseBySoundId(e){return 0}resumeBySoundId(e){return 0}playTone(e,t,i={}){if(!this.ctx||!this.masterGain)return;let{type:n="sine",volume:a=.3,attack:s=.01,release:c=.1}=i,r=this.ctx.currentTime,o=this.ctx.createOscillator();o.type=n,o.frequency.setValueAtTime(e,r);let u=this.ctx.createGain();u.gain.setValueAtTime(0,r),u.gain.linearRampToValueAtTime(a,r+s),u.gain.setValueAtTime(a,r+t-c),u.gain.linearRampToValueAtTime(0,r+t),o.connect(u),u.connect(this.masterGain),o.start(r),o.stop(r+t)}playStartSound(){this.ctx&&this.masterGain&&f.playStartSound(this.ctx,this.masterGain)}destroy(){this.stopAll(),this.ctx&&(this.ctx.close().catch(()=>{}),this.ctx=null),this.masterGain=null,this.reverbBus=null,this.soundBank=null,this.onAudioEvent=null}};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { ISoundLoader, IAudioProcessor, AudioAck, AudioPlayOptions, AudioPlayResult, AudioSpatialOptions, SoundInstanceId, SpatialAudioConfig } from '@primitiv/types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Low-level cache for decoded AudioBuffers.
|
|
5
|
+
* Implements ISoundLoader for platform-agnostic sound loading.
|
|
6
|
+
*/
|
|
7
|
+
declare class SoundBank implements ISoundLoader {
|
|
8
|
+
private sounds;
|
|
9
|
+
private nameToId;
|
|
10
|
+
private audioContext;
|
|
11
|
+
constructor(audioContext: AudioContext);
|
|
12
|
+
/**
|
|
13
|
+
* Load a sound from binary data (MP3, WAV, etc.)
|
|
14
|
+
*/
|
|
15
|
+
loadFromData(soundId: number, name: string, data: Uint8Array): Promise<void>;
|
|
16
|
+
/**
|
|
17
|
+
* Load a sound from an external URL
|
|
18
|
+
*/
|
|
19
|
+
loadFromUrl(soundId: number, name: string, url: string): Promise<void>;
|
|
20
|
+
/**
|
|
21
|
+
* Store a decoded buffer directly
|
|
22
|
+
*/
|
|
23
|
+
store(soundId: number, name: string, buffer: AudioBuffer): void;
|
|
24
|
+
/**
|
|
25
|
+
* Get a decoded buffer by ID or name
|
|
26
|
+
*/
|
|
27
|
+
get(idOrName: number | string): AudioBuffer | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* Check if a sound is loaded
|
|
30
|
+
*/
|
|
31
|
+
has(idOrName: number | string): boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Clear all cached sounds
|
|
34
|
+
*/
|
|
35
|
+
clear(): void;
|
|
36
|
+
/**
|
|
37
|
+
* Get all loaded sounds as an array of descriptors.
|
|
38
|
+
* Used by the visual-debugger assets panel.
|
|
39
|
+
*/
|
|
40
|
+
getAll(): Array<{
|
|
41
|
+
soundId: number;
|
|
42
|
+
name: string;
|
|
43
|
+
duration: number;
|
|
44
|
+
}>;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
declare class AudioEngine implements IAudioProcessor {
|
|
48
|
+
private ctx;
|
|
49
|
+
private masterGain;
|
|
50
|
+
private reverbBus;
|
|
51
|
+
private soundBank;
|
|
52
|
+
private spatial;
|
|
53
|
+
private instances;
|
|
54
|
+
private nextInstanceId;
|
|
55
|
+
/**
|
|
56
|
+
* Optional callback invoked on audio lifecycle events
|
|
57
|
+
* (playback-started, playback-ended).
|
|
58
|
+
*
|
|
59
|
+
* Set by ClientRuntime to queue acks for the server.
|
|
60
|
+
*/
|
|
61
|
+
onAudioEvent: ((ack: AudioAck) => void) | null;
|
|
62
|
+
initialize(): boolean;
|
|
63
|
+
private createImpulseResponse;
|
|
64
|
+
getLoader(): SoundBank | null;
|
|
65
|
+
/**
|
|
66
|
+
* Set the master volume (0.0 = muted, 1.0 = full).
|
|
67
|
+
*/
|
|
68
|
+
setMasterVolume(volume: number): void;
|
|
69
|
+
/**
|
|
70
|
+
* Get the current master volume.
|
|
71
|
+
*/
|
|
72
|
+
getMasterVolume(): number;
|
|
73
|
+
play(sound: string | number, options?: AudioPlayOptions): AudioPlayResult | null;
|
|
74
|
+
stop(target: number | string): number;
|
|
75
|
+
stopAll(): number;
|
|
76
|
+
fadeOut(target: number | string | 'all', duration: number): number;
|
|
77
|
+
pause(_target: number | string | 'all'): number;
|
|
78
|
+
resume(_target: number | string | 'all'): number;
|
|
79
|
+
setListenerPosition(x: number, y: number): void;
|
|
80
|
+
configureSpatial(config: AudioSpatialOptions): void;
|
|
81
|
+
setEffects(instanceId: number, options: {
|
|
82
|
+
lowpass?: number;
|
|
83
|
+
highpass?: number;
|
|
84
|
+
reverb?: number;
|
|
85
|
+
pitch?: number;
|
|
86
|
+
volume?: number;
|
|
87
|
+
}): void;
|
|
88
|
+
stopBySoundId(soundId: number): number;
|
|
89
|
+
fadeOutBySoundId(soundId: number, duration: number): number;
|
|
90
|
+
pauseBySoundId(_soundId: number): number;
|
|
91
|
+
resumeBySoundId(_soundId: number): number;
|
|
92
|
+
/**
|
|
93
|
+
* Play a pure oscillator tone.
|
|
94
|
+
*
|
|
95
|
+
* @param frequency - Tone frequency in Hz (e.g. 440 for A4)
|
|
96
|
+
* @param duration - Duration in seconds
|
|
97
|
+
* @param options - Oscillator type, volume, attack & release envelope
|
|
98
|
+
*/
|
|
99
|
+
playTone(frequency: number, duration: number, options?: {
|
|
100
|
+
type?: OscillatorType;
|
|
101
|
+
volume?: number;
|
|
102
|
+
attack?: number;
|
|
103
|
+
release?: number;
|
|
104
|
+
}): void;
|
|
105
|
+
playStartSound(): void;
|
|
106
|
+
/**
|
|
107
|
+
* Destroy the audio engine and release all resources.
|
|
108
|
+
* Closes the underlying AudioContext to free the browser audio thread.
|
|
109
|
+
* After calling destroy(), this instance must not be reused.
|
|
110
|
+
*/
|
|
111
|
+
destroy(): void;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Managed wrapper for a playing sound instance.
|
|
116
|
+
* Handles volume, pitch, filters and lifecycle events.
|
|
117
|
+
*/
|
|
118
|
+
declare class ManagedSource {
|
|
119
|
+
readonly instanceId: SoundInstanceId;
|
|
120
|
+
readonly soundId: number;
|
|
121
|
+
readonly name: string;
|
|
122
|
+
private source;
|
|
123
|
+
private gainNode;
|
|
124
|
+
private pannerNode?;
|
|
125
|
+
private lowpassNode?;
|
|
126
|
+
private highpassNode?;
|
|
127
|
+
private reverbSend?;
|
|
128
|
+
private audioContext;
|
|
129
|
+
private destination;
|
|
130
|
+
private _stopped;
|
|
131
|
+
private _paused;
|
|
132
|
+
private _baseVolume;
|
|
133
|
+
private _spatialVolume;
|
|
134
|
+
private _fadeOutTimer;
|
|
135
|
+
position?: {
|
|
136
|
+
x: number;
|
|
137
|
+
y: number;
|
|
138
|
+
};
|
|
139
|
+
onEnded?: () => void;
|
|
140
|
+
constructor(ctx: AudioContext, instanceId: SoundInstanceId, soundId: number, buffer: AudioBuffer, dest: AudioNode, options?: AudioPlayOptions);
|
|
141
|
+
start(offset?: number): void;
|
|
142
|
+
stop(duration?: number): void;
|
|
143
|
+
private internalStop;
|
|
144
|
+
setVolume(volume: number, duration?: number): void;
|
|
145
|
+
setSpatialVolume(volume: number): void;
|
|
146
|
+
private updateTotalVolume;
|
|
147
|
+
setPan(pan: number): void;
|
|
148
|
+
setPitch(pitch: number): void;
|
|
149
|
+
setLowpass(freq: number): void;
|
|
150
|
+
setHighpass(freq: number): void;
|
|
151
|
+
private updateChain;
|
|
152
|
+
setReverb(amount: number): void;
|
|
153
|
+
isPlaying(): boolean;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Handles spatial audio configuration and updates.
|
|
158
|
+
* Supports legacy 2D math and modern 3D panner nodes.
|
|
159
|
+
*/
|
|
160
|
+
declare class SpatialProcessor {
|
|
161
|
+
private config;
|
|
162
|
+
configure(options: AudioSpatialOptions): void;
|
|
163
|
+
setListenerPosition(x: number, y: number): void;
|
|
164
|
+
getConfig(): Readonly<SpatialAudioConfig>;
|
|
165
|
+
/**
|
|
166
|
+
* Legacy 2D calculation (ported from UTSP)
|
|
167
|
+
*/
|
|
168
|
+
calculate2D(soundX: number, soundY: number): {
|
|
169
|
+
pan: number;
|
|
170
|
+
distanceVolume: number;
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Utility for generating retro arcade-style sounds and tones.
|
|
176
|
+
*/
|
|
177
|
+
declare class RetroTones {
|
|
178
|
+
/**
|
|
179
|
+
* Play a retro arcade arpeggio
|
|
180
|
+
*/
|
|
181
|
+
static playStartSound(ctx: AudioContext, dest: AudioNode): void;
|
|
182
|
+
/**
|
|
183
|
+
* Convert note name (e.g. 'A4', 'C#5') to frequency
|
|
184
|
+
*/
|
|
185
|
+
static noteToFrequency(note: string): number | null;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
export { AudioEngine, ManagedSource, RetroTones, SoundBank, SpatialProcessor };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Logger as A}from"@primitiv/logger";import{Logger as y}from"@primitiv/logger";var g=y.create("audio:soundbank"),p=class{sounds=new Map;nameToId=new Map;audioContext;constructor(e){this.audioContext=e}async loadFromData(e,t,i){try{let n=await this.audioContext.decodeAudioData(i.buffer);this.store(e,t,n)}catch(n){throw g.error(`Failed to decode sound "${t}" (${e})`,n),n}}async loadFromUrl(e,t,i){try{let a=await(await fetch(i)).arrayBuffer(),s=await this.audioContext.decodeAudioData(a);this.store(e,t,s)}catch(n){throw g.error(`Failed to load sound "${t}" from URL ${i}`,n),n}}store(e,t,i){this.sounds.set(e,i),this.nameToId.set(t,e)}get(e){if(typeof e=="number")return this.sounds.get(e);let t=this.nameToId.get(e);return t!==void 0?this.sounds.get(t):void 0}has(e){return this.get(e)!==void 0}clear(){this.sounds.clear(),this.nameToId.clear()}getAll(){let e=[],t=new Map;for(let[i,n]of this.nameToId)t.set(n,i);for(let[i,n]of this.sounds)e.push({soundId:i,name:t.get(i)??`Sound ${i}`,duration:n.duration});return e}};var m=class{instanceId;soundId;name;source;gainNode;pannerNode;lowpassNode;highpassNode;reverbSend;audioContext;destination;t=!1;n=!1;e=1;s=1;i=null;position;onEnded;constructor(e,t,i,n,a,s={}){this.audioContext=e,this.instanceId=t,this.soundId=i,this.name=s.name??"",this.destination=a,this.e=s.volume??1,this.position=s.position,this.source=e.createBufferSource(),this.source.buffer=n,this.source.loop=s.loop??!1,this.source.playbackRate.value=s.pitch??1,this.gainNode=e.createGain();let c=s.fadeIn??0;c>0?(this.gainNode.gain.setValueAtTime(0,e.currentTime),this.gainNode.gain.linearRampToValueAtTime(this.e,e.currentTime+c)):this.gainNode.gain.value=this.e,s.position&&(this.pannerNode=e.createStereoPanner()),this.source.connect(this.gainNode),this.pannerNode?(this.gainNode.connect(this.pannerNode),this.pannerNode.connect(this.destination)):this.gainNode.connect(this.destination),s.reverbNode&&(this.reverbSend=e.createGain(),this.reverbSend.gain.value=s.reverb??0,this.gainNode.connect(this.reverbSend),this.reverbSend.connect(s.reverbNode)),s.lowpass&&this.setLowpass(s.lowpass),s.highpass&&this.setHighpass(s.highpass),this.source.onended=()=>{this.n||(this.t=!0,this.onEnded?.())}}start(e=0){this.source.start(0,e)}stop(e=0){this.t||(e>0?(this.gainNode.gain.linearRampToValueAtTime(0,this.audioContext.currentTime+e),this.i=setTimeout(()=>this.internalStop(),e*1e3)):this.internalStop())}internalStop(){this.i!==null&&(clearTimeout(this.i),this.i=null);try{this.source.stop()}catch{}this.t=!0,this.onEnded?.()}setVolume(e,t=0){this.e=e,this.updateTotalVolume(t)}setSpatialVolume(e){this.s=e,this.updateTotalVolume()}updateTotalVolume(e=0){let t=this.e*this.s;e>0?this.gainNode.gain.linearRampToValueAtTime(t,this.audioContext.currentTime+e):this.gainNode.gain.setValueAtTime(t,this.audioContext.currentTime)}setPan(e){this.pannerNode&&this.pannerNode.pan.setValueAtTime(e,this.audioContext.currentTime)}setPitch(e){this.source.playbackRate.setValueAtTime(e,this.audioContext.currentTime)}setLowpass(e){e<=0?this.lowpassNode=void 0:(this.lowpassNode||(this.lowpassNode=this.audioContext.createBiquadFilter(),this.lowpassNode.type="lowpass"),this.lowpassNode.frequency.setValueAtTime(e,this.audioContext.currentTime)),this.updateChain()}setHighpass(e){e<=0?this.highpassNode=void 0:(this.highpassNode||(this.highpassNode=this.audioContext.createBiquadFilter(),this.highpassNode.type="highpass"),this.highpassNode.frequency.setValueAtTime(e,this.audioContext.currentTime)),this.updateChain()}updateChain(){this.source.disconnect(),this.lowpassNode&&this.lowpassNode.disconnect(),this.highpassNode&&this.highpassNode.disconnect();let e=this.source;this.lowpassNode&&(e.connect(this.lowpassNode),e=this.lowpassNode),this.highpassNode&&(e.connect(this.highpassNode),e=this.highpassNode),e.connect(this.gainNode),this.reverbSend&&this.gainNode.connect(this.reverbSend)}setReverb(e){this.reverbSend&&this.reverbSend.gain.setTargetAtTime(e,this.audioContext.currentTime,.1)}isPlaying(){return!this.t&&!this.n}};var f=class{config={listenerX:0,listenerY:0,maxDistance:200,referenceDistance:20,rolloffFactor:1,panSpread:1};configure(e){e.maxDistance!==void 0&&(this.config.maxDistance=e.maxDistance),e.referenceDistance!==void 0&&(this.config.referenceDistance=e.referenceDistance),e.rolloffFactor!==void 0&&(this.config.rolloffFactor=e.rolloffFactor),e.panSpread!==void 0&&(this.config.panSpread=e.panSpread)}setListenerPosition(e,t){this.config.listenerX=e,this.config.listenerY=t}getConfig(){return this.config}calculate2D(e,t){let{listenerX:i,listenerY:n,maxDistance:a,referenceDistance:s,panSpread:c}=this.config,r=e-i,o=t-n,u=Math.sqrt(r*r+o*o),l;u<=s?l=1:u>=a?l=0:l=1-(u-s)/(a-s);let h=0;return a>0&&c>0&&(h=r/a*c,h=Math.max(-1,Math.min(1,h))),{pan:h,distanceVolume:l}}};var b=class{static playStartSound(e,t){let i=e.currentTime,n=[261.63,329.63,392,523.25],a=.06,s=.07;n.forEach((c,r)=>{let o=i+r*s,u=e.createOscillator(),l=e.createGain();u.type="square",u.frequency.setValueAtTime(c,o),l.gain.setValueAtTime(0,o),l.gain.linearRampToValueAtTime(.2,o+.005),l.gain.setValueAtTime(.2,o+a-.01),l.gain.linearRampToValueAtTime(0,o+a),u.connect(l),l.connect(t),u.start(o),u.stop(o+a)})}static noteToFrequency(e){let t=/^([A-G])([#b]?)(\d)$/i,i=e.match(t);if(!i)return null;let[,n,a,s]=i,c=parseInt(s,10),o={C:0,D:2,E:4,F:5,G:7,A:9,B:11}[n.toUpperCase()];a==="#"?o+=1:a==="b"&&(o-=1);let u=o+(c+1)*12;return 440*Math.pow(2,(u-49)/12)}};var x=A.create("audio:engine"),v=class{ctx=null;masterGain=null;reverbBus=null;soundBank=null;spatial=new f;instances=new Map;nextInstanceId=1;onAudioEvent=null;initialize(){if(this.ctx)return!0;try{return this.ctx=new(window.AudioContext||window.webkitAudioContext),this.masterGain=this.ctx.createGain(),this.masterGain.connect(this.ctx.destination),this.ctx.state==="suspended"&&this.ctx.resume(),this.reverbBus=this.ctx.createConvolver(),this.reverbBus.buffer=this.createImpulseResponse(2,2),this.reverbBus.connect(this.masterGain),this.soundBank=new p(this.ctx),!0}catch(e){return x.error("Failed to initialize",e),!1}}createImpulseResponse(e,t){if(!this.ctx)throw new Error("Context not initialized");let i=this.ctx.sampleRate,n=i*e,a=this.ctx.createBuffer(2,n,i);for(let s=0;s<2;s++){let c=a.getChannelData(s);for(let r=0;r<n;r++){let o=Math.pow(1-r/n,t);c[r]=(Math.random()*2-1)*o}}return a}getLoader(){return this.soundBank}setMasterVolume(e){this.masterGain&&(this.masterGain.gain.value=Math.max(0,Math.min(1,e)))}getMasterVolume(){return this.masterGain?.gain.value??1}play(e,t={}){if(!this.ctx||!this.masterGain||!this.soundBank)return null;let i=this.soundBank.get(e);if(!i)return null;let n=t.instanceId??this.nextInstanceId++,a=typeof e=="number"?e:-1,s=new m(this.ctx,n,a,i,this.masterGain,{...t,name:t.name??(typeof e=="string"?e:""),reverbNode:this.reverbBus||void 0});if(t.position){let{pan:c,distanceVolume:r}=this.spatial.calculate2D(t.position.x,t.position.y);s.setSpatialVolume(r),s.setPan(c)}return s.onEnded=()=>{this.onAudioEvent?.({type:"playback-ended",instanceId:n,soundId:a}),this.instances.delete(n)},this.instances.set(n,s),s.start(),this.onAudioEvent?.({type:"playback-started",instanceId:n,soundId:a}),{instanceId:n}}stop(e){if(typeof e=="number"){let t=this.instances.get(e);if(t)return t.stop(),1}else{let t=0;for(let i of this.instances.values())(e==="all"||i.name===e)&&(i.stop(),t++);return t}return 0}stopAll(){let e=this.instances.size;return this.instances.forEach(t=>t.stop()),this.instances.clear(),e}fadeOut(e,t){if(e==="all"){let i=this.instances.size;return this.instances.forEach(n=>n.stop(t)),i}if(typeof e=="number"){let i=this.instances.get(e);if(i)return i.stop(t),1}return 0}pause(e){return 0}resume(e){return 0}setListenerPosition(e,t){this.spatial.setListenerPosition(e,t);for(let i of this.instances.values())if(i.position){let{pan:n,distanceVolume:a}=this.spatial.calculate2D(i.position.x,i.position.y);i.setPan(n),i.setSpatialVolume(a)}}configureSpatial(e){this.spatial.configure(e)}setEffects(e,t){let i=this.instances.get(e);i&&(t.lowpass!==void 0&&i.setLowpass(t.lowpass),t.highpass!==void 0&&i.setHighpass(t.highpass),t.reverb!==void 0&&i.setReverb(t.reverb),t.pitch!==void 0&&i.setPitch(t.pitch),t.volume!==void 0&&i.setVolume(t.volume))}stopBySoundId(e){let t=0;for(let i of this.instances.values())i.soundId===e&&(i.stop(),t++);return t}fadeOutBySoundId(e,t){let i=0;for(let n of this.instances.values())n.soundId===e&&(n.stop(t),i++);return i}pauseBySoundId(e){return 0}resumeBySoundId(e){return 0}playTone(e,t,i={}){if(!this.ctx||!this.masterGain)return;let{type:n="sine",volume:a=.3,attack:s=.01,release:c=.1}=i,r=this.ctx.currentTime,o=this.ctx.createOscillator();o.type=n,o.frequency.setValueAtTime(e,r);let u=this.ctx.createGain();u.gain.setValueAtTime(0,r),u.gain.linearRampToValueAtTime(a,r+s),u.gain.setValueAtTime(a,r+t-c),u.gain.linearRampToValueAtTime(0,r+t),o.connect(u),u.connect(this.masterGain),o.start(r),o.stop(r+t)}playStartSound(){this.ctx&&this.masterGain&&b.playStartSound(this.ctx,this.masterGain)}destroy(){this.stopAll(),this.ctx&&(this.ctx.close().catch(()=>{}),this.ctx=null),this.masterGain=null,this.reverbBus=null,this.soundBank=null,this.onAudioEvent=null}};export{v as AudioEngine,m as ManagedSource,b as RetroTones,p as SoundBank,f as SpatialProcessor};
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@primitiv/audio",
|
|
3
|
+
"version": "0.19.0",
|
|
4
|
+
"description": "Primitiv audio module",
|
|
5
|
+
"author": "THP Software",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/thp-software/primitiv",
|
|
9
|
+
"directory": "packages/audio"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://primitivengine.com",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/thp-software/primitiv/issues"
|
|
14
|
+
},
|
|
15
|
+
"license": "Apache-2.0",
|
|
16
|
+
"type": "module",
|
|
17
|
+
"main": "./dist/index.cjs",
|
|
18
|
+
"module": "./dist/index.mjs",
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
23
|
+
"import": "./dist/index.mjs",
|
|
24
|
+
"require": "./dist/index.cjs"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"engines": {
|
|
28
|
+
"node": ">=18.0.0"
|
|
29
|
+
},
|
|
30
|
+
"sideEffects": false,
|
|
31
|
+
"files": [
|
|
32
|
+
"dist",
|
|
33
|
+
"README.md",
|
|
34
|
+
"LICENSE.txt"
|
|
35
|
+
],
|
|
36
|
+
"publishConfig": {
|
|
37
|
+
"access": "public"
|
|
38
|
+
},
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"@primitiv/logger": "0.19.0",
|
|
41
|
+
"@primitiv/types": "0.19.0"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"typescript": "^5.6.3"
|
|
45
|
+
},
|
|
46
|
+
"scripts": {
|
|
47
|
+
"build": "rimraf dist && node ../../scripts/build-package.mjs packages/audio",
|
|
48
|
+
"dev": "tsc --watch",
|
|
49
|
+
"clean": "rimraf dist",
|
|
50
|
+
"lint": "eslint \"src/**/*.ts\" --max-warnings 0",
|
|
51
|
+
"typecheck": "tsc --noEmit",
|
|
52
|
+
"test": "node --test --import tsx src/**/*.test.ts"
|
|
53
|
+
}
|
|
54
|
+
}
|