ClementSparrow / Pattern-Script

Open Source HTML5 Game Engine based on PuzzleScript
20 stars 2 forks source link

Add Karoo's syntax to control sound effects volume #46

Closed ClementSparrow closed 2 years ago

ClementSparrow commented 2 years ago

See #increpare/PuzzleScript/pull/920.

Things to change:

  1. regex should use non-catching groups and exactly 1 or 2 digits for the volume. I don't think there is a need for more precise settings than by 10% steps.
  2. possible volumes should have a minimum value and a maximum value (typically, 100/SOUND_VOL so that users can boost a sound up to 100% the volume allowed by the browser, while using values expressed relatively to SOUND_VOL).
  3. it requires updating the documentation.
  4. Theoretically, it would also require autocomplete support but I will not care about that for some reason.
ClementSparrow commented 2 years ago

As Karoo noticed, my comment in point 2. is wrong.

The SOUND_VOL is actually used to compute the value of the gain with the formula gain = e^SOUND_VOL -1 ~= 0.284 for the default value of SOUND_VOL=0.25. The gain is used during sound generation as a multiplier for the buffer's value and the buffer is played directly without volume specification.

So there is no reason to limit the volume in the seed, except that high values will create a lot of distortion. Actually, it can create distortion as soon as e^(SOUND_VOLvol/100)-1>1 <=> vol > 100ln(2)/SOUND_VOL ~= 277... So, we may add a warning in case volume values higher than that are used. It also mean we can limit the volume to three-digits numbers, as 999 already gives a gain of 11.152.

That said, I still believe we don't need to express the volume in percents but that tenths is enough precision.