-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
10,399 additions
and
3,646 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// This needs some refinement! | ||
|
||
class AudioNormalizerProcessor extends AudioWorkletProcessor { | ||
static get parameterDescriptors() { | ||
return [{ name: 'peakLoudness', defaultValue: -3 }]; | ||
} | ||
|
||
process(inputs, outputs, parameters) { | ||
const input = inputs[0]; | ||
const output = outputs[0]; | ||
|
||
const peakLoudness = parameters.peakLoudness[0]; | ||
|
||
for (let channel = 0; channel < input.length; ++channel) { | ||
const inputData = input[channel]; | ||
const outputData = output[channel]; | ||
|
||
// Increase buffer size | ||
const bufferSize = 1024; // Adjust as needed | ||
|
||
for (let sample = 0; sample < inputData.length; sample += bufferSize) { | ||
let maxAbsValue = 0; | ||
const endSample = Math.min(sample + bufferSize, inputData.length); | ||
|
||
for (let s = sample; s < endSample; ++s) { | ||
const absValue = Math.abs(inputData[s]); | ||
if (absValue > maxAbsValue) { | ||
maxAbsValue = absValue; | ||
} | ||
} | ||
|
||
const desiredPeak = Math.pow(10, peakLoudness / 20); // Convert dB to linear scale | ||
const scaleFactor = desiredPeak / (maxAbsValue + 1e-5); // Handle division by zero | ||
|
||
for (let s = sample; s < endSample; ++s) { | ||
outputData[s] = inputData[s] * scaleFactor; | ||
} | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
} | ||
|
||
registerProcessor('audio-normalizer-processor', AudioNormalizerProcessor); | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.