Skip to content

Commit

Permalink
actually sounds pretty ok.
Browse files Browse the repository at this point in the history
  • Loading branch information
gricklegrass committed Jun 8, 2017
1 parent 91fbb32 commit 63e368a
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/Talk.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ let audioStream;
let audioContext;
let socket;

const bufferSize = 1024;
const sampleFrames = 22050;
const sampleRate = 22050;
const sampleRate = sampleFrames * 2;
var frameCount = 0;
var playing = false;
var audioBuffers = [];
Expand Down Expand Up @@ -87,7 +88,7 @@ function startAudioStream(relayAddr, room, encryptionKey, audio) {
audioStream = stream;
audioContext = new AudioContext();
const source = audioContext.createMediaStreamSource(audioStream);
const analyser = audioContext.createScriptProcessor(1024,1,1);
const analyser = audioContext.createScriptProcessor(bufferSize,1,1);
currentBuffer = audioContext.createBuffer(1, sampleFrames, sampleRate);

source.connect(analyser);
Expand Down Expand Up @@ -116,7 +117,7 @@ function encryptAudio(audio) {
for (var channel = 0; channel < inputBuffer.numberOfChannels; channel++) {
var inputData = inputBuffer.getChannelData(channel);

for (var sample = 0; sample < inputBuffer.length; sample++) {
for (var sample = 0; sample < bufferSize; sample++) {
// encrypt the data here
viewBuffer[sample] = inputData[sample];
}
Expand All @@ -127,11 +128,11 @@ function encryptAudio(audio) {
function decodeAudio(audioArray) {
var audioData = currentBuffer.getChannelData(0);

for (var sample = 0; sample < audioArray.length; sample++) {
for (var sample = 0; sample < bufferSize; sample++) {
// decrypt the data here
audioData[frameCount] = audioArray[sample];
frameCount++;
if(frameCount >= sampleFrames) {
if(frameCount == sampleFrames) {
frameCount = 0;
shiftAudioBuffer();
}
Expand Down

0 comments on commit 63e368a

Please sign in to comment.