Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Track volume limited to initial value #453

Closed
jordanske opened this issue Dec 6, 2020 · 5 comments · Fixed by #487
Closed

Track volume limited to initial value #453

jordanske opened this issue Dec 6, 2020 · 5 comments · Fixed by #487
Assignees
Labels
area-player Related to the audio playback engine. platform-javascript Related to the JavaScript version of alphaTab state-needs-discussion 💬

Comments

@jordanske
Copy link
Contributor

jordanske commented Dec 6, 2020

Your environment

  • Version used: 1.2.0-alpha.64
  • Platform used: JavaScript
  • Rendering engine used: SVG
  • Browser Name and Version: Any
  • Operating System and version Win10
  • Link to your project:
    Example with track-volume.gp

Description

While working on #451 I noticed that when I increase the volume slider (of a track that is by default for example 20%) the volume does not increase. But if I go lower that 20% is does decrease. So it seems the volume is limited to the volume in the track information.

Expected Results

Volume increases when I increase the slider

Observed Results

Volume is limited to the initial value.

Steps to Reproduce (for bugs)

  1. Load any file with a track volume lower then the default, for example 50%
  2. Solo the track
  3. Hear that there is no difference if the slider is at 50% or 100%.
    But lower than 50% still lowers the volume.

As example you can use the project link, and the -16DB track.

Possible Solution

I am not sure what the intended behaviour is.

volumeSlider.oninput = function (e) {
e.preventDefault();
// Here we need to do some math to map the 1-16 slider to the
// volume in alphaTab. In alphaTab it is 1.0 for 100% which is
// equal to the volume in the track information
at.changeTrackVolume([track], volumeSlider.value / track.playbackInfo.volume);
};

If I read this than I think that the slider should initially always be set to 100%, and the slider is relative to the track information.

But I think that it would be more logical that the slider value represent the actual volume. So if the initial value from the track information is at 50%, the slider would also be at 50% and can be set higher by the user if desired.

@Danielku15
Copy link
Member

Have you checked whether this is an issue within alphaTab or only in the playground? changeTrackVolume is meant to change the "relative mixing volume" of the track and not set an absolute value. Absolute values are managed in the data model.

The volume of the tracks is firstly defined on the data model with a value from 0-16. This volume of the track can change over time. e.g. during the intro the first guitar might be only on 8 but then on the chorus it changes to 12. This is also the reason why changeTrackVolume cannot set an absolute value.

When changeTrackVolume is called with 0.5 it is an additional factor to the volume the track has already defined.

An example. You have a song with 3 tracks:

  1. Volume 16
  2. Volume 6, changing to 12 on bar 12
  3. Volume 6, changing to 3 on bar 12.

When we now set for all tracks the volume to 0.5 they will actually have the volume

  1. Volume 8
  2. Volume 3, changing to 6 on bar 12
  3. Volume 3, chaning to 1.5 on bar 12.

That's how alphaTab should work. The playground is having a UI which might be a bit confusing. It tries to show the initial values of the tracks. And when changing it tries to map it back to a percentual scale. The initial volume of the slider defines the 100%, changing the lsider is making it more silent or louder.

With this information I think what you see is not a bug unless the changeTrackVolume does not what I explained.

A track with initial volume 8, will have the 0-16 slider centered. Pulling it to 16 will result in 16 / 8 = 200% volume compared to the normal playback. Unfortunately this does not play well with volume changes but the playground is also not a production ready full solution. The maximum volume is 300%.

So I'm not sure what is now the actual bug you are seeing. From what I see in your example link, everything should be fine.
image

@Danielku15 Danielku15 self-assigned this Dec 9, 2020
@Danielku15 Danielku15 added state-needs-discussion 💬 🕷️ type-bug area-player Related to the audio playback engine. platform-javascript Related to the JavaScript version of alphaTab labels Dec 9, 2020
@Danielku15 Danielku15 added this to the 1.2 milestone Dec 9, 2020
@jordanske
Copy link
Contributor Author

Thanks for the awesome explanation.

I've been doing some more testing.

I noticed 2 things:

You said that the maximum volume is 300%. But the volume get clamped here to a maximum of 100%.

public setChannelVolume(channel: number, volume: number): void {
volume = SynthHelper.clamp(volume, SynthConstants.MinVolume, SynthConstants.MaxVolume);
this._synthesizer.channelSetMixVolume(channel, volume);
}

From 0 to 1 as seen here:
public static readonly MinVolume: number = 0;
public static readonly MaxVolume: number = 1;

If I remove the clamp, or change the MaxVolume constant, I hear a difference in volume if I increase the slider.

But if I align the slider that is initially 50%, then it still sounds a lot quieter then the first track.
Thus the second thing I noticed.
The volume slider is linear (not logarithmic). While the volume from the track data is logarithmic.

If for example I change this line:

gainMono *= this.mixVolume;

To:
gainMono *= (Math.pow(this.mixVolume, 3.0));

Then the volumes sound the same if I set the sliders to the same value.

Here are some examples:
With the musicxml fix from the pull request:
http://jordanske.net/alphatab-tests/?test=track-volume-balance.musicxml&file=alphaTab-musicxml.js

With the MaxVolume constant set to 3, and the gainMono change:
http://jordanske.net/alphatab-tests/?test=track-volume-balance.musicxml&file=alphaTab-musicxml-volume-fix-1.js

If you change the sliders to 100%, they should sound the same (except for the last 2, because the slider is maxed at 300%)

The same test with the .gp file:
http://jordanske.net/alphatab-tests/?test=track-volume.gp&file=alphaTab-musicxml-volume-fix-1.js

@Danielku15
Copy link
Member

Oh, the MaxVolume seems to be the root cause of the issue. It used to be way higher at 10 on the old synthesizer:

public const float MaxVolume = 10;

Not sure why I reduced this to 1, seems like rather an unintended change.

@jordanske
Copy link
Contributor Author

Any plans to change that back?

And I also think that logarithmic sliders would be a nice addition, at least as an optional setting.

@Danielku15
Copy link
Member

I simply removed the whole max volume limitation. "Let the people turn up the volume!" 📢 🤘 😁

Building logarithmic sliders is something for the developer integrating alphaTab as it is part of the surrounding UI. The playground and tutorial are more samples how to use alphaTab and not an all-in-one control.

This was referenced Jan 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-player Related to the audio playback engine. platform-javascript Related to the JavaScript version of alphaTab state-needs-discussion 💬
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants