Prepend packet with 1-based 10 bit number of byte count
This commit is contained in:
30
index.js
30
index.js
@@ -33,6 +33,7 @@ var samplesPerBit = [];
|
|||||||
var bitSampleCount = 0;
|
var bitSampleCount = 0;
|
||||||
var PAUSE = false;
|
var PAUSE = false;
|
||||||
var PAUSE_AFTER_END = true;
|
var PAUSE_AFTER_END = true;
|
||||||
|
var PACKET_SIZE_BITS = 10;
|
||||||
|
|
||||||
function handleWindowLoad() {
|
function handleWindowLoad() {
|
||||||
// grab dom elements
|
// grab dom elements
|
||||||
@@ -156,11 +157,32 @@ function getChannels() {
|
|||||||
}
|
}
|
||||||
return channels;
|
return channels;
|
||||||
}
|
}
|
||||||
function sendBits(bits) {
|
function logSent(text) {
|
||||||
|
|
||||||
// display what is being sent
|
// display what is being sent
|
||||||
sentDataTextArea.value += bits.join('') + '\n';
|
sentDataTextArea.value += text + '\n';
|
||||||
sentDataTextArea.scrollTop = sentDataTextArea.scrollHeight;
|
sentDataTextArea.scrollTop = sentDataTextArea.scrollHeight;
|
||||||
|
}
|
||||||
|
function sendBits(bits) {
|
||||||
|
const byteCount = bits.length / 8;
|
||||||
|
if(bits.length === 0) {
|
||||||
|
logSent('No bits to send!');
|
||||||
|
return;
|
||||||
|
} else if(bits.length % 8 !== 0 || bits.length === 0) {
|
||||||
|
logSent('Bit count must be divisible by 8.');
|
||||||
|
return;
|
||||||
|
} else if(byteCount > (1 << PACKET_SIZE_BITS)) {
|
||||||
|
logSent(`Can not transfer more than ${(1 << PACKET_SIZE_BITS)} bytes.`);
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
logSent(bits.join(''));
|
||||||
|
}
|
||||||
|
|
||||||
|
const packetLength = ((byteCount - 1) >>> 0)
|
||||||
|
.toString(2)
|
||||||
|
.padStart(PACKET_SIZE_BITS, '0')
|
||||||
|
.split('')
|
||||||
|
.map(Number);
|
||||||
|
bits.unshift(...packetLength);
|
||||||
|
|
||||||
var audioContext = getAudioContext();
|
var audioContext = getAudioContext();
|
||||||
const channels = getChannels();
|
const channels = getChannels();
|
||||||
@@ -316,7 +338,7 @@ function processBitsReceived() {
|
|||||||
bits.forEach(({pairs}) => {
|
bits.forEach(({pairs}) => {
|
||||||
pairs.forEach(({ isHigh, isMissing }, i) => {
|
pairs.forEach(({ isHigh, isMissing }, i) => {
|
||||||
if(isHigh) channels[i].isHigh ++;
|
if(isHigh) channels[i].isHigh ++;
|
||||||
else if(isMissing) channels[i].isMissing ++;
|
// else if(isMissing) channels[i].isMissing ++;
|
||||||
else channels[i].isLow++;
|
else channels[i].isLow++;
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user