Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.
TypeScript cross-platformelectronffmpegopen-sourceproduct-demorustscreen-capturescreen-recorderscreen-recordingscreen-studioscreencastspeech-to-texttypescriptvideo-editingvideo-editorwaylandwgpuwhisper
fix: keep sub-factor AAC packets on the interpolation path
超超超超超级喜欢你的达妮娅bbbc6d55d674
diff --git a/electron/native/wgc-capture/src/audio_sample_utils.cpp b/electron/native/wgc-capture/src/audio_sample_utils.cppindex f62008354..ec6ecdbd7 100644--- a/electron/native/wgc-capture/src/audio_sample_utils.cpp+++ b/electron/native/wgc-capture/src/audio_sample_utils.cpp@@ -214,31 +214,31 @@ void convertAudioWithGain(sourceFormat.sampleRate % targetFormat.sampleRate == 0) {const UINT32 factor = sourceFormat.sampleRate / targetFormat.sampleRate;const size_t targetFrames = sourceFrames / factor;- if (targetFrames == 0) {- destination.clear();- return;- }- destination.assign(targetFrames * targetFormat.blockAlign, 0);- for (size_t targetFrame = 0; targetFrame < targetFrames; ++targetFrame) {- for (UINT32 channel = 0; channel < targetFormat.channels; ++channel) {- double sum = 0.0;- for (UINT32 tap = 0; tap < factor; ++tap) {- sum += readMappedChannel(- source,- sourceFormat,- targetFrame * factor + tap,+ if (targetFrames > 0) {+ destination.assign(targetFrames * targetFormat.blockAlign, 0);+ for (size_t targetFrame = 0; targetFrame < targetFrames; ++targetFrame) {+ for (UINT32 channel = 0; channel < targetFormat.channels; ++channel) {+ double sum = 0.0;+ for (UINT32 tap = 0; tap < factor; ++tap) {+ sum += readMappedChannel(+ source,+ sourceFormat,+ targetFrame * factor + tap,+ channel,+ targetFormat.channels);+ }+ writeSampleFromDouble(+ destination.data(),+ targetFormat,+ targetFrame,channel,- targetFormat.channels);+ (sum / static_cast<double>(factor)) * gain);}- writeSampleFromDouble(- destination.data(),- targetFormat,- targetFrame,- channel,- (sum / static_cast<double>(factor)) * gain);}+ return;}- return;+ // Too few source frames for one averaged output frame (tiny WASAPI+ // packets). Fall through to interpolation instead of dropping them.}const double rateRatio = static_cast<double>(targetFormat.sampleRate) /diff --git a/electron/native/wgc-capture/src/audio_sample_utils_test.cpp b/electron/native/wgc-capture/src/audio_sample_utils_test.cppindex 0dc7e8c00..b261a7d28 100644--- a/electron/native/wgc-capture/src/audio_sample_utils_test.cpp+++ b/electron/native/wgc-capture/src/audio_sample_utils_test.cpp@@ -7,6 +7,7 @@#include <wrl/client.h>#include <cstdint>+#include <cstdio>#include <cstdlib>#include <iostream>#include <string>@@ -275,6 +276,25 @@ int main() {}expect("resample-96k-nyquist-box", folded, "frames=" + std::to_string(downFrames));+ std::vector<BYTE> shortPkt(source96k.blockAlign, 0);+ auto* shortSamples = reinterpret_cast<int16_t*>(shortPkt.data());+ shortSamples[0] = 12345;+ shortSamples[1] = -12345;+ std::vector<BYTE> shortOut;+ convertAudioWithGain(+ shortPkt.data(),+ static_cast<DWORD>(shortPkt.size()),+ source96k,+ target48k,+ 1.0,+ shortOut);+ const bool shortOk = !shortOut.empty() && target48k.blockAlign != 0 &&+ (shortOut.size() % target48k.blockAlign == 0);+ expect(+ "resample-96k-short-packet",+ shortOk,+ "bytes=" + std::to_string(shortOut.size()));+HRESULT mfHr = CoInitializeEx(nullptr, COINIT_MULTITHREADED);if (FAILED(mfHr) && mfHr != RPC_E_CHANGED_MODE) {skip("mf-startup", "CoInitializeEx failed — no Media Foundation on this host");