diff options
| -rw-r--r-- | Whisper/MF/AudioBuffer.h | 13 | ||||
| -rw-r--r-- | Whisper/Whisper/ContextImpl.capture.cpp | 5 |
2 files changed, 16 insertions, 2 deletions
diff --git a/Whisper/MF/AudioBuffer.h b/Whisper/MF/AudioBuffer.h index b12dff4..77be1e0 100644 --- a/Whisper/MF/AudioBuffer.h +++ b/Whisper/MF/AudioBuffer.h @@ -1,4 +1,5 @@ #pragma once +#include <algorithm> #include <vector> namespace Whisper @@ -52,5 +53,17 @@ namespace Whisper memcpy(tmp.data(), mono.data() + len, remainder); mono = std::move(tmp); } + + void normalize() + { + const auto &min = *std::min_element(mono.begin(), mono.end()); + const auto &max = *std::max_element(mono.begin(), mono.end()); + + for (auto& elm : mono) { + elm -= min; + elm /= (max - min) + 1; + elm *= 255.0; + } + } }; }
\ No newline at end of file diff --git a/Whisper/Whisper/ContextImpl.capture.cpp b/Whisper/Whisper/ContextImpl.capture.cpp index 0b213b8..bc88249 100644 --- a/Whisper/Whisper/ContextImpl.capture.cpp +++ b/Whisper/Whisper/ContextImpl.capture.cpp @@ -138,7 +138,8 @@ namespace workStatus = S_FALSE; buffer.currentOffset = pcmStartTime; - pcm.swap( buffer.pcm ); + buffer.pcm = pcm; + buffer.pcm.normalize(); SubmitThreadpoolWork( work ); pcmStartTime = nextSampleTime; pcm.clear(); @@ -419,4 +420,4 @@ HRESULT COMLIGHTCALL ContextImpl::runCapture( const sFullParams& params, const s return S_OK; CHECK( capture.run() ); } -}
\ No newline at end of file +} |
