Classified ads
audiosource.h
Go to the documentation of this file.
1 /* -*-C++-*- -*-coding: utf-8-unix;-*-
2  Classified Ads is Copyright (c) Antti Järvinen 2015.
3 
4  This file is part of Classified Ads.
5 
6  Classified Ads is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Lesser General Public
8  License as published by the Free Software Foundation; either
9  version 2.1 of the License, or (at your option) any later version.
10 
11  Classified Ads is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Lesser General Public License for more details.
15 
16  You should have received a copy of the GNU Lesser General Public
17  License along with Classified Ads; if not, write to the Free Software
18  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20 
21 #ifndef AUDIO_SOURCE_H
22 #define AUDIO_SOURCE_H
23 
24 #include <QAudioFormat>
25 #include <QAudio> // type definitions
26 #include <QByteArray>
27 #include <QTimer>
28 #include <QIODevice>
29 
30 class QAudioInput ;
31 class Model ;
32 
41 class AudioSource : public QIODevice {
42  Q_OBJECT
43 
44 public:
48  AudioSource(Model& aModel) ;
49  ~AudioSource() ;
53  quint32 getCurrentSeqNo() const { return iSeqNo ; } ;
57  void stopCapturing() ;
58 // next methods inherited from QIODevice:
59 protected:
68  virtual qint64 writeData ( const char * data, qint64 maxSize ) ;
75  virtual qint64 readData ( char * data, qint64 maxSize ) ;
79  virtual bool open ( OpenMode mode ) ;
80  /*
81  * method for opening QIODevice: tells that this is no random-access
82  * device.
83  *
84  * @return true always
85  */
86  virtual bool isSequential () const {
87  return true ; // is not random-access,
88  }
92  void timerEvent(QTimerEvent *event);
93 signals:
103  void frameCaptured(const QByteArray& aFrame,
104  quint32 aSeqNo,
105  float aVolumeLevel) ;
109  void audioMaxLevel(float aMaxVolume) ;
110 public slots:
115  void processCapturedAudio() ;
119  void inputStatusChanged(QAudio::State aState) ;
120 private: // members
121  QAudioFormat iFormat;
122  QAudioInput* iAudioInput ;
123  QByteArray iAudioBuffer ;
124  quint32 iSeqNo ;
125  bool iNeedsToRun ;
127  int iTimerId ;
128 } ;
129 #endif
opposite of audiosink.
Definition: audiosource.h:41
void timerEvent(QTimerEvent *event)
void stopCapturing()
virtual qint64 writeData(const char *data, qint64 maxSize)
void audioMaxLevel(float aMaxVolume)
virtual bool open(OpenMode mode)
QAudioFormat iFormat
Definition: audiosource.h:121
virtual bool isSequential() const
Definition: audiosource.h:86
M of the MVC pattern. Handles permanent storage.
Definition: model.h:50
QByteArray iAudioBuffer
Definition: audiosource.h:123
virtual qint64 readData(char *data, qint64 maxSize)
bool iNeedsToRun
Definition: audiosource.h:125
void processCapturedAudio()
Model & iModel
Definition: audiosource.h:126
void frameCaptured(const QByteArray &aFrame, quint32 aSeqNo, float aVolumeLevel)
QAudioInput * iAudioInput
Definition: audiosource.h:122
int iTimerId
Definition: audiosource.h:127
quint32 getCurrentSeqNo() const
Definition: audiosource.h:53
quint32 iSeqNo
Definition: audiosource.h:124
AudioSource(Model &aModel)
void inputStatusChanged(QAudio::State aState)