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

Sound volume #2236

Closed
Soeufans opened this issue May 30, 2020 · 20 comments
Closed

Sound volume #2236

Soeufans opened this issue May 30, 2020 · 20 comments
Assignees
Milestone

Comments

@Soeufans
Copy link

Name of the game: Legend of Heroen

Player platform: Windows 7

Describe the issue in detail and how to reproduce it:

Hello!

I was recently creating my menu for the game, and i notice, that the "Volume" for the sounds, works different from RM2k3

I creat an event with fading a sound to volume 100 to 0 and with RPG maker 2003 the sounds get offf gradually like this:

Volume:
100 --- > 100
90 ---> 90
80 ---> 80
70 ---> 70
60 ---> 60
50 ---> 50
40 ---> 40
30 ---> 30
20 ---> 20
10 ---> 10
0 ---> 1
In the volume lower than 60, theres a "noise" on them

With Player Easy RPG, the sounds get off, but it looks like it goes like this (or is my ear)
Editor ---> EasyRPG
100 ---> 100
90 ---> 95
80 ---> 85
70 ---> 75
60 ---> 65
50 ---> 55
40 ---> 45
30 ---> 35
20 ---> 25
10 ---> 15
0 ---> 0

not exactly as these numbers i expose, maybe its my ears, but theres some difference betwen them

Heres a Video about the sound
Easy Video sounds.zip

@elsemieni
Copy link
Member

elsemieni commented May 30, 2020

I used to think there's a similar issue that I talked about different volume scales, but I couldn't find it.
I will document it again.

Seems RPG_RT volume scale is more sort-of-exponential one, meanwhile in Player volume scale is linear.
There's a visual example of the attached video example for seeing more clearly.
image

As workaround hotfix for SuperCrystalHunter's Player repo I implemented some sort of lookup table for correcting volume values closer to RPG_RT ones in https://github.com/elsemieni/easyrpg-player-ne-sch/blob/master/src/game_system.h#L79 and https://github.com/elsemieni/easyrpg-player-ne-sch/blob/master/src/game_system.cpp#L194 . However, didn't PR this one beacuse the hotfix is ugly code-speaking.

For other side, I don't know the source of the noise from RPG_RT. User machine-specific issue?

@ghost
Copy link

ghost commented Oct 9, 2020

The diagram looks like a cubic (power of 3) curve to me, so we could try
volume = (int)std::ceil(100.0 * std::pow(volume / 100.0, 3.0));

Disregard my comment, the formula I had provided here doesn't exactly match @elsemieni's lookup table.

@elsemieni
Copy link
Member

The diagram looks like a cubic (power of 3) curve to me, so we could try volume = (int)std::ceil(100.0 * std::pow(volume / 100.0, 3.0));
Disregard my comment, the formula I had provided here doesn't exactly match @elsemieni's lookup table.

Don't rely on my lookup table. That's just a vague approximation :)

@ghost
Copy link

ghost commented Mar 20, 2021

Made volume tests with a VU meter and came to the following volume values (about 90% accuracy, for 100% accuracy we need to dig into the binary):

Volume setting Actual volume
100% 100%
90% 70%
80% 47%
70% 29%
60% 20%
50% 15%
40% 10%
30% 7%
20% 4%
10% 3%
1% 2%
0% 0%

I have only tested in 10%-increments because RPG Maker allows setting the volume in 10%-increments only (but you can still get to intermediate settings by hex editing the files). And there seems to be a volume floor if the volume is greater than 0%. Moreover judging by the steps in the volume table there does not seem a mathematical formula being used to get the actual volume values. Using the volumes in the table provided here makes the rain in "Vampires Dawn" sound right (tested it myself). I recall the rain was mentioned in #2427.

@carstene1ns
Copy link
Member

carstene1ns commented Mar 20, 2021

Maybe not too useful:
Figure_1

Used python
#!/usr/bin/python

import matplotlib.pyplot as plt
import numpy as np

x = np.array([0,1,10,20,30,40,50,60,70,80,90,100])

y1 = x
plt.plot(x, y1, label = "easyrpg")

y2 = np.array([0,2,3,4,7,10,15,20,29,47,70,100])
plt.plot(x, y2, label = "rpg_rt") 

log_y2 = np.log(y2[1:])
curve_fit = np.polyfit(x[1:], log_y2, 1)
#print(curve_fit)
a = round(curve_fit[1],2)
b = round(curve_fit[0],2)

x3 = np.arange(0, 100, 1)
y3 = np.exp(a) * np.exp(b * x3)
plt.plot(x3, y3, label = "y= e^" + str(a) + " * e^(" + str(b) + " * x)")

