1
0
mirror of synced 2024-12-20 03:15:55 +01:00
OpenTaiko/FDK19/コード/03.サウンド/SongGainController.cs

33 lines
1.2 KiB
C#
Raw Normal View History

2021-09-21 00:16:38 +02:00
namespace FDK
{
/// <summary>
/// SongGainController provides a central place through which song preview
/// and song playback attempt to apply BS1770GAIN-based loudness metadata
/// or .tja SONGVOL as the Gain of a song sound.
///
/// By doing so through SongGainController instead of directly against the
/// song (preview) CSound object, SongGainController can override the Gain
/// value based on configuration or other information.
/// </summary>
public sealed class SongGainController
{
public bool ApplyLoudnessMetadata { private get; set; }
public Lufs TargetLoudness { private get; set; }
public bool ApplySongVol { private get; set; }
public void Set(int songVol, LoudnessMetadata? songLoudnessMetadata, CSound sound)
{
if (ApplyLoudnessMetadata && songLoudnessMetadata.HasValue)
{
var gain = TargetLoudness - songLoudnessMetadata.Value.Integrated;
sound.SetGain(gain, songLoudnessMetadata.Value.TruePeak);
}
else
{
sound.SetGain(ApplySongVol ? songVol : CSound.DefaultSongVol);
}
}
}
}