|
| 1 | +/****************************************************************************** |
| 2 | + * FluidSynth - A Software Synthesizer |
| 3 | + * |
| 4 | + * Copyright (C) 2025 Neoharp development team |
| 5 | + * |
| 6 | + * This library is free software; you can redistribute it and/or |
| 7 | + * modify it under the terms of the GNU Lesser General Public License |
| 8 | + * as published by the Free Software Foundation; either version 2.1 of |
| 9 | + * the License, or (at your option) any later version. |
| 10 | + * |
| 11 | + * This library is distributed in the hope that it will be useful, but |
| 12 | + * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | + * Lesser General Public License for more details. |
| 15 | + * |
| 16 | + * You should have received a copy of the GNU Lesser General Public |
| 17 | + * License along with this library; if not, see |
| 18 | + * <https://www.gnu.org/licenses/>. |
| 19 | + * |
| 20 | + */ |
| 21 | + |
| 22 | +#include "fluidsynth_priv.h" |
| 23 | + |
| 24 | +#ifdef LIMITER |
| 25 | + |
| 26 | +#include "fluid_limiter.h" |
| 27 | +#include "fluid_limiter_impl.h" |
| 28 | +#include "fluid_sys.h" |
| 29 | + |
| 30 | +/*---------------------------------------------------------------------------- |
| 31 | + Limiter API |
| 32 | +-----------------------------------------------------------------------------*/ |
| 33 | +/* |
| 34 | +* Creates a limiter with default parameters |
| 35 | +* |
| 36 | +* @param sample_rate actual sample rate needed in Hz. |
| 37 | +* @return pointer on the new limiter or NULL if memory error. |
| 38 | +* Limiter API. |
| 39 | +*/ |
| 40 | +fluid_limiter_t* |
| 41 | +new_fluid_limiter(fluid_real_t sample_rate, fluid_limiter_settings_t* settings) |
| 42 | +{ |
| 43 | + fluid_limiter_t* lim; |
| 44 | + |
| 45 | + if(sample_rate <= 0) |
| 46 | + { |
| 47 | + return NULL; |
| 48 | + } |
| 49 | + |
| 50 | + lim = fluid_limiter_impl_new(sample_rate, settings); |
| 51 | + |
| 52 | + if(lim == NULL) |
| 53 | + { |
| 54 | + return NULL; |
| 55 | + } |
| 56 | + |
| 57 | + return lim; |
| 58 | +} |
| 59 | + |
| 60 | +/* |
| 61 | +* free the limiter. |
| 62 | +* @param lim pointer on limiter to free. |
| 63 | +* Limiter API. |
| 64 | +*/ |
| 65 | +void |
| 66 | +delete_fluid_limiter(fluid_limiter_t *lim) |
| 67 | +{ |
| 68 | + fluid_return_if_fail(lim != NULL); |
| 69 | + fluid_limiter_impl_delete(lim); |
| 70 | +} |
| 71 | + |
| 72 | +/* |
| 73 | +* Applies a sample rate change on the limiter. |
| 74 | +* |
| 75 | +* @param lim the limiter. |
| 76 | +* @param sample_rate new sample rate value |
| 77 | +* @return FLUID_OK if success, FLUID_FAILED if lim is NULL |
| 78 | +* Limiter API. |
| 79 | +*/ |
| 80 | +int |
| 81 | +fluid_limiter_samplerate_change(fluid_limiter_t *lim, fluid_real_t sample_rate) |
| 82 | +{ |
| 83 | + int status = FLUID_OK; |
| 84 | + |
| 85 | + fluid_return_val_if_fail(lim != NULL, FLUID_FAILED); |
| 86 | + |
| 87 | + fluid_limiter_impl_set_sample_rate(lim, sample_rate); |
| 88 | + |
| 89 | + return status; |
| 90 | +} |
| 91 | + |
| 92 | +/*----------------------------------------------------------------------------- |
| 93 | +* Run the limiter |
| 94 | +* @param lim pointer on limiter. |
| 95 | +* @param buf_l left buffer to process (will be modified in-place) |
| 96 | +* @param buf_r right buffer to process (will be modified in-place) |
| 97 | +* Limiter API. |
| 98 | +-----------------------------------------------------------------------------*/ |
| 99 | +void |
| 100 | +fluid_limiter_run(fluid_limiter_t *lim, fluid_real_t *buf_l, fluid_real_t *buf_r, int block_count) |
| 101 | +{ |
| 102 | + int i; |
| 103 | + fluid_real_t* bufs[FLUID_LIMITER_NUM_CHANNELS_AT_ONCE]; |
| 104 | + |
| 105 | + for (i = 0; i < block_count; i++) |
| 106 | + { |
| 107 | +#if FLUID_LIMITER_NUM_CHANNELS_AT_ONCE < 2 |
| 108 | +#error "expected FLUID_LIMITER_NUM_CHANNELS_AT_ONCE >= 2" |
| 109 | +#endif |
| 110 | + bufs[0] = buf_l + i*FLUID_BUFSIZE; |
| 111 | + bufs[1] = buf_r + i*FLUID_BUFSIZE; |
| 112 | + |
| 113 | + fluid_limiter_impl_process_buffers(lim, bufs); |
| 114 | + } |
| 115 | +} |
| 116 | + |
| 117 | +#endif /* LIMITER */ |
0 commit comments