]> git.mxchange.org Git - flightgear.git/blob - src/Sound/voice.hxx
fix trx and rx heights and improve calculations
[flightgear.git] / src / Sound / voice.hxx
1 // speech synthesis interface subsystem
2 //
3 // Written by Melchior FRANZ, started February 2006.
4 //
5 // Copyright (C) 2006  Melchior FRANZ - mfranz@aon.at
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 // General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20 //
21 // $Id$
22
23 #ifndef _VOICE_HXX
24 #define _VOICE_HXX
25
26 #ifdef HAVE_CONFIG_H
27 #  include <config.h>
28 #endif
29
30 #include <vector>
31
32 #include <simgear/compiler.h>
33 #include <simgear/props/props.hxx>
34 #include <simgear/io/sg_socket.hxx>
35 #include <simgear/structure/subsystem_mgr.hxx>
36
37 #include <Main/fg_props.hxx>
38
39 #if defined(ENABLE_THREADS)
40 #  include <OpenThreads/Thread>
41 #  include <OpenThreads/Mutex>
42 #  include <OpenThreads/ScopedLock>
43 #  include <OpenThreads/Condition>
44 #  include <simgear/threads/SGQueue.hxx>
45 #else
46 #  include <queue>
47    using std::queue;
48 #endif // ENABLE_THREADS
49
50 using std::vector;
51
52
53
54 class FGVoiceMgr : public SGSubsystem {
55 public:
56         FGVoiceMgr();
57         ~FGVoiceMgr();
58         void init(void);
59         void update(double dt);
60
61 private:
62         class FGVoice;
63
64 #if defined(ENABLE_THREADS)
65         class FGVoiceThread;
66         FGVoiceThread *_thread;
67 #endif
68
69         string _host;
70         string _port;
71         bool _enabled;
72         SGPropertyNode_ptr _pausedNode;
73         bool _paused;
74         vector<FGVoice *> _voices;
75 };
76
77
78
79 #if defined(ENABLE_THREADS)
80 class FGVoiceMgr::FGVoiceThread : public OpenThreads::Thread {
81 public:
82         FGVoiceThread(FGVoiceMgr *mgr) : _mgr(mgr) {}
83         void run();
84         void wake_up() { _jobs.signal(); }
85
86 private:
87         void wait_for_jobs() { OpenThreads::ScopedLock<OpenThreads::Mutex> g(_mutex); _jobs.wait(&_mutex); }
88         OpenThreads::Condition _jobs;
89         OpenThreads::Mutex _mutex;
90         FGVoiceMgr *_mgr;
91 };
92 #endif
93
94
95
96 class FGVoiceMgr::FGVoice {
97 public:
98         FGVoice(FGVoiceMgr *, const SGPropertyNode_ptr);
99         ~FGVoice();
100         bool speak();
101         void update();
102         void setVolume(double);
103         void setPitch(double);
104         void setSpeed(double);
105         void pushMessage(string);
106
107 private:
108         class FGVoiceListener;
109         SGSocket *_sock;
110         double _volume;
111         double _pitch;
112         double _speed;
113         SGPropertyNode_ptr _volumeNode;
114         SGPropertyNode_ptr _pitchNode;
115         SGPropertyNode_ptr _speedNode;
116         bool _festival;
117         FGVoiceMgr *_mgr;
118
119 #if defined(ENABLE_THREADS)
120         SGLockedQueue<string> _msg;
121 #else
122         queue<string> _msg;
123 #endif
124
125 };
126
127
128
129 class FGVoiceMgr::FGVoice::FGVoiceListener : public SGPropertyChangeListener {
130 public:
131         FGVoiceListener(FGVoice *voice) : _voice(voice) {}
132         void valueChanged(SGPropertyNode *node);
133
134 private:
135         FGVoice *_voice;
136 };
137
138
139 #endif // _VOICE_HXX