[beast: 48/73] BSE: SF2: replace manually allocated repo arrays with std::vector
- From: Tim Janik <timj src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [beast: 48/73] BSE: SF2: replace manually allocated repo arrays with std::vector
- Date: Thu, 23 Mar 2017 21:45:42 +0000 (UTC)
commit d18cf11a0705b0b7098503091ca34b5aba1e7fc5
Author: Stefan Westerfeld <stefan space twc de>
Date: Sat Dec 3 17:56:36 2016 +0100
BSE: SF2: replace manually allocated repo arrays with std::vector
Signed-off-by: Stefan Westerfeld <stefan space twc de>
bse/bsesoundfontosc.cc | 20 ++++++++++++--------
bse/bsesoundfontrepo.cc | 39 +++++++++++----------------------------
bse/bsesoundfontrepo.hh | 12 +++++++++---
3 files changed, 32 insertions(+), 39 deletions(-)
---
diff --git a/bse/bsesoundfontosc.cc b/bse/bsesoundfontosc.cc
index 09464c1..8bdbeb1 100644
--- a/bse/bsesoundfontosc.cc
+++ b/bse/bsesoundfontosc.cc
@@ -356,6 +356,8 @@ process_fluid_L (BseSoundFontRepo *sfrepo,
fluid_synth_t *fluid_synth,
guint64 now_tick_stamp)
{
+ Bse::SoundFontRepoImpl *sfrepo_impl = sfrepo->as<Bse::SoundFontRepoImpl *>();
+
float **channel_values_left = (float **) g_alloca (sfrepo->n_fluid_channels * sizeof (float *));
float **channel_values_right = (float **) g_alloca (sfrepo->n_fluid_channels * sizeof (float *));
float null_fx[BSE_STREAM_MAX_VALUES];
@@ -369,8 +371,8 @@ process_fluid_L (BseSoundFontRepo *sfrepo,
the block (until the next event) is calculated, and so on */
for (guint i = 0; i < sfrepo->n_fluid_channels; i++)
{
- channel_values_left[i] = sfrepo->channel_values_left[i];
- channel_values_right[i] = sfrepo->channel_values_right[i];
+ channel_values_left[i] = &sfrepo_impl->channel_state[i].values_left[0];
+ channel_values_right[i] = &sfrepo_impl->channel_state[i].values_right[0];
}
guint values_remaining = bse_engine_block_size();
while (values_remaining)
@@ -393,7 +395,7 @@ process_fluid_L (BseSoundFontRepo *sfrepo,
switch (event->command)
{
case BSE_MIDI_NOTE_ON: fluid_synth_noteon (fluid_synth, event->channel, event->arg1,
event->arg2);
- sfrepo->n_silence_samples[event->channel] = 0;
+ sfrepo_impl->channel_state[event->channel].n_silence_samples = 0;
break;
case BSE_MIDI_NOTE_OFF: fluid_synth_noteoff (fluid_synth, event->channel, event->arg1);
break;
@@ -435,6 +437,8 @@ sound_font_osc_process (BseModule *module,
{
SoundFontOscModule *flmod = (SoundFontOscModule *) module->user_data;
BseSoundFontRepo *sfrepo = flmod->config.sfrepo;
+ Bse::SoundFontRepoImpl *sfrepo_impl = sfrepo->as<Bse::SoundFontRepoImpl *>();
+
fluid_synth_t *fluid_synth = bse_sound_font_repo_lock_fluid_synth (sfrepo);
guint i;
if (flmod->config.update_preset != flmod->last_update_preset)
@@ -447,8 +451,8 @@ sound_font_osc_process (BseModule *module,
if (sfrepo->channel_values_tick_stamp != now_tick_stamp)
process_fluid_L (sfrepo, fluid_synth, now_tick_stamp);
- float *left_output = sfrepo->channel_values_left[sfrepo->channel_map[flmod->config.osc_id]];
- float *right_output = sfrepo->channel_values_right[sfrepo->channel_map[flmod->config.osc_id]];
+ float *left_output = &sfrepo_impl->channel_state[sfrepo->channel_map[flmod->config.osc_id]].values_left[0];
+ float *right_output =
&sfrepo_impl->channel_state[sfrepo->channel_map[flmod->config.osc_id]].values_right[0];
int delta = bse_module_tick_stamp (module) - now_tick_stamp;
if (delta + n_values <= bse_engine_block_size()) /* paranoid check, should always pass */
@@ -467,10 +471,10 @@ sound_font_osc_process (BseModule *module,
for (i = 0; i < n_values && left_output[i] == 0.0 && right_output[i] == 0.0; i++)
;
if (i == n_values)
- sfrepo->n_silence_samples[sfrepo->channel_map[flmod->config.osc_id]] += n_values;
+ sfrepo_impl->channel_state[sfrepo->channel_map[flmod->config.osc_id]].n_silence_samples += n_values;
else
- sfrepo->n_silence_samples[sfrepo->channel_map[flmod->config.osc_id]] = 0;
- float done = (sfrepo->n_silence_samples[sfrepo->channel_map[flmod->config.osc_id]] >
flmod->config.silence_bound && sfrepo->fluid_events == NULL) ? 1.0 : 0.0;
+ sfrepo_impl->channel_state[sfrepo->channel_map[flmod->config.osc_id]].n_silence_samples = 0;
+ float done = (sfrepo_impl->channel_state[sfrepo->channel_map[flmod->config.osc_id]].n_silence_samples
flmod->config.silence_bound && sfrepo->fluid_events == NULL) ? 1.0 : 0.0;
BSE_MODULE_OSTREAM (module, BSE_SOUND_FONT_OSC_OCHANNEL_DONE_OUT).values = bse_engine_const_values
(done);
}
diff --git a/bse/bsesoundfontrepo.cc b/bse/bsesoundfontrepo.cc
index 694dfec..1686b44 100644
--- a/bse/bsesoundfontrepo.cc
+++ b/bse/bsesoundfontrepo.cc
@@ -113,9 +113,6 @@ bse_sound_font_repo_init (BseSoundFontRepo *sfrepo)
sfrepo->fluid_mix_freq = 0;
sfrepo->n_fluid_channels = 0;
- sfrepo->channel_values_left = NULL;
- sfrepo->channel_values_right = NULL;
- sfrepo->n_silence_samples = NULL;
sfrepo->n_channel_oscs_active = 0;
sfrepo->channel_values_tick_stamp = 0;
@@ -143,6 +140,8 @@ static void
bse_sound_font_repo_prepare (BseSource *source)
{
BseSoundFontRepo *sfrepo = BSE_SOUND_FONT_REPO (source);
+ Bse::SoundFontRepoImpl *sfrepo_impl = sfrepo->as<Bse::SoundFontRepoImpl *>();
+
guint i, channels_required = 0;
for (i = 0; i < sfrepo->n_oscs; i++)
{
@@ -152,20 +151,15 @@ bse_sound_font_repo_prepare (BseSource *source)
guint mix_freq = bse_engine_sample_freq();
if (sfrepo->n_fluid_channels != channels_required || sfrepo->fluid_mix_freq != mix_freq)
{
- for (i = channels_required; i < sfrepo->n_fluid_channels; i++) // n_fluid_channels > channels_required
- {
- g_free (sfrepo->channel_values_left[i]);
- g_free (sfrepo->channel_values_right[i]);
- }
- sfrepo->channel_values_left = (float **)g_realloc (sfrepo->channel_values_left, sizeof (float *) *
channels_required);
- sfrepo->channel_values_right = (float **)g_realloc (sfrepo->channel_values_right, sizeof (float *) *
channels_required);
- sfrepo->n_silence_samples = (gint *) g_realloc (sfrepo->n_silence_samples, sizeof (gint) *
channels_required);
- for (i = sfrepo->n_fluid_channels; i < channels_required; i++) // n_fluid_channels < channels_required
- {
- sfrepo->channel_values_left[i] = g_new0 (float, BSE_STREAM_MAX_VALUES);
- sfrepo->channel_values_right[i] = g_new0 (float, BSE_STREAM_MAX_VALUES);
- sfrepo->n_silence_samples[i] = 0;
- }
+ sfrepo_impl->channel_state.resize (channels_required);
+
+ for (auto& cstate : sfrepo_impl->channel_state)
+ {
+ cstate.n_silence_samples = 0;
+ cstate.values_left.resize (BSE_STREAM_MAX_VALUES);
+ cstate.values_right.resize (BSE_STREAM_MAX_VALUES);
+ }
+
sfrepo->n_fluid_channels = channels_required;
sfrepo->fluid_mix_freq = mix_freq;
@@ -223,18 +217,7 @@ bse_sound_font_repo_dispose (GObject *object)
sfrepo->channel_map = NULL;
g_free (sfrepo->oscs);
sfrepo->oscs = NULL;
- for (guint i = 0; i < sfrepo->n_fluid_channels; i++)
- {
- g_free (sfrepo->channel_values_left[i]);
- g_free (sfrepo->channel_values_right[i]);
- }
sfrepo->n_fluid_channels = 0;
- g_free (sfrepo->channel_values_left);
- sfrepo->channel_values_left = NULL;
- g_free (sfrepo->channel_values_right);
- sfrepo->channel_values_right = NULL;
- g_free (sfrepo->n_silence_samples);
- sfrepo->n_silence_samples = NULL;
if (sfrepo->fluid_events != NULL)
g_warning (G_STRLOC ": fluid event queue should be empty in dispose");
diff --git a/bse/bsesoundfontrepo.hh b/bse/bsesoundfontrepo.hh
index 6c95f5f..5bb5aaf 100644
--- a/bse/bsesoundfontrepo.hh
+++ b/bse/bsesoundfontrepo.hh
@@ -33,10 +33,7 @@ struct BseSoundFontRepo : BseSuper {
guint fluid_mix_freq;
guint n_fluid_channels;
- float **channel_values_left; /* [0..n_fluid_channels-1] */
- float **channel_values_right; /* [0..n_fluid_channels-1] */
guint64 channel_values_tick_stamp;
- gint *n_silence_samples; /* [0..n_fluid_channels-1] */
guint n_oscs;
BseSoundFontOsc **oscs; /* [0..n_oscs-1] */
@@ -64,7 +61,16 @@ void bse_sound_font_repo_remove_osc (BseSoundFontRepo *sfrepo,
namespace Bse {
class SoundFontRepoImpl : public SuperImpl, public virtual SoundFontRepoIface {
+public:
+ struct ChannelState {
+ std::vector<float> values_left;
+ std::vector<float> values_right;
+ int n_silence_samples;
+ };
+ std::vector<ChannelState> channel_state; /* [0..n_fluid_channels-1] */
+
protected:
+
virtual ~SoundFontRepoImpl ();
public:
explicit SoundFontRepoImpl (BseObject*);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]