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:
101  void frameCaptured(const QByteArray& aFrame,quint32 aSeqNo) ;
105  void audioMaxLevel(float aMaxVolume) ;
106 public slots:
111  void processCapturedAudio() ;
115  void inputStatusChanged(QAudio::State aState) ;
116 private: // members
117  QAudioFormat iFormat;
118  QAudioInput* iAudioInput ;
119  QByteArray iAudioBuffer ;
120  quint32 iSeqNo ;
121  bool iNeedsToRun ;
123  int iTimerId ;
124 } ;
125 #endif
opposite of audiosink.
Definition: audiosource.h:41
void timerEvent(QTimerEvent *event)
void stopCapturing()
quint32 getCurrentSeqNo() const
Definition: audiosource.h:53
void frameCaptured(const QByteArray &aFrame, quint32 aSeqNo)
virtual qint64 writeData(const char *data, qint64 maxSize)
void audioMaxLevel(float aMaxVolume)
virtual bool open(OpenMode mode)
virtual bool isSequential() const
Definition: audiosource.h:86
QAudioFormat iFormat
Definition: audiosource.h:117
M of the MVC pattern. Handles permanent storage.
Definition: model.h:48
QByteArray iAudioBuffer
Definition: audiosource.h:119
virtual qint64 readData(char *data, qint64 maxSize)
bool iNeedsToRun
Definition: audiosource.h:121
void processCapturedAudio()
Model & iModel
Definition: audiosource.h:122
QAudioInput * iAudioInput
Definition: audiosource.h:118
int iTimerId
Definition: audiosource.h:123
quint32 iSeqNo
Definition: audiosource.h:120
AudioSource(Model &aModel)
void inputStatusChanged(QAudio::State aState)