@affectively/entrainment-audio 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/CHANGELOG.md ADDED
@@ -0,0 +1,19 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ ## [1.0.0] - 2026-01-25
6
+
7
+ ### Added
8
+
9
+ - Initial release
10
+ - `EntrainmentEngine` - Main coordinator class
11
+ - `BinauralGenerator` - Binaural beats with Oster Curve validation
12
+ - `IsochronicGenerator` - Isochronic tones with envelope shaping
13
+ - `MonauralGenerator` - Monaural beats for speaker playback
14
+ - `BrownNoiseGenerator` - Brown noise (1/f²)
15
+ - `PinkNoiseGenerator` - Pink noise (1/f)
16
+ - Brainwave presets: Delta, Theta, Alpha, Low/Mid/High Beta, Gamma
17
+ - Progressive frequency ramping
18
+ - Safety warnings system
19
+ - Full TypeScript support
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 AFFECTIVELY
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 ADDED
@@ -0,0 +1,176 @@
1
+ # @affectively/entrainment-audio
2
+
3
+ Brainwave entrainment audio generators using the Web Audio API. Generate binaural beats, isochronic tones, monaural beats, and colored noise for meditation, focus, and relaxation applications.
4
+
5
+ ## Features
6
+
7
+ - **Binaural Beats** - Stereo-separated tones that create perceived frequencies in the brain (requires headphones)
8
+ - **Isochronic Tones** - Pulsed tones with 100% modulation depth for speaker playback
9
+ - **Monaural Beats** - Physical interference patterns created by mixing two frequencies
10
+ - **Brown Noise** - Deep, rumbling colored noise (1/f²) for masking and relaxation
11
+ - **Pink Noise** - Balanced colored noise (1/f) like steady rain
12
+ - **Preset Library** - Science-based presets for Delta, Theta, Alpha, Beta, and Gamma states
13
+ - **Progressive Ramping** - Gradual frequency transitions for smoother entrainment
14
+ - **Safety Warnings** - Built-in safety protocols and user warnings
15
+
16
+ ## Installation
17
+
18
+ ```bash
19
+ npm install @affectively/entrainment-audio
20
+ # or
21
+ bun add @affectively/entrainment-audio
22
+ # or
23
+ yarn add @affectively/entrainment-audio
24
+ ```
25
+
26
+ ## Quick Start
27
+
28
+ ```typescript
29
+ import { EntrainmentEngine, BRAINWAVE_PRESETS } from '@affectively/entrainment-audio';
30
+
31
+ // Create engine instance
32
+ const engine = new EntrainmentEngine();
33
+
34
+ // Initialize (must be called from user gesture due to browser autoplay policy)
35
+ await engine.initialize();
36
+
37
+ // Start alpha wave entrainment (10 Hz) with brown noise
38
+ await engine.start({
39
+ preset: 'alpha',
40
+ manualMode: false,
41
+ generators: {
42
+ binaural: {
43
+ enabled: true,
44
+ volume: 0.5,
45
+ type: 'binaural',
46
+ carrierFrequency: 450, // Oster Curve: 400-500 Hz
47
+ beatFrequency: 10,
48
+ },
49
+ isochronic: {
50
+ enabled: false,
51
+ volume: 0.5,
52
+ type: 'isochronic',
53
+ carrierFrequency: 200,
54
+ beatFrequency: 10,
55
+ dutyCycle: 0.5,
56
+ attackTime: 5,
57
+ releaseTime: 5,
58
+ },
59
+ brownNoise: {
60
+ enabled: true,
61
+ volume: 0.15,
62
+ type: 'brown-noise',
63
+ filterStrength: 0.02,
64
+ },
65
+ },
66
+ masterVolume: 0.8,
67
+ progressiveRamping: true,
68
+ rampingDuration: 30,
69
+ mode: 'headphones',
70
+ });
71
+
72
+ // Stop entrainment
73
+ engine.stop();
74
+
75
+ // Cleanup when done
76
+ engine.cleanup();
77
+ ```
78
+
79
+ ## Brainwave Presets
80
+
81
+ | Preset | Frequency | Use Case |
82
+ |--------|-----------|----------|
83
+ | `delta` | 0.5-4 Hz | Deep sleep, restoration |
84
+ | `theta` | 4-8 Hz | Meditation, creativity |
85
+ | `alpha` | 8-12 Hz | Relaxed alertness, flow state |
86
+ | `low-beta` | 12-15 Hz | Calm focus (SMR) |
87
+ | `mid-beta` | 15-20 Hz | Active focus, problem-solving |
88
+ | `high-beta` | 20-30 Hz | High energy, alertness |
89
+ | `gamma` | 30-100 Hz | Peak performance, insight |
90
+
91
+ ## Using Individual Generators
92
+
93
+ ```typescript
94
+ import { BinauralGenerator, IsochronicGenerator, BrownNoiseGenerator } from '@affectively/entrainment-audio';
95
+
96
+ // Create AudioContext
97
+ const ctx = new AudioContext();
98
+ const masterGain = ctx.createGain();
99
+ masterGain.connect(ctx.destination);
100
+
101
+ // Binaural beats (requires headphones)
102
+ const binaural = new BinauralGenerator(ctx);
103
+ binaural.start({
104
+ enabled: true,
105
+ volume: 0.5,
106
+ type: 'binaural',
107
+ carrierFrequency: 450,
108
+ beatFrequency: 10, // Alpha wave
109
+ }, masterGain);
110
+
111
+ // Stop after use
112
+ binaural.stop();
113
+ ```
114
+
115
+ ## Safety Warnings
116
+
117
+ ```typescript
118
+ import { getSafetyWarnings, getAllSafetyWarnings } from '@affectively/entrainment-audio';
119
+
120
+ // Get warnings for current configuration
121
+ const warnings = getSafetyWarnings({
122
+ hasVisualizer: true,
123
+ currentPreset: 'alpha',
124
+ });
125
+
126
+ // All warnings include:
127
+ // - Epilepsy warning (for visual effects)
128
+ // - Driving warning (for low-frequency presets)
129
+ // - Pacemaker warning
130
+ // - Mental health considerations
131
+ // - Visual strobing warning
132
+ ```
133
+
134
+ ## The Oster Curve
135
+
136
+ Binaural beats work best with carrier frequencies between 400-500 Hz (the "Oster Curve"). The library validates this automatically:
137
+
138
+ ```typescript
139
+ import { validateOsterCurve, getRecommendedCarrierFrequency } from '@affectively/entrainment-audio';
140
+
141
+ validateOsterCurve(450); // true
142
+ validateOsterCurve(200); // false
143
+
144
+ const recommended = getRecommendedCarrierFrequency(); // 450 Hz
145
+ ```
146
+
147
+ ## API Reference
148
+
149
+ ### EntrainmentEngine
150
+
151
+ Main coordinator class that manages all generators.
152
+
153
+ - `initialize()` - Initialize AudioContext (call from user gesture)
154
+ - `start(config)` - Start entrainment with configuration
155
+ - `stop()` - Stop all generators
156
+ - `pause()` - Pause playback
157
+ - `resumePlayback()` - Resume from pause
158
+ - `updateConfig(config)` - Update parameters in real-time
159
+ - `getSessionInfo()` - Get current session state
160
+ - `cleanup()` - Disconnect and close AudioContext
161
+
162
+ ### Individual Generators
163
+
164
+ - `BinauralGenerator` - Binaural beat generation
165
+ - `IsochronicGenerator` - Isochronic tone generation
166
+ - `MonauralGenerator` - Monaural beat generation
167
+ - `BrownNoiseGenerator` - Brown noise generation
168
+ - `PinkNoiseGenerator` - Pink noise generation
169
+
170
+ ## Browser Support
171
+
172
+ Requires Web Audio API support (all modern browsers).
173
+
174
+ ## License
175
+
176
+ MIT © AFFECTIVELY