-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is MP3 interleaving different than WAV? #20
Comments
I created a minimum code that produces the mentioned effect. It is running in Electron var $=require("jquery");
var load = require('audio-loader');
var WaveSurfer = require('wavesurfer.js');
load('./test-media/megaman.mp3').then(function (audioBuffer) {
var $el=$('<div class="wavesurfer"></div>');
$el.appendTo('body');
var DOM_el=$el[0];
let self=this;
const wavesurfer = WaveSurfer.create({
container: DOM_el,
waveColor: 'violet',
progressColor: 'purple',
splitChannels:true,
});
wavesurfer.loadDecodedBuffer(audioBuffer);
}); Also, super sketchy code, but this would re-build the mp3 files back in order var audioBufferUtils=require('audio-buffer-utils');
var reInterleave=true;
//rebuild audioBuffer
if(reInterleave){
var channelCount=audioBuffer.numberOfChannels;
var interleavedArray=[];
for(var channelN=0; channelN < channelCount; channelN++){
var samples=audioBuffer.getChannelData(channelN);
for(var spln=0; spln<samples.length; spln++){
interleavedArray.push(samples[spln]);
}
}
var deinterleavedArray=[];
for(var spln =0; spln < interleavedArray.length; spln += channelCount){
for(var ch=0; ch<channelCount; ch++){
if(!deinterleavedArray[ch])deinterleavedArray[ch]=[];
deinterleavedArray[ch].push(interleavedArray[spln+ch]);
}
}
console.log(deinterleavedArray);
var reInterleavedAudioBuffer=audioBufferUtils.create(deinterleavedArray,channelCount,audioBuffer.sampleRate);
audioBuffer=reInterleavedAudioBuffer;
console.log(audioBuffer);
} audioBuffer being, of course the same as in the example code (the provided parameter in the .then callback) |
I just realized that it is not loading the entire file, but only half of it. Anyone knows why this could be happening? |
@autotel Did you ever solve this? I just started using I can't tell yet if this is a problem with the loader, decoder, or player, but I suspect the problem is not with the player. |
I cannot be sure this is not a problem actually with the wavesurfer.js library I am using, or something with my usage of the audio-loader library.
I created one same audio file, and encoded it into WAV and into MP3 aswell. Then loaded it using:
When I load a WAV file, it displays and plays fine. Here the output with a test wav file:
![interleaving-problem-wav](https://user-images.githubusercontent.com/15053243/53243555-ebd10980-36b0-11e9-8781-83eefdaeaa59.PNG)
When I load an MP3 file, however, the file sounds one octave lower (I would guess), I presume it is interleaving channels that are actually present one after another.
![interleaving-problem-mp3](https://user-images.githubusercontent.com/15053243/53243642-479b9280-36b1-11e9-99a5-530f0b59302b.PNG)
The same audio, loaded as MP3:
If I load a musical track, I get the track, playing at half speed, with some artifacts, and the first half of the track is playing on one speaker while the second half is playing from the other speaker. The reported length, sampleRate and numberOfChannels is nearly the same when loading MP3 than WAV.
I would suppose that I am doing something wrong, since such issue hasn't been reported. I think that is still useful to post this as bug in order to reflect how I was expecting the system to work. If I find the source of the error, I will post it.
The text was updated successfully, but these errors were encountered: