mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-31 21:15:33 +08:00
refs #372 Add audio mixer interface and vatlib implementation
This class is an audio router. In order to route audio connect a producer to an input port and a consumer to an output port. The connection is later established by making the mixer connection between an input and an output port.
This commit is contained in:
committed by
Klaus Basan
parent
5146b7357d
commit
8812f3ba28
16
src/blackcore/audio_mixer.cpp
Normal file
16
src/blackcore/audio_mixer.cpp
Normal file
@@ -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)
|
||||
{ }
|
||||
}
|
||||
61
src/blackcore/audio_mixer.h
Normal file
61
src/blackcore/audio_mixer.h
Normal file
@@ -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 <QObject>
|
||||
|
||||
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
|
||||
34
src/blackcore/audio_mixer_vatlib.cpp
Normal file
34
src/blackcore/audio_mixer_vatlib.cpp
Normal file
@@ -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);
|
||||
}
|
||||
}
|
||||
64
src/blackcore/audio_mixer_vatlib.h
Normal file
64
src/blackcore/audio_mixer_vatlib.h
Normal file
@@ -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 <QScopedPointer>
|
||||
|
||||
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<VatProducerConsumer_tag, VatAudioMixerDeleter> m_audioMixer;
|
||||
|
||||
};
|
||||
|
||||
} // namespace BlackCore
|
||||
|
||||
#endif // guard
|
||||
@@ -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<IAudioOutputDevice> createOutputDevice() = 0;
|
||||
|
||||
//! Create audio mixer object
|
||||
virtual std::unique_ptr<IAudioMixer> createAudioMixer() = 0;
|
||||
//! Connect voice channel to an audio output device
|
||||
virtual void connectChannelOutputDevice(IVoiceChannel *channel, IAudioOutputDevice *device) = 0;
|
||||
|
||||
|
||||
@@ -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 <QDebug>
|
||||
@@ -53,6 +54,11 @@ namespace BlackCore
|
||||
return make_unique<CAudioOutputDeviceVatlib>(m_audioService.data(), this);
|
||||
}
|
||||
|
||||
std::unique_ptr<IAudioMixer> CVoiceVatlib::createAudioMixer()
|
||||
{
|
||||
return make_unique<CAudioMixerVatlib>(this);
|
||||
}
|
||||
|
||||
/* FIXME:
|
||||
Can the following methods be more general somehow?
|
||||
E.g.:
|
||||
|
||||
@@ -45,6 +45,8 @@ namespace BlackCore
|
||||
//! \copydoc IVoice::createOutputDevice()
|
||||
virtual std::unique_ptr<IAudioOutputDevice> createOutputDevice() override;
|
||||
|
||||
//! \copydoc IVoice::createAudioMixer()
|
||||
virtual std::unique_ptr<IAudioMixer> createAudioMixer() override;
|
||||
//! \copydoc IVoice::connectChannelOutputDevice()
|
||||
virtual void connectChannelOutputDevice(IVoiceChannel *channel, IAudioOutputDevice *device) override;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user