diff --git a/sdrsrv/webapi/webapiadaptersrv.cpp b/sdrsrv/webapi/webapiadaptersrv.cpp index 2bfc47caf..612f8241a 100644 --- a/sdrsrv/webapi/webapiadaptersrv.cpp +++ b/sdrsrv/webapi/webapiadaptersrv.cpp @@ -25,6 +25,8 @@ #include "SWGInstanceDevicesResponse.h" #include "SWGInstanceChannelsResponse.h" #include "SWGLoggingInfo.h" +#include "SWGAudioDevices.h" +#include "SWGAudioDevicesSelect.h" #include "SWGErrorResponse.h" #include "maincore.h" @@ -35,6 +37,7 @@ #include "device/deviceenumerator.h" #include "dsp/devicesamplesink.h" #include "dsp/devicesamplesource.h" +#include "dsp/dspengine.h" #include "channel/channelsourceapi.h" #include "channel/channelsinkapi.h" #include "plugin/pluginapi.h" @@ -192,6 +195,72 @@ int WebAPIAdapterSrv::instanceLoggingPut( return 200; } +int WebAPIAdapterSrv::instanceAudioGet( + SWGSDRangel::SWGAudioDevices& response, + SWGSDRangel::SWGErrorResponse& error __attribute__((unused))) +{ + const QList& audioInputDevices = m_mainCore.m_audioDeviceInfo.getInputDevices(); + const QList& audioOutputDevices = m_mainCore.m_audioDeviceInfo.getOutputDevices(); + int nbInputDevices = audioInputDevices.size(); + int nbOutputDevices = audioOutputDevices.size(); + + response.init(); + response.setNbInputDevices(nbInputDevices); + response.setInputDeviceSelectedIndex(m_mainCore.m_audioDeviceInfo.getInputDeviceIndex()); + response.setNbOutputDevices(nbOutputDevices); + response.setOutputDeviceSelectedIndex(m_mainCore.m_audioDeviceInfo.getOutputDeviceIndex()); + response.setInputVolume(m_mainCore.m_audioDeviceInfo.getInputVolume()); + QList *inputDevices = response.getInputDevices(); + QList *outputDevices = response.getOutputDevices(); + + for (int i = 0; i < nbInputDevices; i++) + { + inputDevices->append(new SWGSDRangel::SWGAudioDevice); + *inputDevices->back()->getName() = audioInputDevices.at(i).deviceName(); + } + + for (int i = 0; i < nbOutputDevices; i++) + { + outputDevices->append(new SWGSDRangel::SWGAudioDevice); + *outputDevices->back()->getName() = audioOutputDevices.at(i).deviceName(); + } + + return 200; +} + +int WebAPIAdapterSrv::instanceAudioPatch( + SWGSDRangel::SWGAudioDevicesSelect& response, + SWGSDRangel::SWGErrorResponse& error __attribute__((unused))) +{ + // response input is the query actually + float inputVolume = response.getInputVolume(); + int inputIndex = response.getInputIndex(); + int outputIndex = response.getOutputIndex(); + + const QList& audioInputDevices = m_mainCore.m_audioDeviceInfo.getInputDevices(); + const QList& audioOutputDevices = m_mainCore.m_audioDeviceInfo.getOutputDevices(); + int nbInputDevices = audioInputDevices.size(); + int nbOutputDevices = audioOutputDevices.size(); + + inputVolume = inputVolume < 0.0 ? 0.0 : inputVolume > 1.0 ? 1.0 : inputVolume; + inputIndex = inputIndex < -1 ? -1 : inputIndex > nbInputDevices ? nbInputDevices-1 : inputIndex; + outputIndex = outputIndex < -1 ? -1 : outputIndex > nbOutputDevices ? nbOutputDevices-1 : outputIndex; + + m_mainCore.m_audioDeviceInfo.setInputVolume(inputVolume); + m_mainCore.m_audioDeviceInfo.setInputDeviceIndex(inputIndex); + m_mainCore.m_audioDeviceInfo.setOutputDeviceIndex(outputIndex); + + m_mainCore.m_dspEngine->setAudioInputVolume(inputVolume); + m_mainCore.m_dspEngine->setAudioInputDeviceIndex(inputIndex); + m_mainCore.m_dspEngine->setAudioOutputDeviceIndex(outputIndex); + + response.setInputVolume(m_mainCore.m_audioDeviceInfo.getInputVolume()); + response.setInputIndex(m_mainCore.m_audioDeviceInfo.getInputDeviceIndex()); + response.setOutputIndex(m_mainCore.m_audioDeviceInfo.getOutputDeviceIndex()); + + return 200; +} + void WebAPIAdapterSrv::getDeviceSetList(SWGSDRangel::SWGDeviceSetList* deviceSetList) { deviceSetList->init(); diff --git a/sdrsrv/webapi/webapiadaptersrv.h b/sdrsrv/webapi/webapiadaptersrv.h index 25bcea1f8..aa7b94a5b 100644 --- a/sdrsrv/webapi/webapiadaptersrv.h +++ b/sdrsrv/webapi/webapiadaptersrv.h @@ -58,6 +58,14 @@ public: SWGSDRangel::SWGLoggingInfo& response, SWGSDRangel::SWGErrorResponse& error); + virtual int instanceAudioGet( + SWGSDRangel::SWGAudioDevices& response, + SWGSDRangel::SWGErrorResponse& error); + + virtual int instanceAudioPatch( + SWGSDRangel::SWGAudioDevicesSelect& response, + SWGSDRangel::SWGErrorResponse& error); + private: MainCore& m_mainCore;