<commit_before>/**
 * https://webaudio.github.io/web-audio-api/#widl-AnalyserNode-getByteFrequencyData-void-Uint8Array-array
 * getByte -> value between 0 and 255.
 * getFloat -> dB
 * getTime -> waveform
 * getFrequency -> after fft https://webaudio.github.io/web-audio-api/#current-frequency-data
 * https://stackoverflow.com/questions/24083349/understanding-getbytetimedomaindata-and-getbytefrequencydata-in-web-audio
 */

/**
 * Compute the rms (root mean square) of all measured samples
 * given in array. The unit of measured samples is a byte between 0-255, (
 * mapping to (-1, 1), -1 being minDb and +1 maxDb.
 */
var i = 0;
function getRmsVolume(analyser, array) {
    analyser.getByteTimeDomainData(array);
    const length = array.length;
    let total = 0;
    for (let i = 0; i < length; i++) {
        total += array[i] * array[i];
    }
    return Math.sqrt(total / length);
}

/**
 * Return an object with the getRmsVolume method.
 */
function createAudioMeter(audioContext, mediaStreamSource) {
    var analyser = audioContext.createAnalyser();
    analyser.fftSize = 256;
    var array = new Uint8Array(analyser.frequencyBinCount);
    mediaStreamSource.connect(analyser);
    return {analyser: analyser,
            array: array,
            getRmsVolume: function () {
                return getRmsVolume(this.analyser, this.array);
            },
           };
}<commit_msg>Switch to getFloatTimeDomainData<commit_after>/**
 * https://webaudio.github.io/web-audio-api/#widl-AnalyserNode-getByteFrequencyData-void-Uint8Array-array
 * getByte -> value between 0 and 255.
 * getFloat -> dB
 * getTime -> waveform
 * getFrequency -> after fft https://webaudio.github.io/web-audio-api/#current-frequency-data
 * https://stackoverflow.com/questions/24083349/understanding-getbytetimedomaindata-and-getbytefrequencydata-in-web-audio
 */

/**
 * Compute the rms (root mean square) of all measured samples
 * given in array. The unit of measured samples is a byte between 0-255, (
 * mapping to (-1, 1), -1 being minDb and +1 maxDb.
 */
function getRmsVolume(analyser, array) {
    analyser.getFloatTimeDomainData(array);
    const length = array.length;
    let total = 0;
    for (let i = 0; i < length; i++) {
        total += array[i] * array[i];
    }
    return Math.sqrt(total / length);
}

/**
 * Return an object with the getRmsVolume method.
 */
function createAudioMeter(audioContext, mediaStreamSource) {
    var analyser = audioContext.createAnalyser();
    analyser.fftSize = 256;
    var array = new Float32Array(analyser.frequencyBinCount);
    mediaStreamSource.connect(analyser);
    return {analyser: analyser,
            array: array,
            getRmsVolume: function () {
                return getRmsVolume(this.analyser, this.array);
            },
           };
}
{'fraction_non_alphanumeric': 0.12201212986086336, 'fraction_numerical': 0.019978594363182306, 'mean_word_length': 3.154074074074074, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1949491', 'n_tokens_mistral': 912, 'n_tokens_neox': 870, 'n_words': 211}