Привет всем, я полная новичка, и я пытаюсь сделать макрос аудио триггера через C ++.
У меня работает программа, но я не могу заставить ее выполнить должным образом. В нем правильно указывается, что его контролирует микрофон, но я не могу заставить его выполнить независимо от суммы децибела. Любая помощь будет легендарной. < /P>
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#pragma comment(lib, "winmm.lib")
#pragma comment(lib, "ole32.lib")
class AudioTrigger {
private:
// Audio monitoring settings
std::atomic threshold; // dB threshold
std::atomic cooldown; // seconds
std::atomic isRunning;
std::thread monitorThread;
std::mutex mtx;
float lastTriggerTime;
// Audio capture
IMMDeviceEnumerator* pEnumerator = nullptr;
IMMDevice* pDevice = nullptr;
IAudioClient* pAudioClient = nullptr;
IAudioCaptureClient* pCaptureClient = nullptr;
WAVEFORMATEX* pwfx = nullptr;
void executeAltF4() {
// Simulate Alt+F4 keypress
INPUT inputs[4] = {};
// Press Alt key
inputs[0].type = INPUT_KEYBOARD;
inputs[0].ki.wVk = VK_MENU; // Alt key
// Press F4 key
inputs[1].type = INPUT_KEYBOARD;
inputs[1].ki.wVk = VK_F4;
// Release F4 key
inputs[2].type = INPUT_KEYBOARD;
inputs[2].ki.wVk = VK_F4;
inputs[2].ki.dwFlags = KEYEVENTF_KEYUP;
// Release Alt key
inputs[3].type = INPUT_KEYBOARD;
inputs[3].ki.wVk = VK_MENU;
inputs[3].ki.dwFlags = KEYEVENTF_KEYUP;
SendInput(4, inputs, sizeof(INPUT));
std::cout Release();
pAudioClient = nullptr;
}
if (pDevice) {
pDevice->Release();
pDevice = nullptr;
}
if (pEnumerator) {
pEnumerator->Release();
pEnumerator = nullptr;
}
CoUninitialize();
}
float calculateDBFS(const float* samples, UINT32 numSamples) {
if (numSamples == 0) return -100.0f;
float sum = 0.0f;
// Calculate RMS (Root Mean Square)
for (UINT32 i = 0; i < numSamples; i++) {
sum += samples * samples;
}
float rms = sqrt(sum / numSamples);
// Convert to dB
// Reference level is 1.0 for float audio
if (rms > 0.0f) {
return 20.0f * log10(rms);
} else {
return -100.0f; // Silence
}
}
void monitorAudio() {
if (!initializeAudioCapture()) {
std::cerr
Подробнее здесь: https://stackoverflow.com/questions/794 ... shold-in-c
Audio Trigger Alt+ F4 Macro на основе порога Decibel в C ++ ⇐ C++
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение