diff --git a/src/sfizz.h b/src/sfizz.h index 6df7d7b8..0f155850 100644 --- a/src/sfizz.h +++ b/src/sfizz.h @@ -305,6 +305,26 @@ void sfizz_set_num_voices(sfizz_synth_t* synth, int num_voices); */ int sfizz_get_num_voices(sfizz_synth_t* synth); +/** + * @brief Get the number of allocated buffers from the synth. + * + * @param synth The synth + * + * @return The number of buffers held by the synth + */ +int sfizz_get_num_buffers(sfizz_synth_t* synth); +/** + * @brief Get the number of bytes allocated from the synth. Note that this + * value can be less than the actual memory usage since it only + * counts the buffer objects managed by sfizz. + * + * @param synth The synth + * + * @return The number of bytes held by the synth in buffers; + */ +int sfizz_get_num_bytes(sfizz_synth_t* synth); + + #ifdef __cplusplus } #endif diff --git a/src/sfizz/Synth.h b/src/sfizz/Synth.h index 410c14f4..2f91b189 100644 --- a/src/sfizz/Synth.h +++ b/src/sfizz/Synth.h @@ -310,6 +310,20 @@ public: * @return Oversampling */ uint32_t getPreloadSize() const noexcept; + + /** + * @brief Gets the number of allocated buffers. + * + * @return The allocated buffers. + */ + int getAllocatedBuffers() const noexcept { return Buffer::counter().getNumBuffers(); } + + /** + * @brief Gets the number of bytes allocated through the buffers + * + * @return The allocated bytes. + */ + int getAllocatedBytes() const noexcept { return Buffer::counter().getTotalBytes(); } protected: /** * @brief The parser callback; this is called by the parent object each time diff --git a/src/sfizz/sfizz_wrapper.cpp b/src/sfizz/sfizz_wrapper.cpp index 736241d8..2fccaa34 100644 --- a/src/sfizz/sfizz_wrapper.cpp +++ b/src/sfizz/sfizz_wrapper.cpp @@ -192,6 +192,18 @@ int sfizz_get_num_voices(sfizz_synth_t* synth) return self->getNumVoices(); } +int sfizz_get_num_buffers(sfizz_synth_t* synth) +{ + auto self = reinterpret_cast(synth); + return self->getAllocatedBuffers(); +} + +int sfizz_get_num_bytes(sfizz_synth_t* synth) +{ + auto self = reinterpret_cast(synth); + return self->getAllocatedBytes(); +} + #ifdef __cplusplus } #endif