Skip to content

API Reference


API Reference / analyzeFullBuffer

Function: analyzeFullBuffer() ​

ts
function analyzeFullBuffer(originalBuffer, options?): Promise<Tempo[]>;

Defined in: core/offline-pipeline.ts:176

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 ​

ParameterTypeDescription
originalBufferAudioBufferThe AudioBuffer containing the complete audio to analyze
options?AnalyzeFullBufferOptionsOptional filter configuration and tempo range

Returns ​

Promise<Tempo[]>

A promise that resolves to up to 5 tempo candidates, sorted by count

Throws ​

When options.tempoRange is invalid (see TempoRange)

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].confidence);
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;

Slow genres: report 85 instead of 170

typescript
const tempos = await analyzeFullBuffer(audioBuffer, {
  tempoRange: {min: 70, max: 140},  // max must be at least 2 × min
});

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 up to 5 candidates sorted by count (matching intervals)
  • Analysis applies a lowpass filter to isolate bass frequencies for better beat detection
  • BPM values are folded into tempoRange (default 90-180) by doubling or halving
  • confidence is the share of interval votes within ±1 BPM of the candidate

See ​