YARP
Yet Another Robot Platform
AudioPlayerDeviceBase.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3  * SPDX-License-Identifier: BSD-3-Clause
4  */
5 
6 #include <vector>
7 
8 #include <yarp/os/Searchable.h>
10 #include <yarp/dev/api.h>
12 #include <mutex>
13 
14 #ifndef YARP_DEV_AUDIOPLAYERDEVICETEMPLATE_H
15 #define YARP_DEV_AUDIOPLAYERDEVICETEMPLATE_H
16 
17 namespace yarp {
18 namespace dev {
19 
20 
22 {
23  public:
24  size_t numSamples = 0;
25  size_t numChannels = 0;
26  size_t frequency = 0;
27  size_t bytesPerSample = 2;
28 };
29 
51 {
52 protected:
53  bool m_enable_buffer_autoclear = false;
54  bool m_playback_enabled = false;
55  std::recursive_mutex m_mutex;
56  yarp::dev::CircularAudioBuffer_16t* m_outputBuffer = nullptr;
58  double m_sw_gain = 1.0;
59  double m_hw_gain = 1.0;
60  bool m_audiobase_debug = false;
61  enum { RENDER_APPEND = 0, RENDER_IMMEDIATE = 1 } m_renderMode= RENDER_APPEND;
62 
63 public:
64  virtual bool renderSound(const yarp::sig::Sound& sound) override;
65  virtual bool startPlayback() override;
66  virtual bool stopPlayback() override;
67  virtual bool isPlaying(bool& playback_enabled) override;
68  virtual bool getPlaybackAudioBufferMaxSize(yarp::dev::AudioBufferSize& size) override;
69  virtual bool getPlaybackAudioBufferCurrentSize(yarp::dev::AudioBufferSize& size) override;
70  virtual bool resetPlaybackAudioBuffer() override;
71  virtual bool setSWGain(double gain) override;
72 
73  virtual ~AudioPlayerDeviceBase();
74 
75 protected:
76  virtual bool configureDeviceAndStart() = 0;
77  virtual bool interruptDeviceAndClose() = 0;
78  virtual void waitUntilPlaybackStreamIsComplete();
79  virtual bool immediateSound(const yarp::sig::Sound& sound);
80  virtual bool appendSound(const yarp::sig::Sound& sound);
81 
82  bool configurePlayerAudioDevice(yarp::os::Searchable& config, std::string device_name);
83 };
84 
85 } // namespace dev
86 } // namespace yarp
87 
88 #endif
AudioPlayerDeviceBase : a base class for all audio player devices
virtual bool configureDeviceAndStart()=0
virtual bool interruptDeviceAndClose()=0
AudioDeviceDriverSettings m_audioplayer_cfg
A base class for nested structures that can be searched.
Definition: Searchable.h:66
Class for storing sounds See Audio in YARP for additional documentation on YARP audio.
Definition: Sound.h:26
The main, catch-all namespace for YARP.
Definition: dirs.h:16
#define YARP_dev_API
Definition: api.h:18