@adatechnology/game-audio 0.5.0 → 0.6.1

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/dist/index.js CHANGED
@@ -23,6 +23,9 @@ import {
23
23
  GAME_SFX_BANK,
24
24
  GAME_SFX_CLASSES,
25
25
  GAME_SFX_FALLBACK,
26
+ KIT_CATEGORY_BUS,
27
+ KIT_SAMPLES_BANK,
28
+ KIT_SAMPLE_ALIASES,
26
29
  LAYER_FLOOR,
27
30
  LIBRARY_BANK,
28
31
  LIBRARY_LOOPS,
@@ -34,11 +37,16 @@ import {
34
37
  PAN_LIMIT,
35
38
  PAN_MIN_DISTANCE,
36
39
  SAMPLE_ENVIRONMENTS,
40
+ SDK_LICENSES,
37
41
  SFX_BLOWS,
38
42
  SFX_CATALOG,
39
43
  SFX_CATEGORIES,
40
44
  SFX_IMPACTS,
45
+ SFX_LAYERS,
41
46
  SFX_MATERIALS,
47
+ SFX_TIERS,
48
+ USER_SAMPLES_BANK,
49
+ USER_SOUND_PREFIX,
42
50
  VOICE_GROUPS,
43
51
  audioBenchTextOf,
44
52
  balanceOf,
@@ -74,13 +82,18 @@ import {
74
82
  inlineLoader,
75
83
  isCalibrationUrl,
76
84
  isSilent,
85
+ kitSampleBank,
86
+ kitSampleDefaults,
77
87
  limiterCurve,
78
88
  listenerDistance,
89
+ loadKitSamples,
90
+ loadUserSamples,
79
91
  loopCrossfade,
80
92
  measureCriteria,
81
93
  noiseClassRecipe,
82
94
  onsetIndex,
83
95
  panFor,
96
+ parseSfxName,
84
97
  peakIndex,
85
98
  peakOf,
86
99
  pickTake,
@@ -93,151 +106,20 @@ import {
93
106
  retunePlan,
94
107
  ringSeconds,
95
108
  rmsDb,
109
+ sampleBankFromManifest,
96
110
  sampleCutoff,
97
111
  sampleLength,
98
112
  sampleUrls,
99
113
  sfxState,
114
+ soundSourceOf,
115
+ splitTier,
100
116
  streamFor,
101
117
  streamSeed,
102
118
  tierFor,
103
- unlockContext
104
- } from "./chunk-7TLFY7VO.js";
105
-
106
- // src/manifest.ts
107
- var SDK_LICENSES = ["CC0", "CC-BY"];
108
- var SFX_LAYERS = ["close", "far", "tail_in", "tail_out"];
109
- var SFX_TIERS = { light: 0, medium: 0.34, heavy: 0.67 };
110
- function parseSfxName(name) {
111
- const match = /^(.*?)(?:_(close|far|tail_in|tail_out))?(?:_(\d+))?$/.exec(name);
112
- const id = match?.[1] || name;
113
- const layer = match?.[2] ?? "close";
114
- const take = match?.[3] ? Number(match[3]) : 1;
115
- return { id, layer, take };
116
- }
117
- function splitTier(id) {
118
- const match = /^(.*)_(light|medium|heavy)$/.exec(id);
119
- return match ? { base: match[1], tier: match[2] } : { base: id };
120
- }
121
- var refsOf = (entries, baseUrl) => (entries ?? []).map((entry) => ({ url: `${baseUrl}${entry.file}` }));
122
- function sampleBankFromManifest(manifest, options) {
123
- const baseUrl = options.baseUrl ?? "";
124
- const samples = [];
125
- const tiersOf = /* @__PURE__ */ new Map();
126
- for (const sound of manifest.sounds) {
127
- const { base, tier } = splitTier(sound.id);
128
- if (tier) tiersOf.set(base, [...tiersOf.get(base) ?? [], sound]);
129
- }
130
- const bases = /* @__PURE__ */ new Map();
131
- for (const sound of manifest.sounds) {
132
- if (!splitTier(sound.id).tier) bases.set(sound.id, sound);
133
- }
134
- for (const [base, tiers] of tiersOf) {
135
- if (!bases.has(base)) bases.set(base, { id: base, category: tiers[0]?.category ?? "", layers: { close: tiers[0]?.layers.close ?? [] } });
136
- }
137
- for (const sound of bases.values()) {
138
- const numbers = options.sounds?.[sound.id] ?? options.defaults?.(sound);
139
- const close = refsOf(sound.layers.close, baseUrl);
140
- if (!numbers || close.length === 0) continue;
141
- const tiers = (tiersOf.get(sound.id) ?? []).map((tier) => {
142
- const name = splitTier(tier.id).tier;
143
- const tierFar = refsOf(tier.layers.far, baseUrl);
144
- return { name, from: SFX_TIERS[name] ?? 0, close: refsOf(tier.layers.close, baseUrl), ...tierFar.length > 0 ? { far: tierFar } : {} };
145
- }).sort((a, b) => a.from - b.from);
146
- const far = refsOf(sound.layers.far, baseUrl);
147
- const indoor = refsOf(sound.layers.tail_in, baseUrl);
148
- const outdoor = refsOf(sound.layers.tail_out, baseUrl);
149
- const files = [sound, ...tiersOf.get(sound.id) ?? []].flatMap((entry) => Object.values(entry.layers).flatMap((entries) => entries ?? []));
150
- samples.push({
151
- id: sound.id,
152
- bus: numbers.bus,
153
- close,
154
- ...far.length > 0 ? { far } : {},
155
- ...tiers.length > 0 ? { tiers } : {},
156
- ...numbers.crossover ? { crossover: numbers.crossover } : {},
157
- ...indoor.length > 0 || outdoor.length > 0 ? { tail: { ...indoor.length > 0 ? { indoor } : {}, ...outdoor.length > 0 ? { outdoor } : {}, ...numbers.tailGain === void 0 ? {} : { gain: numbers.tailGain } } } : {},
158
- ...numbers.pitch === void 0 ? {} : { pitch: numbers.pitch },
159
- ...numbers.gain === void 0 ? {} : { gain: numbers.gain },
160
- ...numbers.falloff ? { falloff: numbers.falloff } : {},
161
- ...numbers.cutoffK === void 0 ? {} : { cutoffK: numbers.cutoffK },
162
- ...numbers.group ? { group: numbers.group } : {},
163
- ...numbers.priority === void 0 ? {} : { priority: numbers.priority },
164
- ...numbers.fallback ? { fallback: numbers.fallback } : {},
165
- sources: files.map((file) => `${file.file}: ${file.source} ${file.author} ${file.license}`)
166
- });
167
- }
168
- return { id: options.id, samples };
169
- }
170
-
171
- // src/kit-samples.ts
172
- var KIT_CATEGORY_BUS = {
173
- armas: "weapons",
174
- impactos: "world",
175
- "explosoes-fogo": "world",
176
- personagem: "world",
177
- veiculos: "world",
178
- "itens-portas": "world",
179
- ambiente: "ambience"
180
- };
181
- var VOICE_IDS = /^(player_(hurt|death|effort|breath)|scream|zombie_)/;
182
- var KIT_SAMPLE_ALIASES = {
183
- // a house door: the latch giving, the hinge, the leaf meeting the frame, a locked one shaken; a drawer on its runners
184
- latch: "metal_latch",
185
- creak_wood: "door_creak",
186
- shut_wood: "door_wood_shut",
187
- rattle: "door_locked_rattle",
188
- // a drawer stays on its recipe: the recorded runs (1 to 1.9 s) outlast a drawer's pull
189
- // an item taken in the hand (game-destruction-three grab_* keys)
190
- grab_hard: "item_pickup_generic",
191
- grab_soft: "item_pickup_leather"
192
- };
193
- function kitSampleDefaults(sound) {
194
- const bus = VOICE_IDS.test(sound.id) ? "voices" : KIT_CATEGORY_BUS[sound.category];
195
- if (!bus) return void 0;
196
- return { bus, pitch: sound.category === "ambiente" || /_loop/.test(sound.id) ? 0 : 0.04 };
197
- }
198
- function withAliases(manifest, aliases) {
199
- const byId = new Map(manifest.sounds.map((sound) => [sound.id, sound]));
200
- const extra = [];
201
- for (const [alias, target] of Object.entries(aliases)) {
202
- const sound = byId.get(target);
203
- if (sound && !byId.has(alias)) extra.push({ ...sound, id: alias });
204
- }
205
- return { ...manifest, sounds: [...manifest.sounds, ...extra] };
206
- }
207
- function kitSampleBank(manifest, options = {}) {
208
- return sampleBankFromManifest(withAliases(manifest, options.aliases ?? KIT_SAMPLE_ALIASES), {
209
- id: options.id ?? "kit_samples",
210
- baseUrl: options.baseUrl ?? "",
211
- defaults: kitSampleDefaults
212
- });
213
- }
214
- var isFileUrl = (url) => {
215
- const page = globalThis.location?.href;
216
- try {
217
- return new URL(url, page).protocol === "file:";
218
- } catch {
219
- return false;
220
- }
221
- };
222
- var fetchJson = async (url) => {
223
- if (isFileUrl(url)) throw new Error(`${url}: file:// is not fetched`);
224
- const response = await fetch(url);
225
- if (!response.ok) throw new Error(`${url}: ${response.status}`);
226
- return await response.json();
227
- };
228
- async function loadKitSamples(engine, options = {}) {
229
- const baseUrl = options.baseUrl ?? "";
230
- let manifest;
231
- try {
232
- manifest = await (options.fetchManifest ?? fetchJson)(`${baseUrl}manifest.json`);
233
- } catch {
234
- return null;
235
- }
236
- const bank = kitSampleBank(manifest, options);
237
- engine.register(bank);
238
- if (options.preload && engine.loadSamples) void engine.loadSamples(options.preload).catch(() => void 0);
239
- return bank;
240
- }
119
+ unlockContext,
120
+ userSampleBank,
121
+ withAliases
122
+ } from "./chunk-KBTUANNG.js";
241
123
 
242
124
  // src/recipes/scene.ts
243
125
  var ATTACK = 2e-3;
@@ -316,6 +198,82 @@ function sceneRecipe(id, layers, line, options = {}) {
316
198
  };
317
199
  }
318
200
 
201
+ // src/library/cabin.ts
202
+ var CABIN_SOUNDS = [
203
+ {
204
+ id: "blinker_tick",
205
+ bus: "world",
206
+ duration: 0.03,
207
+ layers: [
208
+ // the relay: a click of bright noise and a short low knock
209
+ { source: { kind: "noise", offset: "random" }, filters: { mode: "serial", bank: [{ type: "highpass", frequency: { set: 2600 } }] }, envelope: [[0, 0.22, "set"], [0.025, 1e-4, "exp", "fixed"]] },
210
+ { source: { kind: "osc", wave: "triangle", frequency: { set: 180 } }, envelope: [[0, 0.12, "set"], [0.03, 1e-4, "exp", "fixed"]] }
211
+ ],
212
+ falloff: { model: "none" }
213
+ },
214
+ {
215
+ id: "starter_crank",
216
+ bus: "world",
217
+ duration: 0.9,
218
+ layers: [
219
+ // the starter motor turning the engine over: low noise chopped at the compression strokes
220
+ {
221
+ source: { kind: "noise", offset: "random" },
222
+ filters: { mode: "serial", bank: [{ type: "lowpass", frequency: { set: 420 } }] },
223
+ modulators: [{ target: "gain", wave: "square", rate: 11, depth: 0.08, base: 0.1 }],
224
+ envelope: [[0, 1e-4, "set", "fixed"], [0.05, 0.25, "linear"], [0.8, 0.22, "set"], [0.9, 1e-4, "exp", "fixed"]]
225
+ },
226
+ { source: { kind: "osc", wave: "sawtooth", frequency: { set: 95, to: 120, curve: "linear", over: 0.9 } }, filters: { mode: "serial", bank: [{ type: "lowpass", frequency: { set: 300 } }] }, envelope: [[0, 0.04, "set"], [0.9, 1e-4, "exp", "fixed"]] }
227
+ ],
228
+ falloff: { model: "none" }
229
+ },
230
+ {
231
+ id: "car_alarm",
232
+ bus: "world",
233
+ order: "siren",
234
+ duration: 3,
235
+ tail: 0.1,
236
+ layers: [
237
+ // the whoop of a car alarm: a square swept up and down three times a second
238
+ {
239
+ source: { kind: "osc", wave: "square", frequency: { set: 1100 } },
240
+ modulators: [{ target: "frequency", wave: "triangle", rate: 3, depth: 420 }],
241
+ filters: { mode: "serial", bank: [{ type: "lowpass", frequency: { set: 2600 } }] },
242
+ envelope: [[0, 1e-4, "set", "fixed"], [0.05, 0.05, "linear"], [2.9, 0.05, "set"], [3, 1e-4, "exp", "fixed"]]
243
+ }
244
+ ],
245
+ falloff: { model: "none" }
246
+ },
247
+ {
248
+ id: "alarm_chirp",
249
+ bus: "world",
250
+ duration: 0.1,
251
+ layers: [{ source: { kind: "osc", wave: "square", frequency: { set: 2300 } }, repeat: { count: 2, spacing: 0.16 }, envelope: [[0, 0.05, "set"], [0.09, 1e-4, "exp", "fixed"]] }],
252
+ falloff: { model: "none" }
253
+ },
254
+ {
255
+ id: "wiper_swish",
256
+ bus: "world",
257
+ duration: 0.45,
258
+ layers: [
259
+ {
260
+ source: { kind: "noise", offset: "random" },
261
+ filters: { mode: "serial", bank: [{ type: "bandpass", frequency: { set: 700, to: 1100, curve: "linear", over: 0.45 }, q: 1.2 }] },
262
+ envelope: [[0, 1e-4, "set", "fixed"], [0.2, 0.06, "linear"], [0.45, 1e-4, "exp", "fixed"]]
263
+ }
264
+ ],
265
+ falloff: { model: "none" }
266
+ },
267
+ {
268
+ id: "seatbelt_chime",
269
+ bus: "world",
270
+ duration: 0.5,
271
+ layers: [{ source: { kind: "osc", wave: "sine", frequency: { set: 880 } }, repeat: { count: 3, spacing: 0.7 }, envelope: [[0, 0.06, "set"], [0.5, 1e-4, "exp", "fixed"]] }],
272
+ falloff: { model: "none" }
273
+ }
274
+ ];
275
+ var CABIN_BANK = { id: "vehicle_cabin", sounds: CABIN_SOUNDS, loops: [] };
276
+
319
277
  // src/recipes/foley.ts
320
278
  var FOLEY_FALLOFF = {
321
279
  model: "inverse_square",
@@ -1147,6 +1105,8 @@ export {
1147
1105
  BUILD_ORDERS,
1148
1106
  BUS_IDS,
1149
1107
  BUS_PRIORITY,
1108
+ CABIN_BANK,
1109
+ CABIN_SOUNDS,
1150
1110
  CALIBRATION_ID,
1151
1111
  CALIBRATION_LOOP_ID,
1152
1112
  CALIBRATION_LOOP_SOUND,
@@ -1172,6 +1132,7 @@ export {
1172
1132
  GAME_SFX_FALLBACK,
1173
1133
  ITEM_FOLEY,
1174
1134
  KIT_CATEGORY_BUS,
1135
+ KIT_SAMPLES_BANK,
1175
1136
  KIT_SAMPLE_ALIASES,
1176
1137
  LAYER_FLOOR,
1177
1138
  LEAF_FOLEY,
@@ -1195,6 +1156,8 @@ export {
1195
1156
  SFX_LAYERS,
1196
1157
  SFX_MATERIALS,
1197
1158
  SFX_TIERS,
1159
+ USER_SAMPLES_BANK,
1160
+ USER_SOUND_PREFIX,
1198
1161
  VOICE_GROUPS,
1199
1162
  audioBenchTextOf,
1200
1163
  balanceOf,
@@ -1236,6 +1199,7 @@ export {
1236
1199
  limiterCurve,
1237
1200
  listenerDistance,
1238
1201
  loadKitSamples,
1202
+ loadUserSamples,
1239
1203
  loopCrossfade,
1240
1204
  measureCriteria,
1241
1205
  noiseClassRecipe,
@@ -1264,11 +1228,13 @@ export {
1264
1228
  sceneTone,
1265
1229
  sceneVoice,
1266
1230
  sfxState,
1231
+ soundSourceOf,
1267
1232
  splitTier,
1268
1233
  streamFor,
1269
1234
  streamSeed,
1270
1235
  tierFor,
1271
1236
  unlockContext,
1237
+ userSampleBank,
1272
1238
  withAliases
1273
1239
  };
1274
1240
  //# sourceMappingURL=index.js.map