-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaudiomonitor.h
71 lines (55 loc) · 2.23 KB
/
audiomonitor.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
babyphone - A baby monitor application for Maemo / MeeGo (Nokia N900, N950, N9).
Copyright (C) 2011 Roman Morawek <[email protected]>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <QObject>
#include <QAudioInput>
#include "settings.h"
/*!
AudioMonitor handles the input capture of audio data and analysis the data
stream to extract the audio volume.
It uses QAudioInput to gather audio data and provides a QIODevice to handle
the audio stream. The audio properties (sampling rate, quantisation) are set
as demanded and the audio stream is opened unidirectional to receive data
only.
AudioMonitor performes the volume analysis, compares this with the audio
threshold defined in the application Settings and performs the time based
audio analysis using a counter variable (itsCounter). The threshold check of
the counter variable is performed outside of AudioMonitor.
*/
class AudioMonitor : public QIODevice
{
Q_OBJECT
public:
AudioMonitor(const Settings *settings, QObject *parent);
~AudioMonitor();
bool start();
void stop();
private:
qint64 readData(char *data, qint64 maxlen);
qint64 writeData(const char *data, qint64 len);
signals:
//! reports a new audio sample with its value and the time based threshold counter
void update(int counter, int value);
public:
//! audio duration counter
int itsCounter;
//! active audio sampling state flag
bool itsActive;
private:
const static int COUNTER_SCALE_FACTOR = 5;
//! reference to global application settings
const Settings * const itsSettings;
//! the audio input device
QAudioInput *itsDevice;
};