Skip to content

Commit

Permalink
WaveFileBlob: Made class variables private and updated the class meth…
Browse files Browse the repository at this point in the history
…ods to use them. Also made some minor changes to clean up the appearance of the code.

SoundRecorder.buildWavFileBlob():  Edited comment punctuation to make intent more clear.
SoundRecorder.isReady():  Renamed the eventSet flag and the console log message to be more descriptive.
  • Loading branch information
Robert Derveloy committed Sep 6, 2015
1 parent e6bbb04 commit fa195ff
Showing 1 changed file with 15 additions and 17 deletions.
32 changes: 15 additions & 17 deletions SoundRecorder.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,20 +77,19 @@ if (!Date.now)

function WavFileBlob(desiredDataView)
{
//TODO: Make these private:
this.dataBlob = new Blob ( [ desiredDataView ], { type : 'audio/wav' } );
this.NAME_PREFIX = 'output';
this.EXTENSION = '.wav';
var dataBlob = new Blob ( [ desiredDataView ], { type : 'audio/wav' } );
var NAME_PREFIX = 'output';
var EXTENSION = '.wav';

//Public methods:
this.generateFileName = function()
{
return this.generateFileNameWithoutExtension() + this.EXTENSION;
return this.generateFileNameWithoutExtension() + EXTENSION;
};

this.generateFileNameWithoutExtension = function()
{
return this.NAME_PREFIX + Date.now();
return NAME_PREFIX + Date.now();
};

this.getDataBlob = function()
Expand All @@ -106,12 +105,11 @@ function WavFileBlob(desiredDataView)
console.log("WavFileBlob->downloadLocally(): The URL is: "+url);
console.log("WavFileBlob->downloadLocally(): The file name is: "+url);

var link = window.document.createElement('a');


link.href = url;
var link = window.document.createElement('a');
link.href = url;
link.download = fileName;
link.target = "_blank";
link.target = "_blank";

//link.click(); //This does not work in firefox.

//This doesn't work with firefox either:
Expand Down Expand Up @@ -355,18 +353,18 @@ function SoundRecorder(desiredAudioContext, desiredBufferSize, desiredSampleRate
this.isReady = function()
{

var eventSet = false;
var eventHandlerSet_onaudioprocess = false;
if(this.recorder.onaudioprocess)
{
eventSet = true;
eventHandlerSet_onaudioprocess = true;
}
else
{
eventSet = false;
console.log("SoundRecorder.isReady(): Recorder onaudioprocess event not set!");
eventHandlerSet_onaudioprocess = false;
console.log("SoundRecorder.isReady(): Recorder onaudioprocess event handler is not set!");
}

return (readyFlag && eventSet);
return (readyFlag && eventHandlerSet_onaudioprocess);
};

this.stopRecording = function()
Expand Down Expand Up @@ -501,7 +499,7 @@ function SoundRecorder(desiredAudioContext, desiredBufferSize, desiredSampleRate
{
//Do nothing if not recording:
if (!this.isRecording()) return;
// Copy the data from the input buffers;
// Copy the data from the input buffers:
var left = e.inputBuffer.getChannelData (0);
var right = e.inputBuffer.getChannelData (1);
this.cloneChannelData(left, right);
Expand Down

0 comments on commit fa195ff

Please sign in to comment.