YARP
Yet Another Robot Platform
PortAudioDeviceDriver.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3  * SPDX-License-Identifier: LGPL-2.1-or-later
4  */
5 
6 #ifndef PortAudioDeviceDriverh
7 #define PortAudioDeviceDriverh
8 
9 #include <yarp/os/ManagedBytes.h>
10 #include <yarp/os/Thread.h>
11 
12 #include <yarp/dev/DeviceDriver.h>
14 #include <portaudio.h>
15 #include "PortAudioBuffer.h"
16 
17 #define DEFAULT_SAMPLE_RATE (44100)
18 #define DEFAULT_NUM_CHANNELS (2)
19 #define DEFAULT_DITHER_FLAG (0)
20 #define DEFAULT_FRAMES_PER_BUFFER (512)
21 //#define DEFAULT_FRAMES_PER_BUFFER (1024)
22 
23 
25 {
26 public:
27  int rate;
28  int samples;
31  bool wantRead;
32  bool wantWrite;
34 };
35 
36 class streamThread :
37  public yarp::os::Thread
38 {
39  public:
42  PaStream* stream;
43  void threadRelease() override;
44  bool threadInit() override;
45  void run() override;
46 
47  private:
48  PaError err;
49  void handleError();
50 };
51 
64 {
65 private:
66  PaStreamParameters inputParameters;
67  PaStreamParameters outputParameters;
68  PaStream* stream;
69  PaError err;
70  circularDataBuffers dataBuffers;
71  size_t numSamples;
72  size_t numBytes;
73  streamThread pThread;
74 
76 
77 public:
79 
80  virtual ~PortAudioDeviceDriver();
81 
82  bool open(yarp::os::Searchable& config) override;
83 
101  bool open(PortAudioDeviceDriverSettings& config);
102 
103  bool close() override;
104  bool getSound(yarp::sig::Sound& sound, size_t min_number_of_samples, size_t max_number_of_samples, double max_samples_timeout_s) override;
105  bool renderSound(const yarp::sig::Sound& sound) override;
106  bool startRecording() override;
107  bool stopRecording() override;
108  bool startPlayback() override;
109  bool stopPlayback() override;
110  bool isPlaying(bool& playback_enabled) override;
111  bool isRecording(bool& recording_enabled) override;
112 
113  bool abortSound();
114  bool immediateSound(const yarp::sig::Sound& sound);
115  bool appendSound(const yarp::sig::Sound& sound);
116 
119  bool resetPlaybackAudioBuffer() override;
120 
123  bool resetRecordingAudioBuffer() override;
124 
125  bool setHWGain(double gain) override;
126  bool setSWGain(double gain) override;
127 
128 protected:
135 
138  void handleError();
139 };
140 
141 #endif
portaudio deprecated: This device driver has been deprecated! Please use PortAudioPlayerDeviceDriver ...
bool getSound(yarp::sig::Sound &sound, size_t min_number_of_samples, size_t max_number_of_samples, double max_samples_timeout_s) override
Get a sound from a device.
bool startPlayback() override
Start the playback.
bool setSWGain(double gain) override
Sets a software gain for the grabbed audio.
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
bool stopRecording() override
Stop the recording.
bool isPlaying(bool &playback_enabled) override
Check if the playback has been enabled (e.g.
bool getPlaybackAudioBufferCurrentSize(yarp::dev::AudioBufferSize &size) override
PortAudioDeviceDriverSettings m_driverConfig
bool resetRecordingAudioBuffer() override
bool getPlaybackAudioBufferMaxSize(yarp::dev::AudioBufferSize &size) override
bool setHWGain(double gain) override
Sets the hardware gain of the grabbing device (if supported by the hardware)
bool startRecording() override
Start the recording.
bool getRecordingAudioBufferCurrentSize(yarp::dev::AudioBufferSize &size) override
bool resetPlaybackAudioBuffer() override
bool renderSound(const yarp::sig::Sound &sound) override
Render a sound using a device (i.e.
bool isRecording(bool &recording_enabled) override
Check if the recording has been enabled (e.g.
bool appendSound(const yarp::sig::Sound &sound)
enum PortAudioDeviceDriver::@90 renderMode
bool close() override
Close the DeviceDriver.
bool stopPlayback() override
Stop the playback.
bool immediateSound(const yarp::sig::Sound &sound)
bool getRecordingAudioBufferMaxSize(yarp::dev::AudioBufferSize &size) override
void run() override
Main body of the new thread.
bool threadInit() override
Initialization method.
void threadRelease() override
Release method.
Interface implemented by deprecated device drivers.
Definition: DeviceDriver.h:136
Read a YARP-format sound block from a device.
A base class for nested structures that can be searched.
Definition: Searchable.h:63
An abstraction for a thread of execution.
Definition: Thread.h:21
Class for storing sounds See Audio in YARP for additional documentation on YARP audio.
Definition: Sound.h:25