API Reference / analyzeFullBuffer
Function: analyzeFullBuffer()
ts
function analyzeFullBuffer(originalBuffer, options?): Promise<Tempo[]>;Defined in: core/analyzer.ts:460
Analyzes a complete audio buffer to detect the BPM (tempo) synchronously.
This function performs offline analysis of an entire audio file to detect its tempo. It's ideal for analyzing pre-recorded audio files where you have the complete audio data available.
Parameters
| Parameter | Type | Description |
|---|---|---|
originalBuffer | AudioBuffer | The AudioBuffer containing the complete audio to analyze |
options? | BiquadFilterOptions | Optional filter configuration to customize bass detection |
Returns
Promise<Tempo[]>
A promise that resolves to an array of tempo candidates sorted by confidence
Examples
Analyze an uploaded audio file
typescript
const audioContext = new AudioContext();
// Load audio file
const response = await fetch('song.mp3');
const arrayBuffer = await response.arrayBuffer();
const audioBuffer = await audioContext.decodeAudioData(arrayBuffer);
// Analyze BPM
const tempos = await analyzeFullBuffer(audioBuffer);
console.log('Detected BPM:', tempos[0].tempo);
console.log('Confidence:', tempos[0].count);
console.log('Top 5 candidates:', tempos);With custom filter settings
typescript
const audioBuffer = await audioContext.decodeAudioData(arrayBuffer);
const tempos = await analyzeFullBuffer(audioBuffer, {
frequencyValue: 150, // Focus on bass frequencies
qualityValue: 1 // Filter steepness
});
// Get the most likely BPM
const mostLikelyBPM = tempos[0].tempo;Analyze from file input
typescript
const fileInput = document.querySelector('input[type="file"]');
fileInput.addEventListener('change', async (e) => {
const file = e.target.files[0];
const arrayBuffer = await file.arrayBuffer();
const audioBuffer = await audioContext.decodeAudioData(arrayBuffer);
const tempos = await analyzeFullBuffer(audioBuffer);
if (tempos.length > 0) {
console.log(`Detected BPM: ${tempos[0].tempo} with ${tempos[0].count} matching intervals`);
}
});Remarks
- This is a synchronous/offline analysis method (analyzes complete audio at once)
- For real-time streaming audio, use createRealtimeBpmAnalyzer instead
- The function returns multiple candidates sorted by confidence (count)
- Analysis applies a lowpass filter to isolate bass frequencies for better beat detection
- BPM values are normalized to the 90-180 range (doubles/halves if outside this range)
- Higher
countvalues indicate more confidence in the detected tempo
See
- createRealtimeBpmAnalyzer for real-time streaming audio analysis
- getBiquadFilter for the lowpass filter used internally
- Tempo for the structure of returned tempo candidates
- BiquadFilterOptions for filter configuration options