2013-08-05 09:57:55 -04:00
|
|
|
#ifndef SOUNDOUT_H__
|
|
|
|
#define SOUNDOUT_H__
|
2013-07-31 20:49:58 -04:00
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
#include <QString>
|
2013-08-05 09:57:55 -04:00
|
|
|
#include <QAudioOutput>
|
2013-08-07 19:09:13 -04:00
|
|
|
#include <QAudioDeviceInfo>
|
2013-08-05 09:57:55 -04:00
|
|
|
|
2013-08-07 19:09:13 -04:00
|
|
|
class QAudioDeviceInfo;
|
2013-07-31 20:49:58 -04:00
|
|
|
|
|
|
|
// An instance of this sends audio data to a specified soundcard.
|
2012-05-22 13:09:48 -04:00
|
|
|
|
2013-07-31 20:49:58 -04:00
|
|
|
class SoundOutput : public QObject
|
2012-05-22 13:09:48 -04:00
|
|
|
{
|
2013-07-31 20:49:58 -04:00
|
|
|
Q_OBJECT;
|
2012-05-22 13:09:48 -04:00
|
|
|
|
2013-07-31 20:49:58 -04:00
|
|
|
Q_PROPERTY(bool running READ isRunning);
|
2013-08-10 11:29:55 -04:00
|
|
|
Q_PROPERTY(unsigned attenuation READ attenuation WRITE setAttenuation RESET resetAttenuation);
|
2012-05-22 13:09:48 -04:00
|
|
|
|
2013-08-05 09:57:55 -04:00
|
|
|
private:
|
|
|
|
Q_DISABLE_COPY (SoundOutput);
|
|
|
|
|
|
|
|
public:
|
2013-08-07 19:09:13 -04:00
|
|
|
SoundOutput (QIODevice * source);
|
2013-08-05 09:57:55 -04:00
|
|
|
~SoundOutput ();
|
2012-05-22 13:09:48 -04:00
|
|
|
|
2013-07-31 20:49:58 -04:00
|
|
|
bool isRunning() const {return m_active;}
|
2013-08-10 11:29:55 -04:00
|
|
|
qreal attenuation () const;
|
2013-08-05 09:57:55 -04:00
|
|
|
|
2013-08-10 11:29:55 -04:00
|
|
|
private Q_SLOTS:
|
|
|
|
/* private because we expect to run in a thread and don't want direct
|
|
|
|
C++ calls made, instead they must be invoked via the Qt
|
|
|
|
signal/slot mechanism which is thread safe */
|
2013-09-26 21:06:23 -04:00
|
|
|
void startStream (QAudioDeviceInfo const& device, unsigned channels, unsigned msBuffered = 0u);
|
2013-08-07 19:09:13 -04:00
|
|
|
void suspend ();
|
|
|
|
void resume ();
|
|
|
|
void stopStream ();
|
2013-08-10 11:29:55 -04:00
|
|
|
void setAttenuation (qreal); /* unsigned */
|
|
|
|
void resetAttenuation (); /* to zero */
|
2012-05-22 13:09:48 -04:00
|
|
|
|
2013-08-07 19:09:13 -04:00
|
|
|
Q_SIGNALS:
|
2013-08-05 09:57:55 -04:00
|
|
|
void error (QString message) const;
|
|
|
|
void status (QString message) const;
|
|
|
|
|
2012-05-22 13:09:48 -04:00
|
|
|
private:
|
2013-08-05 09:57:55 -04:00
|
|
|
bool audioError () const;
|
|
|
|
|
2013-08-07 19:09:13 -04:00
|
|
|
private Q_SLOTS:
|
|
|
|
void handleStateChanged (QAudio::State);
|
2013-07-31 20:49:58 -04:00
|
|
|
|
2013-08-05 09:57:55 -04:00
|
|
|
private:
|
|
|
|
QScopedPointer<QAudioOutput> m_stream;
|
|
|
|
|
2013-08-07 19:09:13 -04:00
|
|
|
QIODevice * m_source;
|
|
|
|
bool volatile m_active;
|
|
|
|
QAudioDeviceInfo m_currentDevice;
|
2013-08-10 11:29:55 -04:00
|
|
|
qreal m_volume;
|
2012-05-22 13:09:48 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|