reduce channel data to an array

This commit is contained in:
Lewis Moten
2024-05-05 15:44:14 -04:00
parent 978a664cba
commit 9a5f8a3e59

View File

@@ -448,18 +448,10 @@ function collectSample() {
length, length,
streamEnded: priorStreamEnded streamEnded: priorStreamEnded
}; };
data.pairs = getChannels().map(([low, high], i) => { // Get amplitude of each channels set of frequencies
const lowAmp = frequencies[Math.round(low / length)]; data.pairs = getChannels().map(hzSet => hzSet.map(hz => frequencies[Math.round(hz / length)]));
const highAmp = frequencies[Math.round(high / length)]; const hasSignal = data.hasSignal = data.pairs.some(amps => amps.some(amp => amp > AMPLITUDE_THRESHOLD));
return {
lowAmp,
highAmp,
};
});
const hasSignal = data.hasSignal = data.pairs.some(p =>
p.lowAmp > AMPLITUDE_THRESHOLD ||
p.highAmp > AMPLITUDE_THRESHOLD
);
if(hasSignal) { if(hasSignal) {
if(hadPriorSignal) { if(hadPriorSignal) {
// continued bit stream // continued bit stream
@@ -517,25 +509,22 @@ function GET_SEGMENT_BITS(streamStarted, segmentIndex) {
f.streamStarted === streamStarted f.streamStarted === streamStarted
); );
const channelCount = frequencyOverTime[0].pairs.length; const channelCount = frequencyOverTime[0].pairs.length;
const sums = new Array(channelCount).fill(0).map(() => ({ const channelFrequencyCount = 2;
high: 0, const sums = new Array(channelCount)
low: 0, .fill(0)
heard: 0 .map(() =>
})); new Array(channelFrequencyCount)
.fill(0)
);
samples.forEach(({pairs}) => { samples.forEach(({pairs}) => {
pairs.forEach(({ highAmp, lowAmp }, channel) => { pairs.forEach((amps, channel) => {
sums[channel].high += highAmp; amps.forEach((amp, i) => {
sums[channel].low += lowAmp; sums[channel][i] += amp;
if(highAmp > AMPLITUDE_THRESHOLD || lowAmp > AMPLITUDE_THRESHOLD) { });
sums[channel].heard++; });
}
})
}); });
const bitValues = sums.map(({high, low}) => high >= low ? 1 : 0); const bitValues = sums.map((amps) => amps[0] > amps[1] ? 0 : 1);
// cut off silent bits return bitValues;
// const lastHeard = sums.lastIndexOf(s => s.heard !== 0);
const lastHeard = sums.length -1;
return bitValues.slice(0, lastHeard + 1);
} }
function processSegmentReceived(streamStarted, segmentIndex) { function processSegmentReceived(streamStarted, segmentIndex) {
const { const {
@@ -983,6 +972,7 @@ function getTimePercent(time, newest) {
return ((newest - time) / duration); return ((newest - time) / duration);
} }
function drawChannelData() { function drawChannelData() {
// return;
const canvas = document.getElementById('received-channel-graph'); const canvas = document.getElementById('received-channel-graph');
const ctx = canvas.getContext('2d'); const ctx = canvas.getContext('2d');
const {height, width} = canvas; const {height, width} = canvas;