audiomixer: rewrite the mixer functions

Let the mixer functions accumulate the intermediate results into a
larger size variable and then clamp to the final precission. This avoids
distortions because of intermediate clamping.

Although the access pattern of the reads are no longer sequential, the
writes are sequential and we don't need to read intermediate values.
Together with the avoided clamping this is probably faster overall.

Add a unit test for the various cases.
This commit is contained in:
Wim Taymans 2022-07-09 18:11:13 +02:00
parent 3ffb9f4b26
commit 371b5a1836
4 changed files with 376 additions and 48 deletions

View file

@ -1,6 +1,5 @@
audiomixer_sources = [
'audiomixer.c',
'mix-ops.c',
'mixer-dsp.c',
'plugin.c'
]
@ -47,11 +46,52 @@ if have_avx and have_fma
simd_dependencies += audiomixer_avx
endif
audiomixerlib = shared_library('spa-audiomixer',
audiomixer_lib = static_library('audiomixer',
['mix-ops.c' ],
c_args : [ simd_cargs, '-O3'],
link_with : simd_dependencies,
include_directories : [configinc],
dependencies : [ spa_dep ],
install : false
)
audiomixer_dep = declare_dependency(link_with: audiomixer_lib)
spa_audiomixer_lib = shared_library('spa-audiomixer',
audiomixer_sources,
c_args : simd_cargs,
link_with : simd_dependencies,
dependencies : [ spa_dep, mathlib ],
dependencies : [ spa_dep, mathlib, audiomixer_dep ],
install : true,
install_dir : spa_plugindir / 'audiomixer'
)
spa_audiomixer_dep = declare_dependency(link_with: spa_audiomixer_lib)
test_apps = [
'test-mix-ops',
]
foreach a : test_apps
test(a,
executable(a, a + '.c',
dependencies : [ spa_dep, dl_lib, pthread_lib, mathlib, audiomixer_dep ],
include_directories : [ configinc ],
link_with : [ test_lib ],
install_rpath : spa_plugindir / 'audiomixer',
c_args : [ simd_cargs ],
install : installed_tests_enabled,
install_dir : installed_tests_execdir / 'audiomixer'),
env : [
'SPA_PLUGIN_DIR=@0@'.format(spa_dep.get_variable('plugindir')),
])
if installed_tests_enabled
test_conf = configuration_data()
test_conf.set('exec', installed_tests_execdir / 'audiomixer' / a)
configure_file(
input: installed_tests_template,
output: a + '.test',
install_dir: installed_tests_metadir / 'audiomixer',
configuration: test_conf
)
endif
endforeach