YARP
Yet Another Robot Platform
fakeSpeaker.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2020 Istituto Italiano di Tecnologia (IIT)
3  * All rights reserved.
4  *
5  * This software may be modified and distributed under the terms of the
6  * BSD-3-Clause license. See the accompanying LICENSE file for details.
7  */
8 
9 #include <string>
10 #include <yarp/dev/DeviceDriver.h>
11 #include <yarp/os/PeriodicThread.h>
15 #include <yarp/sig/Sound.h>
16 #include <yarp/sig/SoundFile.h>
17 
18 
19 #define DEFAULT_PERIOD 0.01 //s
20 
28 class fakeSpeaker :
32 {
33 public:
34  fakeSpeaker();
35  fakeSpeaker(const fakeSpeaker&) = delete;
36  fakeSpeaker(fakeSpeaker&&) = delete;
37  fakeSpeaker& operator=(const fakeSpeaker&) = delete;
39 
40  ~fakeSpeaker() override;
41 
42  // Device Driver interface
43  bool open(yarp::os::Searchable &config) override;
44  bool close() override;
45 
46  virtual bool startPlayback() override;
47  virtual bool stopPlayback() override;
48  virtual bool renderSound(const yarp::sig::Sound& sound) override;
49  virtual bool getPlaybackAudioBufferMaxSize(yarp::dev::AudioBufferSize& size) override;
51  virtual bool resetPlaybackAudioBuffer() override;
52 
53 private:
54  bool threadInit() override;
55  void run() override;
56 
57  bool m_isPlaying = false;
58 
59  size_t m_cfg_numSamples = 0;
60  size_t m_cfg_numChannels = 0;
61  size_t m_cfg_frequency = 0;
62  size_t m_cfg_bytesPerSample = 0;
63 
64  yarp::dev::CircularAudioBuffer_16t* m_outputBuffer = nullptr;
65  bool m_renderSoundImmediate = false;
66 };
yarp::os::Searchable
A base class for nested structures that can be searched.
Definition: Searchable.h:69
fakeSpeaker::fakeSpeaker
fakeSpeaker(fakeSpeaker &&)=delete
CircularAudioBuffer.h
yarp::dev::AudioBufferSize
Definition: AudioBufferSize.h:26
fakeSpeaker::close
bool close() override
Close the DeviceDriver.
Definition: fakeSpeaker.cpp:70
yarp::dev::DeviceDriver
Interface implemented by all device drivers.
Definition: DeviceDriver.h:38
AudioGrabberInterfaces.h
fakeSpeaker::fakeSpeaker
fakeSpeaker(const fakeSpeaker &)=delete
yarp::dev::IAudioRender
Definition: IAudioRender.h:21
yarp::dev::CircularAudioBuffer
Definition: CircularAudioBuffer.h:25
fakeSpeaker::operator=
fakeSpeaker & operator=(fakeSpeaker &&)=delete
fakeSpeaker::open
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
Definition: fakeSpeaker.cpp:42
fakeSpeaker::resetPlaybackAudioBuffer
virtual bool resetPlaybackAudioBuffer() override
Definition: fakeSpeaker.cpp:138
fakeSpeaker::getPlaybackAudioBufferCurrentSize
virtual bool getPlaybackAudioBufferCurrentSize(yarp::dev::AudioBufferSize &size) override
Definition: fakeSpeaker.cpp:131
fakeSpeaker::renderSound
virtual bool renderSound(const yarp::sig::Sound &sound) override
Render a sound using a device (i.e.
Definition: fakeSpeaker.cpp:144
fakeSpeaker::fakeSpeaker
fakeSpeaker()
Definition: fakeSpeaker.cpp:32
yarp::os::PeriodicThread
An abstraction for a periodic thread.
Definition: PeriodicThread.h:25
fakeSpeaker::getPlaybackAudioBufferMaxSize
virtual bool getPlaybackAudioBufferMaxSize(yarp::dev::AudioBufferSize &size) override
Definition: fakeSpeaker.cpp:124
PeriodicThread.h
fakeSpeaker
fakeSpeaker : fake device implementing the IAudioRender device interface to play sound
Definition: fakeSpeaker.h:32
yarp::sig::Sound
Class for storing sounds.
Definition: Sound.h:28
fakeSpeaker::operator=
fakeSpeaker & operator=(const fakeSpeaker &)=delete
SoundFile.h
IGenericSensor.h
fakeSpeaker::stopPlayback
virtual bool stopPlayback() override
Stop the playback.
Definition: fakeSpeaker.cpp:92
fakeSpeaker::~fakeSpeaker
~fakeSpeaker() override
Definition: fakeSpeaker.cpp:37
Sound.h
DeviceDriver.h
fakeSpeaker::startPlayback
virtual bool startPlayback() override
Start the playback.
Definition: fakeSpeaker.cpp:87