analyze_frequency_spectrum
Render a REAPER project and obtain RMS levels in dB for seven frequency bands: sub-bass (20–60Hz), bass (60–250Hz), low mids, mids, high mids, presence, and brilliance (8–20kHz).
Instructions
Render the project and analyze frequency band levels. Returns RMS level in dB for seven bands: sub_bass (20–60Hz), bass (60–250Hz), low_mids (250–500Hz), mids (500–2kHz), high_mids (2–4kHz), presence (4–8kHz), brilliance (8–20kHz).
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/reaper_mcp/analysis_tools.py:23-68 (handler)The main handler function for the 'analyze_frequency_spectrum' tool. It renders the project to a temp WAV, uses librosa to compute STFT, splits the spectrum into 7 frequency bands (sub_bass, bass, low_mids, mids, high_mids, presence, brilliance), and returns RMS levels in dB for each band using the helper _band_rms_db.
@mcp.tool() def analyze_frequency_spectrum() -> dict: """ Render the project and analyze frequency band levels. Returns RMS level in dB for seven bands: sub_bass (20–60Hz), bass (60–250Hz), low_mids (250–500Hz), mids (500–2kHz), high_mids (2–4kHz), presence (4–8kHz), brilliance (8–20kHz). """ try: import librosa import soundfile as sf from reaper_mcp.render_tools import render_to_temp_file tmp = render_to_temp_file() try: y, sr = librosa.load(tmp, sr=None, mono=True) finally: if os.path.exists(tmp): os.unlink(tmp) D = np.abs(librosa.stft(y)) freqs = librosa.fft_frequencies(sr=sr) bands = { "sub_bass": (20, 60), "bass": (60, 250), "low_mids": (250, 500), "mids": (500, 2000), "high_mids": (2000, 4000), "presence": (4000, 8000), "brilliance": (8000, min(20000, sr // 2)), } results = { name: { "range_hz": f"{lo}–{hi}", "level_db": round(_band_rms_db(D, freqs, lo, hi), 1), } for name, (lo, hi) in bands.items() } return {"success": True, "frequency_bands": results} except Exception as e: logger.error(f"analyze_frequency_spectrum failed: {e}") return {"success": False, "error": str(e)} - Helper function _band_rms_db that computes the RMS level in dB for a specific frequency range from an STFT magnitude matrix D and its corresponding frequency array.
def _band_rms_db(D: np.ndarray, freqs: np.ndarray, lo: float, hi: float) -> float: mask = (freqs >= lo) & (freqs <= hi) if not mask.any(): return -120.0 power = float(np.mean(D[mask, :] ** 2)) return float(10 * np.log10(power + 1e-12)) - src/reaper_mcp/analysis_tools.py:21-21 (registration)The 'register_tools' function entry point which is called from server.py. Inside it, the @mcp.tool() decorator on line 23 registers 'analyze_frequency_spectrum' as an MCP tool.
def register_tools(mcp): - src/reaper_mcp/server.py:18-18 (registration)Import of the register_tools function from analysis_tools module into the server.
from reaper_mcp.analysis_tools import register_tools as _reg_analysis - src/reaper_mcp/server.py:28-28 (registration)Invocation of _reg_analysis(mcp) which triggers all tool registrations in analysis_tools.py, including analyze_frequency_spectrum.
_reg_analysis(mcp)