(Resampler) Turn this void

This commit is contained in:
twinaphex 2020-02-03 00:16:16 +01:00
parent bcfa6d7e0e
commit 076fddd9d9
2 changed files with 59 additions and 48 deletions

View File

@ -81,10 +81,10 @@ typedef struct rarch_sinc_resampler
/* A buffer for phase_table, buffer_l and buffer_r /* A buffer for phase_table, buffer_l and buffer_r
* are created in a single calloc(). * are created in a single calloc().
* Ensure that we get as good cache locality as we can hope for. */ * Ensure that we get as good cache locality as we can hope for. */
float *main_buffer; void *main_buffer;
float *phase_table; void *phase_table;
float *buffer_l; void *buffer_l;
float *buffer_r; void *buffer_r;
} rarch_sinc_resampler_t; } rarch_sinc_resampler_t;
#if defined(__ARM_NEON__) && !defined(DONT_WANT_ARM_OPTIMIZATIONS) #if defined(__ARM_NEON__) && !defined(DONT_WANT_ARM_OPTIMIZATIONS)
@ -105,8 +105,8 @@ static void resampler_sinc_process_neon(void *re_, struct resampler_data *data)
unsigned phases = 1 << (resamp->phase_bits + resamp->subphase_bits); unsigned phases = 1 << (resamp->phase_bits + resamp->subphase_bits);
uint32_t ratio = phases / data->ratio; uint32_t ratio = phases / data->ratio;
const float *input = data->data_in; const float *input = (const float*)data->data_in;
float *output = data->data_out; float *output = (float*)data->data_out;
size_t frames = data->input_frames; size_t frames = data->input_frames;
size_t out_frames = 0; size_t out_frames = 0;
@ -156,8 +156,8 @@ static void resampler_sinc_process_avx(void *re_, struct resampler_data *data)
unsigned phases = 1 << (resamp->phase_bits + resamp->subphase_bits); unsigned phases = 1 << (resamp->phase_bits + resamp->subphase_bits);
uint32_t ratio = phases / data->ratio; uint32_t ratio = phases / data->ratio;
const float *input = data->data_in; const float *input = (const float*)data->data_in;
float *output = data->data_out; float *output = (float*)data->data_out;
size_t frames = data->input_frames; size_t frames = data->input_frames;
size_t out_frames = 0; size_t out_frames = 0;
@ -306,8 +306,8 @@ static void resampler_sinc_process_sse(void *re_, struct resampler_data *data)
unsigned phases = 1 << (resamp->phase_bits + resamp->subphase_bits); unsigned phases = 1 << (resamp->phase_bits + resamp->subphase_bits);
uint32_t ratio = phases / data->ratio; uint32_t ratio = phases / data->ratio;
const float *input = data->data_in; const float *input = (const float*)data->data_in;
float *output = data->data_out; float *output = (float*)data->data_out;
size_t frames = data->input_frames; size_t frames = data->input_frames;
size_t out_frames = 0; size_t out_frames = 0;
@ -317,16 +317,18 @@ static void resampler_sinc_process_sse(void *re_, struct resampler_data *data)
{ {
while (frames && resamp->time >= phases) while (frames && resamp->time >= phases)
{ {
float *buffer_l = (float*)resamp->buffer_l;
float *buffer_r = (float*)resamp->buffer_r;
/* Push in reverse to make filter more obvious. */ /* Push in reverse to make filter more obvious. */
if (!resamp->ptr) if (!resamp->ptr)
resamp->ptr = resamp->taps; resamp->ptr = resamp->taps;
resamp->ptr--; resamp->ptr--;
resamp->buffer_l[resamp->ptr + resamp->taps] = buffer_l[resamp->ptr + resamp->taps] =
resamp->buffer_l[resamp->ptr] = *input++; buffer_l[resamp->ptr] = *input++;
resamp->buffer_r[resamp->ptr + resamp->taps] = buffer_r[resamp->ptr + resamp->taps] =
resamp->buffer_r[resamp->ptr] = *input++; buffer_r[resamp->ptr] = *input++;
resamp->time -= phases; resamp->time -= phases;
frames--; frames--;
@ -336,11 +338,11 @@ static void resampler_sinc_process_sse(void *re_, struct resampler_data *data)
{ {
unsigned i; unsigned i;
__m128 sum; __m128 sum;
const float *buffer_l = resamp->buffer_l + resamp->ptr; const float *buffer_l = (const float*)resamp->buffer_l + resamp->ptr;
const float *buffer_r = resamp->buffer_r + resamp->ptr; const float *buffer_r = (const float*)resamp->buffer_r + resamp->ptr;
unsigned taps = resamp->taps; unsigned taps = resamp->taps;
unsigned phase = resamp->time >> resamp->subphase_bits; unsigned phase = resamp->time >> resamp->subphase_bits;
float *phase_table = resamp->phase_table + phase * taps * 2; float *phase_table = (float*)resamp->phase_table + phase * taps * 2;
float *delta_table = phase_table + taps; float *delta_table = phase_table + taps;
__m128 delta = _mm_set1_ps((float) __m128 delta = _mm_set1_ps((float)
(resamp->time & resamp->subphase_mask) * resamp->subphase_mod); (resamp->time & resamp->subphase_mask) * resamp->subphase_mod);
@ -396,16 +398,19 @@ static void resampler_sinc_process_sse(void *re_, struct resampler_data *data)
{ {
while (frames && resamp->time >= phases) while (frames && resamp->time >= phases)
{ {
float *buffer_l = (float*)resamp->buffer_l;
float *buffer_r = (float*)resamp->buffer_r;
/* Push in reverse to make filter more obvious. */ /* Push in reverse to make filter more obvious. */
if (!resamp->ptr) if (!resamp->ptr)
resamp->ptr = resamp->taps; resamp->ptr = resamp->taps;
resamp->ptr--; resamp->ptr--;
resamp->buffer_l[resamp->ptr + resamp->taps] = buffer_l[resamp->ptr + resamp->taps] =
resamp->buffer_l[resamp->ptr] = *input++; buffer_l[resamp->ptr] = *input++;
resamp->buffer_r[resamp->ptr + resamp->taps] = buffer_r[resamp->ptr + resamp->taps] =
resamp->buffer_r[resamp->ptr] = *input++; buffer_r[resamp->ptr] = *input++;
resamp->time -= phases; resamp->time -= phases;
frames--; frames--;
@ -415,11 +420,11 @@ static void resampler_sinc_process_sse(void *re_, struct resampler_data *data)
{ {
unsigned i; unsigned i;
__m128 sum; __m128 sum;
const float *buffer_l = resamp->buffer_l + resamp->ptr; const float *buffer_l = (const float*)resamp->buffer_l + resamp->ptr;
const float *buffer_r = resamp->buffer_r + resamp->ptr; const float *buffer_r = (const float*)resamp->buffer_r + resamp->ptr;
unsigned taps = resamp->taps; unsigned taps = resamp->taps;
unsigned phase = resamp->time >> resamp->subphase_bits; unsigned phase = resamp->time >> resamp->subphase_bits;
float *phase_table = resamp->phase_table + phase * taps; float *phase_table = (float*)resamp->phase_table + phase * taps;
__m128 sum_l = _mm_setzero_ps(); __m128 sum_l = _mm_setzero_ps();
__m128 sum_r = _mm_setzero_ps(); __m128 sum_r = _mm_setzero_ps();
@ -475,8 +480,8 @@ static void resampler_sinc_process_c(void *re_, struct resampler_data *data)
unsigned phases = 1 << (resamp->phase_bits + resamp->subphase_bits); unsigned phases = 1 << (resamp->phase_bits + resamp->subphase_bits);
uint32_t ratio = phases / data->ratio; uint32_t ratio = phases / data->ratio;
const float *input = data->data_in; const float *input = (const float*)data->data_in;
float *output = data->data_out; float *output = (float*)data->data_out;
size_t frames = data->input_frames; size_t frames = data->input_frames;
size_t out_frames = 0; size_t out_frames = 0;
@ -486,16 +491,19 @@ static void resampler_sinc_process_c(void *re_, struct resampler_data *data)
{ {
while (frames && resamp->time >= phases) while (frames && resamp->time >= phases)
{ {
float *buffer_l = (float*)resamp->buffer_l;
float *buffer_r = (float*)resamp->buffer_r;
/* Push in reverse to make filter more obvious. */ /* Push in reverse to make filter more obvious. */
if (!resamp->ptr) if (!resamp->ptr)
resamp->ptr = resamp->taps; resamp->ptr = resamp->taps;
resamp->ptr--; resamp->ptr--;
resamp->buffer_l[resamp->ptr + resamp->taps] = buffer_l[resamp->ptr + resamp->taps] =
resamp->buffer_l[resamp->ptr] = *input++; buffer_l[resamp->ptr] = *input++;
resamp->buffer_r[resamp->ptr + resamp->taps] = buffer_r[resamp->ptr + resamp->taps] =
resamp->buffer_r[resamp->ptr] = *input++; buffer_r[resamp->ptr] = *input++;
resamp->time -= phases; resamp->time -= phases;
frames--; frames--;
@ -506,12 +514,12 @@ static void resampler_sinc_process_c(void *re_, struct resampler_data *data)
unsigned i; unsigned i;
float sum_l = 0.0f; float sum_l = 0.0f;
float sum_r = 0.0f; float sum_r = 0.0f;
const float *buffer_l = resamp->buffer_l + resamp->ptr; const float *buffer_l = (const float*)resamp->buffer_l + resamp->ptr;
const float *buffer_r = resamp->buffer_r + resamp->ptr; const float *buffer_r = (const float*)resamp->buffer_r + resamp->ptr;
unsigned taps = resamp->taps; unsigned taps = resamp->taps;
unsigned phase = resamp->time >> resamp->subphase_bits; unsigned phase = resamp->time >> resamp->subphase_bits;
float *phase_table = resamp->phase_table + phase * taps * 2; float *phase_table = (float*)resamp->phase_table + phase * taps * 2;
float *delta_table = phase_table + taps; float *delta_table = (float*)phase_table + taps;
float delta = (float) float delta = (float)
(resamp->time & resamp->subphase_mask) * resamp->subphase_mod; (resamp->time & resamp->subphase_mask) * resamp->subphase_mod;
@ -539,18 +547,21 @@ static void resampler_sinc_process_c(void *re_, struct resampler_data *data)
{ {
while (frames && resamp->time >= phases) while (frames && resamp->time >= phases)
{ {
float *buffer_l = (float*)resamp->buffer_l;
float *buffer_r = (float*)resamp->buffer_r;
/* Push in reverse to make filter more obvious. */ /* Push in reverse to make filter more obvious. */
if (!resamp->ptr) if (!resamp->ptr)
resamp->ptr = resamp->taps; resamp->ptr = resamp->taps;
resamp->ptr--; resamp->ptr--;
resamp->buffer_l[resamp->ptr + resamp->taps] = buffer_l[resamp->ptr + resamp->taps] =
resamp->buffer_l[resamp->ptr] = *input++; buffer_l[resamp->ptr] = *input++;
resamp->buffer_r[resamp->ptr + resamp->taps] = buffer_r[resamp->ptr + resamp->taps] =
resamp->buffer_r[resamp->ptr] = *input++; buffer_r[resamp->ptr] = *input++;
resamp->time -= phases; resamp->time -= phases;
frames--; frames--;
} }
@ -559,11 +570,11 @@ static void resampler_sinc_process_c(void *re_, struct resampler_data *data)
unsigned i; unsigned i;
float sum_l = 0.0f; float sum_l = 0.0f;
float sum_r = 0.0f; float sum_r = 0.0f;
const float *buffer_l = resamp->buffer_l + resamp->ptr; const float *buffer_l = (const float*)resamp->buffer_l + resamp->ptr;
const float *buffer_r = resamp->buffer_r + resamp->ptr; const float *buffer_r = (const float*)resamp->buffer_r + resamp->ptr;
unsigned taps = resamp->taps; unsigned taps = resamp->taps;
unsigned phase = resamp->time >> resamp->subphase_bits; unsigned phase = resamp->time >> resamp->subphase_bits;
float *phase_table = resamp->phase_table + phase * taps; float *phase_table = (float*)resamp->phase_table + phase * taps;
for (i = 0; i < taps; i++) for (i = 0; i < taps; i++)
{ {
@ -812,17 +823,17 @@ static void *resampler_sinc_new(const struct resampler_config *config,
memset(re->main_buffer, 0, sizeof(float) * elems); memset(re->main_buffer, 0, sizeof(float) * elems);
re->phase_table = re->main_buffer; re->phase_table = re->main_buffer;
re->buffer_l = re->main_buffer + phase_elems; re->buffer_l = (float*)re->main_buffer + phase_elems;
re->buffer_r = re->buffer_l + 2 * re->taps; re->buffer_r = (float*)re->buffer_l + 2 * re->taps;
switch (re->window_type) switch (re->window_type)
{ {
case SINC_WINDOW_LANCZOS: case SINC_WINDOW_LANCZOS:
sinc_init_table_lanczos(re, cutoff, re->phase_table, sinc_init_table_lanczos(re, cutoff, (float*)re->phase_table,
1 << re->phase_bits, re->taps, false); 1 << re->phase_bits, re->taps, false);
break; break;
case SINC_WINDOW_KAISER: case SINC_WINDOW_KAISER:
sinc_init_table_kaiser(re, cutoff, re->phase_table, sinc_init_table_kaiser(re, cutoff, (float*)re->phase_table,
1 << re->phase_bits, re->taps, true); 1 << re->phase_bits, re->taps, true);
break; break;
case SINC_WINDOW_NONE: case SINC_WINDOW_NONE:

View File

@ -67,8 +67,8 @@ typedef unsigned resampler_simd_mask_t;
struct resampler_data struct resampler_data
{ {
const float *data_in; const void *data_in;
float *data_out; void *data_out;
size_t input_frames; size_t input_frames;
size_t output_frames; size_t output_frames;