Skip to content
This repository has been archived by the owner on Oct 10, 2019. It is now read-only.

Uncaught RangeError: Invalid array buffer length #8

Open
lightmar opened this issue Aug 10, 2014 · 12 comments
Open

Uncaught RangeError: Invalid array buffer length #8

lightmar opened this issue Aug 10, 2014 · 12 comments

Comments

@lightmar
Copy link

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
Copy link

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:

  • lame_encode_buffer_ieee_float calls _lame_encode_buffer_template
  • _lame_encode_buffer_template is a knotty little state machine, it uses a switch statement as a sort of JMP or GOTO.
  • case 53 of this switch calls _lame_encode_mp3_frame, which works for a bunch of frames, returning a positive integer, and then at some point returns -1, which causes case 60 to return -1 to nread.
  • _lame_encode_mp3_frame gets this -1 as a return value from _copy_buffer
  • I think this is from case 2 of the state machine in _copy_buffer, not entirely clear to me.

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
Copy link

@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
Copy link
Author

lightmar commented Dec 1, 2014

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
Copy link

BondaCB commented Dec 2, 2014

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
Copy link
Author

lightmar commented Dec 8, 2014

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
Copy link

chezbro commented Dec 8, 2014

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
Copy link

@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
Copy link

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

@ybelova
Copy link

ybelova commented Feb 5, 2016

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

@michelboudali
Copy link

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

@ybelov
Copy link

ybelov commented Sep 7, 2016

@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
Copy link

ybelov commented Sep 7, 2016

I can share files with you if you are interested.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants