1 /* Copyright (C) 2010-2020 The RetroArch team
3 * ---------------------------------------------------------------------------------------
4 * The following license statement only applies to this file (nearest_resampler.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 <audio/audio_resampler.h>
29 typedef struct rarch_nearest_resampler
32 } rarch_nearest_resampler_t;
34 static void resampler_nearest_process(
35 void *re_, struct resampler_data *data)
37 rarch_nearest_resampler_t *re = (rarch_nearest_resampler_t*)re_;
38 audio_frame_float_t *inp = (audio_frame_float_t*)data->data_in;
39 audio_frame_float_t *inp_max = (audio_frame_float_t*)inp + data->input_frames;
40 audio_frame_float_t *outp = (audio_frame_float_t*)data->data_out;
41 float ratio = 1.0 / data->ratio;
43 while (inp != inp_max)
45 while (re->fraction > 1)
48 re->fraction -= ratio;
54 data->output_frames = (outp - (audio_frame_float_t*)data->data_out);
57 static void resampler_nearest_free(void *re_)
59 rarch_nearest_resampler_t *re = (rarch_nearest_resampler_t*)re_;
64 static void *resampler_nearest_init(const struct resampler_config *config,
66 enum resampler_quality quality,
67 resampler_simd_mask_t mask)
69 rarch_nearest_resampler_t *re = (rarch_nearest_resampler_t*)
70 calloc(1, sizeof(rarch_nearest_resampler_t));
77 retro_resampler_t nearest_resampler = {
78 resampler_nearest_init,
79 resampler_nearest_process,
80 resampler_nearest_free,
81 RESAMPLER_API_VERSION,