mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-10-29 05:40:27 -04:00
audioconvert: build C versions with -Ofast and -ffast-math
Move resampler implementations to a -c version. Compile some of the functions with other flags to make them more optimized.
This commit is contained in:
parent
0ba3e7c5db
commit
419517fd55
8 changed files with 156 additions and 95 deletions
|
|
@ -9,8 +9,6 @@
|
|||
*/
|
||||
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <spa/utils/defs.h>
|
||||
|
||||
#include <math.h>
|
||||
|
|
|
|||
|
|
@ -3,8 +3,6 @@
|
|||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <float.h>
|
||||
#include <string.h>
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,20 @@ audioconvert_sources = [
|
|||
simd_cargs = []
|
||||
simd_dependencies = []
|
||||
|
||||
audioconvert_c = static_library('audioconvert_c',
|
||||
[ 'channelmix-ops-c.c',
|
||||
'biquad.c',
|
||||
'crossover.c',
|
||||
'volume-ops-c.c',
|
||||
'resample-native-c.c',
|
||||
'resample-peaks-c.c',
|
||||
'fmt-ops-c.c' ],
|
||||
c_args : [sse_args, '-Ofast', '-ffast-math'],
|
||||
dependencies : [ spa_dep ],
|
||||
install : false
|
||||
)
|
||||
simd_dependencies += audioconvert_c
|
||||
|
||||
if have_sse
|
||||
audioconvert_sse = static_library('audioconvert_sse',
|
||||
['resample-native-sse.c',
|
||||
|
|
@ -86,15 +100,10 @@ endif
|
|||
|
||||
audioconvert_lib = static_library('audioconvert',
|
||||
['fmt-ops.c',
|
||||
'biquad.c',
|
||||
'crossover.c',
|
||||
'channelmix-ops.c',
|
||||
'channelmix-ops-c.c',
|
||||
'resample-native.c',
|
||||
'resample-peaks.c',
|
||||
'fmt-ops-c.c',
|
||||
'volume-ops.c',
|
||||
'volume-ops-c.c' ],
|
||||
'volume-ops.c' ],
|
||||
c_args : [ simd_cargs, '-O3'],
|
||||
link_with : simd_dependencies,
|
||||
include_directories : [configinc],
|
||||
|
|
|
|||
65
spa/plugins/audioconvert/resample-native-c.c
Normal file
65
spa/plugins/audioconvert/resample-native-c.c
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
/* Spa
|
||||
*
|
||||
* Copyright © 2019 Wim Taymans
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "resample-native-impl.h"
|
||||
|
||||
static void inner_product_c(float *d, const float * SPA_RESTRICT s,
|
||||
const float * SPA_RESTRICT taps, uint32_t n_taps)
|
||||
{
|
||||
float sum = 0.0f;
|
||||
#if 1
|
||||
uint32_t i, j, nt2 = n_taps/2;
|
||||
for (i = 0, j = n_taps-1; i < nt2; i++, j--)
|
||||
sum += s[i] * taps[i] + s[j] * taps[j];
|
||||
#else
|
||||
uint32_t i;
|
||||
for (i = 0; i < n_taps; i++)
|
||||
sum += s[i] * taps[i];
|
||||
#endif
|
||||
*d = sum;
|
||||
}
|
||||
|
||||
static void inner_product_ip_c(float *d, const float * SPA_RESTRICT s,
|
||||
const float * SPA_RESTRICT t0, const float * SPA_RESTRICT t1, float x,
|
||||
uint32_t n_taps)
|
||||
{
|
||||
float sum[2] = { 0.0f, 0.0f };
|
||||
uint32_t i;
|
||||
#if 1
|
||||
uint32_t j, nt2 = n_taps/2;
|
||||
for (i = 0, j = n_taps-1; i < nt2; i++, j--) {
|
||||
sum[0] += s[i] * t0[i] + s[j] * t0[j];
|
||||
sum[1] += s[i] * t1[i] + s[j] * t1[j];
|
||||
}
|
||||
#else
|
||||
for (i = 0; i < n_taps; i++) {
|
||||
sum[0] += s[i] * t0[i];
|
||||
sum[1] += s[i] * t1[i];
|
||||
}
|
||||
#endif
|
||||
*d = (sum[1] - sum[0]) * x + sum[0];
|
||||
}
|
||||
|
||||
MAKE_RESAMPLER_FULL(c);
|
||||
MAKE_RESAMPLER_INTER(c);
|
||||
|
|
@ -97,46 +97,7 @@ static int build_filter(float *taps, uint32_t stride, uint32_t n_taps, uint32_t
|
|||
return 0;
|
||||
}
|
||||
|
||||
static void inner_product_c(float *d, const float * SPA_RESTRICT s,
|
||||
const float * SPA_RESTRICT taps, uint32_t n_taps)
|
||||
{
|
||||
float sum = 0.0f;
|
||||
#if 1
|
||||
uint32_t i, j, nt2 = n_taps/2;
|
||||
for (i = 0, j = n_taps-1; i < nt2; i++, j--)
|
||||
sum += s[i] * taps[i] + s[j] * taps[j];
|
||||
#else
|
||||
uint32_t i;
|
||||
for (i = 0; i < n_taps; i++)
|
||||
sum += s[i] * taps[i];
|
||||
#endif
|
||||
*d = sum;
|
||||
}
|
||||
|
||||
static void inner_product_ip_c(float *d, const float * SPA_RESTRICT s,
|
||||
const float * SPA_RESTRICT t0, const float * SPA_RESTRICT t1, float x,
|
||||
uint32_t n_taps)
|
||||
{
|
||||
float sum[2] = { 0.0f, 0.0f };
|
||||
uint32_t i;
|
||||
#if 1
|
||||
uint32_t j, nt2 = n_taps/2;
|
||||
for (i = 0, j = n_taps-1; i < nt2; i++, j--) {
|
||||
sum[0] += s[i] * t0[i] + s[j] * t0[j];
|
||||
sum[1] += s[i] * t1[i] + s[j] * t1[j];
|
||||
}
|
||||
#else
|
||||
for (i = 0; i < n_taps; i++) {
|
||||
sum[0] += s[i] * t0[i];
|
||||
sum[1] += s[i] * t1[i];
|
||||
}
|
||||
#endif
|
||||
*d = (sum[1] - sum[0]) * x + sum[0];
|
||||
}
|
||||
|
||||
MAKE_RESAMPLER_COPY(c);
|
||||
MAKE_RESAMPLER_FULL(c);
|
||||
MAKE_RESAMPLER_INTER(c);
|
||||
|
||||
#define MAKE(fmt,copy,full,inter,...) \
|
||||
{ SPA_AUDIO_FORMAT_ ##fmt, do_resample_ ##copy, #copy, \
|
||||
|
|
|
|||
73
spa/plugins/audioconvert/resample-peaks-c.c
Normal file
73
spa/plugins/audioconvert/resample-peaks-c.c
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
/* Spa
|
||||
*
|
||||
* Copyright © 2018 Wim Taymans
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include "resample-peaks-impl.h"
|
||||
|
||||
void resample_peaks_process_c(struct resample *r,
|
||||
const void * SPA_RESTRICT src[], uint32_t *in_len,
|
||||
void * SPA_RESTRICT dst[], uint32_t *out_len)
|
||||
{
|
||||
struct peaks_data *pd = r->data;
|
||||
uint32_t c, i, o, end, chunk, o_count, i_count;
|
||||
|
||||
if (SPA_UNLIKELY(r->channels == 0))
|
||||
return;
|
||||
|
||||
for (c = 0; c < r->channels; c++) {
|
||||
const float *s = src[c];
|
||||
float *d = dst[c], m = pd->max_f[c];
|
||||
|
||||
o_count = pd->o_count;
|
||||
i_count = pd->i_count;
|
||||
o = i = 0;
|
||||
|
||||
while (i < *in_len && o < *out_len) {
|
||||
end = ((uint64_t) (o_count + 1) * r->i_rate) / r->o_rate;
|
||||
end = end > i_count ? end - i_count : 0;
|
||||
chunk = SPA_MIN(end, *in_len);
|
||||
|
||||
for (; i < chunk; i++)
|
||||
m = SPA_MAX(fabsf(s[i]), m);
|
||||
|
||||
if (i == end) {
|
||||
d[o++] = m;
|
||||
m = 0.0f;
|
||||
o_count++;
|
||||
}
|
||||
}
|
||||
pd->max_f[c] = m;
|
||||
}
|
||||
|
||||
*out_len = o;
|
||||
*in_len = i;
|
||||
pd->o_count = o_count;
|
||||
pd->i_count = i_count + i;
|
||||
|
||||
while (pd->i_count >= r->i_rate) {
|
||||
pd->i_count -= r->i_rate;
|
||||
pd->o_count -= r->o_rate;
|
||||
}
|
||||
}
|
||||
|
|
@ -34,6 +34,9 @@ struct peaks_data {
|
|||
float max_f[];
|
||||
};
|
||||
|
||||
void resample_peaks_process_c(struct resample *r,
|
||||
const void * SPA_RESTRICT src[], uint32_t *in_len,
|
||||
void * SPA_RESTRICT dst[], uint32_t *out_len);
|
||||
#if defined (HAVE_SSE)
|
||||
void resample_peaks_process_sse(struct resample *r,
|
||||
const void * SPA_RESTRICT src[], uint32_t *in_len,
|
||||
|
|
|
|||
|
|
@ -29,52 +29,6 @@
|
|||
|
||||
#include "resample-peaks-impl.h"
|
||||
|
||||
static void resample_peaks_process_c(struct resample *r,
|
||||
const void * SPA_RESTRICT src[], uint32_t *in_len,
|
||||
void * SPA_RESTRICT dst[], uint32_t *out_len)
|
||||
{
|
||||
struct peaks_data *pd = r->data;
|
||||
uint32_t c, i, o, end, chunk, o_count, i_count;
|
||||
|
||||
if (SPA_UNLIKELY(r->channels == 0))
|
||||
return;
|
||||
|
||||
for (c = 0; c < r->channels; c++) {
|
||||
const float *s = src[c];
|
||||
float *d = dst[c], m = pd->max_f[c];
|
||||
|
||||
o_count = pd->o_count;
|
||||
i_count = pd->i_count;
|
||||
o = i = 0;
|
||||
|
||||
while (i < *in_len && o < *out_len) {
|
||||
end = ((uint64_t) (o_count + 1) * r->i_rate) / r->o_rate;
|
||||
end = end > i_count ? end - i_count : 0;
|
||||
chunk = SPA_MIN(end, *in_len);
|
||||
|
||||
for (; i < chunk; i++)
|
||||
m = SPA_MAX(fabsf(s[i]), m);
|
||||
|
||||
if (i == end) {
|
||||
d[o++] = m;
|
||||
m = 0.0f;
|
||||
o_count++;
|
||||
}
|
||||
}
|
||||
pd->max_f[c] = m;
|
||||
}
|
||||
|
||||
*out_len = o;
|
||||
*in_len = i;
|
||||
pd->o_count = o_count;
|
||||
pd->i_count = i_count + i;
|
||||
|
||||
while (pd->i_count >= r->i_rate) {
|
||||
pd->i_count -= r->i_rate;
|
||||
pd->o_count -= r->o_rate;
|
||||
}
|
||||
}
|
||||
|
||||
struct resample_info {
|
||||
uint32_t format;
|
||||
uint32_t cpu_flags;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue