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
12namespace {
13YARP_LOG_COMPONENT(SOUND_MARKER, "sound_marker")
14
15void split(const std::string& s, char delim, std::vector<std::string>& elements)
16{
17 std::istringstream iss(s);
18 std::string item;
19 while (std::getline(iss, item, delim)) {
20 elements.push_back(item);
21 }
22}
23} //anonymous namespace
24
25
27{
28 // Split command line string using '+' delimiter
29 std::vector<std::string> parameters;
30 split(carrierString, '+', parameters);
31
32 // Iterate over result strings
33 for (std::string param : parameters)
34 {
35 // If there is no '.', then the param is bad formatted, skip it.
36 auto pointPosition = param.find('.');
37 if (pointPosition == std::string::npos)
38 {
39 continue;
40 }
41
42 // Otherwise, separate key and value
43 std::string paramKey = param.substr(0, pointPosition);
45 std::string s = param.substr(pointPosition + 1, param.length());
46 paramValue.fromString(s.c_str());
47
48 //and append to the returned property
49 prop.put(paramKey, paramValue);
50 }
51 return;
52}
53
55{
56 yCDebug(SOUND_MARKER, "created!\n");
57 yCDebug(SOUND_MARKER, "I am attached to the %s\n",
58 (options.find("sender_side").asBool()) ? "sender side" : "receiver side");
59
60 //parse the user parameters
62 yCDebug(SOUND_MARKER) << "user params:" << options.toString();
63 std::string str = options.find("carrier").asString();
65 yCDebug(SOUND_MARKER) << "parsed params:" << m_user_params.toString();
66
67 return true;
68}
69
71{
72}
73
75{
76 return false;
77}
78
80{
81 return false;
82}
83
85{
87 if (bt == NULL)
88 {
89 yCWarning(SOUND_MARKER, "expected type Sound but got wrong data type!\n");
90 return false;
91 }
92
93 return true;
94}
95
97{
98 //get data to process
100 if (s == NULL)
101 {
102 yCWarning(SOUND_MARKER, "expected type Sound but got wrong data type!\n");
103 return thing;
104 }
105
106 size_t ss_size = s->getSamples();
107 size_t ch_size = s->getChannels();
108 m_s2 = *s;
109 m_s2.resize(ss_size+5, ch_size);
110
111 for (size_t c = 0; c < ch_size; c++)
112 {
113 for (size_t i = 0; i < ss_size; i++)
114 {
115 m_s2.set(s->get(i,c), i, c);
116 }
117 for (size_t i = ss_size; i < ss_size+5; i++)
118 {
119 m_s2.set(32000,i,c);
120 }
121 m_s2.set(-32000, 0, c);
122 }
123
124 //send data
125 m_th.setPortWriter(&m_s2);
126 return m_th;
127}
128
130{
131}
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.