Sample Rate Calculator

Sample Rate & Audio Data Calculator .src-wrapper { max-width: 800px; margin: 0 auto; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; background: #fff; padding: 20px; border-radius: 8px; box-shadow: 0 2px 10px rgba(0,0,0,0.1); } .src-calculator-container { background-color: #f8f9fa; padding: 25px; border-radius: 8px; border: 1px solid #e9ecef; margin-bottom: 30px; } .src-tabs { display: flex; margin-bottom: 20px; border-bottom: 2px solid #ddd; } .src-tab { padding: 10px 20px; cursor: pointer; font-weight: 600; color: #555; border-bottom: 2px solid transparent; margin-bottom: -2px; } .src-tab.active { color: #007bff; border-bottom: 2px solid #007bff; } .src-input-group { margin-bottom: 15px; } .src-label { display: block; margin-bottom: 5px; font-weight: 600; color: #333; } .src-input { width: 100%; padding: 10px; border: 1px solid #ccc; border-radius: 4px; font-size: 16px; box-sizing: border-box; } .src-row { display: flex; gap: 15px; flex-wrap: wrap; } .src-col { flex: 1; min-width: 200px; } .src-btn { background-color: #007bff; color: white; border: none; padding: 12px 20px; font-size: 16px; border-radius: 4px; cursor: pointer; width: 100%; margin-top: 10px; transition: background 0.3s; } .src-btn:hover { background-color: #0056b3; } .src-result-box { margin-top: 20px; padding: 20px; background-color: #e8f4fd; border-left: 5px solid #007bff; border-radius: 4px; display: none; } .src-result-item { margin-bottom: 10px; font-size: 18px; } .src-result-label { font-weight: bold; color: #444; } .src-value { color: #007bff; font-weight: 700; } .src-content h2 { color: #2c3e50; border-bottom: 2px solid #eee; padding-bottom: 10px; margin-top: 30px; } .src-content p { line-height: 1.6; color: #444; margin-bottom: 15px; } .src-content ul { margin-bottom: 20px; padding-left: 20px; } .src-content li { margin-bottom: 8px; color: #444; } .src-info-box { background: #fff3cd; border: 1px solid #ffeeba; padding: 15px; border-radius: 4px; color: #856404; margin-bottom: 20px; } /* Tab logic styles */ #calc-section-size { display: block; } #calc-section-nyquist { display: none; }

Audio Sample Rate & File Size Calculator

File Size & Bitrate
Nyquist Frequency
44,100 Hz (CD Audio) 48,000 Hz (Video standard) 88,200 Hz 96,000 Hz (High-Res) 192,000 Hz (Ultra High-Res) Custom
16-bit (CD Standard) 24-bit (Studio Standard) 32-bit Float
1 (Mono) 2 (Stereo) 6 (5.1 Surround)
Bit Rate: 0 kbps
File Size (Uncompressed): 0 MB
*Calculation applies to uncompressed PCM audio (WAV/AIFF).
Determine the minimum Sample Rate required to capture a specific frequency without aliasing errors.
Human hearing typically tops out at 20,000 Hz.
Required Sample Rate: 0 Hz
This allows for a safety margin of 0 Hz above the theoretical minimum.

Understanding Audio Sample Rate

The sample rate is a fundamental concept in digital audio processing that defines how many times per second an analog audio signal is measured (sampled) to create a digital representation. Measured in Hertz (Hz) or Kilohertz (kHz), the sample rate directly influences the frequency range that can be accurately captured and reproduced.

Common sample rates include 44.1 kHz (standard for CDs) and 48 kHz (standard for video production). This calculator helps engineers, audiophiles, and developers determine the data requirements and theoretical limits of their digital audio projects.

The Nyquist-Shannon Sampling Theorem

To accurately digitize a sound, the sample rate must be at least twice the highest frequency in the audio signal. This rule is known as the Nyquist Theorem.

  • Highest Frequency ($f_{max}$): The highest pitch you want to record. For human hearing, this is generally 20,000 Hz (20 kHz).
  • Nyquist Rate: The minimum sample rate required, calculated as $2 \times f_{max}$.
  • Aliasing: If the sample rate is too low (below the Nyquist rate), high frequencies will be misinterpreted as lower frequencies, causing distortion known as aliasing.

For example, to capture up to 20,000 Hz, you need a sample rate of at least 40,000 Hz. The CD standard of 44,100 Hz provides a small buffer (guard band) above this theoretical minimum to allow for anti-aliasing filters to work effectively.

Calculating Audio File Size

Uncompressed audio files (like WAV or AIFF) consume storage space based on a linear relationship between duration, sample rate, bit depth, and channel count. Understanding this formula is crucial for estimating disk space requirements for recording sessions.

Formula:
File Size (bits) = Sample Rate × Bit Depth × Channels × Duration (seconds)
File Size (Bytes) = File Size (bits) / 8

Inputs explained:

  • Sample Rate: The number of snapshots taken per second (e.g., 48,000).
  • Bit Depth: The dynamic range or resolution of each sample (e.g., 16-bit or 24-bit). Higher bit depth lowers the noise floor.
  • Channels: Mono = 1, Stereo = 2. Each channel multiplies the data requirement.

Bitrate vs. Sample Rate

While sample rate determines the frequency response, Bitrate refers to the amount of data processed per second. It is usually measured in kilobits per second (kbps).

For uncompressed audio: Bitrate = Sample Rate × Bit Depth × Channels.
For example, a stereo CD track (44.1 kHz, 16-bit) has a bitrate of approximately 1,411 kbps.

// Toggle Custom Input visibility var sampleRateSelect = document.getElementById('src_sample_rate'); var customRateInput = document.getElementById('src_custom_rate'); sampleRateSelect.onchange = function() { if (this.value === 'custom') { customRateInput.style.display = 'block'; customRateInput.focus(); } else { customRateInput.style.display = 'none'; } }; // Tab Switching Logic function switchTab(tabName) { var tabSize = document.getElementById('tab-size'); var tabNyquist = document.getElementById('tab-nyquist'); var sectionSize = document.getElementById('calc-section-size'); var sectionNyquist = document.getElementById('calc-section-nyquist'); if (tabName === 'size') { tabSize.classList.add('active'); tabNyquist.classList.remove('active'); sectionSize.style.display = 'block'; sectionNyquist.style.display = 'none'; } else { tabSize.classList.remove('active'); tabNyquist.classList.add('active'); sectionSize.style.display = 'none'; sectionNyquist.style.display = 'block'; } } // Logic: Calculate File Size and Bitrate function calculateFileSize() { // Get Sample Rate var rateVal = document.getElementById('src_sample_rate').value; var sampleRate = 0; if (rateVal === 'custom') { sampleRate = parseFloat(document.getElementById('src_custom_rate').value); } else { sampleRate = parseFloat(rateVal); } // Get other inputs var bitDepth = parseFloat(document.getElementById('src_bit_depth').value); var channels = parseFloat(document.getElementById('src_channels').value); var min = parseFloat(document.getElementById('src_dur_min').value) || 0; var sec = parseFloat(document.getElementById('src_dur_sec').value) || 0; // Validation if (isNaN(sampleRate) || sampleRate <= 0) { alert("Please enter a valid Sample Rate."); return; } // Total seconds var totalDuration = (min * 60) + sec; if (totalDuration 1073741824) { // GB var gb = totalBytes / (1024 * 1024 * 1024); sizeDisplay = gb.toFixed(2) + " GB"; } else { // MB var mb = totalBytes / (1024 * 1024); sizeDisplay = mb.toFixed(2) + " MB"; } // Display Results document.getElementById('res_bitrate').innerText = Math.round(bitrateKbps).toLocaleString() + " kbps"; document.getElementById('res_filesize').innerText = sizeDisplay; document.getElementById('src-result-size').style.display = 'block'; } // Logic: Calculate Nyquist function calculateNyquist() { var inputFreq = parseFloat(document.getElementById('src_target_freq').value); if (isNaN(inputFreq) || inputFreq <= 0) { alert("Please enter a valid frequency in Hz."); return; } // Nyquist is exactly 2x var theoreticalMin = inputFreq * 2; // Recommended usually adds a buffer (e.g. 10% or standard steps). // For this calculator, we show the strict math but mention standard. // Let's suggest 2.2x as a safe "real world" implementation buffer often used in filter design discussion var safeBuffer = theoreticalMin * 1.1; document.getElementById('res_nyquist').innerText = theoreticalMin.toLocaleString() + " Hz"; // Calculate margin used by CD quality (44100) if input is 20000 var margin = 0; if(theoreticalMin < 44100) { margin = 44100 – theoreticalMin; } document.getElementById('res_margin').innerText = (theoreticalMin * 0.1).toFixed(0); // Displaying a 10% buffer recommendation text context // Update the margin text to be dynamic based on result document.getElementById('src-result-nyquist').innerHTML = `
Theoretical Minimum Sample Rate: ${theoreticalMin.toLocaleString()} Hz
Recommended (with safety buffer): ${Math.ceil(safeBuffer).toLocaleString()} Hz
To capture ${inputFreq.toLocaleString()} Hz perfectly, you must sample at least ${theoreticalMin.toLocaleString()} times per second.
`; document.getElementById('src-result-nyquist').style.display = 'block'; }

Leave a Comment