aboutsummaryrefslogtreecommitdiff
path: root/backends/text-to-speech
diff options
context:
space:
mode:
authorJaromir Wysoglad2019-07-18 11:27:17 +0200
committerFilippos Karapetis2019-09-01 22:47:55 +0300
commit5d9f03e71d75a307c8f8e538803fe2f09f38c5ae (patch)
treee472499cd024f74e211dc6cd63c578d300f20e92 /backends/text-to-speech
parent8e4a24f55e2986de6c0556ab1a0faeeca20c724f (diff)
downloadscummvm-rg350-5d9f03e71d75a307c8f8e538803fe2f09f38c5ae.tar.gz
scummvm-rg350-5d9f03e71d75a307c8f8e538803fe2f09f38c5ae.tar.bz2
scummvm-rg350-5d9f03e71d75a307c8f8e538803fe2f09f38c5ae.zip
TTS: Add reference counting to TTSVoice
Also refactor TTSVoice destruction to use this reference counting.
Diffstat (limited to 'backends/text-to-speech')
-rw-r--r--backends/text-to-speech/linux/linux-text-to-speech.cpp11
-rw-r--r--backends/text-to-speech/linux/linux-text-to-speech.h2
-rw-r--r--backends/text-to-speech/windows/windows-text-to-speech.cpp4
-rw-r--r--backends/text-to-speech/windows/windows-text-to-speech.h2
4 files changed, 14 insertions, 5 deletions
diff --git a/backends/text-to-speech/linux/linux-text-to-speech.cpp b/backends/text-to-speech/linux/linux-text-to-speech.cpp
index 633c107727..db036e053a 100644
--- a/backends/text-to-speech/linux/linux-text-to-speech.cpp
+++ b/backends/text-to-speech/linux/linux-text-to-speech.cpp
@@ -206,7 +206,8 @@ void LinuxTextToSpeechManager::setLanguage(Common::String language) {
void LinuxTextToSpeechManager::createVoice(int typeNumber, Common::TTSVoice::Gender gender, Common::TTSVoice::Age age, char *description) {
SPDVoiceType *type = (SPDVoiceType *) malloc(sizeof(SPDVoiceType));
*type = static_cast<SPDVoiceType>(typeNumber);
- _ttsState->_availaibleVoices.push_back(Common::TTSVoice(gender, age, (void *) type, description));
+ Common::TTSVoice voice(gender, age, (void *) type, description);
+ _ttsState->_availaibleVoices.push_back(voice);
}
void LinuxTextToSpeechManager::updateVoices() {
@@ -238,10 +239,6 @@ bool LinuxTextToSpeechManager::popState() {
if (_ttsState->_next == nullptr)
return true;
- for (Common::TTSVoice *i = _ttsState->_availaibleVoices.begin(); i < _ttsState->_availaibleVoices.end(); i++) {
- free(i->getData());
- }
-
Common::TTSState *oldState = _ttsState;
_ttsState = _ttsState->_next;
@@ -254,5 +251,9 @@ bool LinuxTextToSpeechManager::popState() {
return false;
}
+void LinuxTextToSpeechManager::freeVoiceData(void *data) {
+ free(data);
+}
+
#endif
diff --git a/backends/text-to-speech/linux/linux-text-to-speech.h b/backends/text-to-speech/linux/linux-text-to-speech.h
index 64c2371b72..57b9aeea60 100644
--- a/backends/text-to-speech/linux/linux-text-to-speech.h
+++ b/backends/text-to-speech/linux/linux-text-to-speech.h
@@ -67,6 +67,8 @@ public:
void updateState(SpeechState state);
+ virtual void freeVoiceData(void *data);
+
private:
void init();
virtual void updateVoices();
diff --git a/backends/text-to-speech/windows/windows-text-to-speech.cpp b/backends/text-to-speech/windows/windows-text-to-speech.cpp
index f688ec1cd5..fec5a408d1 100644
--- a/backends/text-to-speech/windows/windows-text-to-speech.cpp
+++ b/backends/text-to-speech/windows/windows-text-to-speech.cpp
@@ -360,5 +360,9 @@ bool WindowsTextToSpeechManager::popState() {
setVoice(_ttsState->_activeVoice);
return false;
}
+void WindowsTextToSpeechManager::freeVoiceData(void *data) {
+ ISpObjectToken *voiceToken = (ISpObjectToken *) data;
+ voiceToken->Release();
+}
#endif
diff --git a/backends/text-to-speech/windows/windows-text-to-speech.h b/backends/text-to-speech/windows/windows-text-to-speech.h
index 03a1806849..2ae062ce92 100644
--- a/backends/text-to-speech/windows/windows-text-to-speech.h
+++ b/backends/text-to-speech/windows/windows-text-to-speech.h
@@ -66,6 +66,8 @@ public:
virtual bool popState();
+ virtual void freeVoiceData(void *data);
+
private:
void init();
virtual void updateVoices();