diff options
| author | Konstantin <const@const.me> | 2023-01-22 13:28:24 +0100 |
|---|---|---|
| committer | Konstantin <const@const.me> | 2023-01-23 12:30:34 +0100 |
| commit | 99b87744ba22df78e3c476c92945b75acd267b87 (patch) | |
| tree | ada1fa431d35c0c15fbe9b6f2759915635a88e91 | |
| parent | 8fa57f680f002f4f636da687e40e21225f1ee392 (diff) | |
VAD CPU performance, slightly better code generation
| -rw-r--r-- | Whisper/Whisper/melSpectrogram.cpp | 2 | ||||
| -rw-r--r-- | Whisper/Whisper/voiceActivityDetection.cpp | 10 | ||||
| -rw-r--r-- | Whisper/stdafx.h | 4 |
3 files changed, 12 insertions, 4 deletions
diff --git a/Whisper/Whisper/melSpectrogram.cpp b/Whisper/Whisper/melSpectrogram.cpp index a178d16..8056e23 100644 --- a/Whisper/Whisper/melSpectrogram.cpp +++ b/Whisper/Whisper/melSpectrogram.cpp @@ -1,8 +1,6 @@ #include "stdafx.h" #include <cmath> #include "melSpectrogram.h" -#define _XM_SSE4_INTRINSICS_ -#include <DirectXMath.h> namespace Whisper { diff --git a/Whisper/Whisper/voiceActivityDetection.cpp b/Whisper/Whisper/voiceActivityDetection.cpp index 31763ec..c0eb7ef 100644 --- a/Whisper/Whisper/voiceActivityDetection.cpp +++ b/Whisper/Whisper/voiceActivityDetection.cpp @@ -1,6 +1,5 @@ #include "stdafx.h" #include "voiceActivityDetection.h" -#include <DirectXMath.h> using namespace Whisper; // Initially ported (poorly) from there https://github.com/panmasuo/voice-activity-detection MIT license @@ -56,6 +55,13 @@ void VAD::fft() const constexpr float mulInt16FromFloat = 32768.0; +inline float squareRoot( float x ) +{ + __m128 v = _mm_set_ss( x ); + v = _mm_sqrt_ss( v ); + return _mm_cvtss_f32( v ); +} + float VAD::computeEnergy( const float* rsi ) { // calculate_energy @@ -67,7 +73,7 @@ float VAD::computeEnergy( const float* rsi ) f *= f; sum += f; } - return std::sqrtf( (float)( sum * ( 1.0 / FFT_POINTS ) ) ); + return squareRoot( (float)( sum * ( 1.0 / FFT_POINTS ) ) ); } float VAD::computeDominant( const cplx* spectrum ) diff --git a/Whisper/stdafx.h b/Whisper/stdafx.h index 5df6e1b..907980e 100644 --- a/Whisper/stdafx.h +++ b/Whisper/stdafx.h @@ -17,7 +17,11 @@ #include <sdkddkver.h> #include <windows.h> + +#define _XM_SSE4_INTRINSICS_ #include <d3d11.h> +#include <DirectXMath.h> + #include <atlcomcli.h> #include "Utils/Logger.h" #include "Utils/miscUtils.h" |
