star-audio 0.1.0 → 0.1.2

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/PROMPT.md ADDED
@@ -0,0 +1,119 @@
1
+ **Installation**
2
+
3
+ First, add the package to your project:
4
+ ` ` `bash
5
+ yarn add star-audio
6
+ ` ` `
7
+
8
+ ### Star Audio SDK
9
+
10
+ **Mobile-first, bulletproof audio for web games.** Works on iOS/Android out of the box. Missing files won't crash your game.
11
+
12
+ **Import:**
13
+ ` ` `javascript
14
+ import createAudio from 'star-audio';
15
+ const audio = createAudio();
16
+ ` ` `
17
+
18
+ **CRITICAL:** Import in JavaScript - don't add `<script src="/star-sdk/audio.js">` tags.
19
+
20
+ **Why Star Audio?**
21
+ - ✅ **Mobile-first** - Works on iOS/Android, handles audio unlock automatically, plays even in silent mode
22
+ - ✅ **Never throws** - Missing audio files? Game keeps running with clear warnings
23
+ - ✅ **Zero-config** - Works on first play, no setup needed
24
+ - ✅ **No try/catch needed** - Fire-and-forget API, perfect for AI-generated games
25
+
26
+ ---
27
+
28
+ **Quick Start:**
29
+
30
+ ` ` `javascript
31
+ const audio = createAudio();
32
+
33
+ // CRITICAL: Preload presets before playing them
34
+ // You can set per-sound volumes in preload
35
+ audio.preload({
36
+ jump: { synth: 'jump', volume: 0.5 }, // Quieter jump
37
+ shoot: { synth: 'shoot', volume: 0.8 }, // Loud shoot
38
+ coin: { synth: 'coin', volume: 0.6 },
39
+ explosion: { synth: 'explosion', volume: 1.0 }
40
+ });
41
+
42
+ // Now play them - volumes are already set
43
+ audio.play('jump');
44
+ audio.play('shoot');
45
+ ` ` `
46
+
47
+ **ONLY THESE 17 PRESETS EXIST - DO NOT INVENT NAMES:**
48
+ - UI: `beep`, `click`, `select`, `error`, `success`
49
+ - Actions: `jump`, `swoosh`, `shoot`, `laser`, `explosion`
50
+ - Combat: `hit`, `hurt`
51
+ - Collection: `coin`, `pickup`, `bonus`, `unlock`, `powerup`
52
+
53
+ **If you need a sound that's not in this list, use custom synth or generate audio.**
54
+
55
+ **CRITICAL:** Preload all presets before use. Set volumes in preload:
56
+ ` ` `javascript
57
+ audio.preload({
58
+ jump: { synth: 'jump', volume: 0.5 }, // With custom volume
59
+ coin: 'coin', // Default volume
60
+ explosion: 'explosion' // For crashes/impacts
61
+ });
62
+ ` ` `
63
+
64
+ ---
65
+
66
+ **Custom synth (advanced):**
67
+
68
+ ` ` `javascript
69
+ audio.preload({
70
+ 'sfx.charge': {
71
+ waveform: 'triangle',
72
+ frequency: [200, 300, 450, 650, 900], // Rising charge-up
73
+ duration: 0.40,
74
+ volume: 0.38
75
+ }
76
+ });
77
+ ` ` `
78
+
79
+ **Make sounds feel good:**
80
+ - **Use frequency arrays** - Sweeps/arpeggios are more satisfying than single tones
81
+ - **Rising = positive** - Ascending pitches for rewards (coin, jump, powerup)
82
+ - **Descending = impact** - Falling pitches for actions (shoot, hurt, explosion)
83
+ - **More notes = richer** - 3-6 frequencies sound fuller than 1-2
84
+ - **Musical intervals** - Use harmonious ratios (octaves, fifths, major chords)
85
+
86
+ **Waveform choice:**
87
+ - `sine` - Pure, pleasant (UI, bells, rewards)
88
+ - `triangle` - Warm, full (jumps, explosions, success)
89
+ - `square` - Retro, characterful (powerups, beeps, chiptune)
90
+ - `sawtooth` - Harsh, aggressive (lasers, damage, errors)
91
+
92
+ **Frequency guide:**
93
+ - High (800-2000 Hz): Bright, attention-grabbing (UI, coins)
94
+ - Mid (200-800 Hz): Game actions (jumps, shoots)
95
+ - Low (30-200 Hz): Impacts, bass (explosions, rumbles)
96
+ - Arrays: 3-4 notes for melodies, 6+ for noise-like effects
97
+
98
+ ---
99
+
100
+ **Audio files:**
101
+
102
+ ` ` `javascript
103
+ audio.preload({
104
+ 'sfx.boom': 'assets/boom.mp3',
105
+ 'bgm.theme': 'assets/music.mp3'
106
+ });
107
+ audio.play('sfx.boom');
108
+ audio.music.crossfadeTo('bgm.theme', { duration: 1.5 });
109
+ ` ` `
110
+
111
+ ---
112
+
113
+ **Controls:**
114
+
115
+ ` ` `javascript
116
+ audio.setMusicVolume(0.5);
117
+ audio.setSfxVolume(0.8);
118
+ audio.toggleMute();
119
+ ` ` `
package/dist/index.js CHANGED
@@ -2799,6 +2799,11 @@ var StarAudioImpl = class {
2799
2799
  this.music.fadeTo = this.music.crossfadeTo;
2800
2800
  this.music.switchTo = this.music.crossfadeTo;
2801
2801
  this.musicFadeTo = this.music.crossfadeTo;
2802
+ for (const presetName of Object.keys(PRESET_DEFINITIONS)) {
2803
+ this._loadProceduralSound(presetName, presetName).catch((err) => {
2804
+ console.warn(`[StarAudio] Failed to auto-preload preset ${presetName}:`, err);
2805
+ });
2806
+ }
2802
2807
  }
2803
2808
  get state() {
2804
2809
  return this._state;
@@ -2903,11 +2908,9 @@ var StarAudioImpl = class {
2903
2908
  // --- Playback ---
2904
2909
  play(id, opts = {}) {
2905
2910
  if (isPreset(id) && !this._sounds.has(id)) {
2906
- console.info(`[StarAudio] Auto-generating preset: ${id}`);
2907
2911
  this._loadProceduralSound(id, id).catch((err) => {
2908
2912
  console.error(`[StarAudio] Failed to generate preset ${id}:`, err);
2909
2913
  });
2910
- console.warn(`[StarAudio] Preset ${id} is generating, try again in a moment`);
2911
2914
  return null;
2912
2915
  }
2913
2916
  if ((opts.src || opts.url) && !this._sounds.has(id)) {