From 808bf021e6f970c2fe2ef059af359018704a8aa7 Mon Sep 17 00:00:00 2001 From: Johannes Schultz Date: Sun, 26 Mar 2023 18:54:04 +0200 Subject: [PATCH] Expose BPM detector beat position and strength retrieval API via SoundTouchDLL. --- source/SoundTouchDLL/SoundTouchDLL.cpp | 18 ++++++++++++++++++ source/SoundTouchDLL/SoundTouchDLL.h | 11 +++++++++++ 2 files changed, 29 insertions(+) diff --git a/source/SoundTouchDLL/SoundTouchDLL.cpp b/source/SoundTouchDLL/SoundTouchDLL.cpp index 28ebfba..6021061 100644 --- a/source/SoundTouchDLL/SoundTouchDLL.cpp +++ b/source/SoundTouchDLL/SoundTouchDLL.cpp @@ -562,3 +562,21 @@ SOUNDTOUCHDLL_API float __cdecl bpm_getBpm(HANDLE h) return bpmh->pbpm->getBpm(); } + + +/// Get beat position arrays. Note: The array includes also really low beat detection values +/// in absence of clear strong beats. Consumer may wish to filter low values away. +/// - "pos" receive array of beat positions +/// - "values" receive array of beat detection strengths +/// - max_num indicates max.size of "pos" and "values" array. +/// +/// You can query a suitable array sized by calling this with nullptr in "pos" & "values". +/// +/// \return number of beats in the arrays. +SOUNDTOUCHDLL_API int __cdecl bpm_getBeats(HANDLE h, float* pos, float* strength, int count) +{ + BPMHANDLE *bpmh = (BPMHANDLE *)h; + if (bpmh->dwMagic != BPMMAGIC) return 0; + + return bpmh->pbpm->getBeats(pos, strength, count); +} diff --git a/source/SoundTouchDLL/SoundTouchDLL.h b/source/SoundTouchDLL/SoundTouchDLL.h index 8fb137b..aca1aa1 100644 --- a/source/SoundTouchDLL/SoundTouchDLL.h +++ b/source/SoundTouchDLL/SoundTouchDLL.h @@ -225,5 +225,16 @@ SOUNDTOUCHDLL_API void __cdecl bpm_putSamples_i16(HANDLE h, /// \return Beats-per-minute rate, or zero if detection failed. SOUNDTOUCHDLL_API float __cdecl bpm_getBpm(HANDLE h); +/// Get beat position arrays. Note: The array includes also really low beat detection values +/// in absence of clear strong beats. Consumer may wish to filter low values away. +/// - "pos" receive array of beat positions +/// - "values" receive array of beat detection strengths +/// - max_num indicates max.size of "pos" and "values" array. +/// +/// You can query a suitable array sized by calling this with nullptr in "pos" & "values". +/// +/// \return number of beats in the arrays. +SOUNDTOUCHDLL_API int __cdecl bpm_getBeats(HANDLE h, float *pos, float *strength, int count); + #endif // _SoundTouchDLL_h_