From c76949e6d33527fea2a4b5cdc7ff2421bb58537a Mon Sep 17 00:00:00 2001 From: jjceresa <32781294+jjceresa@users.noreply.github.com> Date: Sat, 22 Aug 2020 13:24:41 +0200 Subject: [PATCH] Limiting audio-channels to audio-groups (#663) --- src/rvoice/fluid_rvoice_mixer.c | 2 +- src/synth/fluid_synth.c | 28 ++++++++++++++++++++-------- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/rvoice/fluid_rvoice_mixer.c b/src/rvoice/fluid_rvoice_mixer.c index 64d4c2e1..298a563b 100644 --- a/src/rvoice/fluid_rvoice_mixer.c +++ b/src/rvoice/fluid_rvoice_mixer.c @@ -51,7 +51,7 @@ struct _fluid_mixer_buffers_t /** buffer to store the left part of a stereo channel to. * Specifically a two dimensional array, containing \c buf_count sample buffers - * (i.e. for each synth.audio-channels), of which each contains + * (i.e. for each synth.audio-groups), of which each contains * FLUID_BUFSIZE * FLUID_MIXER_MAX_BUFFERS_DEFAULT audio items (=samples) * @note Each sample buffer is aligned to the FLUID_DEFAULT_ALIGNMENT * boundary provided that this pointer points to an aligned buffer. diff --git a/src/synth/fluid_synth.c b/src/synth/fluid_synth.c index 14fdd4f3..50de9a8d 100644 --- a/src/synth/fluid_synth.c +++ b/src/synth/fluid_synth.c @@ -607,7 +607,7 @@ new_fluid_synth(fluid_settings_t *settings) fluid_synth_t *synth; fluid_sfloader_t *loader; char *important_channels; - int i, nbuf, prio_level = 0; + int i, prio_level = 0; int with_ladspa = 0; double sample_rate_min, sample_rate_max; @@ -749,14 +749,25 @@ new_fluid_synth(fluid_settings_t *settings) synth->effects_channels = 2; } - /* The number of buffers is determined by the higher number of nr - * groups / nr audio channels. If LADSPA is unused, they should be - * the same. */ - nbuf = synth->audio_channels; + /* + number of buffers rendered by the mixer is determined by synth->audio_groups. + audio from MIDI channel is rendered, mapped and mixed in these buffers. - if(synth->audio_groups > nbuf) + Typically synth->audio_channels is only used by audio driver and should be set + to the same value that synth->audio_groups. In some situation using LADSPA, + it is best to diminish audio-channels so that the driver will be able to pass + the audio to audio devices in the case these devices have a limited number of + audio channels. + + audio-channels must not be greater then audio-groups, otherwise these + audio output above audio-groups will not be rendered by the mixeur. + */ + if(synth->audio_channels > synth->audio_groups) { - nbuf = synth->audio_groups; + synth->audio_channels = synth->audio_groups; + fluid_settings_setint(settings, "synth.audio-channels", synth->audio_channels); + FLUID_LOG(FLUID_WARN, "Requested audio-channels to high. " + "Limiting this setting to audio-groups."); } if(fluid_settings_dupstr(settings, "synth.overflow.important-channels", @@ -788,7 +799,8 @@ new_fluid_synth(fluid_settings_t *settings) /* Allocate event queue for rvoice mixer */ /* In an overflow situation, a new voice takes about 50 spaces in the queue! */ synth->eventhandler = new_fluid_rvoice_eventhandler(synth->polyphony * 64, - synth->polyphony, nbuf, synth->effects_channels, synth->effects_groups, + synth->polyphony, synth->audio_groups, + synth->effects_channels, synth->effects_groups, (fluid_real_t)sample_rate_max, synth->sample_rate, synth->cores - 1, prio_level);