From 2c4e0d87081250187dd1d2aae28d347ba52bb64a Mon Sep 17 00:00:00 2001 From: Alexander Eckart Date: Mon, 30 Apr 2012 14:25:15 +0200 Subject: [PATCH] some more test with pitch detection, new line bonus calculation --- Vocaluxe/Base/CGame.cs | 48 +++++++++++++++++++------ Vocaluxe/Base/CSound.cs | 77 +++++++++++++++++++++-------------------- 2 files changed, 77 insertions(+), 48 deletions(-) diff --git a/Vocaluxe/Base/CGame.cs b/Vocaluxe/Base/CGame.cs index 25d8ac8f..ad7e490d 100644 --- a/Vocaluxe/Base/CGame.cs +++ b/Vocaluxe/Base/CGame.cs @@ -16,6 +16,8 @@ namespace Vocaluxe.Base public string Name; public EGameDifficulty Difficulty; public double Points; + public double PointsLineBonus; + public double PointsGoldenNotes; public int NoteDiff; public int LineNr; public List SingLine; @@ -213,6 +215,8 @@ namespace Vocaluxe.Base for (int i = 0; i < _Player.Length; i++) { _Player[i].Points = 0f; + _Player[i].PointsLineBonus = 0f; + _Player[i].PointsGoldenNotes = 0f; _Player[i].LineNr = 0; _Player[i].NoteDiff = 0; _Player[i].SingLine = new List(); @@ -247,7 +251,7 @@ namespace Vocaluxe.Base CSound.AnalyzeBuffer(p); } - if (_OldBeatD == _CurrentBeatD) + if (_OldBeatD >= _CurrentBeatD) return; for (int p = 0; p < _NumPlayer; p++) @@ -321,8 +325,12 @@ namespace Vocaluxe.Base if (_Player[p].NoteDiff <= (2 - (int)_Player[p].Difficulty)) { // valid - CSound.RecordSetTone(p, Tone); - _Player[p].Points += (CSettings.MaxScore - CSettings.LinebonusScore) * (double)notes[Note].PointsForBeat / (double)song.Notes.GetLines(_Player[p].LineNr).Points; + //CSound.RecordSetTone(p, Tone); + double points = (CSettings.MaxScore - CSettings.LinebonusScore) * (double)notes[Note].PointsForBeat / (double)song.Notes.GetLines(_Player[p].LineNr).Points; + if (notes[Note].NoteType == ENoteType.Golden) + _Player[p].PointsGoldenNotes += points; + + _Player[p].Points += points; // update player notes (sung notes) if (_Player[p].SingLine[Line].NoteCount > 0) @@ -342,11 +350,6 @@ namespace Vocaluxe.Base _Player[p].SingLine[Line].LastNote.IsPerfect(notes[Note]); _Player[p].SingLine[Line].IsPerfect(lines[Line]); - - if (_Player[p].SingLine[Line].PerfectLine) - { - _Player[p].Points += CSettings.LinebonusScore * (double)lines[Line].Points / (double)song.Notes.GetPoints(_Player[p].LineNr); - } } else { @@ -354,7 +357,7 @@ namespace Vocaluxe.Base { CNote nt = _Player[p].SingLine[Line].LastNote; if (nt.EndBeat + 1 != beat || nt.Hit) - _Player[p].SingLine[Line].AddNote(new CNote(beat, 1, TonePlayer, String.Empty, false, notes[Note].NoteType)); + _Player[p].SingLine[Line].AddNote(new CNote(beat, 1, TonePlayer, String.Empty, false, ENoteType.Freestyle)); else { if (nt.Tone == TonePlayer && nt.EndBeat + 1 == beat) @@ -363,17 +366,40 @@ namespace Vocaluxe.Base } else { - _Player[p].SingLine[Line].AddNote(new CNote(beat, 1, TonePlayer, String.Empty, false, notes[Note].NoteType)); + _Player[p].SingLine[Line].AddNote(new CNote(beat, 1, TonePlayer, String.Empty, false, ENoteType.Freestyle)); } } } else { - _Player[p].SingLine[Line].AddNote(new CNote(beat, 1, TonePlayer, String.Empty, false, notes[Note].NoteType)); + _Player[p].SingLine[Line].AddNote(new CNote(beat, 1, TonePlayer, String.Empty, false, ENoteType.Freestyle)); } } } + + // Line Bonus + if (Note == lines[Line].NoteCount - 1) + { + if (notes[Note].EndBeat == beat) + { + double factor = (double)_Player[p].SingLine[Line].Points / (double)song.Notes.GetPoints(_Player[p].LineNr); + if (factor < 0.4) + factor = 0.0; + else if (factor > 0.9) + factor = 1.0; + else + { + factor -= 0.4; + factor *= 2; + factor *= factor; + } + + double points = CSettings.LinebonusScore * factor; + _Player[p].Points += points; + _Player[p].PointsLineBonus += points; + } + } } } diff --git a/Vocaluxe/Base/CSound.cs b/Vocaluxe/Base/CSound.cs index 101e5da4..4268cb57 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*2]; + private Int16[] _AnalysisBuffer = new Int16[4096 * 4]; private Object _AnalysisBufferLock = new Object(); private bool _ToneValid = false; @@ -425,30 +425,25 @@ namespace Vocaluxe.Base lock (_AnalysisBufferLock) { - try - { - // move old samples to the beginning of the array (if necessary) - for (int i = 0; i < _AnalysisBuffer.Length - SampleCount; i++) - { - _AnalysisBuffer[i] = _AnalysisBuffer[i + SampleCount]; - } - - byte[] b = new byte[2]; - // copy new samples to analysis buffer - for (int i = 0; i < SampleCount; i++) - { - b[0] = buffer[BufferOffset + i * 2]; - b[1] = buffer[BufferOffset + i * 2 + 1]; - - _AnalysisBuffer[_AnalysisBuffer.Length - SampleCount + i] = BitConverter.ToInt16(b, 0); - } - } - catch (Exception) - { - - } Add(buffer); - _NewSamples = true; + + int len = _AnalysisBuffer.Length * 2; + if (_Stream.Length >= len) + { + byte[] buf = new byte[len]; + _Stream.Position -= len; + _Stream.Read(buf, 0, len); + + byte[] b = new byte[2]; + for (int i = 0; i < _AnalysisBuffer.Length; i++) + { + b[0] = buf[i * 2]; + b[1] = buf[i * 2 + 1]; + + _AnalysisBuffer[i] = BitConverter.ToInt16(b, 0); + } + _NewSamples = true; + } } } @@ -470,7 +465,7 @@ namespace Vocaluxe.Base _MaxVolume = Volume; } - if (_MaxVolume >= 0.05f) + if (_MaxVolume >= 0.02f) AnalyzeByAutocorrelation(true); else AnalyzeByAutocorrelation(false); @@ -513,27 +508,35 @@ namespace Vocaluxe.Base Weigth[ToneIndex] = (float)CurWeight; } - if (valid && MaxWeight - MinWeight > 0.05) + if (valid && MaxWeight - MinWeight > 0.01) { int m = -1; - float prev = 0f; + float prev = -1f; + bool raising = false; for (int i = 0; i < Weigth.Length; i++) { - if (Weigth[i] < prev && i > 0) - { - m = i; - MaxTone = i; - } + if (i > 0 && Weigth[i] > prev) + raising = true; - if (i == Weigth.Length - 1 && m == -1) - MaxTone = i; + if (Weigth[i] < prev && raising) + { + m = i-1; + MaxTone = i-1; + raising = false; + } prev = Weigth[i]; _ToneWeigth[i] = Weigth[i]; } - _ToneAbs = MaxTone; - _Tone = MaxTone % 12; - _ToneValid = true; + + if (m != -1) + { + _ToneAbs = MaxTone; + _Tone = MaxTone % 12; + _ToneValid = true; + } + else + _ToneValid = false; } else _ToneValid = false;