Audio¶
Audio entrainment pipeline: adaptive session engine, entrainment verification scoring (EVS), SSGF-based geometry-to-audio mapping, and per-user profile persistence.
The package facade is the stable import path for application code:
from sc_neurocore.audio import (
AdaptiveAudioEngine,
EVSEngine,
EVSSnapshot,
SSGFEngine,
UserProfile,
)
tests/test_audio_package_api.py locks the package-level exports and verifies
that an imported SSGFEngine can advance one step and produce the documented
audio mapping keys.
Adaptive Engine¶
AdaptiveAudioEngine is the public closed-loop controller for adaptive audio
sessions. Each EVSSnapshot advances one controller tick, updates the session
phase, adjusts the SSGFEngine configuration when feedback trends change, runs
one geometry step, and returns the current audio mapping.
The controller exposes three stable session phases:
discovery: sweeps the target frequency and keeps geometry parameters in an exploratory range.lock_on: responds to EVS decline or improvement by adjusting geometry coupling and learning rate.deepening: increases field pressure and geometry coupling while reducing the learning rate for stability.
AdaptiveSessionReport summarises total ticks, EVS statistics, verified
percentage, phase durations, adaptation count, and the final audio mapping in a
JSON-compatible dictionary.
sc_neurocore.audio.adaptive_engine
¶
Closed-loop SSGF and EVS adaptive audio controller.
Orchestrates a three-phase adaptive audio session:
DISCOVERY (0-2 min) -- gentle frequency sweep, find resonance
LOCK_ON (2-10 min) -- lock on optimal frequency, responsive
DEEPENING (10+ min) -- push toward theurgic coherence
Each tick receives an EVSSnapshot and returns adjusted audio parameters by modulating the SSGFEngine configuration (sigma_g, lr_z, field_pressure).
SessionPhase
¶
Bases: str, Enum
Adaptive audio control phase for a closed-loop session.
Source code in src/sc_neurocore/audio/adaptive_engine.py
| Python | |
|---|---|
41 42 43 44 45 46 | |
AdaptiveSessionReport
dataclass
¶
Summary of a completed adaptive audio session.
Source code in src/sc_neurocore/audio/adaptive_engine.py
| Python | |
|---|---|
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | |
to_dict()
¶
Return a JSON-compatible summary of the adaptive session.
Source code in src/sc_neurocore/audio/adaptive_engine.py
| Python | |
|---|---|
85 86 87 88 89 90 91 92 93 94 95 96 | |
AdaptiveAudioEngine
¶
Closed-loop adaptive audio controller coupling SSGF with EVS.
Parameters¶
ssgf : SSGFEngine The geometry solver producing audio mappings. evs : EVSEngine The entrainment verification scorer. profile : UserProfile, optional User preferences for chronotype-aware adaptation.
Source code in src/sc_neurocore/audio/adaptive_engine.py
| Python | |
|---|---|
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 | |
current_phase
property
¶
Return the active adaptive-control phase.
tick
property
¶
Return the number of processed EVS updates.
on_evs_update(snapshot)
¶
Process one EVS update and return adapted audio parameters.
This is the main feedback loop entry point. Call it each time a new EVSSnapshot is available (~every 500 ms).
Returns¶
dict Audio parameters from SSGF, possibly adjusted by adaptation.
Source code in src/sc_neurocore/audio/adaptive_engine.py
| Python | |
|---|---|
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 | |
get_session_report()
¶
Generate summary report of the current session.
Source code in src/sc_neurocore/audio/adaptive_engine.py
| Python | |
|---|---|
344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 | |
reset()
¶
Reset session state (does not reset SSGF or EVS).
Source code in src/sc_neurocore/audio/adaptive_engine.py
| Python | |
|---|---|
387 388 389 390 391 392 393 394 395 396 397 | |
EVS Engine¶
EVSEngine verifies whether an audio session is tracking its target band by
combining target-band power increase, spectral peak alignment, band dominance,
and recent score stability. Focused EVS contract tests cover baseline gating,
finite target validation, tiny-window fail-closed FFT behaviour, zero-baseline
relative-increase handling, score-history copying, snapshot serialisation, and
reset semantics.
sc_neurocore.audio.evs_engine
¶
Entrainment Verification Score engine for adaptive audio.
Real-time composite score (0-100) proving that CCW audio entrainment is working on a per-session basis. Measures the correlation between the target brainwave frequency and actual EEG spectral power via FFT-based band analysis.
Score formula (0-100): 40% relative_increase -- target band power vs baseline 30% peak_alignment -- spectral peak proximity to target Hz 20% band_dominance -- target band / total power 10% temporal_consistency -- inverse of recent score variance
Verified = (score >= 50) AND (confidence >= 0.6)
EVSConfig
dataclass
¶
Configuration for FFT-based entrainment scoring.
Attributes¶
sample_rate: EEG sample rate in hertz. fft_window: Number of samples retained in the ring buffer for FFT scoring. baseline_duration_s: Baseline collection duration in seconds. update_interval_samples: Nominal sample interval between external EVS updates.
Source code in src/sc_neurocore/audio/evs_engine.py
| Python | |
|---|---|
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | |
EVSSnapshot
dataclass
¶
Single-tick entrainment verification observation.
Attributes¶
evs_score:
Composite entrainment score in the inclusive range 0 to 100.
relative_increase:
Target-band power increase relative to baseline.
peak_alignment:
Alignment between the spectral peak and target frequency.
band_dominance:
Fraction of total spectral power in the target band.
temporal_consistency:
Stability score computed from recent EVS values.
is_verified:
Whether score and confidence clear the verification threshold.
confidence:
Confidence score derived from the number of scoring updates.
target_hz:
Target entrainment frequency in hertz.
peak_hz:
Dominant measured frequency in hertz.
band_powers:
Per-band FFT power estimates.
timestamp:
Snapshot creation time from time.time().
Source code in src/sc_neurocore/audio/evs_engine.py
| Python | |
|---|---|
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | |
to_dict()
¶
Serialise the snapshot into JSON-compatible telemetry.
Returns¶
dict[str, Any] Rounded score components, verification flags, target and peak frequencies, per-band powers, and timestamp.
Source code in src/sc_neurocore/audio/evs_engine.py
| Python | |
|---|---|
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | |
EVSEngine
¶
FFT-based Entrainment Verification Score engine.
Workflow¶
start_baseline()-- begin collecting baseline EEGadd_sample(voltage)-- feed raw EEG samples one at a time- After baseline_duration_s, baseline finalises automatically
set_target(hz)-- set the entrainment target frequencycompute()returnsEVSSnapshotevery update_interval_samples
Source code in src/sc_neurocore/audio/evs_engine.py
| Python | |
|---|---|
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 | |
baseline_done
property
¶
Whether baseline EEG collection has been finalised.
score_history
property
¶
Return a copy of accumulated EVS scores.
__init__(cfg=None)
¶
Initialise the EVS ring buffer and scoring state.
Parameters¶
cfg:
Optional FFT and baseline configuration. Defaults to EVSConfig
when omitted.
Source code in src/sc_neurocore/audio/evs_engine.py
| Python | |
|---|---|
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 | |
start_baseline()
¶
Begin baseline EEG collection.
Source code in src/sc_neurocore/audio/evs_engine.py
| Python | |
|---|---|
199 200 201 202 203 204 205 | |
add_sample(voltage)
¶
Feed one raw EEG voltage sample.
Source code in src/sc_neurocore/audio/evs_engine.py
| Python | |
|---|---|
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 | |
set_target(hz)
¶
Set the entrainment target frequency.
Parameters¶
hz: Finite target frequency in hertz. Values outside the supported EEG range are clipped to 0.5-45.0 Hz.
Raises¶
ValueError
If hz is not finite.
Source code in src/sc_neurocore/audio/evs_engine.py
| Python | |
|---|---|
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 | |
compute()
¶
Compute current EVS snapshot.
Returns¶
EVSSnapshot | None
Current EVS telemetry, or None until baseline collection is
complete and enough samples are available.
Source code in src/sc_neurocore/audio/evs_engine.py
| Python | |
|---|---|
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 | |
reset()
¶
Clear buffers, baseline state, and score history.
Source code in src/sc_neurocore/audio/evs_engine.py
| Python | |
|---|---|
387 388 389 390 391 392 393 394 395 396 397 | |
SSGF Engine¶
sc_neurocore.audio.ssgf_engine
¶
SSGF geometry-to-audio solver.
Pure-NumPy solver that couples Kuramoto phase oscillators with a learned geometry matrix, producing real-time audio-mapping observables for binaural frequency, pulse rate, spatial angle, intensity, and spectral connectivity.
The implementation is self-contained and intentionally dependency-light: it uses NumPy plus the SC-NeuroCore parameter table so the adaptive audio controller can run without JAX, PyTorch, or topology packages.
SSGFConfig
dataclass
¶
Configuration for the SSGF geometry-coupled oscillator engine.
Attributes¶
N: Number of oscillators in the Kuramoto field. z_dim: Length of the latent geometry vector decoded into the symmetric coupling matrix. lr_z: Gradient-descent step size for the latent geometry vector. sigma_g: Scale applied to geometry-derived phase coupling. micro_steps: Number of Kuramoto integration steps per outer geometry update. dt: Integration timestep in seconds. noise: Standard deviation of phase noise injected during each micro-step. K_base: Baseline Kuramoto coupling retained for compatibility with profile tuning surfaces. K_alpha: Adaptive coupling multiplier retained for compatibility with profile tuning surfaces. field_pressure: Cosine field pressure applied as a global steering term. seed: Deterministic NumPy random seed for reproducible initial conditions.
Source code in src/sc_neurocore/audio/ssgf_engine.py
| Python | |
|---|---|
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | |
SSGFEngine
¶
Lightweight SSGF geometry-coupled Kuramoto solver.
Maintains a latent vector z whose decoded geometry matrix W(t) feeds back into the micro-cycle, steering oscillators toward higher global coherence R. Audio-mapping observables are derived from the resulting phase dynamics and spectral properties of W.
Source code in src/sc_neurocore/audio/ssgf_engine.py
| Python | |
|---|---|
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 | |
__init__(cfg=None)
¶
Initialise the SSGF state from a deterministic configuration.
Parameters¶
cfg:
Optional engine configuration. When omitted, SSGFConfig supplies
the default oscillator count, integration constants, and seed.
Source code in src/sc_neurocore/audio/ssgf_engine.py
| Python | |
|---|---|
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 | |
outer_step()
¶
Advance one SSGF outer cycle.
The step runs the configured Kuramoto micro-cycle, refreshes the spectral bridge, estimates a finite-difference gradient for the latent geometry vector, and stores the cost history used by state snapshots.
Returns¶
float Composite cost before the latent-vector update.
Source code in src/sc_neurocore/audio/ssgf_engine.py
| Python | |
|---|---|
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 | |
get_audio_mapping()
¶
Derive CCW audio parameters from current SSGF state.
Returns¶
dict[str, float | bool]
JSON-compatible audio mapping containing binaural_hz,
pulse_rate, spatial_angle, intensity, fiedler,
spectral_gap, and theurgic_mode.
Source code in src/sc_neurocore/audio/ssgf_engine.py
| Python | |
|---|---|
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 | |
get_state()
¶
Return a JSON-compatible snapshot of the current SSGF state.
Returns¶
dict[str, Any] Snapshot containing step counters, coherence, phase vector, geometry statistics, spectral values, latest cost, and the current audio mapping.
Source code in src/sc_neurocore/audio/ssgf_engine.py
| Python | |
|---|---|
325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 | |
User Profile¶
UserProfile persists chronotype defaults, preferred target frequency,
per-band baseline powers, SSGF cost weights, and sensitivity multipliers as a
JSON-compatible profile dictionary. Focused contract tests cover explicit target
overrides, high-EVS target adoption and smoothing, baseline band-power updates,
and package-facade exports.
sc_neurocore.audio.user_profile
¶
User profile: chronotype and session preferences.
Chronotype
¶
Bases: str, Enum
Sleep chronotype model (after Dr. Michael Breus).
Each chronotype has a preferred entrainment frequency range and optimal session timing.
Source code in src/sc_neurocore/audio/user_profile.py
| Python | |
|---|---|
23 24 25 26 27 28 29 30 31 32 33 | |
UserProfile
dataclass
¶
Per-user preference and adaptation model.
Parameters¶
user_id : str Unique user identifier. chronotype : Chronotype Sleep chronotype. baseline_band_powers : dict Resting-state EEG band powers (populated after first baseline). preferred_cost_weights : dict SSGF cost weights tuned to this user. sensitivity_map : dict Per-band sensitivity multipliers (e.g. {"alpha": 1.2}). session_count : int Total completed sessions. preferred_target_hz : float, optional Explicitly set target frequency (overrides chronotype default).
Source code in src/sc_neurocore/audio/user_profile.py
| Python | |
|---|---|
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 | |
__post_init__()
¶
Populate chronotype-derived defaults for omitted profile maps.
Source code in src/sc_neurocore/audio/user_profile.py
| Python | |
|---|---|
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | |
get_best_target_hz()
¶
Return the best entrainment target for this user.
Uses explicit preference if set, otherwise chronotype default.
Source code in src/sc_neurocore/audio/user_profile.py
| Python | |
|---|---|
120 121 122 123 124 125 126 127 | |
update_from_session(avg_evs, peak_evs, best_target_hz=None, band_powers=None)
¶
Update profile after a completed session.
Parameters¶
avg_evs : float Average EVS score over the session. peak_evs : float Peak EVS score. best_target_hz : float, optional If the adaptive engine found a better target, adopt it. band_powers : dict, optional Updated baseline band powers from this session.
Source code in src/sc_neurocore/audio/user_profile.py
| Python | |
|---|---|
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | |
to_dict()
¶
Serialise the profile into JSON-compatible primitive values.
Returns¶
dict[str, Any] Snapshot containing the user identifier, chronotype value, per-band baselines, preferred SSGF cost weights, sensitivity map, completed session count, and optional preferred target frequency.
Source code in src/sc_neurocore/audio/user_profile.py
| Python | |
|---|---|
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 | |
from_dict(data)
classmethod
¶
Build a profile from a dictionary produced by :meth:to_dict.
Parameters¶
data: JSON-compatible profile snapshot. Missing fields fall back to the same defaults used by the dataclass constructor.
Returns¶
UserProfile
Reconstructed user profile with chronotype defaults populated in
__post_init__ when optional maps are absent.
Source code in src/sc_neurocore/audio/user_profile.py
| Python | |
|---|---|
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 | |