Code Monkey home page Code Monkey logo

Comments (4)

egonelbre avatar egonelbre commented on May 25, 2024

This would require some changes to the code:

  1. https://github.com/loov/jsfx/blob/master/jsfx.js#L7 change numChannels to 2.
  2. Before this https://github.com/loov/jsfx/blob/master/jsfx.js#L970, stride all data values with 0.

With regards to 2. point: M = Mono, R = Right, L = Left. The data array contains all the samples [M, M, M, M ... ], stereo needs to have them in [L, R, L, R, L ... ]..., this means you need to convert the original data vector to [M, 0, M, 0 ...] or [0, M, 0, M ...], depending what you want.

Something like this should do:

var mono = data;
data = new createFloatArray(mono.length);
for(var i = 0; i < mono.length; i++){
    data[i*2] = mono[i];
}

from jsfx.

dsithija avatar dsithija commented on May 25, 2024

Hi Egon,

Thank you. It works but sound was different a bit. It must be because data[i*2] exceeds the array length in half way through the for loop. So it assigns half of the full wave as a mono sound. So changed the for loop like this.

var mono = data;
data = new createFloatArray(mono.length);
for(var i = 0; i < mono.length; i+=2){
    data[i] = mono[i];
}

from jsfx.

egonelbre avatar egonelbre commented on May 25, 2024

Nope, now the sound is two times shorter.... it should be data = new createFloatArray(mono.length * 2); i.e.

var mono = data;
data = new createFloatArray(mono.length * 2);
for(var i = 0; i < mono.length; i++){
    data[i*2] = mono[i];
}

Was tired yesterday, missed the multiplication.

from jsfx.

dsithija avatar dsithija commented on May 25, 2024

Ok. Thanks again.

from jsfx.

Related Issues (12)

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.