Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Longer fade out sounds

I'm using the revised version of L's sound macros by The Mad Exile. The only issue I'm having with them is that 2 seconds fade out is really too ubrupt, I want it more like 6 seconds. But I can't make head nor tail of the code. Doesn't seem to be an easy "2" in there anywhere. Can anyone point out what number to change?

(function() {
"use strict";
version.extensions['soundMacros'] = {
major: 1,
minor: 2,
revision: 0
};
var p = macros['playsound'] = {
soundtracks: {},
handler: function(a, b, c, d) {
var loop = function(m) {
if (m.loop == undefined) {
m.loopfn = function() {
this.play();
};
m.addEventListener('ended', m.loopfn, 0);
} else m.loop = true;
m.play();
};
var s = eval(d.fullArgs());
if (s) {
s = s.toString();
var m = this.soundtracks[s.slice(0, s.lastIndexOf("."))];
if (m) {
if (b == "loadsound" || b == "playsound" || b == "loopsound" || b == "fadeoutsound" || b == "fadeinsound") {
if (m.readyState < HTMLAudioElement.HAVE_CURRENT_DATA) {
m.preload = "auto";
m.load();
}
}
if (b == "playsound") {
m.play();
} else if (b == "loopsound") {
loop(m);
} else if (b == "pausesound") {
m.pause();
} else if (b == "unloopsound") {
if (m.loop != undefined) {
m.loop = false;
} else if (m.loopfn) {
m.removeEventListener('ended', m.loopfn);
delete m.loopfn;
}
} else if (b == "stopsound") {
m.pause();
m.currentTime = 0;
} else if (b == "fadeoutsound" || b == "fadeinsound") {
if (m.interval) clearInterval(m.interval);
if (b == "fadeinsound") {
if (m.currentTime > 0) return;
m.volume = 0;
loop(m);
} else {
if (!m.currentTime) return;
m.play();
}
var v = m.volume;
m.interval = setInterval(function() {
v = Math.min(1, Math.max(0, v + 0.005 * (b == "fadeinsound" ? 1 : -1)));
m.volume = Math.easeInOut(v);
if (v == 0 || v == 1) clearInterval(m.interval);
if (v == 0) {
m.pause();
m.currentTime = 0;
m.volume = 1;
}
}, 10);
}
}
}
}
};
macros['loadsound'] = p;
macros['fadeinsound'] = p;
macros['fadeoutsound'] = p;
macros['unloopsound'] = p;
macros['loopsound'] = p;
macros['pausesound'] = p;
macros['stopsound'] = p;
macros['stopallsound'] = {
handler: function() {
var s = macros.playsound.soundtracks;
for (var j in s) {
if (s.hasOwnProperty(j)) {
s[j].pause();
if (s[j].currentTime) {
s[j].currentTime = 0;
}
}
}
}
};

var store = document.querySelector("tw-storydata");
if (store == null) {
store = document.querySelector("#store-area,#storeArea");
}
if (store == null) {
return false;
}
store = store.firstChild;

var fe = ["ogg", "mp3", "wav", "webm"];
while (store != null) {
var b = String.fromCharCode(92);
var q = '"';
var re = "['" + q + "]([^" + q + "']*?)" + b + ".(ogg|mp3|wav|webm)['" + q + "]";
k(new RegExp(re, "gi"));
store = store.nextSibling;
}

function k(c, e) {
do {
var d = c.exec(store.innerHTML);
if (d &amp;&amp; !macros.playsound.soundtracks.hasOwnProperty(d[1])) {
var a = new Audio();
if (a.canPlayType) {
for (var i = -1; i < fe.length; i += 1) {
if (i >= 0) d[2] = fe[i];
if (a.canPlayType("audio/" + d[2])) break;
}
if (i < fe.length) {
a.src = d[1] + "." + d[2];
a.interval = null;
macros.playsound.soundtracks[d[1]] = a;
} else console.log("Browser can't play '" + d[1] + "'");
}
}
} while (d);
}
}());

Comments

  • Well, you could modify either the volume change interval or level (you could also do both, but that's unnecessary in this case).  To best match your desired duration, it'll be easier to simply jigger the interval.

    FIND:
    }, 10);
    REPLACE WITH:
    }, 30);
    That will lengthen the change interval from every 10ms to every 30ms, which will lengthen the fade from 2s to 6s.
Sign In or Register to comment.