resample: add SSE peaks resampler

This commit is contained in:
Wim Taymans 2018-12-19 16:47:20 +01:00
parent a1e567b985
commit 0a4ef3d2c0
4 changed files with 116 additions and 10 deletions

View file

@ -30,6 +30,10 @@ struct peaks_data {
float max_f[0];
};
#if defined (__SSE__)
#include "resample-peaks-sse.h"
#endif
static void impl_peaks_free(struct resample *r)
{
if (r->data)
@ -45,28 +49,28 @@ static void impl_peaks_process(struct resample *r, int channel,
void *src, uint32_t *in_len, void *dst, uint32_t *out_len)
{
struct peaks_data *pd = r->data;
float *s = src, *d = dst;
float *s = src, *d = dst, m;
int i, o, end, chunk;
o = i = 0;
m = pd->max_f[channel];
while (i < *in_len && o < *out_len) {
end = ((uint64_t) (pd->o_count + 1) * r->i_rate) / r->o_rate;
end = end > pd->i_count ? end - pd->i_count : 0;
chunk = SPA_MIN(end, *in_len);
for (; i < chunk; i++) {
float n = fabsf(s[i]);
if (n > pd->max_f[channel])
pd->max_f[channel] = n;
}
for (; i < chunk; i++)
m = SPA_MAX(fabsf(s[i]), m);
if (i == end) {
d[o++] = pd->max_f[channel];
pd->max_f[channel] = 0.0f;
d[o++] = m;
m = 0.0f;
pd->o_count++;
}
}
pd->max_f[channel] = m;
*out_len = o;
*in_len = i;
pd->i_count += i;
@ -89,7 +93,13 @@ static int impl_peaks_init(struct resample *r)
r->free = impl_peaks_free;
r->update_rate = impl_peaks_update_rate;
r->process = impl_peaks_process;
#if defined (__SSE__)
if (r->cpu_flags & SPA_CPU_FLAG_SSE)
r->process = impl_peaks_process_sse;
else
#endif
r->process = impl_peaks_process;
r->reset = impl_peaks_reset;
d = r->data = calloc(1, sizeof(struct peaks_data) * sizeof(float) * r->channels);
if (r->data == NULL)