audioinput.h
Go to the documentation of this file.
00001 /****************************************************************************
00002 **
00003 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
00004 ** All rights reserved.
00005 ** Contact: Nokia Corporation (qt-info@nokia.com)
00006 **
00007 ** This file is part of the examples of the Qt Toolkit.
00008 **
00009 ** $QT_BEGIN_LICENSE:LGPL$
00010 ** Commercial Usage
00011 ** Licensees holding valid Qt Commercial licenses may use this file in
00012 ** accordance with the Qt Commercial License Agreement provided with the
00013 ** Software or, alternatively, in accordance with the terms contained in
00014 ** a written agreement between you and Nokia.
00015 **
00016 ** GNU Lesser General Public License Usage
00017 ** Alternatively, this file may be used under the terms of the GNU Lesser
00018 ** General Public License version 2.1 as published by the Free Software
00019 ** Foundation and appearing in the file LICENSE.LGPL included in the
00020 ** packaging of this file.  Please review the following information to
00021 ** ensure the GNU Lesser General Public License version 2.1 requirements
00022 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
00023 **
00024 ** In addition, as a special exception, Nokia gives you certain additional
00025 ** rights.  These rights are described in the Nokia Qt LGPL Exception
00026 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
00027 **
00028 ** GNU General Public License Usage
00029 ** Alternatively, this file may be used under the terms of the GNU
00030 ** General Public License version 3.0 as published by the Free Software
00031 ** Foundation and appearing in the file LICENSE.GPL included in the
00032 ** packaging of this file.  Please review the following information to
00033 ** ensure the GNU General Public License version 3.0 requirements will be
00034 ** met: http://www.gnu.org/copyleft/gpl.html.
00035 **
00036 ** If you have questions regarding the use of this file, please contact
00037 ** Nokia at qt-info@nokia.com.
00038 ** $QT_END_LICENSE$
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 


rospeex_audiomonitor
Author(s): Komei Sugiura
autogenerated on Thu Jun 6 2019 18:53:06