Main Page · Modules · All Classes · Class Hierarchy
MASpeakerController.hpp
1 /*
2  * This file is part of the AiBO+ project
3  *
4  * Copyright (C) 2005-2016 Csaba Kertész (csaba.kertesz@gmail.com)
5  *
6  * AiBO+ is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * AiBO+ is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
19  *
20  */
21 
22 #pragma once
23 
24 #include "sound/MASoundBase.hpp"
25 #include "sound/MASpeakerDevice.hpp"
26 #include "MAController.hpp"
27 
28 #include <MCThreadLocalData.hpp>
29 
30 #include <boost/shared_ptr.hpp>
31 #include <boost/tuple/tuple.hpp>
32 #include <boost/unordered_map.hpp>
33 
34 #include <map>
35 #include <string>
36 
37 class MARobotState;
39 
45 namespace MA
46 {
49 
51 typedef boost::tuple<int, int, int64_t, int> PlaybackDescriptor;
53 typedef std::multimap<MA::SoundBaseSPtr, PlaybackDescriptor> SoundPlaybackMap;
54 }
55 
60 {
61 public:
63  virtual ~MASpeakerController();
64 
65 private:
66  virtual void UpdateRobotState(MARobotState& state) override;
67 
68 public:
69  virtual MA::DeviceList GetMotors() const override;
70 
82  static void RegisterFutureSound(const int id, const std::string& name, const int duration);
83 
91  bool IsFree() const;
92 
98  void SwitchSoundProfile();
99 
107  std::string GetSoundProfileName() const;
108 
116  void SetSoundProfileName(const std::string& profile_name);
117 
123  virtual void LoadSoundProfile();
124 
130  virtual void SaveSoundProfile();
131 
137  virtual void LoadVolumeControl();
138 
144  virtual void SaveVolumeControl();
145 
155  bool Preload(const std::string& name);
156 
164  void FreePreloadedSound(const std::string& name);
165 
175  int Play(const std::string& name);
176 
186  int Play(MA::SoundBaseSPtr sound);
187 
197  bool IsPlayed(const int playback_id) const;
198 
208  bool IsPlayed(const std::string& sound_name) const;
209 
217  void SetVolume(const MA::VolumeType new_volume);
218 protected:
219  void MixNextBuffer(int16_t* target_buffer, bool limit_non_cached = true);
220  unsigned int GetRemainingPlaybackTime() const;
221  bool IsOnlyEffectsPlayed() const;
222  virtual MA::DeviceGeneratorsMap GetSkitTransitionGenerators(MA::SkitBaseSPtr skit) override;
223 
224 protected:
228  MA::SoundPlaybackMap Playbacks;
230  boost::shared_ptr<MASpeakerDevice> SpeakerDevice;
231 };
232 
boost::shared_ptr< MASpeakerDevice > SpeakerDevice
Speaker device.
Base class for the controllers.
Speaker controller class.
MA::SoundPlaybackMap Playbacks
Actual playback list of the sound files.
A wrapper class to cover boost::thread_specific_ptr/folly::ThreadLocal API on certain targets...
Robot state.
int BufferSize
Determinates the buffer duration for the playback.