x4 = np.linspace(0, 100, num=100)
fx = []
for i in range(len(x4)):
	fx.append(100*(x4[i]/100)**3)
plt.plot(x4, fx, label = "rueter37 cubic")

plt.grid()
plt.xlabel('%')
plt.ylabel('%')
plt.title('volume comparison') 
plt.legend()
plt.show()

@ghost
Copy link

ghost commented Mar 20, 2021

@carstene1ns Thank you for providing the chart! I think the formula used in the green curve is a good approximation to avoid having to use a volume lookup table.

@Ghabry
Copy link
Member

Ghabry commented Mar 20, 2021

I think this is caused by DirectSound. Harmony calls into a Dsound.dll function.
Harmony is just doing 100 - (fade-volume) / 100 and passes this to a dsound func.

So maybe one could research logarithmic volume in dsound now.

@Ghabry
Copy link
Member

Ghabry commented Mar 20, 2021

I found e.g. this in old Dolphin emu code (before they dropped dsound):

https://github.com/dolphin-emu/dolphin/blob/4.0/Source/Core/AudioCommon/Src/DSoundStream.cpp#L132

@Ghabry
Copy link
Member

Ghabry commented Mar 20, 2021

Via IRC
@rueter37
Got the sound volume formula now! Pseudo-code: volume = (10 ^ ((-100 + volume)/60.0)) * 100

I will assign this to me as this is audio code.

@Ghabry Ghabry self-assigned this Mar 20, 2021
@Ghabry
Copy link
Member

Ghabry commented Apr 8, 2021

Something else of interest @elsemieni @rueter37
There is also an option for controlling the "Panning" (whether the sound is left or right). This is completely unimplemented in the Player right now. Guess this is also implemented by adjusting the volume but per channel, not in general. Could you check how the loudness per channel changes depending on the panning?

Will do this stuff after Midi. Need to get some order in here :)

@ghost
Copy link

ghost commented Apr 9, 2021

The panning scales linear but the sound volume formula gets applied afterwards. Here is a table for 100% volume sounds:

Panning Volume left Volume right Actual volume left Actual volume right
0 (full left) 100% 0% 100% 0%
10 100% 20% 100% 4%
20 100% 40% 100% 10%
30 100% 60% 100% 21%
40 100% 80% 100% 46%
50 (default, center) 100% 100% 100% 100%
60 80% 100% 46% 100%
70 60% 100% 21% 100%
80 40% 100% 10% 100%
90 20% 100% 4% 100%
100 (full right) 0% 100% 0% 100%

@Ghabry Ghabry changed the title Issue about "sounds" Sound volume May 31, 2021
@Ghabry
Copy link
Member

Ghabry commented May 31, 2021

@rueter37 I'm pretty sure I saw a patch by you somewhere. Cannot find it anymore.

Anyway. I'm pretty sure by now that all platforms we are targeting use a linear volume (or are converted like SDL2 when using DSound as a backend). So doing the translation in Game_System makes sense.

This would also give us extra flexibility: One could add an extra chunk to define that the volume scale for this track is linear instead of logarithmic.

@ghost
Copy link

ghost commented May 31, 2021

@Ghabry
Copy link
Member

Ghabry commented May 31, 2021

great. Add a "// Adjust to RPG_RT (Direct Sound) volume scale" and you can PR it.

I will keep myself assigned here because the Panning is more tricky (must be supported in all backends).

@Ghabry
Copy link
Member

Ghabry commented May 31, 2021

wait, this wasn't added for BGM, is this intentional? Guess BGM needs the same.

@ghost
Copy link

ghost commented May 31, 2021

I'm not sure if BGM is affected as well.

@Ghabry
Copy link
Member

Ghabry commented May 31, 2021

okay then this must be measured before a PR makes sense. Sorry :)

@ghost
Copy link

ghost commented Jun 1, 2021

Did some tests and found out that BGM is affected as well. I have updated my patch now, I can PR it now if you want.

@Ghabry
Copy link
Member

Ghabry commented Jun 1, 2021

Yes please do

@ghost ghost mentioned this issue Jun 1, 2021
@Ghabry
Copy link
Member

Ghabry commented Jul 18, 2021

the actual issue is fixed here. I will create a new one for panning

@Ghabry Ghabry closed this as completed Jul 18, 2021
@carstene1ns carstene1ns added this to the 0.7.0 milestone Jul 19, 2021
Ghabry added a commit to Ghabry/easyrpg-player that referenced this issue Jul 22, 2021
- This currently breaks MIDI except WildMidi (too low volume) because Midi is already logarithmic.
- Remove the lying in GetVolume for Midi because it breaks Fade (starts with 100)

Reopens EasyRPG#2236
Related EasyRPG#2587
Related EasyRPG#2589
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

5 participants