mirror of
https://github.com/ggerganov/ggwave.git
synced 2026-03-27 06:18:59 +08:00
r2t2 - Transmit data through the PC speaker (#32)
* inital implementation * remove file * ggwave-cli : txProtocol -> txProtocolId * ggwave : add custom protocol enum values * r2t2 : use cutom protocols * r2t2 : build only on Unix systems * r2t2 : remove thread * r2t2-rx : wip * r2t2 : wasm build ready + various fixes * r2t2 : error message * Update README.md * Update README.md * Update README.md * Update README.md * r2t2 : length 16 * r2t2 : use slow protocol by default * r2t2 : add timestamp * r2t2 : update html * r2t2 : update github link * r2t2 : more robust tx * r2t2 : add option to use beep command * emscripten : cannot use requestAnimationFrame when capturing audio This causes the queued audio buffer to grow indefinitely when the page is not focused, causing the process to run out of memory. * r2t2 : disable beep option * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * r2t2 : add example to README
This commit is contained in:
55
examples/r2t2/main.js
Normal file
55
examples/r2t2/main.js
Normal file
@@ -0,0 +1,55 @@
|
||||
function transmitText(sText) {
|
||||
var r = new Uint8Array(256);
|
||||
for (var i = 0; i < sText.length; ++i) {
|
||||
r[i] = sText.charCodeAt(i);
|
||||
}
|
||||
|
||||
var buffer = Module._malloc(256);
|
||||
Module.writeArrayToMemory(r, buffer, 256);
|
||||
Module._sendData(sText.length, buffer, protocolId, volume);
|
||||
Module._free(buffer);
|
||||
}
|
||||
|
||||
var firstTimeFail = false;
|
||||
var peerInfo = document.querySelector('a#peer-info');
|
||||
|
||||
function updatePeerInfo() {
|
||||
if (typeof Module === 'undefined') return;
|
||||
var framesLeftToRecord = Module._getFramesLeftToRecord();
|
||||
var framesToRecord = Module._getFramesToRecord();
|
||||
var framesLeftToAnalyze = Module._getFramesLeftToAnalyze();
|
||||
var framesToAnalyze = Module._getFramesToAnalyze();
|
||||
|
||||
if (framesToAnalyze > 0) {
|
||||
peerInfo.innerHTML=
|
||||
"Analyzing Rx data: <progress value=" + (framesToAnalyze - framesLeftToAnalyze) +
|
||||
" max=" + (framesToRecord) + "></progress>";
|
||||
peerReceive.innerHTML= "";
|
||||
} else if (framesLeftToRecord > Math.max(0, 0.05*framesToRecord)) {
|
||||
firstTimeFail = true;
|
||||
peerInfo.innerHTML=
|
||||
"Transmission in progress: <progress value=" + (framesToRecord - framesLeftToRecord) +
|
||||
" max=" + (framesToRecord) + "></progress>";
|
||||
} else if (framesToRecord > 0) {
|
||||
peerInfo.innerHTML= "Analyzing Rx data ...";
|
||||
} else if (framesToRecord == 0) {
|
||||
peerInfo.innerHTML= "<p>Listening for waves ...</p>";
|
||||
} else if (framesToRecord == -1) {
|
||||
if (firstTimeFail) {
|
||||
playSound("/media/case-closed");
|
||||
firstTimeFail = false;
|
||||
}
|
||||
peerInfo.innerHTML= "<p style=\"color:red\">Failed to decode Rx data</p>";
|
||||
}
|
||||
}
|
||||
|
||||
function updateRx() {
|
||||
if (typeof Module === 'undefined') return;
|
||||
Module._getText(bufferRx);
|
||||
var result = "";
|
||||
for (var i = 0; i < 140; ++i){
|
||||
result += (String.fromCharCode((Module.HEAPU8)[bufferRx + i]));
|
||||
brx[i] = (Module.HEAPU8)[bufferRx + i];
|
||||
}
|
||||
document.getElementById('rxData').innerHTML = result;
|
||||
}
|
||||
Reference in New Issue
Block a user