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::dev {
18 
19 
21 {
22  public:
23  size_t numSamples = 0;
24  size_t numChannels = 0;
25  size_t frequency = 0;
26  size_t bytesPerSample = 2;
27 };
28 
50 {
51 protected:
52  bool m_enable_buffer_autoclear = false;
53  bool m_playback_enabled = false;
54  std::recursive_mutex m_mutex;
55  yarp::dev::CircularAudioBuffer_16t* m_outputBuffer = nullptr;
57  double m_sw_gain = 1.0;
58  double m_hw_gain = 1.0;
59  bool m_audiobase_debug = false;
60  enum { RENDER_APPEND = 0, RENDER_IMMEDIATE = 1 } m_renderMode= RENDER_APPEND;
61 
62 public:
63  virtual bool renderSound(const yarp::sig::Sound& sound) override;
64  virtual bool startPlayback() override;
65  virtual bool stopPlayback() override;
66  virtual bool isPlaying(bool& playback_enabled) override;
67  virtual bool getPlaybackAudioBufferMaxSize(yarp::dev::AudioBufferSize& size) override;
68  virtual bool getPlaybackAudioBufferCurrentSize(yarp::dev::AudioBufferSize& size) override;
69  virtual bool resetPlaybackAudioBuffer() override;
70  virtual bool setSWGain(double gain) override;
71 
72  virtual ~AudioPlayerDeviceBase();
73 
74 protected:
75  virtual bool configureDeviceAndStart() = 0;
76  virtual bool interruptDeviceAndClose() = 0;
77  virtual void waitUntilPlaybackStreamIsComplete();
78  virtual bool immediateSound(const yarp::sig::Sound& sound);
79  virtual bool appendSound(const yarp::sig::Sound& sound);
80 
81  bool configurePlayerAudioDevice(yarp::os::Searchable& config, std::string device_name);
82 };
83 
84 } // namespace yarp::dev
85 
86 #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:63
Class for storing sounds See Audio in YARP for additional documentation on YARP audio.
Definition: Sound.h:25
For streams capable of holding different kinds of content, check what they actually have.
#define YARP_dev_API
Definition: api.h:18