Update resonance_engine.py
Browse files- resonance_engine.py +70 -5
resonance_engine.py
CHANGED
|
@@ -1,8 +1,7 @@
|
|
| 1 |
#!/usr/bin/env python3
|
| 2 |
"""
|
| 3 |
-
LYGO Resonance Engine v0.
|
| 4 |
-
Image β Living Stereo Soundscape
|
| 5 |
-
A spectral translator that gives voice to the hidden geometry, texture, and color of any image.
|
| 6 |
"""
|
| 7 |
|
| 8 |
import cv2
|
|
@@ -16,7 +15,13 @@ from typing import Optional, Dict, Any
|
|
| 16 |
import mido
|
| 17 |
from mido import MidiFile, MidiTrack, Message
|
| 18 |
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
# Artistic Presets
|
| 22 |
PRESETS = {
|
|
@@ -95,6 +100,11 @@ class ResonanceEngine:
|
|
| 95 |
"verbose": True,
|
| 96 |
"export_stems": False,
|
| 97 |
"export_midi": False,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 98 |
}
|
| 99 |
if config:
|
| 100 |
self.config.update(config)
|
|
@@ -194,13 +204,55 @@ class ResonanceEngine:
|
|
| 194 |
theta = np.interp(features["avg_green"], [0, 255], cfg["theta_lock_range"])
|
| 195 |
w, h = features["width"], features["height"]
|
| 196 |
|
| 197 |
-
# Initialize stem collections
|
| 198 |
audio_noise = np.zeros((int(sr * duration), 2), dtype=np.float32)
|
| 199 |
audio_drone = np.zeros((int(sr * duration), 2), dtype=np.float32)
|
| 200 |
audio_melody = np.zeros((int(sr * duration), 2), dtype=np.float32)
|
| 201 |
audio_glitch = np.zeros((int(sr * duration), 2), dtype=np.float32)
|
| 202 |
melody_events = []
|
| 203 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 204 |
# Layer 1: Texture Floor
|
| 205 |
if features["edge_density"] > 0.007:
|
| 206 |
noise = self._generate_tone(0, duration, "noise")
|
|
@@ -332,6 +384,14 @@ def main():
|
|
| 332 |
parser.add_argument("--midi", action="store_true", help="Export MIDI file from melody events")
|
| 333 |
parser.add_argument("--batch", action="store_true", help="Process all images in a folder")
|
| 334 |
parser.add_argument("--quiet", action="store_true")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 335 |
args = parser.parse_args()
|
| 336 |
|
| 337 |
config = {
|
|
@@ -340,6 +400,11 @@ def main():
|
|
| 340 |
"verbose": not args.quiet,
|
| 341 |
"export_stems": args.stems,
|
| 342 |
"export_midi": args.midi,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 343 |
}
|
| 344 |
if args.noise_filter is not None:
|
| 345 |
config["noise_lowpass_hz"] = args.noise_filter
|
|
|
|
| 1 |
#!/usr/bin/env python3
|
| 2 |
"""
|
| 3 |
+
LYGO Resonance Engine v0.4
|
| 4 |
+
Image β Living Stereo Soundscape with LDQ Protocol integration
|
|
|
|
| 5 |
"""
|
| 6 |
|
| 7 |
import cv2
|
|
|
|
| 15 |
import mido
|
| 16 |
from mido import MidiFile, MidiTrack, Message
|
| 17 |
|
| 18 |
+
# LDQ imports
|
| 19 |
+
import ldq_fingerprint
|
| 20 |
+
import ldq_genre_manifold
|
| 21 |
+
import ldq_percussion
|
| 22 |
+
import ldq_perceptual_layer
|
| 23 |
+
|
| 24 |
+
__version__ = "0.4.0"
|
| 25 |
|
| 26 |
# Artistic Presets
|
| 27 |
PRESETS = {
|
|
|
|
| 100 |
"verbose": True,
|
| 101 |
"export_stems": False,
|
| 102 |
"export_midi": False,
|
| 103 |
+
# LDQ Protocol flags
|
| 104 |
+
"use_ldq": False,
|
| 105 |
+
"genre_manifold": "None",
|
| 106 |
+
"percussion_mode": "standard",
|
| 107 |
+
"perceptual_polish": 0.0,
|
| 108 |
}
|
| 109 |
if config:
|
| 110 |
self.config.update(config)
|
|
|
|
| 204 |
theta = np.interp(features["avg_green"], [0, 255], cfg["theta_lock_range"])
|
| 205 |
w, h = features["width"], features["height"]
|
| 206 |
|
| 207 |
+
# Initialize stem collections for standard mode
|
| 208 |
audio_noise = np.zeros((int(sr * duration), 2), dtype=np.float32)
|
| 209 |
audio_drone = np.zeros((int(sr * duration), 2), dtype=np.float32)
|
| 210 |
audio_melody = np.zeros((int(sr * duration), 2), dtype=np.float32)
|
| 211 |
audio_glitch = np.zeros((int(sr * duration), 2), dtype=np.float32)
|
| 212 |
melody_events = []
|
| 213 |
|
| 214 |
+
# ===== LDQ Protocol Integration =====
|
| 215 |
+
if cfg.get("use_ldq"):
|
| 216 |
+
self._log("π¬ LDQ Protocol Active")
|
| 217 |
+
|
| 218 |
+
# 1. Compute Visual Genesis Hash
|
| 219 |
+
vgh = ldq_fingerprint.compute_vgh(output_path.replace(".wav", ".jpg"))
|
| 220 |
+
self._log(f"π VGH: {vgh[:16]}...")
|
| 221 |
+
|
| 222 |
+
# 2. Genre Manifold Projection
|
| 223 |
+
genre_params = {}
|
| 224 |
+
if cfg.get("genre_manifold") and cfg["genre_manifold"] != "None":
|
| 225 |
+
genre_params = ldq_genre_manifold.project_to_genre(features, cfg["genre_manifold"])
|
| 226 |
+
self._log(f"π΅ Genre: {cfg['genre_manifold']}")
|
| 227 |
+
# Apply genre parameters
|
| 228 |
+
theta = theta * (1 + genre_params.get("swing_amount", 0))
|
| 229 |
+
cfg["root_freq_range"] = (root * 0.9, root * 1.1)
|
| 230 |
+
|
| 231 |
+
# 3. Percussion Engine
|
| 232 |
+
if cfg.get("percussion_mode") == "ldq":
|
| 233 |
+
self._log("π₯ LDQ Percussion Active")
|
| 234 |
+
# Generate drums
|
| 235 |
+
kick = ldq_percussion.generate_kick(features, sr, duration)
|
| 236 |
+
snare = ldq_percussion.generate_snare(features, sr, duration)
|
| 237 |
+
hihats = ldq_percussion.generate_hihats(features, sr, 120, duration)
|
| 238 |
+
|
| 239 |
+
# Mix into audio
|
| 240 |
+
audio += self._stereo_pan(kick, 0.0) * 0.4
|
| 241 |
+
audio += self._stereo_pan(snare, 0.2) * 0.3
|
| 242 |
+
audio += self._stereo_pan(hihats, -0.2) * 0.2
|
| 243 |
+
# Skip standard layers
|
| 244 |
+
return
|
| 245 |
+
|
| 246 |
+
# 4. Perceptual Polish
|
| 247 |
+
if cfg.get("perceptual_polish", 0.0) > 0:
|
| 248 |
+
self._log("ποΈ Applying Perceptual Polish")
|
| 249 |
+
audio = ldq_perceptual_layer.apply_perceptual_mixing(audio, features, sr)
|
| 250 |
+
|
| 251 |
+
# 5. Fingerprinting (applied at end)
|
| 252 |
+
audio = ldq_fingerprint.embed_fingerprint(audio, sr, vgh)
|
| 253 |
+
self._log("π Fingerprint Embedded")
|
| 254 |
+
|
| 255 |
+
# ===== Standard Synthesis (if LDQ not active or partial) =====
|
| 256 |
# Layer 1: Texture Floor
|
| 257 |
if features["edge_density"] > 0.007:
|
| 258 |
noise = self._generate_tone(0, duration, "noise")
|
|
|
|
| 384 |
parser.add_argument("--midi", action="store_true", help="Export MIDI file from melody events")
|
| 385 |
parser.add_argument("--batch", action="store_true", help="Process all images in a folder")
|
| 386 |
parser.add_argument("--quiet", action="store_true")
|
| 387 |
+
# LDQ arguments
|
| 388 |
+
parser.add_argument("--ldq", action="store_true", help="Enable LDQ Protocol")
|
| 389 |
+
parser.add_argument("--genre", choices=["None", "Dubstep", "Phonk", "Industrial"], default="None",
|
| 390 |
+
help="Genre manifold projection")
|
| 391 |
+
parser.add_argument("--percussion", choices=["standard", "ldq"], default="standard",
|
| 392 |
+
help="Percussion engine mode")
|
| 393 |
+
parser.add_argument("--polish", type=float, default=0.0,
|
| 394 |
+
help="Perceptual polish amount (0.0-1.0)")
|
| 395 |
args = parser.parse_args()
|
| 396 |
|
| 397 |
config = {
|
|
|
|
| 400 |
"verbose": not args.quiet,
|
| 401 |
"export_stems": args.stems,
|
| 402 |
"export_midi": args.midi,
|
| 403 |
+
# LDQ config
|
| 404 |
+
"use_ldq": args.ldq,
|
| 405 |
+
"genre_manifold": args.genre,
|
| 406 |
+
"percussion_mode": args.percussion,
|
| 407 |
+
"perceptual_polish": args.polish,
|
| 408 |
}
|
| 409 |
if args.noise_filter is not None:
|
| 410 |
config["noise_lowpass_hz"] = args.noise_filter
|