Commit f069e055 authored by Leander Schulten's avatar Leander Schulten
Browse files

AudioManager: RtAudio:you now can select output devices as input on windows (loopback recording)

parent ac46081d
...@@ -5,6 +5,16 @@ ...@@ -5,6 +5,16 @@
#include "gui/oscillogram.h" #include "gui/oscillogram.h"
#include <algorithm> #include <algorithm>
#ifdef AUDIO_IF_WIN
#error AUDIO_IF_WIN is already defined
#endif
#ifdef Q_OS_WIN
#define AUDIO_IF_WIN(x) x
#else
#define AUDIO_IF_WIN(x)
#endif
namespace Audio { namespace Audio {
AudioCaptureManager::AudioCaptureManager():audiofft(sample.size()) AudioCaptureManager::AudioCaptureManager():audiofft(sample.size())
{ {
...@@ -117,7 +127,7 @@ bool AudioCaptureManager::startCapturingFromInput(unsigned input) { ...@@ -117,7 +127,7 @@ bool AudioCaptureManager::startCapturingFromInput(unsigned input) {
return false; return false;
} }
const auto di = rtAudio.getDeviceInfo(input); const auto di = rtAudio.getDeviceInfo(input);
if (di.inputChannels == 0) { if (di.inputChannels == 0 AUDIO_IF_WIN(&&di.outputChannels == 0)) {
return false; return false;
} }
// it was a device open before now // it was a device open before now
...@@ -130,11 +140,11 @@ bool AudioCaptureManager::startCapturingFromInput(unsigned input) { ...@@ -130,11 +140,11 @@ bool AudioCaptureManager::startCapturingFromInput(unsigned input) {
} else { } else {
sampleRate = static_cast<int>(di.preferredSampleRate); sampleRate = static_cast<int>(di.preferredSampleRate);
} }
initCallback(static_cast<int>(di.inputChannels), sampleRate); initCallback(static_cast<int>(di.inputChannels + di.outputChannels), sampleRate);
RtAudio::StreamParameters isp; RtAudio::StreamParameters isp;
isp.deviceId = input; isp.deviceId = input;
isp.nChannels = di.inputChannels; isp.nChannels = di.inputChannels AUDIO_IF_WIN(+di.outputChannels);
isp.firstChannel = 0; isp.firstChannel = 0;
unsigned samplesPerFrame = static_cast<unsigned>(this->samplesPerFrame); unsigned samplesPerFrame = static_cast<unsigned>(this->samplesPerFrame);
try { try {
...@@ -200,6 +210,20 @@ bool AudioCaptureManager::startCapturingFromCaptureLibrary() { ...@@ -200,6 +210,20 @@ bool AudioCaptureManager::startCapturingFromCaptureLibrary() {
bool AudioCaptureManager::startCapturingFromDefaultInput() { bool AudioCaptureManager::startCapturingFromDefaultInput() {
stopCapturingAndWait(); stopCapturingAndWait();
#ifdef Q_OS_WIN
// check if default output is availible
const auto output = rtAudio.getDefaultOutputDevice();
if (output < rtAudio.getDeviceCount()) {
const auto di = rtAudio.getDeviceInfo(output);
if (di.isDefaultOutput) {
if (startCapturingFromInput(output)) {
currentCaptureDevice = getIndexForDeviceName(di.name.c_str());
emit currentCaptureDeviceChanged();
return true;
}
}
}
#endif
// check if default input is availible // check if default input is availible
const auto input = rtAudio.getDefaultInputDevice(); const auto input = rtAudio.getDefaultInputDevice();
if (input >= rtAudio.getDeviceCount()) { if (input >= rtAudio.getDeviceCount()) {
...@@ -268,7 +292,7 @@ void AudioCaptureManager::updateCaptureDeviceList() { ...@@ -268,7 +292,7 @@ void AudioCaptureManager::updateCaptureDeviceList() {
} }
for (unsigned i = 0; i < rtAudio.getDeviceCount(); ++i) { for (unsigned i = 0; i < rtAudio.getDeviceCount(); ++i) {
if (auto di = rtAudio.getDeviceInfo(i); di.inputChannels > 0) { if (auto di = rtAudio.getDeviceInfo(i); di.inputChannels > 0 AUDIO_IF_WIN(|| di.outputChannels > 0)) {
captureDeviceNames.emplace_back(QString::fromStdString(di.name.c_str())); captureDeviceNames.emplace_back(QString::fromStdString(di.name.c_str()));
} }
} }
......
...@@ -117,7 +117,7 @@ public: ...@@ -117,7 +117,7 @@ public:
*/ */
bool startCapturingFromCaptureLibrary(); bool startCapturingFromCaptureLibrary();
/** /**
* @brief startCapturingFromDefaultInput starts the capturing from the default input device * @brief startCapturingFromDefaultInput starts the capturing from the default input device. On windows from the default output.
* @return true, if the capturing stats successfully, false otherwise * @return true, if the capturing stats successfully, false otherwise
*/ */
bool startCapturingFromDefaultInput(); bool startCapturingFromDefaultInput();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment