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