Tonejs / Tone.js

A Web Audio framework for making interactive music in the browser.
https://tonejs.github.io
MIT License
13.4k stars 976 forks source link

How to set Volume in 0 - 1 #997

Closed mtrucc closed 2 years ago

mtrucc commented 2 years ago

https://tonejs.github.io/examples/oscillator

I can set volume -100 to 0

But I want to set Volume like https://alemangui.github.io/pizzicato/

0 to 1

What should I do?

dirkk0 commented 2 years ago

You can add a Gain Node, which accepts values from 0 to 1: https://tonejs.github.io/docs/14.7.77/Gain

mtrucc commented 2 years ago

You can add a Gain Node, which accepts values from 0 to 1: https://tonejs.github.io/docs/14.7.77/Gain

        const gainNode = new Tone.Gain(0).toDestination();

        gainNode.gain.setValueAtTime(1, Tone.context.currentTime);

        const osc = new Tone.Oscillator({
            type: "square",
            frequency: 440,
            volume: 0
        }).connect(gainNode);

Thank you!

volume is 20 -> Doesn’t increase the size of the sound, maybe this is my illusion.............

dirkk0 commented 2 years ago

there's a volume: 0 in your synth ... ?

mtrucc commented 2 years ago

there's a volume: 0 in your synth ... ?

yes, the demo is -16 ,I think if it is adjusted to 0, there will be no effect on the sound? I don't know what its default value is

dirkk0 commented 2 years ago

You want to ramp up the volume of the synth, right? And this doesn't work? If you open up a CodePen or Glitch, this can be solved, I think.

mtrucc commented 2 years ago

I have solved the problem, I don’t want to increase the volume, I just saw some doubts about the volume parameter, I don’t know what will happen if the parameter value is 20

dirkk0 commented 2 years ago

ok, great! Then you can close this issue.