YARP
Yet Another Robot Platform
PortAudioPlayerDeviceDriver.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2020 Istituto Italiano di Tecnologia (IIT)
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
19 #ifndef PortAudioPlayerDeviceDriverh
20 #define PortAudioPlayerDeviceDriverh
21 
22 #include <yarp/os/ManagedBytes.h>
23 #include <yarp/os/Thread.h>
24 
25 #include <yarp/dev/DeviceDriver.h>
28 #include <portaudio.h>
29 #include <mutex>
30 
31 #define DEFAULT_SAMPLE_RATE (44100)
32 #define DEFAULT_NUM_CHANNELS (2)
33 #define DEFAULT_DITHER_FLAG (0)
34 #define DEFAULT_FRAMES_PER_BUFFER (512)
35 //#define DEFAULT_FRAMES_PER_BUFFER (1024)
36 
37 
39 {
40 public:
41  size_t cfg_rate = 0;
42  size_t cfg_samples = 0;
43  size_t cfg_playChannels = 0;
45 };
46 
48 {
49 public:
51 
52  void threadRelease() override;
53  bool threadInit() override;
54  void run() override;
55 
57  PaStream* stream;
58 
59 private:
60  PaError err;
61  void handleError();
62 };
63 
74 {
75 private:
76  PaStreamParameters m_outputParameters;
77  PaStream* m_stream;
78  PaError m_err;
79  yarp::dev::CircularAudioBuffer_16t* m_playDataBuffer;
81  PlayStreamThread m_pThread;
82  std::mutex m_mutex;
83 
84 public:
90 
92 
93  bool open(yarp::os::Searchable& config) override;
94 
109 
110  bool close() override;
111  bool renderSound(const yarp::sig::Sound& sound) override;
112  bool startPlayback() override;
113  bool stopPlayback() override;
114 
115  bool abortSound();
116  bool immediateSound(const yarp::sig::Sound& sound);
117  bool appendSound(const yarp::sig::Sound& sound);
118 
121  bool resetPlaybackAudioBuffer() override;
122 
123 protected:
125 
128  void handleError();
129 };
130 
131 #endif
PortAudioPlayerDeviceDriverSettings
Definition: PortAudioPlayerDeviceDriver.h:39
PortAudioPlayerDeviceDriver::m_driverConfig
PortAudioPlayerDeviceDriverSettings m_driverConfig
Definition: PortAudioPlayerDeviceDriver.h:126
PlayStreamThread::PlayStreamThread
PlayStreamThread()
Definition: PortAudioPlayerDeviceDriver.cpp:133
yarp::os::Searchable
A base class for nested structures that can be searched.
Definition: Searchable.h:69
PortAudioPlayerDeviceDriver::PortAudioPlayerDeviceDriver
PortAudioPlayerDeviceDriver(PortAudioPlayerDeviceDriver &&)=delete
PlayStreamThread::stream
PaStream * stream
Definition: PortAudioPlayerDeviceDriver.h:57
CircularAudioBuffer.h
PlayStreamThread::threadRelease
void threadRelease() override
Release method.
Definition: PortAudioPlayerDeviceDriver.cpp:140
yarp::dev::AudioBufferSize
Definition: AudioBufferSize.h:26
yarp::dev::DeviceDriver
Interface implemented by all device drivers.
Definition: DeviceDriver.h:38
PortAudioPlayerDeviceDriver::open
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
Definition: PortAudioPlayerDeviceDriver.cpp:216
PortAudioPlayerDeviceDriverSettings::cfg_rate
size_t cfg_rate
Definition: PortAudioPlayerDeviceDriver.h:41
PortAudioPlayerDeviceDriver::RENDER_APPEND
@ RENDER_APPEND
Definition: PortAudioPlayerDeviceDriver.h:127
PortAudioPlayerDeviceDriverSettings::cfg_samples
size_t cfg_samples
Definition: PortAudioPlayerDeviceDriver.h:42
PortAudioPlayerDeviceDriver::abortSound
bool abortSound()
Definition: PortAudioPlayerDeviceDriver.cpp:323
AudioGrabberInterfaces.h
PortAudioPlayerDeviceDriver::appendSound
bool appendSound(const yarp::sig::Sound &sound)
Definition: PortAudioPlayerDeviceDriver.cpp:405
yarp::os::Thread
An abstraction for a thread of execution.
Definition: Thread.h:25
PortAudioPlayerDeviceDriver::operator=
PortAudioPlayerDeviceDriver & operator=(PortAudioPlayerDeviceDriver &&)=delete
yarp::dev::IAudioRender
Definition: IAudioRender.h:21
PortAudioPlayerDeviceDriver::renderMode
enum PortAudioPlayerDeviceDriver::@0 renderMode
yarp::dev::CircularAudioBuffer
Definition: CircularAudioBuffer.h:25
PortAudioPlayerDeviceDriver::RENDER_IMMEDIATE
@ RENDER_IMMEDIATE
Definition: PortAudioPlayerDeviceDriver.h:127
ManagedBytes.h
PlayStreamThread
Definition: PortAudioPlayerDeviceDriver.h:48
PortAudioPlayerDeviceDriver::handleError
void handleError()
Definition: PortAudioPlayerDeviceDriver.cpp:287
PortAudioPlayerDeviceDriver
portaudioPlayer: Documentation to be added
Definition: PortAudioPlayerDeviceDriver.h:74
PortAudioPlayerDeviceDriver::m_system_resource
void * m_system_resource
Definition: PortAudioPlayerDeviceDriver.h:124
PortAudioPlayerDeviceDriver::resetPlaybackAudioBuffer
bool resetPlaybackAudioBuffer() override
Definition: PortAudioPlayerDeviceDriver.cpp:433
PortAudioPlayerDeviceDriver::~PortAudioPlayerDeviceDriver
~PortAudioPlayerDeviceDriver() override
Definition: PortAudioPlayerDeviceDriver.cpp:210
Thread.h
PortAudioPlayerDeviceDriver::getPlaybackAudioBufferCurrentSize
bool getPlaybackAudioBufferCurrentSize(yarp::dev::AudioBufferSize &size) override
Definition: PortAudioPlayerDeviceDriver.cpp:419
PortAudioPlayerDeviceDriver::immediateSound
bool immediateSound(const yarp::sig::Sound &sound)
Definition: PortAudioPlayerDeviceDriver.cpp:339
PortAudioPlayerDeviceDriver::PortAudioPlayerDeviceDriver
PortAudioPlayerDeviceDriver(const PortAudioPlayerDeviceDriver &)=delete
yarp::sig::Sound
Class for storing sounds.
Definition: Sound.h:28
PortAudioPlayerDeviceDriver::stopPlayback
bool stopPlayback() override
Stop the playback.
Definition: PortAudioPlayerDeviceDriver.cpp:447
PortAudioPlayerDeviceDriver::startPlayback
bool startPlayback() override
Start the playback.
Definition: PortAudioPlayerDeviceDriver.cpp:440
PortAudioPlayerDeviceDriver::renderSound
bool renderSound(const yarp::sig::Sound &sound) override
Render a sound using a device (i.e.
Definition: PortAudioPlayerDeviceDriver.cpp:355
PlayStreamThread::run
void run() override
Main body of the new thread.
Definition: PortAudioPlayerDeviceDriver.cpp:150
PortAudioPlayerDeviceDriver::close
bool close() override
Close the DeviceDriver.
Definition: PortAudioPlayerDeviceDriver.cpp:300
PlayStreamThread::threadInit
bool threadInit() override
Initialization method.
Definition: PortAudioPlayerDeviceDriver.cpp:144
PlayStreamThread::something_to_play
bool something_to_play
Definition: PortAudioPlayerDeviceDriver.h:56
PortAudioPlayerDeviceDriverSettings::cfg_playChannels
size_t cfg_playChannels
Definition: PortAudioPlayerDeviceDriver.h:43
PortAudioPlayerDeviceDriver::operator=
PortAudioPlayerDeviceDriver & operator=(const PortAudioPlayerDeviceDriver &)=delete
PortAudioPlayerDeviceDriver::getPlaybackAudioBufferMaxSize
bool getPlaybackAudioBufferMaxSize(yarp::dev::AudioBufferSize &size) override
Definition: PortAudioPlayerDeviceDriver.cpp:426
PortAudioPlayerDeviceDriver::PortAudioPlayerDeviceDriver
PortAudioPlayerDeviceDriver()
Definition: PortAudioPlayerDeviceDriver.cpp:200
PortAudioPlayerDeviceDriverSettings::cfg_deviceNumber
int cfg_deviceNumber
Definition: PortAudioPlayerDeviceDriver.h:44
DeviceDriver.h