Classified ads
audioplayer.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_PLAYER_H
22 #define AUDIO_PLAYER_H
23 
24 #include <QObject>
25 #include <QByteArray>
26 #include <QAudioOutput>
27 #include <QIODevice>
28 
29 class Model ;
30 
38 class AudioPlayer : public QIODevice {
39  Q_OBJECT
40 
41 public:
54  AudioPlayer(Model& aModel,
55  int aFrequency = 8000,
56  int aNumChannels = 1,
57  int aSampleSize = 16 ) ;
58  ~AudioPlayer() ;
62  void stop() ;
63 // next methods inherited from QIODevice:
64 public:
65  virtual qint64 bytesAvailable () const {
66  return iAudioBuffer.size() + QIODevice::bytesAvailable();
67  }
68 protected:
80  virtual qint64 writeData ( const char * data, qint64 maxSize ) ;
91  virtual qint64 readData ( char * data, qint64 maxSize ) ;
95  virtual bool open ( OpenMode mode ) ;
96  /*
97  * method for opening QIODevice: tells that this is no random-access
98  * device.
99  *
100  * @return true always
101  */
102  virtual bool isSequential () const {
103  return true ; // is not random-access,
104  }
105 signals:
109  void error(int aError,
110  const QString& aExplanation) ;
114  void audioMaxLevel(float aMaxVolume) ;
115 public slots:
122  void insertAudioFrame ( const QByteArray& aFrame );
123 
127  void finishedPlaying ( QAudio::State aState );
128 
132  void notify() ;
133 
134 private: // members
135  QAudioFormat iFormat;
136  QAudioOutput* iAudioOutput ;
137  QByteArray iAudioBuffer ;
138  bool iNeedsToRun ;
140  const int iFrequency ;
141  const int iNumChannels ;
142  const int iSampleSize ;
143 } ;
144 #endif
const int iSampleSize
Definition: audioplayer.h:142
virtual qint64 writeData(const char *data, qint64 maxSize)
virtual qint64 readData(char *data, qint64 maxSize)
void insertAudioFrame(const QByteArray &aFrame)
AudioPlayer(Model &aModel, int aFrequency=8000, int aNumChannels=1, int aSampleSize=16)
virtual bool open(OpenMode mode)
Model & iModel
Definition: audioplayer.h:139
bool iNeedsToRun
Definition: audioplayer.h:138
Class for playback of audio stream, via speaker or other audio dev.
Definition: audioplayer.h:38
virtual bool isSequential() const
Definition: audioplayer.h:102
QAudioFormat iFormat
Definition: audioplayer.h:135
const int iNumChannels
Definition: audioplayer.h:141
QAudioOutput * iAudioOutput
Definition: audioplayer.h:136
M of the MVC pattern. Handles permanent storage.
Definition: model.h:50
const int iFrequency
Definition: audioplayer.h:140
QByteArray iAudioBuffer
Definition: audioplayer.h:137
void error(int aError, const QString &aExplanation)
void notify()
void audioMaxLevel(float aMaxVolume)
virtual qint64 bytesAvailable() const
Definition: audioplayer.h:65
void finishedPlaying(QAudio::State aState)