Set Sampler Volume

  • Hey,
    i want to use multiple samplers and set their volumes through knobs.
    It tried it like this

    inline function onVolumeSliderControl(component, value)
       reg x = Synth.getSampler("Top");
       reg x = Synth.getSampler("Bottom");
       reg x = Synth.getSampler("Room");

    but the result is weird and seems not to work.

    any idia?

    1. You can't declare regvariables inside a inline function. Use local.

    2. You can't declare a variable twice.

    3. Create the references to the modules in the onInit callback. You are creating three references including a full tree search for every slider movement which is terrible performance. Even worse, if you automate it, you'll end up with drop outs.

    4. Don't use magic numbers (0 as parameter index). Use Top.Gain for this, there's no performance overhead and the code gets 100x more clear and sustainable - if I decide that I add another parameter before the Gain parameter, it will break your code, the Top.Gain would then automatically point to 1. I admit it's highly unlikely that I do this, especially for the first parameter of the most generic module, but it's good practice.

    5. If you want to control the volume of a sampler with a knob, use a Simple Gain module. You will get a decibel range and much smoother movements. The Gain parameter of a sound generator is not smoothed for performance reasons (you can end up with dozens of sound generators which in 99% of all cases have a static volume).
      I can't say what range you are using in the VolumeSlider, but if you use a Simple Gain module and set the mode to "Decibel", it should work.

    6. Try to avoid repeating code. Use an array for the sampler references.

    Add three Simple Gain modules to the samplers, rename them accordingly and try this code:

    // Use an array with the references
    const var Gainers = [];
    inline function onVolumeSliderControl(component, value)
        for(g in Gainers)
            g.setAttribute(g.Gain, value);

    This is the HISE Snippet containing a full example:

    HiseSnippet 1514.3oc6aEsaaaCEkJNrs1qsnsnOrG1CBAa.NXco1oosaHXnt1ooKX0MFwocaXXnfQh1lnRjBTTo0aneHaeEaXOs25Wv9.1WQ+C1tjRJltyKwZMqqIP5gBwK4k7v68xKuGE2dRgGMNVHQNU2cbDE4bdb+wb0nNiHLNZqMPNWD2kDqnR2TQsGGQhio9HGmJ2WKvo5hHyyqtSaR.g6QmHBgdrf4Qe.KjolHMp0WxBB1j3S2kEZM50Zskmf2QDHR.7TA2.EQ7dJYH8gD8vV.ibv2ymoDx9JhhFibVrsveb+QhmwSG+iYwr8Bn5FMQ8gIJU7lh.eMh0ui5LhE32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ARsAYWAWDMRvYdSmW.JPb3PpzF5yb+.kRBoklH4ps1gFPIwVI19vVO.JBkHmNcWgLEMmeSwg4tdebJbc0o5cOcTnPkS8EJbjt7yd.weSz+8ygRUbFUsCoNADZCZ.YJa2Ww7UirJks0LpjvoxwUr6hycPfF3mbBZuB1XXOIAXii+jCfuDFt29c.3tiHQA0k1k.2YnYyAEP1GJZ1iZWF4B5RSSa2P2VCn9TtuoweBOYc1LulScmMy6bdMI.OVScKtvNTpdG2+cdrojOWM2iSy9Nu7oB1aYua9pENUnbcQiF5tA.Sjfo9fAYeb.nvVTrwoFpKFcQskCj0mrOMsfhT77OxcpKyK+aJnySiWu.jLOGN8K3cJhmYqe4OZUxyrjmYIOyRdlk7LK4YVxy7Mmm44wS9C8UR0rjpYIUyRplkTMKoZVDplmAq+8ebZ5On4veujnYIQyRhlkDMKIZVRzrjn4w.QyZ37ejnkzLKoYVRyrjlYIMyRZlq+1YSGR7jhm3k9qVWu0OmQBf.t4+cKUwc0scal+6TW6rBg5behmm9VzOAbWyViUKrF2nvZrVg03lEViaUXMtcg03SODMzjJtahRDll7Dg9K7T9lS.

  • Thanks alot!
    That helps me out 🙂

  • @Christoph-Hart Can we use the Property Editor to control the output of a sampler's volume?
    I think I have the settings correct for my knob, but it only brings the sampler volume to -100dB and then does nothing.

    0_1527620642411_db volume.png

  • @dustbro You should use a simple gain plugin to avoid nasty noises when changing volume. If you really need to change the volume of a container directly you need to set your knob's min and max to 0 and 1. There is a function (one of the Engine ones) that can convert this value to a dB value if you need to display it anywhere.

  • @d-healey Thanks man! I was trying to avoid adding too many modules in this instrument... but that's definitely the easies route.

Log in to reply