Skip to content

Commit

Permalink
Added default parameters to PlayTone
Browse files Browse the repository at this point in the history
  • Loading branch information
spuulis committed Jan 13, 2020
1 parent bf23dcf commit 38b2d48
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions scripts/play.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,23 @@
var actx = new AudioContext();
var sampleRate = actx.sampleRate;

function defaultize(prms) {
if(prms.frequency == undefined) {
prms.frequency = [];
}
if(prms.duration == undefined) {
prms.duration = 1;
}
if(prms.instrument == undefined) {
prms.instrument = harmonicTone;
}

return prms;
}

function playTone(prms) {
prms = defaultize(prms);

var duration = prms.duration * sampleRate;
var numChannels = 1;
var buffer = actx.createBuffer(numChannels, duration, sampleRate);
Expand Down

0 comments on commit 38b2d48

Please sign in to comment.