Coder Social home page Coder Social logo

Envelope problem about audiolib.js HOT 2 CLOSED

redned avatar redned commented on May 27, 2024
Envelope problem

from audiolib.js.

Comments (2)

jussi-kalliokoski avatar jussi-kalliokoski commented on May 27, 2024

Hey there!

A quick look reveals a few problems:

if(pressed.slice(0,1) == noteOffName){ this will never be true, slice creates a new array, which is a unique object. What you want is if(pressed[0] === noteOffName){. Also probably a good idea to use triple equals.

volENV = new audioLib.ADSREnvelope(sampleRate, 200, 50, 1, 500, 250, 0); discard the last two arguments and it should work. If you specify the those two, triggerGate will not react, because the ADSREnvelope assumes that you want a static envelope (i.e. the ADSREnvelope starts to oscillate), since you specified a static time for sustain and release.

volENV.triggerGate(false); if you turn the oscillator immediately after the key is lifted, you never get to the release part. To get that as well, you need some kind of decay management. Otherwise this is ok, just combined with the way you're dealing with the oscillators makes it malfunction a bit.

osc1 = new audioLib.Oscillator(sampleRate, null); and osc1 = new audioLib.generators.Note(sampleRate, noteOnName); it's probably a better idea to keep the same oscillator instance all the time, since you only have one oscillator anyway. Just set the frequency to match the note whenever the key changes, and when the key is lifted, set the frequency to zero. Or even better, if you're making a mono synth, you can make the choice of never setting the frequency to zero, instead just release the gate for the envelope, and the sound will fade out.

Hope this helps!

Cheers,
Jussi

from audiolib.js.

redned avatar redned commented on May 27, 2024

That sorted it. Thanks a lot!

from audiolib.js.

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.