diff --git a/CMakeLists.txt b/CMakeLists.txt index a916fee..6e471ff 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,9 +22,13 @@ include_directories(include) include_directories(lib/gaborator) include_directories(lib/pffft) +add_executable(test test.cpp) add_library(cgaborator SHARED cgaborator.cpp lib/pffft/pffft.c lib/pffft/fftpack.c) set_target_properties(cgaborator PROPERTIES PUBLIC_HEADER "include/cgaborator.h") +target_link_libraries(test cgaborator) +add_test(test test) + set(target1 cgaborator) set(pc_libs_private) diff --git a/cgaborator.cpp b/cgaborator.cpp index 981791d..169dc31 100644 --- a/cgaborator.cpp +++ b/cgaborator.cpp @@ -19,7 +19,7 @@ struct GaboratorState { 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(); @@ -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 //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: //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) { auto state = reinterpret_cast(ptr); - return state->cArray; + return &state->cArray[0]; } int gaborator_get_array_length(void* ptr) { diff --git a/include/cgaborator.h b/include/cgaborator.h index e697951..0668b51 100644 --- a/include/cgaborator.h +++ b/include/cgaborator.h @@ -3,7 +3,7 @@ extern "C" { #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); void gaborator_analyze(void* ptr, float* audio_block, int audio_block_length); diff --git a/test.cpp b/test.cpp new file mode 100644 index 0000000..93f5c5e --- /dev/null +++ b/test.cpp @@ -0,0 +1,34 @@ +#include "cgaborator.h" +#include +#include + +#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; +} \ No newline at end of file diff --git a/test.raw b/test.raw new file mode 100644 index 0000000..d0541d9 Binary files /dev/null and b/test.raw differ