Commit | Line | Data |
---|---|---|
3719602c PC |
1 | /* Copyright (C) 2010-2020 The RetroArch team |
2 | * | |
3 | * --------------------------------------------------------------------------------------- | |
4 | * The following license statement only applies to this file (nearest_resampler.c). | |
5 | * --------------------------------------------------------------------------------------- | |
6 | * | |
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: | |
12 | * | |
13 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | |
14 | * | |
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. | |
21 | */ | |
22 | ||
23 | #include <stdint.h> | |
24 | #include <stdlib.h> | |
25 | #include <math.h> | |
26 | ||
27 | #include <audio/audio_resampler.h> | |
28 | ||
29 | typedef struct rarch_nearest_resampler | |
30 | { | |
31 | float fraction; | |
32 | } rarch_nearest_resampler_t; | |
33 | ||
34 | static void resampler_nearest_process( | |
35 | void *re_, struct resampler_data *data) | |
36 | { | |
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; | |
42 | ||
43 | while (inp != inp_max) | |
44 | { | |
45 | while (re->fraction > 1) | |
46 | { | |
47 | *outp++ = *inp; | |
48 | re->fraction -= ratio; | |
49 | } | |
50 | re->fraction++; | |
51 | inp++; | |
52 | } | |
53 | ||
54 | data->output_frames = (outp - (audio_frame_float_t*)data->data_out); | |
55 | } | |
56 | ||
57 | static void resampler_nearest_free(void *re_) | |
58 | { | |
59 | rarch_nearest_resampler_t *re = (rarch_nearest_resampler_t*)re_; | |
60 | if (re) | |
61 | free(re); | |
62 | } | |
63 | ||
64 | static void *resampler_nearest_init(const struct resampler_config *config, | |
65 | double bandwidth_mod, | |
66 | enum resampler_quality quality, | |
67 | resampler_simd_mask_t mask) | |
68 | { | |
69 | rarch_nearest_resampler_t *re = (rarch_nearest_resampler_t*) | |
70 | calloc(1, sizeof(rarch_nearest_resampler_t)); | |
71 | if (!re) | |
72 | return NULL; | |
73 | re->fraction = 0; | |
74 | return re; | |
75 | } | |
76 | ||
77 | retro_resampler_t nearest_resampler = { | |
78 | resampler_nearest_init, | |
79 | resampler_nearest_process, | |
80 | resampler_nearest_free, | |
81 | RESAMPLER_API_VERSION, | |
82 | "nearest", | |
83 | "nearest" | |
84 | }; |