mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
refactor(audio): create interface for audio sinks and sources
This commit is contained in:
parent
881aa3083a
commit
c61fcd1f2b
|
@ -239,6 +239,7 @@ set(${PROJECT_NAME}_SOURCES
|
||||||
src/audio/backend/openal.cpp
|
src/audio/backend/openal.cpp
|
||||||
src/audio/backend/openal.h
|
src/audio/backend/openal.h
|
||||||
src/audio/iaudiosettings.h
|
src/audio/iaudiosettings.h
|
||||||
|
src/audio/iaudiosink.h
|
||||||
src/chatlog/chatlinecontent.cpp
|
src/chatlog/chatlinecontent.cpp
|
||||||
src/chatlog/chatlinecontent.h
|
src/chatlog/chatlinecontent.h
|
||||||
src/chatlog/chatlinecontentproxy.cpp
|
src/chatlog/chatlinecontentproxy.cpp
|
||||||
|
|
94
src/audio/iaudiosink.h
Normal file
94
src/audio/iaudiosink.h
Normal file
|
@ -0,0 +1,94 @@
|
||||||
|
#ifndef IAUDIOSINK_H
|
||||||
|
#define IAUDIOSINK_H
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief The IAudioSink class represents an interface to devices that can play audio.
|
||||||
|
*
|
||||||
|
* @enum IAudioSink::Sound
|
||||||
|
* @brief Provides the different sounds for use in the getSound function.
|
||||||
|
* @see getSound
|
||||||
|
*
|
||||||
|
* @value NewMessage Returns the new message notification sound.
|
||||||
|
* @value Test Returns the test sound.
|
||||||
|
* @value IncomingCall Returns the incoming call sound.
|
||||||
|
* @value OutgoingCall Returns the outgoing call sound.
|
||||||
|
*
|
||||||
|
* @fn QString IAudioSink::getSound(Sound s)
|
||||||
|
* @brief Function to get the path of the requested sound.
|
||||||
|
*
|
||||||
|
* @param s Name of the sound to get the path of.
|
||||||
|
* @return The path of the requested sound.
|
||||||
|
*
|
||||||
|
* @fn void IAudioSink::playAudioBuffer(const int16_t* data, int samples,
|
||||||
|
* unsigned channels, int sampleRate)
|
||||||
|
* @brief adds a number of audio frames to the play buffer
|
||||||
|
*
|
||||||
|
* @param[in] data 16bit mono or stereo PCM data with alternating channel
|
||||||
|
* mapping for stereo (LRLR)
|
||||||
|
* @param[in] samples number of samples per channel
|
||||||
|
* @param[in] channels number of channels, currently 1 or 2 is supported
|
||||||
|
* @param[in] sampleRate sample rate in Hertz
|
||||||
|
*
|
||||||
|
* @fn void IAudioSink::playMono16Sound(const Sound& sound)
|
||||||
|
* @brief Play a 44100Hz mono 16bit PCM sound from the builtin sounds.
|
||||||
|
*
|
||||||
|
* @param[in] sound The sound to play
|
||||||
|
*
|
||||||
|
* @fn void IAudioSink::startLoop()
|
||||||
|
* @brief starts looping the sound played with playMono16Sound(...)
|
||||||
|
*
|
||||||
|
* @fn void IAudioSink::stopLoop()
|
||||||
|
* @brief stops looping the sound played with playMono16Sound(...)
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
class IAudioSink : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
enum class Sound
|
||||||
|
{
|
||||||
|
NewMessage,
|
||||||
|
Test,
|
||||||
|
IncomingCall,
|
||||||
|
OutgoingCall,
|
||||||
|
CallEnd
|
||||||
|
};
|
||||||
|
|
||||||
|
inline static QString getSound(Sound s)
|
||||||
|
{
|
||||||
|
switch (s) {
|
||||||
|
case Sound::Test:
|
||||||
|
return QStringLiteral(":/audio/notification.pcm");
|
||||||
|
case Sound::NewMessage:
|
||||||
|
return QStringLiteral(":/audio/notification.pcm");
|
||||||
|
case Sound::IncomingCall:
|
||||||
|
return QStringLiteral(":/audio/ToxIncomingCall.pcm");
|
||||||
|
case Sound::OutgoingCall:
|
||||||
|
return QStringLiteral(":/audio/ToxOutgoingCall.pcm");
|
||||||
|
case Sound::CallEnd:
|
||||||
|
return QStringLiteral(":/audio/ToxEndCall.pcm");
|
||||||
|
}
|
||||||
|
assert(false);
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual ~IAudioSink() {}
|
||||||
|
virtual void playAudioBuffer(const int16_t* data, int samples, unsigned channels,
|
||||||
|
int sampleRate) const = 0;
|
||||||
|
virtual void playMono16Sound(const Sound& sound) = 0;
|
||||||
|
virtual void startLoop() = 0;
|
||||||
|
virtual void stopLoop() = 0;
|
||||||
|
|
||||||
|
virtual operator bool() const = 0;
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void finishedPlaying();
|
||||||
|
void invalidated();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // IAUDIOSINK_H
|
22
src/audio/iaudiosource.h
Normal file
22
src/audio/iaudiosource.h
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
#ifndef IAUDIOSOURCE_H
|
||||||
|
#define IAUDIOSOURCE_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
class Audio;
|
||||||
|
class IAudioSource : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
virtual ~IAudioSource() {}
|
||||||
|
|
||||||
|
virtual operator bool() const = 0;
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void frameAvailable(const int16_t* pcm, size_t sample_count, uint8_t channels,
|
||||||
|
uint32_t sampling_rate);
|
||||||
|
void volumeAvailable(float value);
|
||||||
|
void invalidated();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // IAUDIOSOURCE_H
|
Loading…
Reference in New Issue
Block a user