diff --git a/Vocaluxe/Base/CBackgroundMusic.cs b/Vocaluxe/Base/CBackgroundMusic.cs index ad10b81a..fb3ea35c 100644 --- a/Vocaluxe/Base/CBackgroundMusic.cs +++ b/Vocaluxe/Base/CBackgroundMusic.cs @@ -181,7 +181,7 @@ namespace Vocaluxe.Base { if (_CurrentMusicStream != -1) { - CSound.Fade(_CurrentMusicStream, CConfig.BackgroundMusicVolume, CSettings.BackgroundMusicFadeTime); + CSound.Fade(_CurrentMusicStream, 100f, CSettings.BackgroundMusicFadeTime); CSound.Play(_CurrentMusicStream); if (_VideoEnabled && _Video != -1) CVideo.VdResume(_Video); @@ -276,6 +276,7 @@ namespace Vocaluxe.Base _CurrentPlaylistElement = _PreviousFileNames[_PreviousMusicIndex]; } _CurrentMusicStream = CSound.Load(_CurrentPlaylistElement.MusicFilePath); + CSound.SetStreamVolumeMax(_CurrentMusicStream, CConfig.BackgroundMusicVolume); //Seek to #Start-Tag, if found if (_CurrentPlaylistElement.Start != 0f) @@ -311,6 +312,7 @@ namespace Vocaluxe.Base _CurrentPlaylistElement = _PreviousFileNames[_PreviousMusicIndex]; _CurrentMusicStream = CSound.Load(_CurrentPlaylistElement.MusicFilePath); + CSound.SetStreamVolumeMax(_CurrentMusicStream, CConfig.BackgroundMusicVolume); if (_VideoEnabled) LoadVideo(); CSound.SetStreamVolume(_CurrentMusicStream, 0f); @@ -327,7 +329,7 @@ namespace Vocaluxe.Base public static void ApplyVolume() { - CSound.SetStreamVolume(_CurrentMusicStream, CConfig.BackgroundMusicVolume); + CSound.SetStreamVolumeMax(_CurrentMusicStream, CConfig.BackgroundMusicVolume); } public static void AddOwnMusic() diff --git a/Vocaluxe/Base/CSound.cs b/Vocaluxe/Base/CSound.cs index 986476e9..7f6414d4 100644 --- a/Vocaluxe/Base/CSound.cs +++ b/Vocaluxe/Base/CSound.cs @@ -108,6 +108,10 @@ namespace Vocaluxe.Base _Playback.SetStreamVolume(Stream, Volume); } + public static void SetStreamVolumeMax(int Stream, float Volume) + { + _Playback.SetStreamVolumeMax(Stream, Volume); + } public static float GetLength(int Stream) { diff --git a/Vocaluxe/Lib/Sound/COpenALPlay.cs b/Vocaluxe/Lib/Sound/COpenALPlay.cs index 85e17cd4..18d91b37 100644 --- a/Vocaluxe/Lib/Sound/COpenALPlay.cs +++ b/Vocaluxe/Lib/Sound/COpenALPlay.cs @@ -234,6 +234,21 @@ namespace Vocaluxe.Lib.Sound } } + public void SetStreamVolumeMax(int Stream, float Volume) + { + if (_Initialized) + { + lock (MutexDecoder) + { + if (AlreadyAdded(Stream)) + { + _Decoder[GetStreamIndex(Stream)].VolumeMax = Volume; + } + } + + } + } + public float GetLength(int Stream) { if (_Initialized) @@ -399,6 +414,7 @@ namespace Vocaluxe.Lib.Sound private bool _Initialized; private int _ByteCount = 4; private float _Volume = 1f; + private float _VolumeMax = 1f; private Stopwatch _fadeTimer = new Stopwatch(); @@ -500,6 +516,23 @@ namespace Vocaluxe.Lib.Sound } } + public float VolumeMax + { + get { return _VolumeMax * 100f; } + set + { + lock (MutexData) + { + _VolumeMax = value / 100f; + if (_VolumeMax < 0f) + _VolumeMax = 0f; + + if (_VolumeMax > 1f) + _VolumeMax = 1f; + } + } + } + public float Position { get @@ -826,7 +859,7 @@ namespace Vocaluxe.Lib.Sound b[0] = buf[i]; b[1] = buf[i + 1]; - b = BitConverter.GetBytes((Int16)(BitConverter.ToInt16(b, 0) * _Volume)); + b = BitConverter.GetBytes((Int16)(BitConverter.ToInt16(b, 0) * _Volume * _VolumeMax)); buf[i] = b[0]; buf[i + 1] = b[1]; @@ -835,7 +868,7 @@ namespace Vocaluxe.Lib.Sound b[0] = buf[i + 2]; b[1] = buf[i + 3]; - b = BitConverter.GetBytes((Int16)(BitConverter.ToInt16(b, 0) * _Volume)); + b = BitConverter.GetBytes((Int16)(BitConverter.ToInt16(b, 0) * _Volume * _VolumeMax)); buf[i + 2] = b[0]; buf[i + 3] = b[1]; } diff --git a/Vocaluxe/Lib/Sound/CPortAudioPlay.cs b/Vocaluxe/Lib/Sound/CPortAudioPlay.cs index 6c7ebc7c..ebf80f66 100644 --- a/Vocaluxe/Lib/Sound/CPortAudioPlay.cs +++ b/Vocaluxe/Lib/Sound/CPortAudioPlay.cs @@ -218,6 +218,21 @@ namespace Vocaluxe.Lib.Sound } } + public void SetStreamVolumeMax(int Stream, float Volume) + { + if (_Initialized) + { + lock (MutexDecoder) + { + if (AlreadyAdded(Stream)) + { + _Decoder[GetStreamIndex(Stream)].VolumeMax = Volume; + } + } + + } + } + public float GetLength(int Stream) { if (_Initialized) @@ -375,6 +390,7 @@ namespace Vocaluxe.Lib.Sound private bool _Initialized; private int _ByteCount = 4; private float _Volume = 1f; + private float _VolumeMax = 1f; private Stopwatch _fadeTimer = new Stopwatch(); @@ -480,6 +496,23 @@ namespace Vocaluxe.Lib.Sound } } + public float VolumeMax + { + get { return _VolumeMax * 100f; } + set + { + lock (_LockData) + { + _VolumeMax = value / 100f; + if (_VolumeMax < 0f) + _VolumeMax = 0f; + + if (_VolumeMax > 1f) + _VolumeMax = 1f; + } + } + } + public float Position { get @@ -817,7 +850,7 @@ namespace Vocaluxe.Lib.Sound b[0] = buf[i]; b[1] = buf[i + 1]; - b = BitConverter.GetBytes((Int16)(BitConverter.ToInt16(b, 0) * _Volume)); + b = BitConverter.GetBytes((Int16)(BitConverter.ToInt16(b, 0) * _Volume * _VolumeMax)); buf[i] = b[0]; buf[i + 1] = b[1]; @@ -826,7 +859,7 @@ namespace Vocaluxe.Lib.Sound b[0] = buf[i + 2]; b[1] = buf[i + 3]; - b = BitConverter.GetBytes((Int16)(BitConverter.ToInt16(b, 0) * _Volume)); + b = BitConverter.GetBytes((Int16)(BitConverter.ToInt16(b, 0) * _Volume * _VolumeMax)); buf[i + 2] = b[0]; buf[i + 3] = b[1]; } diff --git a/Vocaluxe/Lib/Sound/IPlayback.cs b/Vocaluxe/Lib/Sound/IPlayback.cs index a1fbd9b1..46fe668e 100644 --- a/Vocaluxe/Lib/Sound/IPlayback.cs +++ b/Vocaluxe/Lib/Sound/IPlayback.cs @@ -37,7 +37,8 @@ namespace Vocaluxe.Lib.Sound void Fade(int Stream, float TargetVolume, float Seconds); void FadeAndPause(int Stream, float TargetVolume, float Seconds); void FadeAndStop(int Stream, float TargetVolume, float Seconds); - void SetStreamVolume(int Stream, float Volume); + void SetStreamVolume(int Stream, float Volume); + void SetStreamVolumeMax(int Stream, float Volume); float GetLength(int Stream); float GetPosition(int Stream); diff --git a/Vocaluxe/Menu/SongMenu/CSongMenu.cs b/Vocaluxe/Menu/SongMenu/CSongMenu.cs index 5e1836d9..3163d783 100644 --- a/Vocaluxe/Menu/SongMenu/CSongMenu.cs +++ b/Vocaluxe/Menu/SongMenu/CSongMenu.cs @@ -73,6 +73,11 @@ namespace Vocaluxe.Menu.SongMenu _SongMenu.Draw(); } + public void ApplyVolume(float VolumeMax) + { + _SongMenu.ApplyVolume(VolumeMax); + } + public bool IsActive() { return _SongMenu.IsActive(); diff --git a/Vocaluxe/Menu/SongMenu/CSongMenuFramework.cs b/Vocaluxe/Menu/SongMenu/CSongMenuFramework.cs index 045ec139..9802f57d 100644 --- a/Vocaluxe/Menu/SongMenu/CSongMenuFramework.cs +++ b/Vocaluxe/Menu/SongMenu/CSongMenuFramework.cs @@ -117,6 +117,8 @@ namespace Vocaluxe.Menu.SongMenu private int _LockedInternal = -1; protected bool _Active = false; + protected float _MaxVolume = 100f; + protected int _PreviewSelected //for preview only { get @@ -510,6 +512,16 @@ namespace Vocaluxe.Menu.SongMenu } + public virtual void ApplyVolume(float VolumeMax) + { + _MaxVolume = VolumeMax; + + foreach (int stream in _streams) + { + CSound.SetStreamVolumeMax(stream, _MaxVolume); + } + } + public virtual bool IsActive() { return _Active; @@ -619,6 +631,7 @@ namespace Vocaluxe.Menu.SongMenu int _stream = CSound.Load(Path.Combine(CSongs.VisibleSongs[_actsong].Folder, CSongs.VisibleSongs[_actsong].MP3FileName), true); + CSound.SetStreamVolumeMax(_stream, _MaxVolume); CSound.SetStreamVolume(_stream, 0f); float startposition = CSongs.VisibleSongs[_actsong].PreviewStart; diff --git a/Vocaluxe/Menu/SongMenu/ISongMenu.cs b/Vocaluxe/Menu/SongMenu/ISongMenu.cs index 8361daba..21d0015a 100644 --- a/Vocaluxe/Menu/SongMenu/ISongMenu.cs +++ b/Vocaluxe/Menu/SongMenu/ISongMenu.cs @@ -17,6 +17,8 @@ namespace Vocaluxe.Menu.SongMenu void HandleMouse(ref MouseEvent MouseEvent); void Draw(); + void ApplyVolume(float VolumeMax); + int GetSelectedSong(); CStatic GetSelectedSongCover(); void SetSelectedSong(int VisibleSongNr); diff --git a/Vocaluxe/Screens/CScreenSing.cs b/Vocaluxe/Screens/CScreenSing.cs index c75081c3..fd814524 100644 --- a/Vocaluxe/Screens/CScreenSing.cs +++ b/Vocaluxe/Screens/CScreenSing.cs @@ -545,6 +545,7 @@ namespace Vocaluxe.Screens Texts[htTexts(TextSongName)].Text = songname; _CurrentStream = CSound.Load(song.GetMP3(), true); + CSound.SetStreamVolumeMax(_CurrentStream, 100f); //TODO: Add volume control var CSound.SetStreamVolume(_CurrentStream, _Volume); CSound.SetPosition(_CurrentStream, song.Start); _CurrentTime = song.Start;