Add test, fix init
This commit is contained in:
parent
5302c67a2f
commit
9140efed75
|
@ -22,9 +22,13 @@ include_directories(include)
|
||||||
include_directories(lib/gaborator)
|
include_directories(lib/gaborator)
|
||||||
include_directories(lib/pffft)
|
include_directories(lib/pffft)
|
||||||
|
|
||||||
|
add_executable(test test.cpp)
|
||||||
add_library(cgaborator SHARED cgaborator.cpp lib/pffft/pffft.c lib/pffft/fftpack.c)
|
add_library(cgaborator SHARED cgaborator.cpp lib/pffft/pffft.c lib/pffft/fftpack.c)
|
||||||
set_target_properties(cgaborator PROPERTIES PUBLIC_HEADER "include/cgaborator.h")
|
set_target_properties(cgaborator PROPERTIES PUBLIC_HEADER "include/cgaborator.h")
|
||||||
|
|
||||||
|
target_link_libraries(test cgaborator)
|
||||||
|
add_test(test test)
|
||||||
|
|
||||||
set(target1 cgaborator)
|
set(target1 cgaborator)
|
||||||
|
|
||||||
set(pc_libs_private)
|
set(pc_libs_private)
|
||||||
|
|
|
@ -19,7 +19,7 @@ struct GaboratorState {
|
||||||
float cArray[C_ARRAY_SIZE];
|
float cArray[C_ARRAY_SIZE];
|
||||||
};
|
};
|
||||||
|
|
||||||
void* gaborator_initialize(int blockSize, double sampleRate, int bandsPerOctave, double minimumFrequency, double maximumFrequency, double referenceFrequency){
|
void* gaborator_initialize(double sampleRate, int bandsPerOctave, double minimumFrequency, double maximumFrequency, double referenceFrequency){
|
||||||
|
|
||||||
auto state = new GaboratorState();
|
auto state = new GaboratorState();
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ void* gaborator_initialize(int blockSize, double sampleRate, int bandsPerOctave,
|
||||||
|
|
||||||
//converts frequency (ff_max) in hertz to the number of bands above the min frequency
|
//converts frequency (ff_max) in hertz to the number of bands above the min frequency
|
||||||
//the ceil is used to end up at a full band
|
//the ceil is used to end up at a full band
|
||||||
int interesting_bands = ceil(bandsPerOctave * log(maximumFrequency/sampleRate)/log(2.0f));
|
int interesting_bands = ceil(bandsPerOctave * log(maximumFrequency/minimumFrequency)/log(2.0f));
|
||||||
|
|
||||||
//since bands are ordered from high to low we are only interested in lower bands:
|
//since bands are ordered from high to low we are only interested in lower bands:
|
||||||
//fs/2.0 is the nyquist frequency
|
//fs/2.0 is the nyquist frequency
|
||||||
|
@ -86,7 +86,7 @@ void gaborator_analyze(void* ptr, float* audio_block, int audio_block_length) {
|
||||||
|
|
||||||
float* gaborator_get_array(void* ptr) {
|
float* gaborator_get_array(void* ptr) {
|
||||||
auto state = reinterpret_cast<GaboratorState*>(ptr);
|
auto state = reinterpret_cast<GaboratorState*>(ptr);
|
||||||
return state->cArray;
|
return &state->cArray[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
int gaborator_get_array_length(void* ptr) {
|
int gaborator_get_array_length(void* ptr) {
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void* gaborator_initialize(int blockSize, double sampleRate, int bandsPerOctave, double minimumFrequency, double maximumFrequency, double referenceFrequency);
|
void* gaborator_initialize(double sampleRate, int bandsPerOctave, double minimumFrequency, double maximumFrequency, double referenceFrequency);
|
||||||
long gaborator_get_anal_support(void* ptr);
|
long gaborator_get_anal_support(void* ptr);
|
||||||
|
|
||||||
void gaborator_analyze(void* ptr, float* audio_block, int audio_block_length);
|
void gaborator_analyze(void* ptr, float* audio_block, int audio_block_length);
|
||||||
|
|
34
test.cpp
Normal file
34
test.cpp
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
#include "cgaborator.h"
|
||||||
|
#include <cstdio>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#define BLOCK_SIZE 8192
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
|
||||||
|
auto fp = fopen("test.raw", "r");
|
||||||
|
|
||||||
|
if (fp == nullptr){
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto ptr = gaborator_initialize(16000, 85, 110, 7040, 440);
|
||||||
|
if (ptr == nullptr){
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
float audioData[BLOCK_SIZE];
|
||||||
|
|
||||||
|
while (true){
|
||||||
|
auto read = fread(&audioData[0], sizeof(audioData[0]), sizeof(audioData) / sizeof(audioData[0]), fp);
|
||||||
|
if (read < sizeof(audioData) / sizeof(audioData[0])) { //EOF
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
gaborator_analyze(ptr, &audioData[0], sizeof(audioData) / sizeof(audioData[0]));
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose(fp);
|
||||||
|
|
||||||
|
gaborator_release(ptr);
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in a new issue