From 99b87744ba22df78e3c476c92945b75acd267b87 Mon Sep 17 00:00:00 2001 From: Konstantin Date: Sun, 22 Jan 2023 13:28:24 +0100 Subject: VAD CPU performance, slightly better code generation --- Whisper/Whisper/melSpectrogram.cpp | 2 -- Whisper/Whisper/voiceActivityDetection.cpp | 10 ++++++++-- 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 #include "melSpectrogram.h" -#define _XM_SSE4_INTRINSICS_ -#include 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 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 #include + +#define _XM_SSE4_INTRINSICS_ #include +#include + #include #include "Utils/Logger.h" #include "Utils/miscUtils.h" -- cgit v1.2.3