Add another pitch detection algorithm (from Performous) and wrapped everything in c++/cli classes
This commit is contained in:
1 parent
64b4f15281
commit
94c7f68688
18 files changed
+1349
-126
No files matched your search
@@ -0,0 +1,61 @@
|
||||
#pragma once
|
||||
#include "pitch.hh"
|
||||
#include "PitchWrapper.h"
|
||||
|
||||
#pragma managed(push, off)
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <cmath>
|
||||
|
||||
float* short2FloatArray(short* in, size_t len){
|
||||
const float maxShort = 32768.0; //maximum abs value of a short
|
||||
|
||||
float* result = static_cast<float*>(malloc(len * sizeof(float)));
|
||||
float* curOut = result;
|
||||
for(int i=0; i<len; i++){
|
||||
*curOut = *in / maxShort;
|
||||
curOut++;
|
||||
in++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
double* short2DoubleArray(short* in, size_t len, bool scale = true){
|
||||
const double maxShort = 32768.0; //maximum abs value of a short
|
||||
|
||||
double* result = static_cast<double*>(malloc(len * sizeof(double)));
|
||||
double* curOut = result;
|
||||
for(int i=0; i<len; i++){
|
||||
*curOut = *in;
|
||||
if(scale)
|
||||
*curOut /= maxShort;
|
||||
curOut++;
|
||||
in++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void freeFloatArray(float* floats){
|
||||
free(floats);
|
||||
}
|
||||
|
||||
void freeDoubleArray(double* floats){
|
||||
free(floats);
|
||||
}
|
||||
|
||||
#pragma managed(pop)
|
||||
|
||||
namespace Native{
|
||||
namespace PitchTracking{
|
||||
CTone^ ConvertToneToManaged(Tone tone){
|
||||
CTone^ result = gcnew CTone();
|
||||
result->Freq = tone.freq;
|
||||
result->DB = tone.db;
|
||||
result->Stabledb = tone.stabledb;
|
||||
result->Age = static_cast<int>(tone.age);
|
||||
result->NoteExact = 12.0 * std::log(tone.freq / 127.09) / std::log(2.0) + 27.5 - 16; // 16 = C2
|
||||
result->Note = static_cast<int>(std::round(result->NoteExact));
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user