21 std::string
m_name =
"/yarpAudioPlayer";
28 bool play(
const std::string& filename)
override;
29 bool test(
const std::string& type,
const double duration,
const double frequency,
const std::int16_t amplitude,
const std::int16_t sampling_rate,
const std::int16_t channels)
override;
32 bool openFile(
const std::string& file_name);
45 if (rf.
check(
"split_size"))
50 yInfo() <<
"yarpAudioPlayer --name <portname> --split_size <value>";
51 yInfo() <<
"portname: prefix for the opened ports default: /yarpAudioPlayer";
52 yInfo() <<
"value: int32 (default value 16000) The output sound will be split into packets of <value> samples each";
53 yInfo() <<
"the tool accepts commands on its rpc port";
60 if (!ret) {
return false;}
66 if (!ret) {
return false;}
68 yInfo() <<
"Module started. Send commands to the RPC port" <<
m_name +
"/rpc" <<
" to play audio files.";
93int main(
int argc,
char *argv[])
101 if (!
yarp.checkNetwork())
103 yError() <<
"yarp.checkNetwork() failed.";
118 if (!ret) {
return false; }
121 if (!ret) {
return false; }
125bool PlayerModule::test(
const std::string& type,
const double duration,
const double frequency,
const std::int16_t amplitude,
const std::int16_t sampling_rate,
const std::int16_t channels)
130 else if (type ==
"sawtooth" )
132 else if (type ==
"squarewave" )
136 yInfo() <<
"Invalid type, should be `sine`, `sawtooth`, or `squarewave`";
141 if (!ret) {
return false; }
144 if (!ret) {
return false; }
150 yInfo() <<
"Opening file:" << file_name;
160 yError() <<
"Unable to open file" << file_name.c_str();
163 yInfo() <<
"File loaded in: " <<
en -
st <<
"s";
172 yInfo() <<
"Sending sound...";
202 yWarning() <<
"No receivers are connected";
205 yInfo() <<
"Sound sent in: " <<
en -
st <<
"s";
bool openFile(const std::string &file_name)
bool updateModule() override
Override this to do whatever your module needs to do.
bool configure(yarp::os::ResourceFinder &rf) override
Configure the module, pass a ResourceFinder object to the module.
bool close() override
Close function.
yarp::os::Port m_audioPort
yarp::sig::Sound m_audioFile
virtual double getPeriod() override
You can override this to control the approximate periodicity at which updateModule() is called by run...
bool test(const std::string &type, const double duration, const double frequency, const std::int16_t amplitude, const std::int16_t sampling_rate, const std::int16_t channels) override
Generate and send a test sound.
bool play(const std::string &filename) override
Play the given audio file.
yarpAudioPlayer_IDL Interface.
A mini-server for performing network communication in the background.
Utilities for manipulating the YARP network, including initialization and shutdown.
A mini-server for network communication.
int getOutputCount() override
Determine how many output connections this port has.
bool write(const PortWriter &writer, const PortWriter *callback=nullptr) const override
Write an object to the port.
void close() override
Stop port activity.
bool open(const std::string &name) override
Start port operation, with a specific name, with automatically-chosen network parameters.
A base-class for standard YARP modules that supports ResourceFinder.
virtual int runModule()
Calls updateModule() until that returns false.
Helper class for finding config files and other external resources.
bool check(const std::string &key) const override
Check if there exists a property of the given name.
bool setDefaultContext(const std::string &contextName)
Sets the context for the current ResourceFinder object.
bool configure(int argc, char *argv[], bool skipFirstArgument=true)
Sets up the ResourceFinder.
std::string toString() const override
Return a standard text representation of the content of the object.
Value & find(const std::string &key) const override
Gets a value corresponding to a given keyword.
virtual std::int32_t asInt32() const
Get 32-bit integer value.
virtual std::string asString() const
Get string value.
bool attachAsServer(yarp::os::UnbufferedContactable &port)
Tag this WireLink as a server, receiving commands via the specified port.
yarp::os::WireLink & yarp()
Get YARP state associated with this object.
Class for storing sounds See Audio in YARP for additional documentation on YARP audio.
Sound subSound(size_t first_sample, size_t len)
Returns a subpart of the sound.
size_t getBytesPerSample() const
Get the number of bytes per sample.
size_t getChannels() const
Get the number of channels of the sound.
int getFrequency() const
Get the frequency of the sound (i.e.
size_t getSamples() const
Get the number of samples contained in the sound.
double now()
Return the current time in seconds, relative to an arbitrary starting point.
An interface to the operating system, including Port based communication.
bool read(ImageOf< PixelRgb > &dest, const std::string &src, image_fileformat format=FORMAT_ANY)
bool makeSawTooth(Sound &outSound, double duration_s=1.0, size_t channels=1, size_t sampleRate=16000, double frequency=1, size_t amplitude=30000)
Generate a sound containing a sawtooth signal.
bool makeTone(Sound &outSound, double duration_s=1.0, size_t channels=1, size_t sampleRate=16000, double frequency=440, size_t amplitude=30000)
Generate a sound containing a sine wave tone.
bool makeSquareWave(Sound &outSound, double duration_s=1.0, size_t channels=1, size_t sampleRate=16000, double frequency=1, size_t amplitude=30000)
Generate a sound containing a square wave signal.
The main, catch-all namespace for YARP.
int main(int argc, char *argv[])