diff --git a/docs/index.html b/docs/index.html index e321e47..9064ae6 100644 --- a/docs/index.html +++ b/docs/index.html @@ -1,4 +1,4 @@ - + @@ -9,7 +9,9 @@ body { background: #eee; color: #111; - font-family: system-ui, -apple-system; + font-family: + system-ui, + -apple-system; margin: 1rem auto; max-width: 80ch; } @@ -82,11 +84,11 @@

Pitchy example

Math.round(pitch * 10) / 10 } Hz`; document.getElementById("clarity").textContent = `${Math.round( - clarity * 100 + clarity * 100, )} %`; window.setTimeout( () => updatePitch(analyserNode, detector, input, sampleRate), - 100 + 100, ); } diff --git a/docs/playground.html b/docs/playground.html index 0a83672..7680310 100644 --- a/docs/playground.html +++ b/docs/playground.html @@ -1,4 +1,4 @@ - + @@ -9,7 +9,9 @@ body { background: #eee; color: #111; - font-family: system-ui, -apple-system; + font-family: + system-ui, + -apple-system; margin: 1rem auto; max-width: 80ch; } @@ -215,7 +217,7 @@

Pitchy playground

lastClarityPercent = Math.round(lastClarityPercent * 1000) / 10; canvas.innerText = `Last pitch: ${lastPitch.toFixed( - 1 + 1, )} Hz at ${lastClarityPercent.toFixed(1)}% clarity`; const filteredPitches = filteredHistory.map(([pitch]) => pitch); @@ -238,7 +240,7 @@

Pitchy playground

`${lastPitch.toFixed(1)} Hz (${lastClarityPercent.toFixed(1)}%)`, w / 2, headingHeight / 2, - w + w, ); ctx.lineWidth = 1; @@ -270,7 +272,7 @@

Pitchy playground

`${lastPitch.toFixed(1)} Hz`, w - labelWidth, y(lastPitch), - labelWidth + labelWidth, ); } @@ -298,7 +300,7 @@

Pitchy playground

sampleRate = analyserNode = inputBuffer = null; const actualSampleRate = document.getElementById("actual-sample-rate"); const actualInputBufferSize = document.getElementById( - "actual-input-buffer-size" + "actual-input-buffer-size", ); actualSampleRate.innerText = actualInputBufferSize.innerText = "Unset"; @@ -346,7 +348,7 @@

Pitchy playground

}); const overrideSampleRateInput = document.getElementById( - "override-sample-rate" + "override-sample-rate", ); overrideSampleRateInput.addEventListener("change", () => { overrideSampleRate = overrideSampleRateInput.checked; @@ -361,7 +363,7 @@

Pitchy playground

}); const minClarityPercentInput = document.getElementById( - "min-clarity-percent" + "min-clarity-percent", ); minClarityPercentInput.addEventListener("change", () => { minClarityPercent = Number.parseFloat(minClarityPercentInput.value); diff --git a/index.js b/index.js index ed95f68..e896bde 100644 --- a/index.js +++ b/index.js @@ -39,7 +39,7 @@ export class Autocorrelator { static forFloat32Array(inputLength) { return new Autocorrelator( inputLength, - (length) => new Float32Array(length) + (length) => new Float32Array(length), ); } @@ -53,7 +53,7 @@ export class Autocorrelator { static forFloat64Array(inputLength) { return new Autocorrelator( inputLength, - (length) => new Float64Array(length) + (length) => new Float64Array(length), ); } @@ -113,7 +113,7 @@ export class Autocorrelator { autocorrelate(input, output = this._bufferSupplier(input.length)) { if (input.length !== this._inputLength) { throw new Error( - `Input must have length ${this._inputLength} but had length ${input.length}` + `Input must have length ${this._inputLength} but had length ${input.length}`, ); } // Step 0: pad the input array with zeros @@ -342,12 +342,12 @@ export class PitchDetector { // we know of at least one key maximum satisfying this condition (whichever // key maximum gave us nMax). const resultIndex = keyMaximumIndices.find( - (i) => this._nsdfBuffer[i] >= this._clarityThreshold * nMax + (i) => this._nsdfBuffer[i] >= this._clarityThreshold * nMax, ); const [refinedResultIndex, clarity] = refineResultIndex( // @ts-expect-error resultIndex is guaranteed to be defined resultIndex, - this._nsdfBuffer + this._nsdfBuffer, ); // Due to floating point errors, the clarity may occasionally come out to be diff --git a/package-lock.json b/package-lock.json index 6e54cc3..10e4db4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,7 +15,7 @@ "eslint": "^8.36.0", "http-server": "^14.1.1", "npm-run-all": "^4.1.5", - "prettier": "2.8.8", + "prettier": "3.0.3", "rimraf": "^5.0.1", "semantic-release": "^21.0.0", "typescript": "^5.0.2", @@ -7306,15 +7306,15 @@ } }, "node_modules/prettier": { - "version": "2.8.8", - "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.8.8.tgz", - "integrity": "sha512-tdN8qQGvNjw4CHbY+XXk0JgCXn9QiF21a55rBe5LJAU+kDyC4WQn4+awm2Xfk2lQMk5fKup9XgzTZtGkjBdP9Q==", + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.0.3.tgz", + "integrity": "sha512-L/4pUDMxcNa8R/EthV08Zt42WBO4h1rarVtK0K+QJG0X187OLo7l699jWw0GKuwzkPQ//jMFA/8Xm6Fh3J/DAg==", "dev": true, "bin": { - "prettier": "bin-prettier.js" + "prettier": "bin/prettier.cjs" }, "engines": { - "node": ">=10.13.0" + "node": ">=14" }, "funding": { "url": "https://github.com/prettier/prettier?sponsor=1" @@ -14251,9 +14251,9 @@ "dev": true }, "prettier": { - "version": "2.8.8", - "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.8.8.tgz", - "integrity": "sha512-tdN8qQGvNjw4CHbY+XXk0JgCXn9QiF21a55rBe5LJAU+kDyC4WQn4+awm2Xfk2lQMk5fKup9XgzTZtGkjBdP9Q==", + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.0.3.tgz", + "integrity": "sha512-L/4pUDMxcNa8R/EthV08Zt42WBO4h1rarVtK0K+QJG0X187OLo7l699jWw0GKuwzkPQ//jMFA/8Xm6Fh3J/DAg==", "dev": true }, "process-nextick-args": { diff --git a/package.json b/package.json index 7aa5eb5..a69b8c6 100644 --- a/package.json +++ b/package.json @@ -55,7 +55,7 @@ "eslint": "^8.36.0", "http-server": "^14.1.1", "npm-run-all": "^4.1.5", - "prettier": "2.8.8", + "prettier": "3.0.3", "rimraf": "^5.0.1", "semantic-release": "^21.0.0", "typescript": "^5.0.2", diff --git a/test/autocorrelator.js b/test/autocorrelator.js index 5cdfa09..256c3ea 100644 --- a/test/autocorrelator.js +++ b/test/autocorrelator.js @@ -37,11 +37,11 @@ const test = suite("Autocorrelator"); test("constructor throws an error if the input length is too small", () => { assert.throws( () => new Autocorrelator(0, (length) => new Float32Array(length)), - "Input length must be at least one" + "Input length must be at least one", ); assert.throws( () => new Autocorrelator(-5, (length) => new Float32Array(length)), - "Input length must be at least one" + "Input length must be at least one", ); }); @@ -53,7 +53,7 @@ test("autocorrelate throws an error if the input is not of the configured input const autocorrelator = Autocorrelator.forFloat32Array(5); assert.throws( () => autocorrelator.autocorrelate(Float32Array.of(1, 2, 3)), - "Input must have length 5 but had length 3" + "Input must have length 5 but had length 3", ); }); @@ -67,7 +67,7 @@ for (const bufferType of inputTypes) { const assertAutocorrelationIs = (input, expects) => { const autocorrelator = bufferType.supplier(input.length); const actual = Array.from( - autocorrelator.autocorrelate(inputType.arrayConverter(input)) + autocorrelator.autocorrelate(inputType.arrayConverter(input)), ); let match = actual.length === expects.length; @@ -81,7 +81,7 @@ for (const bufferType of inputTypes) { } if (!match) { assert.unreachable( - `expected autocorrelation of ${input} to be ${expects}, got ${actual}` + `expected autocorrelation of ${input} to be ${expects}, got ${actual}`, ); } }; @@ -92,7 +92,7 @@ for (const bufferType of inputTypes) { assertAutocorrelationIs([1, 2, 3, 4], [30, 20, 11, 4]); assertAutocorrelationIs( [1, -1, 1, -1, 1, -1, 1, -1], - [8, -7, 6, -5, 4, -3, 2, -1] + [8, -7, 6, -5, 4, -3, 2, -1], ); }); } diff --git a/test/pitch-detector.js b/test/pitch-detector.js index 3adeeaa..5559af9 100644 --- a/test/pitch-detector.js +++ b/test/pitch-detector.js @@ -105,11 +105,11 @@ const test = suite("PitchDetector"); test("constructor throws an error if the input length is too small", () => { assert.throws( () => new PitchDetector(0, (length) => new Float32Array(length)), - "Input length must be at least one" + "Input length must be at least one", ); assert.throws( () => new PitchDetector(-5, (length) => new Float32Array(length)), - "Input length must be at least one" + "Input length must be at least one", ); }); @@ -121,7 +121,7 @@ test("findPitch throws an error if the input is not of the configured input leng const detector = PitchDetector.forFloat32Array(8); assert.throws( () => detector.findPitch(Float32Array.of(1, 2, 3), 5), - "Input must have length 8 but had length 3" + "Input must have length 8 but had length 3", ); }); @@ -149,7 +149,7 @@ function runTests( amplitude, frequency, sampleRate, - windowSize + windowSize, ) { /** * @param {ArrayLike} input @@ -162,7 +162,7 @@ function runTests( }; const input = inputType.arrayConverter( - waveform.generator(windowSize, frequency, amplitude, sampleRate) + waveform.generator(windowSize, frequency, amplitude, sampleRate), ); const [pitch, clarity] = findPitch(input, sampleRate); @@ -171,18 +171,18 @@ function runTests( const percentError = (100 * Math.abs(pitch - frequency)) / frequency; assert.ok( percentError <= 1, - `expected pitch ${pitch} Hz to be within 1% of ${frequency} Hz` + `expected pitch ${pitch} Hz to be within 1% of ${frequency} Hz`, ); const centsError = Math.abs(1200 * Math.log2(pitch / frequency)); assert.ok( centsError <= waveform.maxCents, - `expected pitch ${pitch} Hz to be within ${centsError} of ${frequency} Hz` + `expected pitch ${pitch} Hz to be within ${centsError} of ${frequency} Hz`, ); assert.ok( clarity >= waveform.minClarity, - `expected clarity ${clarity} to be at least ${waveform.minClarity}` + `expected clarity ${clarity} to be at least ${waveform.minClarity}`, ); assert.ok(clarity <= 1.0, `expected clarity ${clarity} to be at most 1.0`); }); @@ -219,7 +219,7 @@ for (const waveform of waveforms) { amplitude, frequency, sampleRate, - inputSize + inputSize, ); } }