Giter VIP home page Giter VIP logo

Comments (6)

zhuker avatar zhuker commented on July 1, 2024

Looks like you encode stereo as mono

Sent from my iPhone

On Jun 21, 2016, at 00:56, Julius Athenstaedt [email protected] wrote:

First of all thank you for that great lib!

I want to convert a 1411 kbps pcm_s16le 44100 Hz stereo, s16(recorded with recordRTC) to mp3.
The problem is that the wav file sounds perfect but the converted mp3 file sounds bad, sounds lower than the original and is twice as long.

Full js: http://julius.athenstaedt.net/rep/rcx2/background.js
recorded wav: http://julius.athenstaedt.net/rep/wav%20(16).wav
converted mp3 http://julius.athenstaedt.net/rep/mpeg%20(14).mp3

function convertToMP3(audioBlob) {
//audioBlob is the recorded Blob from recordRTC api
//with FileReader get the dataform like with XMLHttpRequest (maybe the problem?)
console.log(audioBlob);
var audioData;
fileReader = fileReader || new FileReader();
fileReader.onload = function() {
audioData = this.result;

            var wav = lamejs.WavHeader.readHeader(new DataView(audioData));
            console.log("wav:",wav);
            mp3encoder = new lamejs.Mp3Encoder(wav.channels, wav.sampleRate, 128);
            var mp3Data = [];

            left = new Int16Array(audioData, wav.dataOffset, wav.dataLen /2); 
            right = new Int16Array(audioData, wav.dataOffset, wav.dataLen /2); 

            sampleBlockSize = 1152; 

            var mp3buf=[];
            for (var i = 0; i < left.length; i += sampleBlockSize) {
                leftChunk = left.subarray(i, i + sampleBlockSize);
                rightChunk = right.subarray(i, i + sampleBlockSize);
                mp3buf = mp3encoder.encodeBuffer(leftChunk, rightChunk);
                if (mp3buf.length > 0) {
                    mp3Data.push(new Int8Array(mp3buf));
                }
            }
            mp3buf = mp3encoder.flush(); //finish writing mp3

            if (mp3buf.length > 0) {
                mp3Data.push(new Int8Array(mp3buf));
            }

            var blob = new Blob(mp3Data, {
                type: 'audio/mp3'
            });
            var url = window.URL.createObjectURL(blob);
    saveFile(url, "mpeg.mp3");
};
fileReader.readAsArrayBuffer(audioBlob);

}
Thank You for help!!
(sorry for bad english)


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or mute the thread.

from lamejs.

sevenuz avatar sevenuz commented on July 1, 2024

And what I have to change? I have used the code for stereo from the example.

from lamejs.

zhuker avatar zhuker commented on July 1, 2024

Did you split your stereo input into left and right channels?

Sent from my iPhone

On Jun 24, 2016, at 18:34, Julius Athenstaedt [email protected] wrote:

And what I have to change? I have used the code for stereo from the example.


You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or mute the thread.

from lamejs.

sevenuz avatar sevenuz commented on July 1, 2024

Yes like in the example, but their was only one second silence. So maybe I splitted wrong:

left = new Int16Array(audioData, wav.dataOffset, wav.dataLen /2); 
right = new Int16Array(audioData, wav.dataOffset, wav.dataLen /2); 

from lamejs.

zhuker avatar zhuker commented on July 1, 2024

Yes this is wrong.
Split by taking every other sample into separate channel.
For i=0 i<data.length i+=2
Left= data [i]
Right = data[i+1]

And then put left and right samples into their own int16 arrays

Sent from my iPhone

On Jun 24, 2016, at 19:18, Julius Athenstaedt [email protected] wrote:

Yes like in the example, but their was only one second silence. So maybe I splitted wrong:

left = new Int16Array(audioData, wav.dataOffset, wav.dataLen /2);
right = new Int16Array(audioData, wav.dataOffset, wav.dataLen /2);

You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or mute the thread.

from lamejs.

sevenuz avatar sevenuz commented on July 1, 2024

Thank you that was the error.
correctly splitted:

//audioData is the wav-blob converted to an ArrayBuffer
var data = new Int16Array(audioData, wav.dataOffset, wav.dataLen/2);

 for (i = 0; i < data.length; i += 2) {
         left.push(data[i]);
         right.push(data[i + 1]);
}

left = new Int16Array(left);
right = new Int16Array(right);

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.