FS2_Open
Open source remastering of the Freespace 2 engine
fsspeech.cpp
Go to the documentation of this file.
1 /*
2  * Code created by Thomas Whittaker (RT) for a FreeSpace 2 source code project
3  *
4  * You may not sell or otherwise commercially exploit the source or things you
5  * created based on the source.
6  *
7 */
8 
9 
10 
11 
12 
13 #ifdef FS2_SPEECH
14 
15 
16 #ifdef _WIN32
17 #include <windows.h>
18 #endif
19 
20 #include "globalincs/pstypes.h"
21 #include "osapi/osregistry.h"
22 #include "sound/fsspeech.h"
23 #include "sound/speech.h"
24 
25 
27 
28 const int MAX_SPEECH_BUFFER_LEN = 4096;
29 
30 static int speech_inited = 0;
31 
32 bool FSSpeech_play_from[FSSPEECH_FROM_MAX];
33 char *FSSpeech_play_id[FSSPEECH_FROM_MAX] =
34 {
35  "SpeechTechroom",
36  "SpeechBriefings",
37  "SpeechIngame",
38  "SpeechMulti"
39 };
40 
41 char Speech_buffer[MAX_SPEECH_BUFFER_LEN] = "";
42 int Speech_buffer_len;
43 
44 bool fsspeech_init()
45 {
46  if (speech_inited) {
47  return true;
48  }
49 
50  // if sound is disabled from the cmdline line then don't do speech either
52  return false;
53  }
54 
55  if(speech_init() == false) {
56  return false;
57  }
58 
59  // Get the settings from the registry
60  for(int i = 0; i < FSSPEECH_FROM_MAX; i++) {
61  FSSpeech_play_from[i] =
62  os_config_read_uint(NULL, FSSpeech_play_id[i], 0) ? true : false;
63  }
64 
65  int volume = os_config_read_uint(NULL, "SpeechVolume", 100);
66  speech_set_volume((unsigned short) volume);
67 
68  int voice = os_config_read_uint(NULL, "SpeechVoice", 0);
69  speech_set_voice(voice);
70 
71  speech_inited = 1;
72 
73  return true;
74 }
75 
76 void fsspeech_deinit()
77 {
78  if (!speech_inited)
79  return;
80 
81  speech_deinit();
82 
83  speech_inited = 0;
84 }
85 
86 void fsspeech_play(int type, const char *text)
87 {
88  if (!speech_inited)
89  return;
90 
91  if(type >= FSSPEECH_FROM_MAX) return;
92 
93  if(type >= 0 && FSSpeech_play_from[type] == false) return;
94 
95  speech_play(text);
96 }
97 
98 void fsspeech_stop()
99 {
100  if (!speech_inited)
101  return;
102 
103  speech_stop();
104 }
105 
106 void fsspeech_pause(bool playing)
107 {
108  if (!speech_inited)
109  return;
110 
111  if(playing) {
112  speech_pause();
113  } else {
114  speech_resume();
115  }
116 }
117 
119 {
120  Speech_buffer_len = 0;
121  Speech_buffer[0] = '\0';
122 }
123 
124 void fsspeech_stuff_buffer(const char *text)
125 {
126  if (!speech_inited)
127  return;
128 
129  int len = strlen(text);
130 
131  if(Speech_buffer_len + len < MAX_SPEECH_BUFFER_LEN) {
132  strcat_s(Speech_buffer, text);
133  }
134 
135  Speech_buffer_len += len;
136 }
137 
138 void fsspeech_play_buffer(int type)
139 {
140  if (!speech_inited)
141  return;
142 
143  fsspeech_play(type, Speech_buffer);
144 }
145 
146 // Goober5000
147 bool fsspeech_play_from(int type)
148 {
149  Assert(type >= 0 && type < FSSPEECH_FROM_MAX);
150 
151  return (speech_inited && FSSpeech_play_from[type]);
152 }
153 
154 // Goober5000
155 bool fsspeech_playing()
156 {
157  if (!speech_inited)
158  return false;
159 
160  return speech_is_speaking();
161 }
162 
163 #endif // FS2_SPEECH defined
void fsspeech_pause(bool playing)
Definition: fsspeech.h:46
int i
Definition: multi_pxo.cpp:466
uint os_config_read_uint(const char *section, const char *name, uint default_value)
Definition: osregistry.cpp:372
#define speech_play(text)
Definition: speech.h:35
void fsspeech_stop()
Definition: fsspeech.h:45
#define speech_set_volume(volume)
Definition: speech.h:39
Assert(pm!=NULL)
bool fsspeech_init()
Definition: fsspeech.h:42
#define speech_pause()
Definition: speech.h:36
#define speech_stop()
Definition: speech.h:38
GLenum type
Definition: Gl.h:1492
void fsspeech_start_buffer()
Definition: fsspeech.h:48
#define speech_is_speaking()
Definition: speech.h:41
void fsspeech_play(int type, const char *text)
Definition: fsspeech.h:44
#define speech_resume()
Definition: speech.h:37
void fsspeech_play_buffer(int type)
Definition: fsspeech.h:50
#define speech_deinit()
Definition: speech.h:34
#define speech_init()
Definition: speech.h:33
bool fsspeech_play_from(int type)
Definition: fsspeech.h:52
void fsspeech_deinit()
Definition: fsspeech.h:43
void fsspeech_stuff_buffer(const char *text)
Definition: fsspeech.h:49
#define strcat_s(...)
Definition: safe_strings.h:68
int Cmdline_freespace_no_sound
Definition: cmdline.cpp:272
GLenum GLsizei len
Definition: Glext.h:6283
bool fsspeech_playing()
Definition: fsspeech.h:53
#define speech_set_voice(voice)
Definition: speech.h:40