Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Contributor Guidelines

- Every code change must be accompanied by regression tests.
- Any user-reported bug signals a failure in both implementation and testing. When a bug is discovered, document the testing gap and add guidelines here to prevent similar issues in the future. This file is our living record of lessons learned and improved testing strategies; keep it updated.
8 changes: 8 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "audio-interpolator",
"version": "1.0.0",
"type": "module",
"scripts": {
"test": "node --test"
}
}
19 changes: 2 additions & 17 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@
</div>
</div>

<script>
<script type="module">
import { TARGET_SAMPLE_RATE, humanTime, clamp, bytesHuman } from './utils.js';
(() => {
// ---- Utilities -----------------------------------------------------------
const $ = (sel) => document.querySelector(sel);
Expand All @@ -106,16 +107,6 @@
let files = { A: null, B: null };
let lastBlobUrl = null;

const TARGET_SAMPLE_RATE = 44100; // Common denominator; browsers will resample if needed

function humanTime(seconds) {
if (!isFinite(seconds)) return '—';
const m = Math.floor(seconds / 60);
const s = Math.round(seconds % 60).toString().padStart(2,'0');
return `${m}:${s}`;
}
function clamp(v, lo, hi){ return Math.min(hi, Math.max(lo, v)); }

function setStatus(text, kind='info') {
statusEl.textContent = text;
statusEl.style.color = kind === 'error' ? '#ff9c9c' : kind === 'ok' ? '#8ef18e' : '#aab6c4';
Expand Down Expand Up @@ -209,12 +200,6 @@
}
});

function bytesHuman(n){
if (n < 1024) return n + ' B';
const u = ['KB','MB','GB']; let i = -1; do { n/=1024; i++; } while (n>=1024 && i<u.length-1);
return n.toFixed(n<10?2:1)+' '+u[i];
}

function suggestOutName(a, b){
function base(n){ return (n||'track').replace(/\.[^.]+$/, ''); }
return `${base(a)}__AVERAGE__${base(b)}.wav`;
Expand Down
18 changes: 18 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export const TARGET_SAMPLE_RATE = 44100; // Common denominator; browsers will resample if needed

export function humanTime(seconds) {
if (!isFinite(seconds)) return '—';
const m = Math.floor(seconds / 60);
const s = Math.round(seconds % 60).toString().padStart(2,'0');
return `${m}:${s}`;
}

export function clamp(v, lo, hi) {
return Math.min(hi, Math.max(lo, v));
}

export function bytesHuman(n){
if (n < 1024) return n + ' B';
const u = ['KB','MB','GB']; let i = -1; do { n/=1024; i++; } while (n>=1024 && i<u.length-1);
return n.toFixed(n<10?2:1)+' '+u[i];
}
18 changes: 18 additions & 0 deletions test/utils.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import { humanTime, clamp, bytesHuman } from '../src/utils.js';

test('humanTime formats seconds', () => {
assert.equal(humanTime(0), '0:00');
assert.equal(humanTime(65), '1:05');
});

test('clamp limits values', () => {
assert.equal(clamp(5, 0, 3), 3);
assert.equal(clamp(-1, 0, 3), 0);
});

test('bytesHuman converts bytes to human-readable form', () => {
assert.equal(bytesHuman(500), '500 B');
assert.equal(bytesHuman(1024), '1.00 KB');
});