Why is libmp3lame.js creating garbled MP3s?

I have forked Recorder.js to add MP3 encoding support to reduce the size of the recorded data. The repository is here . Encoding works to a certain point, and I can play back the recorded sound that was encoded in MP3. However, the sound quality is distorted. The decisive is the recorderWorker.js method:

function exportMP3(type){
    var bufferL = mergeBuffers(recBuffersL, recLength);
    var bufferR = mergeBuffers(recBuffersR, recLength);

    console.log("Start MP3 encoding");
    var mp3codec = Lame.init();
    Lame.set_mode(mp3codec, Lame.JOINT_STEREO);
    Lame.set_num_channels(mp3codec, 2);
    Lame.set_out_samplerate(mp3codec, sampleRate);
    Lame.set_bitrate(mp3codec, 128);
    Lame.init_params(mp3codec);

    var mp3data = Lame.encode_buffer_ieee_float(mp3codec, bufferL, bufferR);
    audioBlob = new Blob([mp3data.data], { type: "audio/mp3" });
    console.log("Done MP3 encoding");

    this.postMessage(audioBlob);
}

Here is an exemplary entry .

Here, bufferL and bufferR are PCM data like Float32Array. What can I do to fix garbled coding? Thanks.

+4
source share

Source: https://habr.com/ru/post/1528848/


All Articles