YARP
Yet Another Robot Platform
fakeMicrophone.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 
10 #include <yarp/os/PeriodicThread.h>
14 #include <yarp/sig/Sound.h>
15 #include <yarp/sig/SoundFile.h>
16 
17 #include <string>
18 #include <mutex>
19 
20 #define DEFAULT_PERIOD 0.01 //s
21 
30 {
31 public:
33  fakeMicrophone(const fakeMicrophone&) = delete;
37 
38  ~fakeMicrophone() override;
39 
40  // Device Driver interface
41  bool open(yarp::os::Searchable &config) override;
42  bool close() override;
43 
44  virtual bool getSound(yarp::sig::Sound& sound, size_t min_number_of_samples, size_t max_number_of_samples, double max_samples_timeout_s) override;
45  virtual bool startRecording() override;
46  virtual bool stopRecording() override;
49  virtual bool resetRecordingAudioBuffer() override;
50 
51 private:
52  bool threadInit() override;
53  void run() override;
54 
55  bool m_isRecording;
56  std::mutex m_mutex;
57  yarp::sig::Sound m_audioFile;
58 
59  size_t m_cfg_numSamples;
60  size_t m_cfg_numChannels;
61  size_t m_cfg_frequency;
62  size_t m_cfg_bytesPerSample;
63 
64  std::string m_audio_filename;
65  size_t m_bpnt;
67  bool m_getSoundIsNotBlocking;
68 };
fakeMicrophone : fake device implementing the IAudioGrabberSound device interface to play sound
virtual 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.
virtual bool resetRecordingAudioBuffer() override
fakeMicrophone & operator=(const fakeMicrophone &)=delete
virtual bool startRecording() override
Start the recording.
bool close() override
Close the DeviceDriver.
virtual bool getRecordingAudioBufferCurrentSize(yarp::dev::AudioBufferSize &size) override
virtual bool stopRecording() override
Stop the recording.
fakeMicrophone(fakeMicrophone &&)=delete
fakeMicrophone & operator=(fakeMicrophone &&)=delete
fakeMicrophone(const fakeMicrophone &)=delete
virtual bool getRecordingAudioBufferMaxSize(yarp::dev::AudioBufferSize &size) override
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
~fakeMicrophone() override
Interface implemented by all device drivers.
Definition: DeviceDriver.h:38
Read a YARP-format sound block from a device.
An abstraction for a periodic thread.
A base class for nested structures that can be searched.
Definition: Searchable.h:69
Class for storing sounds.
Definition: Sound.h:28