Fix gapless playback on Chrome, improve gapless on Firefox

serial
William Toohey 10 years ago
parent 5fdb8b0204
commit 3f021f5542
  1. 25
      js/ResourcePack.js
  2. 30
      js/SoundManager.js

@ -181,6 +181,16 @@ Respack.prototype.parseImage = function(file) {
Respack.prototype.parseXML = function() { Respack.prototype.parseXML = function() {
var that = this; var that = this;
if (this._infoFile) {
this._infoFile.getText(function(text) {
text = text.replace(/&/g, '&');
text = text.replace(/&/g, '&');
that.parseInfoFile(text);
that._infoFile = null;
that.parseXML();
});
return;
}
if (this.songs.length > 0) { if (this.songs.length > 0) {
if (this._songFile) { if (this._songFile) {
this._songFile.getText(function(text) { this._songFile.getText(function(text) {
@ -209,16 +219,6 @@ Respack.prototype.parseXML = function() {
}); });
return; return;
} }
if (this._infoFile) {
this._infoFile.getText(function(text) {
text = text.replace(/&/g, '&');
text = text.replace(/&/g, '&');
that.parseInfoFile(text);
that._infoFile = null;
that.parseXML();
});
return;
}
// Finally done! // Finally done!
this.file = null; this.file = null;
@ -287,6 +287,11 @@ Respack.prototype.parseSongFile = function(text) {
song.buildupRhythm = el.getTag("buildupRhythm"); song.buildupRhythm = el.getTag("buildupRhythm");
song.source = el.getTag("source"); song.source = el.getTag("source");
// Because PackShit breaks everything
console.log(this.name);
if(this.name == "PackShit") {
song.forceTrim = true;
}
newSongs.push(song); newSongs.push(song);
debug(" [I] " + song.name, ": '" + song.title + "' added to songs"); debug(" [I] " + song.name, ": '" + song.title + "' added to songs");
} else { } else {

@ -19,7 +19,8 @@
* THE SOFTWARE. * THE SOFTWARE.
*/ */
var LAME_DELAY_START = 2258; // Flash value + MAGIC WEB VALUE
var LAME_DELAY_START = 2258 + 1534;
var LAME_DELAY_END = 1000; var LAME_DELAY_END = 1000;
function SoundManager(core) { function SoundManager(core) {
@ -196,9 +197,9 @@ SoundManager.prototype.getAudioCallback = function(song, isBuild) {
return; return;
} }
if(isBuild) { if(isBuild) {
that.tmpBuild = that.trimMP3(buffer); that.tmpBuild = that.trimMP3(buffer, song.forceTrim);
} else { } else {
that.tmpBuffer = that.trimMP3(buffer); that.tmpBuffer = that.trimMP3(buffer, song.forceTrim);
} }
that.onSongLoad(song); that.onSongLoad(song);
}; };
@ -225,19 +226,26 @@ SoundManager.prototype.onSongLoad = function(song) {
} }
// because MP3 is bad, we nuke silence // because MP3 is bad, we nuke silence
SoundManager.prototype.trimMP3 = function(buffer) { SoundManager.prototype.trimMP3 = function(buffer, forceTrim) {
/*var isFirefox = navigator.userAgent.toLowerCase().indexOf('firefox') > -1; // Firefox has to trim always, Chrome only on PackShit
if(!isFirefox) { var isFirefox = navigator.userAgent.toLowerCase().indexOf('firefox') > -1;
// Webkit is better than Gecko, clearly // forceTrim is because PackShit breaks everything
if(!(isFirefox || forceTrim)) {
return buffer; return buffer;
}*/ }
var ret = this.context.createBuffer(buffer.numberOfChannels, var start = LAME_DELAY_START;
buffer.length - LAME_DELAY_START - LAME_DELAY_END, buffer.sampleRate); var newLength = buffer.length - LAME_DELAY_START - LAME_DELAY_END;
if(forceTrim && !isFirefox) {
// yes, really
newLength -= 1200;
start += 1200;
}
var ret = this.context.createBuffer(buffer.numberOfChannels, newLength, buffer.sampleRate);
for(var i=0; i<buffer.numberOfChannels; i++) { for(var i=0; i<buffer.numberOfChannels; i++) {
var oldBuf = buffer.getChannelData(i); var oldBuf = buffer.getChannelData(i);
var newBuf = ret.getChannelData(i); var newBuf = ret.getChannelData(i);
for(var j=0; j<ret.length; j++) { for(var j=0; j<ret.length; j++) {
newBuf[j] = oldBuf[LAME_DELAY_START + j]; newBuf[j] = oldBuf[start + j];
} }
} }
return ret; return ret;

Loading…
Cancel
Save