1 /* Copyright (C) 2010-2020 The RetroArch team
3 * ---------------------------------------------------------------------------------------
4 * The following license statement only applies to this file (panning.c).
5 * ---------------------------------------------------------------------------------------
7 * Permission is hereby granted, free of charge,
8 * to any person obtaining a copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation the rights to
10 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
11 * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
16 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
19 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 #include <libretro_dspfilter.h>
35 static void panning_free(void *data)
40 static void panning_process(void *data, struct dspfilter_output *output,
41 const struct dspfilter_input *input)
44 struct panning_data *pan = (struct panning_data*)data;
45 float *out = output->samples;
47 output->samples = input->samples;
48 output->frames = input->frames;
50 for (i = 0; i < input->frames; i++, out += 2)
54 out[0] = left * pan->left[0] + right * pan->left[1];
55 out[1] = left * pan->right[0] + right * pan->right[1];
59 static void *panning_init(const struct dspfilter_info *info,
60 const struct dspfilter_config *config, void *userdata)
62 static const float default_left[] = { 1.0f, 0.0f };
63 static const float default_right[] = { 0.0f, 1.0f };
66 unsigned num_left = 0;
67 unsigned num_right = 0;
68 struct panning_data *pan = (struct panning_data*)
69 calloc(1, sizeof(*pan));
74 config->get_float_array(userdata, "left_mix",
75 &left, &num_left, default_left, 2);
76 config->get_float_array(userdata, "right_mix",
77 &right, &num_right, default_right, 2);
79 memcpy(pan->left, (num_left == 2) ?
80 left : default_left, sizeof(pan->left));
81 memcpy(pan->right, (num_right == 2) ?
82 right : default_right, sizeof(pan->right));
90 static const struct dspfilter_implementation panning = {
95 DSPFILTER_API_VERSION,
100 #ifdef HAVE_FILTERS_BUILTIN
101 #define dspfilter_get_implementation panning_dspfilter_get_implementation
104 const struct dspfilter_implementation *
105 dspfilter_get_implementation(dspfilter_simd_mask_t mask)
110 #undef dspfilter_get_implementation