From 614a7e0ed2b97877e7c384e77d4b95a2ee172572 Mon Sep 17 00:00:00 2001 From: Flamefire Date: Mon, 31 Mar 2014 17:55:31 +0200 Subject: [PATCH] Add step size --- PitchTracker/PitchWrapper.cpp | 4 ++-- PitchTracker/PitchWrapper.h | 2 +- PitchTracker/ptAKF.cpp | 4 +++- PitchTracker/ptAKF.h | 3 ++- Vocaluxe/Lib/Sound/Record/CAnalyzer.cs | 6 +++--- 5 files changed, 11 insertions(+), 8 deletions(-) diff --git a/PitchTracker/PitchWrapper.cpp b/PitchTracker/PitchWrapper.cpp index 4fc47b4c..3d725b15 100644 --- a/PitchTracker/PitchWrapper.cpp +++ b/PitchTracker/PitchWrapper.cpp @@ -58,8 +58,8 @@ bool Analyzer_OutputFloat(Analyzer* analyzer, float* data, int sampleCt, float r return analyzer->output(data, data + sampleCt, rate); } -DllExport PtAKF* PtAKF_Create(){ - return new PtAKF(); +DllExport PtAKF* PtAKF_Create(unsigned step){ + return new PtAKF(step); } DllExport void PtAKF_Free(PtAKF* analyzer){ diff --git a/PitchTracker/PitchWrapper.h b/PitchTracker/PitchWrapper.h index d3039bc9..08f32eed 100644 --- a/PitchTracker/PitchWrapper.h +++ b/PitchTracker/PitchWrapper.h @@ -15,7 +15,7 @@ DllExport double Analyzer_GetPeak(Analyzer* analyzer); DllExport double Analyzer_FindNote(Analyzer* analyzer, double minFreq, double maxFreq); DllExport bool Analyzer_OutputFloat(Analyzer* analyzer, float* data, int sampleCt, float rate); -DllExport PtAKF* PtAKF_Create(); +DllExport PtAKF* PtAKF_Create(unsigned step); DllExport void PtAKF_Free(PtAKF* analyzer); DllExport int PtAKF_GetNumHalfTones(); DllExport void PtAKF_InputByte(PtAKF* analyzer, char* data, int sampleCt); diff --git a/PitchTracker/ptAKF.cpp b/PitchTracker/ptAKF.cpp index fd272a6f..b5e8bccb 100644 --- a/PitchTracker/ptAKF.cpp +++ b/PitchTracker/ptAKF.cpp @@ -21,7 +21,7 @@ static constexpr double HalftoneBase = 1.05946309436; // 2^(1/12) -> HalftoneBas int PtAKF::_InitCount = 0; float* PtAKF::_SamplesPerPeriodPerTone = NULL; -PtAKF::PtAKF(){ +PtAKF::PtAKF(unsigned step){ _InitCount++; if(_InitCount == 1){ _SamplesPerPeriodPerTone = new float[_MaxHalfTone + 1]; @@ -32,6 +32,7 @@ PtAKF::PtAKF(){ _SamplesPerPeriodPerTone[toneIndex] = static_cast(44100.0 / freq); // samples in one period } } + _Step = step; } PtAKF::~PtAKF(){ @@ -49,6 +50,7 @@ int PtAKF::GetNote(double* maxVolume, float* weights){ _AnalysisBuf.pop(size - _SampleCt); if(!_AnalysisBuf.read(AnaylsisBuf, AnaylsisBuf + _SampleCt)) return -1; + _AnalysisBuf.pop(_Step); return _GetNote(AnaylsisBuf, maxVolume, weights); } diff --git a/PitchTracker/ptAKF.h b/PitchTracker/ptAKF.h index 240e7aa7..8ddc7c97 100644 --- a/PitchTracker/ptAKF.h +++ b/PitchTracker/ptAKF.h @@ -4,7 +4,7 @@ // A pitch detection that is based on the AKF and AMDF (initially from original Vocaluxe/USDx) class PtAKF{ public: - PtAKF(); + PtAKF(unsigned step); ~PtAKF(); void input(short* begin, short* end){ @@ -21,6 +21,7 @@ private: constexpr static size_t _SampleCt = 4096; RingBuffer<_SampleCt * 2> _AnalysisBuf; + unsigned _Step; static int _GetNote(float* samples, double* maxVolume, float* weights); static float _AnalyzeToneFunc(float* samples, int toneIndex); diff --git a/Vocaluxe/Lib/Sound/Record/CAnalyzer.cs b/Vocaluxe/Lib/Sound/Record/CAnalyzer.cs index 39d79f00..e4e5807c 100644 --- a/Vocaluxe/Lib/Sound/Record/CAnalyzer.cs +++ b/Vocaluxe/Lib/Sound/Record/CAnalyzer.cs @@ -108,7 +108,7 @@ namespace Vocaluxe.Lib.Sound.Record { #region Imports [DllImport("PitchTracker.dll", CallingConvention = CallingConvention.Cdecl)] - private static extern IntPtr PtAKF_Create(); + private static extern IntPtr PtAKF_Create(uint step); [DllImport("PitchTracker.dll", CallingConvention = CallingConvention.Cdecl)] private static extern void PtAKF_Free(IntPtr analyzer); @@ -125,9 +125,9 @@ namespace Vocaluxe.Lib.Sound.Record private IntPtr _Instance; - public CPtAKF() + public CPtAKF(uint step = 200) { - _Instance = PtAKF_Create(); + _Instance = PtAKF_Create(step); } ~CPtAKF()