GithubHelp home page GithubHelp logo

mp3 is too much noisy about lamejs HOT 2 OPEN

zhuker avatar zhuker commented on June 16, 2024
mp3 is too much noisy

from lamejs.

Comments (2)

shanewho avatar shanewho commented on June 16, 2024

I've used this library to encode MP3's at high quality, it works very well. I was getting noise at first, one of the main problems I ran into was working with 8, 16, 24, etc bit audio samples and converting between them. 8 bit audio gives you 256 possible values, 16 bit audio is 65,536, so much higher quality. This is just a guess, but I think the issue might be here:

var out = new Int8Array(samples.length/2);

You are converting mp3buf's return to 8 bit and may be getting distortion in the conversion. Here is the code I use (note this is stereo, not mono, so you might have to change):

function lameEncode(l, r, sampleRate, progress) {
        var liblame = new lamejs();
        var mp3Encoder = new liblame.Mp3Encoder(2, sampleRate, 128);

        var blockSize = 1152;
        var blocks = [];
        var mp3Buffer;

        var length = l.length;
        for (var i = 0; i < length; i += blockSize) {
            progress((i/length)*100);
            var lc = l.subarray(i, i + blockSize);
            var rc = r.subarray(i, i + blockSize);
            mp3Buffer = mp3Encoder.encodeBuffer(lc, rc);
            if (mp3Buffer.length > 0) blocks.push(mp3Buffer);
        }
        mp3Buffer = mp3Encoder.flush();   
        if (mp3Buffer.length > 0) blocks.push(mp3Buffer);
        progress(100);
        return new Blob(blocks, {type: 'audio/mpeg'});
    }

from lamejs.

Dewsworld avatar Dewsworld commented on June 16, 2024

Still couldn't find my luck! Also see that mp3Buf is also of type Int8Array

Update: I found the problem. I was mixing singed and unsigned int. I changed
samples = new Uint16Array(audioData, wav.dataOffset, wav.dataLen / 2);
to
samples = new Int16Array(audioData, wav.dataOffset, wav.dataLen / 2);

I think that resolve the issue as closed.

from lamejs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.