Skip to content

Commit

Permalink
Added a function that returns the number of active voices
Browse files Browse the repository at this point in the history
Related to issue #27
  • Loading branch information
schellingb committed Oct 17, 2018
1 parent d182f65 commit 0ed1d61
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion tsf.h
Expand Up @@ -148,6 +148,9 @@ TSFDEF int tsf_bank_note_off(tsf* f, int bank, int preset_number, int key);
// 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)
Expand Down Expand Up @@ -914,7 +917,6 @@ static void tsf_voice_lfo_process(struct tsf_voice_lfo* e, int blockSamples)

static void tsf_voice_kill(struct tsf_voice* v)
{
v->region = TSF_NULL;
v->playingPreset = -1;
}

Expand Down Expand Up @@ -1340,6 +1342,14 @@ TSFDEF void tsf_note_off_all(tsf* f)
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)
{
float *floatSamples;
Expand Down

0 comments on commit 0ed1d61

Please sign in to comment.