GithubHelp home page GithubHelp logo

Comments (16)

zhuker avatar zhuker commented on June 16, 2024

i cant tell from looking at the code
but it looks like you are not feeding the encoder properly

from lamejs.

durgadp avatar durgadp commented on June 16, 2024

Please let me help what i need to be code for encoder properly

from lamejs.

zhuker avatar zhuker commented on June 16, 2024

sounds like you are calling flush() too often, try calling it only at the end of encode

from lamejs.

durgadp avatar durgadp commented on June 16, 2024

Can I share the code file with you? You want me to call flush after sending to the server or before.

from lamejs.

zhuker avatar zhuker commented on June 16, 2024

Can I share the code file with you? You want me to call flush after sending to the server or before.

Post the most relevant snippet here, i'll take a look

from lamejs.

durgadp avatar durgadp commented on June 16, 2024

from lamejs.

zhuker avatar zhuker commented on June 16, 2024
    var data = new Float32Array(arrayBuffer);
    var out = new Int16Array(arrayBuffer.length);

change to

    var data = new Float32Array(arrayBuffer);
    var out = new Int16Array(data.length);

from lamejs.

durgadp avatar durgadp commented on June 16, 2024

I have tried by replace this code but still facing same issue. Please let me know where i am doing wrong with code.

from lamejs.

zhuker avatar zhuker commented on June 16, 2024

can you create an end-to-end example i can reproduce here?
i mean no worker code, no messages

from lamejs.

durgadp avatar durgadp commented on June 16, 2024

Above is my file please let me know which code i need to remove from it.

from lamejs.

zhuker avatar zhuker commented on June 16, 2024

from lamejs.

zhuker avatar zhuker commented on June 16, 2024

arrayBuffer passed to your var encode = function (arrayBuffer) {
must be of size divisible by 1152 * 4
if size is different encoder will produce the clicks you are hearing

from lamejs.

durgadp avatar durgadp commented on June 16, 2024

What i need to do for 1152 * 4 into my encode function so it will ignore

from lamejs.

lostrepo avatar lostrepo commented on June 16, 2024

@durgadp I'm testing lamejs as fallback for vmsgjs right now.
Here is my handling of this limitation (mono sound example).

// assumes that t - is some sort of object, in my case it's vmsgjs Recorder instance
t.len = 0;
// List of valid buffSize values can be found here:
// https://developer.mozilla.org/en-US/docs/Web/API/BaseAudioContext/createScriptProcessor
// To use buffSize = 256 change t.samplesInFrame to 18. In other cases you don't change it
t.buffSize = 1024;
t.samplesInFrame = 9;
t.sampleFrameSize = t.buffSize * t.samplesInFrame;
t.unsentSamples = [];

function startRecording(){
  // assumes that
  //  t.encNode = (t.audioCtx.createScriptProcessor || t.audioCtx.createJavaScriptNode)
  //              .call(t.audioCtx, t.buffSize, inputChannelsNumber, outputChannelsNumber)
  t.encNode.onaudioprocess = function(e){
   // create new array so data won't be corrupted, references suck sometimes
   t.unsentSamples[t.len++]	=	new Float32Array(e.inputBuffer.getChannelData(0));
    if (!(t.len % t.samplesInFrame)){
      t.worker.postMessage({
         cmd: 'encode',
         data: { buf: concatSamples(t.unsentSamples, t.sampleFrameSize) }
      });
      t.len = 0;
      t.unsentSamples = [];
    }
  }
  t.encNode.connect(t.audioCtx.destination);
}

function stopRecording(){
  t.len = 0;
  t.unsentSamples = [];
  t.encNode.onaudioprocess = null;
  t.unsentSamples && t.unsentSamples.length && t.worker.postMessage({
    cmd: 'encode',
    data: {
       buf: concatSamples(t.unsentSamples, t.sampleFrameSize)
    }
 });
 t.worker.postMessage({ cmd: 'finish' });
 // disconnect Nodes, destroy stuff
}

// concatenate audio samples
// if not enough samples passed we will still return valid Float32Array
// when totalLength passed divisible by 4608 = 1152*4
// samples - array of Float32Arrays
// totalLength - combined length of Float32Arrays in samples
function concatSamples(samples, totalLength){
  var l = samples.length,
  len = 0,
  res = new Float32Array(totalLength);		
  for (var i = 0; i < l; i++){
    res.set(samples[i], len);
    len += samples[i].length;
  }
  return res;
}

Hope this helps others to work around this limitation.

from lamejs.

durgadp avatar durgadp commented on June 16, 2024

sounds like you are calling flush() too often, try calling it only at the end of encode

What do you mean by calling flush() too often?

from lamejs.

durgadp avatar durgadp commented on June 16, 2024
t.sampleFrameSize

var remaining = samplesMono.length;
I am getting 2048 length here which is divisible by 4. Help me if i am doing any thing wrong.

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.