analyze
Perform comprehensive audio analysis with Strudel MCP Server's tool, enabling AI-driven music generation, live coding, and pattern creation for TidalCycles/Strudel projects.
Instructions
Complete audio analysis
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/AudioAnalyzer.ts:38-95 (handler)Core handler logic: Performs real-time FFT spectrum analysis on Strudel's audio output, computes frequency bands (bass, mids, treble), peak frequency, spectral centroid, activity detection (playing/silent). This is the injected JavaScript analyzer function.if (!this.analyser || !this.isConnected) { return { connected: false, error: 'Analyzer not connected' }; } this.analyser.getByteFrequencyData(this.dataArray); const data: number[] = Array.from(this.dataArray); const sum = data.reduce((a, b) => a + b, 0); const average = sum / data.length; const bass = data.slice(0, 8).reduce((a, b) => a + b, 0) / 8; const lowMid = data.slice(8, 32).reduce((a, b) => a + b, 0) / 24; const mid = data.slice(32, 128).reduce((a, b) => a + b, 0) / 96; const highMid = data.slice(128, 256).reduce((a, b) => a + b, 0) / 128; const treble = data.slice(256, 512).reduce((a, b) => a + b, 0) / 256; const peak = Math.max(...data); const peakIndex = data.indexOf(peak); const peakFreq = (peakIndex / data.length) * 22050; let weightedSum = 0; let magnitudeSum = 0; data.forEach((mag, i) => { weightedSum += i * mag; magnitudeSum += mag; }); const centroid = magnitudeSum > 0 ? weightedSum / magnitudeSum : 0; const isPlaying = average > 5; const isSilent = average < 1; return { connected: true, timestamp: Date.now(), features: { average: Math.round(average * 10) / 10, peak, peakFrequency: Math.round(peakFreq), centroid: Math.round(centroid * 10) / 10, bass: Math.round(bass), lowMid: Math.round(lowMid), mid: Math.round(mid), highMid: Math.round(highMid), treble: Math.round(treble), isPlaying, isSilent, bassToTrebleRatio: treble > 0 ? (bass / treble).toFixed(2) : 'N/A', brightness: centroid > 500 ? 'bright' : centroid > 200 ? 'balanced' : 'dark' } }; } };
- src/AudioAnalyzer.ts:101-108 (handler)Handler wrapper: Executes the injected analyze() function via page.evaluate to retrieve current audio analysis.async getAnalysis(page: Page): Promise<any> { return await page.evaluate(() => { if ((window as any).strudelAudioAnalyzer) { return (window as any).strudelAudioAnalyzer.analyze(); } return { error: 'Analyzer not initialized' }; }); }
- src/StrudelController.ts:87-91 (helper)Helper method in StrudelController: Delegates audio analysis to AudioAnalyzer instance.async analyzeAudio(): Promise<any> { if (!this.page) throw new Error('Not initialized'); return await this.analyzer.getAnalysis(this.page); }
- src/server/EnhancedMCPServer.ts:631-632 (handler)MCP tool dispatch handler: Switch case in executeTool that invokes controller.analyzeAudio() for the 'analyze' tool.case 'analyze': return await this.controller.analyzeAudio();
- src/server/EnhancedMCPServer.ts:243-247 (registration)Tool registration: Defines the 'analyze' tool in getTools() list with empty input schema for MCP ListTools response.{ name: 'analyze', description: 'Complete audio analysis', inputSchema: { type: 'object', properties: {} } },