tee342 commited on
Commit
086e495
Β·
verified Β·
1 Parent(s): d2e08bc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -16
app.py CHANGED
@@ -173,14 +173,29 @@ def ai_mastering_chain(audio_path, genre="Pop", target_lufs=-14.0):
173
  loudness = meter.integrated_loudness(samples.astype(np.float64) / 32768.0)
174
  gain_db = target_lufs - loudness
175
  final_audio = eq_audio + gain_db
176
-
177
- # Final limiting
178
  final_audio = apply_limiter(final_audio)
179
 
180
  out_path = os.path.join(tempfile.gettempdir(), "mastered_output.wav")
181
  final_audio.export(out_path, format="wav")
182
  return out_path
183
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
184
  # === Vocal Isolation Helpers ===
185
  def load_track_local(path, sample_rate, channels=2):
186
  sig, rate = torchaudio.load(path)
@@ -428,6 +443,20 @@ with gr.Blocks(title="AI Audio Studio", css="style.css") as demo:
428
  allow_flagging="never"
429
  )
430
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
431
  # --- Remix Mode ---
432
  with gr.Tab("πŸŽ› Remix Mode"):
433
  gr.Interface(
@@ -445,20 +474,6 @@ with gr.Blocks(title="AI Audio Studio", css="style.css") as demo:
445
  clear_btn=None
446
  )
447
 
448
- # --- Harmonic Saturation / Exciter ===
449
- with gr.Tab("🧬 Harmonic Saturation"):
450
- gr.Interface(
451
- fn=harmonic_saturation,
452
- inputs=[
453
- gr.Audio(label="Upload Track", type="filepath"),
454
- gr.Dropdown(choices=["Tube", "Tape", "Console", "Mix Bus"], label="Saturation Type", value="Tube"),
455
- gr.Slider(minimum=0.1, maximum=1.0, value=0.2, label="Intensity")
456
- ],
457
- outputs=gr.Audio(label="Warm Output", type="filepath"),
458
- title="Add Analog-Style Warmth",
459
- description="Enhance clarity and presence using saturation styles like Tube or Tape."
460
- )
461
-
462
  # --- Preset Cards Gallery ===
463
  with gr.Tab("πŸŽ› Preset Gallery"):
464
  gr.Markdown("### Select a preset visually")
 
173
  loudness = meter.integrated_loudness(samples.astype(np.float64) / 32768.0)
174
  gain_db = target_lufs - loudness
175
  final_audio = eq_audio + gain_db
 
 
176
  final_audio = apply_limiter(final_audio)
177
 
178
  out_path = os.path.join(tempfile.gettempdir(), "mastered_output.wav")
179
  final_audio.export(out_path, format="wav")
180
  return out_path
181
 
182
+ # === Harmonic Saturation / Exciter – Now Defined Before Use ===
183
+ def harmonic_saturation(audio, saturation_type="Tube", intensity=0.2):
184
+ samples = np.array(audio.get_array_of_samples()).astype(np.float32)
185
+
186
+ if saturation_type == "Tube":
187
+ saturated = np.tanh(intensity * samples)
188
+ elif saturation_type == "Tape":
189
+ saturated = np.where(samples > 0, 1 - np.exp(-intensity * samples), -1 + np.exp(intensity * samples))
190
+ elif saturation_type == "Console":
191
+ saturated = np.clip(samples, -32768, 32768) * intensity
192
+ elif saturation_type == "Mix Bus":
193
+ saturated = np.log1p(np.abs(samples)) * np.sign(samples) * intensity
194
+ else:
195
+ saturated = samples
196
+
197
+ return array_to_audiosegment(saturated.astype(np.int16), audio.frame_rate, channels=audio.channels)
198
+
199
  # === Vocal Isolation Helpers ===
200
  def load_track_local(path, sample_rate, channels=2):
201
  sig, rate = torchaudio.load(path)
 
443
  allow_flagging="never"
444
  )
445
 
446
+ # --- Harmonic Saturation / Exciter – Now Included ===
447
+ with gr.Tab("🧬 Harmonic Saturation"):
448
+ gr.Interface(
449
+ fn=harmonic_saturation,
450
+ inputs=[
451
+ gr.Audio(label="Upload Track", type="filepath"),
452
+ gr.Dropdown(choices=["Tube", "Tape", "Console", "Mix Bus"], label="Saturation Type", value="Tube"),
453
+ gr.Slider(minimum=0.1, maximum=1.0, value=0.2, label="Intensity")
454
+ ],
455
+ outputs=gr.Audio(label="Warm Output", type="filepath"),
456
+ title="Add Analog-Style Warmth",
457
+ description="Enhance clarity and presence using saturation styles like Tube or Tape."
458
+ )
459
+
460
  # --- Remix Mode ---
461
  with gr.Tab("πŸŽ› Remix Mode"):
462
  gr.Interface(
 
474
  clear_btn=None
475
  )
476
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
477
  # --- Preset Cards Gallery ===
478
  with gr.Tab("πŸŽ› Preset Gallery"):
479
  gr.Markdown("### Select a preset visually")