PageSourceSearch

https://speakworldlanguages.github.io/js_reusables/js_for_mic_input_vis_web_worker.js

js speakworldlanguages.github.io collected 2026-10-03 09:59:01 UTC 2,054 bytes, 51 lines download raw bytes

1"use strict";
2// Code written by Manheart Earthman=B. A. Bilgekılınç Topraksoy=土本 智一勇夫剛志
3// This file MAY NOT BE MODIFIED WITHOUT CONSENT i.e. OFFICIAL AUTHORIZATION
4
5// This is js_for_mic_input_vis_web_worker.js
6
7let startIndex, endIndex; // High-pass & low-pass frequency limits (already converted to array indexes)
8
9self.onmessage = function (event) {
10  const { data, task } = event.data;
11
12  if (task === 'filterAndCalculate') {
13    const result = processDataForArray(data);
14    self.postMessage({ type: 'dataAvailable', yield: result });
15  } else if (task === 'setStartIndexAndEndIndex') { // High-pass Low-pass limits
16    const result = data;
17    console.log("start index in worker = " + result[0]); // Works OK
18    console.log("end index in worker = " + result[1]); // Works OK
19    startIndex = result[0];
20    endIndex = result[1];
21  } else {
22    // Handle unknown identifier or provide an error response
23    self.postMessage({ type: 'error', whichIs: 'Unknown task name' });
24  }
25};
26
27// The threshold of minimum is a fixed value, so we don't need » let volumeMeterFloor=10;
28let volumeMeterCeiling=40; // Starting values
29let frameCounter = 0;
30// ---
31function processDataForArray(fromAnalyserUint8Array) {
32  const filteredDataArray = fromAnalyserUint8Array.slice(startIndex, endIndex);
33  const sum = filteredDataArray.reduce((acc, val) => acc + val, 0);
34  const averageAmplitude = (sum / filteredDataArray.length / 256)*100; // Normalize to 0-100
35
36  if (volumeMeterCeiling<averageAmplitude) {
37    volumeMeterCeiling++;
38    self.postMessage({ type: 'adjust', newCeiling: volumeMeterCeiling });
39  } else if (volumeMeterCeiling>40) {
40    frameCounter++;
41    if (frameCounter>90) { // When RAF runs at 60 fps «90» will take one and a half seconds for one decrement and «120» will take two seconds
42      volumeMeterCeiling--;
43      self.postMessage({ type: 'adjust', newCeiling: volumeMeterCeiling });
44      frameCounter = 0;
45    }
46  }
47  return averageAmplitude;
48}
49
50
51self.postMessage({ type: 'ready', say: 'ready to calculate' });

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.