|
YARP
Yet Another Robot Platform
|
|
Go to the documentation of this file.
32 m_audio_filename(
"audio_out")
43 if (config.
check(
"file_name"))
46 yCInfo(AUDIOTOFILE) <<
"Audio will be saved on exit to file:" << m_audio_filename;
51 yCInfo(AUDIOTOFILE) <<
"No `file_name` option specified. Audio will be saved on exit to default file:" << m_audio_filename;
54 if (config.
find(
"save_mode").
toString() ==
"overwrite_file") { m_save_mode = save_mode_t::save_overwrite_file;}
55 else if (config.
find(
"save_mode").
toString() ==
"append_data") { m_save_mode = save_mode_t::save_append_data; }
56 else if (config.
find(
"save_mode").
toString() ==
"rename_file") { m_save_mode = save_mode_t::save_rename_file; }
57 else if (config.
check(
"save_mode")) {
yError() <<
"Unsupported value for save_mode parameter";
return false;}
59 if (m_save_mode == save_mode_t::save_overwrite_file) {
yCInfo(AUDIOTOFILE) <<
"overwrite_file mode selected. File will be saved both on exit and on stop"; }
60 else if (m_save_mode == save_mode_t::save_append_data) {
yCInfo(AUDIOTOFILE) <<
"append_data mode selected. File will be saved on exit only"; }
61 else if (m_save_mode == save_mode_t::save_rename_file) {
yCInfo(AUDIOTOFILE) <<
"rename_file mode selected. File will be saved both on exit and on stop"; }
66 void audioToFileDevice::save_to_file()
69 if (m_sounds.size() == 0)
return;
73 m_audioFile.
setFrequency(m_sounds.front().getFrequency());
74 m_audioFile.
resize(0, m_sounds.front().getChannels());
75 while (!m_sounds.empty())
77 m_audioFile += m_sounds.front();
82 size_t lastindex = m_audio_filename.find(
".wav");
83 std::string rawname = m_audio_filename.substr(0, lastindex);
85 if (m_save_mode == save_mode_t::save_rename_file)
87 rawname = rawname +std::to_string(m_filename_counter++);
89 rawname = rawname +
".wav";
93 yCDebug(AUDIOTOFILE) <<
"Wrote audio to:" << rawname;
119 std::lock_guard<std::mutex> lock(m_mutex);
126 std::lock_guard<std::mutex> lock(m_mutex);
127 yCDebug(AUDIOTOFILE) <<
"start";
128 m_playback_running =
true;
129 if (m_save_mode != save_mode_t::save_append_data)
138 std::lock_guard<std::mutex> lock(m_mutex);
139 yCDebug(AUDIOTOFILE) <<
"stop";
140 m_playback_running =
false;
141 if (m_save_mode != save_mode_t::save_append_data)
150 std::lock_guard<std::mutex> lock(m_mutex);
151 if (m_playback_running)
153 m_sounds.push_back(sound);
void setFrequency(int freq)
Set the frequency of the sound (i.e.
virtual bool startPlayback() override
Start the playback.
A base class for nested structures that can be searched.
virtual bool resetPlaybackAudioBuffer() override
#define YARP_LOG_COMPONENT(name,...)
virtual bool getPlaybackAudioBufferMaxSize(yarp::dev::AudioBufferSize &size) override
An interface for the device drivers.
virtual bool getPlaybackAudioBufferCurrentSize(yarp::dev::AudioBufferSize &size) override
bool close() override
Close the DeviceDriver.
virtual bool stopPlayback() override
Stop the playback.
virtual std::string asString() const
Get string value.
virtual bool renderSound(const yarp::sig::Sound &sound) override
Render a sound using a device (i.e.
virtual bool check(const std::string &key) const =0
Check if there exists a property of the given name.
virtual Value & find(const std::string &key) const =0
Gets a value corresponding to a given keyword.
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
unsigned short int audio_sample_16t
#define yCInfo(component,...)
An interface to the operating system, including Port based communication.
#define yCDebug(component,...)
Class for storing sounds.
void resize(size_t samples, size_t channels=1)
Set the sound size.
std::string toString() const override
Return a standard text representation of the content of the object.
bool write(const ImageOf< PixelRgb > &src, const std::string &dest, image_fileformat format=FORMAT_PPM)
~audioToFileDevice() override