YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
sound_markerTest.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2026-2026 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5
7#include <yarp/os/Network.h>
8#include <yarp/os/LogStream.h>
9#include <yarp/os/Time.h>
11#include <yarp/os/Carriers.h>
12#include <yarp/sig/Sound.h>
13
15
16#include <array>
17#include <thread>
18
19#include <catch2/catch_amalgamated.hpp>
20#include <harness.h>
21
22TEST_CASE("pm::sound_markerTest", "[yarp::pm]")
23{
24 YARP_REQUIRE_PLUGIN("sound_marker", "portmonitor")
25
27
29
30 REQUIRE(yarp::os::Carriers::getCarrierTemplate("portmonitor") != nullptr);
31
33
34 struct TestCase {
35 std::string carrier;
36 bool use_marker;
37 };
38
39 auto tc = GENERATE(
40 TestCase {"fast_tcp", false},
41 TestCase {"fast_tcp+recv.portmonitor+file.sound_marker+type.dll", true}
42 );
43
44 SECTION("Test sound transmission with and without marker")
45 {
48
49 sender.open("/send");
50 receiver.open("/recv");
51
52 bool b = yarp::os::Network::connect("/send", "/recv", tc.carrier);
53 REQUIRE(b);
54
55 // Create a test sound
56 const int frequency = 16000;
57 const size_t samples = 1600;
58 const size_t channels = 1;
59
60 yarp::sig::Sound& snd = sender.prepare();
61 snd.setFrequency(frequency);
62 snd.resize(samples, channels);
63
64 // Fill with simple data
65 for (size_t i = 0; i < samples; i++) {
66 snd.set(static_cast<yarp::sig::Sound::audio_sample>(i % 1000), i, 0);
67 }
68
69 sender.write();
70
72
73 yarp::sig::Sound* received = receiver.read();
74 REQUIRE(received != nullptr);
75
76 // Verify basic properties
77 CHECK(received->getFrequency() == frequency);
78 CHECK(received->getChannels() == channels);
79
80 if (tc.use_marker) {
81 // When marker is used, the sound should have markers added
82 // The size might be different due to markers at beginning/end
83 CHECK(received->getSamples() >= samples);
84 } else {
85 // Without marker, size should match exactly
86 CHECK(received->getSamples() == samples);
87 }
88
89 receiver.close();
90 sender.close();
91 }
92
94}
A mini-server for performing network communication in the background.
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.
T * read(bool shouldWait=true) override
Read an available object from the port.
void write(bool forceStrict=false)
Write the current object being returned by BufferedPort::prepare.
T & prepare()
Access the object which will be transmitted by the next call to yarp::os::BufferedPort::write.
static Carrier * getCarrierTemplate(const std::string &name)
Get template for carrier.
Definition Carriers.cpp:238
static bool connect(const std::string &src, const std::string &dest, const std::string &carrier="", bool quiet=true)
Request that an output port connect to an input port.
Definition Network.cpp:784
static bool setLocalMode(bool flag)
Chooses whether communication is process-local.
Definition Network.cpp:1137
Utilities for manipulating the YARP network, including initialization and shutdown.
Definition Network.h:718
Class for storing sounds See Audio in YARP for additional documentation on YARP audio.
Definition Sound.h:39
void setFrequency(int freq)
Set the frequency of the sound (i.e.
Definition Sound.cpp:369
size_t getChannels() const
Get the number of channels of the sound.
Definition Sound.cpp:669
void resize(size_t samples, size_t channels=1)
Set the sound size.
Definition Sound.cpp:267
int getFrequency() const
Get the frequency of the sound (i.e.
Definition Sound.cpp:364
void set(audio_sample value, size_t sample, size_t channel=0)
Definition Sound.cpp:342
size_t getSamples() const
Get the number of samples contained in the sound.
Definition Sound.cpp:664
void delay(double seconds)
Wait for a certain number of seconds.
Definition Time.cpp:111
@ YARP_CLOCK_SYSTEM
Definition Time.h:28
The main, catch-all namespace for YARP.
Definition dirs.h:16
TEST_CASE("pm::sound_markerTest", "[yarp::pm]")