diff options
Diffstat (limited to 'soundin.h')
| -rw-r--r-- | soundin.h | 72 |
1 files changed, 36 insertions, 36 deletions
@@ -1,50 +1,50 @@ -#ifndef SOUNDIN_H -#define SOUNDIN_H +// -*- Mode: C++ -*- +#ifndef SOUNDIN_H__ +#define SOUNDIN_H__ -#include <QtCore> -#include <QDebug> +#include <QObject> +#include <QString> +#include <QScopedPointer> +#include <QAudioInput> +#include "AudioDevice.hpp" -// Thread gets audio data from soundcard and signals when a buffer of -// specified size is available. -class SoundInThread : public QThread -{ - Q_OBJECT - bool quitExecution; // if true, thread exits gracefully +class QAudioDeviceInfo; +class QAudioInput; -protected: - virtual void run(); +// Gets audio data from sound sample source and passes it to a sink device +class SoundInput + : public QObject +{ + Q_OBJECT; public: - bool m_dataSinkBusy; - - SoundInThread(): - quitExecution(false), - m_dataSinkBusy(false) + SoundInput (QObject * parent = nullptr) + : QObject {parent} + , m_sink {nullptr} { } - void setInputDevice(qint32 n); - void setMonitoring(bool b); - void setPeriod(int ntrperiod, int nsps); - int mstep(); - double samFacIn(); + ~SoundInput (); -signals: - void readyForFFT(int k); - void error(const QString& message); - void status(const QString& message); + // sink must exist from the start call until the next start call or + // stop call + Q_SLOT void start(QAudioDeviceInfo const&, int framesPerBuffer, AudioDevice * sink, unsigned downSampleFactor, AudioDevice::Channel = AudioDevice::Mono); + Q_SLOT void suspend (); + Q_SLOT void resume (); + Q_SLOT void stop (); -public slots: - void quit(); + Q_SIGNAL void error (QString message) const; + Q_SIGNAL void status (QString message) const; private: - double m_SamFacIn; //(Input sample rate)/12000.0 - qint32 m_step; - qint32 m_nDevIn; - qint32 m_TRperiod; - qint32 m_TRperiod0; - qint32 m_nsps; - bool m_monitoring; + // used internally + Q_SLOT void handleStateChanged (QAudio::State) const; + + bool audioError () const; + + QScopedPointer<QAudioInput> m_stream; + AudioDevice * m_sink; }; -#endif // SOUNDIN_H + +#endif |
