Add test, fix init

This commit is contained in:
DataHoarder 2022-01-25 13:59:02 +01:00
parent 5302c67a2f
commit 9140efed75
5 changed files with 42 additions and 4 deletions

View file

@ -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)

View file

@ -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<GaboratorState*>(ptr);
return state->cArray;
return &state->cArray[0];
}
int gaborator_get_array_length(void* ptr) {

View file

@ -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);

34
test.cpp Normal file
View 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;
}

BIN
test.raw Normal file

Binary file not shown.