Skip to content
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

Buffer length problem for long recordings. #65

Closed
seannyD opened this issue Jul 13, 2017 · 5 comments
Closed

Buffer length problem for long recordings. #65

seannyD opened this issue Jul 13, 2017 · 5 comments
Labels

Comments

@seannyD
Copy link
Owner

seannyD commented Jul 13, 2017

...
MP3 Worker uk_1499943820618_uk_lowp_taka_1 mp3Worker.js:41:3
uncaught exception: buffer over flow (unknown)

Related to Audior/Recordmp3js#23 and akrennmair/libmp3lame-js#8

@seannyD
Copy link
Owner Author

seannyD commented Jul 13, 2017

This part of the code:

function enlargeMemory() {
  abort('Cannot enlarge memory arrays. Either (1) compile with -s TOTAL_MEMORY=X with X higher than the current value ' + TOTAL_MEMORY + ', (2) compile with ALLOW_MEMORY_GROWTH which adjusts the size at runtime but prevents some optimizations, or (3) set Module.TOTAL_MEMORY before the program runs.');
}
var TOTAL_STACK = Module['TOTAL_STACK'] || 5242880;
var TOTAL_MEMORY = Module['TOTAL_MEMORY'] || 16777216;
var FAST_MEMORY = Module['FAST_MEMORY'] || 2097152;
// Initialize the runtime's memory
// check for full engine support (use string 'subarray' to avoid closure compiler confusion)
assert(typeof Int32Array !== 'undefined' && typeof Float64Array !== 'undefined' && !!(new Int32Array(1)['subarray']) && !!(new Int32Array(1)['set']),
       'Cannot fallback to non-typed array case: Code is too specialized');
var buffer = new ArrayBuffer(TOTAL_MEMORY);

Suggests there's a maximum memory limit that can be set by:

Module = {};
Module.TOTAL_MEMORY = 128;// low number to test 
mp3codec = Lame.init();

But there are problems with the non-min version of the code. Even with the default settings, we get an error

RangeError: invalid or out-of-range index

I'm condiering switching to https://github.com/zhuker/lamejs

@seannyD
Copy link
Owner Author

seannyD commented Jul 13, 2017

https://github.com/zhuker/lamejs didn't like my e.data.buf in the splice command.
I just updated the bitrate call to mp3Worker_2.js, so maybe that will work with one of the other attempts?

This project uses lamejs: https://github.com/zzarcon/microm/blob/728ade6789fe110c8419adfc9b1b209f0a261992/lib/converter.js

But we may as well convert totally to using microm.

@seannyD
Copy link
Owner Author

seannyD commented Jul 14, 2017

In recordmp3.js, I need to pass the arrayBuffer to the encoderWorker.
Then in mp3Worker_2.js, I need to extract the sound buffer correctly:

var wav = lamejs.WavHeader.readHeader(new DataView(e.data.buf));
var samples = new Int16Array(e.data.buf, wav.dataOffset, wav.dataLen / 2);

Then use the example encoding code from:
https://github.com/zhuker/lamejs/blob/master/example.html

@seannyD
Copy link
Owner Author

seannyD commented Jul 14, 2017

This seems to suggest there's a memory limit on workers themselves:
https://stackoverflow.com/questions/36175480/web-worker-out-of-memory-when-processing-large-array

@rewberl rewberl added the bug label Jul 14, 2017
@seannyD
Copy link
Owner Author

seannyD commented Jul 17, 2017

The program now cuts the recordings into manageable chunks before converting to wav (and then converts the wav chunks to mp3). The ID3 tags are also working again now.

A branch tried to do the whole conversion to mp3 directly from samples, but ran into problems.

@seannyD seannyD closed this as completed Jul 17, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants