2013-07-30 20:36:14 +00:00
|
|
|
#ifndef QAUDIO_INPUT
|
2012-05-22 17:09:48 +00:00
|
|
|
#ifndef SOUNDIN_H
|
|
|
|
#define SOUNDIN_H
|
|
|
|
|
2013-07-30 00:51:42 +00:00
|
|
|
#include <portaudio.h>
|
|
|
|
|
2012-05-22 17:09:48 +00:00
|
|
|
#include <QtCore>
|
2013-07-30 00:51:42 +00:00
|
|
|
#include <QScopedPointer>
|
2012-05-22 17:09:48 +00:00
|
|
|
#include <QDebug>
|
|
|
|
|
2013-07-30 00:51:42 +00:00
|
|
|
extern "C" int a2dCallback( const void *, void *, unsigned long, PaStreamCallbackTimeInfo const *, PaStreamCallbackFlags, void *);
|
2012-05-22 17:09:48 +00:00
|
|
|
|
2013-07-30 00:51:42 +00:00
|
|
|
// Gets audio data from soundcard and signals when a buffer of
|
2012-05-22 17:09:48 +00:00
|
|
|
// specified size is available.
|
2013-07-30 00:51:42 +00:00
|
|
|
class SoundInput : public QObject
|
2012-05-22 17:09:48 +00:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2013-07-30 00:51:42 +00:00
|
|
|
SoundInput();
|
|
|
|
~SoundInput();
|
2012-05-22 17:09:48 +00:00
|
|
|
|
2013-07-30 00:51:42 +00:00
|
|
|
void setMonitoring(bool b);
|
|
|
|
void setPeriod(int ntrperiod, int nsps) /* this can be called while processing samples */
|
2012-05-22 17:09:48 +00:00
|
|
|
{
|
2013-07-30 00:51:42 +00:00
|
|
|
m_TRperiod=ntrperiod;
|
|
|
|
m_nsps=nsps;
|
2012-05-22 17:09:48 +00:00
|
|
|
}
|
2013-07-30 00:51:42 +00:00
|
|
|
int mstep() const {return m_step;}
|
|
|
|
double samFacIn() const {return m_SamFacIn;}
|
2012-05-22 17:09:48 +00:00
|
|
|
|
|
|
|
signals:
|
|
|
|
void readyForFFT(int k);
|
|
|
|
void error(const QString& message);
|
|
|
|
void status(const QString& message);
|
|
|
|
|
|
|
|
public slots:
|
2013-07-30 00:51:42 +00:00
|
|
|
void start(qint32 device);
|
|
|
|
void intervalNotify();
|
|
|
|
void stop();
|
2012-05-22 17:09:48 +00:00
|
|
|
|
|
|
|
private:
|
2013-07-30 00:51:42 +00:00
|
|
|
PaStream * m_inStream;
|
|
|
|
bool m_dataSinkBusy;
|
2012-11-13 20:23:03 +00:00
|
|
|
double m_SamFacIn; //(Input sample rate)/12000.0
|
2012-07-04 16:27:57 +00:00
|
|
|
qint32 m_step;
|
2012-09-24 19:11:31 +00:00
|
|
|
qint32 m_TRperiod;
|
|
|
|
qint32 m_TRperiod0;
|
2012-09-26 00:48:49 +00:00
|
|
|
qint32 m_nsps;
|
2012-11-13 20:23:03 +00:00
|
|
|
bool m_monitoring;
|
2013-07-30 00:51:42 +00:00
|
|
|
qint64 m_ms0;
|
|
|
|
int m_ntr0;
|
|
|
|
int m_nBusy;
|
|
|
|
int m_nstep0;
|
|
|
|
int m_nsps0;
|
|
|
|
|
|
|
|
QTimer m_intervalTimer;
|
|
|
|
|
|
|
|
struct CallbackData
|
|
|
|
{
|
|
|
|
int kin; //Parameters sent to/from the portaudio callback function
|
|
|
|
int ncall;
|
|
|
|
bool bzero;
|
|
|
|
bool monitoring;
|
|
|
|
} m_callbackData;
|
|
|
|
|
|
|
|
friend int a2dCallback(void const *, void *, unsigned long, PaStreamCallbackTimeInfo const *, PaStreamCallbackFlags, void *);
|
2012-05-22 17:09:48 +00:00
|
|
|
};
|
|
|
|
#endif // SOUNDIN_H
|
2013-07-30 20:36:14 +00:00
|
|
|
|
|
|
|
#else // QAUDIO_INPUT
|
|
|
|
#ifndef SOUNDIN_H
|
|
|
|
#define SOUNDIN_H
|
|
|
|
|
|
|
|
#include <QtCore>
|
|
|
|
#include <QScopedPointer>
|
|
|
|
#include <QDebug>
|
|
|
|
#include <QAudioDeviceInfo>
|
|
|
|
#include <QAudioInput>
|
|
|
|
|
|
|
|
// Gets audio data from soundcard and signals when a buffer of
|
|
|
|
// specified size is available.
|
|
|
|
class SoundInput : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
SoundInput();
|
|
|
|
~SoundInput();
|
|
|
|
|
|
|
|
void setMonitoring(bool b);
|
|
|
|
void setPeriod(int ntrperiod, int nsps) /* this can be called while processing samples */
|
|
|
|
{
|
|
|
|
m_TRperiod=ntrperiod;
|
|
|
|
m_nsps=nsps;
|
|
|
|
}
|
|
|
|
int mstep() const {return m_step;}
|
|
|
|
double samFacIn() const {return m_SamFacIn;}
|
|
|
|
|
|
|
|
signals:
|
|
|
|
void readyForFFT(int k);
|
|
|
|
void error(const QString& message);
|
|
|
|
void status(const QString& message);
|
|
|
|
|
|
|
|
public slots:
|
|
|
|
void start(qint32 device);
|
|
|
|
void intervalNotify();
|
|
|
|
void stop();
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool m_dataSinkBusy;
|
|
|
|
double m_SamFacIn; //(Input sample rate)/12000.0
|
|
|
|
qint32 m_step;
|
|
|
|
qint32 m_TRperiod;
|
|
|
|
qint32 m_TRperiod0;
|
|
|
|
qint32 m_nsps;
|
|
|
|
bool m_monitoring;
|
|
|
|
qint64 m_ms0;
|
|
|
|
int m_ntr0;
|
|
|
|
int m_nBusy;
|
|
|
|
int m_nstep0;
|
|
|
|
int m_nsps0;
|
|
|
|
|
|
|
|
QTimer m_intervalTimer;
|
|
|
|
QAudioDeviceInfo inputDevice; // audioinput device name
|
|
|
|
QAudioInput* audioInput;
|
|
|
|
QIODevice* stream;
|
|
|
|
|
|
|
|
struct CallbackData
|
|
|
|
{
|
|
|
|
int kin; //Parameters sent to/from the portaudio callback function
|
|
|
|
int ncall;
|
|
|
|
bool bzero;
|
|
|
|
bool monitoring;
|
|
|
|
} m_callbackData;
|
|
|
|
};
|
|
|
|
#endif // SOUNDIN_H
|
|
|
|
#endif // QAUDIO_INPUT
|