send audio direct to analyzer
This commit is contained in:
@@ -12,6 +12,9 @@
|
|||||||
<div class="panels">
|
<div class="panels">
|
||||||
<div>
|
<div>
|
||||||
<h2>Message</h2>
|
<h2>Message</h2>
|
||||||
|
<label>
|
||||||
|
<input type="checkbox" id="send-via-speaker">Speakers
|
||||||
|
</label><br />
|
||||||
<input type="text" id="text-to-send">
|
<input type="text" id="text-to-send">
|
||||||
<button id="send-button">Send</button><br />
|
<button id="send-button">Send</button><br />
|
||||||
<textarea id="sent-data" rows="10" cols="40"></textarea><br />
|
<textarea id="sent-data" rows="10" cols="40"></textarea><br />
|
||||||
|
|||||||
21
index.js
21
index.js
@@ -28,6 +28,7 @@ var FREQUENCY_RESOLUTION_MULTIPLIER = 2;
|
|||||||
var SMOOTHING_TIME_CONSTANT = 0;
|
var SMOOTHING_TIME_CONSTANT = 0;
|
||||||
var HAMMING_ERROR_CORRECTION = true;
|
var HAMMING_ERROR_CORRECTION = true;
|
||||||
|
|
||||||
|
var SEND_VIA_SPEAKER = false;
|
||||||
var LAST_STREAM_STARTED;
|
var LAST_STREAM_STARTED;
|
||||||
var MINIMUM_INTERVAL_MS = 3; // DO NOT SET THIS BELOW THE BROWSERS MINIMUM "real" INTERVAL
|
var MINIMUM_INTERVAL_MS = 3; // DO NOT SET THIS BELOW THE BROWSERS MINIMUM "real" INTERVAL
|
||||||
const SAMPLING_INTERVAL_COUNT = 2;
|
const SAMPLING_INTERVAL_COUNT = 2;
|
||||||
@@ -70,6 +71,10 @@ function handleWindowLoad() {
|
|||||||
PAUSE_AFTER_END = event.target.checked;
|
PAUSE_AFTER_END = event.target.checked;
|
||||||
if(!PAUSE_AFTER_END) resumeGraph();
|
if(!PAUSE_AFTER_END) resumeGraph();
|
||||||
})
|
})
|
||||||
|
document.getElementById('send-via-speaker').checked = SEND_VIA_SPEAKER;
|
||||||
|
document.getElementById('send-via-speaker').addEventListener('input', event => {
|
||||||
|
SEND_VIA_SPEAKER = event.target.checked;
|
||||||
|
})
|
||||||
document.getElementById('frequency-resolution-multiplier').value = FREQUENCY_RESOLUTION_MULTIPLIER;
|
document.getElementById('frequency-resolution-multiplier').value = FREQUENCY_RESOLUTION_MULTIPLIER;
|
||||||
document.getElementById('frequency-resolution-multiplier').addEventListener('input', event => {
|
document.getElementById('frequency-resolution-multiplier').addEventListener('input', event => {
|
||||||
FREQUENCY_RESOLUTION_MULTIPLIER = parseInt(event.target.value);
|
FREQUENCY_RESOLUTION_MULTIPLIER = parseInt(event.target.value);
|
||||||
@@ -355,10 +360,13 @@ function sendBits(bits) {
|
|||||||
|
|
||||||
const currentTime = audioContext.currentTime + 0.1;
|
const currentTime = audioContext.currentTime + 0.1;
|
||||||
|
|
||||||
|
const destination = SEND_VIA_SPEAKER ? audioContext.destination : getAnalyser();
|
||||||
|
|
||||||
// create our oscillators
|
// create our oscillators
|
||||||
for(let i = 0; i < channelCount; i++) {
|
for(let i = 0; i < channelCount; i++) {
|
||||||
var oscillator = audioContext.createOscillator();
|
var oscillator = audioContext.createOscillator();
|
||||||
oscillator.connect(audioContext.destination);
|
|
||||||
|
oscillator.connect(destination);
|
||||||
oscillator.type = 'sawtooth';
|
oscillator.type = 'sawtooth';
|
||||||
oscillators.push(oscillator);
|
oscillators.push(oscillator);
|
||||||
}
|
}
|
||||||
@@ -706,15 +714,20 @@ function handleSendButtonClick() {
|
|||||||
EXPECTED_TEXT = text;
|
EXPECTED_TEXT = text;
|
||||||
sendBits(textToBits(text));
|
sendBits(textToBits(text));
|
||||||
}
|
}
|
||||||
|
function getAnalyser() {
|
||||||
|
if(analyser) return analyser;
|
||||||
|
analyser = audioContext.createAnalyser();
|
||||||
|
analyser.smoothingTimeConstant = SMOOTHING_TIME_CONSTANT;
|
||||||
|
analyser.fftSize = 2 ** FFT_SIZE_POWER;
|
||||||
|
return analyser;
|
||||||
|
}
|
||||||
function handleListeningCheckbox(e) {
|
function handleListeningCheckbox(e) {
|
||||||
stopGraph();
|
stopGraph();
|
||||||
var audioContext = getAudioContext();
|
var audioContext = getAudioContext();
|
||||||
function handleMicrophoneOn(stream) {
|
function handleMicrophoneOn(stream) {
|
||||||
microphoneStream = stream;
|
microphoneStream = stream;
|
||||||
microphoneNode = audioContext.createMediaStreamSource(stream);
|
microphoneNode = audioContext.createMediaStreamSource(stream);
|
||||||
analyser = audioContext.createAnalyser();
|
analyser = getAnalyser();
|
||||||
analyser.smoothingTimeConstant = SMOOTHING_TIME_CONSTANT;
|
|
||||||
analyser.fftSize = 2 ** FFT_SIZE_POWER;
|
|
||||||
microphoneNode.connect(analyser);
|
microphoneNode.connect(analyser);
|
||||||
resumeGraph();
|
resumeGraph();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user