2Btainment commited on
Commit
607c4f0
·
verified ·
1 Parent(s): 29c3be9

v0.6: Arrangement Studio, Demucs htdemucs (CPU), bucket persistence

Browse files
Dockerfile CHANGED
@@ -1,12 +1,26 @@
1
  FROM python:3.11-slim
2
- RUN apt-get update && apt-get install -y --no-install-recommends libsndfile1 && rm -rf /var/lib/apt/lists/*
 
3
  RUN useradd -m -u 1000 user
4
  USER user
5
  ENV HOME=/home/user PATH=/home/user/.local/bin:$PATH \
6
- ABSOLUTION_DATA_DIR=/tmp/omega_data ABSOLUTION_MAX_UPLOAD_MIB=200
 
 
 
7
  WORKDIR /home/user/app
 
 
 
 
 
 
 
 
 
 
8
  COPY --chown=user pyproject.toml requirements.txt ./
9
  COPY --chown=user app ./app
10
- RUN pip install --no-cache-dir --user .
11
  EXPOSE 7860
12
  CMD ["uvicorn", "app.server:app", "--host", "0.0.0.0", "--port", "7860"]
 
1
  FROM python:3.11-slim
2
+ RUN apt-get update && apt-get install -y --no-install-recommends libsndfile1 ffmpeg git curl ca-certificates \
3
+ && rm -rf /var/lib/apt/lists/*
4
  RUN useradd -m -u 1000 user
5
  USER user
6
  ENV HOME=/home/user PATH=/home/user/.local/bin:$PATH \
7
+ ABSOLUTION_DATA_DIR=/data ABSOLUTION_FALLBACK_DIR=/tmp/omega_data \
8
+ ABSOLUTION_MAX_UPLOAD_MIB=200 \
9
+ ABSOLUTION_DEMUCS_REPO=/home/user/demucs_models ABSOLUTION_DEMUCS_MAX_SECONDS=120 \
10
+ OMP_NUM_THREADS=2 TORCH_HOME=/home/user/.cache/torch
11
  WORKDIR /home/user/app
12
+ # CPU-only PyTorch + Demucs (demucs.api lives on the upstream main branch, not in PyPI 4.0.1)
13
+ RUN pip install --no-cache-dir --user --index-url https://download.pytorch.org/whl/cpu \
14
+ torch==2.1.2 torchaudio==2.1.2 \
15
+ && pip install --no-cache-dir --user "numpy<2" \
16
+ "demucs @ git+https://github.com/adefossez/demucs@2883f3db65617d6d178c6ed10d869dc14e44e59b"
17
+ # Official htdemucs v4 checkpoint, verified by SHA-256 at build time
18
+ RUN mkdir -p $ABSOLUTION_DEMUCS_REPO && cd $ABSOLUTION_DEMUCS_REPO \
19
+ && curl -fsSL -o 955717e8-8726e21a.th https://dl.fbaipublicfiles.com/demucs/hybrid_transformer/955717e8-8726e21a.th \
20
+ && echo "8726e21a993978c7ba086d3872e7608d7d5bfca646ca4aca459ffda844faa8b4 955717e8-8726e21a.th" | sha256sum -c - \
21
+ && printf "models: ['955717e8']\n" > htdemucs.yaml
22
  COPY --chown=user pyproject.toml requirements.txt ./
23
  COPY --chown=user app ./app
24
+ RUN pip install --no-cache-dir --user . "numpy<2"
25
  EXPOSE 7860
26
  CMD ["uvicorn", "app.server:app", "--host", "0.0.0.0", "--port", "7860"]
README.md CHANGED
@@ -6,257 +6,360 @@ colorTo: purple
6
  sdk: docker
7
  app_port: 7860
8
  pinned: false
9
- short_description: Forensic audio lab – HPSS stem separation (FastAPI)
10
  ---
11
 
12
- > **Hugging Face Space note:** Public demo instance. No authentication, shared process-local storage in `/tmp` (not persistent, cleared on restart). Upload limit 200 MiB. Do not upload private/confidential audio.
13
 
14
- # ABSOLUTION Ω — OMNISTEM FORENSIC ENGINE (v0.2.1 · Website)
15
 
16
- A **working local-first vertical slice** of an audio analysis and source decomposition system.
17
- This release provides a redesigned German-language responsive website, FastAPI server, deterministic harmonic/percussive
18
- separation (HPSS), source-aligned residual, audio previews, quality report, and export.
19
 
20
- > **Research honesty:** HPSS is classical DSP, not AI or perfect instrument separation.
21
- > The optional Demucs adapter is neural but needs trusted model weights installed manually.
22
- > Neither method can guarantee perfectly pure or "quantum-exact" source extraction.
23
- > No Zero-Day AI breakthrough is claimed.
24
 
25
- ## Update v0.2.1: No 180-second duration limit
26
-
27
- The 180-second restriction has been removed from decoding, API upload, browser
28
- interface and job polling. HPSS now uses memory-bounded overlapping STFT
29
- chunks and streams three stems directly to disk. Large files can take much
30
- longer and consume substantial storage. Uploaded file size is still limited
31
- to **1024 MiB by default**, configurable with `ABSOLUTION_MAX_UPLOAD_MIB`
32
- (1–4096 MiB). Available disk space and hardware remain practical limits.
33
- The optional neural Demucs adapter still decodes the entire file to memory:
34
- long Demucs jobs may exceed available RAM/VRAM.
35
-
36
- ## Full German audio website
37
-
38
- The web experience includes a guided import flow, a bundled synthetic demo
39
- (`GET /api/v1/demo`), an interactive waveform/seek control, persistent local
40
- project recall, a four-section workspace, a global playback dock, single-stem
41
- masters, batch ZIP export and a provenance dashboard.
42
-
43
- **Run the included site:** `bash start.sh` on macOS/Linux,
44
- `start_windows.bat` on Windows, or `docker compose up --build`.
45
- Then open **http://127.0.0.1:8000**.
46
-
47
- For installation details, user guide, security and actual feature scope,
48
- see **[docs/WEBSITE.md](docs/WEBSITE.md)**.
49
-
50
- **Public @sites deployment is not part of this deliverable.**
51
- The FastAPI server does not have authentication: do not expose it publicly.
52
-
53
- ## Quickstart (Linux / macOS / Windows)
54
-
55
- Requires Python **3.11+**, recommended virtual environment; tested with Python 3.13.
56
 
 
57
  ```bash
58
  python -m venv .venv
59
- # Linux/macOS:
60
- source .venv/bin/activate
61
- # Windows PowerShell:
62
- # .venv\Scripts\Activate.ps1
63
-
64
  python -m pip install -e ".[dev]"
65
- python tools/generate_demo.py
66
  python -m pytest -q
67
  python -m uvicorn app.server:app --host 127.0.0.1 --port 8000
68
  ```
69
 
70
- Open **http://127.0.0.1:8000**. Drag in `demo.wav` or your own audio.
71
- Click **RUN SEPARATION**, then play/download each stem and **EXPORT STEMS**.
72
-
73
- For a lightweight installation without the test extras:
74
- `python -m pip install -r requirements.txt`
75
-
76
- ### Docker (local-only bound port)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
77
 
78
  ```bash
79
- docker compose up --build
80
- ```
81
-
82
- Then open **http://127.0.0.1:8000**. Project assets persist inside `./omega_data`.
83
- Docker image enables DSP; it does **not** include trained neural checkpoints.
84
-
85
- ## Architecture and flow
86
-
87
- ```text
88
- Browser (HTML/CSS/JS; fully offline-compatible)
89
- |
90
- | HTTP (FastAPI 0.1 REST / OpenAPI)
91
- v
92
- Audio Upload --- sanitize/check extension -> configurable upload size quota (default 1024 MiB)
93
- | |
94
- v v
95
- Immutable Original SHA-256 + manifest.json
96
- |
97
- v
98
- libsndfile streaming decoder -> metadata/peak waveform -> in-process queued job
99
- |
100
- +--> chunked STFT -> median harmonic/percussive masks -> inverse STFT
101
- | |
102
- | v
103
- | Harmonic + Percussive
104
- | |
105
- | Original - both = Residual
106
- | |
107
- | v
108
- | Mixture consistency report
109
- | |
110
- +--> [optional trusted Demucs local repo] |
111
- trained four-source neural model |
112
- | |
113
- +------> residual calculation --------------+
114
- |
115
- v
116
- WAV FLOAT master + PCM16 preview
117
- |
118
- v
119
- Per-stem WAV / ZIP export
120
  ```
121
 
122
- A single-process `ThreadPoolExecutor` executes separation jobs, to keep the
123
- first version easy to run locally. **Jobs are not durable across restart**.
124
- For the full hybrid roadmap, replace this with persistent Redis/RQ/Celery plus
125
- PostgreSQL metadata and an optional S3-compatible artifact store. The browser
126
- client remains usable without any external web service or CDN.
127
-
128
- ## Model setup (optional, experimental)
129
-
130
- The model list advertises **HPSS READY** by default. It advertises Demucs
131
- as configured only if `ABSOLUTION_DEMUCS_REPO` points to a directory containing
132
- a `.th` file. Configuration alone does **not** guarantee the model loads.
133
-
134
- 1. Install `python -m pip install -e ".[neural]"` with a compatible PyTorch
135
- and torchaudio environment. Confirm your CPU/GPU installation.
136
- 2. Manually obtain compatible **trusted** Demucs v4 `htdemucs` model files,
137
- model definition YAML, and any required reference files in a local repository.
138
- Review all model and dataset licenses first.
139
- 3. `export ABSOLUTION_DEMUCS_REPO=/absolute/path/to/release_models` (on Windows
140
- set an equivalent environment variable), then restart the server.
141
- 4. Run a short file first; Demucs will process on CPU if CUDA is unavailable.
142
 
143
- Code calls `demucs.api.Separator(repo=local_path, ...)` with no implicit
144
- remote checkpoint fetching. Only load model weights from trusted sources,
145
- because some checkpoint formats can execute code during deserialization.
146
 
147
- **Important:** The Demucs branch is integrated but **untested against actual
148
- weights in this environment**. It might need environment-specific fixes, e.g.
149
- torchaudio binaries. This is not a model training pipeline and does not
150
- implement arbitrary text-conditioned separation.
 
 
 
 
 
151
 
152
- ## REST API
 
 
 
 
 
 
 
 
 
 
 
 
 
153
 
154
- Interactive OpenAPI docs: **http://127.0.0.1:8000/docs**
155
 
156
- | Method | Endpoint | Description |
157
- |---|---|---|
158
- | GET | `/api/v1/health` | Server and security capabilities |
159
- | GET | `/api/v1/models` | Ready / configured model summary |
160
- | POST | `/api/v1/projects` | Create project `{"name":"..."}` |
161
- | GET | `/api/v1/projects/{id}` | Get manifest and analysis |
162
- | POST | `/api/v1/assets` | Multipart `project_id` and `file` |
163
- | POST | `/api/v1/jobs/separate` | `{"project_id":"...", "model":"hpss"}` |
164
- | GET | `/api/v1/jobs/{id}` | Poll queued/running/done/failed |
165
- | GET | `/api/v1/projects/{id}/stems` | Stem metadata and reconstruction report |
166
- | GET | `/api/v1/projects/{id}/audio/{stem}` | Master audio; `?preview=true` for PCM16 |
167
- | GET | `/api/v1/projects/{id}/export` | ZIP source + stems + manifest |
168
 
169
- The source WAV is not rewritten. The original file's **SHA-256** is retained.
170
- The master stems use WAV 32-bit float for processing headroom.
171
- The separate 16-bit PCM listening files are intentionally not master exports.
172
 
173
- ## Numerical assurance
174
 
175
- For input `x[n]`, estimated stems `s_k[n]`, residual `r[n]`:
176
 
177
- ```
178
- r[n] = x[n] - sum_k s_k[n]
179
- assert max(abs(x - (sum_k s_k + r))) < 1e-8
180
- ```
181
-
182
- Reported maximum reconstruction error is measured on the in-memory 64-bit
183
- floating-point signal. Saving WAV 32-bit float adds rounding that is **not**
184
- included in this internal error report. Reopen/export tests validate the file
185
- format, but no claim of bit-exact preservation of saved STEM PCM is made.
186
- Master sources are estimates; perfect reconstruction of the mix does **not**
187
- mean leakage-free extraction or successful semantic source attribution.
188
- No SDR, source-purity or confidence score is invented without reference stems.
189
-
190
- ## Limits in this version
191
-
192
- - No fixed audio-duration limit. Default upload size ceiling: 1024 MiB
193
- (`ABSOLUTION_MAX_UPLOAD_MIB` adjusts this); 8k–192kHz; mono/stereo only.
194
- - Single-user local interface; **no authentication**. Do not publish port
195
- 8000 to the public internet. Docker Compose binds to loopback.
196
- - One original asset per project. Creating a new project starts a new import.
197
- - Standard browser HTML/JS instead of Next.js; Tauri, cloud deployment,
198
- websocket updates, Redis, PostgreSQL, team workspaces and multi-user auth
199
- are **future work**.
200
- - 2 workers, process-local job status; incomplete jobs are not recovered.
201
- - Waveform and coarse diagnostics are available. No musical-note or
202
- instrument-specific semantic ontology, no speech diarization, no generative
203
- restoration, and no patentable breakthrough are included.
204
- - HPSS uses overlapping disk-streamed chunks rather than allocating full-track
205
- spectra. Temporary files, output WAVs, audio previews and ZIP exports consume
206
- substantial disk space. Processing time scales with audio length.
207
- - The optional Demucs path is still in-memory and may exhaust RAM or VRAM
208
- on long inputs.
209
- - FLAC/MP3/OGG decoding depends on your `libsndfile` build and installed codecs.
210
- - A partial failed stem export may leave master files; the manifest is updated
211
- only after all expected stems finish successfully.
212
-
213
- ## Test suite
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
214
 
215
  ```bash
 
 
 
 
 
 
216
  python -m pytest -q
217
- node --check app/static/app.js
218
- ```
219
-
220
- The eleven automated tests cover reconstruction, stereo, silence, malformed
221
- files, >180-second import and separation, streamed chunk boundaries,
222
- API project/upload/separation/export and refusal of unsupported
223
- prompt-based operations. Additional model-weight, browser
224
- interaction, stress and security tests are needed before production use.
225
-
226
- ## File layout
227
-
228
- ```text
229
- app/
230
- audio.py - file decode and signal processing
231
- server.py - FastAPI, project store, jobs and export
232
- static/ - responsive browser workstation
233
- tests/
234
- test_audio.py - DSP, format and limit checks
235
- test_api.py - HTTP end-to-end and negative cases
236
- tools/
237
- generate_demo.py - creates entirely synthetic demo.wav
238
- Dockerfile
239
- compose.yaml
240
- pyproject.toml
241
- requirements.txt
242
- .env.example
243
- docs/ARCHITECTURE.md
244
- docs/LICENSE_AND_SECURITY.md
245
  ```
246
 
247
- ## Roadmap
248
 
249
- **Milestone 0.2:** model registry with explicit checkpoint validation,
250
- streaming chunked processing, model comparisons and stored job state.
251
-
252
- **Milestone 0.3:** semantic audio taxonomy, optional text-conditioned
253
- adapters, source-by-source review, note/beat/transient labels.
254
-
255
- **Milestone 0.4:** forensic preservation mode, non-destructive restorers,
256
- provenance ledger, aligned blind listening evaluation.
257
-
258
- **Milestone 1.0:** authenticated hybrid client, packaged desktop app,
259
- scalable persistent worker backend, integration benchmarks.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
260
 
261
- Research hypotheses (e.g., uncertainty-gated model fusion) must be tested
262
- against baseline models and never sold as proven source-recovery capabilities.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
  sdk: docker
7
  app_port: 7860
8
  pinned: false
9
+ short_description: Forensic audio lab – HPSS + Demucs stems, arrangement mixer
10
  ---
11
 
12
+ > **Hugging Face Space note:** Public demo instance, no authentication. Demucs htdemucs v4 runs on CPU (max. 120 s audio per job); HPSS has no duration limit. Upload limit 200 MiB. Projects are stored in an attached HF Storage Bucket at `/data` if mounted, otherwise in `/tmp` (lost on restart). Do not upload private/confidential audio.
13
 
14
+ # ABSOLUTION Ω — v0.6 · Arrangement Studio + OMEGA-TAG Mini
15
 
16
+ **Lokales Fullstack-Audiostudio.** Enthält alle Funktionen aus v0.4 (BASS-CORE, NOISE-CORE,
17
+ Virtual Bass, HPSS, optional Demucs) und zusätzlich ein farbiges Mehrspur-Arrangement.
 
18
 
19
+ ## Schnellstart
 
 
 
20
 
21
+ 1. ZIP entpacken. **Python 3.11+** muss installiert sein.
22
+ 2. Windows: `start_windows.bat` ausführen. macOS/Linux: `bash start.sh`.
23
+ 3. Browser: **http://127.0.0.1:8000**.
24
+ 4. `Studio` → eigene Musik laden oder **Demo-Sound laden**.
25
+ 5. Sidebar: **Arrangement** → **Mini-KI analysieren**.
26
+ 6. Automatische *Klangtextur-Hypothesen* prüfen, ändern und **Plan speichern**.
27
+ 7. **Separation starten**: HPSS (harmonisch/perkussiv/Residuum) ist sofort verfügbar;
28
+ Demucs nur mit separat zugänglichen lokalen Gewichten und Neural Dependencies.
29
+ 8. Im Arrangement vorhandene Stems durch **M** (Mute), **S** (Solo), Gain, Stereo-
30
+ Panorama, Effekte bearbeiten. Oben die farbige Mixübersicht und Timeline nutzen.
31
+ 9. **Mix berechnen** → **Mix anhören** → **WAV exportieren**.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
 
33
+ **Beispiel direkt starten, ohne Startskript:**
34
  ```bash
35
  python -m venv .venv
36
+ # Linux/macOS: source .venv/bin/activate
37
+ # Windows PowerShell: .venv\Scripts\Activate.ps1
 
 
 
38
  python -m pip install -e ".[dev]"
 
39
  python -m pytest -q
40
  python -m uvicorn app.server:app --host 127.0.0.1 --port 8000
41
  ```
42
 
43
+ ### Neue Funktionen
44
+
45
+ - Mehrspur-Arrangement mit einzelnen Instrumenten-/Signalstems je nach verfügbarem Modell.
46
+ - Jedes *tatsächlich* verfügbare Audio-Stem erhält eigene Farbe und samplebasierte
47
+ Waveform-Visualisierung, links Lautstärke/Mute/Solo, mittig L/C/R-Pan, rechts
48
+ ausklappbare Effekte (Low-Cut, High-Cut, Sättigung, Stereobreite).
49
+ - Farbig überlagerte Gesamtübersicht, klickbare Zeitleiste und Scroll/Zoom.
50
+ - **OMEGA-TAG Mini**: Offline-MLP (35 Features → 32 tanh Neuronen → 6 Sigmoid-Ausgaben).
51
+ Mitgeliefertes `.npz`-Checkpoint wurde zweistufig auf **synthetischen Signalen**
52
+ trainiert und anschließend auf **synthetischen Mischungen feinjustiert**.
53
+ Es erkennt *nur* Klangtexturen: Bass-ähnlich, Kick-ähnlich, Snare-ähnlich,
54
+ Hi-Hat-ähnlich, harmonische Mitten und rauschähnliche Anteile.
55
+ **Keine trainierte oder validierte Instrumentenerkennung auf echter Musik.**
56
+ - Editable Trennziele (bis 128 aus Ressourcen-/Sicherheitsgründen).
57
+ Das Speichern eines Ziels separiert **keine** zusätzliche Audiospur.
58
+ - Nichtdestruktiver, chunkweiser Stereo-Float32-Mix mit Gain, Mute, Solo,
59
+ Panorama, Hoch-/Tiefpass, Stereo Width und harmonischer Sättigung.
60
+ - Optional von 50–200 % unabhängiges Tempo und ±12 Halbtöne transponieren
61
+ mittels **FFmpeg mit Rubber Band Filter**.
62
+ Der Button wird ohne Rubber Band deaktiviert, nicht simuliert.
63
+ - WAV-Float32-Export und messbarer Pegelbericht einschließlich möglicher
64
+ Überschreitung von 0 dBFS.
65
+
66
+ ### Integritätsregeln
67
+
68
+ - Original wird niemals in-place überschrieben. Quellen und Export werden
69
+ in getrennten Projektordnern gespeichert.
70
+ - Kein Eingriff und kein Sound Processing ohne explizites **Mix berechnen**.
71
+ - Gespeicherte KI-Trennplan-Hypothesen sind ausdrücklich nicht als isolierte
72
+ Instrumentenspuren bezeichnet.
73
+ - HPSS ist **kein Instrumentenerkennungsmodell**, sondern strukturelle Trennung.
74
+ Demucs v4 ist optional und bietet vier Grobkategorien; es zerlegt nicht beliebig
75
+ viele benannte Instrumente.
76
+ - Waveforms werden für rasche Anzeige sparsam gesampelt; sie sind **keine**
77
+ vollständige Peak- oder Forensikmessung.
78
+ - Synthetisch generierte Oberwellen, Tontranspositionen und FX sind
79
+ Klangänderungen, **keine** Rekonstruktion physisch nachweisbarer fehlender Daten.
80
+ - Kein automatisches Mastering, kein pauschales Denoising oder 0-dB-Normalisieren.
81
+
82
+ ### Tooling und Deployment
83
+
84
+ - Python / FastAPI / NumPy / SciPy / SoundFile.
85
+ - Frontend: eigenständiges HTML/CSS/JavaScript, kein CDN, keine fremde Cloud.
86
+ - Startet als lokaler Browser-Webserver; optional Docker Compose (nicht
87
+ als produktionsbereite Public-Cloud-Anwendung absichern).
88
+ - FFmpeg ist für Grundfunktionen nicht erforderlich, für spezielle Dateiformate,
89
+ Virtual Bass und unabhängige Pitch/Tempo-Transformation hingegen erforderlich.
90
+ - `start.sh`/`.bat` installieren Python-Abhängigkeiten über pip und benötigen bei
91
+ Erstinstallation Netzwerkzugang; die Anwendung selbst ruft danach keine
92
+ externen Server auf.
93
+ - Keine Benutzeranmeldung, keine öffentliche Mehrnutzer-Bereitstellung.
94
+ - Datenspeicherung in `omega_data/`, falls nicht über `ABSOLUTION_DATA_DIR` geändert.
95
+
96
+ ### Tests
97
 
98
  ```bash
99
+ python -m pip install -e ".[dev]"
100
+ python -m pytest -q
101
+ node --check app/static/app.js
102
+ node --check app/static/arrangement.js
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
103
  ```
104
 
105
+ Neue Tests: neutrale Summierung, Solo/Mute, Panorama, FX, Wellenform-API,
106
+ synthetisches Mini-Modell, Plan-Persistenz, tatsächliche Mix-Jobs und WAV-Export.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
107
 
108
+ ### Neue API
 
 
109
 
110
+ ```
111
+ POST /api/v1/projects/{id}/inventory Mini-Tagging, synchron (lokal)
112
+ PUT /api/v1/projects/{id}/plan editierbare Zielhypothesen
113
+ GET /api/v1/projects/{id}/wave/{stem} sparsames Wellenform-Sampling
114
+ POST /api/v1/jobs/mix Offline-Mix-Job
115
+ GET /api/v1/jobs/{job_id} Fortschritt
116
+ GET /api/v1/projects/{id}/mixer Mix-Report und gespeicherte Parameter
117
+ GET /api/v1/projects/{id}/mixer/audio WAV-Export
118
+ ```
119
 
120
+ Request-Body für Mix-Jobs:
121
+ ```json
122
+ {
123
+ "project_id": "<PROJECT_UUID>",
124
+ "tracks": {
125
+ "harmonic": {"gain_db": -2.0, "pan": -0.2, "mute": false, "solo": false,
126
+ "highpass_hz": 25, "lowpass_hz": 0, "drive": 0.1, "width": 1.0}
127
+ },
128
+ "tempo": 1.0,
129
+ "pitch_semitones": 0
130
+ }
131
+ ```
132
+ Nicht spezifizierte Stems sind ohne Effekte und bei 0 dB enthalten. Solo-Modus
133
+ spielt ausschließlich Solo-markierte, nicht stumm geschaltete Stems.
134
 
135
+ ### Forschungsstatus
136
 
137
+ Weitere getrennte Instrumente benötigen leistungsfähige bedingte oder
138
+ hierarchische KI-Separatoren plus realistisch evaluiertes Modellrouting.
139
+ Das integrierte Mini-Modell ist hierfür nur eine Vorinventur, kein universelles
140
+ Separationsmodell. Das Projekt bleibt eine lokale Forschungs-/Prototyp-Version.
 
 
 
 
 
 
 
 
141
 
142
+ Weitere Details: `docs/ARRANGEMENT_STUDIO.md` sowie das historische
143
+ NOISE-/BASS-CORE-Material unten.
 
144
 
145
+ ---
146
 
147
+ # ABSOLUTION Ω — v0.4.0 · NOISE-CORE + BASS-CORE
148
 
149
+ > Local-first audio-forensics workbench with BASS-CORE (experimental DSP-derived kick/bassline
150
+ > estimates, non-destructive bass processing and optional use of pre-separated HPSS/Demucs stems).
151
+
152
+ ## Starten
153
+
154
+ 1. Das ZIP entpacken.
155
+ 2. `start_windows.bat` (Windows) oder `bash start.sh` (macOS/Linux) im Projektordner starten.
156
+ 3. `http://127.0.0.1:8000` im Browser öffnen.
157
+ 4. Unter **Studio** WAV/FLAC/AIFF/OGG/unterstütztes MP3 importieren oder Demo laden.
158
+ 5. Den Bereich **BASS-CORE** öffnen, Preset/Regler wählen und **Bass analysieren & optimieren** drücken.
159
+ 6. **Bassband vorher/nachher**, Kick-/Bassline-Schätzung, erzeugte Obertöne und Vollmix anhören.
160
+ 7. Einzel-WAVs oder **Alle Bass-Tracks herunterladen** (ZIP) exportieren.
161
+
162
+ Mit vorhandenem HPSS-Ergebnis kann BASS-CORE die harmonischen/perkussiven Stems als
163
+ Quellenhypothese verwenden. Bei korrekt konfiguriertem Demucs und vorab generierten
164
+ `bass`/`drums`-Stems nutzt die Engine diese als Ausgangspunkt. Ein manueller Modus
165
+ erzwingt entsprechende Quellen und wird mit HTTP 409 abgelehnt, falls sie fehlen.
166
+
167
+ ## Neu: NOISE-CORE Ω — PRESERVE FIRST (v0.4)
168
+
169
+ **Hauptregel:** Erhaltung von Musik, Luft, Hall, feinen Transienten und dem
170
+ Original hat Vorrang vor der Störminderung. Es gibt **keine Garantie**,
171
+ dass eine Reparatur bei Überlagerungen ausschließlich Störgeräusche ändert.
172
+ Daher setzt diese Version die Reparatur nicht automatisch ein.
173
+
174
+ **Bedienung**
175
+
176
+ 1. Importiere eine Audiodatei im Studio.
177
+ 2. Öffne **NOISE-CORE** und wähle **Störspur analysieren**.
178
+ 3. Überprüfe einzelne Klick-Verdachtsfälle durch Anhören des Originals.
179
+ Kein Ereignis ist vorab ausgewählt; die Klick-Erkennung ist nur eine
180
+ Heuristik, **kein KI-Detektor** und kein Beweis für eine Störung.
181
+ 4. Wähle einzelne geprüfte Ereignisse und die Reparaturstärke aus.
182
+ 5. Bestätige die Reparatur. Es werden **nur die ausgewählten einzelnen
183
+ Samples** interpoliert; keine sonstigen Samples gezielt verändert.
184
+ 6. Höre **Clean** und insbesondere **Differenzspur** an und exportiere
185
+ beide als WAV 32-bit Float plus JSON-Bericht.
186
+
187
+ Die Differenzspur ist exakt als `Original - Clean` berechnet (vor
188
+ Float32-Dateiquantisierung). Sie kann echte musikalische Inhalte enthalten.
189
+ Ein kleiner numerischer Rekonstruktionsfehler beweist **nicht**, dass die
190
+ Veränderung hörpsychologisch unbedenklich ist.
191
+
192
+ **Was absichtlich NICHT automatisiert ist**
193
+
194
+ - Keine pauschale Broadband-Noise-Reduction und kein Spectral-Gate.
195
+ - Keine 50/60-Hz-Notches ohne Prüfung, da Bassnoten oder Obertöne betroffen sein können.
196
+ - Keine generative Resynthese verlorener Musik.
197
+ - Keine selbständige Klassifikation als „sicheres Störgeräusch“.
198
+ - Keine angebliche KI-Qualität, wo nur Heuristiken vorliegen.
199
+
200
+ Tonal-Indikatoren bei 50/60/100/120 Hz sind ausschließlich **mehrdeutige
201
+ Spektralspitzen**, die ohne automatischen Eingriff angezeigt werden.
202
+ Ein Scan unterstützt auch Audiodateien von mehr als 180 Sekunden; RAM
203
+ bleibt durch blockweise Verarbeitung begrenzt. Die Dateigrößen-
204
+ und Speicherplatzgrenzen bleiben bestehen.
205
+
206
+ **API:**
207
+
208
+ - `POST /api/v1/jobs/noise/scan` mit `{"project_id": "[UUID]"}`;
209
+ - `POST /api/v1/jobs/noise/repair` mit `{"project_id":"[UUID]", "approved_samples":[4321], "strength":0.8}`;
210
+ - `GET /api/v1/projects/{id}/noise` für Scan/Repair-Bericht;
211
+ - `GET /api/v1/projects/{id}/noise/audio/{clean|difference}`;
212
+ - `GET /api/v1/projects/{id}/noise/export`.
213
+
214
+ ## Neu: Kdenlive-kompatibler Virtual-Bass-Export (optional)
215
+
216
+ BASS-CORE bietet einen **separaten FFmpeg-Virtualbass-Adapter** (nur falls
217
+ `ffmpeg` mit Filter `virtualbass` lokal verfügbar ist). Dieser Filter
218
+ konvertiert **2-Kanal-Stereo → 2.1**. Die ursprünglichen Stereo-Kanäle werden
219
+ vom Filter unverändert weitergegeben; der dritte Kanal ist ein künstlich
220
+ generierter LFE-Kanal. Ein neuer Bass-Ton wird **nicht zurückgewonnen**.
221
+
222
+ Wähle in BASS-CORE `Cutoff` 100–500 Hz, `Strength` 0.5–3, starte den Export
223
+ und lade `ABSOLUTION_VIRTUAL_BASS_2_1.wav` herunter (WAV Float32).
224
+ Nur für echte Stereoquellen. Eine echte 2.1-Wiedergabekette wird empfohlen;
225
+ Browser-Audio unterstützt dreikanalige WAV-Dateien nicht zuverlässig.
226
+ Die LFE-Amplitude kann 0 dBFS überschreiten und muss im Zielsystem geprüft werden.
227
+
228
+ Offizielle Filterbeschreibung: https://ffmpeg.org/ffmpeg-filters.html#virtualbass
229
+
230
+ **API:**
231
+
232
+ - `POST /api/v1/jobs/bass/virtual` (`project_id`, `cutoff_hz`, `strength`);
233
+ - `GET /api/v1/projects/{id}/virtualbass`;
234
+ - `GET /api/v1/projects/{id}/virtualbass/audio` (2.1-WAV).
235
+
236
+ ### Warum keine Normalisierung auf −0,01 dB vor Analyse/Trennung?
237
+
238
+ Weil Verstärkung keine fehlende Information wiederherstellt und spätere
239
+ Bearbeitung bei nahezu Vollaussteuerung leichter übersteuert. Originalpegel
240
+ unverändert halten; falls ein Modell Normalisierung braucht, nur reversible
241
+ temporäre Kopien mit dokumentiertem Verstärkungsfaktor verwenden.
242
+ Output-True-Peak-Messung nach der Bearbeitung, nicht aggressives
243
+ Pre-Normalizing. **−0,01 dBFS Sample-Peak ist keine Garantie für
244
+ −0,01 dBTP (True Peak).**
245
+
246
+ ## Verarbeitung: BASS-CORE v0.3
247
+
248
+ - **DSP-Modus:** 45–350-Hz Tiefband mittels Zero-Phase-Crossover. Ein
249
+ transientenbasierter Maskierungsansatz schätzt Kick vs. Bassline.
250
+ Dies ist **keine** unabhängige Instrumentenquellentrennung.
251
+ - **HPSS-Modus:** Tiefband der vorab separierten `percussive`- und `harmonic`-Spuren.
252
+ Harmonische Instrumente außer Bass und tiefe Schlagzeuganteile können überlappen.
253
+ - **Demucs-Modus:** Tiefband der vorab geschätzten `drums`- und `bass`-Spuren.
254
+ Erfordert lokale Demucs-Gewichte und erfolgreiche Separation; automatische Downloads AUS.
255
+ - **Processing:** Pegelregler für Kick/Bassline, Bass-Subgain, Rumpelfilter,
256
+ symmetrische nichtlineare Obertongenerierung, Stereo-zu-Mono unter Grenzfrequenz,
257
+ Dry/Wet-Mischung.
258
+ - **Output-Ceiling:** nach dem Rendern wird *der optimierte Mix* bei Bedarf
259
+ global abgesenkt. Das ist **kein True-Peak-Limiter**. Einzelstems bleiben
260
+ unverändert und dürfen Peaks > 0 dBFS enthalten (WAV 32-bit Float).
261
+ - **Export:** `bass_band`, `kick_estimate`, `bassline_estimate`, `other_unprocessed`,
262
+ `harmonics_added`, `bass_optimized`, `mix_optimized`, jeweils WAV Float32 plus
263
+ separate PCM16-Hörvorschauen. ZIP enthält `bass_report.json`.
264
+ - **Consistency:** Die Zerlegung `kick_estimate + bassline_estimate +
265
+ other_unprocessed` entspricht dem eingelesenen Mix innerhalb einer numerischen
266
+ Toleranz. Das beweist nicht die semantische Reinheit.
267
+
268
+ Der Inspector zeigt Energien für Frequenzbänder von 20–1280 Hz aus dem ersten
269
+ Audio-Chunk. Er stellt keine Tonhöhen oder einzelnen Instrumente fest.
270
+
271
+ ## Grenzen und Sicherheit
272
+
273
+ - Originaldateien bleiben unverändert gespeichert, inklusive SHA-256.
274
+ - Keine feste 180-Sekunden-Grenze. Maximalgröße standardmäßig 1024 MiB
275
+ (konfigurierbar über `ABSOLUTION_MAX_UPLOAD_MIB` bis 4096).
276
+ - Chunkweise/offline Verarbeitung vermindert, **eliminiert aber nicht** mögliche
277
+ Artefakte an Blockgrenzen. Sie kann erhebliche Diskkapazität erfordern
278
+ (sieben Float32-WAVs plus Vorschauen).
279
+ - Kein echtes Deep-Learning für die DSP-Schätzung. Keine Noten-/F0-Reparatur,
280
+ keine intelligenten Sub-Oszillatoren, kein echtes De-Clip, kein vollautomatisches KI-De-Noise, kein Echtzeit-Audio,
281
+ kein VST3-/AU-Hosting in v0.3. Diese Funktionen sind auf der Roadmap.
282
+ - Nicht für öffentliche Mehrbenutzer-Deployments geeignet:
283
+ Benutzeranmeldung, Job-Persistenz, Rate Limiting und Plugin-Sandbox fehlen.
284
+ - Keine Telemetrie und keine externen Modell-Downloads durch diese Anwendung.
285
+ - Für optionale Bibliotheken wie Demucs, Pedalboard/Surge XT und kommerzielle
286
+ VST-Plugins gelten jeweils eigene Lizenz-/Checkpoints-/Nutzungsbedingungen.
287
+
288
+ ## Entwickler: API und Tests
289
 
290
  ```bash
291
+ python -m venv .venv
292
+ # Linux/macOS:
293
+ source .venv/bin/activate
294
+ # Windows PowerShell:
295
+ # .venv\\Scripts\\Activate.ps1
296
+ pip install -e ".[dev]"
297
  python -m pytest -q
298
+ python -m uvicorn app.server:app --host 127.0.0.1 --port 8000
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
299
  ```
300
 
301
+ ### Wichtige API-Pfade
302
 
303
+ | HTTP | Pfad | Beschreibung |
304
+ |---|---|---|
305
+ | POST | `/api/v1/projects` | Projekt anlegen |
306
+ | POST | `/api/v1/assets` | WAV/FLAC/etc. importieren |
307
+ | POST | `/api/v1/jobs/separate` | HPSS oder optional Demucs |
308
+ | POST | `/api/v1/jobs/bass` | Neuer BASS-CORE-Job |
309
+ | GET | `/api/v1/jobs/{job_id}` | Status/Fortschritt |
310
+ | GET | `/api/v1/projects/{id}/bass` | Quelle, Report, Outputs |
311
+ | GET | `/api/v1/projects/{id}/bass/audio/{track}` | Master; `?preview=true` für Player |
312
+ | GET | `/api/v1/projects/{id}/bass/export` | ZIP aller Bass-Stems |
313
+ | GET | `/docs` | Interaktive OpenAPI-Dokumentation |
314
+
315
+ Beispiel-JSON für `/api/v1/jobs/bass`:
316
+
317
+ ```json
318
+ {
319
+ "project_id": "[UUID-AUS-DER-PROJEKT-ANLAGE]",
320
+ "source_mode": "auto",
321
+ "crossover_hz": 220,
322
+ "kick_focus": 0.75,
323
+ "kick_gain_db": 2.0,
324
+ "bass_gain_db": 1.0,
325
+ "sub_gain_db": 1.5,
326
+ "harmonics": 0.35,
327
+ "lowcut_hz": 22,
328
+ "mono_below_hz": 100,
329
+ "wet": 1.0,
330
+ "ceiling_dbfs": -1.0
331
+ }
332
+ ```
333
 
334
+ ## KI-Roadmap nach Erhaltungs-Priorität
335
+
336
+ 1. **AI Noise Event Triage:** Click-vs-Instrumenten-Transient-Klassifikator
337
+ auf echten musikalischen Negativbeispielen, mit Unsicherheits-Gating/
338
+ Abstention; keine automatische Massenreparatur.
339
+ 2. **Source-aware Noise:** Zwischen Bass, Schlagzeug, Stimmen und Rest
340
+ separieren; Störhypothese gezielt im betreffenden Stem prüfen.
341
+ 3. **Harmonic Preservation:** Zeit-Frequenz-Masken mit Erhaltung von
342
+ Noten, Harmonischen, Atemgeräuschen, Hallfahnen und Transienten.
343
+ Nicht sicher unterscheidbare Energie bleibt im Original.
344
+ 4. **Independent Repair Judge:** Automatische Vorher-/Nachher-Prüfung,
345
+ Difference-Stem, Nulltests, Blindhörtest und Leckage-/Transientmetriken.
346
+ 5. Echte Bass-/Drum-Separation durch modellbasierte Quellenzerlegung und
347
+ mehrstufige Kick-/Bassline-/808-Klassifikation.
348
+ 6. Semantischer Low-End-Eventgraph mit validiertem F0- und Transienten-Tracking.
349
+ 7. Optionaler phase-/pitch-locked Sub-Synthesizer unter Unsicherheits-Gating.
350
+ 8. Selektive Event-Reparatur (z. B. Clicks und Dropouts) mit Provenance.
351
+ 9. Geschützter, separat betriebener VST3-/AU-Host und kommerzielle Lizenzprüfung;
352
+ externe Plugins dürfen niemals ungeprüft im API-Prozess laufen.
353
+ 10. True-Peak-Meter/Limiter, Oversampling, A/B-Loudness-Matching, Listening Benchmarks
354
+ und getrennte quantitative Benchmarks mit Ground Truth.
355
+
356
+ Alle Forschungsstufen sind noch nicht implementiert. Eine mathematisch
357
+ saubere Restmischung ist nicht gleichbedeutend mit perfekten Original-Stems.
358
+
359
+ ## Weitere Dokumentation
360
+
361
+ Siehe `docs/ARCHITECTURE.md`, `docs/LICENSE_AND_SECURITY.md`, `docs/WEBSITE.md`.
362
+
363
+ ## Dokumentation NOISE-CORE
364
+
365
+ Siehe `docs/NOISE_CORE_DESIGN.md` für Schutzprinzipien, Grenzen und Teststrategie.
app/bass.py ADDED
@@ -0,0 +1,284 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """BASS-CORE Ω: local, deterministic, non-destructive low-frequency laboratory.
2
+
3
+ No semantic separation or restoration of absent information is claimed.
4
+ - DSP mode: transient-gated sub-band approximation.
5
+ - HPSS mode: HPSS-derived sub-band estimates.
6
+ - Demucs mode: licensed/precomputed bass and drums stems.
7
+ All modes retain a mathematically explicit unprocessed remainder.
8
+ """
9
+ from __future__ import annotations
10
+
11
+ import math
12
+ from contextlib import ExitStack
13
+ from dataclasses import asdict, dataclass
14
+ from pathlib import Path
15
+ from typing import Callable
16
+
17
+ import numpy as np
18
+ import soundfile as sf
19
+ from scipy.ndimage import uniform_filter1d
20
+ from scipy.integrate import trapezoid
21
+ from scipy.signal import butter, sosfiltfilt, welch
22
+
23
+ from .audio import AudioError, audio_info
24
+
25
+
26
+ @dataclass(frozen=True)
27
+ class BassParams:
28
+ crossover_hz: float = 220.0
29
+ kick_focus: float = 0.75
30
+ kick_gain_db: float = 0.0
31
+ bass_gain_db: float = 0.0
32
+ sub_gain_db: float = 0.0
33
+ harmonics: float = 0.20
34
+ lowcut_hz: float = 22.0
35
+ mono_below_hz: float = 100.0
36
+ wet: float = 1.0
37
+ ceiling_dbfs: float = -1.0
38
+
39
+
40
+ TRACKS = {
41
+ "bass_band": "Original low-frequency estimate",
42
+ "kick_estimate": "Low-frequency kick hypothesis (not instrument truth)",
43
+ "bassline_estimate": "Low-frequency bassline hypothesis (not instrument truth)",
44
+ "other_unprocessed": "Original minus estimated bass band",
45
+ "harmonics_added": "Synthesized harmonics only (not recovered information)",
46
+ "bass_optimized": "Edited low-frequency estimate",
47
+ "mix_optimized": "Reconstructed mix, with global ceiling gain",
48
+ }
49
+
50
+
51
+ def _lp(signal: np.ndarray, sr: int, hz: float, order: int = 4) -> np.ndarray:
52
+ hz = max(4.0, min(float(hz), sr * .46))
53
+ return sosfiltfilt(butter(order, hz, btype="low", fs=sr, output="sos"), signal, axis=0)
54
+
55
+
56
+ def _hp(signal: np.ndarray, sr: int, hz: float, order: int = 3) -> np.ndarray:
57
+ hz = max(4.0, min(float(hz), sr * .46))
58
+ return sosfiltfilt(butter(order, hz, btype="high", fs=sr, output="sos"), signal, axis=0)
59
+
60
+
61
+ def _level(samples: np.ndarray) -> dict:
62
+ peak = float(np.max(np.abs(samples))) if samples.size else 0.0
63
+ rms = float(np.sqrt(np.mean(np.square(samples)))) if samples.size else 0.0
64
+ return {"peak_dbfs": round(20 * math.log10(max(peak, 1e-12)), 3),
65
+ "rms_dbfs": round(20 * math.log10(max(rms, 1e-12)), 3)}
66
+
67
+
68
+ def _kick_mask(low: np.ndarray, sr: int, amount: float) -> np.ndarray:
69
+ """Transient emphasis, NOT an instrument classifier."""
70
+ mono = np.mean(low, axis=1)
71
+ energy = np.square(mono)
72
+ fast = np.sqrt(np.maximum(0, uniform_filter1d(energy, size=max(3, int(sr*.008)))))
73
+ slow = np.sqrt(np.maximum(0, uniform_filter1d(energy, size=max(7, int(sr*.110)))))
74
+ ratio = np.maximum(0.0, fast / np.maximum(slow, 1e-5) - 0.96)
75
+ transients = np.clip(ratio * 1.15, 0.0, 1.0)
76
+ # Smooth short spikes; use context to avoid abrupt gates.
77
+ activation = uniform_filter1d(transients, size=max(3, int(sr*.024)))
78
+ return np.clip(activation * amount, 0, 1)[:, None]
79
+
80
+
81
+ def _transform(samples: np.ndarray, sr: int, cfg: BassParams,
82
+ mode: str, harmonic=None, percussive=None, bass=None, drums=None) -> dict[str, np.ndarray]:
83
+ if mode == "demucs":
84
+ if bass is None or drums is None:
85
+ raise AudioError("Demucs bass and drums stems are required.")
86
+ kick = _lp(drums, sr, cfg.crossover_hz)
87
+ bassline = _lp(bass, sr, cfg.crossover_hz)
88
+ band = kick + bassline
89
+ elif mode == "hpss":
90
+ if harmonic is None or percussive is None:
91
+ raise AudioError("HPSS harmonic and percussive stems are required.")
92
+ kick = _lp(percussive, sr, cfg.crossover_hz)
93
+ bassline = _lp(harmonic, sr, cfg.crossover_hz)
94
+ band = kick + bassline
95
+ else:
96
+ band = _lp(samples, sr, cfg.crossover_hz)
97
+ mask = _kick_mask(band, sr, cfg.kick_focus)
98
+ kick = band * mask
99
+ bassline = band - kick
100
+
101
+ other = samples - band
102
+ # A DC/sub-rumble cut is a *change* to the original, never hidden.
103
+ edited_kick = _hp(kick, sr, cfg.lowcut_hz) * 10 ** (cfg.kick_gain_db / 20)
104
+ edited_line = _hp(bassline, sr, cfg.lowcut_hz) * 10 ** (cfg.bass_gain_db / 20)
105
+ if abs(cfg.sub_gain_db) > 1e-8:
106
+ low_sub = _lp(edited_line, sr, min(65.0, cfg.crossover_hz*.65))
107
+ edited_line = edited_line + low_sub * (10 ** (cfg.sub_gain_db/20) - 1)
108
+ # Odd harmonic synthesis through symmetric soft saturation.
109
+ drive = np.clip(edited_line * 3.5, -12, 12)
110
+ synthesized = np.tanh(drive) - drive
111
+ synthesized = _hp(synthesized, sr, min(100.0, cfg.crossover_hz * .6))
112
+ synthesized = _lp(synthesized, sr, min(1500.0, sr*.42))
113
+ synthesized *= cfg.harmonics * .6
114
+ optimized = edited_kick + edited_line + synthesized
115
+ if samples.shape[1] == 2 and cfg.mono_below_hz > 0:
116
+ centered_low = _lp(optimized, sr, cfg.mono_below_hz)
117
+ optimized = optimized - centered_low + np.mean(centered_low, axis=1, keepdims=True)
118
+ optimized = cfg.wet * optimized + (1-cfg.wet) * band
119
+ mix = other + optimized
120
+ return {
121
+ "bass_band": band, "kick_estimate": kick,
122
+ "bassline_estimate": bassline, "other_unprocessed": other,
123
+ "harmonics_added": synthesized * cfg.wet,
124
+ "bass_optimized": optimized, "mix_optimized": mix,
125
+ }
126
+
127
+
128
+ def _bands(signal: np.ndarray, sr: int) -> list[dict]:
129
+ mono = np.mean(signal, axis=1)
130
+ n = min(8192, len(mono))
131
+ frequencies, power = welch(mono, fs=sr, nperseg=n, noverlap=n//2)
132
+ output = []
133
+ for lower, upper in [(20,40), (40,80), (80,160), (160,320), (320,640), (640,1280)]:
134
+ selection = (frequencies >= lower) & (frequencies < upper)
135
+ energy = float(trapezoid(power[selection], frequencies[selection])) if np.count_nonzero(selection) >= 2 else 0
136
+ output.append({"range_hz": [lower,upper], "estimated_rms_dbfs": round(
137
+ 10 * math.log10(max(energy, 1e-24)), 2)})
138
+ return output
139
+
140
+
141
+ def process_bass_file(input_path: Path, output_dir: Path, cfg: BassParams,
142
+ mode: str = "dsp", refs: dict[str, Path] | None = None,
143
+ progress: Callable[[float], None] | None = None,
144
+ chunk_frames: int = 262144,
145
+ context_frames: int | None = None) -> tuple[dict, dict]:
146
+ """Bounded-memory offline editing; symmetric context reduces boundary artifacts.
147
+
148
+ Stems are WAV 32-bit float. Preview copies are PCM16 for browser playback.
149
+ A final global ceiling gain is applied to optimized MIX only.
150
+ """
151
+ info = audio_info(input_path)
152
+ if mode not in ("dsp","hpss","demucs"):
153
+ raise AudioError("Unknown bass extraction mode.")
154
+ if not (45 <= cfg.crossover_hz <= min(350.0, info.samplerate*.42)):
155
+ raise AudioError("Crossover must be between 45 and 350 Hz.")
156
+ if context_frames is None:
157
+ context_frames = max(8192, int(info.samplerate * .32))
158
+ if chunk_frames < 4096 or context_frames < 1024:
159
+ raise AudioError("Processing chunks/context too small.")
160
+ required = {"hpss":("harmonic","percussive"),"demucs":("bass","drums"),"dsp":()}[mode]
161
+ refs = refs or {}
162
+ for name in required:
163
+ if name not in refs:
164
+ raise AudioError(f"Missing reference stem: {name}")
165
+ ref = audio_info(refs[name])
166
+ if ref.samplerate != info.samplerate or ref.frames != info.frames or ref.channels != info.channels:
167
+ raise AudioError("Stem must match source sample rate, length and channels.")
168
+
169
+ output_dir.mkdir(parents=True, exist_ok=True)
170
+ measured_peak = 0.0
171
+ max_reconstruction_error = 0.0
172
+ first = None
173
+ rms_accum = {key:0.0 for key in TRACKS}
174
+ peaks = {key:0.0 for key in TRACKS}
175
+ metadata = {}
176
+ try:
177
+ with ExitStack() as stack:
178
+ input_file = stack.enter_context(sf.SoundFile(str(input_path), "r"))
179
+ input_refs = {name:stack.enter_context(sf.SoundFile(str(refs[name]),"r")) for name in required}
180
+ writers = {name:stack.enter_context(sf.SoundFile(
181
+ str(output_dir / f"{name}.wav"), "w", format="WAV", subtype="FLOAT",
182
+ samplerate=info.samplerate, channels=info.channels,
183
+ )) for name in TRACKS}
184
+ previews = {name:stack.enter_context(sf.SoundFile(
185
+ str(output_dir / f"{name}_preview.wav"),"w", format="WAV", subtype="PCM_16",
186
+ samplerate=info.samplerate,channels=info.channels,
187
+ )) for name in TRACKS}
188
+ for pos in range(0, info.frames, chunk_frames):
189
+ target_end = min(info.frames, pos + chunk_frames)
190
+ start = max(0, pos - context_frames)
191
+ end = min(info.frames, target_end + context_frames)
192
+ input_file.seek(start)
193
+ x = input_file.read(end-start, dtype="float64", always_2d=True)
194
+ if len(x) != end-start or not np.isfinite(x).all():
195
+ raise AudioError("Audio contains unreadable or non-finite samples.")
196
+ extra = {}
197
+ for name, inp in input_refs.items():
198
+ inp.seek(start)
199
+ extra[name] = inp.read(end-start,dtype="float64",always_2d=True)
200
+ if len(extra[name]) != len(x) or not np.isfinite(extra[name]).all():
201
+ raise AudioError("Reference stem contains invalid samples.")
202
+ tracks = _transform(x,info.samplerate,cfg,mode,**extra)
203
+ sel = slice(pos-start, pos-start + target_end-pos)
204
+ inner = {name:arr[sel] for name,arr in tracks.items()}
205
+ err = np.max(np.abs((inner["kick_estimate"]+inner["bassline_estimate"]+
206
+ inner["other_unprocessed"]) - x[sel]))
207
+ max_reconstruction_error = max(max_reconstruction_error,float(err))
208
+ measured_peak = max(measured_peak,float(np.max(np.abs(inner["mix_optimized"]))))
209
+ if first is None:
210
+ first = {"before": _bands(inner["bass_band"],info.samplerate),
211
+ "after": _bands(inner["bass_optimized"],info.samplerate)}
212
+ for name, signal in inner.items():
213
+ writers[name].write(signal)
214
+ previews[name].write(np.clip(signal,-1,1))
215
+ rms_accum[name] += float(np.sum(np.square(signal)))
216
+ peaks[name] = max(peaks[name], float(np.max(np.abs(signal))))
217
+ if progress:
218
+ progress((target_end / info.frames)*.90)
219
+ # A global, non-clipping gain for MIX output; individual stems remain unaltered.
220
+ ceiling = 10 ** (cfg.ceiling_dbfs/20)
221
+ gain = min(1.0, ceiling / max(measured_peak, 1e-12))
222
+ if gain < 1:
223
+ from tempfile import NamedTemporaryFile
224
+ with NamedTemporaryFile(prefix="omega_mix_",suffix=".wav",dir=output_dir,delete=False) as target:
225
+ temporary = Path(target.name)
226
+ try:
227
+ with sf.SoundFile(str(output_dir / "mix_optimized.wav"), "r") as inp, \
228
+ sf.SoundFile(str(temporary),"w",samplerate=info.samplerate,
229
+ channels=info.channels,subtype="FLOAT", format="WAV") as out:
230
+ while True:
231
+ block = inp.read(131072,dtype="float64",always_2d=True)
232
+ if not len(block): break
233
+ out.write(block*gain)
234
+ temporary.replace(output_dir / "mix_optimized.wav")
235
+ with sf.SoundFile(str(output_dir/"mix_optimized_preview.wav"),"w",
236
+ samplerate=info.samplerate,channels=info.channels,
237
+ format="WAV",subtype="PCM_16") as preview, \
238
+ sf.SoundFile(str(output_dir/"mix_optimized.wav"),"r") as mixed:
239
+ while True:
240
+ block=mixed.read(131072, dtype="float64", always_2d=True)
241
+ if not len(block): break
242
+ preview.write(np.clip(block,-1,1))
243
+ finally:
244
+ temporary.unlink(missing_ok=True)
245
+ for name in TRACKS:
246
+ value = math.sqrt(rms_accum[name] / (info.frames * info.channels))
247
+ metadata[name] = {
248
+ "name": name, "label": TRACKS[name], "master": f"{name}.wav",
249
+ "preview": f"{name}_preview.wav",
250
+ "duration_seconds": round(info.frames/info.samplerate,4),
251
+ "peak_dbfs": round(20 * math.log10(max(peaks[name] * (
252
+ gain if name=="mix_optimized" else 1),1e-12)),3),
253
+ "rms_dbfs": round(20 * math.log10(max(value * (gain if name=="mix_optimized" else 1),1e-12)),3),
254
+ }
255
+ report = {
256
+ "mode": mode, "source_quality": ("AI stem estimate" if mode=="demucs" else
257
+ "HPSS low-band estimate" if mode=="hpss" else
258
+ "DSP transient estimate; not instrument isolation"),
259
+ "created_harmonics_are_synthetic": True,
260
+ "reconstruction_check": {
261
+ "max_abs_error": float(max_reconstruction_error),
262
+ "tolerance": 2e-6,
263
+ "consistent": max_reconstruction_error < 2e-6,
264
+ "scope": "Kick estimate + bassline estimate + unprocessed other = internal input",
265
+ },
266
+ "params": asdict(cfg),
267
+ "first_chunk_spectrum": first,
268
+ "output_ceiling_gain_db": round(20 * math.log10(max(gain, 1e-12)), 3),
269
+ "output_peak_dbfs": round(20 * math.log10(max(measured_peak*gain, 1e-12)), 3),
270
+ "warnings": [
271
+ "Instrument identities are estimates; isolation quality requires listening tests.",
272
+ "Added overtones are synthesized, not restored originals.",
273
+ "The ceiling operates on the optimized MIX; exported individual stems are not peak-limited.",
274
+ "Per-chunk zero-phase filtering can produce low-level boundary artifacts.",
275
+ ],
276
+ }
277
+ if progress: progress(1.0)
278
+ return metadata, report
279
+ except Exception:
280
+ # Never leave a partial result mistaken for a completed edit.
281
+ for name in TRACKS:
282
+ for suffix in (".wav","_preview.wav"):
283
+ (output_dir / f"{name}{suffix}").unlink(missing_ok=True)
284
+ raise
app/guardian.py ADDED
@@ -0,0 +1,145 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Preservation Guardian v0.5: interpretable transient protection and independent repair audit.
2
+
3
+ This is classical DSP signal heuristics, NOT a pretrained neural classifier.
4
+ Neither its risk labels nor the original click detector establish ground truth.
5
+ Default operation is fail-closed: protected candidate events cannot be repaired.
6
+ """
7
+ from __future__ import annotations
8
+
9
+ import hashlib
10
+ import math
11
+ from pathlib import Path
12
+
13
+ import numpy as np
14
+ import soundfile as sf
15
+
16
+ from .audio import audio_info
17
+
18
+
19
+ def label_event(x: np.ndarray, i: int, sr: int) -> dict:
20
+ """Provide explainable evidence and a conservative protection decision.
21
+
22
+ x: frames x channels. i must have 35 ms of neighboring context where
23
+ available. No model-inferred probabilities or 'musical certainty' implied.
24
+ """
25
+ if i < 2 or i >= len(x) - 2:
26
+ return {
27
+ "guardian_verdict": "protect_boundary",
28
+ "repair_allowed": False,
29
+ "guardian_reasons": ["Insufficient samples for local contextual review."],
30
+ }
31
+ width = max(16, round(0.025 * sr))
32
+ before = x[max(0, i-width):i]
33
+ after = x[i+1:min(len(x), i+1+width)]
34
+ # Insufficient context occurs near file boundaries, not chunk boundaries
35
+ # because the scanner reads overlap on both sides.
36
+ if len(before) < max(8, width // 2) or len(after) < max(8, width // 2):
37
+ return {
38
+ "guardian_verdict": "protect_boundary",
39
+ "repair_allowed": False,
40
+ "guardian_reasons": ["Not enough surrounding audio to assess onset structure."],
41
+ }
42
+ innovation = np.abs(x[i] - (x[i-1] + x[i+1]) * 0.5)
43
+ high = float(np.max(innovation))
44
+ active = int(np.count_nonzero(innovation >= max(0.035, high * 0.38)))
45
+ pre_rms = float(np.sqrt(np.mean(before * before)))
46
+ post_rms = float(np.sqrt(np.mean(after * after)))
47
+ attack_ratio = post_rms / max(pre_rms, 1e-7)
48
+ # A musical onset usually has continuation energy; impulsive digital damage
49
+ # isolated to one sample does not reliably create such continuation.
50
+ sustained_onset = bool(
51
+ post_rms > 0.012 and post_rms > pre_rms * 2.5
52
+ and (post_rms - pre_rms) > 0.009
53
+ )
54
+ # A simultaneous stereo impulse might be a drum transient OR a stereo
55
+ # corruption: protect by default rather than guessing.
56
+ multichannel = bool(x.shape[1] >= 2 and active >= 2)
57
+ reasons = []
58
+ if sustained_onset:
59
+ reasons.append("Sustained energy rises after the event; possible musical attack.")
60
+ if multichannel:
61
+ reasons.append("Impulse appears across channels; possible correlated musical transient.")
62
+ if not reasons:
63
+ reasons.append("Isolated candidate, not proof of a non-musical defect. Listening required.")
64
+ blocked = sustained_onset or multichannel
65
+ return {
66
+ "guardian_verdict": "protect_possible_music" if blocked else "review_isolated_candidate",
67
+ "repair_allowed": not blocked,
68
+ "guardian_reasons": reasons,
69
+ "evidence": {
70
+ "channels_with_impulse": active,
71
+ "energy_after_before_ratio": round(min(attack_ratio, 99999), 3),
72
+ "before_rms": round(pre_rms, 6),
73
+ "after_rms": round(post_rms, 6),
74
+ },
75
+ }
76
+
77
+
78
+ def file_sha256(path: Path) -> str:
79
+ h = hashlib.sha256()
80
+ with open(path, "rb") as source:
81
+ for block in iter(lambda: source.read(1024 * 1024), b""):
82
+ h.update(block)
83
+ return h.hexdigest()
84
+
85
+
86
+ def audit_repair(
87
+ original: Path,
88
+ clean: Path,
89
+ difference: Path,
90
+ approved_samples: list[int],
91
+ original_hash_before: str,
92
+ chunk_frames: int = 131072,
93
+ ) -> dict:
94
+ """Independent readback, samplewise preservation check and mix consistency.
95
+
96
+ 'Pass' means changes outside selected sample indices are within the declared
97
+ float32 conversion tolerance; it does NOT prove edits are musically correct.
98
+ """
99
+ info = audio_info(original)
100
+ changed_outside_max = 0.0
101
+ recon_error_max = 0.0
102
+ selected = set(int(i) for i in approved_samples)
103
+ modified_indices = set()
104
+ selected_delta_peak = 0.0
105
+ with sf.SoundFile(str(original)) as a, sf.SoundFile(str(clean)) as b, sf.SoundFile(str(difference)) as d:
106
+ if ((a.frames, a.samplerate, a.channels) != (b.frames, b.samplerate, b.channels)
107
+ or (a.frames, a.samplerate, a.channels) != (d.frames, d.samplerate, d.channels)):
108
+ raise ValueError("Guardian audit failed: mismatched audio dimensions.")
109
+ for start in range(0, info.frames, chunk_frames):
110
+ end = min(info.frames, start + chunk_frames)
111
+ x = a.read(end-start,dtype="float64",always_2d=True)
112
+ y = b.read(end-start,dtype="float64",always_2d=True)
113
+ z = d.read(end-start,dtype="float64",always_2d=True)
114
+ if not all(np.isfinite(k).all() for k in (x,y,z)):
115
+ raise ValueError("Guardian audit failed: non-finite output.")
116
+ delta = np.max(np.abs(x-y),axis=1)
117
+ unselected = np.ones(len(delta), dtype=bool)
118
+ for loc in selected:
119
+ if start <= loc < end:
120
+ unselected[loc-start] = False
121
+ if np.any(unselected):
122
+ changed_outside_max = max(changed_outside_max, float(np.max(delta[unselected])))
123
+ if np.any(~unselected):
124
+ selected_delta_peak = max(selected_delta_peak, float(np.max(delta[~unselected])))
125
+ modified_indices.update(int(start + j) for j in np.flatnonzero((delta > 2e-7) & ~unselected))
126
+ recon_error_max = max(recon_error_max, float(np.max(np.abs(x-y-z))))
127
+ hash_after = file_sha256(original)
128
+ original_untouched = original_hash_before == hash_after
129
+ # Float32 WAV stores ~7 significant digits; PCM32 inputs can quantize.
130
+ # 2e-7 absolute is an explicit tolerance, not bit-identical representation.
131
+ tolerance = 2.0e-7
132
+ passed = original_untouched and changed_outside_max <= tolerance and recon_error_max <= tolerance
133
+ return {
134
+ "engine": "independent_samplewise_guardian_audit_v0.5",
135
+ "result": "PASS" if passed else "BLOCK",
136
+ "original_hash_unchanged": original_untouched,
137
+ "approved_sample_count": len(selected),
138
+ "changed_approved_sample_count": len(modified_indices),
139
+ "unapproved_max_absolute_change": changed_outside_max,
140
+ "selected_peak_absolute_change": selected_delta_peak,
141
+ "reconstruction_max_absolute_error": recon_error_max,
142
+ "absolute_float32_tolerance": tolerance,
143
+ "interpretation": "Numerical preservation outside approved sample frames, not perceptual proof.",
144
+ "air_and_reverb": "Samples outside approved indices preserved to float32 tolerance; edited samples remain uncertain.",
145
+ }
app/mini_model.py ADDED
@@ -0,0 +1,280 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """OMEGA-TAG Mini v0.5: tiny, OFFLINE multilabel spectral-event model.
2
+
3
+ Model shipped with project uses *synthetic* two-stage training: isolated/pair
4
+ pretraining, then overlapping-mixture fine-tuning. It has NEVER been trained
5
+ on real labelled music, so it must not claim reliable instrument identities.
6
+ All scores are uncalibrated classifier activations, not probabilities.
7
+ No remote downloads or unsafe pickle deserialization.
8
+ """
9
+ from __future__ import annotations
10
+
11
+ from pathlib import Path
12
+ import hashlib
13
+ import json
14
+ import math
15
+
16
+ import numpy as np
17
+ import soundfile as sf
18
+ from scipy.signal import resample_poly
19
+
20
+ LABELS = ("bass_sustain", "kick_like", "snare_like", "hi_hat_like",
21
+ "harmonic_mid", "noise_texture")
22
+ FRIENDLY = {
23
+ "bass_sustain": "Tieffrequente, anhaltende Töne / Bass-Verdacht",
24
+ "kick_like": "Tieffrequente Impulse / Kick-Verdacht",
25
+ "snare_like": "Breitbandige Mitten-Impulse / Snare-Verdacht",
26
+ "hi_hat_like": "Helle, kurze Impulse / Hi-Hat-Verdacht",
27
+ "harmonic_mid": "Harmonische Mitten / Melodie-Verdacht",
28
+ "noise_texture": "Rauschähnliche Textur (kann musikalisch sein)",
29
+ }
30
+ SR = 8000
31
+ N = 4096
32
+ MODEL_FILE = Path(__file__).resolve().parent / "models" / "omega_tag_mini_v1.npz"
33
+ BANDS = ((25,80),(80,180),(180,400),(400,900),(900,1900),(1900,3500),(3500,3950))
34
+
35
+ def features(x: np.ndarray) -> np.ndarray:
36
+ """32 stable feature components from 0.512s mono resampled audio.
37
+
38
+ Features are descriptive and deliberately do not identify instruments
39
+ through semantic embedding / pretrained audio foundation features.
40
+ """
41
+ x = np.asarray(x, dtype=np.float64).reshape(-1)
42
+ if len(x) != N:
43
+ raise ValueError(f"Expected {N} samples, got {len(x)}")
44
+ if not np.isfinite(x).all():
45
+ raise ValueError("Non-finite features input")
46
+ # Fixed frames. Use per-frame relative energies for spectral activity.
47
+ windows = np.stack([x[i:i+1024] for i in range(0, N-1024+1, 384)], axis=0)
48
+ fft = np.abs(np.fft.rfft(windows*np.hanning(1024), axis=-1))**2+1e-15
49
+ hz = np.fft.rfftfreq(1024, 1./SR)
50
+ bands=np.stack([fft[:,(hz>=lo)&(hz<hi)].sum(axis=1) for lo,hi in BANDS],axis=1)
51
+ frame_energy = fft.sum(axis=1,keepdims=True)
52
+ proportion=bands/frame_energy
53
+ avg=proportion.mean(axis=0)
54
+ variability=proportion.std(axis=0)
55
+ logenergy=np.log10(np.maximum(bands.mean(axis=0),1e-10))
56
+ logtotal=np.log10(max(float(np.mean(x*x)),1e-10))
57
+ flatness=(np.exp(np.mean(np.log(fft),axis=1))/np.mean(fft,axis=1)).mean()
58
+ zcr=np.mean(np.signbit(x[1:])!=np.signbit(x[:-1]))
59
+ power=np.mean(windows*windows,axis=1)
60
+ onset=np.maximum(np.diff(power),0)
61
+ novelty=float(np.max(onset)/(np.mean(power)+1e-12))
62
+ fluctuation=float(np.std(power)/(np.mean(power)+1e-12))
63
+ crest=float(np.max(np.abs(x))/(math.sqrt(float(np.mean(x*x)))+1e-10))
64
+ spectral_flux=np.maximum(np.diff(np.sqrt(fft),axis=0),0).sum()/np.sqrt(fft).sum()
65
+ # 7+7+7+7 = 28, then 7 metadata => 35
66
+ result=np.r_[avg,variability,np.clip(logenergy,-10,7),
67
+ np.clip(logenergy-logenergy.mean(),-12,12),
68
+ logtotal, flatness,zcr,np.log1p(novelty),
69
+ np.log1p(fluctuation), np.log1p(crest),spectral_flux]
70
+ return np.asarray(result,dtype=np.float32)
71
+
72
+ FEATURE_COUNT = len(features(np.zeros(N,dtype=np.float32)))
73
+
74
+ def synthetic_signal(label: str, rng: np.random.Generator) -> np.ndarray:
75
+ """Generated test/training signals, NOT copyrighted music nor real stems."""
76
+ t=np.arange(N)/SR
77
+ x=np.zeros(N,dtype=np.float64)
78
+ if label=="bass_sustain":
79
+ freq=rng.uniform(46,160)
80
+ for harmonic in (1,2,3):
81
+ x+=np.sin(2*np.pi*(harmonic*freq*t+rng.uniform(0,1)))*(.6/harmonic**1.3)
82
+ x*=.4+.6*np.sin(2*np.pi*rng.uniform(.3,2)*t+rng.uniform(0,6))**2
83
+ elif label=="kick_like":
84
+ for loc in rng.choice(np.arange(0,N-850,300),size=int(rng.integers(1,4)),replace=False):
85
+ k=np.arange(min(1500,N-loc)); time=k/SR
86
+ phase=2*np.pi*(50*time+90*(1-np.exp(-time*32))/32)
87
+ env=np.exp(-time*rng.uniform(17,35))
88
+ x[loc:loc+len(k)] += np.sin(phase)*env
89
+ elif label=="snare_like":
90
+ for loc in rng.choice(np.arange(0,N-450,280),size=int(rng.integers(1,4)),replace=False):
91
+ k=np.arange(min(850,N-loc)); time=k/SR
92
+ pulse=rng.standard_normal(len(k))
93
+ pulse=np.r_[0,np.diff(pulse)]
94
+ x[loc:loc+len(k)] += pulse*np.exp(-time*27)*.3
95
+ elif label=="hi_hat_like":
96
+ for loc in rng.choice(np.arange(0,N-150,170),size=int(rng.integers(2,7)),replace=False):
97
+ k=np.arange(min(380,N-loc));time=k/SR
98
+ noise=rng.standard_normal(len(k))
99
+ noise=np.r_[0,np.diff(noise)]
100
+ x[loc:loc+len(k)]+=noise*np.exp(-time*85)*.35
101
+ elif label=="harmonic_mid":
102
+ for freq in rng.uniform(200,900,size=int(rng.integers(1,4))):
103
+ x+=np.sin(2*np.pi*(freq*t+rng.uniform(0,1)))*.4
104
+ x*=.3+.7*(np.sin(np.pi*np.clip(t/rng.uniform(.25,.85),0,1))**2)
105
+ elif label=="noise_texture":
106
+ noise=rng.standard_normal(N)
107
+ if rng.random()<.6:
108
+ noise=np.convolve(noise,np.ones(37)/37,mode='same')
109
+ x += noise*.3
110
+ return x.astype(np.float32)
111
+
112
+ def synthetic_case(rng:np.random.Generator, phase: str) -> tuple[np.ndarray,np.ndarray]:
113
+ max_sources=2 if phase=="pretrain" else 5
114
+ count=int(rng.integers(1,max_sources+1))
115
+ indices=rng.choice(len(LABELS),size=count,replace=False)
116
+ y=np.zeros(len(LABELS),dtype=np.float32)
117
+ x=np.zeros(N,dtype=np.float32)
118
+ for idx in indices:
119
+ y[idx]=1.
120
+ x+=synthetic_signal(LABELS[idx],rng)*rng.uniform(.2,1.0)
121
+ # Apply nonstationary gain, external hum/noise and polarity changes to test
122
+ # robustness; all remain synthetic.
123
+ if rng.random()<.4:x*=np.linspace(rng.uniform(.35,1),rng.uniform(.35,1),N)
124
+ if rng.random()<.5:x+=rng.standard_normal(N).astype(np.float32)*rng.uniform(0,.016)
125
+ if rng.random()<.5:x*=-1
126
+ peak=max(float(np.max(np.abs(x))),1e-8)
127
+ x*=float(rng.uniform(.15,.8))/peak
128
+ return x,y
129
+
130
+ def generate_training(n:int,seed:int,phase:str):
131
+ rng=np.random.default_rng(seed)
132
+ X=np.empty((n,FEATURE_COUNT),np.float32)
133
+ Y=np.empty((n,len(LABELS)),np.float32)
134
+ for i in range(n):
135
+ x,y=synthetic_case(rng,phase)
136
+ X[i]=features(x);Y[i]=y
137
+ return X,Y
138
+
139
+ def _sigmoid(z): return 1/(1+np.exp(-np.clip(z,-35,35)))
140
+
141
+ def _net(X,W1,b1,W2,b2):
142
+ h=np.tanh(X@W1+b1)
143
+ return h,_sigmoid(h@W2+b2)
144
+
145
+ def train_model(destination:Path=MODEL_FILE,seed:int=25,epochs1:int=90,epochs2:int=105,
146
+ pretrain_count:int=650,finetune_count:int=1100) -> dict:
147
+ """Offline reproducible 2-stage neural training, using only synthetic audio.
148
+
149
+ Stage 2 is real parameter fine-tuning of stage 1 weights but NOT transfer
150
+ learning from a commercial foundation model or real instrument recordings.
151
+ """
152
+ rng=np.random.default_rng(seed)
153
+ xp,yp=generate_training(pretrain_count,seed,"pretrain")
154
+ xf,yf=generate_training(finetune_count,seed+1,"finetune")
155
+ xt,yt=generate_training(300,seed+2,"finetune")
156
+ mu=xp.mean(axis=0)
157
+ sigma=np.maximum(xp.std(axis=0),.08)
158
+ xp=np.clip((xp-mu)/sigma,-8,8)
159
+ xf=np.clip((xf-mu)/sigma,-8,8)
160
+ xt=np.clip((xt-mu)/sigma,-8,8)
161
+ hidden=32
162
+ W1=(rng.standard_normal((FEATURE_COUNT,hidden))*.15).astype(np.float64)
163
+ b1=np.zeros(hidden)
164
+ W2=(rng.standard_normal((hidden,len(LABELS)))*.15).astype(np.float64)
165
+ b2=np.zeros(len(LABELS))
166
+ params=[W1,b1,W2,b2]
167
+ mt=[np.zeros_like(p) for p in params]
168
+ vt=[np.zeros_like(p) for p in params]
169
+ step=0
170
+ def loop(X,Y,epochs,lr):
171
+ nonlocal step
172
+ for epoch in range(epochs):
173
+ for batchidx in np.array_split(rng.permutation(len(X)),max(1,len(X)//96)):
174
+ data,labels=X[batchidx],Y[batchidx]
175
+ h,prob=_net(data,*params)
176
+ grad=(prob-labels)/len(batchidx)
177
+ g2=h.T@grad
178
+ gb2=grad.sum(axis=0)
179
+ gh=(grad@W2.T)*(1-h*h)
180
+ g1=data.T@gh
181
+ gb1=gh.sum(axis=0)
182
+ for idx, g in enumerate((g1,gb1,g2,gb2)):
183
+ step+=1 if idx==0 else 0
184
+ mt[idx][:]=.9*mt[idx]+.1*g
185
+ vt[idx][:]=.999*vt[idx]+.001*g*g
186
+ mhat=mt[idx]/(1-.9**step)
187
+ vhat=vt[idx]/(1-.999**step)
188
+ params[idx]-=lr*mhat/(np.sqrt(vhat)+1e-8)
189
+ loop(xp,yp,epochs1,.012)
190
+ loop(xf,yf,epochs2,.006)
191
+ h,pred=_net(xt,*params)
192
+ estimates=pred>=.5
193
+ precision=float(np.sum((estimates==1)&(yt==1))/max(1,np.sum(estimates==1)))
194
+ recall=float(np.sum((estimates==1)&(yt==1))/max(1,np.sum(yt==1)))
195
+ acc=float(np.mean(estimates==yt))
196
+ destination.parent.mkdir(parents=True,exist_ok=True)
197
+ np.savez_compressed(destination,
198
+ W1=W1.astype(np.float32),b1=b1.astype(np.float32),
199
+ W2=W2.astype(np.float32),b2=b2.astype(np.float32),
200
+ mu=mu.astype(np.float32),sigma=sigma.astype(np.float32),
201
+ model_schema=np.array("omega_mini_synthetic_v1"),
202
+ labels=np.asarray(LABELS))
203
+ return {"stage1":"synthetic isolated/pair pretraining",
204
+ "stage2":"fine-tuning on synthetic overlapping mixtures",
205
+ "heldout_synthetic_precision":round(precision,3),
206
+ "heldout_synthetic_recall":round(recall,3),
207
+ "heldout_synthetic_label_accuracy":round(acc,3),
208
+ "validation_dataset":"300 held-out synthetic mixtures, NOT real-world benchmark",
209
+ "checkpoint":str(destination),
210
+ "checkpoint_sha256":hashlib.sha256(destination.read_bytes()).hexdigest(),
211
+ "architecture":f"feature({FEATURE_COUNT}) -> tanh(32) -> sigmoid({len(LABELS)})",
212
+ "train_examples":pretrain_count+finetune_count}
213
+
214
+ def load_model(path:Path=MODEL_FILE)->dict:
215
+ if not path.is_file():
216
+ raise FileNotFoundError("Mini model missing. Run python -m app.mini_model --train")
217
+ with np.load(path,allow_pickle=False) as f:
218
+ params={k:f[k].copy() for k in ("W1","b1","W2","b2","mu","sigma")}
219
+ schema=str(f["model_schema"].item())
220
+ labels=tuple(str(x) for x in f["labels"])
221
+ if schema!="omega_mini_synthetic_v1" or labels!=LABELS:
222
+ raise ValueError("Unsupported/incompatible mini model weights")
223
+ if params["W1"].shape!=(FEATURE_COUNT,32) or params["W2"].shape!=(32,len(LABELS)):
224
+ raise ValueError("Corrupt mini model dimensions")
225
+ if not all(np.isfinite(v).all() for v in params.values()):
226
+ raise ValueError("Non-finite model weights")
227
+ return params
228
+
229
+ def predict_features(x:np.ndarray,model:dict)->np.ndarray:
230
+ scaled=np.clip((x-model["mu"])/model["sigma"],-8,8)
231
+ return _net(scaled,model["W1"],model["b1"],model["W2"],model["b2"])[1]
232
+
233
+ def inspect_file(path:Path,max_windows:int=12, model_path:Path=MODEL_FILE)->dict:
234
+ """Inspect strategically sampled 0.512s segments; bounded RAM, any duration."""
235
+ model=load_model(model_path)
236
+ scores=[]
237
+ with sf.SoundFile(str(path)) as source:
238
+ if source.frames<=0:
239
+ raise ValueError("Empty audio")
240
+ count=min(max_windows,max(1,math.ceil(source.frames/source.samplerate/.65)))
241
+ positions=np.linspace(0,max(0,source.frames-int(.55*source.samplerate)),count,dtype=int)
242
+ for pos in positions:
243
+ source.seek(int(pos))
244
+ block=source.read(min(source.frames-int(pos),int(.65*source.samplerate)),
245
+ dtype="float32",always_2d=True)
246
+ if not np.isfinite(block).all():raise ValueError("Invalid audio samples")
247
+ mono=block.mean(axis=1)
248
+ if len(mono)>0:
249
+ g=math.gcd(source.samplerate,SR)
250
+ mono=resample_poly(mono,SR//g,source.samplerate//g)
251
+ if len(mono)<N:mono=np.pad(mono,(0,N-len(mono)))
252
+ mono=mono[:N]
253
+ scores.append(predict_features(features(mono),model))
254
+ pred=np.stack(scores)
255
+ score=np.mean(pred,axis=0)*.6+np.max(pred,axis=0)*.4
256
+ return {
257
+ "model":"OMEGA-TAG Mini v1",
258
+ "model_kind":"tiny_neural_network__synthetic_pretrained_and_finetuned",
259
+ "checkpoint_sha256":hashlib.sha256(Path(model_path).read_bytes()).hexdigest(),
260
+ "input_sha256":hashlib.sha256(Path(path).read_bytes()).hexdigest(),
261
+ "sampled_windows":len(scores),
262
+ "scope":"SYNTHETIC SIGNAL TEXTURE TAGGING; no verified instrument identification",
263
+ "score_definition":"uncalibrated neural activation; NOT real-world probability",
264
+ "detections":[{"id":label,"label":FRIENDLY[label],"score":round(float(prob),4),
265
+ "suggested":bool(prob>=.55),
266
+ "note":"Hypothesis only. May be wrong for real recordings."}
267
+ for label,prob in zip(LABELS,score)],
268
+ "limitations":["No pretrained music foundation model",
269
+ "No isolated real music-stem training data",
270
+ "Scores are not calibrated for real recordings",
271
+ "Short sampled windows may miss rare or late events"],
272
+ }
273
+
274
+ if __name__=="__main__":
275
+ import sys
276
+ if sys.argv[1:]==["--train"]:
277
+ details=train_model()
278
+ print(json.dumps(details,indent=2))
279
+ else:
280
+ print("Use: python -m app.mini_model --train")
app/mixer.py ADDED
@@ -0,0 +1,160 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """ABSOLUTION Ω arrangement mixer: offline stem mix with non-destructive gain/pan/FX.
2
+
3
+ Only real stem files issued by separation can be mixed. Planning hypotheses
4
+ never become audible tracks. No mastering / denoising is implicit.
5
+ """
6
+ from __future__ import annotations
7
+
8
+ import json
9
+ import math
10
+ import shutil
11
+ import subprocess
12
+ import tempfile
13
+ from pathlib import Path
14
+
15
+ import numpy as np
16
+ import soundfile as sf
17
+ from scipy.signal import butter, sosfilt, sosfilt_zi
18
+
19
+
20
+ def rubberband_available() -> bool:
21
+ exe=shutil.which("ffmpeg")
22
+ if not exe:return False
23
+ try:
24
+ out=subprocess.run([exe,"-hide_banner","-filters"],capture_output=True,text=True,timeout=8)
25
+ return "rubberband" in out.stdout
26
+ except (OSError,subprocess.TimeoutExpired):
27
+ return False
28
+
29
+
30
+ def render_mix(sources:dict[str,Path], settings:dict, destination:Path,
31
+ progress=None) -> dict:
32
+ """Chunked deterministic float32 WAV mixer. Returns audited peak and metadata.
33
+
34
+ Source files must be sample-aligned, with identical sample rate and frame
35
+ count. Effects are independent per stem and maintain filter state.
36
+ """
37
+ if not sources:raise ValueError("No real separated stems are available")
38
+ if len(sources)>128:raise ValueError("Maximum 128 simultaneously mixed stems for resource safety")
39
+ desired=settings.get("tracks") or {}
40
+ if set(desired)-set(sources):
41
+ raise ValueError("Unknown track names in mixer settings")
42
+ infos={name:sf.info(str(path)) for name,path in sources.items()}
43
+ sr=next(iter(infos.values())).samplerate
44
+ frames=next(iter(infos.values())).frames
45
+ if any(i.samplerate!=sr or i.frames!=frames or i.channels not in (1,2) for i in infos.values()):
46
+ raise ValueError("Stem sample rates, lengths or channels are incompatible")
47
+ # Preserve channel topology for original stereo recordings.
48
+ channels=max(i.channels for i in infos.values())
49
+ is_solo=any(bool(desired.get(n,{}).get("solo",False)) for n in sources)
50
+ track_state={}
51
+ for name in sources:
52
+ p=desired.get(name,{})
53
+ gain=float(p.get("gain_db",0));pan=float(p.get("pan",0))
54
+ hp=float(p.get("highpass_hz",0));lp=float(p.get("lowpass_hz",0))
55
+ width=float(p.get("width",1));drive=float(p.get("drive",0))
56
+ if not (-48<=gain<=12 and -1<=pan<=1 and 0<=hp<=400 and
57
+ 0<=lp<=min(18000,sr*.47) and 0<=drive<=1 and 0<=width<=2):
58
+ raise ValueError("Mixer parameter outside supported range")
59
+ if hp and lp and hp>=lp:raise ValueError("Highpass must be below lowpass")
60
+ chain=[]
61
+ for typ,freq in (("highpass",hp),("lowpass",lp)):
62
+ if freq:
63
+ sos=butter(2,freq,btype=typ,fs=sr,output="sos")
64
+ zi=np.zeros((len(sos),2,channels),np.float64)
65
+ chain.append([sos,zi])
66
+ track_state[name]=(p,10**(gain/20),pan,drive,width,chain)
67
+ destination.parent.mkdir(parents=True,exist_ok=True)
68
+ tmp=destination.with_name(f".{destination.stem}.tmp.wav")
69
+ peak=0.;rms_sq=0.;n=0
70
+ try:
71
+ from contextlib import ExitStack
72
+ with ExitStack() as stack:
73
+ readers={k:stack.enter_context(sf.SoundFile(str(v),"r")) for k,v in sources.items()}
74
+ out=stack.enter_context(sf.SoundFile(str(tmp),"w",samplerate=sr,
75
+ channels=channels,subtype="FLOAT",format="WAV"))
76
+ blocksize=32768
77
+ for start in range(0,frames,blocksize):
78
+ count=min(blocksize,frames-start)
79
+ mixed=np.zeros((count,channels),dtype=np.float64)
80
+ for name,src in readers.items():
81
+ x=src.read(count,dtype="float64",always_2d=True)
82
+ if len(x)!=count:raise ValueError(f"Incomplete stem {name}")
83
+ p,gain,pan,drive,width,chain=track_state[name]
84
+ if bool(p.get("mute",False)) or (is_solo and not p.get("solo",False)):
85
+ continue
86
+ if x.shape[1]==1 and channels==2:x=np.repeat(x,2,axis=1)
87
+ if x.shape[1]!=channels:raise ValueError("Channel mismatch")
88
+ for entry in chain:
89
+ # One persistent state per channel, chunk boundary safe.
90
+ sos,zi=entry
91
+ for c in range(channels):
92
+ x[:,c],zi[:,:,c]=sosfilt(sos,x[:,c],zi=zi[:,:,c])
93
+ if drive:
94
+ amount=1+drive*5
95
+ x=np.tanh(x*amount)/amount
96
+ if channels==2:
97
+ mid=(x[:,0]+x[:,1])*.5
98
+ side=(x[:,0]-x[:,1])*.5*width
99
+ left=mid+side;right=mid-side
100
+ x=np.column_stack((left,right))
101
+ # Constant center gain and smoothly attenuate opposite side.
102
+ gl=math.cos((pan+1)*math.pi/4)*math.sqrt(2)
103
+ gr=math.sin((pan+1)*math.pi/4)*math.sqrt(2)
104
+ x*=np.array([gl,gr])
105
+ mixed+=x*gain
106
+ if not np.isfinite(mixed).all():raise ValueError("Non-finite mixer output")
107
+ peak=max(peak,float(np.max(np.abs(mixed))) if mixed.size else 0)
108
+ rms_sq+=float(np.sum(mixed*mixed));n+=mixed.size
109
+ out.write(mixed.astype(np.float32))
110
+ if progress:progress((start+count)/frames)
111
+ tmp.replace(destination)
112
+ finally:
113
+ tmp.unlink(missing_ok=True)
114
+ tempo=float(settings.get("tempo",1))
115
+ pitch=float(settings.get("pitch_semitones",0))
116
+ if not (0.5<=tempo<=2 and -12<=pitch<=12):raise ValueError("Invalid tempo/pitch")
117
+ if abs(tempo-1)>1e-5 or abs(pitch)>1e-5:
118
+ if not rubberband_available():
119
+ destination.unlink(missing_ok=True)
120
+ raise ValueError("Independent tempo/pitch needs FFmpeg with rubberband filter")
121
+ shifted=destination.with_name("render_transformed.wav")
122
+ try:
123
+ args=["ffmpeg","-nostdin","-hide_banner","-loglevel","error","-y","-i",str(destination),
124
+ "-af",f"rubberband=tempo={tempo:.6f}:pitch={2**(pitch/12):.8f}",
125
+ "-c:a","pcm_f32le",str(shifted)]
126
+ p=subprocess.run(args,capture_output=True,text=True)
127
+ if p.returncode!=0:raise ValueError("Rubberband processing failed: "+p.stderr[-300:])
128
+ shifted.replace(destination)
129
+ finally:
130
+ shifted.unlink(missing_ok=True)
131
+ with sf.SoundFile(destination) as f:
132
+ peak=0;rms_sq=0;n=0
133
+ while True:
134
+ b=f.read(32768,dtype="float32",always_2d=True)
135
+ if len(b)==0:break
136
+ peak=max(peak,float(np.max(np.abs(b))))
137
+ rms_sq+=float(np.sum(b.astype(np.float64)**2));n+=b.size
138
+ return {"samplerate":sr,"channels":channels,"source_frames":frames,
139
+ "output_frames":sf.info(str(destination)).frames,
140
+ "peak_dbfs":round(20*math.log10(max(peak,1e-12)),3),
141
+ "rms_dbfs":round(20*math.log10(max(math.sqrt(rms_sq/max(n,1)),1e-12)),3),
142
+ "float_wav":True,"clip_warning":peak>1,
143
+ "isolation":"Only actual separated stems; no proposed tracks",
144
+ "tempo":tempo,"pitch_semitones":pitch}
145
+
146
+
147
+ def sampled_peaks(path:Path, size:int=360)->dict:
148
+ """Downsample visual amplitude envelope by sampling short blocks; not an exhaustive peak scan."""
149
+ info=sf.info(str(path))
150
+ if info.channels not in (1,2):raise ValueError("Only mono/stereo available")
151
+ size=max(64,min(size,1000))
152
+ points=[]
153
+ with sf.SoundFile(str(path)) as f:
154
+ for pos in np.linspace(0,max(0,info.frames-512),size,dtype=int):
155
+ f.seek(int(pos))
156
+ block=f.read(min(512,info.frames-int(pos)),dtype="float32",always_2d=True)
157
+ points.append(round(float(np.max(np.abs(block))) if block.size else 0,5))
158
+ return {"samples":points,"duration":round(info.duration,3),
159
+ "samplerate":info.samplerate,"sample_method":"sparse_windows_512frames",
160
+ "peak_reliability":"visualization only; not exhaustive"}
app/models/omega_tag_mini_v1.npz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4fd952daf742ab4c8e0fbf31b19b25f2e1baa124e304f04bd0a5f1641d90dfad
3
+ size 7030
app/noise.py ADDED
@@ -0,0 +1,253 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """NOISE-CORE Ω — preservation-first detection and explicitly approved sample repairs.
2
+
3
+ Important: a click hypothesis is *not* proof that the sample is noise.
4
+ Nothing is modified during the scan. Repair needs indices explicitly
5
+ selected by a user and always produces an exact conceptual difference stem.
6
+
7
+ No network, pretrained model, or destructive replacement is performed.
8
+ """
9
+ from __future__ import annotations
10
+
11
+ import math
12
+ from contextlib import ExitStack
13
+ from dataclasses import dataclass
14
+ from pathlib import Path
15
+ from typing import Callable
16
+
17
+ import numpy as np
18
+ import soundfile as sf
19
+ from scipy.signal import welch
20
+
21
+ from .audio import AudioError, audio_info
22
+ from .guardian import label_event
23
+
24
+
25
+ @dataclass(frozen=True)
26
+ class RepairParams:
27
+ strength: float = 0.8 # Blend factor for just the selected click sample
28
+
29
+
30
+ def _impulses(x: np.ndarray, absolute_start: int, sr: int) -> list[dict]:
31
+ """Find high-salience isolated, single-sample discontinuities.
32
+
33
+ Detection deliberately has high thresholds to prioritize false-negative
34
+ rather than false-positive results. No score is a probability.
35
+ """
36
+ if x.shape[0] < 9:
37
+ return []
38
+ # x has 2D shape: frames x channels
39
+ center = x[1:-1]
40
+ left = x[:-2]
41
+ right = x[2:]
42
+ innovation = np.max(np.abs(center - 0.5 * (left + right)), axis=1)
43
+ # Robust local background for this block. Frequency-rich content naturally
44
+ # has large second derivatives; it will not pass the sharp outlier threshold.
45
+ p995 = float(np.percentile(innovation, 99.5))
46
+ threshold = max(0.065, p995 * 6.0)
47
+ candidates = np.flatnonzero(innovation > threshold)
48
+ hits = []
49
+ for offset in candidates:
50
+ idx = int(offset) + 1
51
+ # Opposite slopes (a single-sample impulse) and comparatively similar
52
+ # neighbors. Music transients can still pass: user review is mandatory.
53
+ a = x[idx] - x[idx - 1]
54
+ b = x[idx + 1] - x[idx]
55
+ channel = int(np.argmax(np.abs(x[idx] - .5 * (x[idx-1] + x[idx+1]))))
56
+ if a[channel] * b[channel] >= 0:
57
+ continue
58
+ if abs(x[idx-1,channel]-x[idx+1,channel]) > 0.28 * max(
59
+ abs(a[channel]), abs(b[channel]), 1e-8):
60
+ continue
61
+ score = float(innovation[offset] / max(threshold,1e-12))
62
+ hits.append({
63
+ "sample": int(absolute_start + idx),
64
+ "time_seconds": round((absolute_start + idx)/sr, 6),
65
+ "salience": round(min(score, 999), 3),
66
+ "kind": "single_sample_impulse_hypothesis",
67
+ "warning": "May be a genuine musical transient. Manual approval required.",
68
+ })
69
+ return hits
70
+
71
+
72
+ def _tonal_indicators(source: sf.SoundFile, samplerate: int, total_frames: int) -> list[dict]:
73
+ """Very rough hum-frequency indicators, never identified as certain noise."""
74
+ size = min(total_frames, max(2048, 4 * samplerate))
75
+ if size < max(512, samplerate // 4):
76
+ return []
77
+ positions = sorted(set([0, max(0,(total_frames-size)//2), max(0,total_frames-size)]))
78
+ powers = []
79
+ for pos in positions:
80
+ source.seek(pos)
81
+ sample = source.read(size,dtype="float64",always_2d=True)
82
+ mono = np.mean(sample,axis=1)
83
+ nperseg=min(len(mono),max(4096, samplerate))
84
+ freq, density=welch(mono,fs=samplerate,nperseg=nperseg)
85
+ powers.append(density)
86
+ values = np.mean(powers,axis=0)
87
+ indicators = []
88
+ for hz in (50.0,60.0,100.0,120.0):
89
+ if hz >= samplerate*.48:
90
+ continue
91
+ idx=int(np.argmin(abs(freq-hz)))
92
+ floor = np.median(values[(freq>=hz-12)&(freq<=hz+12)])
93
+ ratio = float(values[idx] / max(floor, 1e-16))
94
+ if ratio>12.0 and values[idx]>1e-12:
95
+ indicators.append({
96
+ "frequency_hz": hz,
97
+ "peak_to_local_median_db": round(10*math.log10(ratio),2),
98
+ "classification": "ambiguous_tonal_peak",
99
+ "warning": "A bass note or musical harmonic can cause this peak. No notch applied."
100
+ })
101
+ return indicators
102
+
103
+
104
+ def inspect_noise_file(
105
+ input_path: Path,
106
+ progress: Callable[[float],None] | None=None,
107
+ chunk_frames: int=131072,
108
+ max_events: int=400
109
+ ) -> dict:
110
+ """Bounded-memory scan. No original modification, no auto repair."""
111
+ info = audio_info(input_path)
112
+ total = info.frames
113
+ events = []
114
+ total_hits = 0
115
+ last_hit = -1000000
116
+ guard = max(4, int(round(info.samplerate * 0.04)))
117
+ with sf.SoundFile(str(input_path),"r") as source:
118
+ for start in range(0,total,chunk_frames):
119
+ end=min(total,start+chunk_frames)
120
+ left=max(0,start-guard)
121
+ right=min(total,end+guard)
122
+ source.seek(left)
123
+ block=source.read(right-left,dtype="float64",always_2d=True)
124
+ if not np.isfinite(block).all() or len(block)!=(right-left):
125
+ raise AudioError("Nonfinite or truncated input.")
126
+ for event in _impulses(block,left,info.samplerate):
127
+ loc=event["sample"]
128
+ if not (start<=loc<end):
129
+ continue
130
+ # Suppress clusters within 2 milliseconds, which are less
131
+ # safely modeled as isolated one-sample clicks.
132
+ if loc-last_hit <= max(2,int(info.samplerate*.002)):
133
+ continue
134
+ event.update(label_event(block, loc-left, info.samplerate))
135
+ last_hit=loc
136
+ total_hits+=1
137
+ if len(events)<max_events:
138
+ events.append(event)
139
+ if progress:
140
+ progress(.87*(end/total))
141
+ tonal=_tonal_indicators(source,info.samplerate,total)
142
+ if progress:
143
+ progress(1.)
144
+ return {
145
+ "mode":"inspect_only",
146
+ "guardian_engine":"explainable_signal_heuristics_v0.5_NOT_neural_AI",
147
+ "protected_event_count":sum(not x.get("repair_allowed",False) for x in events),
148
+ "reviewable_event_count":sum(x.get("repair_allowed",False) for x in events),
149
+ "auto_repair":False,
150
+ "input_frames":total,
151
+ "samplerate":info.samplerate,
152
+ "events":events,
153
+ "event_count":total_hits,
154
+ "event_limit_reached":total_hits>len(events),
155
+ "tonal_indicators":tonal,
156
+ "noise_profile_ready":False,
157
+ "broadband_denoise_available":False,
158
+ "reason":"No noise-only region verified; automatic denoising could erase air, reverberation and tones.",
159
+ "notes":[
160
+ "Click and hum proposals are uncertain: musical transients and bass notes may be mistaken for noise.",
161
+ "Guardian protects possible musical attacks and correlated stereo impulses from repair.",
162
+ "Inspection does not alter music. Manual sample selection is required for any repair.",
163
+ "This version does not remove continuous hiss or tonal hum automatically."
164
+ ]
165
+ }
166
+
167
+
168
+ def repair_noise_file(
169
+ input_path:Path,
170
+ output_dir:Path,
171
+ approved_samples:list[int],
172
+ params:RepairParams=RepairParams(),
173
+ progress: Callable[[float],None]|None=None,
174
+ chunk_frames:int=131072,
175
+ ) -> tuple[dict,dict]:
176
+ """Apply only approved repairs; create (original = clean + difference).
177
+
178
+ Uses an isolated-sample linear interpolation as a *hypothesis* for a
179
+ click. It cannot mathematically guarantee that no music is affected.
180
+ """
181
+ if not (0<=params.strength<=1):
182
+ raise ValueError("Repair strength must be between 0 and 1.")
183
+ info=audio_info(input_path)
184
+ unique=sorted(set(int(x) for x in approved_samples))
185
+ if len(unique)>400 or any(x<2 or x>=info.frames-2 for x in unique):
186
+ raise ValueError("Invalid or excessive approved sample indices.")
187
+ output_dir.mkdir(parents=True,exist_ok=True)
188
+ max_err=0.0
189
+ changed=0
190
+ peak_change=0.0
191
+ energy=0.0
192
+ with ExitStack() as stack:
193
+ input_file=stack.enter_context(sf.SoundFile(str(input_path),"r"))
194
+ outs={}
195
+ for name in ("clean","difference"):
196
+ outs[name]=stack.enter_context(sf.SoundFile(
197
+ str(output_dir/f"{name}.wav"),"w",samplerate=info.samplerate,
198
+ channels=info.channels,format="WAV",subtype="FLOAT"))
199
+ outs[name+"_preview"]=stack.enter_context(sf.SoundFile(
200
+ str(output_dir/f"{name}_preview.wav"),"w",samplerate=info.samplerate,
201
+ channels=info.channels,format="WAV",subtype="PCM_16"))
202
+ cursor=0
203
+ for start in range(0,info.frames,chunk_frames):
204
+ end=min(info.frames,start+chunk_frames)
205
+ left=max(0,start-2)
206
+ right=min(info.frames,end+2)
207
+ input_file.seek(left)
208
+ x=input_file.read(right-left,dtype="float64",always_2d=True)
209
+ if len(x)!=right-left or not np.isfinite(x).all():
210
+ raise AudioError("Invalid or truncated audio.")
211
+ i0=start-left
212
+ original=x[i0:i0+end-start].copy()
213
+ clean=original.copy()
214
+ while cursor<len(unique) and unique[cursor]<end:
215
+ loc=unique[cursor]
216
+ if loc>=start:
217
+ index=loc-left
218
+ interp=.5*(x[index-1]+x[index+1])
219
+ clean[loc-start]=(1-params.strength)*x[index]+params.strength*interp
220
+ changed+=1
221
+ cursor+=1
222
+ difference=original-clean
223
+ reconstruction=np.max(np.abs(original-(clean+difference)))
224
+ max_err=max(max_err,float(reconstruction))
225
+ peak_change=max(peak_change,float(np.max(np.abs(difference))))
226
+ energy+=float(np.sum(np.square(difference),dtype=np.float64))
227
+ outs["clean"].write(clean)
228
+ outs["difference"].write(difference)
229
+ outs["clean_preview"].write(np.clip(clean,-1,1))
230
+ outs["difference_preview"].write(np.clip(difference,-1,1))
231
+ if progress:
232
+ progress(end/info.frames)
233
+ tracks={
234
+ name: {"name":name,"master":f"{name}.wav",
235
+ "preview":f"{name}_preview.wav","duration_seconds":round(info.frames/info.samplerate,4)}
236
+ for name in ("clean","difference")
237
+ }
238
+ report={
239
+ "mode":"manual_selected_single_sample_interpolation",
240
+ "selected_sample_count":len(unique),
241
+ "changed_sample_frames":changed,
242
+ "repair_strength":params.strength,
243
+ "peak_absolute_change":peak_change,
244
+ "difference_rms":math.sqrt(energy/(info.frames*info.channels)),
245
+ "reconstruction_max_absolute_error":max_err,
246
+ "reconstruction_consistent":max_err<1e-10,
247
+ "no_auto_denoise":True,
248
+ "warning":"A removed signal may contain authentic music. Listen to the difference stem.",
249
+ "original_file_untouched":True,
250
+ "master_format":"WAV float32",
251
+ "preview_format":"WAV PCM16 (listening only)",
252
+ }
253
+ return tracks, report
app/server.py CHANGED
@@ -22,6 +22,12 @@ from fastapi.responses import FileResponse, JSONResponse
22
  from fastapi.staticfiles import StaticFiles
23
  from pydantic import BaseModel, Field
24
 
 
 
 
 
 
 
25
  from .audio import (
26
  AudioError, align_and_resample, analyze_file, hpss_separate_file,
27
  load_audio, mixture_report, save_stems, sha256_file,
@@ -31,6 +37,8 @@ from .audio import (
31
  # Configure ABSOLUTION_MAX_UPLOAD_MIB to fit your available storage.
32
  MAX_UPLOAD_MIB = max(1, min(4096, int(os.environ.get("ABSOLUTION_MAX_UPLOAD_MIB", "1024"))))
33
  MAX_UPLOAD_BYTES = MAX_UPLOAD_MIB * 1024 * 1024
 
 
34
  ALLOWED_EXTENSIONS = {".wav", ".flac", ".aif", ".aiff", ".mp3", ".ogg"}
35
 
36
 
@@ -55,6 +63,67 @@ class SeparationRequest(BaseModel):
55
  target_description: str = Field(default="", max_length=300)
56
 
57
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58
  class Service:
59
  def __init__(self, data_root: Path):
60
  self.data_root = data_root.resolve()
@@ -88,11 +157,53 @@ class Service:
88
  manifest = {
89
  "id": project_id, "name": name, "created_at": timestamp(),
90
  "asset": None, "analysis": None, "stems": {},
91
- "separation": None, "report": None,
 
92
  }
93
  self.write_manifest(project_id, manifest)
94
  return manifest
95
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
96
  def model_info(self) -> list[dict]:
97
  local = Path(self.model_repo).expanduser() if self.model_repo else None
98
  configured = bool(local and local.is_dir() and
@@ -108,7 +219,7 @@ class Service:
108
  "id": "demucs", "name": "Demucs HT v4 · neural (local weights)",
109
  "ready": configured, "type": "neural_network",
110
  "stems": ["drums", "bass", "other", "vocals", "residual"],
111
- "limitations": ("Requires trusted local htdemucs weights/config and optional "
112
  "demucs/torch dependencies. No automatic downloads."),
113
  },
114
  ]
@@ -121,6 +232,12 @@ class Service:
121
  raise HTTPException(status_code=409, detail="Import audio before separation.")
122
  if request.model == "demucs" and not self.model_info()[1]["ready"]:
123
  raise HTTPException(status_code=409, detail="Demucs not configured; local checkpoints required.")
 
 
 
 
 
 
124
  if request.target_description.strip() and request.model == "hpss":
125
  raise HTTPException(status_code=422, detail="HPSS cannot follow arbitrary text prompts.")
126
  # Explicitly reject the unsupported "text conditioned" interpretation for neural.
@@ -137,6 +254,171 @@ class Service:
137
  self.executor.submit(self.run_job, job["id"])
138
  return dict(job)
139
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
140
  def update_job(self, job_id: str, **kwargs) -> None:
141
  with self.lock:
142
  self.jobs[job_id].update(kwargs)
@@ -213,10 +495,24 @@ class Service:
213
  return stems
214
 
215
 
 
 
 
 
 
 
 
 
 
 
 
 
216
  def create_app(data_root: Path | None = None) -> FastAPI:
217
  default = Path(os.environ.get("ABSOLUTION_DATA_DIR", "./omega_data"))
218
- service = Service(data_root or default)
219
- app = FastAPI(title="ABSOLUTION Ω", version="0.2.1",
 
 
220
  description="Local-first audio forensic vertical slice")
221
  app.state.service = service
222
  static_dir = Path(__file__).parent / "static"
@@ -236,7 +532,7 @@ def create_app(data_root: Path | None = None) -> FastAPI:
236
 
237
  @app.get("/api/v1/health")
238
  def health():
239
- return {"status": "ok", "version": "0.2.1", "job_backend": "process-local",
240
  "network_downloads": False, "auth": False,
241
  "max_upload_bytes": MAX_UPLOAD_BYTES,
242
  "duration_limit_seconds": None, "streaming_hpss": True}
@@ -310,6 +606,172 @@ def create_app(data_root: Path | None = None) -> FastAPI:
310
  except (ValueError, KeyError) as exc:
311
  raise HTTPException(status_code=404, detail="Job not found.") from exc
312
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
313
  @app.get("/api/v1/projects/{project_id}/stems")
314
  def get_stems(project_id: str):
315
  manifest = service.manifest(project_id)
 
22
  from fastapi.staticfiles import StaticFiles
23
  from pydantic import BaseModel, Field
24
 
25
+ from .bass import BassParams, TRACKS, process_bass_file
26
+ from .noise import RepairParams, inspect_noise_file, repair_noise_file
27
+ from .virtualbass import available as virtualbass_available, render_virtualbass
28
+ from .mini_model import inspect_file as inspect_mini, MODEL_FILE
29
+ from .mixer import render_mix, sampled_peaks, rubberband_available
30
+
31
  from .audio import (
32
  AudioError, align_and_resample, analyze_file, hpss_separate_file,
33
  load_audio, mixture_report, save_stems, sha256_file,
 
37
  # Configure ABSOLUTION_MAX_UPLOAD_MIB to fit your available storage.
38
  MAX_UPLOAD_MIB = max(1, min(4096, int(os.environ.get("ABSOLUTION_MAX_UPLOAD_MIB", "1024"))))
39
  MAX_UPLOAD_BYTES = MAX_UPLOAD_MIB * 1024 * 1024
40
+ # Demucs on shared CPU hardware: cap input duration (0 = unlimited).
41
+ DEMUCS_MAX_SECONDS = float(os.environ.get("ABSOLUTION_DEMUCS_MAX_SECONDS", "0"))
42
  ALLOWED_EXTENSIONS = {".wav", ".flac", ".aif", ".aiff", ".mp3", ".ogg"}
43
 
44
 
 
63
  target_description: str = Field(default="", max_length=300)
64
 
65
 
66
+ class BassRequest(BaseModel):
67
+ project_id: str
68
+ source_mode: Literal["auto", "dsp", "hpss", "demucs"] = "auto"
69
+ crossover_hz: float = Field(default=220, ge=45, le=350)
70
+ kick_focus: float = Field(default=0.75, ge=0, le=1)
71
+ kick_gain_db: float = Field(default=0, ge=-12, le=12)
72
+ bass_gain_db: float = Field(default=0, ge=-12, le=12)
73
+ sub_gain_db: float = Field(default=0, ge=-12, le=12)
74
+ harmonics: float = Field(default=0.20, ge=0, le=1)
75
+ lowcut_hz: float = Field(default=22, ge=10, le=45)
76
+ mono_below_hz: float = Field(default=100, ge=0, le=180)
77
+ wet: float = Field(default=1, ge=0, le=1)
78
+ ceiling_dbfs: float = Field(default=-1, ge=-6, le=-0.1)
79
+
80
+
81
+ class NoiseScanRequest(BaseModel):
82
+ project_id: str
83
+
84
+
85
+ class NoiseRepairRequest(BaseModel):
86
+ project_id: str
87
+ approved_samples: list[int] = Field(default_factory=list, max_length=400)
88
+ strength: float = Field(default=0.8, ge=0, le=1)
89
+
90
+
91
+
92
+ class VirtualBassRequest(BaseModel):
93
+ project_id: str
94
+ cutoff_hz: float = Field(default=250, ge=100, le=500)
95
+ strength: float = Field(default=1.0, ge=0.5, le=3.0)
96
+
97
+
98
+
99
+ class TrackMix(BaseModel):
100
+ gain_db: float = Field(default=0, ge=-48, le=12)
101
+ pan: float = Field(default=0, ge=-1, le=1)
102
+ mute: bool = False
103
+ solo: bool = False
104
+ highpass_hz: float = Field(default=0, ge=0, le=400)
105
+ lowpass_hz: float = Field(default=0, ge=0, le=18000)
106
+ width: float = Field(default=1, ge=0, le=2)
107
+ drive: float = Field(default=0, ge=0, le=1)
108
+
109
+
110
+ class MixerRequest(BaseModel):
111
+ project_id: str
112
+ tracks: dict[str, TrackMix] = Field(default_factory=dict)
113
+ tempo: float = Field(default=1, ge=0.5, le=2)
114
+ pitch_semitones: float = Field(default=0, ge=-12, le=12)
115
+
116
+
117
+ class PlannedTrack(BaseModel):
118
+ id: str = Field(min_length=1, max_length=60, pattern=r"^[a-z0-9_-]+$")
119
+ label: str = Field(min_length=1, max_length=100)
120
+ enabled: bool = True
121
+
122
+
123
+ class PlanRequest(BaseModel):
124
+ tracks: list[PlannedTrack] = Field(max_length=128)
125
+
126
+
127
  class Service:
128
  def __init__(self, data_root: Path):
129
  self.data_root = data_root.resolve()
 
157
  manifest = {
158
  "id": project_id, "name": name, "created_at": timestamp(),
159
  "asset": None, "analysis": None, "stems": {},
160
+ "separation": None, "report": None, "bass": None, "noise": None, "virtualbass": None,
161
+ "inventory": None, "plan": [], "mixer": None,
162
  }
163
  self.write_manifest(project_id, manifest)
164
  return manifest
165
 
166
+ def create_mixer_job(self, request: MixerRequest) -> dict:
167
+ project_id=check_id(request.project_id)
168
+ with self.lock:
169
+ manifest=self.manifest(project_id)
170
+ if not manifest.get("stems"):
171
+ raise HTTPException(status_code=409,detail="Run actual separation first; planned labels are not audio.")
172
+ unknown=set(request.tracks)-set(manifest["stems"])
173
+ if unknown:
174
+ raise HTTPException(status_code=422,detail="Unknown real stems: "+", ".join(sorted(unknown)))
175
+ if len(manifest["stems"])>128:
176
+ raise HTTPException(status_code=422,detail="More than 128 stems not supported for one render.")
177
+ if (request.tempo!=1 or request.pitch_semitones!=0) and not rubberband_available():
178
+ raise HTTPException(status_code=422,detail="FFmpeg with rubberband is required for independent tempo/pitch.")
179
+ if any(j["project_id"]==project_id and j["status"] in ("queued","running")
180
+ for j in self.jobs.values()):
181
+ raise HTTPException(status_code=409,detail="Project already processing.")
182
+ job={"id":str(uuid.uuid4()),"project_id":project_id,
183
+ "model":"arrangement_mixer","kind":"mix","status":"queued",
184
+ "progress":0,"created_at":timestamp(),"error":None}
185
+ self.jobs[job["id"]]=job
186
+ self.executor.submit(self.run_mixer_job,job["id"],request.model_dump())
187
+ return dict(job)
188
+
189
+ def run_mixer_job(self, job_id: str, settings:dict):
190
+ job=self.jobs[job_id];project_id=job["project_id"]
191
+ try:
192
+ self.update_job(job_id,status="running",progress=3)
193
+ manifest=self.manifest(project_id);folder=self.folder(project_id)
194
+ sources={name:folder/"stems"/data["master"] for name,data in manifest["stems"].items()}
195
+ output=folder/"mixer"/(job_id+".wav")
196
+ result=render_mix(sources,settings,output,
197
+ progress=lambda r:self.update_job(job_id,progress=3+int(r*90)))
198
+ with self.lock:
199
+ newest=self.manifest(project_id)
200
+ newest["mixer"]={"id":job_id,"file":output.name,"settings":settings,
201
+ "result":result,"created_at":timestamp()}
202
+ self.write_manifest(project_id,newest)
203
+ self.update_job(job_id,status="done",progress=100)
204
+ except Exception as exc:
205
+ self.update_job(job_id,status="failed",error=f"{type(exc).__name__}: {exc}")
206
+
207
  def model_info(self) -> list[dict]:
208
  local = Path(self.model_repo).expanduser() if self.model_repo else None
209
  configured = bool(local and local.is_dir() and
 
219
  "id": "demucs", "name": "Demucs HT v4 · neural (local weights)",
220
  "ready": configured, "type": "neural_network",
221
  "stems": ["drums", "bass", "other", "vocals", "residual"],
222
+ "limitations": ("Requires trusted local htdemucs weights/config (official checkpoint 955717e8) and "
223
  "demucs/torch dependencies. No automatic downloads."),
224
  },
225
  ]
 
232
  raise HTTPException(status_code=409, detail="Import audio before separation.")
233
  if request.model == "demucs" and not self.model_info()[1]["ready"]:
234
  raise HTTPException(status_code=409, detail="Demucs not configured; local checkpoints required.")
235
+ if request.model == "demucs" and DEMUCS_MAX_SECONDS > 0:
236
+ duration = float((manifest.get("analysis") or {}).get("duration_seconds") or 0)
237
+ if duration > DEMUCS_MAX_SECONDS:
238
+ raise HTTPException(status_code=413, detail=(
239
+ f"Demucs on this CPU instance is limited to {DEMUCS_MAX_SECONDS:g} s audio "
240
+ f"(file: {duration:.0f} s). Use HPSS or run locally."))
241
  if request.target_description.strip() and request.model == "hpss":
242
  raise HTTPException(status_code=422, detail="HPSS cannot follow arbitrary text prompts.")
243
  # Explicitly reject the unsupported "text conditioned" interpretation for neural.
 
254
  self.executor.submit(self.run_job, job["id"])
255
  return dict(job)
256
 
257
+ def create_bass_job(self, request: BassRequest) -> dict:
258
+ project_id = check_id(request.project_id)
259
+ with self.lock:
260
+ manifest = self.manifest(project_id)
261
+ if not manifest["asset"]:
262
+ raise HTTPException(status_code=409, detail="Import audio before BASS-CORE.")
263
+ active = any(j["project_id"] == project_id and j["status"] in ("queued", "running")
264
+ for j in self.jobs.values())
265
+ if active:
266
+ raise HTTPException(status_code=409, detail="A project job is already running.")
267
+ stems = manifest.get("stems") or {}
268
+ separation = (manifest.get("separation") or {}).get("method")
269
+ valid_hpss = separation == "hpss" and all(k in stems for k in ("harmonic","percussive"))
270
+ valid_neural = separation == "demucs" and all(k in stems for k in ("bass","drums"))
271
+ mode = request.source_mode
272
+ if mode == "auto":
273
+ mode = "demucs" if valid_neural else "hpss" if valid_hpss else "dsp"
274
+ if mode == "hpss" and not valid_hpss:
275
+ raise HTTPException(status_code=409, detail="Run HPSS separation first.")
276
+ if mode == "demucs" and not valid_neural:
277
+ raise HTTPException(status_code=409, detail="Run Demucs bass/drums separation first.")
278
+ job = {
279
+ "id": str(uuid.uuid4()), "project_id": project_id, "model": "basscore",
280
+ "mode": mode, "kind": "bass", "status": "queued", "progress": 0,
281
+ "created_at": timestamp(), "error": None,
282
+ }
283
+ self.jobs[job["id"]] = job
284
+ self.executor.submit(self.run_bass_job, job["id"], request)
285
+ return dict(job)
286
+
287
+ def run_bass_job(self, job_id: str, request: BassRequest) -> None:
288
+ job = self.jobs[job_id]
289
+ project_id, mode = job["project_id"], job["mode"]
290
+ try:
291
+ self.update_job(job_id, status="running", progress=5)
292
+ manifest = self.manifest(project_id)
293
+ folder = self.folder(project_id)
294
+ refs = {}
295
+ wanted = {"dsp": (), "hpss": ("harmonic","percussive"),
296
+ "demucs": ("bass","drums")}[mode]
297
+ for name in wanted:
298
+ refs[name] = folder / "stems" / manifest["stems"][name]["master"]
299
+ settings = BassParams(**request.model_dump(exclude={"project_id","source_mode"}))
300
+ out = folder / "basscore" / job_id
301
+ stems, report = process_bass_file(
302
+ folder / manifest["asset"]["stored_name"], out, settings,
303
+ mode=mode, refs=refs,
304
+ progress=lambda ratio:self.update_job(job_id, progress=5 + int(90 * ratio)),
305
+ )
306
+ result = {"id": job_id, "completed_at": timestamp(), "mode": mode,
307
+ "source_sha256": manifest["asset"]["sha256"],
308
+ "stems": stems, "report": report}
309
+ with self.lock:
310
+ updated = self.manifest(project_id)
311
+ updated["bass"] = result
312
+ self.write_manifest(project_id, updated)
313
+ self.update_job(job_id, status="done", progress=100)
314
+ except Exception as exc:
315
+ self.update_job(job_id, status="failed", error=f"{type(exc).__name__}: {exc}")
316
+
317
+ def create_noise_job(self, project_id: str, action: str,
318
+ approved: list[int] | None=None, strength: float=0.8) -> dict:
319
+ project_id=check_id(project_id)
320
+ with self.lock:
321
+ manifest=self.manifest(project_id)
322
+ if not manifest.get("asset"):
323
+ raise HTTPException(status_code=409,detail="Import audio before NOISE-CORE.")
324
+ if any(j["project_id"]==project_id and j["status"] in ("queued","running")
325
+ for j in self.jobs.values()):
326
+ raise HTTPException(status_code=409,detail="A project job is already running.")
327
+ if action=="repair":
328
+ scan=(manifest.get("noise") or {}).get("scan")
329
+ if not scan:
330
+ raise HTTPException(status_code=409,detail="Scan for click hypotheses first.")
331
+ allowed={event["sample"] for event in scan["events"]}
332
+ if not set(approved or []).issubset(allowed):
333
+ raise HTTPException(status_code=422,detail="Repair only confirmed scan events.")
334
+ if not approved:
335
+ raise HTTPException(status_code=422,detail="Select at least one click candidate.")
336
+ job={
337
+ "id":str(uuid.uuid4()),"project_id":project_id,
338
+ "model":"noisecore","kind":"noise_"+action,
339
+ "status":"queued","progress":0,"created_at":timestamp(),"error":None,
340
+ }
341
+ self.jobs[job["id"]]=job
342
+ self.executor.submit(self.run_noise_job,job["id"],action,approved or [],strength)
343
+ return dict(job)
344
+
345
+ def run_noise_job(self, job_id:str, action:str, approved:list[int], strength:float)->None:
346
+ project_id=self.jobs[job_id]["project_id"]
347
+ try:
348
+ self.update_job(job_id,status="running",progress=3)
349
+ manifest=self.manifest(project_id)
350
+ folder=self.folder(project_id)
351
+ source=folder/manifest["asset"]["stored_name"]
352
+ callback=lambda ratio:self.update_job(job_id,progress=5+int(90*ratio))
353
+ if action=="scan":
354
+ scan=inspect_noise_file(source,progress=callback)
355
+ with self.lock:
356
+ updated=self.manifest(project_id)
357
+ # Old repair, if any, must not be attached to a new scan.
358
+ updated["noise"]={"scan":scan,"repair":None,
359
+ "source_sha256":manifest["asset"]["sha256"],
360
+ "scanned_at":timestamp()}
361
+ self.write_manifest(project_id,updated)
362
+ else:
363
+ root=folder/"noisecore"/job_id
364
+ tracks,report=repair_noise_file(
365
+ source,root,approved,RepairParams(strength),progress=callback)
366
+ with self.lock:
367
+ updated=self.manifest(project_id)
368
+ updated["noise"]["repair"]={
369
+ "id":job_id,"completed_at":timestamp(),
370
+ "source_sha256":manifest["asset"]["sha256"],
371
+ "tracks":tracks,"report":report,
372
+ }
373
+ self.write_manifest(project_id,updated)
374
+ self.update_job(job_id,status="done",progress=100)
375
+ except Exception as exc:
376
+ self.update_job(job_id,status="failed",error=f"{type(exc).__name__}: {exc}")
377
+
378
+ def create_virtualbass_job(self, request: VirtualBassRequest) -> dict:
379
+ pid=check_id(request.project_id)
380
+ with self.lock:
381
+ manifest=self.manifest(pid)
382
+ if not manifest.get("asset"):
383
+ raise HTTPException(status_code=409,detail="Import stereo audio first.")
384
+ if not virtualbass_available():
385
+ raise HTTPException(status_code=409,detail="FFmpeg virtualbass filter not available locally.")
386
+ if manifest["analysis"]["channels"]!=2:
387
+ raise HTTPException(status_code=422,detail="Virtualbass requires two-channel stereo.")
388
+ if any(j["project_id"]==pid and j["status"] in ("queued","running")
389
+ for j in self.jobs.values()):
390
+ raise HTTPException(status_code=409,detail="Project has a running job.")
391
+ job={"id":str(uuid.uuid4()),"project_id":pid,"model":"ffmpeg_virtualbass",
392
+ "kind":"virtualbass","status":"queued","progress":0,
393
+ "created_at":timestamp(),"error":None}
394
+ self.jobs[job["id"]]=job
395
+ self.executor.submit(self.run_virtualbass_job,job["id"],request)
396
+ return dict(job)
397
+
398
+ def run_virtualbass_job(self, job_id:str, request:VirtualBassRequest) -> None:
399
+ job=self.jobs[job_id]
400
+ pid=job["project_id"]
401
+ try:
402
+ self.update_job(job_id,status="running",progress=10)
403
+ manifest=self.manifest(pid)
404
+ folder=self.folder(pid)
405
+ target=folder/"virtualbass"/job_id/"virtualbass_2_1.wav"
406
+ report=render_virtualbass(
407
+ folder/manifest["asset"]["stored_name"],target,
408
+ cutoff_hz=request.cutoff_hz,strength=request.strength
409
+ )
410
+ self.update_job(job_id,progress=95)
411
+ with self.lock:
412
+ updated=self.manifest(pid)
413
+ updated["virtualbass"]={
414
+ "id":job_id,"source_sha256":manifest["asset"]["sha256"],
415
+ "completed_at":timestamp(),"report":report,
416
+ }
417
+ self.write_manifest(pid,updated)
418
+ self.update_job(job_id,status="done",progress=100)
419
+ except Exception as exc:
420
+ self.update_job(job_id,status="failed",error=f"{type(exc).__name__}: {exc}")
421
+
422
  def update_job(self, job_id: str, **kwargs) -> None:
423
  with self.lock:
424
  self.jobs[job_id].update(kwargs)
 
495
  return stems
496
 
497
 
498
+ def writable_dir(preferred: Path, fallback: Path) -> Path:
499
+ """Use the persistent mount (e.g. HF bucket at /data) if writable, else fallback."""
500
+ try:
501
+ preferred.mkdir(parents=True, exist_ok=True)
502
+ probe = preferred / f".probe-{uuid.uuid4().hex}"
503
+ probe.write_text("ok"); probe.unlink()
504
+ return preferred
505
+ except OSError:
506
+ fallback.mkdir(parents=True, exist_ok=True)
507
+ return fallback
508
+
509
+
510
  def create_app(data_root: Path | None = None) -> FastAPI:
511
  default = Path(os.environ.get("ABSOLUTION_DATA_DIR", "./omega_data"))
512
+ if data_root is None:
513
+ data_root = writable_dir(default, Path(os.environ.get("ABSOLUTION_FALLBACK_DIR", "/tmp/omega_data")))
514
+ service = Service(data_root)
515
+ app = FastAPI(title="ABSOLUTION Ω", version="0.6.0",
516
  description="Local-first audio forensic vertical slice")
517
  app.state.service = service
518
  static_dir = Path(__file__).parent / "static"
 
532
 
533
  @app.get("/api/v1/health")
534
  def health():
535
+ return {"status": "ok", "version": "0.6.0", "arrangement_studio": True, "mini_tag_model_ready": MODEL_FILE.is_file(), "rubberband_ready": rubberband_available(), "basscore": True, "noisecore": True, "virtualbass_ready": virtualbass_available(), "job_backend": "process-local", "data_dir": str(service.data_root), "persistent_storage": str(service.data_root).startswith("/data"), "demucs_max_seconds": DEMUCS_MAX_SECONDS or None,
536
  "network_downloads": False, "auth": False,
537
  "max_upload_bytes": MAX_UPLOAD_BYTES,
538
  "duration_limit_seconds": None, "streaming_hpss": True}
 
606
  except (ValueError, KeyError) as exc:
607
  raise HTTPException(status_code=404, detail="Job not found.") from exc
608
 
609
+ @app.post("/api/v1/jobs/bass", status_code=202)
610
+ def bass_job(request: BassRequest):
611
+ return service.create_bass_job(request)
612
+
613
+ @app.get("/api/v1/projects/{project_id}/bass")
614
+ def bass_results(project_id: str):
615
+ result = service.manifest(project_id).get("bass")
616
+ return {"bass": result}
617
+
618
+ @app.get("/api/v1/projects/{project_id}/bass/audio/{track}")
619
+ def bass_audio(project_id: str, track: str, preview: bool = False):
620
+ manifest = service.manifest(project_id)
621
+ result = manifest.get("bass")
622
+ if not result or track not in TRACKS or track not in result["stems"]:
623
+ raise HTTPException(status_code=404, detail="Bass track not found.")
624
+ info = result["stems"][track]
625
+ key = "preview" if preview else "master"
626
+ path = service.folder(project_id) / "basscore" / result["id"] / info[key]
627
+ if not path.is_file():
628
+ raise HTTPException(status_code=404, detail="Bass track not found.")
629
+ return FileResponse(path, media_type="audio/wav", filename=path.name)
630
+
631
+ @app.get("/api/v1/projects/{project_id}/bass/export")
632
+ def bass_export(project_id: str):
633
+ manifest = service.manifest(project_id)
634
+ result = manifest.get("bass")
635
+ if not result:
636
+ raise HTTPException(status_code=409, detail="Run BASS-CORE before exporting.")
637
+ folder = service.folder(project_id)
638
+ root = folder / "basscore" / result["id"]
639
+ target = root / "BASS_CORE_EXPORT.zip"
640
+ tmp = root / f".{uuid.uuid4().hex}.zip"
641
+ with zipfile.ZipFile(tmp, "w", compression=zipfile.ZIP_STORED) as archive:
642
+ archive.writestr("bass_report.json", json.dumps(result,indent=2,ensure_ascii=False))
643
+ for name, entry in result["stems"].items():
644
+ archive.write(root / entry["master"], f"stems/{entry['master']}")
645
+ tmp.replace(target)
646
+ return FileResponse(target,media_type="application/zip",filename="ABSOLUTION_BASS_CORE.zip")
647
+
648
+ @app.post("/api/v1/jobs/noise/scan",status_code=202)
649
+ def noise_scan(request:NoiseScanRequest):
650
+ return service.create_noise_job(request.project_id,"scan")
651
+
652
+ @app.post("/api/v1/jobs/noise/repair",status_code=202)
653
+ def noise_repair(request:NoiseRepairRequest):
654
+ return service.create_noise_job(request.project_id,"repair",
655
+ request.approved_samples,request.strength)
656
+
657
+ @app.get("/api/v1/projects/{project_id}/noise")
658
+ def noise_results(project_id:str):
659
+ return {"noise":service.manifest(project_id).get("noise")}
660
+
661
+ @app.get("/api/v1/projects/{project_id}/noise/audio/{track}")
662
+ def noise_audio(project_id:str, track:str, preview:bool=False):
663
+ result=(service.manifest(project_id).get("noise") or {}).get("repair")
664
+ if not result or track not in ("clean","difference"):
665
+ raise HTTPException(status_code=404,detail="NOISE-CORE track not found.")
666
+ item=result["tracks"][track]
667
+ path=service.folder(project_id)/"noisecore"/result["id"]/item[
668
+ "preview" if preview else "master"]
669
+ if not path.is_file():
670
+ raise HTTPException(status_code=404,detail="NOISE-CORE file not found.")
671
+ return FileResponse(path,media_type="audio/wav",filename=path.name)
672
+
673
+ @app.get("/api/v1/projects/{project_id}/noise/export")
674
+ def noise_export(project_id:str):
675
+ result=(service.manifest(project_id).get("noise") or {}).get("repair")
676
+ if not result:
677
+ raise HTTPException(status_code=409,detail="Approve and render repairs first.")
678
+ folder=service.folder(project_id)/"noisecore"/result["id"]
679
+ tmp=folder/f".{uuid.uuid4().hex}.zip"
680
+ target=folder/"NOISE_CORE_EXPORT.zip"
681
+ with zipfile.ZipFile(tmp,"w",compression=zipfile.ZIP_STORED) as archive:
682
+ archive.writestr("report.json",json.dumps(result,indent=2,ensure_ascii=False))
683
+ for name,entry in result["tracks"].items():
684
+ archive.write(folder/entry["master"],f"tracks/{entry['master']}")
685
+ tmp.replace(target)
686
+ return FileResponse(target,media_type="application/zip",
687
+ filename="ABSOLUTION_NOISE_CORE.zip")
688
+
689
+ @app.post("/api/v1/jobs/bass/virtual",status_code=202)
690
+ def create_virtual(request:VirtualBassRequest):
691
+ return service.create_virtualbass_job(request)
692
+
693
+ @app.get("/api/v1/projects/{project_id}/virtualbass")
694
+ def virtual_result(project_id:str):
695
+ return {"virtualbass":service.manifest(project_id).get("virtualbass")}
696
+
697
+ @app.get("/api/v1/projects/{project_id}/virtualbass/audio")
698
+ def virtual_audio(project_id:str):
699
+ result=service.manifest(project_id).get("virtualbass")
700
+ if not result:
701
+ raise HTTPException(status_code=404,detail="No Virtual Bass result.")
702
+ path=service.folder(project_id)/"virtualbass"/result["id"]/"virtualbass_2_1.wav"
703
+ if not path.is_file():
704
+ raise HTTPException(status_code=404,detail="Virtual Bass file not found.")
705
+ return FileResponse(path,media_type="audio/wav",filename="ABSOLUTION_VIRTUAL_BASS_2_1.wav")
706
+
707
+ @app.post("/api/v1/projects/{project_id}/inventory")
708
+ def run_inventory(project_id:str):
709
+ project_id=check_id(project_id)
710
+ with service.lock:
711
+ manifest=service.manifest(project_id)
712
+ if not manifest.get("asset"):
713
+ raise HTTPException(status_code=409,detail="Audio import required.")
714
+ path=service.folder(project_id)/manifest["asset"]["stored_name"]
715
+ try:
716
+ inventory=inspect_mini(path)
717
+ except (ValueError,FileNotFoundError) as exc:
718
+ raise HTTPException(status_code=422,detail=str(exc)) from exc
719
+ # Editable suggestions are hypotheses, NOT separated audio.
720
+ suggested=[{"id":d["id"],"label":d["label"],"enabled":True}
721
+ for d in inventory["detections"] if d["suggested"]]
722
+ manifest["inventory"]=inventory
723
+ if not manifest.get("plan"):manifest["plan"]=suggested
724
+ service.write_manifest(project_id,manifest)
725
+ return {"inventory":inventory,"plan":manifest["plan"],
726
+ "actual_stems":list(manifest.get("stems",{}))}
727
+
728
+ @app.put("/api/v1/projects/{project_id}/plan")
729
+ def update_plan(project_id:str,req:PlanRequest):
730
+ ids=[x.id for x in req.tracks]
731
+ if len(ids)!=len(set(ids)):
732
+ raise HTTPException(status_code=422,detail="Duplicate planned IDs.")
733
+ with service.lock:
734
+ manifest=service.manifest(project_id)
735
+ if not manifest.get("asset"):
736
+ raise HTTPException(status_code=409,detail="Import audio first.")
737
+ manifest["plan"]=[x.model_dump() for x in req.tracks]
738
+ service.write_manifest(project_id,manifest)
739
+ return {"plan":manifest["plan"],"status":"hypotheses_only",
740
+ "notice":"A saved plan does not separate or generate new stems."}
741
+
742
+ @app.get("/api/v1/projects/{project_id}/wave/{stem}")
743
+ def get_wave(project_id:str,stem:str,points:int=360):
744
+ manifest=service.manifest(project_id);folder=service.folder(project_id)
745
+ if stem=="original":
746
+ if not manifest.get("asset"):raise HTTPException(status_code=404,detail="No audio")
747
+ path=folder/manifest["asset"]["stored_name"]
748
+ else:
749
+ if stem not in manifest.get("stems",{}):
750
+ raise HTTPException(status_code=404,detail="Unknown stem")
751
+ path=folder/"stems"/manifest["stems"][stem]["master"]
752
+ if points<64 or points>1000:
753
+ raise HTTPException(status_code=422,detail="points must be 64..1000")
754
+ try:return sampled_peaks(path,points)
755
+ except (ValueError,RuntimeError) as exc:
756
+ raise HTTPException(status_code=422,detail=str(exc)) from exc
757
+
758
+ @app.post("/api/v1/jobs/mix",status_code=202)
759
+ def start_mix(request:MixerRequest):
760
+ return service.create_mixer_job(request)
761
+
762
+ @app.get("/api/v1/projects/{project_id}/mixer")
763
+ def mixer_status(project_id:str):
764
+ return {"mixer":service.manifest(project_id).get("mixer")}
765
+
766
+ @app.get("/api/v1/projects/{project_id}/mixer/audio")
767
+ def mixer_audio(project_id:str):
768
+ manifest=service.manifest(project_id)
769
+ mixer=manifest.get("mixer")
770
+ if not mixer:raise HTTPException(status_code=404,detail="Render a mix first.")
771
+ path=service.folder(project_id)/"mixer"/mixer["file"]
772
+ if not path.is_file():raise HTTPException(status_code=404,detail="Rendered mix missing")
773
+ return FileResponse(path,media_type="audio/wav",filename="ABSOLUTION_ARRANGEMENT_MIX.wav")
774
+
775
  @app.get("/api/v1/projects/{project_id}/stems")
776
  def get_stems(project_id: str):
777
  manifest = service.manifest(project_id)
app/static/app.js CHANGED
@@ -7,7 +7,7 @@ const BASE = "/api/v1";
7
  const STORAGE = "absolution_omega_current_project_v02";
8
  const state = {
9
  projectId: null, projectName: "", asset: null, analysis: null,
10
- stems: {}, report: null, separation: null,
11
  model: "hpss", models: [], busy: false, playing: "original",
12
  view: "studio",
13
  };
@@ -62,9 +62,15 @@ function setBusy(value) {
62
  $("#newProject").disabled = value;
63
  $("#dropzone").setAttribute("aria-disabled", String(value));
64
  $("#run").disabled = value || !state.projectId || !state.models.find(m => m.id === state.model && m.ready);
 
 
 
 
 
 
65
  }
66
  function navigate(view) {
67
- if (!["studio","stems","quality","guide"].includes(view)) return;
68
  state.view = view;
69
  $$(".view").forEach(node => node.classList.toggle("active", node.id === `view-${view}`));
70
  $$(".nav-link").forEach(node => {
@@ -72,10 +78,11 @@ function navigate(view) {
72
  node.classList.toggle("active", active);
73
  if (active) node.setAttribute("aria-current", "page"); else node.removeAttribute("aria-current");
74
  });
75
- const names = {studio:"STUDIO",stems:"MEINE STEMS",quality:"FORENSIK-BERICHT",guide:"HILFE & TECHNIK"};
76
  $("#crumbCurrent").textContent = names[view];
77
  document.title = `ABSOLUTION Ω — ${names[view]}`;
78
  closeMenu();
 
79
  window.scrollTo({top:0,behavior:"instant"});
80
  }
81
  function closeMenu() {
@@ -86,7 +93,7 @@ function closeMenu() {
86
  function resetUi() {
87
  state.projectId = null; state.projectName = "";
88
  state.analysis = null; state.asset = null;
89
- state.stems = {}; state.report = null; state.separation = null;
90
  audio.pause(); audio.removeAttribute("src"); audio.load();
91
  state.playing = "original";
92
  $("#nowPlaying").textContent = "Kein Audio geladen";
@@ -116,7 +123,8 @@ function resetUi() {
116
  $("#reportExplanation").textContent = "Nach einer Separation berechnen wir, wie genau alle Stems inklusive Residual den internen Eingangsmix rekonstruieren.";
117
  $("#reportMark").textContent = "◇";
118
  $("#err").textContent = "—"; $("#rmsErr").textContent = "—";
119
- renderStems(); drawWave();
 
120
  setBusy(false);
121
  }
122
  function loadManifest(project) {
@@ -127,6 +135,9 @@ function loadManifest(project) {
127
  state.stems = project.stems || {};
128
  state.report = project.report;
129
  state.separation = project.separation;
 
 
 
130
  safeStore(project.id);
131
  $("#sidebarProject").textContent = project.name || project.asset?.filename || "Projekt";
132
  $("#sidebarProjectInfo").textContent = project.analysis ? `${timeText(project.analysis.duration_seconds)} · ${project.analysis.channels} Kanal/Kanäle` : "Projekt ohne Datei";
@@ -145,7 +156,11 @@ function loadManifest(project) {
145
  }
146
  renderStems();
147
  renderReport();
 
 
 
148
  drawWave();
 
149
  setBusy(false);
150
  }
151
  async function uploadFile(file) {
@@ -364,12 +379,321 @@ async function runSeparation() {
364
  toast(`Separation fehlgeschlagen: ${error.message}`,true);
365
  } finally {setBusy(false);}
366
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
367
  async function init() {
368
  resetUi();
369
  audio.volume=.8;
370
  try{
371
  const health = await api(`${BASE}/health`);
372
  maxUploadBytes = Number(health.max_upload_bytes) || maxUploadBytes;
 
 
373
  $("#uploadLimits").textContent = `WAV · FLAC · AIFF · MP3 · OGG • bis ${Math.round(maxUploadBytes/1048576)} MiB • keine feste Zeitgrenze`;
374
  $("#guideImportLimits").textContent = `Maximale Dateigröße: ${Math.round(maxUploadBytes/1048576)} MiB. Keine feste Zeitgrenze; Verarbeitungszeit hängt von Datei und Hardware ab.`;
375
  $("#apiIndicator").classList.add("online");$("#apiLabel").textContent="ENGINE ONLINE";
@@ -410,6 +734,30 @@ $("#dropzone").addEventListener("dragover",event=>{event.preventDefault();$("#dr
410
  $("#dropzone").addEventListener("dragleave",()=>$("#dropzone").classList.remove("dragging"));
411
  $("#dropzone").addEventListener("drop",event=>{event.preventDefault();$("#dropzone").classList.remove("dragging");uploadFile(event.dataTransfer.files?.[0]);});
412
  $$(".method input").forEach(input=>input.addEventListener("change",()=>selectMethod(input.value)));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
413
  $("#run").addEventListener("click",runSeparation);
414
  $("#export").addEventListener("click",()=>{if(state.projectId && Object.keys(state.stems).length) window.location.href=`${BASE}/projects/${state.projectId}/export`;});
415
  $("#waveform").addEventListener("click",event=>{
 
7
  const STORAGE = "absolution_omega_current_project_v02";
8
  const state = {
9
  projectId: null, projectName: "", asset: null, analysis: null,
10
+ stems: {}, report: null, separation: null, bass: null, noise: null, virtualbass: null, virtualReady: false,
11
  model: "hpss", models: [], busy: false, playing: "original",
12
  view: "studio",
13
  };
 
62
  $("#newProject").disabled = value;
63
  $("#dropzone").setAttribute("aria-disabled", String(value));
64
  $("#run").disabled = value || !state.projectId || !state.models.find(m => m.id === state.model && m.ready);
65
+ $("#bassRun").disabled = value || !state.asset;
66
+ $("#bassExport").disabled = value || !state.bass;
67
+ $("#virtualRun").disabled = value || !state.asset || state.analysis?.channels !== 2 || !state.virtualReady;
68
+ $("#noiseScan").disabled = value || !state.asset;
69
+ $("#noiseExport").disabled = value || !state.noise?.repair;
70
+ $("#noiseRepair").disabled = value || !state.noise?.scan || !document.querySelector("#noiseCandidates input:checked");
71
  }
72
  function navigate(view) {
73
+ if (!["studio","arrangement","bass","noise","stems","quality","guide"].includes(view)) return;
74
  state.view = view;
75
  $$(".view").forEach(node => node.classList.toggle("active", node.id === `view-${view}`));
76
  $$(".nav-link").forEach(node => {
 
78
  node.classList.toggle("active", active);
79
  if (active) node.setAttribute("aria-current", "page"); else node.removeAttribute("aria-current");
80
  });
81
+ const names = {studio:"STUDIO",arrangement:"ARRANGEMENT",bass:"BASS-CORE",noise:"NOISE-CORE",stems:"MEINE STEMS",quality:"FORENSIK-BERICHT",guide:"HILFE & TECHNIK"};
82
  $("#crumbCurrent").textContent = names[view];
83
  document.title = `ABSOLUTION Ω — ${names[view]}`;
84
  closeMenu();
85
+ if(view==="arrangement" && window.omegaArrangementDraw)window.omegaArrangementDraw();
86
  window.scrollTo({top:0,behavior:"instant"});
87
  }
88
  function closeMenu() {
 
93
  function resetUi() {
94
  state.projectId = null; state.projectName = "";
95
  state.analysis = null; state.asset = null;
96
+ state.stems = {}; state.report = null; state.separation = null; state.bass = null; state.noise = null; state.virtualbass = null;
97
  audio.pause(); audio.removeAttribute("src"); audio.load();
98
  state.playing = "original";
99
  $("#nowPlaying").textContent = "Kein Audio geladen";
 
123
  $("#reportExplanation").textContent = "Nach einer Separation berechnen wir, wie genau alle Stems inklusive Residual den internen Eingangsmix rekonstruieren.";
124
  $("#reportMark").textContent = "◇";
125
  $("#err").textContent = "—"; $("#rmsErr").textContent = "—";
126
+ renderStems(); drawWave(); renderBass(); renderNoise(); renderVirtual();
127
+ if(window.omegaArrangementReset) window.omegaArrangementReset();
128
  setBusy(false);
129
  }
130
  function loadManifest(project) {
 
135
  state.stems = project.stems || {};
136
  state.report = project.report;
137
  state.separation = project.separation;
138
+ state.bass = project.bass || null;
139
+ state.noise = project.noise || null;
140
+ state.virtualbass = project.virtualbass || null;
141
  safeStore(project.id);
142
  $("#sidebarProject").textContent = project.name || project.asset?.filename || "Projekt";
143
  $("#sidebarProjectInfo").textContent = project.analysis ? `${timeText(project.analysis.duration_seconds)} · ${project.analysis.channels} Kanal/Kanäle` : "Projekt ohne Datei";
 
156
  }
157
  renderStems();
158
  renderReport();
159
+ renderBass();
160
+ renderNoise();
161
+ renderVirtual();
162
  drawWave();
163
+ if(window.omegaArrangementLoad) window.omegaArrangementLoad(project);
164
  setBusy(false);
165
  }
166
  async function uploadFile(file) {
 
379
  toast(`Separation fehlgeschlagen: ${error.message}`,true);
380
  } finally {setBusy(false);}
381
  }
382
+ // BASS-CORE Ω: user-controlled, non-destructive DSP stage.
383
+ const bassPresets = {
384
+ transparent: {bassCrossover:220,bassFocus:75,bassKick:0,bassLine:0,bassSub:0,bassHarm:0,bassLowcut:10,bassMono:0,bassWet:100,bassCeiling:-1},
385
+ club: {bassCrossover:200,bassFocus:85,bassKick:3,bassLine:1.5,bassSub:2,bassHarm:35,bassLowcut:22,bassMono:110,bassWet:90,bassCeiling:-1},
386
+ warm: {bassCrossover:240,bassFocus:50,bassKick:0.5,bassLine:2,bassSub:2,bassHarm:45,bassLowcut:20,bassMono:90,bassWet:85,bassCeiling:-1},
387
+ translate: {bassCrossover:180,bassFocus:65,bassKick:1,bassLine:0,bassSub:-1,bassHarm:80,bassLowcut:26,bassMono:110,bassWet:100,bassCeiling:-1},
388
+ };
389
+ const bassSliderIds = ["bassCrossover","bassFocus","bassKick","bassLine","bassSub","bassHarm","bassLowcut","bassMono","bassWet","bassCeiling"];
390
+ function bassNumber(id) {return Number($("#"+id).value);}
391
+ function updateBassValues() {
392
+ const values={
393
+ bassCrossoverValue:`${bassNumber("bassCrossover")} Hz`,
394
+ bassFocusValue:`${bassNumber("bassFocus")} %`,
395
+ bassKickValue:`${bassNumber("bassKick")>=0?"+":""}${bassNumber("bassKick").toFixed(1)} dB`,
396
+ bassLineValue:`${bassNumber("bassLine")>=0?"+":""}${bassNumber("bassLine").toFixed(1)} dB`,
397
+ bassSubValue:`${bassNumber("bassSub")>=0?"+":""}${bassNumber("bassSub").toFixed(1)} dB`,
398
+ bassHarmValue:`${bassNumber("bassHarm")} %`,
399
+ bassLowcutValue:`${bassNumber("bassLowcut")} Hz`,
400
+ bassMonoValue:`${bassNumber("bassMono")} Hz`,
401
+ bassWetValue:`${bassNumber("bassWet")} %`,
402
+ bassCeilingValue:`${bassNumber("bassCeiling").toFixed(1)} dBFS`,
403
+ };
404
+ Object.entries(values).forEach(([id,label])=>$("#"+id).textContent=label);
405
+ }
406
+ function applyBassPreset(name) {
407
+ const p=bassPresets[name]; if(!p)return;
408
+ Object.entries(p).forEach(([id,val])=>{ $("#"+id).value=String(val);});
409
+ updateBassValues();
410
+ $$(".bass-preset").forEach(el=>el.classList.toggle("active",el.dataset.bassPreset===name));
411
+ }
412
+ function bassSourceUrl(track,preview=true) {
413
+ return `${BASE}/projects/${state.projectId}/bass/audio/${encodeURIComponent(track)}${preview?"?preview=true":""}`;
414
+ }
415
+ function playBassTrack(name) {
416
+ if(!state.bass || !state.projectId)return;
417
+ audio.pause();
418
+ audio.src=bassSourceUrl(name,true);
419
+ audio.dataset.stem="bass:"+name;
420
+ audio.load();
421
+ $("#playButton").disabled=false;
422
+ $("#back10").disabled=false;
423
+ $("#forward10").disabled=false;
424
+ $("#seekBar").disabled=false;
425
+ $("#nowPlaying").textContent=state.bass.stems[name]?.label||name;
426
+ $("#nowPlayingSub").textContent=`BASS-CORE · ${state.asset?.filename||""}`;
427
+ $("#playDuration").textContent=timeText(state.analysis?.duration_seconds);
428
+ audio.play().catch(()=>toast("Bass-Audio konnte nicht abgespielt werden.",true));
429
+ }
430
+ function renderBass() {
431
+ const content=$("#bassResults");
432
+ content.replaceChildren();
433
+ const data=state.bass;
434
+ $("#bassReady").textContent=!state.asset?"DATEI IMPORTIEREN":data?"VERARBEITET":"BEREIT";
435
+ $("#bassSourceUsed").textContent=data?.mode?.toUpperCase()||"—";
436
+ $("#bassMixPeak").textContent=data?dbText(data.report.output_peak_dbfs):"—";
437
+ $("#bassPeakGain").textContent=data?`${data.report.output_ceiling_gain_db.toFixed(2)} dB`:"—";
438
+ $("#bassRecon").textContent=data?(data.report.reconstruction_check.consistent?"OK":"PRÜFEN"):"—";
439
+ if(!data) {
440
+ const empty=el("div","empty-state");
441
+ empty.append(el("h3","","Noch keine Bass-Bearbeitung"),el("p","","Importiere eine Audiodatei im Studio und starte BASS-CORE."));
442
+ content.append(empty);
443
+ $("#bassFrequency").replaceChildren(el("div","bass-frequency-empty","Noch kein Spektralvergleich vorhanden."));
444
+ $("#bassExport").disabled=true;
445
+ return;
446
+ }
447
+ $("#bassExport").disabled=state.busy;
448
+ for(const [name,meta] of Object.entries(data.stems)) {
449
+ const block=el("article","bass-result");
450
+ const labels={
451
+ bass_band:"Bassband · vorher",kick_estimate:"Kick · Schätzung",
452
+ bassline_estimate:"Bassline · Schätzung",other_unprocessed:"Rest ohne Bassband",
453
+ harmonics_added:"Neue Obertöne · Synthese",bass_optimized:"Bassband · optimiert",
454
+ mix_optimized:"Voller Mix · nachher"
455
+ };
456
+ block.append(el("h3","",labels[name]||name),el("p","",meta.label||""));
457
+ const actions=el("div","stem-actions");
458
+ const play=el("button","","▶ Anhören");
459
+ play.type="button"; play.addEventListener("click",()=>playBassTrack(name));
460
+ const download=el("a","","↓ WAV 32-bit");
461
+ download.href=bassSourceUrl(name,false);
462
+ download.download=name+".wav";
463
+ actions.append(play,download);block.append(actions);content.append(block);
464
+ }
465
+ const freq=$("#bassFrequency");freq.replaceChildren();
466
+ const before=data.report.first_chunk_spectrum?.before||[];
467
+ const after=data.report.first_chunk_spectrum?.after||[];
468
+ for(let i=0;i<Math.min(before.length,after.length);i++){
469
+ const a=before[i].estimated_rms_dbfs, b=after[i].estimated_rms_dbfs;
470
+ const range=before[i].range_hz;
471
+ const scaled=v=>Math.max(0,Math.min(100,(v+95)/95*100));
472
+ const row=el("div","bass-freq-item");
473
+ const band=el("span","",`${range[0]}–${range[1]} Hz`);
474
+ const rail=el("div","bass-freq-rail");
475
+ const old=el("div","bass-before"), newer=el("div","bass-after");
476
+ old.style.width=scaled(a)+"%";newer.style.width=scaled(b)+"%";
477
+ rail.append(old,newer);
478
+ const info=el("span","bass-freq-key",`${(b-a)>=0?"+":""}${(b-a).toFixed(1)} dB`);
479
+ row.append(band,rail,info);freq.append(row);
480
+ }
481
+ }
482
+ function bassPayload() {
483
+ return {
484
+ project_id:state.projectId,source_mode:$("#bassMode").value,
485
+ crossover_hz:bassNumber("bassCrossover"),kick_focus:bassNumber("bassFocus")/100,
486
+ kick_gain_db:bassNumber("bassKick"),bass_gain_db:bassNumber("bassLine"),
487
+ sub_gain_db:bassNumber("bassSub"),harmonics:bassNumber("bassHarm")/100,
488
+ lowcut_hz:bassNumber("bassLowcut"),mono_below_hz:bassNumber("bassMono"),
489
+ wet:bassNumber("bassWet")/100,ceiling_dbfs:bassNumber("bassCeiling")
490
+ };
491
+ }
492
+ async function runBass() {
493
+ if(state.busy||!state.asset)return;
494
+ setBusy(true);
495
+ $("#bassProgress").hidden=false;
496
+ $("#bassProgressFill").style.width="0%";$("#bassProgressNum").textContent="0 %";
497
+ $("#bassJobLabel").textContent="Analyse und Bass-Bearbeitung starten …";
498
+ try {
499
+ const job=await api(`${BASE}/jobs/bass`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(bassPayload())});
500
+ while(true){
501
+ await new Promise(resolve=>setTimeout(resolve,650));
502
+ const now=await api(`${BASE}/jobs/${job.id}`);
503
+ const pct=Math.min(100,Math.max(0,Number(now.progress)||0));
504
+ $("#bassProgressFill").style.width=`${pct}%`;
505
+ $("#bassProgressNum").textContent=`${pct} %`;
506
+ $("#bassJobLabel").textContent=now.status==="queued"?"Wartet auf freien Worker …":now.status==="running"?"Tieffrequenzen werden verarbeitet …":now.status==="done"?"Bass-Bearbeitung abgeschlossen":"Fehlgeschlagen";
507
+ if(now.status==="failed")throw new Error(now.error||"Fehler beim Bass-Processing.");
508
+ if(now.status==="done")break;
509
+ }
510
+ const project=await api(`${BASE}/projects/${state.projectId}`);
511
+ state.bass=project.bass;
512
+ renderBass();
513
+ toast("BASS-CORE abgeschlossen! Vergleiche Bassband vorher/nachher mit deinem Gehör.");
514
+ } catch(error){
515
+ $("#bassJobLabel").textContent="Verarbeitung fehlgeschlagen";
516
+ toast(`BASS-CORE: ${error.message}`,true);
517
+ } finally {setBusy(false);}
518
+ }
519
+
520
+ function renderVirtual() {
521
+ const res=state.virtualbass;
522
+ $("#virtualRun").disabled=state.busy||!state.asset||state.analysis?.channels!==2||!state.virtualReady;
523
+ $("#virtualReady").textContent=!state.virtualReady?"FFMPEG-FILTER FEHLT":!state.asset?"STEREO IMPORTIEREN":res?"2.1 EXPORT BEREIT":"BEREIT";
524
+ $("#virtualDownload").hidden=!res;
525
+ if(res) {
526
+ $("#virtualDownload").href=`${BASE}/projects/${encodeURIComponent(state.projectId)}/virtualbass/audio`;
527
+ $("#virtualDownload").download="ABSOLUTION_VIRTUAL_BASS_2_1.wav";
528
+ $("#virtualSummary").textContent=`3 Kanäle (L/R + LFE) · LFE Peak: ${res.report.lfe_peak_dbfs} dBFS · Stereo-Differenz: ${res.report.left_right_max_abs_difference.toExponential(2)}. Nicht automatisch als Stereo-Mix verwenden.`;
529
+ } else $("#virtualSummary").textContent="Benötigt Stereo + FFmpeg mit virtualbass. Exportiert einen 2.1-Master, ohne die Stereo-Originaldatei zu ändern.";
530
+ }
531
+ async function runVirtual() {
532
+ if(state.busy||!state.virtualReady||!state.asset)return;
533
+ setBusy(true);
534
+ try {
535
+ const payload={
536
+ project_id:state.projectId,
537
+ cutoff_hz:Number($("#virtualCutoff").value),
538
+ strength:Number($("#virtualStrength").value)
539
+ };
540
+ const job=await api(`${BASE}/jobs/bass/virtual`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(payload)});
541
+ toast("Virtual Bass 2.1 wird lokal erzeugt …");
542
+ while(true){
543
+ await new Promise(resolve=>setTimeout(resolve,600));
544
+ const current=await api(`${BASE}/jobs/${job.id}`);
545
+ if(current.status==="failed")throw new Error(current.error||"Virtual Bass konnte nicht erzeugt werden.");
546
+ if(current.status==="done")break;
547
+ }
548
+ state.virtualbass=(await api(`${BASE}/projects/${state.projectId}/virtualbass`)).virtualbass;
549
+ toast("2.1-Virtual-Bass-Datei erstellt. Links/Rechts-Kanäle bleiben getrennt vom synthetischen LFE.");
550
+ }catch(error){toast(`Virtual Bass: ${error.message}`,true)}
551
+ finally{setBusy(false);renderVirtual();}
552
+ }
553
+ // NOISE-CORE: all changes require individually selected scan samples.
554
+ function noiseAudioUrl(name,preview=true) {
555
+ return `${BASE}/projects/${encodeURIComponent(state.projectId)}/noise/audio/${encodeURIComponent(name)}${preview?"?preview=true":""}`;
556
+ }
557
+ function playNoiseTrack(name) {
558
+ if(!state.noise?.repair)return;
559
+ audio.pause();
560
+ audio.src=noiseAudioUrl(name,true);
561
+ audio.dataset.stem="noise:"+name;
562
+ audio.load();
563
+ $("#playButton").disabled=false;
564
+ $("#back10").disabled=false;
565
+ $("#forward10").disabled=false;
566
+ $("#seekBar").disabled=false;
567
+ $("#nowPlaying").textContent=name==="clean"?"Manuell repariertes Signal":"DIFFERENZ: tatsächlich verändertes Musiksignal";
568
+ $("#nowPlayingSub").textContent=`NOISE-CORE · ${state.asset?.filename||""}`;
569
+ $("#playDuration").textContent=timeText(state.analysis?.duration_seconds);
570
+ audio.play().catch(()=>toast("Audio konnte nicht wiedergegeben werden.",true));
571
+ }
572
+ function renderNoise() {
573
+ const scan=state.noise?.scan;
574
+ const repair=state.noise?.repair;
575
+ $("#noiseReady").textContent=!state.asset?"DATEI IMPORTIEREN":scan?"SCAN VORHANDEN":"BEREIT";
576
+ $("#noiseScan").disabled=state.busy||!state.asset;
577
+ $("#noiseScanMeta").textContent=scan?`${scan.event_count} Kandidaten · keine automatische Veränderung`:"Noch kein Scan";
578
+ $("#noiseCount").textContent=scan?`${scan.event_count} Kandidaten`:"0 Kandidaten";
579
+ const candidates=$("#noiseCandidates");
580
+ candidates.replaceChildren();
581
+ if(!scan) {
582
+ const placeholder=el("div","empty-state");
583
+ placeholder.append(el("h3","","Noch keine Kandidaten"),el("p","","Lade eine Audiodatei und starte den Scan."));
584
+ candidates.append(placeholder);
585
+ } else if (!scan.events.length) {
586
+ candidates.append(el("p","bass-note","Keine auffälligen Einzel-Sample-Impulse gefunden. Das beweist nicht die Abwesenheit von Störungen."));
587
+ } else {
588
+ for(const event of scan.events) {
589
+ const row=el("div","noise-candidate");
590
+ const cb=el("input");
591
+ cb.type="checkbox";cb.value=String(event.sample);cb.id=`noiseEvent_${event.sample}`;
592
+ cb.addEventListener("change",()=>{$("#noiseRepair").disabled=state.busy||!document.querySelector("#noiseCandidates input:checked")});
593
+ const label=el("label");
594
+ label.htmlFor=cb.id;
595
+ label.append(el("strong","",`${event.time_seconds.toFixed(4)} s · Kandidat #${event.sample}`));
596
+ label.append(el("small","","Unsicherer Einzelimpuls · kein Nachweis für einen Defekt"));
597
+ const button=el("button","","▶ Umfeld anhören");
598
+ button.type="button";
599
+ button.addEventListener("click",()=>{
600
+ setSource("original",false);
601
+ audio.currentTime=Math.max(0,event.time_seconds-.3);
602
+ audio.play().catch(()=>toast("Original konnte nicht abgespielt werden.",true));
603
+ });
604
+ row.append(cb,label,button);
605
+ candidates.append(row);
606
+ }
607
+ }
608
+ $("#noiseRepair").disabled=state.busy||!scan||!document.querySelector("#noiseCandidates input:checked");
609
+ const results=$("#noiseTracks");
610
+ results.replaceChildren();
611
+ if(repair) {
612
+ for(const name of ["clean","difference"]) {
613
+ const track=el("div","noise-track");
614
+ track.append(el("h3","",name==="clean"?"Reparatur · nachher":"Differenzspur · entnommenes Signal"));
615
+ track.append(el("p","",name==="clean"?"Bearbeiteter Mix aus explizit bestätigten Korrekturen.":"WICHTIG: Enthält möglicherweise echte Musikanteile. Immer abhören!"));
616
+ const actions=el("div","stem-actions");
617
+ const play=el("button","","▶ Anhören");
618
+ play.addEventListener("click",()=>playNoiseTrack(name));
619
+ const download=el("a","","↓ WAV Float32");
620
+ download.href=noiseAudioUrl(name,false);download.download=`noise_${name}.wav`;
621
+ actions.append(play,download);
622
+ track.append(actions);results.append(track);
623
+ }
624
+ } else {
625
+ const blank=el("div","empty-state");
626
+ blank.append(el("h3","","Noch keine Bearbeitung"),el("p","","Das unveränderte Original ist weiterhin verfügbar."));
627
+ results.append(blank);
628
+ }
629
+ $("#noiseExport").disabled=state.busy||!repair;
630
+ const details=$("#noiseDiagnostics");details.replaceChildren();
631
+ if(scan) {
632
+ const tonal=scan.tonal_indicators||[];
633
+ details.append(el("div","noise-line",tonal.length ?
634
+ `Mögliche schmale Spektralspitzen (keine sichere Störung): ${tonal.map(t=>`${t.frequency_hz} Hz · +${t.peak_to_local_median_db} dB`).join(" | ")}. Keine automatischen Notches.`
635
+ :"Keine auffällige 50-/60-Hz-Spektralspitze festgestellt. Kein automatisches Breitband-Entrauschen."));
636
+ if(scan.event_limit_reached) details.append(el("div","noise-line","Anzeigegrenze für Klickkandidaten erreicht; vollständige Zählung siehe Bericht."));
637
+ }
638
+ if(repair) {
639
+ const report=repair.report;
640
+ details.append(el("div","noise-line",
641
+ `${report.changed_sample_frames} explizit bestätigte Einzel-Samples verändert · Max. absolute Änderung ${report.peak_absolute_change.toExponential(3)} · Rekonstruktionsfehler ${report.reconstruction_max_absolute_error.toExponential(3)}. Die Differenzspur kann musikalische Anteile enthalten.`));
642
+ }
643
+ }
644
+ async function pollNoiseJob(jobId,caption) {
645
+ while(true) {
646
+ await new Promise(resolve=>setTimeout(resolve,650));
647
+ const status=await api(`${BASE}/jobs/${jobId}`);
648
+ const pct=Math.min(100,Math.max(0,Number(status.progress)||0));
649
+ $("#noiseProgressFill").style.width=`${pct}%`;
650
+ $("#noiseProgressNum").textContent=`${pct} %`;
651
+ $("#noiseJobLabel").textContent=status.status==="queued"?"Wartet auf Worker …":status.status==="running"?caption:status.status==="done"?"Fertig":"Fehlgeschlagen";
652
+ if(status.status==="failed") throw new Error(status.error||"NOISE-CORE Job fehlgeschlagen.");
653
+ if(status.status==="done")break;
654
+ }
655
+ }
656
+ async function startNoiseScan() {
657
+ if(state.busy||!state.asset)return;
658
+ setBusy(true);
659
+ $("#noiseProgress").hidden=false;$("#noiseProgressFill").style.width="0%";
660
+ try{
661
+ const job=await api(`${BASE}/jobs/noise/scan`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({project_id:state.projectId})});
662
+ await pollNoiseJob(job.id,"Musikalische Impulse werden vorsichtig untersucht …");
663
+ const response=await api(`${BASE}/projects/${state.projectId}/noise`);
664
+ state.noise=response.noise;renderNoise();
665
+ toast("Scan beendet. Nichts wurde verändert. Bitte jeden Kandidaten einzeln prüfen.");
666
+ }catch(error){toast(`NOISE-CORE: ${error.message}`,true)}
667
+ finally{setBusy(false);renderNoise();}
668
+ }
669
+ async function startNoiseRepair() {
670
+ if(state.busy||!state.noise?.scan)return;
671
+ const selected=$$("#noiseCandidates input:checked").map(x=>Number(x.value));
672
+ if(!selected.length)return toast("Wähle eine geprüfte Klickstelle aus.",true);
673
+ if(!window.confirm(`Du hast ${selected.length} Stelle(n) ausgewählt. Diese Samples werden interpoliert. Die Differenzspur kann echte Musikanteile enthalten. Fortfahren?`))return;
674
+ setBusy(true);
675
+ $("#noiseProgress").hidden=false;$("#noiseProgressFill").style.width="0%";
676
+ try{
677
+ const job=await api(`${BASE}/jobs/noise/repair`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({
678
+ project_id:state.projectId,approved_samples:selected,
679
+ strength:Number($("#noiseStrength").value)/100
680
+ })});
681
+ await pollNoiseJob(job.id,"Nur freigegebene Einzelstellen werden behutsam bearbeitet …");
682
+ const response=await api(`${BASE}/projects/${state.projectId}/noise`);
683
+ state.noise=response.noise;renderNoise();
684
+ toast("Reparatur gerendert. Bitte die Differenzspur anhören.");
685
+ }catch(error){toast(`NOISE-CORE: ${error.message}`,true)}
686
+ finally{setBusy(false);renderNoise();}
687
+ }
688
+
689
  async function init() {
690
  resetUi();
691
  audio.volume=.8;
692
  try{
693
  const health = await api(`${BASE}/health`);
694
  maxUploadBytes = Number(health.max_upload_bytes) || maxUploadBytes;
695
+ state.virtualReady=Boolean(health.virtualbass_ready);
696
+ renderVirtual();
697
  $("#uploadLimits").textContent = `WAV · FLAC · AIFF · MP3 · OGG • bis ${Math.round(maxUploadBytes/1048576)} MiB • keine feste Zeitgrenze`;
698
  $("#guideImportLimits").textContent = `Maximale Dateigröße: ${Math.round(maxUploadBytes/1048576)} MiB. Keine feste Zeitgrenze; Verarbeitungszeit hängt von Datei und Hardware ab.`;
699
  $("#apiIndicator").classList.add("online");$("#apiLabel").textContent="ENGINE ONLINE";
 
734
  $("#dropzone").addEventListener("dragleave",()=>$("#dropzone").classList.remove("dragging"));
735
  $("#dropzone").addEventListener("drop",event=>{event.preventDefault();$("#dropzone").classList.remove("dragging");uploadFile(event.dataTransfer.files?.[0]);});
736
  $$(".method input").forEach(input=>input.addEventListener("change",()=>selectMethod(input.value)));
737
+ bassSliderIds.forEach(id=>$("#"+id).addEventListener("input",()=>{
738
+ updateBassValues();$$(".bass-preset").forEach(node=>node.classList.remove("active"));
739
+ }));
740
+ $$(".bass-preset").forEach(node=>node.addEventListener("click",()=>applyBassPreset(node.dataset.bassPreset)));
741
+ $("#virtualRun").addEventListener("click",runVirtual);
742
+ for(const id of ["virtualCutoff","virtualStrength"]) {
743
+ $("#"+id).addEventListener("input",()=>{
744
+ $("#virtualCutoffValue").textContent=$("#virtualCutoff").value+" Hz";
745
+ $("#virtualStrengthValue").textContent=Number($("#virtualStrength").value).toFixed(1);
746
+ });
747
+ }
748
+ $("#noiseScan").addEventListener("click",startNoiseScan);
749
+ $("#noiseRepair").addEventListener("click",startNoiseRepair);
750
+ $("#noiseStrength").addEventListener("input",event=>{
751
+ $("#noiseStrengthValue").textContent=`${event.target.value} %`;
752
+ });
753
+ $("#noiseExport").addEventListener("click",()=>{
754
+ if(state.projectId&&state.noise?.repair)window.location.href=`${BASE}/projects/${state.projectId}/noise/export`;
755
+ });
756
+ $("#bassRun").addEventListener("click",runBass);
757
+ $("#bassExport").addEventListener("click",()=>{
758
+ if(state.projectId&&state.bass)window.location.href=`${BASE}/projects/${state.projectId}/bass/export`;
759
+ });
760
+ applyBassPreset("transparent");
761
  $("#run").addEventListener("click",runSeparation);
762
  $("#export").addEventListener("click",()=>{if(state.projectId && Object.keys(state.stems).length) window.location.href=`${BASE}/projects/${state.projectId}/export`;});
763
  $("#waveform").addEventListener("click",event=>{
app/static/arrangement.css ADDED
@@ -0,0 +1,171 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* ABSOLUTION Ω Arrangement Studio — specialized DAW view.
2
+ Scoped to arr-* classes: existing BASS-/NOISE-CORE views remain unchanged. */
3
+ main:has(>.arr-view.active){width:100%;max-width:1840px;padding:26px 24px 22px}
4
+ .arr-view{--arr-bg:#0c1524;--arr-panel:#101d2d;--arr-muted:#91a6b9;--arr-edge:#26394b;--arr-teal:#72f3cf;--arr-gold:#f2c47c;color:#eaf6fc}
5
+ .arr-view h1,.arr-view h2,.arr-view p{margin:0}
6
+ .arr-view button,.arr-view select,.arr-view input{font:inherit}
7
+ .arr-header{display:flex;align-items:center;justify-content:space-between;gap:25px;padding:12px 7px 24px}
8
+ .arr-kicker{color:#82dfca;letter-spacing:.18em;font-size:10px;font-weight:800;display:flex;align-items:center;gap:10px;margin-bottom:16px}
9
+ .arr-light{width:8px;height:8px;border-radius:50%;background:#81f1c9;box-shadow:0 0 15px #81f1c9}
10
+ .arr-beta{margin-left:10px;font-size:10px;color:#d2e3df;background:#163f3e;border:1px solid #275d57;padding:4px 8px;border-radius:99px;letter-spacing:0}
11
+ .arr-title h1{font-weight:750;font-size:clamp(27px,3.6vw,48px);letter-spacing:-.045em;line-height:1.12}
12
+ .arr-title h1 em{font-style:normal;background:linear-gradient(100deg,#86ffdb,#65cbeb 45%,#c9acff);-webkit-background-clip:text;background-clip:text;color:transparent}
13
+ .arr-title p{color:#a1b3c6;font-size:13px;margin-top:12px;line-height:1.6}
14
+ .arr-header-actions,.arr-toolbar,.arr-plan-foot>div,.arr-footer-actions,.arr-separate-group{display:flex;align-items:center;gap:9px;flex-wrap:wrap}
15
+ .arr-header-actions{flex-shrink:0}
16
+ .arr-btn{border:1px solid #365168;border-radius:9px;background:#172738;color:#c9e9f2;padding:11px 14px;line-height:1;min-height:38px;font-weight:750;font-size:12px;display:inline-flex;justify-content:center;align-items:center;gap:8px;transition:background .15s,border-color .15s}
17
+ .arr-btn:hover{border-color:#73b9bc;background:#243b51}
18
+ .arr-btn-primary{background:linear-gradient(130deg,#74efcf,#67bbd8);color:#06232c;border-color:#8cf8d7;box-shadow:0 4px 18px #3fe8c620}
19
+ .arr-btn-primary:hover{background:#9af7d7;border-color:#d4fff1}
20
+ .arr-btn-ghost{background:#152536;color:#d0e6ef}
21
+ .arr-btn:disabled{opacity:.4;cursor:not-allowed}
22
+ .arr-status{display:flex;justify-content:space-between;align-items:center;gap:10px;white-space:nowrap;overflow:hidden;border:1px solid #28404e;background:linear-gradient(90deg,#122432,#121d2c);border-radius:9px;color:#bdd6e0;font-size:11px;padding:12px 18px}
23
+ #arrSourceName{overflow:hidden;text-overflow:ellipsis}
24
+ #arrStemStatus{color:#89ead1;font-weight:800;flex-shrink:0}
25
+ .arr-workflow{margin:15px 0 16px;display:flex;align-items:stretch;gap:11px}
26
+ .arr-step{min-width:0;flex:1;padding:13px 15px;border:1px solid #203d4a;border-radius:9px;background:#101d2a;display:grid;grid-template-columns:auto 1fr;grid-template-rows:auto auto;gap:3px 9px}
27
+ .arr-step>span{grid-row:span 2;font-size:18px;font-weight:750;color:#68dec2;align-self:center}
28
+ .arr-step strong{font-size:10px;letter-spacing:.08em}
29
+ .arr-step small{font-size:10px;color:#879eae}
30
+ .arr-workflow-arrow{display:grid;place-items:center;color:#507c83}
31
+ .arr-card{background:linear-gradient(140deg,#111e2e,#101925 90%);border:1px solid #2a3c50;border-radius:14px;box-shadow:0 18px 50px #03071117}
32
+ .arr-planning{padding:20px 21px;margin-bottom:20px}
33
+ .arr-card-head,.arr-console-top{display:flex;align-items:center;justify-content:space-between;gap:14px}
34
+ .arr-card-head h2,.arr-console-heading h2{font-size:20px;letter-spacing:-.03em;margin-top:6px}
35
+ .arr-micro{color:#87c9c4;letter-spacing:.16em;font-size:9px;font-weight:800}
36
+ .arr-kind{border:1px solid #385b6b;border-radius:30px;color:#91ecd1;background:#17363d;padding:7px 12px;font-size:9px;font-weight:800;letter-spacing:.08em;white-space:nowrap}
37
+ .arr-desc{color:#91aab9;line-height:1.6;margin:10px 0 16px!important;font-size:12px;max-width:920px}
38
+ .arr-desc strong{color:#e4f3f2}
39
+ .arr-plan-content{display:grid;grid-template-columns:repeat(auto-fill,minmax(min(100%,365px),1fr));gap:9px;margin:13px 0}
40
+ .arr-plan-row{display:flex;align-items:center;gap:10px;min-width:0;border:1px solid #2a3c4f;border-radius:9px;padding:9px 10px;background:#152638}
41
+ .arr-plan-name{min-width:75px;flex:1;border:1px solid transparent;border-radius:4px;background:transparent;color:#dbeaf4;font-size:11px;padding:6px}
42
+ .arr-plan-name:focus{border-color:#70c7c4;outline:none;background:#1d3144}
43
+ .arr-check input{width:16px;height:16px;accent-color:#70e7c9}
44
+ .arr-plan-score{width:64px;display:grid;gap:4px;flex-shrink:0;color:#a2b5bf;font-size:9px;text-align:right}
45
+ .arr-score-bar{width:100%;height:3px;border-radius:4px;background:#2d4050;overflow:hidden}
46
+ .arr-score-bar i{display:block;background:#71d3c5;height:100%}
47
+ .arr-planned-pill{font-size:8px;font-weight:900;color:#d4bb79;background:#3f3928;padding:5px;border-radius:4px}
48
+ .arr-remove{padding:0 3px;background:transparent;border:0;color:#91a1af;font-size:18px}
49
+ .arr-remove:hover{color:#ff8f99}
50
+ .arr-plan-asterisk{grid-column:1/-1;color:#879eac;font-size:10px}
51
+ .arr-empty-inline{color:#93abb9;font-size:12px;padding:13px;background:#142332;border:1px dashed #34485b;border-radius:8px}
52
+ .arr-plan-foot{border-top:1px solid #263a4c;display:flex;justify-content:space-between;gap:12px;align-items:center;padding-top:16px}
53
+ .arr-separate-group>span{font-size:10px;color:#93b5bc}
54
+ .arr-separate-group select{color:#d8eff5;background:#132533;border:1px solid #375365;border-radius:8px;padding:9px 13px;max-width:300px;font-size:11px}
55
+ .arr-separate-group select option{background:#132533}
56
+ .arr-help-text{margin-top:12px;color:#89a1b3;font-size:11px}
57
+ .arr-console{overflow:hidden}
58
+ .arr-console-top{padding:20px 20px 16px}
59
+ .arr-toolbar{gap:8px}
60
+ .arr-compact{display:flex;align-items:center;gap:8px;color:#91b0be;font-weight:800;font-size:9px;letter-spacing:.09em}
61
+ .arr-compact input{width:80px;accent-color:#71e4ca}
62
+ .arr-overview-box{padding:0 20px}
63
+ .arr-overview-title{display:flex;justify-content:space-between;background:#0b1928;border:1px solid #294151;border-bottom:0;border-radius:9px 9px 0 0;padding:10px 15px;color:#80c6bd;font-size:9px;letter-spacing:.16em;font-weight:850}
64
+ .arr-overview-title span:last-child{color:#6b91a4}
65
+ .arr-overview-canvas{position:relative;background:#0a1320;border:1px solid #294151;overflow:hidden;height:136px}
66
+ #arrOverview{display:block;width:100%;height:100%;cursor:crosshair}
67
+ .arr-overview-empty{position:absolute;inset:0;display:grid;place-items:center;color:#788f9e;font-size:12px;text-align:center;padding:15px;pointer-events:none}
68
+ .arr-playhead{position:absolute;top:0;bottom:0;border-left:2px solid #f8f6d5;box-shadow:0 0 11px #fff9;left:0;pointer-events:none}
69
+ .arr-ruler{display:flex;justify-content:space-between;padding:9px 10px;background:#0c1b2b;border:1px solid #294151;border-top:0;border-radius:0 0 8px 8px;color:#8ca9bd;font-size:10px;font-variant-numeric:tabular-nums}
70
+ .arr-mix-meta{display:flex;align-items:center;justify-content:space-between;gap:10px;flex-wrap:wrap;padding:14px 20px}
71
+ .arr-selection{display:flex;align-items:center;gap:8px;color:#9faebc;font-size:11px}
72
+ .arr-selection strong{color:#80e7cf}
73
+ .arr-sep{color:#43687a}
74
+ .arr-mix-warning{color:#8ba7b5;font-size:10px}
75
+ .arr-tracks-wrap{padding:0 20px 16px;overflow-x:auto}
76
+ .arr-track-labels,.arr-track{display:grid;grid-template-columns:260px 156px minmax(230px,1fr) 230px;gap:0;min-width:906px}
77
+ .arr-track-labels{background:#101c2b;color:#6c93a6;font-size:8px;letter-spacing:.12em;font-weight:850;border:1px solid #2b4153;border-bottom:0;border-radius:8px 8px 0 0}
78
+ .arr-track-labels>div{padding:13px 12px}
79
+ .arr-track-labels>div+div{border-left:1px solid #2b4153}
80
+ .arr-track{border:1px solid #2a3f52;border-bottom:0;background:#132132;min-height:116px}
81
+ .arr-track:last-child{border-bottom:1px solid #2a3f52;border-radius:0 0 8px 8px}
82
+ .arr-track:nth-child(even){background:#12202f}
83
+ .arr-track>div+div{border-left:1px solid #2a3f52}
84
+ .arr-track-left{padding:12px 12px;min-width:0}
85
+ .arr-track-name{display:flex;gap:10px;align-items:center;min-width:0}
86
+ .arr-track-dot{width:7px;height:31px;border-radius:5px;background:var(--arr-color);box-shadow:0 0 12px var(--arr-color);flex-shrink:0}
87
+ .arr-track-name>div{min-width:0;flex:1}
88
+ .arr-track-name strong{font-size:12px;display:block;overflow:hidden;white-space:nowrap;text-overflow:ellipsis}
89
+ .arr-track-name small{display:block;color:var(--arr-color);font-size:8px;letter-spacing:.09em;margin-top:5px}
90
+ .arr-track-preview{color:#c0dde7;background:#1c3244;border:1px solid #395062;width:27px;height:27px;display:grid;place-items:center;border-radius:6px}
91
+ .arr-track-preview:hover{background:#2d5863;color:white}
92
+ .arr-track-ctrl{margin-top:15px;display:flex;align-items:center;gap:6px}
93
+ .arr-mute,.arr-solo{width:28px;height:26px;flex-shrink:0;border:1px solid #375167;border-radius:5px;font-size:10px;font-weight:850;color:#8fabb9;background:#1b3041}
94
+ .arr-mute.on{background:#6b343a;border-color:#db7a7d;color:#ffe2e1}
95
+ .arr-solo.on{background:#675027;border-color:#f5c86b;color:#fff1c3}
96
+ .arr-track-ctrl input{min-width:35px;max-width:100%;flex:1;accent-color:var(--arr-color);height:15px}
97
+ .arr-track-ctrl output{width:39px;text-align:right;flex-shrink:0;font-size:9px;font-variant-numeric:tabular-nums;color:#c2d6e1}
98
+ .arr-pan-area{padding:15px 13px;display:flex;align-items:center;flex-direction:column;justify-content:center;gap:8px}
99
+ .arr-pan-label{width:100%;display:flex;justify-content:space-between;color:#88acbe;font-size:9px;letter-spacing:.1em;font-weight:800}
100
+ .arr-pan-label span:nth-child(2){font-size:7px;color:#6d93a1}
101
+ .arr-pan-guide{position:relative;width:100%;display:flex;align-items:center}
102
+ .arr-pan-guide>i{position:absolute;left:50%;top:-7px;bottom:-8px;border-left:1px dashed #63819a;pointer-events:none}
103
+ .arr-pan-guide input{width:100%;accent-color:var(--arr-color);z-index:1}
104
+ .arr-pan-area output{color:var(--arr-color);font-weight:850;font-size:12px;font-variant-numeric:tabular-nums}
105
+ .arr-wave-area{position:relative;background:#0a1421;overflow:hidden;min-width:0}
106
+ .arr-stemwave{display:block;width:100%;height:116px;cursor:crosshair}
107
+ .arr-stemhead{position:absolute;top:0;bottom:0;width:1px;background:#ecfbf4;box-shadow:0 0 9px #f7ffde;left:0;pointer-events:none}
108
+ .arr-fx-area{padding:10px;align-self:stretch;min-width:0}
109
+ .arr-fx{border:1px solid #304d60;background:#192c3d;border-radius:7px}
110
+ .arr-fx summary{cursor:pointer;padding:11px 12px;list-style:none;color:#d0e4e8;font-size:11px;font-weight:700;display:flex;gap:9px;align-items:center}
111
+ .arr-fx summary::-webkit-details-marker{display:none}
112
+ .arr-fx summary>span{color:var(--arr-color)}
113
+ .arr-fx summary>b{margin-left:auto;color:#8da5b7}
114
+ .arr-fx[open] summary>b{transform:rotate(45deg)}
115
+ .arr-fx-stack{padding:11px;display:grid;gap:12px;border-top:1px solid #344a59}
116
+ .arr-fx-stack label{display:grid;grid-template-columns:1fr auto;font-size:9px;font-weight:800;color:#a2c3cc;gap:6px}
117
+ .arr-fx-stack input{grid-column:1/-1;width:100%;accent-color:var(--arr-color)}
118
+ .arr-fx-stack span{color:#e5f1f4;font-variant-numeric:tabular-nums}
119
+ .arr-fx-stack small{color:#91a6b6;font-size:9px;line-height:1.5}
120
+ .arr-empty-track{min-height:170px;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:9px;padding:24px;text-align:center;color:#8aa3b2;border:1px dashed #385168;border-radius:0 0 9px 9px;font-size:11px;background:#111d2c}
121
+ .arr-empty-track strong{color:#98d7cc;letter-spacing:.15em;font-size:10px}
122
+ .arr-mixer-footer{padding:18px 20px 20px;border-top:1px solid #2b4154;display:flex;align-items:end;justify-content:space-between;gap:18px}
123
+ .arr-transform{display:flex;align-items:center;gap:18px;flex-wrap:wrap}
124
+ .arr-transform label{display:flex;flex-direction:column;gap:8px;font-size:9px;font-weight:800;letter-spacing:.08em;color:#8dabba;min-width:145px}
125
+ .arr-transform label span{font-size:12px;color:#8cf4d5;letter-spacing:0;font-variant-numeric:tabular-nums}
126
+ .arr-transform input{accent-color:#8af4d5;width:165px}
127
+ .arr-transform small{font-size:10px;color:#8498a8;max-width:200px;line-height:1.5}
128
+ .arr-footer-actions{justify-content:end}
129
+ .arr-render-report{font-size:10px;color:#96beae;font-variant-numeric:tabular-nums;max-width:250px}
130
+ .arr-download.disabled{pointer-events:none;opacity:.45}
131
+ .arr-disclaimer{font-size:11px;color:#859db0;line-height:1.6;margin:13px 8px 0!important}
132
+ @media(max-width:1600px){
133
+ .arr-track-labels,.arr-track{grid-template-columns:218px 130px minmax(200px,1fr) 198px;min-width:746px}
134
+ .arr-track-name strong{font-size:11px}
135
+ .arr-fx summary{padding:9px}
136
+ .arr-track-ctrl output{font-size:8px;width:34px}
137
+ }
138
+ @media(max-width:1100px){
139
+ .arr-header{align-items:start;flex-wrap:wrap}
140
+ .arr-plan-foot{align-items:start;flex-direction:column}
141
+ .arr-workflow{gap:5px}.arr-step{padding:9px}.arr-workflow-arrow{font-size:12px}
142
+ .arr-step strong{font-size:9px}.arr-step small{font-size:9px}
143
+ .arr-mixer-footer{align-items:start;flex-direction:column}
144
+ }
145
+ @media(max-width:760px){
146
+ main:has(>.arr-view.active){padding:20px 12px}
147
+ .arr-header{padding:4px 4px 17px}
148
+ .arr-title h1{font-size:29px}
149
+ .arr-header-actions{width:100%;justify-content:space-between}
150
+ .arr-header-actions .arr-btn{flex:1}
151
+ .arr-workflow{display:grid;grid-template-columns:1fr 1fr}
152
+ .arr-workflow-arrow{display:none}
153
+ .arr-step{min-height:61px}
154
+ .arr-planning{padding:14px}
155
+ .arr-card-head{flex-wrap:wrap}
156
+ .arr-plan-content{grid-template-columns:minmax(0,1fr)}
157
+ .arr-console-top{align-items:start;flex-direction:column;padding:16px}
158
+ .arr-overview-box,.arr-tracks-wrap{padding-left:12px;padding-right:12px}
159
+ .arr-overview-canvas{height:112px}
160
+ .arr-overview-canvas canvas{height:112px}
161
+ .arr-mix-meta{padding:12px}
162
+ .arr-mixer-footer{padding:14px 12px}
163
+ .arr-footer-actions{justify-content:start}
164
+ .arr-separate-group{align-items:stretch}
165
+ .arr-separate-group>span{width:100%}
166
+ .arr-separate-group select{flex:1;max-width:100%}
167
+ .arr-plan-row{gap:6px;padding:7px}
168
+ }
169
+
170
+ .arr-scroll-label{display:flex;align-items:center;justify-content:end;gap:10px;padding:8px 3px;color:#89a9b6;font-size:9px;font-weight:800;letter-spacing:.1em}
171
+ .arr-scroll-label input{width:min(320px,60%);accent-color:#70e4cb}
app/static/arrangement.js ADDED
@@ -0,0 +1,382 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* ABSOLUTION Ω v0.6 — no external libraries, analytics or remote requests.
2
+ * Frontend renders real sampled stem envelopes. Editable inventory is not audio.
3
+ * Mixer FX are applied only by backend after an explicit Render action.
4
+ */
5
+ "use strict";
6
+ (() => {
7
+ const A=document.querySelector.bind(document);
8
+ const ROOT="/api/v1";
9
+ const COLORS=["#5ee2cf","#f0ba72","#a99afb","#f579a2","#6eaafb","#bcf178","#f68d65",
10
+ "#6ed7f3","#d59bf4","#e7df79","#ef87b5","#7ab3c3"];
11
+ const G={
12
+ inventory:null,plan:[],real:[],peaks:{},settings:{},zoom:1,scroll:0,
13
+ mixed:null,projectId:null,rubberband:false,serverModel:true,rendering:false,
14
+ length:0
15
+ };
16
+ const escape=(x)=>String(x??"").replace(/[&<>"']/g,c=>({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"}[c]));
17
+ const dt=t=>{if(!Number.isFinite(t))return "—";let h=Math.floor(t/3600),m=Math.floor(t%3600/60),s=Math.floor(t%60);return h?`${h}:${String(m).padStart(2,"0")}:${String(s).padStart(2,"0")}`:`${m}:${String(s).padStart(2,"0")}`;};
18
+ const byId=x=>document.getElementById(x);
19
+ const notice=(txt,err=false)=>{if(typeof toast==="function")toast(txt,err);};
20
+ async function request(route,init={}){
21
+ if(typeof api==="function")return api(ROOT+route,init);
22
+ const r=await fetch(ROOT+route,init);if(!r.ok)throw new Error(`HTTP ${r.status}`);return r.json();
23
+ }
24
+ function updateStatus(){
25
+ byId("arrSourceName").textContent=state.asset?.filename||"Noch keine Datei — importiere im Studio oder lade die Demo.";
26
+ byId("arrStemStatus").textContent=`${G.real.length} echte Stems`;
27
+ byId("arrActiveTracks").textContent=`${G.real.length} reale Spuren`;
28
+ byId("arrInspect").disabled=!state.asset||G.rendering;
29
+ byId("arrSeparate").disabled=!state.asset||G.rendering;
30
+ byId("arrRender").disabled=!G.real.length||G.rendering;
31
+ byId("arrSourceName").title=state.asset?.filename||"";
32
+ const solos=G.real.filter(x=>G.settings[x]?.solo);
33
+ byId("arrSoloList").textContent=solos.length?`SOLO: ${solos.join(" · ")}`:"Keine Solo-Spur aktiv";
34
+ }
35
+ function setUnrendered(){
36
+ G.mixed=null;
37
+ byId("arrListenMix").disabled=true;
38
+ const dl=byId("arrDownload");dl.removeAttribute("href");dl.classList.add("disabled");dl.setAttribute("aria-disabled","true");
39
+ byId("arrRenderReport").textContent=G.real.length?"Änderungen ungerendert":"Noch kein Mix berechnet";
40
+ }
41
+ function reset(){
42
+ G.projectId=null;G.inventory=null;G.plan=[];G.real=[];G.peaks={};G.settings={};G.mixed=null;G.length=0;
43
+ byId("arrPlanContent").innerHTML='<div class="arr-empty-inline">Noch keine Vorinventur. Klicke auf „Mini-KI analysieren“.</div>';
44
+ renderTracks();updateStatus();setUnrendered();draw();
45
+ }
46
+ async function onProject(manifest){
47
+ const projectId=manifest.id;
48
+ const different=G.projectId!==projectId;
49
+ G.projectId=projectId;G.inventory=manifest.inventory||null;
50
+ G.plan=(manifest.plan||[]).map(p=>({...p}));
51
+ G.real=Object.keys(manifest.stems||{});
52
+ G.length=Number(manifest.analysis?.duration_seconds)||0;
53
+ if(different){G.peaks={};G.settings={};G.mixed=null;}
54
+ const settings=manifest.mixer?.settings?.tracks||{};
55
+ if(different){for(const [n,p] of Object.entries(settings))G.settings[n]={...p};}
56
+ if(different && manifest.mixer)G.mixed=manifest.mixer;
57
+ if(different){
58
+ const tempo=Math.round((manifest.mixer?.settings?.tempo??1)*100);
59
+ const pitch=Number(manifest.mixer?.settings?.pitch_semitones??0);
60
+ byId("arrTempo").value=String(tempo);
61
+ byId("arrPitch").value=String(pitch);
62
+ byId("arrTempoOut").textContent=tempo+" %";
63
+ byId("arrPitchOut").textContent=(pitch>=0?"+":"")+pitch+" HT";
64
+ }
65
+ renderPlan();renderTracks();updateStatus();
66
+ if(G.mixed)setMixed(G.mixed);
67
+ else setUnrendered();
68
+ await Promise.all([
69
+ ...["original",...G.real].map(async name=>{
70
+ if(G.peaks[name])return;
71
+ try{
72
+ const data=await request(`/projects/${encodeURIComponent(projectId)}/wave/${encodeURIComponent(name)}?points=480`);
73
+ if(G.projectId===projectId)G.peaks[name]=data.samples||[];
74
+ }catch(e){console.warn("Waveform not ready",name,e);}
75
+ }),
76
+ refreshModelStatus()
77
+ ]);
78
+ if(G.projectId===projectId)draw();
79
+ }
80
+ async function refreshModelStatus(){
81
+ try{
82
+ const m=await request("/models");
83
+ const neural=m.models?.find(x=>x.id==="demucs");
84
+ const opt=byId("arrModel").querySelector('option[value="demucs"]');
85
+ opt.disabled=!neural?.ready;
86
+ opt.textContent=neural?.ready?"Demucs · 4 Gruppen (konfiguriert)":"Demucs · lokale Gewichte fehlen";
87
+ const h=await request("/health");
88
+ G.rubberband=!!h.rubberband_ready;
89
+ byId("arrRubberbandNote").textContent=G.rubberband?
90
+ "Tempo und Transposition verwenden FFmpeg/Rubber Band beim Export. Tonart-Erkennung ist nicht implementiert.":
91
+ "Unabhängiges Tempo/Transponieren benötigt FFmpeg mit Rubber Band; Standard-Mix funktioniert ohne.";
92
+ for(const id of ["arrTempo","arrPitch"]){byId(id).disabled=!G.rubberband;}
93
+ }catch(e){console.warn("Could not refresh model capabilities",e);}
94
+ }
95
+ function renderPlan(){
96
+ const c=byId("arrPlanContent");
97
+ if(!G.inventory&&!G.plan.length){c.innerHTML='<div class="arr-empty-inline">Noch keine Mini-KI-Vorinventur. Die Hypothesen erscheinen hier.</div>';return;}
98
+ const acts=new Map((G.inventory?.detections||[]).map(x=>[x.id,x]));
99
+ c.innerHTML=G.plan.map((p,i)=>{
100
+ const act=acts.get(p.id);
101
+ return `<div class="arr-plan-row" data-plan="${i}">
102
+ <label class="arr-check"><input type="checkbox" class="arr-plan-on" ${p.enabled?"checked":""}><span></span></label>
103
+ <input class="arr-plan-name" aria-label="Trennziel ${i+1}" maxlength="100" value="${escape(p.label)}">
104
+ <div class="arr-plan-score">${act?`<div class="arr-score-bar"><i style="width:${Math.round(act.score*100)}%"></i></div><span>${Math.round(act.score*100)} / 100*</span>`:'<span>Manuell</span>'}</div>
105
+ <span class="arr-planned-pill">PLAN</span>
106
+ <button class="arr-remove" title="Planpunkt entfernen" aria-label="Trennziel entfernen">×</button>
107
+ </div>`;
108
+ }).join("")+`<small class="arr-plan-asterisk">* Unkalibrierte Modellaktivität — ausdrücklich keine Wahrscheinlichkeit, dass ein Instrument vorhanden ist.</small>`;
109
+ }
110
+ function pullPlanEdits(){
111
+ for(const node of byId("arrPlanContent").querySelectorAll(".arr-plan-row")){
112
+ const i=Number(node.dataset.plan);
113
+ if(G.plan[i]){G.plan[i].label=node.querySelector(".arr-plan-name").value.trim().slice(0,100)||"Unbenannt";
114
+ G.plan[i].enabled=node.querySelector(".arr-plan-on").checked;}
115
+ }
116
+ }
117
+ async function inspect(){
118
+ if(!state.projectId){notice("Importiere zuerst im Studio eine Datei.",true);return;}
119
+ const b=byId("arrInspect");b.disabled=true;b.textContent="✧ Analysiere lokal …";
120
+ try{
121
+ const result=await request(`/projects/${state.projectId}/inventory`,{method:"POST"});
122
+ G.inventory=result.inventory;G.plan=result.plan||[];
123
+ renderPlan();notice(`Mini-Modell: ${G.inventory.sampled_windows} Ausschnitte analysiert. Bitte Hypothesen prüfen.`);
124
+ }catch(e){notice("Mini-KI: "+e.message,true);}
125
+ finally{b.disabled=false;b.textContent="✧ Mini-KI analysieren";}
126
+ }
127
+ async function savePlan(){
128
+ if(!state.projectId){notice("Erst Datei importieren.",true);return;}
129
+ pullPlanEdits();
130
+ try{
131
+ await request(`/projects/${state.projectId}/plan`,{
132
+ method:"PUT",headers:{"content-type":"application/json"},
133
+ body:JSON.stringify({tracks:G.plan})
134
+ });
135
+ notice("Trennplan gespeichert. Noch keine Audiospur wurde dadurch erzeugt.");
136
+ }catch(e){notice("Trennplan: "+e.message,true);}
137
+ }
138
+ function defaultSettings(){return {gain_db:0,pan:0,mute:false,solo:false,highpass_hz:0,lowpass_hz:0,width:1,drive:0};}
139
+ function getSettings(name){return G.settings[name]||(G.settings[name]=defaultSettings());}
140
+ function colorFor(index){return COLORS[index%COLORS.length];}
141
+ function pretty(name){
142
+ const labels={vocals:"Gesang / Vocals",drums:"Schlagzeug / Drums",
143
+ bass:"Bass",other:"Andere Instrumente",harmonic:"Harmonische Klanganteile",
144
+ percussive:"Perkussive Klanganteile",residual:"Residuum / Restmaterial"};
145
+ return labels[name]||name.replace(/[_-]/g," ");
146
+ }
147
+ function renderTracks(){
148
+ const wrap=byId("arrTracks");
149
+ if(!G.real.length){
150
+ wrap.innerHTML='<div class="arr-empty-track"><strong>NOCH KEINE SEPARIERTEN SPUREN</strong><span>Analysiere den Track, überprüfe den Plan und starte die Separation. Die vorhandenen Stems erscheinen dann farbig auf der Timeline.</span></div>';
151
+ updateStatus();return;
152
+ }
153
+ wrap.innerHTML=G.real.map((name,i)=>{
154
+ const p=getSettings(name),color=colorFor(i);
155
+ return `<article class="arr-track" style="--arr-color:${color}" data-index="${i}">
156
+ <div class="arr-track-left">
157
+ <div class="arr-track-name"><span class="arr-track-dot"></span><div><strong title="${escape(name)}">${escape(pretty(name))}</strong><small>STEM ${String(i+1).padStart(2,"0")} · REAL AUDIO</small></div>
158
+ <button type="button" class="arr-track-preview" data-action="play" title="Diese Spur einzeln hören" aria-label="${escape(pretty(name))} anhören">▶</button>
159
+ </div>
160
+ <div class="arr-track-ctrl"><button class="arr-mute ${p.mute?"on":""}" type="button" data-action="mute" aria-pressed="${!!p.mute}" title="Mute">M</button>
161
+ <button class="arr-solo ${p.solo?"on":""}" type="button" data-action="solo" aria-pressed="${!!p.solo}" title="Solo">S</button>
162
+ <input type="range" data-param="gain_db" min="-48" max="12" step=".5" value="${p.gain_db}" aria-label="${escape(pretty(name))} Lautstärke">
163
+ <output data-output="gain_db">${p.gain_db>0?"+":""}${p.gain_db} dB</output>
164
+ </div>
165
+ </div>
166
+ <div class="arr-pan-area"><div class="arr-pan-label"><span>L</span><span>STEREO FIELD</span><span>R</span></div>
167
+ <div class="arr-pan-guide"><i></i><input type="range" data-param="pan" min="-1" max="1" step=".01" value="${p.pan}" aria-label="${escape(pretty(name))} Stereo-Panorama"></div>
168
+ <output data-output="pan">${p.pan===0?"C":p.pan<0?`L${Math.round(-p.pan*100)}`:`R${Math.round(p.pan*100)}`}</output>
169
+ </div>
170
+ <div class="arr-wave-area"><canvas class="arr-stemwave" data-wave="${i}" height="114" role="img" aria-label="Waveform ${escape(pretty(name))}" tabindex="0"></canvas><i class="arr-stemhead" aria-hidden="true"></i></div>
171
+ <div class="arr-fx-area"><details class="arr-fx"><summary><span>◈</span> Effekte <b>+</b></summary><div class="arr-fx-stack">
172
+ <label>LOW CUT <span data-output="highpass_hz">${p.highpass_hz||"Aus"}${p.highpass_hz?" Hz":""}</span><input type="range" data-param="highpass_hz" min="0" max="400" step="5" value="${p.highpass_hz}"></label>
173
+ <label>HIGH CUT <span data-output="lowpass_hz">${p.lowpass_hz?p.lowpass_hz+" Hz":"Aus"}</span><input type="range" data-param="lowpass_hz" min="0" max="18000" step="100" value="${p.lowpass_hz}"></label>
174
+ <label>SÄTTIGUNG <span data-output="drive">${Math.round(p.drive*100)} %</span><input type="range" data-param="drive" min="0" max="1" step=".01" value="${p.drive}"></label>
175
+ <label>STEREO WIDTH <span data-output="width">${Math.round(p.width*100)} %</span><input type="range" data-param="width" min="0" max="2" step=".02" value="${p.width}"></label>
176
+ <small>Effekte wirken erst nach „Mix berechnen“ und verändern nie das Original.</small>
177
+ </div></details></div>
178
+ </article>`;
179
+ }).join("");
180
+ updateStatus();requestAnimationFrame(draw);
181
+ }
182
+ function outputValue(param,p){
183
+ switch(param){
184
+ case"gain_db":return `${p>0?"+":""}${p} dB`;
185
+ case"pan":return p===0?"C":p<0?`L${Math.round(-p*100)}`:`R${Math.round(p*100)}`;
186
+ case"highpass_hz":return p?p+" Hz":"Aus";
187
+ case"lowpass_hz":return p?p+" Hz":"Aus";
188
+ case"drive":case"width":return Math.round(p*100)+" %";
189
+ }return String(p);
190
+ }
191
+ function drawCanvas(canvas,fn){
192
+ if(!canvas||!canvas.isConnected)return;
193
+ const cssW=canvas.getBoundingClientRect().width;
194
+ if(cssW<8)return;
195
+ const cssH=canvas.getBoundingClientRect().height;
196
+ const dpr=Math.min(2,window.devicePixelRatio||1);
197
+ canvas.width=Math.floor(cssW*dpr);
198
+ canvas.height=Math.floor(cssH*dpr);
199
+ const ctx=canvas.getContext("2d");ctx.setTransform(dpr,0,0,dpr,0,0);
200
+ fn(ctx,cssW,cssH);
201
+ }
202
+ function grid(ctx,w,h){
203
+ ctx.fillStyle="#0a1320";ctx.fillRect(0,0,w,h);
204
+ ctx.strokeStyle="#203044";ctx.lineWidth=.7;
205
+ for(let i=0;i<=16;i++){const x=Math.round(i*w/16)+.5;ctx.beginPath();ctx.moveTo(x,0);ctx.lineTo(x,h);ctx.stroke();}
206
+ ctx.strokeStyle="#30435a";ctx.beginPath();ctx.moveTo(0,h/2+.5);ctx.lineTo(w,h/2+.5);ctx.stroke();
207
+ }
208
+ function plot(ctx,peaks,color,w,h,zoom=1,scroll=0,alpha=1){
209
+ if(!peaks?.length)return;
210
+ ctx.strokeStyle=color;ctx.lineWidth=Math.max(.75,1/Math.min(zoom,2));ctx.globalAlpha=alpha;
211
+ const n=peaks.length;const visible=1/zoom;
212
+ const start=scroll*(1-visible);
213
+ for(let x=0;x<w;x+=2){
214
+ const fraction=x/Math.max(1,w);
215
+ const a=Math.floor((start+fraction*visible)*n);
216
+ const b=Math.max(a+1,Math.ceil((start+(fraction+2)/w*visible)*n));
217
+ let val=0;
218
+ for(let j=Math.max(0,a);j<Math.min(n,b);j++){val=Math.max(val,Math.abs(peaks[j]));}
219
+ const v=Math.min(1,Math.sqrt(val))*h*.45;
220
+ ctx.beginPath();ctx.moveTo(x,h/2-v);ctx.lineTo(x,h/2+v);ctx.stroke();
221
+ }
222
+ ctx.globalAlpha=1;
223
+ }
224
+ function draw(){
225
+ const ov=byId("arrOverview");
226
+ drawCanvas(ov,(ctx,w,h)=>{
227
+ grid(ctx,w,h);
228
+ if(G.real.length){
229
+ G.real.forEach((name,i)=>plot(ctx,G.peaks[name],colorFor(i),w,h,1,0,.7));
230
+ }else if(G.peaks.original?.length){plot(ctx,G.peaks.original,"#667688",w,h,1,0,.65);}
231
+ });
232
+ byId("arrOverviewEmpty").hidden=G.real.length>0;
233
+ for(const canvas of document.querySelectorAll(".arr-stemwave")){
234
+ const i=Number(canvas.dataset.wave),name=G.real[i];
235
+ drawCanvas(canvas,(ctx,w,h)=>{
236
+ grid(ctx,w,h);
237
+ plot(ctx,G.peaks[name],colorFor(i),w,h,G.zoom,G.scroll,.95);
238
+ });
239
+ }
240
+ const span=G.length/G.zoom,start=G.scroll*(G.length-span);
241
+ const ruler=byId("arrRuler");
242
+ ruler.innerHTML=Array.from({length:5},(_,i)=>`<span>${dt(start+span*i/4)}</span>`).join("");
243
+ updatePlayhead();
244
+ }
245
+ function updatePlayhead(){
246
+ const t=audio?.currentTime||0;
247
+ const fraction=G.length>0?Math.max(0,Math.min(1,t/G.length)):0;
248
+ byId("arrPlayhead").style.left=(fraction*100)+"%";
249
+ const visible=1/G.zoom;
250
+ const start=G.scroll*(1-visible);
251
+ const local=(fraction-start)/visible;
252
+ for(const node of document.querySelectorAll(".arr-stemhead")){
253
+ node.style.display=local>=0&&local<=1?"block":"none";
254
+ node.style.left=(local*100)+"%";
255
+ }
256
+ }
257
+ function timelineSeek(e,overview=false){
258
+ if(!G.length)return;
259
+ const rect=e.currentTarget.getBoundingClientRect();
260
+ let f=Math.max(0,Math.min(1,(e.clientX-rect.left)/rect.width));
261
+ if(!overview)f=G.scroll*(1-1/G.zoom)+f/G.zoom;
262
+ audio.currentTime=f*G.length;updatePlayhead();
263
+ }
264
+ function setMixed(mixer){
265
+ G.mixed=mixer;
266
+ byId("arrListenMix").disabled=false;
267
+ const d=byId("arrDownload");
268
+ d.href=`${ROOT}/projects/${encodeURIComponent(G.projectId)}/mixer/audio`;
269
+ d.classList.remove("disabled");d.removeAttribute("aria-disabled");
270
+ const r=mixer.result||{};
271
+ byId("arrRenderReport").textContent=`✓ WAV Float32 · Peak ${r.peak_dbfs??"—"} dBFS${r.clip_warning?" · WARNUNG: über 0 dBFS":""}`;
272
+ }
273
+ async function renderMix(){
274
+ if(!G.real.length || G.rendering){notice("Erst real separieren.",true);return;}
275
+ G.rendering=true;updateStatus();setUnrendered();
276
+ const btn=byId("arrRender");btn.textContent="◴ MIX LÄUFT …";
277
+ const project=G.projectId;
278
+ try{
279
+ const job=await request("/jobs/mix",{method:"POST",
280
+ headers:{"content-type":"application/json"},
281
+ body:JSON.stringify({project_id:project,tracks:G.settings,
282
+ tempo:Number(byId("arrTempo").value)/100,
283
+ pitch_semitones:Number(byId("arrPitch").value)})
284
+ });
285
+ while(true){
286
+ await new Promise(r=>setTimeout(r,400));
287
+ const status=await request("/jobs/"+job.id);
288
+ if(status.status==="failed")throw new Error(status.error||"Mix fehlgeschlagen");
289
+ if(project!==G.projectId)return;
290
+ byId("arrRenderReport").textContent=`Mix wird berechnet: ${status.progress||0} %`;
291
+ if(status.status==="done")break;
292
+ }
293
+ const r=await request(`/projects/${project}/mixer`);
294
+ setMixed(r.mixer);
295
+ notice("Arrangierter Mix gerendert. Hörprobe und Download bereit.");
296
+ }catch(e){notice("Arrangement: "+e.message,true);byId("arrRenderReport").textContent="Mix fehlgeschlagen";}
297
+ finally{G.rendering=false;btn.textContent="◉ Mix berechnen";updateStatus();}
298
+ }
299
+ function listenMix(){
300
+ if(!G.mixed)return;
301
+ audio.pause();
302
+ audio.src=`${ROOT}/projects/${G.projectId}/mixer/audio?v=${encodeURIComponent(G.mixed.id)}`;
303
+ state.playing="arrangement_mix";
304
+ byId("nowPlaying").textContent="Arrangement Mix";
305
+ byId("nowPlayingSub").textContent="Gerenderte Stems · Float WAV";
306
+ audio.load();audio.play().catch(()=>notice("Mix lässt sich nicht abspielen.",true));
307
+ }
308
+ function listeners(){
309
+ byId("arrDemo").addEventListener("click",loadDemo);
310
+ byId("arrInspect").addEventListener("click",inspect);
311
+ byId("arrSavePlan").addEventListener("click",savePlan);
312
+ byId("arrAddPlan").addEventListener("click",()=>{
313
+ pullPlanEdits();
314
+ if(G.plan.length>=128)return notice("Mehr als 128 Plan-Ziele erfordern ein erweitertes Ressourcenprofil.",true);
315
+ G.plan.push({id:"custom_"+Date.now().toString(36)+"_"+G.plan.length,label:"Neues Element",enabled:true});renderPlan();
316
+ });
317
+ byId("arrPlanContent").addEventListener("click",e=>{
318
+ const b=e.target.closest(".arr-remove");if(!b)return;
319
+ pullPlanEdits();G.plan.splice(Number(b.closest(".arr-plan-row").dataset.plan),1);renderPlan();
320
+ });
321
+ byId("arrSeparate").addEventListener("click",()=>{
322
+ if(!state.asset)return notice("Importiere erst Audio.",true);
323
+ const selected=byId("arrModel").value;
324
+ if(selected==="demucs" && byId("arrModel").querySelector('option[value="demucs"]').disabled)
325
+ return notice("Demucs ist ohne lokale Gewichte nicht verfügbar.",true);
326
+ selectMethod(selected);runSeparation();
327
+ });
328
+ byId("arrResetMix").addEventListener("click",()=>{
329
+ G.settings={};for(const n of G.real)G.settings[n]=defaultSettings();
330
+ byId("arrTempo").value=100;byId("arrPitch").value=0;byId("arrTempoOut").textContent="100 %";byId("arrPitchOut").textContent="±0 HT";
331
+ renderTracks();setUnrendered();
332
+ });
333
+ byId("arrTracks").addEventListener("input",e=>{
334
+ const el=e.target;
335
+ if(!el.matches("[data-param]"))return;
336
+ const node=el.closest(".arr-track"),i=Number(node.dataset.index),name=G.real[i];
337
+ if(!name)return;
338
+ const param=el.dataset.param,val=Number(el.value);
339
+ getSettings(name)[param]=val;
340
+ const output=node.querySelector(`[data-output="${param}"]`);
341
+ if(output)output.textContent=outputValue(param,val);
342
+ setUnrendered();
343
+ });
344
+ byId("arrTracks").addEventListener("click",e=>{
345
+ const a=e.target.closest("[data-action]");if(!a)return;
346
+ const row=a.closest(".arr-track"),name=G.real[Number(row.dataset.index)];
347
+ if(!name)return;
348
+ if(a.dataset.action==="play"){setSource(name,true);return;}
349
+ const s=getSettings(name),kind=a.dataset.action;
350
+ s[kind]=!s[kind];a.classList.toggle("on",s[kind]);a.setAttribute("aria-pressed",String(s[kind]));
351
+ updateStatus();setUnrendered();
352
+ });
353
+ byId("arrRender").addEventListener("click",renderMix);
354
+ byId("arrListenMix").addEventListener("click",listenMix);
355
+ byId("arrZoom").addEventListener("input",e=>{G.zoom=Number(e.target.value);draw();});
356
+ for(const [id,out,suffix] of [["arrTempo","arrTempoOut"," %"],["arrPitch","arrPitchOut"," HT"]]){
357
+ byId(id).addEventListener("input",e=>{
358
+ const v=Number(e.target.value);byId(out).textContent=(id==="arrPitch"&&v>=0?"+":"")+v+suffix;
359
+ setUnrendered();
360
+ });
361
+ }
362
+ byId("arrOverview").addEventListener("click",e=>timelineSeek(e,true));
363
+ byId("arrOverview").addEventListener("keydown",e=>{
364
+ if(e.key==="ArrowLeft"||e.key==="ArrowRight"){e.preventDefault();audio.currentTime=Math.max(0,Math.min(G.length,(audio.currentTime||0)+(e.key==="ArrowRight"?5:-5)));updatePlayhead();}
365
+ });
366
+ byId("arrTracks").addEventListener("click",e=>{
367
+ if(e.target.classList.contains("arr-stemwave"))timelineSeek(e,false);
368
+ });
369
+ byId("arrTracks").addEventListener("keydown",e=>{
370
+ if(e.target.classList.contains("arr-stemwave")&&(e.key==="ArrowLeft"||e.key==="ArrowRight")){
371
+ e.preventDefault();audio.currentTime=Math.max(0,Math.min(G.length,(audio.currentTime||0)+(e.key==="ArrowRight"?1:-1)));updatePlayhead();
372
+ }
373
+ });
374
+ window.addEventListener("resize",()=>{if(state.view==="arrangement")draw();});
375
+ audio.addEventListener("timeupdate",updatePlayhead);
376
+ byId("arrScroll")?.addEventListener("input",e=>{G.scroll=Number(e.target.value)/1000;draw();});
377
+ }
378
+ window.omegaArrangementReset=reset;
379
+ window.omegaArrangementLoad=onProject;
380
+ window.omegaArrangementDraw=()=>requestAnimationFrame(draw);
381
+ listeners();updateStatus();draw();
382
+ })();
app/static/index.html CHANGED
@@ -8,7 +8,9 @@
8
  <title>ABSOLUTION Ω — Dein Audio-Labor</title>
9
  <link rel="icon" href="/static/favicon.svg" type="image/svg+xml">
10
  <link rel="stylesheet" href="/static/style.css">
 
11
  <script src="/static/app.js" defer></script>
 
12
  </head>
13
  <body>
14
  <a class="skip-link" href="#main-content">Zum Inhalt springen</a>
@@ -21,6 +23,9 @@
21
  <div class="nav-group-label">WORKSPACE</div>
22
  <nav class="nav-stack" aria-label="Bereiche">
23
  <button class="nav-link active" data-view="studio" aria-current="page"><span class="nav-icon">◈</span> Studio <span class="nav-number">01</span></button>
 
 
 
24
  <button class="nav-link" data-view="stems"><span class="nav-icon">≋</span> Meine Stems <span class="nav-count" id="stem-count">0</span></button>
25
  <button class="nav-link" data-view="quality"><span class="nav-icon">◇</span> Forensik-Bericht <span class="nav-number">03</span></button>
26
  <button class="nav-link" data-view="guide"><span class="nav-icon">ⓘ</span> Hilfe & Technik <span class="nav-number">04</span></button>
@@ -36,7 +41,7 @@
36
  <span class="privacy-icon">◉</span>
37
  <div><strong>Lokale Verarbeitung</strong><small>Kein Cloud-Upload durch diese App</small></div>
38
  </div>
39
- <div class="sidebar-foot">ABSOLUTION Ω · v0.2 SITE<br>Forschungsversion · Single User</div>
40
  </aside>
41
 
42
  <div class="content-shell">
@@ -50,6 +55,89 @@
50
  </header>
51
 
52
  <main id="main-content" tabindex="-1">
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53
  <section id="view-studio" class="view active" aria-label="Audio-Studio">
54
  <div class="hero">
55
  <div class="hero-copy">
@@ -123,6 +211,105 @@
123
  <div id="stemsPreview" class="stems-preview"><div class="empty-state"><div class="empty-icon">≋</div><h3>Noch keine Stems vorhanden</h3><p>Importiere einen Track und starte die Separation. Deine Ergebnisse erscheinen genau hier.</p></div></div>
124
  </section>
125
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
126
  <section id="view-stems" class="view" aria-label="Export und Stems">
127
  <div class="page-heading"><span class="eyebrow">WORKSPACE / STEM LIBRARY</span><h1>Jeder Klang. <em>Einzeln.</em></h1><p>Höre die getrennten Komponenten an und exportiere die unkomprimierten Dateien.</p></div>
128
  <div class="section-header section-header-tight"><div><span class="section-numeral">LIBRARY</span><h2>Extrahierte Audiospuren</h2></div><button id="export" class="btn btn-primary" type="button" disabled>Alle Stems als ZIP <span>↓</span></button></div>
@@ -153,7 +340,7 @@
153
  </div>
154
  <div class="help-split">
155
  <section class="panel help-panel"><span class="eyebrow">WAS IST BEREITS MÖGLICH?</span><ul class="feature-list"><li>✓ Audioanalyse und Wellenform</li><li>✓ Harmonic-Percussive-Separation</li><li>✓ Residual- und Rekonstruktionsprüfung</li><li>✓ Originaltreue und SHA-256-Nachweis</li><li>✓ Browser-Player und WAV-Export</li><li>◌ Optionales Demucs mit lokalen Gewichten</li></ul></section>
156
- <section class="panel help-panel"><span class="eyebrow">NOCH NICHT VERFÜGBAR</span><ul class="feature-list future"><li>— Freie Sprachbefehle für beliebige Klänge</li><li>— Restaurations- und Masteringmodule</li><li>— Echte Sprecher- und Instrumentenerkennung mit HPSS</li><li>— Cloud-GPU oder öffentliche Mehrnutzer-Website</li><li>— Native Desktop-App</li></ul><p class="help-note">Aus Sicherheitsgründen ausschließlich lokal oder in einer geschützten Umgebung verwenden. Die Anwendung besitzt noch keine Anmeldung.</p></section>
157
  </div>
158
  <div class="guide-actions"><button data-goto="studio" class="btn btn-primary" type="button">Audio-Labor öffnen <span>↗</span></button><a href="/docs" class="btn btn-outline">API-Dokumentation ↗</a></div>
159
  </section>
 
8
  <title>ABSOLUTION Ω — Dein Audio-Labor</title>
9
  <link rel="icon" href="/static/favicon.svg" type="image/svg+xml">
10
  <link rel="stylesheet" href="/static/style.css">
11
+ <link rel="stylesheet" href="/static/arrangement.css">
12
  <script src="/static/app.js" defer></script>
13
+ <script src="/static/arrangement.js" defer></script>
14
  </head>
15
  <body>
16
  <a class="skip-link" href="#main-content">Zum Inhalt springen</a>
 
23
  <div class="nav-group-label">WORKSPACE</div>
24
  <nav class="nav-stack" aria-label="Bereiche">
25
  <button class="nav-link active" data-view="studio" aria-current="page"><span class="nav-icon">◈</span> Studio <span class="nav-number">01</span></button>
26
+ <button class="nav-link" data-view="arrangement"><span class="nav-icon">▥</span> Arrangement <span class="nav-number">NEU</span></button>
27
+ <button class="nav-link" data-view="bass"><span class="nav-icon">♮</span> BASS-CORE <span class="nav-number">02</span></button>
28
+ <button class="nav-link" data-view="noise"><span class="nav-icon">⌁</span> NOISE-CORE <span class="nav-number">03</span></button>
29
  <button class="nav-link" data-view="stems"><span class="nav-icon">≋</span> Meine Stems <span class="nav-count" id="stem-count">0</span></button>
30
  <button class="nav-link" data-view="quality"><span class="nav-icon">◇</span> Forensik-Bericht <span class="nav-number">03</span></button>
31
  <button class="nav-link" data-view="guide"><span class="nav-icon">ⓘ</span> Hilfe & Technik <span class="nav-number">04</span></button>
 
41
  <span class="privacy-icon">◉</span>
42
  <div><strong>Lokale Verarbeitung</strong><small>Kein Cloud-Upload durch diese App</small></div>
43
  </div>
44
+ <div class="sidebar-foot">ABSOLUTION Ω · v0.6 ARRANGEMENT<br>Forschungsversion · Single User</div>
45
  </aside>
46
 
47
  <div class="content-shell">
 
55
  </header>
56
 
57
  <main id="main-content" tabindex="-1">
58
+ <section id="view-arrangement" class="view arr-view" aria-label="Mehrspur-Arrangement Studio">
59
+ <div class="arr-header">
60
+ <div class="arr-title">
61
+ <div class="arr-kicker"><span class="arr-light"></span> ABSOLUTION Ω / MULTITRACK WORKSTATION <span class="arr-beta">v0.6</span></div>
62
+ <h1>Alle Frequenzen. <em>Alle Ebenen.</em></h1>
63
+ <p>KI-Vorinventur → editierbarer Trennplan → echte Stems → präziser Mix. Originaltreue steht über aggressiver Verarbeitung.</p>
64
+ </div>
65
+ <div class="arr-header-actions">
66
+ <button class="arr-btn arr-btn-ghost" id="arrDemo">♫ Demo laden</button>
67
+ <button class="arr-btn arr-btn-primary" id="arrInspect">✧ Mini-KI analysieren</button>
68
+ </div>
69
+ </div>
70
+
71
+ <div class="arr-status" role="status" aria-live="polite"><span id="arrSourceName">Noch keine Datei — importiere im Studio oder lade die Demo.</span><span id="arrStemStatus">0 echte Stems</span></div>
72
+
73
+ <div class="arr-workflow">
74
+ <div class="arr-step"><span>01</span><strong>KI-VORINVENTUR</strong><small>Hypothesen, keine Stems</small></div>
75
+ <div class="arr-workflow-arrow">→</div>
76
+ <div class="arr-step"><span>02</span><strong>TRENNPLAN</strong><small>frei editierbar</small></div>
77
+ <div class="arr-workflow-arrow">→</div>
78
+ <div class="arr-step"><span>03</span><strong>QUELLENSEPARATION</strong><small>HPSS oder lokale Demucs</small></div>
79
+ <div class="arr-workflow-arrow">→</div>
80
+ <div class="arr-step"><span>04</span><strong>ARRANGEMENT</strong><small>bearbeiten &amp; exportieren</small></div>
81
+ </div>
82
+
83
+ <section class="arr-planning arr-card">
84
+ <div class="arr-card-head"><div><span class="arr-micro">KI-ANALYSE / ELEMENTAR-PLANER</span><h2>Was steckt in deinem Track?</h2></div>
85
+ <span class="arr-kind">OMEGA-TAG MINI · LOKAL</span></div>
86
+ <p class="arr-desc">Das kleine neuronale Modell wurde auf synthetischen Überlagerungen feinjustiert. Es erkennt nur grobe Klangtexturen als <strong>unsichere Hypothesen</strong> — keine zuverlässigen Instrumentnamen. Markiere, benenne und ergänze die gewünschten Trennziele.</p>
87
+ <div class="arr-plan-content" id="arrPlanContent"><div class="arr-empty-inline">Noch keine Vorinventur. Klicke auf „Mini-KI analysieren“.</div></div>
88
+ <div class="arr-plan-foot">
89
+ <div><button class="arr-btn arr-btn-ghost" id="arrAddPlan">+ Trennziel hinzufügen</button><button class="arr-btn arr-btn-ghost" id="arrSavePlan">Plan speichern</button></div>
90
+ <div class="arr-separate-group"><span>Reale Stems erzeugen mit</span><select id="arrModel"><option value="hpss">HPSS / DSP · 3 Signalanteile</option><option value="demucs">Demucs · 4 Instrument-Gruppen (nur mit Gewichten)</option></select><button class="arr-btn arr-btn-primary" id="arrSeparate">Separation starten ↗</button></div>
91
+ </div>
92
+ <div class="arr-help-text" id="arrPlanHint">Der Trennplan kann mehr Ziele enthalten als das gewählte Modell separat erzeugen kann. Nicht verfügbare Instrumente bleiben Planungseinträge, keine Audiodateien.</div>
93
+ </section>
94
+
95
+ <section class="arr-console arr-card">
96
+ <div class="arr-console-top">
97
+ <div class="arr-console-heading"><span class="arr-micro">MULTI-STEM WORKSPACE / MIXER</span><h2>Arrangement &amp; Frequenzspuren</h2></div>
98
+ <div class="arr-toolbar">
99
+ <label class="arr-compact">ZOOM <input id="arrZoom" type="range" min="1" max="4" step="0.5" value="1" aria-label="Timeline-Zoom"></label>
100
+ <button class="arr-btn arr-btn-ghost" id="arrResetMix">↺ Regler zurücksetzen</button>
101
+ <button class="arr-btn arr-btn-primary" id="arrRender">◉ Mix berechnen</button>
102
+ </div>
103
+ </div>
104
+
105
+ <div class="arr-overview-box">
106
+ <div class="arr-overview-title"><span>MASTER OVERVIEW</span><span id="arrOverviewInfo">ALLE ELEMENTE / FARBEN</span></div>
107
+ <div class="arr-overview-canvas">
108
+ <canvas id="arrOverview" height="136" aria-label="Farbig überlagerte, tatsächlich separierte Signalwellen" role="img" tabindex="0"></canvas>
109
+ <div id="arrPlayhead" class="arr-playhead" aria-hidden="true"></div>
110
+ <span id="arrOverviewEmpty" class="arr-overview-empty">Nach der Separation erscheinen hier alle Spuren in ihren eigenen Farben.</span>
111
+ </div>
112
+ <div class="arr-ruler" id="arrRuler"><span>0:00</span><span>—</span><span>—</span><span>—</span><span>—</span></div>
113
+ <label class="arr-scroll-label">TIMELINE SCHIEBEN <input id="arrScroll" type="range" min="0" max="1000" value="0" aria-label="Timeline horizontal verschieben"></label>
114
+ </div>
115
+ <div class="arr-mix-meta">
116
+ <div class="arr-selection"><strong id="arrActiveTracks">0 Spuren</strong><span class="arr-sep">/</span><span id="arrSoloList">Keine Solo-Spur aktiv</span></div>
117
+ <div class="arr-mix-warning">ⓘ Keine automatische Klangänderung · Original bleibt sicher</div>
118
+ </div>
119
+ <div class="arr-tracks-wrap">
120
+ <div class="arr-track-labels">
121
+ <div>SPUR · LEVEL · MUTE / SOLO</div><div>STEREOFELD / PAN</div><div>FREQUENZ-WAVEFORM / ZEIT</div><div>EFFEKTE / MODULE</div>
122
+ </div>
123
+ <div id="arrTracks"><div class="arr-empty-track">Hier erscheinen deine tatsächlich separierten Stems. Die Anzahl richtet sich nach dem Separationsmodell und den vorhandenen Quellen.</div></div>
124
+ </div>
125
+ <div class="arr-mixer-footer">
126
+ <div class="arr-transform">
127
+ <label>TEMPO <span id="arrTempoOut">100 %</span><input type="range" id="arrTempo" min="50" max="200" value="100" step="5"></label>
128
+ <label>TONHÖHE / TRANSPOSE <span id="arrPitchOut">±0 HT</span><input type="range" id="arrPitch" min="-12" max="12" step="1" value="0"></label>
129
+ <small id="arrRubberbandNote">Unabhängiges Tempo/Transponieren benötigt FFmpeg mit Rubber Band. Die Tonart wird nicht automatisch erkannt.</small>
130
+ </div>
131
+ <div class="arr-footer-actions">
132
+ <span id="arrRenderReport" class="arr-render-report">Noch kein Mix berechnet</span>
133
+ <button class="arr-btn arr-btn-ghost" id="arrListenMix" disabled>▶ Mix anhören</button>
134
+ <a class="arr-btn arr-btn-primary arr-download disabled" id="arrDownload" aria-disabled="true">↓ WAV exportieren</a>
135
+ </div>
136
+ </div>
137
+ </section>
138
+ <p class="arr-disclaimer">Präzisionshinweis: Farbige Wellenformen sind Visualisierungen realer, geschätzter Stems; die Mini-KI liefert nur Textur-Hypothesen. Der Offline-Mix kann mit Filtern, Sättigung, Pan und Transposition hörbar vom Original abweichen und wird deshalb separat gerendert.</p>
139
+ </section>
140
+
141
  <section id="view-studio" class="view active" aria-label="Audio-Studio">
142
  <div class="hero">
143
  <div class="hero-copy">
 
211
  <div id="stemsPreview" class="stems-preview"><div class="empty-state"><div class="empty-icon">≋</div><h3>Noch keine Stems vorhanden</h3><p>Importiere einen Track und starte die Separation. Deine Ergebnisse erscheinen genau hier.</p></div></div>
212
  </section>
213
 
214
+ <section id="view-bass" class="view" aria-label="BASS-CORE Bass-Labor">
215
+ <div class="page-heading">
216
+ <span class="eyebrow">ABSOLUTION Ω / BASS-CORE · v0.3</span>
217
+ <h1>Tiefen verstehen. <em>Bass formen.</em></h1>
218
+ <p>Kick-Impulse, Bassline, Subfrequenzen und synthetische Obertöne kontrolliert bearbeiten. Vollständig lokal, ohne Veränderung des Originals.</p>
219
+ </div>
220
+ <div class="bass-truth"><strong>Was dieser Modus tatsächlich macht</strong><p>DSP schätzt Kick- und Bassanteile aus tiefen Frequenzen – keine perfekte Instrumententrennung. Liegen HPSS-Stems oder separat erzeugte Demucs-Bass/Drum-Stems vor, verwendet „Automatisch“ diese als bessere Ausgangsschätzung. Zugesetzte Obertöne sind synthetisiert und werden nicht als zurückgewonnene Originalinformationen ausgegeben.</p></div>
221
+ <section class="panel bass-workspace">
222
+ <div class="panel-head"><div><span class="eyebrow">01 / AUDIO SOURCE ROUTING</span><h2>Analysiere die Tiefen</h2></div><span id="bassReady" class="panel-pill">DATEI IMPORTIEREN</span></div>
223
+ <div class="bass-mode-row">
224
+ <label for="bassMode">Quellenbasis</label>
225
+ <select id="bassMode" class="bass-select">
226
+ <option value="auto">Automatisch · Beste vorhandene Stems</option>
227
+ <option value="dsp">DSP · Tiefband und Transienten</option>
228
+ <option value="hpss">HPSS · Harmonisch / Perkussiv (vorher trennen)</option>
229
+ <option value="demucs">Demucs · Bass / Drums (vorher trennen)</option>
230
+ </select>
231
+ </div>
232
+ <div class="bass-presets" role="group" aria-label="Bass-Presets">
233
+ <button type="button" class="bass-preset active" data-bass-preset="transparent">Originaltreu</button>
234
+ <button type="button" class="bass-preset" data-bass-preset="club">Club / Punch</button>
235
+ <button type="button" class="bass-preset" data-bass-preset="warm">Warm &amp; rund</button>
236
+ <button type="button" class="bass-preset" data-bass-preset="translate">Kleine Lautsprecher</button>
237
+ </div>
238
+ <div class="bass-controls">
239
+ <label class="bass-control"><span>Low-Band-Grenze <small>Cutoff / Frequenzbereich</small></span><output id="bassCrossoverValue">220 Hz</output><input type="range" id="bassCrossover" min="45" max="350" value="220" step="5"></label>
240
+ <label class="bass-control"><span>Kick-Erkennung <small>Transienten-Gewichtung nur in DSP</small></span><output id="bassFocusValue">75 %</output><input type="range" id="bassFocus" min="0" max="100" value="75" step="5"></label>
241
+ <label class="bass-control"><span>Kick-Punch <small>Geschätzte Kick-Lautstärke</small></span><output id="bassKickValue">+0.0 dB</output><input type="range" id="bassKick" min="-12" max="12" value="0" step=".5"></label>
242
+ <label class="bass-control"><span>Bassline-Körper <small>Geschätzter Bassline-Anteil</small></span><output id="bassLineValue">+0.0 dB</output><input type="range" id="bassLine" min="-12" max="12" value="0" step=".5"></label>
243
+ <label class="bass-control"><span>Subfrequenzen <small>Bassline unter ca. 65 Hz</small></span><output id="bassSubValue">+0.0 dB</output><input type="range" id="bassSub" min="-12" max="12" value="0" step=".5"></label>
244
+ <label class="bass-control"><span>Obertöne hinzufügen <small>Synthetische Sättigung, kein Repair</small></span><output id="bassHarmValue">20 %</output><input type="range" id="bassHarm" min="0" max="100" value="20" step="5"></label>
245
+ <label class="bass-control"><span>Rumpeln entfernen <small>Hochpass im bearbeiteten Bass</small></span><output id="bassLowcutValue">22 Hz</output><input type="range" id="bassLowcut" min="10" max="45" value="22" step="1"></label>
246
+ <label class="bass-control"><span>Mono-Bass bis <small>Nur im veränderten Bassband</small></span><output id="bassMonoValue">100 Hz</output><input type="range" id="bassMono" min="0" max="180" value="100" step="10"></label>
247
+ <label class="bass-control"><span>Dry / Wet <small>Nur die Bassbearbeitung mischen</small></span><output id="bassWetValue">100 %</output><input type="range" id="bassWet" min="0" max="100" value="100" step="5"></label>
248
+ <label class="bass-control"><span>Peak-Ceiling <small>Globale Verstärkung des Mix-Exports</small></span><output id="bassCeilingValue">−1.0 dBFS</output><input type="range" id="bassCeiling" min="-6" max="-.1" value="-1" step=".1"></label>
249
+ </div>
250
+ <div class="bass-action-row">
251
+ <button id="bassRun" class="btn btn-primary" type="button" disabled>Bass analysieren &amp; optimieren ↗</button>
252
+ <button id="bassExport" class="btn btn-outline" type="button" disabled>↓ Alle Bass-Tracks herunterladen</button>
253
+ </div>
254
+ <div class="job-progress" id="bassProgress" hidden role="status" aria-live="polite"><div class="job-track"><div id="bassProgressFill"></div></div><div class="job-label"><span id="bassJobLabel">Vorbereitung …</span><span id="bassProgressNum">0 %</span></div></div>
255
+ </section>
256
+ <div class="section-header section-header-tight"><div><span class="section-numeral">02 — RESULTS / BEFORE AFTER</span><h2>Deine Tiefen, einzeln hörbar</h2></div></div>
257
+ <div class="bass-stats" id="bassStats"><div><span>QUELLENMODUS</span><strong id="bassSourceUsed">—</strong></div><div><span>OPTIMIERTER MIX-PEAK</span><strong id="bassMixPeak">—</strong></div><div><span>CEILING-ABSENKUNG</span><strong id="bassPeakGain">—</strong></div><div><span>REKONSTRUKTION</span><strong id="bassRecon">—</strong></div></div>
258
+ <div id="bassResults" class="bass-result-grid"><div class="empty-state"><h3>Noch keine Bass-Bearbeitung</h3><p>Importiere Audio im Studio und starte hier das BASS-CORE Processing.</p></div></div>
259
+ <div class="panel bass-spectrum"><div class="panel-head"><div><span class="eyebrow">03 / FREQUENCY INSPECTOR</span><h2>Frequenzenergie vor / nach Bearbeitung</h2></div></div><div id="bassFrequency" class="bass-frequency-empty">Nach dem Processing werden hier gemessene Frequenzbänder von 20 bis 1280 Hz angezeigt.</div><p class="bass-note">RMS-Bandschätzungen des ersten Processing-Blocks, keine Einzelnoten oder instrumentengenaue Quellenidentifikation. Vergleiche immer mit pegelangepasster Hörprobe.</p></div>
260
+ <div class="panel noise-panel" style="margin-top:24px">
261
+ <div class="panel-head"><div><span class="eyebrow">04 / OPTIONAL LFE SYNTHESIS</span><h2>Virtual Bass — wie bei Kdenlive</h2></div><span id="virtualReady" class="panel-pill">FFMPEG / OPTIONAL</span></div>
262
+ <p class="bass-note">Der FFmpeg-Filter <code>virtualbass</code> erzeugt einen zusätzlichen künstlichen LFE-Kanal (Stereo → 2.1). Die ursprünglichen Links-/Rechts-Kanäle werden im Filter nicht verändert. Keine Original-Bass-Restauration und nicht für normale Stereo-Player gedacht.</p>
263
+ <div class="noise-tools">
264
+ <label for="virtualCutoff">LFE Cutoff <strong id="virtualCutoffValue">250 Hz</strong></label>
265
+ <input id="virtualCutoff" type="range" min="100" max="500" step="10" value="250">
266
+ <label for="virtualStrength">Virtual Bass Stärke <strong id="virtualStrengthValue">1.0</strong></label>
267
+ <input id="virtualStrength" type="range" min=".5" max="3" step=".1" value="1">
268
+ <button id="virtualRun" class="btn btn-outline" type="button" disabled>2.1 Virtual Bass erzeugen</button>
269
+ <a id="virtualDownload" class="btn btn-primary" href="#" hidden>↓ LFE 2.1 WAV herunterladen</a>
270
+ <p class="bass-note" id="virtualSummary">Benötigt eine Stereo-Datei und lokal installiertes FFmpeg mit virtualbass-Filter.</p>
271
+ </div>
272
+ </div>
273
+ </section>
274
+
275
+
276
+ <section id="view-noise" class="view" aria-label="NOISE-CORE Störgeräuschinspektor">
277
+ <div class="page-heading">
278
+ <span class="eyebrow">WORKSPACE / NOISE-CORE Ω v0.4</span>
279
+ <h1>Musik bewahren. <em>Störquellen prüfen.</em></h1>
280
+ <p>Jeder Ton zählt. Wir markieren isolierte Klick-Verdachtsfälle, aber entfernen standardmäßig nichts. Nur von dir einzeln bestätigte Stellen werden vorsichtig interpoliert.</p>
281
+ </div>
282
+ <div class="noise-law">
283
+ <strong>◉ PRESERVE FIRST — DAS KLANGSCHUTZ-GESETZ</strong>
284
+ <p>Kein automatisches De-Noise oder Notch-Filtering. Kein pauschales Löschen von Rauschen, „Luft“, Hall oder Musiktransienten. Bearbeitungen benötigen deine Freigabe; die Differenzspur zeigt, was tatsächlich verändert wurde.</p>
285
+ </div>
286
+ <div class="panel noise-panel">
287
+ <div class="panel-head"><div><span class="eyebrow">01 / NON-DESTRUCTIVE SCAN</span><h2>Störgeräusche untersuchen</h2></div><span id="noiseReady" class="panel-pill">DATEI IMPORTIEREN</span></div>
288
+ <p class="bass-note">Einzelne Sample-Ausreißer werden als <strong>Hypothesen</strong> markiert. Musik mit scharfen Transienten kann dieselben Muster erzeugen. Es findet zunächst keine Signalveränderung statt.</p>
289
+ <div class="noise-actions"><button id="noiseScan" class="btn btn-primary" type="button" disabled>♫ Störspur analysieren →</button><span id="noiseScanMeta">Noch kein Scan</span></div>
290
+ <div class="job-progress" id="noiseProgress" hidden>
291
+ <div class="progress-top"><strong id="noiseJobLabel">Analyse …</strong><span id="noiseProgressNum">0 %</span></div>
292
+ <div class="progress-track"><div id="noiseProgressFill"></div></div>
293
+ </div>
294
+ </div>
295
+ <div class="panel noise-panel">
296
+ <div class="panel-head"><div><span class="eyebrow">02 / REVIEW REQUIRED</span><h2>Klick-Verdachtsfälle freigeben</h2></div><span id="noiseCount" class="panel-pill">0 Kandidaten</span></div>
297
+ <p class="bass-note">Prüfe jede Markierung im Original. Eine Markierung ist kein Nachweis für ein Störgeräusch. Niemals blind alle auswählen.</p>
298
+ <div id="noiseCandidates" class="noise-candidates"><div class="empty-state"><h3>Noch keine Kandidaten</h3><p>Starte zuerst den Scan.</p></div></div>
299
+ <div class="noise-tools">
300
+ <label for="noiseStrength">Reparaturstärke <strong id="noiseStrengthValue">80 %</strong></label>
301
+ <input id="noiseStrength" type="range" min="0" max="100" step="5" value="80">
302
+ <span class="bass-note">Nur ausdrücklich markierte Einzel-Samples werden verändert. 0 % = keine Änderung, 100 % = lineare Nachbarinterpolation.</span>
303
+ <button id="noiseRepair" class="btn btn-primary" type="button" disabled>Ausgewählte Stellen reparieren →</button>
304
+ </div>
305
+ </div>
306
+ <div class="panel noise-panel">
307
+ <div class="panel-head"><div><span class="eyebrow">03 / DIFFERENCE MONITOR</span><h2>Original · Reparatur · Differenzspur</h2></div><button id="noiseExport" class="btn btn-outline" type="button" disabled>WAVs + Bericht als ZIP ↓</button></div>
308
+ <div id="noiseTracks" class="noise-track-grid"><div class="empty-state"><h3>Noch keine Bearbeitung</h3><p>Die Originaldatei bleibt jederzeit erhalten. Nach einer Reparatur kannst du das Ergebnis und die Differenzspur anhören.</p></div></div>
309
+ <div id="noiseDiagnostics" class="noise-diagnostics"></div>
310
+ </div>
311
+ </section>
312
+
313
  <section id="view-stems" class="view" aria-label="Export und Stems">
314
  <div class="page-heading"><span class="eyebrow">WORKSPACE / STEM LIBRARY</span><h1>Jeder Klang. <em>Einzeln.</em></h1><p>Höre die getrennten Komponenten an und exportiere die unkomprimierten Dateien.</p></div>
315
  <div class="section-header section-header-tight"><div><span class="section-numeral">LIBRARY</span><h2>Extrahierte Audiospuren</h2></div><button id="export" class="btn btn-primary" type="button" disabled>Alle Stems als ZIP <span>↓</span></button></div>
 
340
  </div>
341
  <div class="help-split">
342
  <section class="panel help-panel"><span class="eyebrow">WAS IST BEREITS MÖGLICH?</span><ul class="feature-list"><li>✓ Audioanalyse und Wellenform</li><li>✓ Harmonic-Percussive-Separation</li><li>✓ Residual- und Rekonstruktionsprüfung</li><li>✓ Originaltreue und SHA-256-Nachweis</li><li>✓ Browser-Player und WAV-Export</li><li>◌ Optionales Demucs mit lokalen Gewichten</li></ul></section>
343
+ <section class="panel help-panel"><span class="eyebrow">NOCH NICHT VERFÜGBAR</span><ul class="feature-list future"><li>— Freie Sprachbefehle für beliebige Klänge</li><li>✓ NOISE-CORE: manuelle Einzelklick-Reparatur · breitbandige Entrauschung noch nicht verfügbar</li><li>— Echte Sprecher- und Instrumentenerkennung mit HPSS</li><li>— Cloud-GPU oder öffentliche Mehrnutzer-Website</li><li>— Native Desktop-App</li></ul><p class="help-note">Aus Sicherheitsgründen ausschließlich lokal oder in einer geschützten Umgebung verwenden. Die Anwendung besitzt noch keine Anmeldung.</p></section>
344
  </div>
345
  <div class="guide-actions"><button data-goto="studio" class="btn btn-primary" type="button">Audio-Labor öffnen <span>↗</span></button><a href="/docs" class="btn btn-outline">API-Dokumentation ↗</a></div>
346
  </section>
app/static/style.css CHANGED
@@ -28,3 +28,59 @@ main{width:min(1440px,100%);margin:0 auto;flex:1;padding:38px 44px 20px}.view{di
28
  @media(max-width:750px){.sidebar{transform:translateX(-100%);transition:transform .2s;width:260px;flex-basis:260px;box-shadow:0 0 40px #02071190}.sidebar.open{transform:translateX(0)}.content-shell{margin-left:0}.transport{left:0;height:76px;padding:0 13px}.topbar{height:60px;padding:0 18px}.menu-toggle{display:block;font-size:23px;padding:0 8px 0 0}.top-right{gap:8px}.top-help{display:none}.crumb{font-size:9px}main{padding:20px 16px}.hero{min-height:auto;padding:25px 22px;margin-bottom:27px}.hero h1{font-size:clamp(28px,7vw,42px)}.hero-tags{gap:10px;font-size:9px}.upload-surface{flex-wrap:wrap;padding:18px;gap:13px}.upload-icon{height:49px;width:49px;font-size:30px}.upload-copy{flex-basis:calc(100% - 75px)}.upload-browse{width:100%}.import-footer{flex-wrap:wrap}.import-optional{display:none}.stems-preview,.stems-full,.report-grid,.guide-grid,.help-split{grid-template-columns:1fr}.page-footer{padding:14px 16px 22px;flex-wrap:wrap}.transport-track{width:140px}.transport-volume{display:none}.report-banner{padding:19px}.report-mark{height:45px;width:45px;font-size:25px}.provenance-panel dl>div{grid-template-columns:1fr;gap:5px}.mobile-scrim{position:fixed;inset:0;background:#0009;z-index:18}.quickresults-heading{align-items:start}.quickresults-heading .btn{padding:10px;font-size:10px}.waveform-frame{height:160px}}
29
  @media(max-width:450px){.api-indicator span{display:none}.hero h1{font-size:30px}.hero-tags{gap:10px}.transport-track{max-width:100px}.track-thumb{display:none}.transport{gap:8px}.transport-timeline{gap:6px}.transport-timeline span{font-size:8px}.transport-main{min-width:0}.transport-controls{gap:7px}.audio-stats strong{font-size:13px}.section-header h2,.quickresults-heading h2{font-size:18px}.quickresults-heading .btn{font-size:0;gap:0}.quickresults-heading .btn span{font-size:18px}.wave-panel,.engine-panel{padding:15px}}
30
  @media(prefers-reduced-motion:reduce){*,*:before,*:after{scroll-behavior:auto!important;transition:none!important;animation:none!important}}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
  @media(max-width:750px){.sidebar{transform:translateX(-100%);transition:transform .2s;width:260px;flex-basis:260px;box-shadow:0 0 40px #02071190}.sidebar.open{transform:translateX(0)}.content-shell{margin-left:0}.transport{left:0;height:76px;padding:0 13px}.topbar{height:60px;padding:0 18px}.menu-toggle{display:block;font-size:23px;padding:0 8px 0 0}.top-right{gap:8px}.top-help{display:none}.crumb{font-size:9px}main{padding:20px 16px}.hero{min-height:auto;padding:25px 22px;margin-bottom:27px}.hero h1{font-size:clamp(28px,7vw,42px)}.hero-tags{gap:10px;font-size:9px}.upload-surface{flex-wrap:wrap;padding:18px;gap:13px}.upload-icon{height:49px;width:49px;font-size:30px}.upload-copy{flex-basis:calc(100% - 75px)}.upload-browse{width:100%}.import-footer{flex-wrap:wrap}.import-optional{display:none}.stems-preview,.stems-full,.report-grid,.guide-grid,.help-split{grid-template-columns:1fr}.page-footer{padding:14px 16px 22px;flex-wrap:wrap}.transport-track{width:140px}.transport-volume{display:none}.report-banner{padding:19px}.report-mark{height:45px;width:45px;font-size:25px}.provenance-panel dl>div{grid-template-columns:1fr;gap:5px}.mobile-scrim{position:fixed;inset:0;background:#0009;z-index:18}.quickresults-heading{align-items:start}.quickresults-heading .btn{padding:10px;font-size:10px}.waveform-frame{height:160px}}
29
  @media(max-width:450px){.api-indicator span{display:none}.hero h1{font-size:30px}.hero-tags{gap:10px}.transport-track{max-width:100px}.track-thumb{display:none}.transport{gap:8px}.transport-timeline{gap:6px}.transport-timeline span{font-size:8px}.transport-main{min-width:0}.transport-controls{gap:7px}.audio-stats strong{font-size:13px}.section-header h2,.quickresults-heading h2{font-size:18px}.quickresults-heading .btn{font-size:0;gap:0}.quickresults-heading .btn span{font-size:18px}.wave-panel,.engine-panel{padding:15px}}
30
  @media(prefers-reduced-motion:reduce){*,*:before,*:after{scroll-behavior:auto!important;transition:none!important;animation:none!important}}
31
+
32
+ /* BASS-CORE Ω v0.3 -- integrated controls */
33
+ .bass-truth{border:1px solid rgba(114,234,214,.27);border-left:3px solid #7ce8cb;background:rgba(23,73,73,.28);border-radius:12px;padding:19px 23px;margin:18px 0 25px}
34
+ .bass-truth strong{color:#a4f7dc;font-size:.95rem}.bass-truth p{line-height:1.7;color:#aebec8;margin:8px 0 0;font-size:.9rem}
35
+ .bass-workspace{padding:24px}.bass-mode-row{display:flex;align-items:center;justify-content:space-between;gap:14px;margin:24px 0 18px;flex-wrap:wrap}
36
+ .bass-mode-row label{font-weight:650}.bass-select{max-width:100%;background:#141f2b;border:1px solid #38515e;color:#effaf8;border-radius:10px;padding:13px;font:inherit;min-width:min(100%,340px)}
37
+ .bass-presets{display:flex;flex-wrap:wrap;gap:9px;margin:18px 0 24px}
38
+ .bass-preset{padding:11px 13px;color:#b8c9d1;background:#192733;border:1px solid #3a5260;border-radius:9px;font:inherit;cursor:pointer}
39
+ .bass-preset.active,.bass-preset:hover{border-color:#72dbc7;background:#153c39;color:#a9ffe4}
40
+ .bass-controls{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:14px}
41
+ .bass-control{display:grid;grid-template-columns:1fr auto;gap:8px 12px;padding:17px;background:#121e29;border:1px solid #304552;border-radius:12px}
42
+ .bass-control span{font-size:.93rem;font-weight:680}.bass-control small{display:block;color:#8fa8b6;font-weight:400;margin-top:4px;font-size:.77rem}
43
+ .bass-control output{font-size:.88rem;color:#9cf8d8;font-weight:700;white-space:nowrap}.bass-control input{grid-column:1 / -1;width:100%;accent-color:#7cf0c4;cursor:pointer}
44
+ .bass-action-row{display:flex;flex-wrap:wrap;gap:12px;margin-top:24px}.bass-action-row .btn{min-height:45px}
45
+ .bass-stats{display:grid;grid-template-columns:repeat(4,minmax(0,1fr));gap:11px;margin:15px 0 24px}
46
+ .bass-stats>div{border-radius:12px;background:#16232e;border:1px solid #304552;padding:19px 14px;min-width:0}
47
+ .bass-stats span{display:block;color:#87a2b0;font-size:.7rem;letter-spacing:.07em}.bass-stats strong{display:block;margin-top:10px;color:#b8ffe8;font-size:1.2rem;overflow-wrap:anywhere}
48
+ .bass-result-grid{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:12px}
49
+ .bass-result{background:#16232e;border:1px solid #344c56;padding:19px;border-radius:12px;min-width:0}
50
+ .bass-result h3{font-size:1.01rem;margin:0 0 7px}.bass-result p{font-size:.79rem;color:#9cb4c1;margin:0 0 15px;line-height:1.5}
51
+ .bass-result .stem-actions{display:flex;gap:10px;flex-wrap:wrap}.bass-result .stem-actions button,.bass-result .stem-actions a{border:1px solid #43616c;background:#223641;border-radius:7px;padding:10px 12px;color:#d7f8ed;cursor:pointer;font:inherit;font-size:.85rem;text-decoration:none}
52
+ .bass-result .stem-actions button:hover,.bass-result .stem-actions a:hover{background:#31534f}
53
+ .bass-spectrum{padding:20px;margin-top:20px}.bass-frequency-empty{color:#8ca9b7;padding:25px}
54
+ .bass-freq-item{display:grid;grid-template-columns:100px 1fr 65px;align-items:center;gap:12px;margin:12px 0;font-size:.85rem}
55
+ .bass-freq-rail{height:10px;display:flex;align-items:center;position:relative;border-radius:12px;background:#2b4250;overflow:hidden}
56
+ .bass-freq-rail .bass-before{height:100%;background:#587a91;position:absolute;left:0}
57
+ .bass-freq-rail .bass-after{height:4px;background:#89f6ce;position:absolute;left:0;top:3px}
58
+ .bass-freq-key{font-size:.78rem;color:#acbbc6;text-align:right}
59
+ .bass-note{font-size:.8rem;color:#8fa7b4;line-height:1.6}
60
+ @media(max-width:950px){.bass-stats{grid-template-columns:repeat(2,minmax(0,1fr))}.bass-result-grid{grid-template-columns:1fr}}
61
+ @media(max-width:720px){.bass-controls{grid-template-columns:1fr}.bass-workspace{padding:16px}.bass-stats strong{font-size:1rem}.bass-mode-row{display:grid}.bass-select{min-width:0;width:100%}}
62
+
63
+ /* NOISE-CORE Ω */
64
+ .noise-law{border:1px solid #4a615d;border-left:4px solid #94edc9;border-radius:13px;padding:23px 25px;margin-bottom:24px;background:linear-gradient(100deg,#162b2c,#161e2d)}
65
+ .noise-law strong{display:block;color:#aaf7dd;font-size:13px;letter-spacing:.55px}
66
+ .noise-law p{margin:10px 0 0;color:#b8c9d0;font-size:13px;line-height:1.75;max-width:900px}
67
+ .noise-panel{padding:25px;margin-bottom:21px}
68
+ .noise-actions,.noise-tools{display:flex;align-items:center;gap:18px;flex-wrap:wrap;margin-top:15px}
69
+ .noise-actions>span{color:#92a5b7;font-size:12px}
70
+ .noise-candidates{display:grid;gap:8px;max-height:420px;overflow:auto}
71
+ .noise-candidate{display:flex;align-items:center;gap:14px;background:#121c2b;border:1px solid #2b3748;border-radius:10px;padding:12px 14px}
72
+ .noise-candidate:has(input:checked){border-color:#74cbaf;background:#1a3436}
73
+ .noise-candidate input{accent-color:#96edcd;width:18px;height:18px}
74
+ .noise-candidate>label{flex:1;line-height:1.5;cursor:pointer}
75
+ .noise-candidate small{display:block;color:#91a3b6;font-size:11px}
76
+ .noise-candidate button{background:#202d3d;border:1px solid #40596e;border-radius:8px;color:#c7f2e9;padding:8px 12px}
77
+ .noise-tools{display:grid;gap:12px;grid-template-columns:1fr;justify-items:start;border-top:1px solid #263648;padding-top:22px;margin-top:24px}
78
+ .noise-tools input{width:min(460px,100%);accent-color:#94edc9}
79
+ .noise-track-grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(210px,1fr));gap:12px}
80
+ .noise-track{background:#141f30;border:1px solid #2e4050;border-radius:13px;padding:18px}
81
+ .noise-track h3{font-size:15px}.noise-track p{font-size:12px;color:#98aabc;line-height:1.6}
82
+ .noise-track .stem-actions{margin-top:14px;display:flex;gap:10px;flex-wrap:wrap}
83
+ .noise-track a,.noise-track button{display:inline-block;background:#1c3037;border:1px solid #437868;border-radius:8px;padding:9px 11px;color:#cdf9e9;font-size:12px;cursor:pointer}
84
+ .noise-diagnostics{margin-top:20px;display:grid;gap:10px}
85
+ .noise-diagnostics .noise-line{font-size:12px;color:#b1c6ce;border:1px solid #2b3e4a;background:#172330;padding:11px;border-radius:8px}
86
+ @media (max-width:650px){.noise-panel{padding:16px}.noise-candidate{gap:8px;padding:9px}.noise-candidate button{font-size:11px;padding:8px}}
app/virtualbass.py ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Kdenlive-compatible FFmpeg Virtual Bass adapter (optional, local only).
2
+
3
+ FFmpeg's 'virtualbass' filter converts stereo to 2.1, preserving L/R and
4
+ adding a synthesized LFE channel. This is a loudspeaker effect and *not*
5
+ source separation, denoising, or a restored original bass signal.
6
+ """
7
+ from __future__ import annotations
8
+ import os
9
+ import shutil
10
+ import subprocess
11
+ import math
12
+ from pathlib import Path
13
+
14
+ import numpy as np
15
+ import soundfile as sf
16
+ from .audio import AudioError, audio_info
17
+
18
+
19
+ def available() -> bool:
20
+ binary=shutil.which("ffmpeg")
21
+ if not binary:
22
+ return False
23
+ try:
24
+ result=subprocess.run([binary,"-hide_banner","-filters"],
25
+ capture_output=True,text=True,timeout=10)
26
+ return result.returncode==0 and "virtualbass" in result.stdout
27
+ except (OSError,subprocess.TimeoutExpired):
28
+ return False
29
+
30
+
31
+ def render_virtualbass(
32
+ source:Path, destination:Path, cutoff_hz:float=250,
33
+ strength:float=1.0
34
+ ) -> dict:
35
+ if not (100<=cutoff_hz<=500 and .5<=strength<=3):
36
+ raise ValueError("Virtualbass cutoff 100–500 Hz, strength 0.5–3.")
37
+ info=audio_info(source)
38
+ if info.channels!=2:
39
+ raise AudioError("FFmpeg virtualbass requires a stereo source (2 channels).")
40
+ if not available():
41
+ raise AudioError("ffmpeg with virtualbass audio filter not installed.")
42
+ binary=shutil.which("ffmpeg")
43
+ destination.parent.mkdir(parents=True,exist_ok=True)
44
+ tmp=destination.with_name(".virtualbass-tmp.wav")
45
+ command=[
46
+ binary,"-nostdin","-hide_banner","-loglevel","error",
47
+ "-y","-i",str(source),
48
+ "-map","0:a:0","-vn","-af",
49
+ f"virtualbass=cutoff={float(cutoff_hz):.3f}:strength={float(strength):.3f}",
50
+ "-c:a","pcm_f32le",str(tmp)
51
+ ]
52
+ try:
53
+ completed=subprocess.run(command,capture_output=True,text=True)
54
+ if completed.returncode:
55
+ raise AudioError("FFmpeg Virtualbass failed: "+completed.stderr[-550:])
56
+ output=sf.info(str(tmp))
57
+ if (output.channels!=3 or output.samplerate!=info.samplerate
58
+ or output.frames!=info.frames):
59
+ raise AudioError("Invalid Virtualbass 2.1 output dimensions.")
60
+ # Confirm that the two stereo channels were not unintentionally altered
61
+ # by the FFmpeg processing pipeline. For codecs, decoder variations are
62
+ # possible, so report actual error rather than promising bit identity.
63
+ diff_max=0.0
64
+ lfe_peak=0.0
65
+ with sf.SoundFile(str(source),"r") as inp, sf.SoundFile(str(tmp),"r") as out:
66
+ while True:
67
+ a=inp.read(65536,dtype="float64",always_2d=True)
68
+ b=out.read(len(a),dtype="float64",always_2d=True)
69
+ if not len(a):
70
+ break
71
+ if len(a)!=len(b):
72
+ raise AudioError("Virtualbass channel alignment error.")
73
+ diff_max=max(diff_max,float(np.max(np.abs(a-b[:,:2]))))
74
+ lfe_peak=max(lfe_peak,float(np.max(np.abs(b[:,2]))))
75
+ # Extra float32 rounding and some codec decode differences are legitimate.
76
+ tmp.replace(destination)
77
+ return {
78
+ "mode":"ffmpeg_virtualbass_2_1",
79
+ "output_filename":destination.name,
80
+ "channels":3,"samplerate":info.samplerate,"frames":info.frames,
81
+ "cutoff_hz":cutoff_hz,"strength":strength,
82
+ "left_right_max_abs_difference":diff_max,
83
+ "lfe_peak_dbfs":round(20*math.log10(max(lfe_peak,1e-12)),3),
84
+ "virtual_lfe_is_synthetic":True,
85
+ "warning":"2.1 output. L/R should remain unchanged; added LFE is synthesized, not recovered. LFE output may exceed 0 dBFS."
86
+ }
87
+ finally:
88
+ tmp.unlink(missing_ok=True)
docs/ARRANGEMENT_STUDIO.md ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Arrangement Studio / v0.6
2
+
3
+ ## Audio routing
4
+
5
+ Import -> immutable source -> user-assisted mini inventory -> optional plan -> real source
6
+ separator -> actual WAV stems -> mixer offline rendering -> float WAV + independent report.
7
+
8
+ The plan is metadata only. An "instrument" in the plan is not a synthesized or
9
+ separated track and must never be represented as a stem.
10
+
11
+ ## OMEGA-TAG Mini
12
+
13
+ `python -m app.mini_model --train` reproduces synthetic two-stage training with a
14
+ fixed seed. Re-training replaces the checked-in mini model artifact, so keep a backup
15
+ if reproducibility is required.
16
+
17
+ Its six activations are *uncalibrated*. The model analyzes at most twelve short
18
+ windows, so segments missed by sampling can go undetected. Sounds containing
19
+ musical hiss, cymbals or reverb may trigger the 'noise texture' tag. The mini model
20
+ must never authorize irreversible noise subtraction.
21
+
22
+ The tiny model is not the engine that extracts sources; HPSS and Demucs adapters
23
+ provide the actual separation.
24
+
25
+ ## Non-destructive mix
26
+
27
+ `app/mixer.py`: sample-aligned chunked float WAV mix. Gain, Mute, Solo, constant-
28
+ center-gain stereo balance, low/high cuts (stateful IIR), tanh saturation, Mid/Side
29
+ width. Warning if output peak exceeds 0 dBFS; no hidden normalization.
30
+ Optional FFmpeg rubberband independent time stretch + pitch shifting.
31
+ Users should re-evaluate all effects when changing tempo/pitch, since no
32
+ perceptual losslessness can be assured.
33
+
34
+ ## Practical limits
35
+
36
+ Up to 128 plan targets, up to 128 simultaneously mixed real stems in code.
37
+ Heavy sessions can exceed open-file/resource limits; not a hard promise of 128
38
+ instrument-aware separations. Source sample rates, lengths and channels must match.
39
+ No real-time multi-audio-device ASIO/AU/VST plugin hosting in this version.
40
+ Stereo track waveform uses sparse sampling, not bit-exact peak extraction.
41
+ Audio-player previews isolated stems; full multitrack playback requires an
42
+ explicit offline mix render and is not DAW-grade zero-latency audition.
docs/BASS_CORE_DESIGN.md ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # BASS-CORE Ω — Entwicklungskonzept
2
+
3
+ ## Trennen vs. bearbeiten
4
+ Tiefe Frequenzen schneiden sich über mehrere Instrumente: ein 50-Hz-Band
5
+ ist kein Synonym für Bassgitarre, und ein Kick-Transient kann Obertonenergie
6
+ bis in den kHz-Bereich besitzen. Deshalb trennt das System Qualitätsstufen.
7
+
8
+ 1. **Mix DSP**: Tiefband plus Transientenmaskierung. Schnelle
9
+ frequenzgebundene Schätzung, keine Instrumentenidentifikation.
10
+ 2. **HPSS**: Tiefband von harmonischen/perkussiven Quellenschätzungen.
11
+ 3. **Demucs**: Tiefband von bereits geschätztem Bass-/Drum-Stem.
12
+ 4. **Geplant**: Multimodale ereignisbasierte Separation bis zu Kick-Attack,
13
+ Kick-Body, Bassline, Subbass, Slide, Saturation und Room-Tail.
14
+
15
+ ## Signalkette
16
+
17
+ ```
18
+ Original X
19
+ ├── Quellschätzung: Kick K, Bassline B
20
+ ├── Low-band L = K+B
21
+ ├── Unprocessed U = X-L
22
+ ├── Repair: lowcut DC/Rumble; edit kick / bassline
23
+ ├── Sub-EQ + synthetische Obertöne H
24
+ ├── Stereo-Bass-Center + Dry/Wet
25
+ ├── Edited Bass E
26
+ └── Edited Mix Y = U + E
27
+ └── optional global gain ceiling
28
+ ```
29
+
30
+ Kein Signalbereich wird als verlorenes Originalmaterial ausgegeben, wenn
31
+ er synthetisiert wurde. FFT-/PSD- und RMS-Ergebnisse sind Indikatoren für
32
+ Bandenergie, keine messtechnisch validierte Aussage über wahrgenommene
33
+ Qualität.
34
+
35
+ ## Detaillierte Weiterentwicklung
36
+
37
+ ### Quellzuordnung
38
+ Transiente Kick-Events mit mehrskaliger Wavelet-/STFT-Analyse ermitteln,
39
+ Bassline-F0 mit pYIN/CREPE vergleichend schätzen, Polyphonie diagnostizieren.
40
+ Unsichere Events müssen als Hypothesen angezeigt werden.
41
+
42
+ ### Reparatur
43
+ De-click und Aussetzer-Erkennung zunächst in einzelnen Events ermitteln,
44
+ anschließend signalerhaltende Ersatzverfahren auf ausgewählten Zeitfenstern.
45
+ Alle Eingriffe mit Region, Modell, Parameter und A/B-Ansicht protokollieren.
46
+
47
+ ### Synthetischer Subbass
48
+ Phasenkohärente subharmonische Oszillatoren nur bei stabiler harmonischer
49
+ Basis, mindestens mit Confidence-Filter. Ohne sichere Tonhöhe kein
50
+ subtonaler Ersatz. Der jetzige Overdrive ergänzt Obertöne, keine
51
+ zuverlässige fehlende Grundfrequenz.
52
+
53
+ ### VST3-/AU-Plugins
54
+ Als mögliche Host-Bibliothek eignet sich Spotifys `pedalboard`, die
55
+ VST3 und auf macOS AU unterstützt (GPL-3.0 im Repository). Nicht im
56
+ Produktionsserver in-process: Plugins als eigener beschränkter Prozess
57
+ mit Dateibasiertem IPC/Timeout/Crash-Isolation und explizitem Nutzerpfad.
58
+ Nur vom Nutzer installierte Plugins, keinerlei automatische Downloads.
59
+ Lizenzprüfung vor Weiterverteilung.
60
+
61
+ Geeignete erste Integrationsziele: FabFilter Pro-Q 4 (dynamische/spektrale
62
+ EQ-Bearbeitung), Pro-MB (Low-Band-Dynamik), Sonic Academy KICK 3
63
+ (Kick-Synthese), Surge XT (freie Synthese, GPL3). Diese Tools sind
64
+ Vorschläge und nicht Bestandteil der bisherigen Implementierung.
docs/NOISE_CORE_DESIGN.md ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # NOISE-CORE Ω v0.4 — Preservation-First Design
2
+
3
+ ## Grundprinzip
4
+
5
+ Ein beobachteter Signalanteil darf nicht allein deshalb als Störgeräusch
6
+ gelten, weil er rauschhaft, kurz oder tonal wirkt. Transienten, Hall,
7
+ Luft, Mikrodetails und tieffrequente Noten können ähnliche Merkmale tragen.
8
+
9
+ **Fachliche Grenze:** Aus der gemischten Wellenform lässt sich nicht in jedem
10
+ Fall nachweisen, dass eine bestimmte Komponente kein musikalischer Anteil
11
+ ist. Perfektion ist deshalb kein garantiertes Feature. Die risikoärmste
12
+ Standard-Aktion ist **Original unverändert lassen**.
13
+
14
+ ## v0.4 ausgeliefert
15
+
16
+ - Chunk-streamende Suche nach isolierten Single-Sample-Impulsen
17
+ (`app/noise.py`) mit bewusst konservativem Schwellenwert;
18
+ - Mehrdeutige Indikatoren für schmale 50/60/100/120-Hz-Spektralspitzen;
19
+ - Standardmäßig reiner Inspektionsmodus: keine Signalveränderung;
20
+ - Explizite Einzelmarkierung aller zu reparierenden Samples;
21
+ - Nur diese Stellen werden mittels Nachbarinterpolation bearbeitet;
22
+ - Einstellbarer Blend-Faktor 0–1;
23
+ - WAV-Float32: Clean-Signal und Original-minus-Clean als Differenzspur;
24
+ - PCM16-Hörkopien und ZIP mit JSON-Provenance-Bericht;
25
+ - SHA-256 des Originals unverändert; rekonstruktive Konsistenz geprüft;
26
+ - Zeitlich beliebig lange Dateien **innerhalb RAM-/Festplatten-/Dateigrößenlimits**;
27
+ - Optionaler Virtualbass 2.1-Export mit FFmpeg.
28
+
29
+ ## NICHT ausgeliefert
30
+
31
+ - Kein KI-Modell für semantische Stördetektion;
32
+ - Keine automatische Entrauschung eines gesamten Stücks;
33
+ - Keine echte Störquelle als wiederhergestelltes Ground-Truth-Signal;
34
+ - Kein breitbandiges Spectral De-Noise, keine 50/60-Hz-Notch-Reparatur;
35
+ - Keine beliebig breiten Pops/Crackles, mehrmillisekündigen Dropouts
36
+ oder vollständige Spektralrekonstruktion;
37
+ - Keine absolute Garantie für Erhaltung aller Musikdetails.
38
+
39
+ ## Safety/QA
40
+
41
+ - Niemals auto approve, nie „Select all“;
42
+ - Report enthält alle angewandten Samples, Stärke und Effektstärke;
43
+ - Alle Kandidaten müssen nach menschlicher Bestätigung akzeptiert werden;
44
+ - Differenzspur darf musikalische Anteile enthalten. Immer abhören;
45
+ - Code prüft Inputlänge, Finite Values, Outputlänge und Mix-Identität;
46
+ - UI-Erfolgsmeldung erst nach tatsächlicher Fertigstellung des Jobs.
47
+
48
+ **Bekannte Limitierung:** Click Detector benutzt blocklokale Statistik;
49
+ Kandidaten abhängig vom Quellmaterial. Stereo-Musik mit extrem hoher
50
+ Transientendichte kann False Positives erzeugen. Durch die manuelle
51
+ Freigabe wird der automatische Schaden vermieden, nicht jeder Schaden
52
+ durch menschlichen Irrtum.
53
+
54
+ ## Höchster KI-Hebel
55
+
56
+ 1. **Event Classifier (Listen First):** echte Klicks vs Snare/Kick/HiHat
57
+ und plucked instruments mit calibrated confidence und abstention.
58
+ 2. **Sound Source Model:** Störer vom Instrumenten-Stem unterscheiden,
59
+ Leakage messen und unklare Zeit-Frequenz-Zellen erhalten.
60
+ 3. **Conservative Inpainting (nur bestätigte Region):** Fallunterscheidung
61
+ Click (einige Samples), Glitch (Millisekunden), Dropout (länger),
62
+ vollständig identifizierte alternative Kanäle; Änderungen markieren.
63
+ 4. **Artifact/Detail Judge:** Erhalt von Sustain, Hall und Air durch
64
+ blind und reference-based Tests, plus Removal-Audition.
65
+ 5. **Bass Event Graph + F0 tracking:** Phasen-/Tonhöhen-gebundene
66
+ resynthetische Verstärkung statt pauschaler Bass-Normalisierung.
67
+
68
+ ## Referenzen
69
+
70
+ - https://downloads.izotope.com/docs/rx6/34-spectral-de-noise/index.html
71
+ - https://downloads.izotope.com/docs/rx6/35-spectral-repair/index.html
72
+ - https://www.izotope.com/community/blog/audio-artifacts
73
+ - https://ffmpeg.org/ffmpeg-filters.html#virtualbass
74
+ - https://github.com/facebookresearch/demucs
docs/RELEASE_0.6.md ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # ABSOLUTION Ω · Release v0.6.0
2
+
3
+ ## Delivered
4
+ - Arrangement nav/page and responsive DAW-like UI
5
+ - Real color-coded stereo/mono stem waveforms + color overview
6
+ - Mute, Solo, Gain, Pan, low/high cut, saturation, stereo width
7
+ - Offline mix WAV float32 and report; independent tempo and pitch via optional FFmpeg rubberband
8
+ - Synthetic-only fine-tuned OMEGA-TAG Mini inventory, editable plan with up to 128 hypotheses
9
+ - Existing NOISE-CORE and BASS-CORE workflows preserved
10
+
11
+ ## Quality verification performed in build environment
12
+ - Python pytest: 32 passed
13
+ - Node.js: app.js and arrangement.js passed `node --check`
14
+ - Actual localhost backend API tested: upload, inventory, real HPSS separation,
15
+ colored stem waveform endpoints, mixer render, +2 semitones, 115% tempo,
16
+ float WAV export.
17
+ - Browser visuals tested in an isolated JavaScript/browser environment with
18
+ actual waveform API samples. Mobile viewport had no page-level horizontal overflow.
19
+ - Direct browser HTTP navigation was blocked by the testing environment.
20
+ - Docker build and real Demucs inference were not performed.
21
+
22
+ ## Research limitation
23
+ OMEGA-TAG Mini is trained/fine-tuned on synthetic signals only. It cannot
24
+ confirm real instrument identity. The separation engine remains HPSS or
25
+ optionally locally installed Demucs; editable plan labels do NOT produce
26
+ isolated audio tracks on their own. Neither correct instrument attribution,
27
+ bit-exact perfection, nor zero-impact processing is guaranteed.
pyproject.toml CHANGED
@@ -4,8 +4,8 @@ build-backend = "setuptools.build_meta"
4
 
5
  [project]
6
  name = "absolution-omega"
7
- version = "0.2.0"
8
- description = "Local-first audio-forensic vertical slice with verified DSP stems and optional local Demucs."
9
  requires-python = ">=3.11"
10
  dependencies = [
11
  "fastapi>=0.115,<1",
@@ -23,7 +23,7 @@ neural = ["demucs==4.0.1", "torch>=2.2,<3"]
23
  [tool.setuptools]
24
  packages = ["app"]
25
  [tool.setuptools.package-data]
26
- app = ["static/*.html", "static/*.css", "static/*.js", "static/*.svg", "static/*.wav"]
27
 
28
  [tool.pytest.ini_options]
29
  testpaths = ["tests"]
 
4
 
5
  [project]
6
  name = "absolution-omega"
7
+ version = "0.6.0"
8
+ description = "Local-first audio workbench with multi-stem arrangement, synthetic mini tag model, BASS-CORE and NOISE-CORE."
9
  requires-python = ">=3.11"
10
  dependencies = [
11
  "fastapi>=0.115,<1",
 
23
  [tool.setuptools]
24
  packages = ["app"]
25
  [tool.setuptools.package-data]
26
+ app = ["static/*.html", "static/*.css", "static/*.js", "static/*.svg", "static/*.wav", "models/*.npz"]
27
 
28
  [tool.pytest.ini_options]
29
  testpaths = ["tests"]
tests/test_arrangement.py ADDED
@@ -0,0 +1,158 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """ABSOLUTION Ω v0.6: multi-stem planning and audible arrangement render."""
2
+ from pathlib import Path
3
+ import math
4
+ import threading
5
+ import time
6
+
7
+ import numpy as np
8
+ import pytest
9
+ import soundfile as sf
10
+ from fastapi.testclient import TestClient
11
+ from app.mixer import render_mix, sampled_peaks
12
+ from app.mini_model import MODEL_FILE, inspect_file
13
+ from app.server import create_app
14
+
15
+
16
+ def make_stems(folder, sr=8000, seconds=1.5):
17
+ folder.mkdir(parents=True,exist_ok=True)
18
+ t=np.arange(int(sr*seconds))/sr
19
+ a=np.column_stack((.10*np.sin(2*np.pi*90*t),.08*np.sin(2*np.pi*90*t)))
20
+ b=np.column_stack((.07*np.sin(2*np.pi*420*t),.05*np.sin(2*np.pi*420*t)))
21
+ for k,v in (("bass",a),("other",b)):
22
+ sf.write(folder/f"{k}.wav",v,sr,subtype="FLOAT")
23
+ return {"bass":folder/"bass.wav","other":folder/"other.wav"},a,b
24
+
25
+
26
+ def test_mixer_is_additive_at_neutral_controls(tmp_path):
27
+ paths,a,b=make_stems(tmp_path)
28
+ report=render_mix(paths,{},tmp_path/"mixed.wav")
29
+ out,sr=sf.read(tmp_path/"mixed.wav",always_2d=True)
30
+ assert sr==8000 and report["channels"]==2
31
+ assert np.max(np.abs(out-(a+b)))<2e-7
32
+ assert report["float_wav"] is True
33
+
34
+
35
+ def test_mute_solo_and_pan_are_real(tmp_path):
36
+ paths,a,b=make_stems(tmp_path)
37
+ options={"tracks":{"bass":{"solo":True,"pan":-1},"other":{"mute":False}}}
38
+ render_mix(paths,options,tmp_path/"mix.wav")
39
+ out,_=sf.read(tmp_path/"mix.wav",always_2d=True)
40
+ assert np.max(np.abs(out[:,1]))<1e-7
41
+ assert np.max(np.abs(out[:,0]))>0.06
42
+ options={"tracks":{"bass":{"mute":True},"other":{"mute":True}}}
43
+ render_mix(paths,options,tmp_path/"silent.wav")
44
+ out,_=sf.read(tmp_path/"silent.wav",always_2d=True)
45
+ assert np.max(np.abs(out))==0
46
+
47
+
48
+ def test_mixer_fx_and_reject_unknown(tmp_path):
49
+ paths,a,b=make_stems(tmp_path)
50
+ options={"tracks":{"bass":{"gain_db":-6,"highpass_hz":60,"lowpass_hz":550,
51
+ "drive":.3,"width":.7}}}
52
+ report=render_mix(paths,options,tmp_path/"fx.wav")
53
+ assert math.isfinite(report["peak_dbfs"])
54
+ assert sf.info(tmp_path/"fx.wav").frames==len(a)
55
+ with pytest.raises(ValueError,match="Unknown track"):
56
+ render_mix(paths,{"tracks":{"vocals":{"gain_db":3}}},tmp_path/"bad.wav")
57
+ with pytest.raises(ValueError,match="Highpass"):
58
+ render_mix(paths,{"tracks":{"bass":{"highpass_hz":300,"lowpass_hz":120}}},tmp_path/"bad2.wav")
59
+
60
+
61
+ def test_sparse_waveform_is_file_derived(tmp_path):
62
+ paths,a,b=make_stems(tmp_path)
63
+ w=sampled_peaks(paths["bass"],80)
64
+ assert len(w["samples"])==80 and max(w["samples"])>.08
65
+ assert w["peak_reliability"].startswith("visualization")
66
+
67
+
68
+ def test_synthetic_mini_model_is_bundled(tmp_path):
69
+ assert MODEL_FILE.is_file()
70
+ paths,a,b=make_stems(tmp_path)
71
+ inv=inspect_file(paths["bass"],max_windows=3)
72
+ assert inv["model"]=="OMEGA-TAG Mini v1"
73
+ assert len(inv["detections"])==6
74
+ assert inv["sampled_windows"]==3
75
+ assert "SYNTHETIC" in inv["scope"]
76
+ assert all(0<=d["score"]<=1 for d in inv["detections"])
77
+
78
+
79
+ def test_inventory_plan_and_mixer_api(tmp_path):
80
+ app=create_app(tmp_path/"data")
81
+ with TestClient(app) as cli:
82
+ paths,a,b=make_stems(tmp_path/"testsignal")
83
+ res=cli.post("/api/v1/projects",json={"name":"Arrangement QA"})
84
+ assert res.status_code==201
85
+ project=res.json()["id"]
86
+ with open(paths["bass"],"rb") as f:
87
+ up=cli.post("/api/v1/assets",data={"project_id":project},
88
+ files={"file":("mix.wav",f,"audio/wav")})
89
+ assert up.status_code==201,up.text
90
+ res=cli.post(f"/api/v1/projects/{project}/inventory")
91
+ assert res.status_code==200,res.text
92
+ assert res.json()["inventory"]["model_kind"].startswith("tiny_neural_network")
93
+ plan=[{"id":"my_custom_bass","label":"Bass-Synth 2","enabled":True},
94
+ {"id":"kick_like","label":"Kick-Verdacht","enabled":False}]
95
+ resp=cli.put(f"/api/v1/projects/{project}/plan",json={"tracks":plan})
96
+ assert resp.status_code==200,resp.text
97
+ assert resp.json()["status"]=="hypotheses_only"
98
+ assert cli.get(f"/api/v1/projects/{project}").json()["plan"]==plan
99
+ bad=cli.put(f"/api/v1/projects/{project}/plan",
100
+ json={"tracks":[plan[0],plan[0]]})
101
+ assert bad.status_code==422
102
+ assert cli.post("/api/v1/jobs/mix",
103
+ json={"project_id":project,"tracks":{}}).status_code==409
104
+ wave=cli.get(f"/api/v1/projects/{project}/wave/original?points=64")
105
+ assert wave.status_code==200 and len(wave.json()["samples"])==64
106
+ assert cli.get(f"/api/v1/projects/{project}/wave/not-a-stem").status_code==404
107
+ start=cli.post("/api/v1/jobs/separate",json={"project_id":project,"model":"hpss"})
108
+ assert start.status_code==202,start.text
109
+ jobid=start.json()["id"]
110
+ for _ in range(100):
111
+ item=cli.get("/api/v1/jobs/"+jobid).json()
112
+ if item["status"] in ("done","failed"):break
113
+ time.sleep(.08)
114
+ assert item["status"]=="done",item
115
+ mani=cli.get(f"/api/v1/projects/{project}").json()
116
+ assert set(mani["stems"])=={"harmonic","percussive","residual"}
117
+ assert cli.get(f"/api/v1/projects/{project}/wave/harmonic?points=64").status_code==200
118
+ bad=cli.post("/api/v1/jobs/mix",
119
+ json={"project_id":project,"tracks":{"imaginary":{"gain_db":2}}})
120
+ assert bad.status_code==422
121
+ start=cli.post("/api/v1/jobs/mix",json={"project_id":project,"tracks":{
122
+ "harmonic":{"gain_db":-3,"pan":-.45,"solo":True},
123
+ "percussive":{"gain_db":0,"mute":False}}})
124
+ assert start.status_code==202,start.text
125
+ jid=start.json()["id"]
126
+ for _ in range(100):
127
+ item=cli.get("/api/v1/jobs/"+jid).json()
128
+ if item["status"] in ("done","failed"):break
129
+ time.sleep(.08)
130
+ assert item["status"]=="done",item
131
+ result=cli.get(f"/api/v1/projects/{project}/mixer").json()["mixer"]
132
+ assert result["result"]["float_wav"]
133
+ mixfile=cli.get(f"/api/v1/projects/{project}/mixer/audio")
134
+ assert mixfile.status_code==200 and mixfile.content[:4]==b"RIFF"
135
+
136
+
137
+ def test_long_181_second_mix_without_duration_cutoff(tmp_path):
138
+ sr=8000
139
+ length=181*sr
140
+ src=tmp_path/"long.wav"
141
+ with sf.SoundFile(src,mode="w",samplerate=sr,channels=2,subtype="FLOAT") as out:
142
+ rng=np.random.default_rng(14)
143
+ for i in range(0,length,32768):
144
+ n=min(32768,length-i)
145
+ x=rng.standard_normal((n,2)).astype(np.float32)*.002
146
+ out.write(x)
147
+ report=render_mix({"one":src},{},tmp_path/"long_render.wav")
148
+ assert report["source_frames"]==length
149
+ assert sf.info(tmp_path/"long_render.wav").frames==length
150
+ assert report["peak_dbfs"]<0
151
+
152
+
153
+ def test_mixing_more_than_four_real_stems(tmp_path):
154
+ src,a,b=make_stems(tmp_path)
155
+ stems={f"layer_{i}":src["bass"] for i in range(7)}
156
+ report=render_mix(stems,{},tmp_path/"seven_stems.wav")
157
+ assert report["source_frames"]==a.shape[0]
158
+ assert report["peak_dbfs"]>-10
tests/test_bass.py ADDED
@@ -0,0 +1,168 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """BASS-CORE regression tests with entirely synthetic input, no model download."""
2
+ import io
3
+ import json
4
+ import math
5
+ import time
6
+ import zipfile
7
+
8
+ import numpy as np
9
+ import pytest
10
+ import soundfile as sf
11
+ from fastapi.testclient import TestClient
12
+
13
+ from app.audio import sha256_file
14
+ from app.bass import BassParams, _transform, process_bass_file
15
+ from app.server import create_app
16
+
17
+
18
+ def make_audio(sr=8000, duration=2.0, stereo=True):
19
+ t = np.arange(int(sr * duration)) / sr
20
+ bass = .18 * np.sin(2 * np.pi * 55 * t)
21
+ kick = np.zeros_like(t)
22
+ for when in np.arange(.15, duration, .5):
23
+ pos = int(when * sr)
24
+ end = min(len(t), pos + int(sr * .12))
25
+ i = np.arange(end-pos) / sr
26
+ kick[pos:end] += .33 * np.sin(2*np.pi*(90 - 40*(i/.12))*i) * np.exp(-i*32)
27
+ high = .08 * np.sin(2 * np.pi * 900 * t)
28
+ mono = bass + kick + high
29
+ return np.column_stack((mono,mono*.9)) if stereo else mono[:,None]
30
+
31
+
32
+ def test_bass_stems_derive_from_original_and_synth_harmonics(tmp_path):
33
+ sr=8000
34
+ source=tmp_path/"source.wav"
35
+ x=make_audio()
36
+ sf.write(source,x,sr,subtype="FLOAT")
37
+ cfg=BassParams(kick_gain_db=3, bass_gain_db=2, sub_gain_db=3,
38
+ harmonics=.85, mono_below_hz=100, ceiling_dbfs=-1)
39
+ stems,report=process_bass_file(source,tmp_path/"bass",cfg,
40
+ chunk_frames=8192,context_frames=4096)
41
+ assert report["reconstruction_check"]["consistent"]
42
+ assert report["reconstruction_check"]["max_abs_error"] < 1e-9
43
+ assert report["created_harmonics_are_synthetic"] is True
44
+ assert report["mode"]=="dsp"
45
+ before,_=sf.read(tmp_path/"bass"/"bass_band.wav",always_2d=True)
46
+ kick,_=sf.read(tmp_path/"bass"/"kick_estimate.wav",always_2d=True)
47
+ line,_=sf.read(tmp_path/"bass"/"bassline_estimate.wav",always_2d=True)
48
+ other,_=sf.read(tmp_path/"bass"/"other_unprocessed.wav",always_2d=True)
49
+ mix,_=sf.read(tmp_path/"bass"/"mix_optimized.wav",always_2d=True)
50
+ harm,_=sf.read(tmp_path/"bass"/"harmonics_added.wav",always_2d=True)
51
+ assert np.max(np.abs(before-(kick+line))) < 1e-6
52
+ assert np.max(np.abs(x-(kick+line+other))) < 2e-6
53
+ assert np.max(np.abs(harm)) > 1e-6
54
+ assert not np.allclose(mix,x)
55
+ assert np.max(np.abs(mix)) <= 10**(-1/20) + 3e-6
56
+ assert len(stems)==7
57
+ assert all(sf.info(tmp_path/"bass"/v["master"]).frames == len(x) for v in stems.values())
58
+ assert all((tmp_path/"bass"/v["preview"]).exists() for v in stems.values())
59
+ assert len(report["first_chunk_spectrum"]["before"]) == 6
60
+
61
+
62
+ def test_bass_dry_and_invalid_model_stem_lengths(tmp_path):
63
+ x=make_audio(sr=8000,duration=.6)
64
+ tracks=_transform(x,8000,BassParams(wet=0,lowcut_hz=35),"dsp")
65
+ assert np.max(np.abs(tracks["mix_optimized"]-x)) < 1e-8
66
+ source=tmp_path/"input.wav"
67
+ wrong=tmp_path/"wrong.wav"
68
+ sf.write(source,x,8000)
69
+ sf.write(wrong,x[:-100],8000)
70
+ with pytest.raises(ValueError,match="match source"):
71
+ process_bass_file(source,tmp_path/"out", BassParams(),"hpss",
72
+ refs={"harmonic":wrong,"percussive":wrong})
73
+
74
+
75
+ def test_bass_api_dsp_hpss_and_zip_without_changing_original(tmp_path):
76
+ app=create_app(tmp_path/"store")
77
+ x=make_audio(duration=.8)
78
+ payload=io.BytesIO()
79
+ sf.write(payload,x,8000,format="WAV",subtype="FLOAT")
80
+ with TestClient(app) as c:
81
+ p=c.post("/api/v1/projects",json={"name":"Bass Lab"}).json()
82
+ pid=p["id"]
83
+ result=c.post("/api/v1/assets",data={"project_id":pid},
84
+ files={"file":("bass.wav",payload.getvalue(),"audio/wav")})
85
+ assert result.status_code==201,result.text
86
+ original_sha=result.json()["asset"]["sha256"]
87
+ assert c.get(f"/api/v1/projects/{pid}/bass").json()["bass"] is None
88
+ empty=c.get(f"/api/v1/projects/{pid}/bass/export")
89
+ assert empty.status_code==409
90
+ assert c.post("/api/v1/jobs/bass",json={
91
+ "project_id":pid,"source_mode":"hpss"}).status_code==409
92
+ assert c.post("/api/v1/jobs/bass",json={
93
+ "project_id":pid,"kick_gain_db":999}).status_code==422
94
+ job=c.post("/api/v1/jobs/bass",json={
95
+ "project_id":pid,"source_mode":"auto",
96
+ "kick_gain_db":2,"sub_gain_db":1,"harmonics":.6
97
+ })
98
+ assert job.status_code==202,job.text
99
+ for _ in range(160):
100
+ result=c.get(f"/api/v1/jobs/{job.json()['id']}").json()
101
+ if result["status"] in ("done","failed"):break
102
+ time.sleep(.05)
103
+ assert result["status"]=="done",result
104
+ bass=c.get(f"/api/v1/projects/{pid}/bass").json()["bass"]
105
+ assert bass["mode"]=="dsp"
106
+ assert bass["source_sha256"]==original_sha
107
+ assert bass["report"]["reconstruction_check"]["consistent"]
108
+ out=c.get(f"/api/v1/projects/{pid}/bass/audio/mix_optimized")
109
+ assert out.status_code==200
110
+ xx, sr=sf.read(io.BytesIO(out.content),always_2d=True)
111
+ assert sr==8000 and len(xx)==len(x)
112
+ preview=c.get(f"/api/v1/projects/{pid}/bass/audio/kick_estimate?preview=true")
113
+ assert preview.content[:4]==b"RIFF"
114
+ assert c.get(f"/api/v1/projects/{pid}/bass/audio/not_real").status_code==404
115
+ z=c.get(f"/api/v1/projects/{pid}/bass/export")
116
+ assert z.status_code==200
117
+ with zipfile.ZipFile(io.BytesIO(z.content)) as archive:
118
+ assert "bass_report.json" in archive.namelist()
119
+ assert "stems/mix_optimized.wav" in archive.namelist()
120
+ assert json.loads(archive.read("bass_report.json"))["mode"]=="dsp"
121
+ assert c.get(f"/api/v1/projects/{pid}").json()["asset"]["sha256"]==original_sha
122
+
123
+ # The existing HPSS engine is available, now test source routing.
124
+ job=c.post("/api/v1/jobs/separate",json={"project_id":pid,"model":"hpss"}).json()
125
+ for _ in range(160):
126
+ status=c.get(f"/api/v1/jobs/{job['id']}").json()
127
+ if status["status"] in ("done","failed"):break
128
+ time.sleep(.05)
129
+ assert status["status"]=="done",status
130
+ job=c.post("/api/v1/jobs/bass",json={"project_id":pid,"source_mode":"auto"}).json()
131
+ for _ in range(160):
132
+ status=c.get(f"/api/v1/jobs/{job['id']}").json()
133
+ if status["status"] in ("done","failed"):break
134
+ time.sleep(.05)
135
+ assert status["status"]=="done",status
136
+ assert c.get(f"/api/v1/projects/{pid}/bass").json()["bass"]["mode"]=="hpss"
137
+ root=tmp_path/"store"/pid
138
+ assert sha256_file(root/"source.wav")==original_sha
139
+
140
+
141
+ def test_bass_streaming_over_180_seconds(tmp_path):
142
+ src=tmp_path/"long.wav"
143
+ with sf.SoundFile(src,"w",samplerate=8000,channels=1,subtype="PCM_16") as file:
144
+ file.seek(181*8000-1)
145
+ file.write([.1])
146
+ m,r=process_bass_file(src,tmp_path/"long_bass",BassParams(
147
+ crossover_hz=140,harmonics=0,lowcut_hz=20,mono_below_hz=0
148
+ ), chunk_frames=131072)
149
+ assert r["reconstruction_check"]["consistent"],r
150
+ assert sf.info(tmp_path/"long_bass"/m["mix_optimized"]["master"]).frames == 181*8000
151
+
152
+
153
+
154
+ def test_bass_at_standard_music_rate_and_chunk_boundaries(tmp_path):
155
+ sr = 44100
156
+ samples = make_audio(sr=sr, duration=3.25)
157
+ src = tmp_path/"standard.wav"
158
+ sf.write(src,samples,sr,subtype="FLOAT")
159
+ outs, rep = process_bass_file(src,tmp_path/"standard_out",
160
+ BassParams(kick_gain_db=1.5,harmonics=.4),
161
+ chunk_frames=65536,context_frames=16384)
162
+ assert rep["reconstruction_check"]["consistent"]
163
+ bass,_=sf.read(tmp_path/"standard_out"/outs["bass_band"]["master"],always_2d=True)
164
+ assert np.isfinite(bass).all()
165
+ # Streaming does not create abrupt jumps across chunk boundaries.
166
+ jumps=np.max(np.abs(np.diff(bass,axis=0)),axis=1)
167
+ edges=[65536, 131072]
168
+ assert max(float(jumps[e-1]) for e in edges) < max(0.015,float(np.percentile(jumps,99.99))*4)
tests/test_noise.py ADDED
@@ -0,0 +1,198 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """NOISE-CORE Ω — regression against accidental removal of original music."""
2
+ import io
3
+ import json
4
+ import shutil
5
+ import time
6
+ import zipfile
7
+
8
+ import numpy as np
9
+ import pytest
10
+ import soundfile as sf
11
+ from fastapi.testclient import TestClient
12
+
13
+ from app.audio import sha256_file
14
+ from app.noise import RepairParams, inspect_noise_file, repair_noise_file
15
+ from app.server import create_app
16
+ from app.virtualbass import available, render_virtualbass
17
+
18
+
19
+ def make_audio(sr=8000, duration=2.0, stereo=True, clicks=True):
20
+ t=np.arange(int(sr*duration))/sr
21
+ # Include low tone, middle tone and low-amplitude air frequencies.
22
+ pure=0.15*np.sin(2*np.pi*55*t)+.04*np.sin(2*np.pi*440*t)
23
+ pure+=.012*np.sin(2*np.pi*1200*t)
24
+ x=np.stack([pure,pure*.87],axis=1) if stereo else pure[:,None]
25
+ if clicks:
26
+ x[int(.540125*sr),0]+=.85
27
+ x[int(1.250125*sr),0]-=.8
28
+ return x
29
+
30
+
31
+ def await_job(client, jid, delay=.025, count=300):
32
+ for _ in range(count):
33
+ job=client.get(f"/api/v1/jobs/{jid}").json()
34
+ if job["status"] in ("done","failed"):
35
+ return job
36
+ time.sleep(delay)
37
+ pytest.fail(f"Timed out waiting for job {jid}")
38
+
39
+
40
+ def test_noise_scan_only_has_no_mutation_and_preserves_clean_music(tmp_path):
41
+ src=tmp_path/"music.wav"
42
+ x=make_audio(clicks=False)
43
+ sf.write(src,x,8000,subtype="FLOAT")
44
+ digest=sha256_file(src)
45
+ scan=inspect_noise_file(src)
46
+ assert scan["event_count"]==0
47
+ assert scan["mode"]=="inspect_only"
48
+ assert scan["auto_repair"] is False
49
+ assert scan["broadband_denoise_available"] is False
50
+ assert sha256_file(src)==digest
51
+
52
+
53
+ def test_manually_approved_clicks_have_exact_difference_stem(tmp_path):
54
+ src=tmp_path/"click.wav"
55
+ x=make_audio()
56
+ sf.write(src,x,8000,subtype="FLOAT")
57
+ digest=sha256_file(src)
58
+ scan=inspect_noise_file(src)
59
+ positions=[e["sample"] for e in scan["events"]]
60
+ assert 4321 in positions and 10001 in positions, positions
61
+ assert scan["event_count"]==2
62
+ tracks,report=repair_noise_file(src,tmp_path/"processed",
63
+ [4321],RepairParams(strength=.8),
64
+ chunk_frames=3072)
65
+ assert report["changed_sample_frames"]==1
66
+ assert report["reconstruction_consistent"]
67
+ assert sha256_file(src)==digest
68
+ after,_=sf.read(tmp_path/"processed"/tracks["clean"]["master"],always_2d=True)
69
+ removed,_=sf.read(tmp_path/"processed"/tracks["difference"]["master"],always_2d=True)
70
+ original,_=sf.read(src,always_2d=True)
71
+ assert np.max(np.abs(after+removed-original))<7e-8
72
+ unaffected=np.ones(len(original),dtype=bool)
73
+ unaffected[4321]=False
74
+ assert np.max(np.abs(after[unaffected]-original[unaffected]))<7e-8
75
+ assert np.max(np.abs(removed[unaffected]))<1e-12
76
+ assert abs(removed[10001,0])<1e-12 # second, unapproved click not touched
77
+ assert np.max(np.abs(removed[4321]))>.4
78
+ for kind in ("clean","difference"):
79
+ assert sf.info(tmp_path/"processed"/tracks[kind]["preview"]).frames==len(x)
80
+
81
+
82
+ def test_no_selected_samples_renders_no_changes(tmp_path):
83
+ src=tmp_path/"music.wav"
84
+ sf.write(src,make_audio(),8000,subtype="FLOAT")
85
+ tracks,report=repair_noise_file(src,tmp_path/"render",[],
86
+ RepairParams(.5),chunk_frames=4096)
87
+ a,_=sf.read(src,always_2d=True)
88
+ b,_=sf.read(tmp_path/"render"/tracks["clean"]["master"],always_2d=True)
89
+ assert np.max(np.abs(a-b))<3e-8
90
+ assert report["changed_sample_frames"]==0
91
+ with pytest.raises(ValueError):
92
+ repair_noise_file(src,tmp_path/"wrong",[999999],RepairParams(.8))
93
+
94
+
95
+ def test_noise_api_scan_approval_export_and_manifest(tmp_path):
96
+ x=make_audio()
97
+ buff=io.BytesIO()
98
+ sf.write(buff,x,8000,format="WAV",subtype="FLOAT")
99
+ app=create_app(tmp_path/"store")
100
+ with TestClient(app) as client:
101
+ pid=client.post("/api/v1/projects",json={"name":"NOISE Test"}).json()["id"]
102
+ assert client.post("/api/v1/jobs/noise/scan",
103
+ json={"project_id":pid}).status_code==409
104
+ assert client.post("/api/v1/assets",data={"project_id":pid},
105
+ files={"file":("music.wav",buff.getvalue(),"audio/wav")}).status_code==201
106
+ original_hash=client.get(f"/api/v1/projects/{pid}").json()["asset"]["sha256"]
107
+ assert client.post("/api/v1/jobs/noise/repair",
108
+ json={"project_id":pid,"approved_samples":[4321]}).status_code==409
109
+ scanjob=client.post("/api/v1/jobs/noise/scan",json={"project_id":pid})
110
+ assert scanjob.status_code==202
111
+ assert await_job(client,scanjob.json()["id"])["status"]=="done"
112
+ details=client.get(f"/api/v1/projects/{pid}/noise").json()["noise"]
113
+ assert details["scan"]["event_count"]==2
114
+ assert details["repair"] is None
115
+ assert client.post("/api/v1/jobs/noise/repair",
116
+ json={"project_id":pid,"approved_samples":[222]}).status_code==422
117
+ assert client.post("/api/v1/jobs/noise/repair",
118
+ json={"project_id":pid,"approved_samples":[]}).status_code==422
119
+ job=client.post("/api/v1/jobs/noise/repair",json={
120
+ "project_id":pid,"approved_samples":[4321],"strength":.8
121
+ })
122
+ assert job.status_code==202,job.text
123
+ assert await_job(client,job.json()["id"])["status"]=="done"
124
+ result=client.get(f"/api/v1/projects/{pid}/noise").json()["noise"]["repair"]
125
+ assert result["source_sha256"]==original_hash
126
+ assert result["report"]["changed_sample_frames"]==1
127
+ assert result["report"]["reconstruction_consistent"]
128
+ assert client.get(f"/api/v1/projects/{pid}/noise/audio/clean?preview=true").content[:4]==b"RIFF"
129
+ diff=client.get(f"/api/v1/projects/{pid}/noise/audio/difference")
130
+ assert diff.status_code==200
131
+ assert client.get(f"/api/v1/projects/{pid}/noise/audio/bad").status_code==404
132
+ packed=client.get(f"/api/v1/projects/{pid}/noise/export")
133
+ assert packed.status_code==200
134
+ with zipfile.ZipFile(io.BytesIO(packed.content)) as z:
135
+ assert "tracks/clean.wav" in z.namelist()
136
+ assert "tracks/difference.wav" in z.namelist()
137
+ assert json.loads(z.read("report.json"))["report"]["reconstruction_consistent"]
138
+ assert client.get(f"/api/v1/projects/{pid}").json()["asset"]["sha256"]==original_hash
139
+
140
+
141
+ def test_noise_scan_longer_than_three_minutes(tmp_path):
142
+ source=tmp_path/"long.wav"
143
+ sr=8000; frames=sr*181
144
+ with sf.SoundFile(source,"w",samplerate=sr,channels=1,subtype="PCM_16") as wav:
145
+ wav.seek(frames-1);wav.write([0.])
146
+ result=inspect_noise_file(source)
147
+ assert result["input_frames"]==frames
148
+ assert result["samplerate"]==sr
149
+
150
+
151
+ @pytest.mark.skipif(not available(),reason="FFmpeg virtualbass not installed")
152
+ def test_virtualbass_2_1_without_stereo_mutation(tmp_path):
153
+ src=tmp_path/"stereo.wav"
154
+ sf.write(src,make_audio(clicks=False),8000,subtype="FLOAT")
155
+ sha=sha256_file(src)
156
+ result=render_virtualbass(src,tmp_path/"virtual.wav",250,1.)
157
+ a,s=sf.read(src,always_2d=True)
158
+ b,sb=sf.read(tmp_path/"virtual.wav",always_2d=True)
159
+ assert s==sb==8000 and b.shape==(a.shape[0],3)
160
+ assert np.max(np.abs(a-b[:,:2]))<1e-6
161
+ assert np.max(np.abs(b[:,2]))>.01
162
+ assert result["virtual_lfe_is_synthetic"] and result["left_right_max_abs_difference"]<1e-6
163
+ assert sha256_file(src)==sha
164
+
165
+
166
+ @pytest.mark.skipif(not available(),reason="FFmpeg virtualbass not installed")
167
+ def test_virtualbass_api_job_and_download(tmp_path):
168
+ source=io.BytesIO()
169
+ sf.write(source,make_audio(clicks=False),8000,format="WAV",subtype="FLOAT")
170
+ with TestClient(create_app(tmp_path/"db")) as c:
171
+ pid=c.post("/api/v1/projects",json={"name":"Virtual"}).json()["id"]
172
+ uploaded=c.post("/api/v1/assets",data={"project_id":pid},
173
+ files={"file":("virtual.wav",source.getvalue(),"audio/wav")})
174
+ sha=uploaded.json()["asset"]["sha256"]
175
+ bad=c.post("/api/v1/jobs/bass/virtual",
176
+ json={"project_id":pid,"cutoff_hz":2000})
177
+ assert bad.status_code==422
178
+ job=c.post("/api/v1/jobs/bass/virtual",
179
+ json={"project_id":pid,"cutoff_hz":250,"strength":1})
180
+ assert job.status_code==202,job.text
181
+ assert await_job(c,job.json()["id"],count=400)["status"]=="done"
182
+ result=c.get(f"/api/v1/projects/{pid}/virtualbass").json()["virtualbass"]
183
+ assert result["report"]["channels"]==3
184
+ output=c.get(f"/api/v1/projects/{pid}/virtualbass/audio")
185
+ assert output.status_code==200
186
+ assert sf.info(io.BytesIO(output.content)).channels==3
187
+ assert c.get(f"/api/v1/projects/{pid}").json()["asset"]["sha256"]==sha
188
+
189
+
190
+ def test_noise_ui_routes_and_preserve_first_notice(tmp_path):
191
+ with TestClient(create_app(tmp_path/"tmp")) as client:
192
+ html=client.get("/").text
193
+ assert "PRESERVE FIRST" in html and "NOISE-CORE" in html
194
+ js=client.get("/static/app.js").text
195
+ assert "startNoiseScan" in js and "startNoiseRepair" in js
196
+ spec=client.get("/openapi.json").json()["paths"]
197
+ assert "/api/v1/jobs/noise/scan" in spec
198
+ assert "/api/v1/jobs/bass/virtual" in spec