Skip to content

Commit f9630db

Browse files
committed
Restructure SoundEffect classes a little
1 parent 055f289 commit f9630db

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
setTimeout(function () {
5151
var audio = new Audio();
5252
if (!noregen) {
53-
SOUND = new SoundEffectByUI(PARAMS).generate();
53+
SOUND = new SoundEffect(PARAMS).generate();
5454
$("#file_size").text(Math.round(SOUND.wav.length / 1024) + "kB");
5555
$("#num_samples").text(SOUND.header.subChunk2Size /
5656
(SOUND.header.bitsPerSample >> 3));

sfxr.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -639,8 +639,15 @@ Params.prototype.tone = function () {
639639

640640

641641

642-
function SoundEffectByUI(ps) {
642+
function SoundEffect(ps) {
643+
if (ps.oldParams)
644+
this.initFromUI(ps);
645+
else
646+
this.init(ps);
647+
}
643648

649+
650+
SoundEffect.prototype.initFromUI = function (ps) {
644651
//
645652
// Convert user-facing parameter values to units usable by the sound
646653
// generator
@@ -716,8 +723,7 @@ function SoundEffectByUI(ps) {
716723

717724

718725

719-
function SoundEffect(ps) {
720-
726+
SoundEffect.prototype.init = function (ps) {
721727
//
722728
// Convert user-facing parameter values to units usable by the sound
723729
// generator
@@ -781,8 +787,7 @@ function SoundEffect(ps) {
781787
}
782788

783789

784-
SoundEffectByUI.prototype.generate =
785-
SoundEffect.prototype.generate = function () {
790+
SoundEffect.prototype.generate = function () {
786791
var fltp = 0;
787792
var fltdp = 0;
788793
var fltphp = 0;
@@ -1010,7 +1015,6 @@ if (typeof exports !== 'undefined') {
10101015
exports.Params = Params;
10111016
exports.Knobs = Knobs;
10121017
exports.SoundEffect = SoundEffect;
1013-
exports.SoundEffectByUI = SoundEffectByUI;
10141018
exports.SQUARE = SQUARE;
10151019
exports.SAWTOOTH = SAWTOOTH;
10161020
exports.SINE = SINE;

test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ function diff(a, b, title) {
3131
}
3232

3333

34-
//var sound = new sfxr.SoundEffectByUI((new sfxr.Params()).tone()).generate();
34+
//var sound = new sfxr.SoundEffect((new sfxr.Params()).tone()).generate();
3535
/*
3636
var knobs = new sfxr.Knobs({
3737
shape: sfxr.SAWTOOTH,
@@ -53,7 +53,7 @@ console.log("\nKNOBS FOR IT\n");
5353
dump(new sfxr.Knobs().tone());
5454
5555
console.log("\nPARAMS TONE\n")
56-
dump(b = new sfxr.SoundEffectByUI(new sfxr.Params().tone()));
56+
dump(b = new sfxr.SoundEffect(new sfxr.Params().tone()));
5757
5858
console.log("\nPARAMS FOR IT\n")
5959
dump(new sfxr.Params().tone());
@@ -70,7 +70,7 @@ require("fs").writeFile("./test.wav", new Buffer(sound.wav), 'binary',
7070
if(err) {
7171
sys.puts(err);
7272
} else {
73-
sys.puts("The file was saved!");
73+
sys.puts("test.wav saved!");
7474
}
7575
});
7676

0 commit comments

Comments
 (0)