30 |
30 |
#include "AudioPlayerLibAO.h"
|
31 |
31 |
#include "AudioPlayerRSB.h"
|
32 |
32 |
#include <boost/algorithm/string/predicate.hpp>
|
33 |
|
#include <boost/thread/mutex.hpp>
|
|
33 |
#include <mutex>
|
|
34 |
#include <thread>
|
34 |
35 |
#include <iostream>
|
35 |
36 |
|
36 |
37 |
using namespace boost;
|
... | ... | |
71 |
72 |
|
72 |
73 |
void Arbiter::set_default_emotion(EmotionState e) {
|
73 |
74 |
// lock access
|
74 |
|
boost::mutex::scoped_lock scoped_lock(emotion_config_default_mutex);
|
|
75 |
const std::lock_guard<std::mutex> lock(emotion_config_default_mutex);
|
75 |
76 |
|
76 |
77 |
// update our config, ignore duration as this is the default emotion
|
77 |
78 |
emotion_config_default.select_config(e.value);
|
... | ... | |
84 |
85 |
|
85 |
86 |
void Arbiter::set_current_emotion(EmotionState e) {
|
86 |
87 |
// lock access
|
87 |
|
boost::mutex::scoped_lock scoped_lock(emotion_config_current_mutex);
|
|
88 |
const std::lock_guard<std::mutex> lock(emotion_config_current_mutex);
|
88 |
89 |
|
89 |
90 |
// this will set a emotion override for a given time, after the timeout
|
90 |
91 |
// we will return to the default emotion state:
|
... | ... | |
99 |
100 |
|
100 |
101 |
void Arbiter::set_mouth_config(MouthConfig m) {
|
101 |
102 |
// lock access
|
102 |
|
boost::mutex::scoped_lock scoped_lock(mouth_config_override_mutex);
|
|
103 |
const std::lock_guard<std::mutex> lock(mouth_config_override_mutex);
|
103 |
104 |
|
104 |
105 |
mouth_config = m;
|
105 |
106 |
}
|
106 |
107 |
|
107 |
108 |
void Arbiter::set_gaze_target(humotion::GazeState target) {
|
108 |
109 |
// lock access
|
109 |
|
boost::mutex::scoped_lock scoped_lock(requested_gaze_state_mutex);
|
|
110 |
const std::lock_guard<std::mutex> lock(requested_gaze_state_mutex);
|
110 |
111 |
|
111 |
112 |
requested_gaze_state = target;
|
112 |
113 |
}
|
113 |
114 |
|
114 |
115 |
void Arbiter::set_mouth_target(humotion::MouthState target) {
|
115 |
116 |
// lock access
|
116 |
|
boost::mutex::scoped_lock scoped_lock(requested_mouth_state_mutex);
|
|
117 |
const std::lock_guard<std::mutex> lock(requested_mouth_state_mutex);
|
117 |
118 |
|
118 |
119 |
requested_mouth_state = target;
|
119 |
120 |
}
|
... | ... | |
122 |
123 |
void Arbiter::play_animation(boost::shared_ptr<Animation> incoming_animation) {
|
123 |
124 |
// incoming animation, check if this would conflict with any pending animations:
|
124 |
125 |
// lock access & iterate over vector:
|
125 |
|
boost::mutex::scoped_lock lock_av(active_animation_vector_mutex);
|
|
126 |
std::unique_lock<std::mutex> lock_av(active_animation_vector_mutex);
|
126 |
127 |
active_animation_vector_t::iterator it;
|
127 |
128 |
for (it = active_animation_vector.begin(); it < active_animation_vector.end(); it++) {
|
128 |
129 |
boost::shared_ptr<Animation> current_ani = *it;
|
... | ... | |
167 |
168 |
void Arbiter::speak(
|
168 |
169 |
boost::shared_ptr<Utterance> u) { //, ao_sample_format audio_format, char *audio_data, unsigned int audio_len){
|
169 |
170 |
// lock audio playback as such:
|
170 |
|
boost::mutex::scoped_lock scoped_lock_audio(audio_player_mutex);
|
|
171 |
const std::lock_guard<std::mutex> lock_audio(audio_player_mutex);
|
171 |
172 |
|
172 |
|
// lock utterance & store data:
|
173 |
|
boost::mutex::scoped_lock scoped_lock(utterance_mutex);
|
174 |
|
utterance = u;
|
175 |
|
scoped_lock.unlock();
|
|
173 |
{
|
|
174 |
// lock utterance & store data:
|
|
175 |
const std::lock_guard<std::mutex> lock(utterance_mutex);
|
|
176 |
utterance = u;
|
|
177 |
}
|
176 |
178 |
|
177 |
179 |
// start audio playback, this function returns once we started playback
|
178 |
180 |
if (audio_player == NULL) {
|
... | ... | |
279 |
281 |
}
|
280 |
282 |
|
281 |
283 |
// lock access
|
282 |
|
boost::mutex::scoped_lock scoped_lock1(emotion_config_default_mutex);
|
|
284 |
const std::lock_guard<std::mutex> lock1(emotion_config_default_mutex);
|
283 |
285 |
|
284 |
286 |
// did the current emotion time out?
|
285 |
287 |
if (!emotion_target->is_active()) {
|
... | ... | |
351 |
353 |
|
352 |
354 |
void Arbiter::override_by_animation() {
|
353 |
355 |
// lock access & iterate over vector:
|
354 |
|
boost::mutex::scoped_lock lock_av(active_animation_vector_mutex);
|
|
356 |
const std::lock_guard<std::mutex> lock_av(active_animation_vector_mutex);
|
355 |
357 |
active_animation_vector_t::iterator it;
|
356 |
358 |
for (it = active_animation_vector.begin(); it < active_animation_vector.end(); it++) {
|
357 |
359 |
boost::shared_ptr<Animation> current_ani = *it;
|