cacophony 0.1.1 → 0.1.3
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 +21 -0
- package/README.md +2 -2
- package/package.json +26 -25
- package/src/cacophony.ts +41 -17
package/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Christopher Toth
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -17,7 +17,7 @@ Cacophony is a highly robust and versatile audio library for Typescript leveragi
|
|
|
17
17
|
Cacophony is provided as a regular NPM module. Install it using:
|
|
18
18
|
|
|
19
19
|
```bash
|
|
20
|
-
$ npm install cacophony
|
|
20
|
+
$ npm install cacophony
|
|
21
21
|
```
|
|
22
22
|
|
|
23
23
|
## Straightforward Usage
|
|
@@ -50,7 +50,7 @@ Crafts a `Sound` instance using either an `AudioBuffer` or a URL string leading
|
|
|
50
50
|
|
|
51
51
|
#### Method: `async createGroup(sounds: Sound[]): Promise<Group>`
|
|
52
52
|
|
|
53
|
-
|
|
53
|
+
Creates a `Group` entity from an array of `Sound` instances.
|
|
54
54
|
|
|
55
55
|
#### Method: `async createGroupFromUrls(urls: string[]): Promise<Group>`
|
|
56
56
|
|
package/package.json
CHANGED
|
@@ -1,25 +1,26 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "cacophony",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "Typescript audio library with caching",
|
|
5
|
-
"main": "dist/index.js",
|
|
6
|
-
"types": "dist/index.d.ts",
|
|
7
|
-
"scripts": {
|
|
8
|
-
"build": "npm run clean && tsc --build",
|
|
9
|
-
"clean": "tsc --build --clean",
|
|
10
|
-
"prepublishOnly": "npm run build",
|
|
11
|
-
"test": "echo \"Error: no test specified\" && exit 1"
|
|
12
|
-
},
|
|
13
|
-
"keywords": [
|
|
14
|
-
"audio",
|
|
15
|
-
"webaudio"
|
|
16
|
-
],
|
|
17
|
-
"author": "Christopher Toth",
|
|
18
|
-
"license": "ISC",
|
|
19
|
-
"devDependencies": {
|
|
20
|
-
"
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "cacophony",
|
|
3
|
+
"version": "0.1.3",
|
|
4
|
+
"description": "Typescript audio library with caching",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "npm run clean && tsc --build",
|
|
9
|
+
"clean": "tsc --build --clean",
|
|
10
|
+
"prepublishOnly": "npm run build",
|
|
11
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [
|
|
14
|
+
"audio",
|
|
15
|
+
"webaudio"
|
|
16
|
+
],
|
|
17
|
+
"author": "Christopher Toth",
|
|
18
|
+
"license": "ISC",
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"standardized-audio-context-mock": "^9.6.29",
|
|
21
|
+
"typescript": "^5.1.6"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"standardized-audio-context": "^25.3.55"
|
|
25
|
+
}
|
|
26
|
+
}
|
package/src/cacophony.ts
CHANGED
|
@@ -21,6 +21,8 @@ export interface BaseSound {
|
|
|
21
21
|
addFilter(filter: BiquadFilterNode): void;
|
|
22
22
|
removeFilter(filter: BiquadFilterNode): void;
|
|
23
23
|
moveTo(x: number, y: number, z: number): void;
|
|
24
|
+
volume: number;
|
|
25
|
+
|
|
24
26
|
loop(loopCount?: LoopCount): LoopCount;
|
|
25
27
|
}
|
|
26
28
|
|
|
@@ -68,7 +70,6 @@ export class Cacophony {
|
|
|
68
70
|
return filter;
|
|
69
71
|
}
|
|
70
72
|
|
|
71
|
-
|
|
72
73
|
pause() {
|
|
73
74
|
if ('suspend' in this.context) {
|
|
74
75
|
this.context.suspend();
|
|
@@ -91,6 +92,14 @@ export class Cacophony {
|
|
|
91
92
|
this.globalGainNode.gain.value = volume;
|
|
92
93
|
}
|
|
93
94
|
|
|
95
|
+
get volume(): number {
|
|
96
|
+
return this.globalGainNode.gain.value;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
set volume(volume: number) {
|
|
100
|
+
this.setGlobalVolume(volume);
|
|
101
|
+
}
|
|
102
|
+
|
|
94
103
|
mute() {
|
|
95
104
|
this.prevVolume = this.globalGainNode.gain.value;
|
|
96
105
|
this.setGlobalVolume(0);
|
|
@@ -197,8 +206,16 @@ export class Sound extends FilterManager implements BaseSound {
|
|
|
197
206
|
super.removeFilter(filter);
|
|
198
207
|
this.playbacks.forEach(p => p.removeFilter(filter));
|
|
199
208
|
}
|
|
200
|
-
}
|
|
201
209
|
|
|
210
|
+
get volume(): number {
|
|
211
|
+
return this.globalGainNode.gain.value;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
set volume(volume: number) {
|
|
215
|
+
this.globalGainNode.gain.value = volume;
|
|
216
|
+
this.playbacks.forEach(p => p.volume = volume);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
202
219
|
|
|
203
220
|
class Playback extends FilterManager implements BaseSound {
|
|
204
221
|
context: AudioContext;
|
|
@@ -223,7 +240,6 @@ class Playback extends FilterManager implements BaseSound {
|
|
|
223
240
|
source.start();
|
|
224
241
|
}
|
|
225
242
|
|
|
226
|
-
|
|
227
243
|
handleLoop(): void {
|
|
228
244
|
if (this.loopCount === 'infinite' || this.currentLoop < this.loopCount) {
|
|
229
245
|
this.currentLoop++;
|
|
@@ -238,25 +254,26 @@ class Playback extends FilterManager implements BaseSound {
|
|
|
238
254
|
return [this];
|
|
239
255
|
}
|
|
240
256
|
|
|
257
|
+
get volume(): number {
|
|
258
|
+
return this.gainNode.gain.value;
|
|
259
|
+
}
|
|
260
|
+
|
|
241
261
|
set volume(v: number) {
|
|
242
262
|
this.gainNode.gain.value = v;
|
|
243
263
|
}
|
|
244
264
|
|
|
245
265
|
fadeIn(time: number, FfadeType: FadeType = 'linear'): Promise<void> {
|
|
246
266
|
return new Promise(resolve => {
|
|
247
|
-
|
|
248
|
-
this.gainNode.gain.
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
}
|
|
258
|
-
// Resolving the Promise after the fade-in time
|
|
259
|
-
setTimeout(() => resolve(), time * 1000);
|
|
267
|
+
let volume = 0;
|
|
268
|
+
const increment = this.gainNode.gain.value / (time * 60); // Assuming time is in seconds
|
|
269
|
+
const interval = setInterval(() => {
|
|
270
|
+
volume += increment;
|
|
271
|
+
this.gainNode.gain.value = volume;
|
|
272
|
+
if (volume >= this.gainNode.gain.value) {
|
|
273
|
+
clearInterval(interval);
|
|
274
|
+
resolve();
|
|
275
|
+
}
|
|
276
|
+
}, 1000 / 60); // 60 times per second
|
|
260
277
|
});
|
|
261
278
|
}
|
|
262
279
|
|
|
@@ -297,8 +314,8 @@ class Playback extends FilterManager implements BaseSound {
|
|
|
297
314
|
if ('suspend' in this.source.context) {
|
|
298
315
|
this.source.context.suspend();
|
|
299
316
|
}
|
|
300
|
-
|
|
301
317
|
}
|
|
318
|
+
|
|
302
319
|
resume(): void {
|
|
303
320
|
if ('resume' in this.source.context) {
|
|
304
321
|
this.source.context.resume();
|
|
@@ -391,6 +408,13 @@ export class Group implements BaseSound {
|
|
|
391
408
|
this.sounds.forEach(sound => sound.moveTo(x, y, z));
|
|
392
409
|
}
|
|
393
410
|
|
|
411
|
+
get volume(): number {
|
|
412
|
+
return this.sounds[0].volume;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
set volume(volume: number) {
|
|
416
|
+
this.sounds.forEach(sound => sound.volume = volume);
|
|
417
|
+
}
|
|
394
418
|
|
|
395
419
|
}
|
|
396
420
|
|