trikRuntime
tonePlayer.h
Go to the documentation of this file.
1 /* Copyright 2016 Artem Sharganov
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License. */
14 
15 #pragma once
16 
17 #include "audioSynthDevice.h"
18 
19 #include <QtCore/QObject>
20 #include <QtCore/QTimer>
21 #include <QtMultimedia/QAudioOutput>
22 
23 namespace trikControl {
24 
26 class TonePlayer : public QObject
27 {
28  Q_OBJECT
29 public:
30 
32  TonePlayer();
33 
34 public slots:
35 
37  void play(int freqHz, int durationMs);
38 
39 private:
40  QAudioFormat mFormat;
41 
42  AudioSynthDevice *mDevice; // Has ownership
43  QAudioOutput *mOutput; // Has ownership
44  QTimer mTimer;
45 
46  void initializeAudio();
47 
48  static constexpr int CHANNEL_COUNT = 1;
49  static constexpr int SAMPLE_RATE = 16000;
50  static constexpr int SAMPLE_SIZE = 16;
51 
52 public slots:
54  void stop();
55 };
56 }
QIODevice that synthesize sine wave values.
Definition: audioSynthDevice.h:23
Tone player. Play tones.
Definition: tonePlayer.h:26
void stop()
Stop playing.
Definition: tonePlayer.cpp:81
Definition: trikCommunicator.h:27
void play(int freqHz, int durationMs)
Play sound.
Definition: tonePlayer.cpp:51
TonePlayer()
Constructor.
Definition: tonePlayer.cpp:21