diff --git a/src/blackcore/audio_mixer.cpp b/src/blackcore/audio_mixer.cpp new file mode 100644 index 000000000..98879c59b --- /dev/null +++ b/src/blackcore/audio_mixer.cpp @@ -0,0 +1,16 @@ +/* Copyright (C) 2014 + * swift project community / contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +#include "audio_mixer.h" + +namespace BlackCore +{ + IAudioMixer::IAudioMixer(QObject *parent) : QObject(parent) + { } +} diff --git a/src/blackcore/audio_mixer.h b/src/blackcore/audio_mixer.h new file mode 100644 index 000000000..97f2d1cf5 --- /dev/null +++ b/src/blackcore/audio_mixer.h @@ -0,0 +1,61 @@ +/* Copyright (C) 2014 + * swift project community / contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +#ifndef BLACKCORE_AUDIOMIXER_H +#define BLACKCORE_AUDIOMIXER_H + +#include + +namespace BlackCore +{ + //! Interface to an audio mixer + class IAudioMixer : public QObject + { + Q_OBJECT + + public: + + //! Audio mixer input ports + enum InputPort + { + InputMicrophone, + InputVoiceChannel1, + InputVoiceChannel2, + }; + + //! Audio mixer output ports + enum OutputPort + { + OutputOutputDevice1, + OutputVoiceChannel1, + OutputVoiceChannel2, + }; + + /*! + * \brief Default constructor with parent + * \param parent + */ + IAudioMixer(QObject *parent = nullptr); + + //! Virtual destructor. + virtual ~IAudioMixer() {} + + //! Connect mixer input to a mixer output. This causes audio to be routed from the input to output + virtual void makeMixerConnection(InputPort inputPort, OutputPort outputPort) = 0; + + //! Remove the mixer connection from input to output + virtual void removeMixerConnection(InputPort inputPort, OutputPort outputPort) = 0; + + //! Returns true if input port and output port are connected + virtual bool hasMixerConnection(InputPort inputPort, OutputPort outputPort) = 0; + }; + +} // namespace BlackCore + +#endif // guard diff --git a/src/blackcore/audio_mixer_vatlib.cpp b/src/blackcore/audio_mixer_vatlib.cpp new file mode 100644 index 000000000..81dd491f0 --- /dev/null +++ b/src/blackcore/audio_mixer_vatlib.cpp @@ -0,0 +1,34 @@ +/* Copyright (C) 2014 + * swift project community / contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +#include "audio_mixer_vatlib.h" + +namespace BlackCore +{ + CAudioMixerVatlib::CAudioMixerVatlib(QObject *parent) + : IAudioMixer(parent) + { + m_audioMixer.reset(Vat_CreateAudioMixer()); + } + + void CAudioMixerVatlib::makeMixerConnection(InputPort inputPort, OutputPort outputPort) + { + Vat_MakeMixerConnection(m_audioMixer.data(), inputPort, outputPort, true); + } + + void CAudioMixerVatlib::removeMixerConnection(InputPort inputPort, OutputPort outputPort) + { + Vat_MakeMixerConnection(m_audioMixer.data(), inputPort, outputPort, false); + } + + bool CAudioMixerVatlib::hasMixerConnection(InputPort inputPort, OutputPort outputPort) + { + return Vat_HasMixerConnection(m_audioMixer.data(), inputPort, outputPort); + } +} diff --git a/src/blackcore/audio_mixer_vatlib.h b/src/blackcore/audio_mixer_vatlib.h new file mode 100644 index 000000000..82cc96ccc --- /dev/null +++ b/src/blackcore/audio_mixer_vatlib.h @@ -0,0 +1,64 @@ +/* Copyright (C) 2014 + * swift project community / contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +#ifndef BLACKCORE_AUDIOMIXERVATLIB_H +#define BLACKCORE_AUDIOMIXERVATLIB_H + +#include "audio_mixer.h" + +#include "vatlib/vatlib2.h" +#include + +namespace BlackCore +{ + //! Interface to an audio mixer + class CAudioMixerVatlib : public IAudioMixer + { + Q_OBJECT + + public: + + /*! + * \brief Default constructor with parent + * \param parent + */ + CAudioMixerVatlib(QObject *parent = nullptr); + + //! Virtual destructor. + virtual ~CAudioMixerVatlib() {} + + //! \copydoc IAudioMixer::makeMixerConnection + virtual void makeMixerConnection(InputPort inputPort, OutputPort outputPort) override; + + //! \copydoc IAudioMixer::removeMixerConnection + virtual void removeMixerConnection(InputPort inputPort, OutputPort outputPort) override; + + //! \copydoc IAudioMixer::hasMixerConnection + virtual bool hasMixerConnection(InputPort inputPort, OutputPort outputPort) override; + + //! Return the pointer to vatlib audio mixer + VatAudioMixer getVatAudioMixer() { return m_audioMixer.data(); } + + private: + + struct VatAudioMixerDeleter + { + static inline void cleanup(VatProducerConsumer_tag *obj) + { + if (obj) Vat_DestroyAudioMixer(obj); + } + }; + + QScopedPointer m_audioMixer; + + }; + +} // namespace BlackCore + +#endif // guard diff --git a/src/blackcore/voice.h b/src/blackcore/voice.h index dd0537645..abd6e827d 100644 --- a/src/blackcore/voice.h +++ b/src/blackcore/voice.h @@ -8,6 +8,7 @@ #include "audio_device.h" #include "voice_channel.h" +#include "audio_mixer.h" #include "../blackmisc/avcallsignlist.h" #include "../blackmisc/avselcal.h" @@ -47,6 +48,8 @@ namespace BlackCore //! Create output device object virtual std::unique_ptr createOutputDevice() = 0; + //! Create audio mixer object + virtual std::unique_ptr createAudioMixer() = 0; //! Connect voice channel to an audio output device virtual void connectChannelOutputDevice(IVoiceChannel *channel, IAudioOutputDevice *device) = 0; diff --git a/src/blackcore/voice_vatlib.cpp b/src/blackcore/voice_vatlib.cpp index 85f16eb0e..56e6d7f5a 100644 --- a/src/blackcore/voice_vatlib.cpp +++ b/src/blackcore/voice_vatlib.cpp @@ -6,6 +6,7 @@ #include "voice_vatlib.h" #include "voice_channel_vatlib.h" #include "audio_device_vatlib.h" +#include "audio_mixer_vatlib.h" #include "blackmisc/logmessage.h" #include "blackmisc/blackmiscfreefunctions.h" #include @@ -53,6 +54,11 @@ namespace BlackCore return make_unique(m_audioService.data(), this); } + std::unique_ptr CVoiceVatlib::createAudioMixer() + { + return make_unique(this); + } + /* FIXME: Can the following methods be more general somehow? E.g.: diff --git a/src/blackcore/voice_vatlib.h b/src/blackcore/voice_vatlib.h index 34487db9d..ec038f800 100644 --- a/src/blackcore/voice_vatlib.h +++ b/src/blackcore/voice_vatlib.h @@ -45,6 +45,8 @@ namespace BlackCore //! \copydoc IVoice::createOutputDevice() virtual std::unique_ptr createOutputDevice() override; + //! \copydoc IVoice::createAudioMixer() + virtual std::unique_ptr createAudioMixer() override; //! \copydoc IVoice::connectChannelOutputDevice() virtual void connectChannelOutputDevice(IVoiceChannel *channel, IAudioOutputDevice *device) override;