API change: do not use callbacks
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
ecd3ca8420
commit
0d63ad8d32
|
@ -60,25 +60,31 @@ public:
|
|||
}
|
||||
|
||||
|
||||
void gabor_transform(float* audio_block, int audio_block_length, gaborator_transform_callback callback, uintptr_t callback_data) {
|
||||
float* gaborTransform(float* audio_block, int audio_block_length, size_t* return_size, size_t* slice_size) {
|
||||
resultCache.clear();
|
||||
|
||||
if (audio_block == nullptr || audio_block_length == 0) { //finish
|
||||
finish(callback, callback_data);
|
||||
finish();
|
||||
} else {
|
||||
analyze(audio_block, audio_block_length, callback, callback_data);
|
||||
analyze(audio_block, audio_block_length);
|
||||
}
|
||||
|
||||
if(!resultCache.empty()){
|
||||
callback(callback_data, resultCache.data(), resultCache.size(), static_cast<int>(numberOfBandsCache));
|
||||
}
|
||||
*return_size = resultCache.size();
|
||||
*slice_size = numberOfBandsCache;
|
||||
return resultCache.data();
|
||||
} else{
|
||||
*return_size = 0;
|
||||
*slice_size = 0;
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
int64_t analysis_support() const {
|
||||
int64_t analysisSupport() const {
|
||||
return latency;
|
||||
}
|
||||
|
||||
int number_of_bands() const {
|
||||
int numberOfBands() const {
|
||||
return numberOfBandsCache;
|
||||
}
|
||||
|
||||
|
@ -86,14 +92,14 @@ public:
|
|||
|
||||
|
||||
private:
|
||||
void analyze(float* audio_block, int audio_block_length, gaborator_transform_callback callback, uintptr_t callback_data){
|
||||
void analyze(float* audio_block, int audio_block_length){
|
||||
analyzer.analyze(audio_block, t_in, t_in + audio_block_length, coefs);
|
||||
|
||||
int64_t st0 = t_in - latency;
|
||||
int64_t st1 = t_in - latency + audio_block_length;
|
||||
|
||||
gaborator::process([&](int band, int64_t audioSampleIndex, std::complex<float>& coef) {
|
||||
gabor_process_entry(band, int(audioSampleIndex), coef);
|
||||
gaborProcessEntry(band, int(audioSampleIndex), coef);
|
||||
}, min_band, INT_MAX, st0, st1, coefs);
|
||||
|
||||
|
||||
|
@ -104,13 +110,13 @@ private:
|
|||
forget_before(analyzer, coefs, t_out - audio_block_length);
|
||||
}
|
||||
|
||||
void finish(gaborator_transform_callback callback, uintptr_t callback_data){
|
||||
void finish(){
|
||||
int64_t st0 = t_in - latency;
|
||||
int64_t st1 = t_in;
|
||||
|
||||
//flush all till latency spot
|
||||
gaborator::process([&](int band, int64_t audioSampleIndex, std::complex<float>& coef) {
|
||||
gabor_process_entry(band, int(audioSampleIndex), coef);
|
||||
gaborProcessEntry(band, int(audioSampleIndex), coef);
|
||||
}, min_band, INT_MAX, st0, st1, coefs);
|
||||
|
||||
//flush remaining
|
||||
|
@ -125,7 +131,7 @@ private:
|
|||
}
|
||||
}
|
||||
|
||||
inline void gabor_process_entry(int band, int sampleIndex, std::complex<float>& coef) {
|
||||
inline void gaborProcessEntry(int band, int sampleIndex, std::complex<float>& coef) {
|
||||
int coefficientIndex = sampleIndex / frequencyBinTimeStepSize;
|
||||
int bandIndex = band - firstBandCache;
|
||||
|
||||
|
@ -185,15 +191,15 @@ uintptr_t gaborator_initialize(int blockSize, double sampleRate, int bandsPerOct
|
|||
}
|
||||
|
||||
int64_t gaborator_analysis_support(uintptr_t ptr) {
|
||||
return reinterpret_cast<Gaborator*>(ptr)->analysis_support();
|
||||
return reinterpret_cast<Gaborator*>(ptr)->analysisSupport();
|
||||
}
|
||||
|
||||
int gaborator_number_of_bands(uintptr_t ptr) {
|
||||
return reinterpret_cast<Gaborator*>(ptr)->number_of_bands();
|
||||
return reinterpret_cast<Gaborator*>(ptr)->numberOfBands();
|
||||
}
|
||||
|
||||
void gaborator_transform(uintptr_t ptr, float* audio_block, int audio_block_length, gaborator_transform_callback callback, uintptr_t callback_data){
|
||||
reinterpret_cast<Gaborator*>(ptr)->gabor_transform(audio_block, audio_block_length, callback, callback_data);
|
||||
float* gaborator_transform(uintptr_t ptr, float* audio_block, int audio_block_length, size_t* return_size, size_t* slice_size){
|
||||
return reinterpret_cast<Gaborator*>(ptr)->gaborTransform(audio_block, audio_block_length, return_size, slice_size);
|
||||
}
|
||||
|
||||
void gaborator_release(uintptr_t ptr) {
|
||||
|
|
|
@ -9,15 +9,13 @@ extern "C" {
|
|||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
typedef void (*gaborator_transform_callback)(uintptr_t callback_data, float* data, size_t size, size_t slice_size);
|
||||
|
||||
uintptr_t gaborator_initialize(int blockSize, double sampleRate, int bandsPerOctave, double minimumFrequency, double referenceFrequency, double maximumFrequency, int stepSize);
|
||||
void gaborator_release(uintptr_t ptr);
|
||||
|
||||
int64_t gaborator_analysis_support(uintptr_t ptr);
|
||||
int gaborator_number_of_bands(uintptr_t ptr);
|
||||
|
||||
void gaborator_transform(uintptr_t ptr, float* audio_block, int audio_block_length, gaborator_transform_callback callback, uintptr_t callback_data);
|
||||
float* gaborator_transform(uintptr_t ptr, float* audio_block, int audio_block_length, size_t* return_size, size_t* slice_size);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
10
test.cpp
10
test.cpp
|
@ -15,20 +15,18 @@ int main() {
|
|||
|
||||
float audioData[BLOCK_SIZE];
|
||||
|
||||
|
||||
size_t return_size, slice_size;
|
||||
while (true){
|
||||
auto read = fread(&audioData[0], sizeof(audioData[0]), sizeof(audioData) / sizeof(audioData[0]), fp);
|
||||
gaborator_transform(ptr, &audioData[0], sizeof(audioData) / sizeof(audioData[0]), [](uintptr_t, float*, size_t, size_t){
|
||||
|
||||
}, 0);
|
||||
gaborator_transform(ptr, &audioData[0], sizeof(audioData) / sizeof(audioData[0]), &return_size, &slice_size);
|
||||
|
||||
if (read < sizeof(audioData) / sizeof(audioData[0])) { //EOF
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
gaborator_transform(ptr, nullptr, 0, [](uintptr_t, float*, size_t, size_t){
|
||||
|
||||
}, 0);
|
||||
gaborator_transform(ptr, nullptr, 0, &return_size, &slice_size);
|
||||
|
||||
fclose(fp);
|
||||
|
||||
|
|
Loading…
Reference in a new issue