ArPiRobot-CoreLib C++
C++ library for ArPiRobot robots
AudioManager.hpp
1 /*
2  * Copyright 2021 Marcus Behel
3  *
4  * This file is part of ArPiRobot-CoreLib.
5  *
6  * ArPiRobot-CoreLib is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * ArPiRobot-CoreLib 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 Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with ArPiRobot-CoreLib. If not, see <https://www.gnu.org/licenses/>.
18  */
19 
20 #pragma once
21 
22 #include <miniaudio.h>
23 
24 #include <vector>
25 #include <unordered_map>
26 #include <mutex>
27 
28 #include <arpirobot/core/audio/AudioDeviceInfo.hpp>
29 
30 namespace arpirobot{
36  class AudioManager{
37  public:
38 
43  static std::vector<AudioDeviceInfo> getPlaybackDevices();
44 
50  static int playSound(std::string file);
51 
58  static int playSound(std::string file, AudioDeviceInfo info);
59 
65  static void stopJob(int jobId);
66 
67  private:
68  class PlaybackSetup{
69  public:
70  int jobId;
71  ma_device device;
72  ma_decoder decoder;
73  ma_device_config deviceConfig;
74  };
75 
76  static void playbackDataCallback(ma_device *device, void *output, const void *input, ma_uint32 frameCount);
77  static int nextJobId();
78 
79  static void init();
80  static void finish();
81 
82  static bool initDone;
83  static ma_context context;
84  static ma_device_info *playbackDeviceInfos;
85  static ma_uint32 playbackDeviceCount;
86  static ma_device_info *captureDeviceInfos;
87  static ma_uint32 captureDeviceCount;
88 
89  static std::unordered_map<ma_device*, PlaybackSetup*> playbackSetups;
90  static std::unordered_map<int, ma_device*> jobIdMap;
91 
92  static std::mutex lock;
93 
94  static AudioDeviceInfo defaultPlaybackDeviceInfo;
95 
96  friend class BaseRobot;
97  };
98 }
Definition: AudioDeviceInfo.hpp:31
Definition: AudioManager.hpp:36
static int playSound(std::string file, AudioDeviceInfo info)
static void stopJob(int jobId)
static std::vector< AudioDeviceInfo > getPlaybackDevices()
static int playSound(std::string file)
Definition: BaseRobot.hpp:40
Definition: ArduinoDevice.hpp:27