akrennmair / libmp3lame-js

port of libmp3lame to JavaScript using emscripten
223 stars 61 forks source link

Uncaught RangeError: Invalid array buffer length #8

Open lightmar opened 10 years ago

lightmar commented 10 years ago

Hi,

Thank you for this great plugin. Unfortunately I have a problem which I can't figure out. When I encode to mp3 from microphone, on some computers it works great, however on others when I try to encode to I get the following error: Uncaught RangeError: Invalid array buffer length

Does anyone knows whats the reason and how solve it?

Thanks

awarenetdev commented 10 years ago

I have this problem too. The error message is caused by trying to create a new ArrayBuffer of size -1 just before the end of the code:

        var nread = Module.ccall('lame_encode_buffer_ieee_float', ...]);
        var arraybuf = new ArrayBuffer(nread);

I get the "Invalid array buffer length" because nread is -1. The transcompiled code is hard to follow, but so far I have learned the following:

Here's a paste of the function giving that -1.. Will comment again if I get it working for me.

edit: here's a trace after instrumenting it a bit.

awarenetdev commented 10 years ago

@lightmar: I have a solution which works for me. I could not get the copy of libmp3lame.js in this repo working for recordings longer than 8 seconds, I suspect this is because of something bad in my input, am sending mono and the number of samples seems to be wrong.

Anyway, this copy works for me, found at: http://audior.ec/recordmp3js/, via this tutorial.

Swapping it in, I no longer experience the issue you describe.

lightmar commented 9 years ago

Thank you, however I still can't make it work. I just came back to try again after I left it for few months. I have discovered that the error occurs only when a user records microphone with an high sample rate of 192000. When I try it on my mac with 44000 input, it works.

How can I make it work? or Maybe reduce the sample rate somehow?

BondaCB commented 9 years ago

I'm having problems also on windows computers, which, as @lightmar has stated, have sample rates of 192000 instead of 44000.

Any approach with this?

lightmar commented 9 years ago

I have tried changing the Lame config like this:

Lame.set_in_samplerate(mp3codec, 44100); Lame.set_out_samplerate(mp3codec, 44100); Lame.set_bitrate(mp3codec, 128);

And it did worked, but the problem is that the sound recording was really bad, it sounds something like roaring lions....

chezbro commented 9 years ago

Can anyone point me to how I can increase the length of time I can record..? I suspect it deals with increasing the bufferlength, etc..

Any help is greatly appreciated. Thanks!

abhilashLenka commented 9 years ago

@lightmar , Is this solution helpful?

"Lame.set_in_samplerate(mp3codec, 44100); Lame.set_out_samplerate(mp3codec, 44100); Lame.set_bitrate(mp3codec, 128);"

I am not trying this yet as it works beautifully on linux but has suddenly stopped working on Windows, I'll take your word on it.

abhilashLenka commented 9 years ago

@lightmar I should have taken you seriously on the roaring lions thing, Any idea how to fix it??

ybelova commented 8 years ago

We run into the same issue. Since it has been a while, may be someone already found the solution ? really appreciate you help.

michelboudali commented 8 years ago

@lightmar i also get the "roaring lions", did you manage to solve this problem?

ybelov commented 8 years ago

@michelboudali, we did not find solution per say, but figured what causing that. On Windows: Try to go Control Panel -> Sound ->Payback-> Advanced and try to change sample rate. We get "Invalid array buffer length" with certain settings and don't get with others.

We do catch that issue by adding onerror handler to worker:

encoderWorker.onerror = function (err) {
    var errorText = 'Sorry, We are having some technical <br/>difficulties to convert your recorder <br/>sound to mp3 format and save.';
    console.log('worker is suffering!', err)
    document.getElementById('recorder_error').innerHTML = errorText;
}
ybelov commented 8 years ago

I can share files with you if you are interested.