4

I have forked Recorder.js to add support for MP3 encoding to reduce recorded data size. Repository here. The encoding is working to a point and I can play back the recorded audio that has been encoded into MP3. However, the audio quality is garbled. The crucial method is in recorderWorker.js:

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 a sample recording.

Here bufferL and bufferR are PCM data as Float32Array. What can I do to fix the garbled encoding? Thank you.

RajV
  • 6,860
  • 8
  • 44
  • 62
  • Well, it's not a sample rate problem. It also isn't constant noise... the effect seems to be more present the louder your voice is. I don't think the output file is corrupt... that tends to sound like harder artifacts, sometimes with loss of sync. I think the issue is somewhere on the input or encoding end, and I'm guessing encoding. Can you start with a simpler sample? Try a 1 kHz tone in mono. My guess is that there some type conversion issues with buffers used internally in LAME and the way it is built with Emscripten. – Brad Apr 07 '14 at 02:34

0 Answers0