From d57d43c7c84fb7c7bc881fc52e4180c308731ff5 Mon Sep 17 00:00:00 2001 From: Alexander Eckart Date: Sun, 4 Mar 2012 20:59:30 +0100 Subject: [PATCH] added AudioLatency and AudioBufferSize to config --- Vocaluxe/Base/CConfig.cs | 30 +++++++++++++++++++++++++++- Vocaluxe/Lib/Sound/CPortAudioPlay.cs | 4 ++-- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/Vocaluxe/Base/CConfig.cs b/Vocaluxe/Base/CConfig.cs index 1aad119c..975a7d7f 100644 --- a/Vocaluxe/Base/CConfig.cs +++ b/Vocaluxe/Base/CConfig.cs @@ -66,6 +66,19 @@ namespace Vocaluxe.Base TR_CONFIG_LEVEL_MAX //all debug infos } + public enum EBufferSize + { + b0 = 0, + b512 = 512, + b1024 = 1024, + b1536 = 1536, + b2048 = 2048, + b2560 = 2560, + b3072 = 3072, + b3584 = 3584, + b4096 = 4096 + } + public enum EPlaybackLib { PortAudio, @@ -177,7 +190,8 @@ namespace Vocaluxe.Base // Sound public static EPlaybackLib PlayBackLib = EPlaybackLib.PortAudio; public static ERecordLib RecordLib = ERecordLib.PortAudio; - public static uint PortAudioBufferSize = 1024; + public static EBufferSize AudioBufferSize = EBufferSize.b2048; + public static int AudioLatency = 200; public static int BackgroundMusicVolume = 50; public static EOffOn BackgroundMusic = EOffOn.TR_CONFIG_ON; public static EBackgroundMusicSource BackgroundMusicSource = EBackgroundMusicSource.TR_CONFIG_NO_OWN_MUSIC; @@ -286,6 +300,14 @@ namespace Vocaluxe.Base #region Sound CHelper.TryGetEnumValueFromXML("//root/Sound/PlayBackLib", navigator, ref PlayBackLib); CHelper.TryGetEnumValueFromXML("//root/Sound/RecordLib", navigator, ref RecordLib); + CHelper.TryGetEnumValueFromXML("//root/Sound/AudioBufferSize", navigator, ref AudioBufferSize); + + CHelper.TryGetIntValueFromXML("//root/Sound/AudioLatency", navigator, ref AudioLatency); + if (AudioLatency < -500) + AudioLatency = -500; + if (AudioLatency > 500) + AudioLatency = 500; + CHelper.TryGetEnumValueFromXML("//root/Sound/BackgroundMusic", navigator, ref BackgroundMusic); CHelper.TryGetIntValueFromXML("//root/Sound/BackgroundMusicVolume", navigator, ref BackgroundMusicVolume); CHelper.TryGetEnumValueFromXML("//root/Sound/BackgroundMusicSource", navigator, ref BackgroundMusicSource); @@ -480,6 +502,12 @@ namespace Vocaluxe.Base writer.WriteComment("RecordLib: " + ListStrings(Enum.GetNames(typeof(ERecordLib)))); writer.WriteElementString("RecordLib", Enum.GetName(typeof(ERecordLib), RecordLib)); + writer.WriteComment("AudioBufferSize: " + ListStrings(Enum.GetNames(typeof(EBufferSize)))); + writer.WriteElementString("AudioBufferSize", Enum.GetName(typeof(EBufferSize), AudioBufferSize)); + + writer.WriteComment("AudioLatency from -500 to 500 ms"); + writer.WriteElementString("AudioLatency", AudioLatency.ToString()); + writer.WriteComment("Background Music"); writer.WriteElementString("BackgroundMusicEnabled", Enum.GetName(typeof(EOffOn), BackgroundMusic)); diff --git a/Vocaluxe/Lib/Sound/CPortAudioPlay.cs b/Vocaluxe/Lib/Sound/CPortAudioPlay.cs index d39c6942..334ba25b 100644 --- a/Vocaluxe/Lib/Sound/CPortAudioPlay.cs +++ b/Vocaluxe/Lib/Sound/CPortAudioPlay.cs @@ -620,7 +620,7 @@ namespace Vocaluxe.Lib.Sound IntPtr.Zero, ref outputParams, format.SamplesPerSecond, - 0,//CConfig.PortAudioBufferSize, + (uint)CConfig.AudioBufferSize, PortAudio.PaStreamFlags.paNoFlag, _paStreamCallback, data)); @@ -844,7 +844,7 @@ namespace Vocaluxe.Lib.Sound else _waiting = true; - float latency = buf.Length / _BytesPerSecond; + float latency = buf.Length / _BytesPerSecond + CConfig.AudioLatency/1000f; float time = _TimeCode - _data.BytesNotRead / _BytesPerSecond - latency; _CurrentTime = _SyncTimer.Update(time);