jp9000/obs-studio — pull request #112 by antihax (2014-06-08 05:27:40+00:00)
Title: Slight modification of audio mixing function

Made a small modification to the mixing function. The use of clamp was resulting in the use of scalar SSE instructions instead of the packed versions. By hinting to the compiler, was able to correctly sequence the assembly code as needed (see far below).

Result was a 3.2x reduction in CPU ticks to execute the function.

Level	Number	Mean	Std Dev	Std Err Mean	Lower 95%	Upper 95%
mix ps	1081	1.96289	0.93642	0.02848	1.9070	2.0188
mix ss	783	6.34622	2.69428	0.09629	6.1572	6.5352

Also experimented with buffer size, but anything greater than 256 yielded no improvement and anything smaller saw a slower execution time.

Current ASM using MSVC 2013:

mix_val = *mix + vals[i];
71ED28B0 movups xmm0,xmmword ptr [edi]
71ED28B3 add ecx,4
71ED28B6 movups xmm2,xmmword ptr [eax]
71ED28B9 add eax,10h
71ED28BC movaps xmm1,xmm3
71ED28BF addps xmm2,xmm0
71ED28C2 movaps xmm0,xmm4
71ED28C5 minps xmm1,xmm2
71ED28C8 maxps xmm0,xmm1