Spaces:
Running
on
Zero
Running
on
Zero
File size: 29,906 Bytes
309dea0 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 |
"""
Audio mastering service with industry-standard presets using Pedalboard
"""
import os
import logging
import numpy as np
from pathlib import Path
from typing import Dict, List, Optional
import soundfile as sf
from pedalboard import (
Pedalboard,
Compressor,
Limiter,
Gain,
HighpassFilter,
LowpassFilter,
PeakFilter,
LowShelfFilter,
HighShelfFilter,
Reverb,
Chorus,
Delay
)
logger = logging.getLogger(__name__)
class MasteringPreset:
"""Mastering preset configuration"""
def __init__(self, name: str, description: str, chain: List):
self.name = name
self.description = description
self.chain = chain
class MasteringService:
"""Audio mastering and EQ service"""
# Industry-standard mastering presets
PRESETS = {
# Clean/Transparent Presets
"clean_master": MasteringPreset(
"Clean Master",
"Transparent mastering with gentle compression",
[
HighpassFilter(cutoff_frequency_hz=30),
PeakFilter(cutoff_frequency_hz=100, gain_db=-1, q=0.7),
PeakFilter(cutoff_frequency_hz=3000, gain_db=0.5, q=1.0),
PeakFilter(cutoff_frequency_hz=10000, gain_db=1.0, q=0.7),
Compressor(threshold_db=-12, ratio=2.0, attack_ms=5, release_ms=100),
Limiter(threshold_db=-1.0, release_ms=100)
]
),
"subtle_warmth": MasteringPreset(
"Subtle Warmth",
"Gentle low-end enhancement with smooth highs",
[
HighpassFilter(cutoff_frequency_hz=25),
LowShelfFilter(cutoff_frequency_hz=100, gain_db=1.5, q=0.7),
PeakFilter(cutoff_frequency_hz=200, gain_db=0.8, q=0.5),
PeakFilter(cutoff_frequency_hz=8000, gain_db=-0.5, q=1.0),
HighShelfFilter(cutoff_frequency_hz=12000, gain_db=1.0, q=0.7),
Compressor(threshold_db=-15, ratio=2.5, attack_ms=10, release_ms=150),
Limiter(threshold_db=-0.5, release_ms=100)
]
),
# Pop/Commercial Presets
"modern_pop": MasteringPreset(
"Modern Pop",
"Radio-ready pop sound with punchy compression",
[
HighpassFilter(cutoff_frequency_hz=35),
PeakFilter(cutoff_frequency_hz=80, gain_db=-1.5, q=0.8),
LowShelfFilter(cutoff_frequency_hz=120, gain_db=2.0, q=0.7),
PeakFilter(cutoff_frequency_hz=2500, gain_db=1.5, q=1.2),
HighShelfFilter(cutoff_frequency_hz=10000, gain_db=2.5, q=0.7),
Compressor(threshold_db=-10, ratio=4.0, attack_ms=3, release_ms=80),
Limiter(threshold_db=-0.3, release_ms=50)
]
),
"radio_ready": MasteringPreset(
"Radio Ready",
"Maximum loudness for commercial radio",
[
HighpassFilter(cutoff_frequency_hz=40),
PeakFilter(cutoff_frequency_hz=60, gain_db=-2.0, q=1.0),
LowShelfFilter(cutoff_frequency_hz=150, gain_db=1.5, q=0.8),
PeakFilter(cutoff_frequency_hz=3000, gain_db=2.0, q=1.5),
PeakFilter(cutoff_frequency_hz=8000, gain_db=1.5, q=1.0),
HighShelfFilter(cutoff_frequency_hz=12000, gain_db=3.0, q=0.7),
Compressor(threshold_db=-8, ratio=6.0, attack_ms=2, release_ms=60),
Limiter(threshold_db=-0.1, release_ms=30)
]
),
"punchy_commercial": MasteringPreset(
"Punchy Commercial",
"Aggressive punch for mainstream appeal",
[
HighpassFilter(cutoff_frequency_hz=30),
PeakFilter(cutoff_frequency_hz=100, gain_db=-2.0, q=1.2),
LowShelfFilter(cutoff_frequency_hz=200, gain_db=2.5, q=0.7),
PeakFilter(cutoff_frequency_hz=1000, gain_db=-1.0, q=0.8),
PeakFilter(cutoff_frequency_hz=4000, gain_db=2.5, q=1.5),
HighShelfFilter(cutoff_frequency_hz=10000, gain_db=2.0, q=0.8),
Compressor(threshold_db=-9, ratio=5.0, attack_ms=1, release_ms=50),
Limiter(threshold_db=-0.2, release_ms=40)
]
),
# Rock/Alternative Presets
"rock_master": MasteringPreset(
"Rock Master",
"Powerful rock sound with emphasis on mids",
[
HighpassFilter(cutoff_frequency_hz=35),
LowShelfFilter(cutoff_frequency_hz=100, gain_db=1.0, q=0.7),
PeakFilter(cutoff_frequency_hz=400, gain_db=1.5, q=1.0),
PeakFilter(cutoff_frequency_hz=2000, gain_db=2.0, q=1.2),
PeakFilter(cutoff_frequency_hz=5000, gain_db=1.5, q=1.0),
HighShelfFilter(cutoff_frequency_hz=8000, gain_db=1.0, q=0.8),
Compressor(threshold_db=-12, ratio=3.5, attack_ms=5, release_ms=120),
Limiter(threshold_db=-0.5, release_ms=80)
]
),
"metal_aggressive": MasteringPreset(
"Metal Aggressive",
"Heavy, aggressive metal mastering",
[
HighpassFilter(cutoff_frequency_hz=40),
PeakFilter(cutoff_frequency_hz=80, gain_db=-1.5, q=1.0),
LowShelfFilter(cutoff_frequency_hz=150, gain_db=2.0, q=0.8),
PeakFilter(cutoff_frequency_hz=800, gain_db=-1.5, q=1.2),
PeakFilter(cutoff_frequency_hz=3000, gain_db=3.0, q=1.5),
HighShelfFilter(cutoff_frequency_hz=10000, gain_db=2.5, q=0.7),
Compressor(threshold_db=-8, ratio=6.0, attack_ms=1, release_ms=50),
Limiter(threshold_db=-0.1, release_ms=30)
]
),
"indie_rock": MasteringPreset(
"Indie Rock",
"Lo-fi character with mid presence",
[
HighpassFilter(cutoff_frequency_hz=30),
LowShelfFilter(cutoff_frequency_hz=120, gain_db=0.5, q=0.7),
PeakFilter(cutoff_frequency_hz=500, gain_db=1.5, q=1.0),
PeakFilter(cutoff_frequency_hz=2500, gain_db=2.0, q=1.2),
PeakFilter(cutoff_frequency_hz=7000, gain_db=-0.5, q=1.0),
HighShelfFilter(cutoff_frequency_hz=10000, gain_db=0.5, q=0.8),
Compressor(threshold_db=-14, ratio=3.0, attack_ms=8, release_ms=150),
Limiter(threshold_db=-0.8, release_ms=100)
]
),
# Electronic/EDM Presets
"edm_club": MasteringPreset(
"EDM Club",
"Powerful club sound with deep bass",
[
HighpassFilter(cutoff_frequency_hz=25),
LowShelfFilter(cutoff_frequency_hz=80, gain_db=3.0, q=0.7),
PeakFilter(cutoff_frequency_hz=150, gain_db=2.0, q=0.8),
PeakFilter(cutoff_frequency_hz=1000, gain_db=-1.5, q=1.0),
PeakFilter(cutoff_frequency_hz=5000, gain_db=2.0, q=1.2),
HighShelfFilter(cutoff_frequency_hz=12000, gain_db=3.0, q=0.7),
Compressor(threshold_db=-6, ratio=8.0, attack_ms=0.5, release_ms=40),
Limiter(threshold_db=0.0, release_ms=20)
]
),
"house_groovy": MasteringPreset(
"House Groovy",
"Smooth house music with rolling bass",
[
HighpassFilter(cutoff_frequency_hz=30),
LowShelfFilter(cutoff_frequency_hz=100, gain_db=2.5, q=0.7),
PeakFilter(cutoff_frequency_hz=250, gain_db=1.0, q=0.8),
PeakFilter(cutoff_frequency_hz=2000, gain_db=0.5, q=1.0),
PeakFilter(cutoff_frequency_hz=8000, gain_db=1.5, q=1.0),
HighShelfFilter(cutoff_frequency_hz=10000, gain_db=2.0, q=0.7),
Compressor(threshold_db=-10, ratio=4.0, attack_ms=2, release_ms=60),
Limiter(threshold_db=-0.2, release_ms=40)
]
),
"techno_dark": MasteringPreset(
"Techno Dark",
"Dark, pounding techno master",
[
HighpassFilter(cutoff_frequency_hz=35),
PeakFilter(cutoff_frequency_hz=60, gain_db=2.0, q=1.0),
LowShelfFilter(cutoff_frequency_hz=120, gain_db=1.5, q=0.8),
PeakFilter(cutoff_frequency_hz=800, gain_db=-2.0, q=1.5),
PeakFilter(cutoff_frequency_hz=4000, gain_db=1.0, q=1.0),
HighShelfFilter(cutoff_frequency_hz=10000, gain_db=-0.5, q=0.8),
Compressor(threshold_db=-8, ratio=6.0, attack_ms=1, release_ms=50),
Limiter(threshold_db=-0.1, release_ms=30)
]
),
"dubstep_heavy": MasteringPreset(
"Dubstep Heavy",
"Sub-bass focused with crispy highs",
[
HighpassFilter(cutoff_frequency_hz=20),
PeakFilter(cutoff_frequency_hz=50, gain_db=3.5, q=1.2),
LowShelfFilter(cutoff_frequency_hz=100, gain_db=2.5, q=0.8),
PeakFilter(cutoff_frequency_hz=500, gain_db=-2.0, q=1.5),
PeakFilter(cutoff_frequency_hz=6000, gain_db=2.5, q=1.2),
HighShelfFilter(cutoff_frequency_hz=12000, gain_db=3.5, q=0.7),
Compressor(threshold_db=-6, ratio=10.0, attack_ms=0.3, release_ms=30),
Limiter(threshold_db=0.0, release_ms=20)
]
),
# Hip-Hop/R&B Presets
"hiphop_modern": MasteringPreset(
"Hip-Hop Modern",
"Contemporary hip-hop with deep bass",
[
HighpassFilter(cutoff_frequency_hz=25),
LowShelfFilter(cutoff_frequency_hz=80, gain_db=2.5, q=0.7),
PeakFilter(cutoff_frequency_hz=150, gain_db=1.5, q=0.8),
PeakFilter(cutoff_frequency_hz=1000, gain_db=-1.0, q=1.0),
PeakFilter(cutoff_frequency_hz=3500, gain_db=2.0, q=1.2),
HighShelfFilter(cutoff_frequency_hz=10000, gain_db=1.5, q=0.7),
Compressor(threshold_db=-10, ratio=4.0, attack_ms=5, release_ms=80),
Limiter(threshold_db=-0.3, release_ms=60)
]
),
"trap_808": MasteringPreset(
"Trap 808",
"808-focused trap mastering",
[
HighpassFilter(cutoff_frequency_hz=20),
PeakFilter(cutoff_frequency_hz=50, gain_db=3.0, q=1.0),
LowShelfFilter(cutoff_frequency_hz=100, gain_db=2.0, q=0.7),
PeakFilter(cutoff_frequency_hz=800, gain_db=-1.5, q=1.2),
PeakFilter(cutoff_frequency_hz=5000, gain_db=2.5, q=1.2),
HighShelfFilter(cutoff_frequency_hz=12000, gain_db=2.0, q=0.7),
Compressor(threshold_db=-8, ratio=5.0, attack_ms=3, release_ms=60),
Limiter(threshold_db=-0.2, release_ms=40)
]
),
"rnb_smooth": MasteringPreset(
"R&B Smooth",
"Silky smooth R&B sound",
[
HighpassFilter(cutoff_frequency_hz=30),
LowShelfFilter(cutoff_frequency_hz=100, gain_db=1.5, q=0.7),
PeakFilter(cutoff_frequency_hz=300, gain_db=1.0, q=0.8),
PeakFilter(cutoff_frequency_hz=2000, gain_db=0.5, q=1.0),
PeakFilter(cutoff_frequency_hz=6000, gain_db=1.5, q=1.0),
HighShelfFilter(cutoff_frequency_hz=10000, gain_db=2.0, q=0.7),
Compressor(threshold_db=-12, ratio=3.0, attack_ms=8, release_ms=120),
Limiter(threshold_db=-0.5, release_ms=80)
]
),
# Acoustic/Organic Presets
"acoustic_natural": MasteringPreset(
"Acoustic Natural",
"Natural, transparent acoustic sound",
[
HighpassFilter(cutoff_frequency_hz=25),
LowShelfFilter(cutoff_frequency_hz=100, gain_db=0.5, q=0.7),
PeakFilter(cutoff_frequency_hz=500, gain_db=0.8, q=0.8),
PeakFilter(cutoff_frequency_hz=3000, gain_db=1.0, q=1.0),
HighShelfFilter(cutoff_frequency_hz=8000, gain_db=1.5, q=0.7),
Compressor(threshold_db=-16, ratio=2.0, attack_ms=15, release_ms=200),
Limiter(threshold_db=-1.0, release_ms=120)
]
),
"folk_warm": MasteringPreset(
"Folk Warm",
"Warm, intimate folk sound",
[
HighpassFilter(cutoff_frequency_hz=30),
LowShelfFilter(cutoff_frequency_hz=150, gain_db=1.0, q=0.7),
PeakFilter(cutoff_frequency_hz=400, gain_db=1.5, q=0.8),
PeakFilter(cutoff_frequency_hz=2500, gain_db=1.0, q=1.0),
PeakFilter(cutoff_frequency_hz=7000, gain_db=-0.5, q=1.0),
HighShelfFilter(cutoff_frequency_hz=10000, gain_db=1.0, q=0.8),
Compressor(threshold_db=-18, ratio=2.5, attack_ms=20, release_ms=250),
Limiter(threshold_db=-1.5, release_ms=150)
]
),
"jazz_vintage": MasteringPreset(
"Jazz Vintage",
"Classic jazz warmth and space",
[
HighpassFilter(cutoff_frequency_hz=35),
LowShelfFilter(cutoff_frequency_hz=120, gain_db=1.0, q=0.7),
PeakFilter(cutoff_frequency_hz=500, gain_db=1.0, q=0.8),
PeakFilter(cutoff_frequency_hz=2000, gain_db=0.5, q=0.8),
PeakFilter(cutoff_frequency_hz=8000, gain_db=-1.0, q=1.0),
HighShelfFilter(cutoff_frequency_hz=12000, gain_db=0.5, q=0.8),
Compressor(threshold_db=-20, ratio=2.0, attack_ms=25, release_ms=300),
Limiter(threshold_db=-2.0, release_ms=180)
]
),
# Classical/Orchestral Presets
"orchestral_wide": MasteringPreset(
"Orchestral Wide",
"Wide, natural orchestral sound",
[
HighpassFilter(cutoff_frequency_hz=20),
LowShelfFilter(cutoff_frequency_hz=80, gain_db=0.5, q=0.7),
PeakFilter(cutoff_frequency_hz=300, gain_db=0.5, q=0.7),
PeakFilter(cutoff_frequency_hz=4000, gain_db=0.8, q=0.8),
HighShelfFilter(cutoff_frequency_hz=10000, gain_db=1.0, q=0.7),
Compressor(threshold_db=-24, ratio=1.5, attack_ms=30, release_ms=400),
Limiter(threshold_db=-3.0, release_ms=250)
]
),
"classical_concert": MasteringPreset(
"Classical Concert",
"Concert hall ambience and dynamics",
[
HighpassFilter(cutoff_frequency_hz=25),
PeakFilter(cutoff_frequency_hz=200, gain_db=0.5, q=0.7),
PeakFilter(cutoff_frequency_hz=1000, gain_db=0.3, q=0.8),
PeakFilter(cutoff_frequency_hz=6000, gain_db=0.8, q=0.8),
HighShelfFilter(cutoff_frequency_hz=12000, gain_db=0.5, q=0.7),
Compressor(threshold_db=-30, ratio=1.2, attack_ms=50, release_ms=500),
Limiter(threshold_db=-4.0, release_ms=300)
]
),
# Ambient/Atmospheric Presets
"ambient_spacious": MasteringPreset(
"Ambient Spacious",
"Wide, spacious ambient master",
[
HighpassFilter(cutoff_frequency_hz=25),
LowShelfFilter(cutoff_frequency_hz=100, gain_db=0.5, q=0.7),
PeakFilter(cutoff_frequency_hz=500, gain_db=-0.5, q=0.8),
PeakFilter(cutoff_frequency_hz=3000, gain_db=0.5, q=1.0),
HighShelfFilter(cutoff_frequency_hz=8000, gain_db=1.5, q=0.7),
Compressor(threshold_db=-20, ratio=2.0, attack_ms=50, release_ms=400),
Limiter(threshold_db=-2.0, release_ms=200)
]
),
"cinematic_epic": MasteringPreset(
"Cinematic Epic",
"Big, powerful cinematic sound",
[
HighpassFilter(cutoff_frequency_hz=30),
LowShelfFilter(cutoff_frequency_hz=100, gain_db=2.0, q=0.7),
PeakFilter(cutoff_frequency_hz=250, gain_db=1.0, q=0.8),
PeakFilter(cutoff_frequency_hz=2000, gain_db=1.5, q=1.0),
PeakFilter(cutoff_frequency_hz=6000, gain_db=2.0, q=1.0),
HighShelfFilter(cutoff_frequency_hz=10000, gain_db=2.5, q=0.7),
Compressor(threshold_db=-14, ratio=3.0, attack_ms=10, release_ms=150),
Limiter(threshold_db=-0.5, release_ms=100)
]
),
# Vintage/Lo-Fi Presets
"lofi_chill": MasteringPreset(
"Lo-Fi Chill",
"Vintage lo-fi character",
[
HighpassFilter(cutoff_frequency_hz=50),
LowpassFilter(cutoff_frequency_hz=10000),
LowShelfFilter(cutoff_frequency_hz=150, gain_db=1.5, q=0.7),
PeakFilter(cutoff_frequency_hz=800, gain_db=-1.0, q=1.2),
PeakFilter(cutoff_frequency_hz=4000, gain_db=-1.5, q=1.0),
Compressor(threshold_db=-12, ratio=3.0, attack_ms=15, release_ms=180),
Limiter(threshold_db=-1.0, release_ms=120)
]
),
"vintage_vinyl": MasteringPreset(
"Vintage Vinyl",
"Classic vinyl record warmth",
[
HighpassFilter(cutoff_frequency_hz=40),
LowpassFilter(cutoff_frequency_hz=12000),
LowShelfFilter(cutoff_frequency_hz=120, gain_db=2.0, q=0.7),
PeakFilter(cutoff_frequency_hz=1000, gain_db=-0.5, q=0.8),
PeakFilter(cutoff_frequency_hz=5000, gain_db=-1.0, q=1.0),
HighShelfFilter(cutoff_frequency_hz=8000, gain_db=-1.5, q=0.8),
Compressor(threshold_db=-16, ratio=2.5, attack_ms=20, release_ms=200),
Limiter(threshold_db=-1.5, release_ms=150)
]
),
"retro_80s": MasteringPreset(
"Retro 80s",
"1980s-inspired mix with character",
[
HighpassFilter(cutoff_frequency_hz=45),
LowShelfFilter(cutoff_frequency_hz=100, gain_db=1.5, q=0.7),
PeakFilter(cutoff_frequency_hz=800, gain_db=1.0, q=1.2),
PeakFilter(cutoff_frequency_hz=3000, gain_db=1.5, q=1.0),
HighShelfFilter(cutoff_frequency_hz=10000, gain_db=2.0, q=0.7),
Compressor(threshold_db=-14, ratio=3.5, attack_ms=5, release_ms=100),
Limiter(threshold_db=-0.8, release_ms=80)
]
),
# Enhancement Presets (Phase 2)
"harmonic_enhance": MasteringPreset(
"Harmonic Enhance",
"Adds subtle harmonic overtones for brightness and warmth",
[
HighpassFilter(cutoff_frequency_hz=30),
# Subtle low-end warmth
LowShelfFilter(cutoff_frequency_hz=100, gain_db=1.0, q=0.7),
# Presence boost
PeakFilter(cutoff_frequency_hz=3000, gain_db=1.5, q=1.0),
# Air and clarity
HighShelfFilter(cutoff_frequency_hz=8000, gain_db=2.0, q=0.7),
# Gentle saturation effect through compression
Compressor(threshold_db=-18, ratio=2.5, attack_ms=10, release_ms=120),
# Final limiting
Limiter(threshold_db=-0.5, release_ms=100),
# Note: Additional harmonic generation would require Distortion plugin
# which adds subtle harmonic overtones
]
),
# Specialized Presets
"vocal_focused": MasteringPreset(
"Vocal Focused",
"Emphasizes vocal clarity and presence",
[
HighpassFilter(cutoff_frequency_hz=30),
PeakFilter(cutoff_frequency_hz=200, gain_db=-1.0, q=0.8),
PeakFilter(cutoff_frequency_hz=1000, gain_db=1.0, q=1.0),
PeakFilter(cutoff_frequency_hz=3000, gain_db=2.5, q=1.2),
PeakFilter(cutoff_frequency_hz=5000, gain_db=1.5, q=1.0),
HighShelfFilter(cutoff_frequency_hz=10000, gain_db=1.0, q=0.7),
Compressor(threshold_db=-12, ratio=3.0, attack_ms=5, release_ms=100),
Limiter(threshold_db=-0.5, release_ms=80)
]
),
"bass_heavy": MasteringPreset(
"Bass Heavy",
"Maximum low-end power",
[
HighpassFilter(cutoff_frequency_hz=20),
LowShelfFilter(cutoff_frequency_hz=60, gain_db=4.0, q=0.7),
PeakFilter(cutoff_frequency_hz=100, gain_db=2.5, q=0.8),
PeakFilter(cutoff_frequency_hz=500, gain_db=-1.5, q=1.0),
PeakFilter(cutoff_frequency_hz=4000, gain_db=1.0, q=1.0),
HighShelfFilter(cutoff_frequency_hz=10000, gain_db=1.5, q=0.7),
Compressor(threshold_db=-10, ratio=4.0, attack_ms=10, release_ms=100),
Limiter(threshold_db=-0.3, release_ms=60)
]
),
"bright_airy": MasteringPreset(
"Bright & Airy",
"Crystal clear highs with airiness",
[
HighpassFilter(cutoff_frequency_hz=30),
LowShelfFilter(cutoff_frequency_hz=100, gain_db=-0.5, q=0.7),
PeakFilter(cutoff_frequency_hz=500, gain_db=-1.0, q=0.8),
PeakFilter(cutoff_frequency_hz=5000, gain_db=2.0, q=1.0),
PeakFilter(cutoff_frequency_hz=10000, gain_db=2.5, q=1.0),
HighShelfFilter(cutoff_frequency_hz=12000, gain_db=3.0, q=0.7),
Compressor(threshold_db=-14, ratio=2.5, attack_ms=8, release_ms=120),
Limiter(threshold_db=-0.8, release_ms=100)
]
),
"midrange_punch": MasteringPreset(
"Midrange Punch",
"Powerful mids for presence",
[
HighpassFilter(cutoff_frequency_hz=30),
LowShelfFilter(cutoff_frequency_hz=100, gain_db=0.5, q=0.7),
PeakFilter(cutoff_frequency_hz=500, gain_db=2.0, q=1.0),
PeakFilter(cutoff_frequency_hz=1500, gain_db=2.5, q=1.2),
PeakFilter(cutoff_frequency_hz=3000, gain_db=2.0, q=1.0),
HighShelfFilter(cutoff_frequency_hz=8000, gain_db=0.5, q=0.7),
Compressor(threshold_db=-11, ratio=3.5, attack_ms=5, release_ms=90),
Limiter(threshold_db=-0.5, release_ms=70)
]
),
"dynamic_range": MasteringPreset(
"Dynamic Range",
"Preserves maximum dynamics",
[
HighpassFilter(cutoff_frequency_hz=25),
PeakFilter(cutoff_frequency_hz=100, gain_db=-0.5, q=0.7),
PeakFilter(cutoff_frequency_hz=3000, gain_db=0.5, q=0.8),
HighShelfFilter(cutoff_frequency_hz=10000, gain_db=1.0, q=0.7),
Compressor(threshold_db=-20, ratio=1.5, attack_ms=20, release_ms=250),
Limiter(threshold_db=-2.0, release_ms=200)
]
),
"streaming_optimized": MasteringPreset(
"Streaming Optimized",
"Optimized for streaming platforms (Spotify, Apple Music)",
[
HighpassFilter(cutoff_frequency_hz=30),
LowShelfFilter(cutoff_frequency_hz=100, gain_db=1.0, q=0.7),
PeakFilter(cutoff_frequency_hz=500, gain_db=0.5, q=0.8),
PeakFilter(cutoff_frequency_hz=3000, gain_db=1.5, q=1.0),
HighShelfFilter(cutoff_frequency_hz=10000, gain_db=1.5, q=0.7),
Compressor(threshold_db=-14, ratio=3.0, attack_ms=5, release_ms=100),
Limiter(threshold_db=-1.0, release_ms=100)
]
)
}
def __init__(self):
"""Initialize mastering service"""
logger.info("Mastering service initialized with 32 presets")
def apply_preset(self, audio_path: str, preset_name: str, output_path: str) -> str:
"""
Apply mastering preset to audio file
Args:
audio_path: Path to input audio file
preset_name: Name of preset to apply
output_path: Path to save processed audio
Returns:
Path to processed audio file
"""
try:
if preset_name not in self.PRESETS:
raise ValueError(f"Unknown preset: {preset_name}")
preset = self.PRESETS[preset_name]
logger.info(f"Applying preset '{preset.name}' to {audio_path}")
# Load audio
audio, sr = sf.read(audio_path)
# Ensure stereo
if len(audio.shape) == 1:
audio = np.stack([audio, audio], axis=1)
# Create pedalboard with preset chain
board = Pedalboard(preset.chain)
# Process audio
processed = board(audio.T, sr)
# Save processed audio
sf.write(output_path, processed.T, sr)
logger.info(f"Saved mastered audio to {output_path}")
return output_path
except Exception as e:
logger.error(f"Error applying preset: {str(e)}", exc_info=True)
raise
def apply_custom_eq(
self,
audio_path: str,
output_path: str,
eq_bands: List[Dict],
compression: Optional[Dict] = None,
limiting: Optional[Dict] = None
) -> str:
"""
Apply custom EQ settings to audio file
Args:
audio_path: Path to input audio file
output_path: Path to save processed audio
eq_bands: List of EQ band settings
compression: Compression settings (optional)
limiting: Limiter settings (optional)
Returns:
Path to processed audio file
"""
try:
logger.info(f"Applying custom EQ to {audio_path}")
# Load audio
audio, sr = sf.read(audio_path)
# Ensure stereo
if len(audio.shape) == 1:
audio = np.stack([audio, audio], axis=1)
# Build processing chain
chain = []
# Add EQ bands
for band in eq_bands:
band_type = band.get('type', 'peak')
freq = band.get('frequency', 1000)
gain = band.get('gain', 0)
q = band.get('q', 1.0)
if band_type == 'highpass':
chain.append(HighpassFilter(cutoff_frequency_hz=freq))
elif band_type == 'lowpass':
chain.append(LowpassFilter(cutoff_frequency_hz=freq))
elif band_type == 'lowshelf':
chain.append(LowShelfFilter(cutoff_frequency_hz=freq, gain_db=gain, q=q))
elif band_type == 'highshelf':
chain.append(HighShelfFilter(cutoff_frequency_hz=freq, gain_db=gain, q=q))
else: # peak
chain.append(PeakFilter(cutoff_frequency_hz=freq, gain_db=gain, q=q))
# Add compression if specified
if compression:
chain.append(Compressor(
threshold_db=compression.get('threshold', -12),
ratio=compression.get('ratio', 2.0),
attack_ms=compression.get('attack', 5),
release_ms=compression.get('release', 100)
))
# Add limiting if specified
if limiting:
chain.append(Limiter(
threshold_db=limiting.get('threshold', -1.0),
release_ms=limiting.get('release', 100)
))
# Create and apply pedalboard
board = Pedalboard(chain)
processed = board(audio.T, sr)
# Save processed audio
sf.write(output_path, processed.T, sr)
logger.info(f"Saved custom EQ audio to {output_path}")
return output_path
except Exception as e:
logger.error(f"Error applying custom EQ: {str(e)}", exc_info=True)
raise
def get_preset_list(self) -> List[Dict]:
"""Get list of available presets with descriptions"""
return [
{
'id': key,
'name': preset.name,
'description': preset.description
}
for key, preset in self.PRESETS.items()
]
|