Fix Testcase
Add commented implementation of new detector (need to decide)
This commit is contained in:
1 parent
94c7f68688
commit
e54892391f
3 files changed
+38
-9
No files matched your search
@@ -27,6 +27,15 @@ namespace Native{
|
|||||||
freeFloatArray(dataFloat);
|
freeFloatArray(dataFloat);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CAnalyzer::Input(array<Byte>^ data){
|
||||||
|
if(data->Length == 0)
|
||||||
|
return;
|
||||||
|
pin_ptr<Byte> dataPtr = &data[0];
|
||||||
|
float* dataFloat = short2FloatArray(static_cast<short*>(static_cast<void*>(dataPtr)), data->Length);
|
||||||
|
m_analyzer->input(dataFloat, dataFloat + data->Length);
|
||||||
|
freeFloatArray(dataFloat);
|
||||||
|
}
|
||||||
|
|
||||||
void CAnalyzer::Process(){
|
void CAnalyzer::Process(){
|
||||||
m_analyzer->process();
|
m_analyzer->process();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ namespace Native{
|
|||||||
|
|
||||||
void Input(array<float>^ data);
|
void Input(array<float>^ data);
|
||||||
void Input(array<short>^ data);
|
void Input(array<short>^ data);
|
||||||
|
void Input(array<Byte>^ data);
|
||||||
void Process();
|
void Process();
|
||||||
double GetPeak();
|
double GetPeak();
|
||||||
array<CTone^>^ GetTones();
|
array<CTone^>^ GetTones();
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ using System.IO;
|
|||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
#if USE_NATIVE_DETECTION
|
#if USE_NATIVE_DETECTION
|
||||||
using Native.PitchTracking;
|
using Native.PitchTracking;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
#if TEST_PITCH
|
#if TEST_PITCH
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
@@ -72,6 +73,8 @@ namespace Vocaluxe.Lib.Sound.Record
|
|||||||
private DAnalyzeTone _AnalyzeToneFunc;
|
private DAnalyzeTone _AnalyzeToneFunc;
|
||||||
private double _MinWeightDiff;
|
private double _MinWeightDiff;
|
||||||
// ReSharper restore FieldCanBeMadeReadOnly.Local
|
// ReSharper restore FieldCanBeMadeReadOnly.Local
|
||||||
|
#else
|
||||||
|
private readonly CAnalyzer _Analyzer = new CAnalyzer(44100.0, "");
|
||||||
#endif
|
#endif
|
||||||
private double _MaxVolume;
|
private double _MaxVolume;
|
||||||
private bool _NewSamples;
|
private bool _NewSamples;
|
||||||
@@ -173,6 +176,7 @@ namespace Vocaluxe.Lib.Sound.Record
|
|||||||
_Add(buffer);
|
_Add(buffer);
|
||||||
_NewSamples = true;
|
_NewSamples = true;
|
||||||
}
|
}
|
||||||
|
//_Analyzer.Input(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AnalyzeBuffer()
|
public void AnalyzeBuffer()
|
||||||
@@ -180,6 +184,19 @@ namespace Vocaluxe.Lib.Sound.Record
|
|||||||
if (!_NewSamples)
|
if (!_NewSamples)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
/*_NewSamples = false;
|
||||||
|
_Analyzer.Process();
|
||||||
|
_MaxVolume = _Analyzer.GetPeak() / 43 + 1;
|
||||||
|
CTone tone = _Analyzer.FindTone();
|
||||||
|
if (tone != null)
|
||||||
|
{
|
||||||
|
ToneAbs = tone.Note;
|
||||||
|
Tone = ToneAbs % 12;
|
||||||
|
ToneValid = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
ToneValid = false;*/
|
||||||
|
|
||||||
lock (_Stream)
|
lock (_Stream)
|
||||||
{
|
{
|
||||||
if (_Stream.Length >= _AnalysisByteBufLen)
|
if (_Stream.Length >= _AnalysisByteBufLen)
|
||||||
@@ -360,11 +377,12 @@ namespace Vocaluxe.Lib.Sound.Record
|
|||||||
Console.WriteLine("Testing notes " + _ToneToNote(toneFrom) + " - " + _ToneToNote(toneTo));
|
Console.WriteLine("Testing notes " + _ToneToNote(toneFrom) + " - " + _ToneToNote(toneTo));
|
||||||
byte[] data;
|
byte[] data;
|
||||||
int ok = 0;
|
int ok = 0;
|
||||||
|
double angle = 0;
|
||||||
for (int distort = 0; distort < 10; distort++)
|
for (int distort = 0; distort < 10; distort++)
|
||||||
{
|
{
|
||||||
for (int tone = toneFrom; tone <= toneTo; tone++)
|
for (int tone = toneFrom; tone <= toneTo; tone++)
|
||||||
{
|
{
|
||||||
_GetSineWave(_BaseToneFreq * Math.Pow(_HalftoneBase, tone), 44100, out data);
|
_GetSineWave(_BaseToneFreq * Math.Pow(_HalftoneBase, tone), 44100, ref angle, out data);
|
||||||
_Distort(data, tone, distort);
|
_Distort(data, tone, distort);
|
||||||
|
|
||||||
ProcessNewBuffer(data);
|
ProcessNewBuffer(data);
|
||||||
@@ -377,7 +395,7 @@ namespace Vocaluxe.Lib.Sound.Record
|
|||||||
ok++;
|
ok++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_GetSineWave(_BaseToneFreq * Math.Pow(_HalftoneBase, 5), 44100, out data);
|
_GetSineWave(_BaseToneFreq * Math.Pow(_HalftoneBase, 5), 44100, ref angle, out data);
|
||||||
ProcessNewBuffer(data);
|
ProcessNewBuffer(data);
|
||||||
AnalyzeBuffer();
|
AnalyzeBuffer();
|
||||||
Stopwatch sw = new Stopwatch();
|
Stopwatch sw = new Stopwatch();
|
||||||
@@ -385,10 +403,8 @@ namespace Vocaluxe.Lib.Sound.Record
|
|||||||
const int repeats = 2000;
|
const int repeats = 2000;
|
||||||
for (int i = 0; i < repeats; i++)
|
for (int i = 0; i < repeats; i++)
|
||||||
{
|
{
|
||||||
//ProcessNewBuffer(data);
|
ProcessNewBuffer(data);
|
||||||
//AnalyzeBuffer();
|
AnalyzeBuffer();
|
||||||
_FindMaxVolume();
|
|
||||||
_AnalyzeTones();
|
|
||||||
}
|
}
|
||||||
sw.Stop();
|
sw.Stop();
|
||||||
string msg = "Analyser: Errors: " + ((toneTo - toneFrom + 1) * 10 - ok) + "; Speed: " +
|
string msg = "Analyser: Errors: " + ((toneTo - toneFrom + 1) * 10 - ok) + "; Speed: " +
|
||||||
@@ -435,7 +451,8 @@ namespace Vocaluxe.Lib.Sound.Record
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
byte[] data2;
|
byte[] data2;
|
||||||
_GetSineWave(_BaseToneFreq * Math.Pow(_HalftoneBase, tone + newTone), 44100, out data2);
|
double angle = 0;
|
||||||
|
_GetSineWave(_BaseToneFreq * Math.Pow(_HalftoneBase, tone + newTone), 44100, ref angle, out data2);
|
||||||
Buffer.BlockCopy(data2, 0, sdata, 0, len * 2);
|
Buffer.BlockCopy(data2, 0, sdata, 0, len * 2);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -469,13 +486,15 @@ namespace Vocaluxe.Lib.Sound.Record
|
|||||||
Buffer.BlockCopy(sdata, 0, data, 0, data.Length);
|
Buffer.BlockCopy(sdata, 0, data, 0, data.Length);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void _GetSineWave(double freq, int sampleRate, out byte[] data)
|
private static void _GetSineWave(double freq, int sampleRate, ref double angle, out byte[] data)
|
||||||
{
|
{
|
||||||
const short max = short.MaxValue;
|
const short max = short.MaxValue;
|
||||||
const int len = _AnalysisBufLen; //sampleRate * durationMs / 1000;
|
const int len = _AnalysisBufLen; //sampleRate * durationMs / 1000;
|
||||||
short[] data16Bit = new short[len];
|
short[] data16Bit = new short[len];
|
||||||
for (int i = 0; i < len; i++)
|
for (int i = 0; i < len; i++)
|
||||||
data16Bit[i] = (short)(Math.Sin(2 * Math.PI * i / sampleRate * freq) * max);
|
data16Bit[i] = (short)(Math.Sin(2 * Math.PI * i / sampleRate * freq + angle) * max);
|
||||||
|
angle = 2 * Math.PI * len / sampleRate * freq + angle;
|
||||||
|
angle = angle % (2 * Math.PI);
|
||||||
data = new byte[data16Bit.Length * 2];
|
data = new byte[data16Bit.Length * 2];
|
||||||
Buffer.BlockCopy(data16Bit, 0, data, 0, data.Length);
|
Buffer.BlockCopy(data16Bit, 0, data, 0, data.Length);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user