shithub: sf2mid

Download patch

ref: 0ed1d615c50bb714a55068273ba4b81dc6ed04dc
parent: d182f65d75feb72cac811a72062c5cf0023f522a
author: Bernhard Schelling <14200249+schellingb@users.noreply.github.com>
date: Wed Oct 17 16:31:59 EDT 2018

Added a function that returns the number of active voices
Related to issue #27

--- a/tsf.h
+++ b/tsf.h
@@ -148,6 +148,9 @@
 // Stop playing all notes (end with sustain and release)
 TSFDEF void tsf_note_off_all(tsf* f);
 
+// Returns the number of active voices
+TSFDEF int tsf_active_voice_count(tsf* f);
+
 // Render output samples into a buffer
 // You can either render as signed 16-bit values (tsf_render_short) or
 // as 32-bit float values (tsf_render_float)
@@ -914,7 +917,6 @@
 
 static void tsf_voice_kill(struct tsf_voice* v)
 {
-	v->region = TSF_NULL;
 	v->playingPreset = -1;
 }
 
@@ -1338,6 +1340,14 @@
 	struct tsf_voice *v = f->voices, *vEnd = v + f->voiceNum;
 	for (; v != vEnd; v++) if (v->playingPreset != -1 && v->ampenv.segment < TSF_SEGMENT_RELEASE)
 		tsf_voice_end(v, f->outSampleRate);
+}
+
+TSFDEF int tsf_active_voice_count(tsf* f)
+{
+	int count = 0;
+	struct tsf_voice *v = f->voices, *vEnd = v + f->voiceNum;
+	for (; v != vEnd; v++) if (v->playingPreset != -1) count++;
+	return count;
 }
 
 TSFDEF void tsf_render_short(tsf* f, short* buffer, int samples, int flag_mixing)