37 std::deque<Sound> sounds;
54 if (p.
check(
"nodevice")) {
60 yError(
"cannot open driver\n");
64 if (!p.
check(
"mute")) {
66 poly.
view(iAudioplay);
67 if (iAudioplay ==
nullptr) {
68 yError(
"cannot open interface\n");
76 yError(
"Communication problem\n");
80 if (p.
check(
"remote")) {
81 Network::connect(p.
check(
"remote",
Value(
"/remote")).asString(),
96 yDebug(
"onread %f\n", t2-t1);
104 yWarning(
"Dropping sound packet -- %d packet(s) behind\n", ct);
118 if (iAudioplay !=
nullptr) {
143 sounds.push_back(sound);
146 yDebug(
" %ld sound frames buffered in memory (%ld samples)\n",
147 (
long int) sounds.size(),
156 total.resize(samples,channels);
158 while (!sounds.empty()) {
160 for (
size_t i=0; i<channels; i++) {
161 for (
size_t j=0;
j<
tmp.getSamples();
j++) {
165 total.setFrequency(
tmp.getFrequency());
166 at +=
tmp.getSamples();
172 yDebug(
"Wrote audio to %s\n", name);
186int main(
int argc,
char *argv[]) {
196 if (!p.
check(
"device")) {
197 p.
put(
"device",
"portaudioPlayer");
209 std::string
fname =
"audio_%06d.wav";
214 yInfo(
" Press return to mute/unmute\n");
215 yInfo(
" Type \"s\" to set start/stop saving audio in memory\n");
216 yInfo(
" Type \"write filename.wav\" to write saved audio to a file\n");
217 yInfo(
" Type \"buf NUMBER\" to set buffering delay (default is 0)\n");
218 yInfo(
" Type \"write\" or \"w\" to write saved audio with same/default name\n");
219 yInfo(
" Type \"q\" to quit\n");
220 yInfo(
" Type \"help\" to see this list again\n");
223 yInfo(
"Type \"help\" for usage\n");
232 yInfo(
"%s\n", muted ?
"Muted" :
"Audible again");
233 }
else if (cmd==
"help") {
235 }
else if (cmd==
"s") {
238 yInfo(
"%s\n", saving ?
"Saving" :
"Stopped saving");
240 yInfo(
" Type \"s\" again to stop saving\n");
242 }
else if (cmd==
"write"||cmd==
"w") {
250 }
else if (cmd==
"q"||cmd==
"quit") {
252 }
else if (cmd==
"buf"||cmd==
"b") {
void save(bool saveFlag=true)
void mute(bool muteFlag=true)
void saveFrame(Sound &sound)
bool saveFile(const char *name)
void onRead(Sound &sound) override
bool view(T *&x)
Get an interface to the device driver.
Interface for rendering a YARP-format sound and controlling its reproduction ona device.
virtual yarp::dev::ReturnValue renderSound(const yarp::sig::Sound &sound)=0
Render a sound using a device (i.e.
A container for a device driver.
bool isValid() const
Check if device is valid.
bool open(const std::string &txt)
Construct and configure a device by its common name.
A simple collection of objects that can be described and transmitted in a portable way.
size_type size() const
Gets the number of elements in the bottle.
Value & get(size_type index) const
Reads a Value v from a certain part of the list.
A mini-server for performing network communication in the background.
std::string getName() const override
Get name of 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.
int getPendingReads() override
Get the number of objects ready to be read.
T * read(bool shouldWait=true) override
Read an available object from the port.
void useCallback(TypedReaderCallback< T > &callback) override
Set an object whose onRead method will be called when data is available.
void setStrict(bool strict=true) override
Call this to strictly keep all messages, or allow old ones to be quietly dropped.
Utilities for manipulating the YARP network, including initialization and shutdown.
A class for storing options and configuration information.
void put(const std::string &key, const std::string &value)
Associate the given key with the given string.
bool check(const std::string &key) const override
Check if there exists a property of the given name.
void fromCommand(int argc, char *argv[], bool skipFirst=true, bool wipe=true)
Interprets a list of command arguments as a list of properties.
A base class for nested structures that can be searched.
virtual bool check(const std::string &key) const =0
Check if there exists a property of the given name.
A callback for typed data from a port.
A single value (typically within a Bottle).
virtual std::int32_t asInt32() const
Get 32-bit integer value.
virtual std::string asString() const
Get string value.
Class for storing sounds See Audio in YARP for additional documentation on YARP audio.
size_t getChannels() const
Get the number of channels of the sound.
size_t getSamples() const
Get the number of samples contained in the sound.
For streams capable of holding different kinds of content, check what they actually have.
void yield()
The calling thread releases its remaining quantum upon calling this function.
double now()
Return the current time in seconds, relative to an arbitrary starting point.
std::string readString(bool *eof)
An interface to the operating system, including Port based communication.
bool write(const ImageOf< PixelRgb > &src, const std::string &dest, image_fileformat format=FORMAT_PPM)
The main, catch-all namespace for YARP.
int main(int argc, char *argv[])