mirror of
https://github.com/cnlohr/lolra.git
synced 2026-06-15 07:19:25 +00:00
Add shim to add sound
This commit is contained in:
@@ -89,7 +89,7 @@ int32_t g_goertzel_coefficient = -1453756170;
|
||||
int32_t g_goertzel_coefficient_s = 1580594514;
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
#if 1
|
||||
int g_pwm_period = (30-1);
|
||||
int g_goertzel_buffer = (180);
|
||||
int32_t g_goertzel_omega_per_sample = 5509657063; // 0.816667 of whole per step / 0.880000MHz
|
||||
@@ -105,7 +105,7 @@ const int32_t g_goertzel_coefficient = 32748822;
|
||||
const int32_t g_goertzel_coefficient_s = 2147233926;
|
||||
#endif
|
||||
|
||||
#if 1
|
||||
#if 0
|
||||
int g_pwm_period = (30-1);
|
||||
int g_goertzel_buffer = (576);
|
||||
int32_t g_goertzel_omega_per_sample = 1264972285; // 0.187500 of whole per step / 90.300000MHz
|
||||
|
||||
@@ -227,7 +227,7 @@ function onLoad()
|
||||
<TD VALIGN=TOP>
|
||||
|
||||
Live Control:
|
||||
<TABLE><TR><TD><INPUT TYPE=SUBMIT onClick="reqConnect()" VALUE="Open Device" ID=connectButton></TD><TD><DIV ID=STATUS></DIV></TD></TR></TABLE>
|
||||
<TABLE><TR><TD><INPUT TYPE=SUBMIT onClick="reqConnect()" VALUE="Open Device" ID=connectButton><INPUT TYPE=SUBMIT onClick="toggleAudio()" VALUE="Play Audio" ID="ToggleAudio"></TD><TD><DIV ID=STATUS></DIV></TD></TR></TABLE>
|
||||
<DIV ID="StatusPerf"></DIV>
|
||||
</TD>
|
||||
|
||||
|
||||
@@ -58,6 +58,77 @@ async function closeDeviceTool()
|
||||
setStatusError( "Disconnected" );
|
||||
}
|
||||
|
||||
|
||||
|
||||
async function toggleAudio()
|
||||
{
|
||||
var bypass = '\
|
||||
class PlayingAudioProcessor extends AudioWorkletProcessor {\
|
||||
static get parameterDescriptors() {\
|
||||
return [\
|
||||
{\
|
||||
name: "ingestRate",\
|
||||
defaultValue: 25000,\
|
||||
minValue: 1,\
|
||||
maxValue: 1000000\
|
||||
},\
|
||||
]\
|
||||
};\
|
||||
constructor() {\
|
||||
super();\
|
||||
this.port.onmessage = (e) => {\
|
||||
console.log(e.data);\
|
||||
this.ingestData = e.data;\
|
||||
};\
|
||||
this.ingestData = new ArrayBuffer(0);\
|
||||
}\
|
||||
\
|
||||
process(inputs, outputs, parameters) {\
|
||||
/*console.log( parameters.ingestRate[0] );*/ \
|
||||
/*console.log( this.ingestData );*/ \
|
||||
let len = outputs[0][0].length; \
|
||||
for (let b = 0|0; b < len|0; b++) { \
|
||||
outputs[0][0][b] = Math.random()*0.01; \
|
||||
} \
|
||||
return true; \
|
||||
} \
|
||||
} \
|
||||
\
|
||||
registerProcessor("playing-audio-processor", PlayingAudioProcessor);';
|
||||
|
||||
// The following mechanism does not work on Chrome.
|
||||
// const dataURI = URL.createObjectURL( new Blob([bypass], { type: 'text/javascript', } ) );
|
||||
|
||||
|
||||
// Extremely tricky trick to side-step local file:// CORS issues.
|
||||
// https://stackoverflow.com/a/67125196/2926815
|
||||
// https://stackoverflow.com/a/72180421/2926815
|
||||
let blob = new Blob([bypass], {type: 'application/javascript'});
|
||||
let reader = new FileReader();
|
||||
await reader.readAsDataURL(blob);
|
||||
let dataURI = await new Promise((res) => {
|
||||
reader.onloadend = function () {
|
||||
res(reader.result);
|
||||
}
|
||||
});
|
||||
|
||||
var audioContext = new AudioContext();
|
||||
|
||||
await audioContext.audioWorklet.addModule(dataURI);
|
||||
|
||||
PlayingAudioProcessor = new AudioWorkletNode(
|
||||
audioContext,
|
||||
"playing-audio-processor"
|
||||
);
|
||||
PlayingAudioProcessor.connect(audioContext.destination);
|
||||
audioContext.resume();
|
||||
|
||||
let testParam = PlayingAudioProcessor.parameters.get("ingestRate");
|
||||
testParam.setValueAtTime(1000, audioContext.currentTime);
|
||||
|
||||
PlayingAudioProcessor.port.postMessage( new ArrayBuffer(0) );
|
||||
}
|
||||
|
||||
function onLoadWebHidControl()
|
||||
{
|
||||
liveGraph = document.getElementById( "LiveGraph" );
|
||||
@@ -174,7 +245,7 @@ async function sendLoop()
|
||||
receiveReport = dev.receiveFeatureReport( 0xAD ).catch( sendLoopError );
|
||||
if( !receiveReport ) sendLoopError( "error creating receiveReport" );
|
||||
|
||||
frameNo++;
|
||||
frameNo++
|
||||
|
||||
const updateStatsPerfPer = 4;
|
||||
if( frameNo % updateStatsPerfPer == 0 )
|
||||
|
||||
Reference in New Issue
Block a user