Skip to content

Commit

Permalink
Merge pull request #3023 from randaz81/improved_audioRecorder_nws_test
Browse files Browse the repository at this point in the history
improved audioRecorder_nws_test
  • Loading branch information
randaz81 authored Sep 19, 2023
2 parents 4fa591d + c1c24dd commit a454a3b
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,36 @@ using namespace yarp::os;
using namespace yarp::dev;
using namespace yarp::sig;

void test_fakeMicrophone (size_t channels)
{
PolyDriver dd_fake;
PolyDriver dd_nws;
Property p_fake;
Property p_nws;

p_nws.put("device", "audioRecorder_nws_yarp");
p_nws.put("start", "");
p_fake.put("device", "fakeMicrophone");

char buff_channels[10];
snprintf (buff_channels, sizeof(buff_channels), "%d", (int)channels);
Property& psub = p_fake.addGroup("AUDIO_BASE");
psub.put("channels", (int)(channels));

REQUIRE(dd_fake.open(p_fake));
REQUIRE(dd_nws.open(p_nws));
yarp::os::SystemClock::delaySystem(0.5);

{yarp::dev::WrapperSingle* ww_nws; dd_nws.view(ww_nws);
REQUIRE(ww_nws);
bool result_att = ww_nws->attach(&dd_fake);
REQUIRE(result_att); }

yarp::os::SystemClock::delaySystem(1.0);

CHECK(dd_nws.close());
CHECK(dd_fake.close());
}

TEST_CASE("dev::AudioRecorder_nws_yarp", "[yarp::dev]")
{
Expand All @@ -45,27 +75,8 @@ TEST_CASE("dev::AudioRecorder_nws_yarp", "[yarp::dev]")

SECTION("Test the audioRecorder_nws_yarp device with a fakeMicrophone device")
{
PolyDriver dd_fake;
PolyDriver dd_nws;
Property p_fake;
Property p_nws;

p_nws.put("device", "audioRecorder_nws_yarp");
p_nws.put("start","");
p_fake.put("device", "fakeMicrophone");
REQUIRE(dd_fake.open(p_fake));
REQUIRE(dd_nws.open(p_nws));
yarp::os::SystemClock::delaySystem(0.5);

{yarp::dev::WrapperSingle* ww_nws; dd_nws.view(ww_nws);
REQUIRE(ww_nws);
bool result_att = ww_nws->attach(&dd_fake);
REQUIRE(result_att); }

yarp::os::SystemClock::delaySystem(1.0);

CHECK(dd_nws.close());
CHECK(dd_fake.close());
test_fakeMicrophone(1);
test_fakeMicrophone(2);
}

Network::setLocalMode(false);
Expand Down
4 changes: 3 additions & 1 deletion src/devices/fakeMicrophone/fakeMicrophone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ bool fakeMicrophone::open(yarp::os::Searchable &config)
return false;
}

bool b = configureRecorderAudioDevice(config.findGroup("AUDIO_BASE"), "fakeMicrophone");
std::string debug_cfg_string = config.toString();
yarp::os::Bottle& bb = config.findGroup("AUDIO_BASE");
bool b = configureRecorderAudioDevice(bb, "fakeMicrophone");
if (!b) { return false; }

//sets the thread period
Expand Down
2 changes: 2 additions & 0 deletions src/libYARP_dev/src/yarp/dev/AudioRecorderDeviceBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ AudioRecorderDeviceBase::~AudioRecorderDeviceBase()

bool AudioRecorderDeviceBase::configureRecorderAudioDevice(yarp::os::Searchable& config, std::string device_name)
{
std::string debug_cfg_string = config.toString();

m_audiorecorder_cfg.frequency = config.check("rate", Value(0), "audio sample rate (0=automatic)").asInt32();
m_audiorecorder_cfg.numSamples = config.check("samples", Value(0), "number of samples per network packet (0=automatic). For chunks of 1 second of recording set samples=rate. Channels number is handled internally.").asInt32();
m_audiorecorder_cfg.numChannels = config.check("channels", Value(0), "number of audio channels (0=automatic, max is 2)").asInt32();
Expand Down

0 comments on commit a454a3b

Please sign in to comment.