Go to the documentation of this file.00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 
00031 
00032 
00033 
00034 
00035 
00036 
00037 
00038 
00039 
00040 
00041 
00042 #include <QPixmap>
00043 
00044 #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
00045 #include <QtWidgets>
00046 #else
00047 #include <QWidget>
00048 #include <QMainWindow>
00049 #endif
00050 
00051 #include <QObject>
00052 #include <QPushButton>
00053 #include <QComboBox>
00054 #include <qaudioinput.h>
00055 #include <QFile>
00056 #include <QQueue>
00057 
00058 #include "soundserver.h"
00059 #include "AtrasrClient.h"
00060 extern ATRASR_CLIENT _atrasrClient;
00061 extern int _epdPort;
00062 
00063 class AudioInfo : public QIODevice
00064 {
00065     Q_OBJECT
00066 public:
00067     AudioInfo(QObject* parent, QAudioInput* device, SoundServer *server);
00068     ~AudioInfo();
00069 
00070     void start();
00071     void stop();
00072 
00073     class Level
00074     {
00075     public:
00076         Level(int _min = 0, int _max = 0, bool _isRecording = false, bool _isEpdOn = true)
00077             : min(_min/32768.0), max(_max/32768.0), recording(_isRecording), epdOn(_isEpdOn)
00078         {
00079 
00080         }
00081 
00082         float min;
00083         float max;
00084         bool recording;
00085         bool epdOn;
00086     };
00087     QList<Level> getLevels();
00088 
00089     qint64 readData(char *data, qint64 maxlen);
00090     qint64 writeData(const char *data, qint64 len);
00091 
00092     bool epdEnabled() const;
00093     void setEpdEnabled(bool bEnabled);
00094 
00095     static void setFileName(const QString& filename);
00096 
00097 private:
00098     void processWave(const void *data, qint64 len);
00099     QAudioInput*   input;
00100 
00101 public slots:
00102     void recstart();
00103     void recstop(bool bEnd = true);
00104 
00105 private slots:
00106     void epdRead();
00107     void onCmd(const QString &cmd);
00108     void onClientConnected(const QHostAddress &addr);
00109     void epdDisconnected();
00110 
00111 private:
00112     bool m_bRec;
00113     bool m_bEpdOn;
00114     bool m_bEpdEnabled;
00115     QList<Level> m_levels;
00116     QFile *m_file;
00117     int m_sampleSize;
00118     static QString m_filename;
00119     SoundServer *m_server;
00120 
00121 signals:
00122     void update();
00123     void validateRecButton(bool);
00124 };
00125 
00126 
00127 class RenderArea : public QWidget
00128 {
00129     Q_OBJECT
00130 
00131 public:
00132     RenderArea(QWidget *parent = 0);
00133 
00134     void setLevel(const QList<AudioInfo::Level> &levels);
00135 
00136 protected:
00137     void paintEvent(QPaintEvent *event);
00138 
00139 private:
00140     QQueue<AudioInfo::Level> m_levels;
00141 
00142     static int STEP;
00143 };
00144 
00145 class SoundServerApp : public QMainWindow
00146 {
00147     Q_OBJECT
00148 public:
00149     SoundServerApp(SoundServer *server);
00150     ~SoundServerApp();
00151 
00152 private:
00153     SoundServer *server;
00154 
00155     QAudioDeviceInfo device;
00156     QAudioFormat   format;
00157     QAudioInput*   audioInput;
00158     AudioInfo*     audioinfo;
00159     QIODevice*     input;
00160     RenderArea*    canvas;
00161 
00162     bool           pullMode;
00163 
00164     QPushButton*   recButton;
00165     QPushButton*   button;
00166     QPushButton*   button2;
00167     QComboBox*     deviceBox;
00168 
00169     char*          buffer;
00170 
00171 private slots:
00172     void refreshDisplay();
00173     void status();
00174     void readMore();
00175     void toggleMode();
00176     void toggleSuspend();
00177     void state(QAudio::State s);
00178     void deviceChanged(int idx);
00179     void epdEnableChanged(bool);
00180     void epdSpeechChanged(bool);
00181 
00182     void recstart();
00183 };
00184