From 74fe5fc9628880eafb47ef666220f33827c14791 Mon Sep 17 00:00:00 2001 From: Alexander Eckart Date: Tue, 1 May 2012 19:26:31 +0200 Subject: [PATCH] fixed linebonus calculation, set frames per buffer to 1024 on capturing --- Vocaluxe/Base/CGame.cs | 11 +++++---- Vocaluxe/Base/CSound.cs | 31 ++++++++++++++++-------- Vocaluxe/GameModes/CGameMode.cs | 8 +++++- Vocaluxe/Lib/Song/CNotes.cs | 22 +++++++++++++++++ Vocaluxe/Lib/Sound/CPortAudioRecord.cs | 5 ++-- Vocaluxe/Screens/CScreenOptionsRecord.cs | 3 ++- 6 files changed, 61 insertions(+), 19 deletions(-) diff --git a/Vocaluxe/Base/CGame.cs b/Vocaluxe/Base/CGame.cs index ad7e490d..f19523d3 100644 --- a/Vocaluxe/Base/CGame.cs +++ b/Vocaluxe/Base/CGame.cs @@ -379,11 +379,12 @@ namespace Vocaluxe.Base } // Line Bonus - if (Note == lines[Line].NoteCount - 1) + int NumLinesWithPoints = song.Notes.GetNumLinesWithPoints(_Player[p].LineNr); + if (Note == lines[Line].NoteCount - 1 && NumLinesWithPoints > 0) { - if (notes[Note].EndBeat == beat) + if (notes[Note].EndBeat == beat && lines[Line].Points > 0f) { - double factor = (double)_Player[p].SingLine[Line].Points / (double)song.Notes.GetPoints(_Player[p].LineNr); + double factor = (double)_Player[p].SingLine[Line].Points / (double)lines[Line].Points; if (factor < 0.4) factor = 0.0; else if (factor > 0.9) @@ -394,8 +395,8 @@ namespace Vocaluxe.Base factor *= 2; factor *= factor; } - - double points = CSettings.LinebonusScore * factor; + + double points = CSettings.LinebonusScore * factor * 1f / NumLinesWithPoints; _Player[p].Points += points; _Player[p].PointsLineBonus += points; } diff --git a/Vocaluxe/Base/CSound.cs b/Vocaluxe/Base/CSound.cs index 4268cb57..ba987212 100644 --- a/Vocaluxe/Base/CSound.cs +++ b/Vocaluxe/Base/CSound.cs @@ -295,7 +295,7 @@ namespace Vocaluxe.Base private const int _NumHalfTones = 47; private float[] _ToneWeigth; - private Int16[] _AnalysisBuffer = new Int16[4096 * 4]; + private Int16[] _AnalysisBuffer = new Int16[4096]; private Object _AnalysisBufferLock = new Object(); private bool _ToneValid = false; @@ -414,15 +414,6 @@ namespace Vocaluxe.Base //if (assigned(fVoiceStream)) then //fVoiceStream.WriteData(Buffer, BufferSize); - int BufferOffset = 0; - int SampleCount = (int)Math.Floor(buffer.Length / 2.0); - - if (SampleCount > _AnalysisBuffer.Length) - { - BufferOffset = (SampleCount - _AnalysisBuffer.Length) * 2; - SampleCount = _AnalysisBuffer.Length; - } - lock (_AnalysisBufferLock) { Add(buffer); @@ -500,7 +491,10 @@ namespace Vocaluxe.Base double CurWeight = AnalyzeAutocorrelationFreq(CurFreq); if (CurWeight > MaxWeight) + { MaxWeight = CurWeight; + MaxTone = ToneIndex; + } if (CurWeight < MinWeight) MinWeight = CurWeight; @@ -508,6 +502,21 @@ namespace Vocaluxe.Base Weigth[ToneIndex] = (float)CurWeight; } + if (valid && MaxWeight - MinWeight > 0.01) + { + for (int i = 0; i < Weigth.Length; i++) + { + _ToneWeigth[i] = Weigth[i]; + } + + _ToneAbs = MaxTone; + _Tone = MaxTone % 12; + _ToneValid = true; + } + else + _ToneValid = false; + + /* if (valid && MaxWeight - MinWeight > 0.01) { int m = -1; @@ -537,9 +546,11 @@ namespace Vocaluxe.Base } else _ToneValid = false; + } else _ToneValid = false; + * */ } private double AnalyzeAutocorrelationFreq(double Freq) diff --git a/Vocaluxe/GameModes/CGameMode.cs b/Vocaluxe/GameModes/CGameMode.cs index 821178e4..15a534a9 100644 --- a/Vocaluxe/GameModes/CGameMode.cs +++ b/Vocaluxe/GameModes/CGameMode.cs @@ -22,7 +22,9 @@ namespace Vocaluxe.GameModes _Rounds[round, player].ProfileID = Player[player].ProfileID; _Rounds[round, player].Name = Player[player].Name; _Rounds[round, player].Difficulty = Player[player].Difficulty; - _Rounds[round, player].Points = 0; + _Rounds[round, player].Points = 0f; + _Rounds[round, player].PointsGoldenNotes = 0f; + _Rounds[round, player].PointsLineBonus = 0f; _Rounds[round, player].Medley = false; _Rounds[round, player].Duet = false; _Rounds[round, player].SongFinished = false; @@ -38,6 +40,8 @@ namespace Vocaluxe.GameModes _Rounds[Round, player].SongID = SongID; _Rounds[Round, player].LineNr = Player[player].LineNr; _Rounds[Round, player].Points = Player[player].Points; + _Rounds[Round, player].PointsGoldenNotes = Player[player].PointsGoldenNotes; + _Rounds[Round, player].PointsLineBonus = Player[player].PointsLineBonus; _Rounds[Round, player].Medley = Medley; _Rounds[Round, player].Duet = Duet; _Rounds[Round, player].DateTicks = DateTicks; @@ -68,6 +72,8 @@ namespace Vocaluxe.GameModes { player[p].Name = _Rounds[Round, p].Name; player[p].Points = _Rounds[Round, p].Points; + player[p].PointsGoldenNotes = _Rounds[Round, p].PointsGoldenNotes; + player[p].PointsLineBonus = _Rounds[Round, p].PointsLineBonus; player[p].SongID = _Rounds[Round, p].SongID; player[p].LineNr = _Rounds[Round, p].LineNr; player[p].Difficulty = _Rounds[Round, p].Difficulty; diff --git a/Vocaluxe/Lib/Song/CNotes.cs b/Vocaluxe/Lib/Song/CNotes.cs index 43bb7a29..edd3b6d3 100644 --- a/Vocaluxe/Lib/Song/CNotes.cs +++ b/Vocaluxe/Lib/Song/CNotes.cs @@ -33,6 +33,14 @@ namespace Vocaluxe.Lib.Song return _Lines[Index].Points; } + public int GetNumLinesWithPoints(int Index) + { + if (Index >= _Lines.Count) + return 0; + + return _Lines[Index].NumLinesWithPoints; + } + public void AddLines(CLines Lines) { _Lines.Add(Lines); @@ -545,6 +553,20 @@ namespace Vocaluxe.Lib.Song } } + public int NumLinesWithPoints + { + get + { + int num = 0; + foreach (CLine line in _Lines) + { + if (line.Points > 0f) + num++; + } + return num; + } + } + #region Methods public void AddLine(CLine Line) { diff --git a/Vocaluxe/Lib/Sound/CPortAudioRecord.cs b/Vocaluxe/Lib/Sound/CPortAudioRecord.cs index d61e06bc..4ebedf32 100644 --- a/Vocaluxe/Lib/Sound/CPortAudioRecord.cs +++ b/Vocaluxe/Lib/Sound/CPortAudioRecord.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.IO; using System.Runtime.InteropServices; using System.Text; @@ -90,6 +91,7 @@ namespace Vocaluxe.Lib.Sound CLog.LogError("Error initializing PortAudio: " + e.Message); return false; } + return true; } @@ -151,7 +153,7 @@ namespace Vocaluxe.Lib.Sound ref inputParams, IntPtr.Zero, 44100, - PortAudio.paFramesPerBufferUnspecified, + 1024, PortAudio.PaStreamFlags.paNoFlag, _myRecProc, new IntPtr(i)))) @@ -161,7 +163,6 @@ namespace Vocaluxe.Lib.Sound return false; } } - return result; } diff --git a/Vocaluxe/Screens/CScreenOptionsRecord.cs b/Vocaluxe/Screens/CScreenOptionsRecord.cs index 79b9985d..2198e506 100644 --- a/Vocaluxe/Screens/CScreenOptionsRecord.cs +++ b/Vocaluxe/Screens/CScreenOptionsRecord.cs @@ -256,7 +256,8 @@ namespace Vocaluxe.Screens _DelayTest[i].Timer.Stop(); _DelayTestRunning = false; } - else if (CSound.RecordGetMaxVolume(player - 1) > 0.4f && CSound.RecordGetToneAbs(player - 1) == 9) + else if (CSound.RecordGetMaxVolume(player - 1) > 0.1f && + (CSound.RecordGetToneAbs(player - 1) == 9 || CSound.RecordGetToneAbs(player - 1) == 21 || CSound.RecordGetToneAbs(player - 1) == 33)) { _DelayTest[i].Delay = _DelayTest[i].Timer.ElapsedMilliseconds; _DelayTest[i].Timer.Stop();