YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
Sound_marker.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5
6#include "Sound_marker.h"
9
10using namespace yarp::os;
11
13
14void split(const std::string& s, char delim, std::vector<std::string>& elements)
15{
16 std::istringstream iss(s);
17 std::string item;
18 while (std::getline(iss, item, delim)) {
19 elements.push_back(item);
20 }
21}
22
24{
25 // Split command line string using '+' delimiter
26 std::vector<std::string> parameters;
27 split(carrierString, '+', parameters);
28
29 // Iterate over result strings
30 for (std::string param : parameters)
31 {
32 // If there is no '.', then the param is bad formatted, skip it.
33 auto pointPosition = param.find('.');
34 if (pointPosition == std::string::npos)
35 {
36 continue;
37 }
38
39 // Otherwise, separate key and value
40 std::string paramKey = param.substr(0, pointPosition);
42 std::string s = param.substr(pointPosition + 1, param.length());
43 paramValue.fromString(s.c_str());
44
45 //and append to the returned property
46 prop.put(paramKey, paramValue);
47 }
48 return;
49}
50
52{
53 yCDebug(SOUND_MARKER, "created!\n");
54 yCDebug(SOUND_MARKER, "I am attached to the %s\n",
55 (options.find("sender_side").asBool()) ? "sender side" : "receiver side");
56
57 //parse the user parameters
59 yCDebug(SOUND_MARKER) << "user params:" << options.toString();
60 std::string str = options.find("carrier").asString();
62 yCDebug(SOUND_MARKER) << "parsed params:" << m_user_params.toString();
63
64 return true;
65}
66
68{
69}
70
72{
73 return false;
74}
75
77{
78 return false;
79}
80
82{
84 if (bt == NULL)
85 {
86 yCWarning(SOUND_MARKER, "expected type Sound but got wrong data type!\n");
87 return false;
88 }
89
90 return true;
91}
92
94{
95 //get data to process
97 if (s == NULL)
98 {
99 yCWarning(SOUND_MARKER, "expected type Sound but got wrong data type!\n");
100 return thing;
101 }
102
103 size_t ss_size = s->getSamples();
104 size_t ch_size = s->getChannels();
105 m_s2 = *s;
106 m_s2.resize(ss_size+5, ch_size);
107
108 for (size_t c = 0; c < ch_size; c++)
109 {
110 for (size_t i = 0; i < ss_size; i++)
111 {
112 m_s2.set(s->get(i,c), i, c);
113 }
114 for (size_t i = ss_size; i < ss_size+5; i++)
115 {
116 m_s2.set(32000,i,c);
117 }
118 m_s2.set(-32000, 0, c);
119 }
120
121 //send data
122 m_th.setPortWriter(&m_s2);
123 return m_th;
124}
125
127{
128}
void split(const std::string &s, char delim, std::vector< std::string > &elements)
const yarp::os::LogComponent & SOUND_MARKER()
void split(const std::string &s, char delim, std::vector< std::string > &elements)
void trig() override
This will be called when one of the peer connections to the same import port receives data.
bool setparam(const yarp::os::Property &params) override
This will be called when the portmonitor carrier parameters are set via YARP admin port.
yarp::os::Things & update(yarp::os::Things &thing) override
After data get accpeted in the accept() callback, an instance of that is given to the update function...
bool create(const yarp::os::Property &options) override
This will be called when the dll is properly loaded by the portmonitor carrier.
void destroy() override
This will be called when the portmonitor object destroyes.
bool accept(yarp::os::Things &thing) override
This will be called when the data reach the portmonitor object.
bool getparam(yarp::os::Property &params) override
This will be called when the portmonitor carrier parameters are requested via YARP admin port.
void getParamsFromCommandLine(std::string carrierString, yarp::os::Property &prop)
A mini-server for performing network communication in the background.
A class for storing options and configuration information.
Definition Property.h:33
Value & find(const std::string &key) const override
Gets a value corresponding to a given keyword.
std::string toString() const override
Return a standard text representation of the content of the object.
void put(const std::string &key, const std::string &value)
Associate the given key with the given string.
Definition Property.cpp:987
Base class for generic things.
Definition Things.h:18
T * cast_as()
Definition Things.h:53
void setPortWriter(yarp::os::PortWriter *writer)
Set the reference to a PortWriter object.
Definition Things.cpp:26
A single value (typically within a Bottle).
Definition Value.h:43
virtual bool asBool() const
Get boolean value.
Definition Value.cpp:186
virtual std::string asString() const
Get string value.
Definition Value.cpp:234
Class for storing sounds See Audio in YARP for additional documentation on YARP audio.
Definition Sound.h:25
size_t getChannels() const
Get the number of channels of the sound.
Definition Sound.cpp:603
void resize(size_t samples, size_t channels=1)
Set the sound size.
Definition Sound.cpp:270
audio_sample get(size_t sample, size_t channel=0) const
Definition Sound.cpp:294
void set(audio_sample value, size_t sample, size_t channel=0)
Definition Sound.cpp:334
size_t getSamples() const
Get the number of samples contained in the sound.
Definition Sound.cpp:598
#define yCWarning(component,...)
#define yCDebug(component,...)
#define YARP_LOG_COMPONENT(name,...)
STL namespace.
An interface to the operating system, including Port based communication.