Skip to content

Commit

Permalink
Major Refactor (part 2/2)
Browse files Browse the repository at this point in the history
Improved `AudioPlayerDeviceBase` and `AudioRecorderDeviceBase` classes to remove duplicated code (e.g. parameters parsing and render modes)
Untested.
  • Loading branch information
randaz81 committed Feb 9, 2021
1 parent 8b1d23f commit 5f1f6f7
Show file tree
Hide file tree
Showing 15 changed files with 378 additions and 361 deletions.
3 changes: 0 additions & 3 deletions src/devices/audioPlayerWrapper/AudioPlayerWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,11 @@ bool AudioPlayerWrapper::read(yarp::os::ConnectionReader& connection)

if (command.get(0).asString() == "start")
{
m_isPlaying = true;
m_irender->startPlayback();
reply.addVocab(VOCAB_OK);
}
else if (command.get(0).asString() == "stop")
{
m_isPlaying = false;
m_irender->stopPlayback();
reply.addVocab(VOCAB_OK);
}
Expand Down Expand Up @@ -234,7 +232,6 @@ bool AudioPlayerWrapper::open(yarp::os::Searchable &config)

if (config.check("start"))
{
m_isPlaying = true;
m_irender->startPlayback();
}

Expand Down
1 change: 0 additions & 1 deletion src/devices/audioPlayerWrapper/AudioPlayerWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ class AudioPlayerWrapper :
double m_buffer_delay;
bool m_isDeviceOwned = false;
bool m_debug_enabled = false;
bool m_isPlaying = false;

bool initialize_YARP(yarp::os::Searchable &config);
bool read(yarp::os::ConnectionReader& connection) override;
Expand Down
18 changes: 18 additions & 0 deletions src/devices/audioToFileDevice/audioToFileDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,21 @@ bool audioToFileDevice::setHWGain(double gain)
yCError(AUDIOTOFILE, "Not yet implemented");
return false;
}

bool audioToFileDevice::configureDeviceAndStart()
{
yCError(AUDIOTOFILE, "configureDeviceAndStart() Not yet implemented");
return true;
}

bool audioToFileDevice::interruptDeviceAndClose()
{
yCError(AUDIOTOFILE, "interruptDeviceAndClose() Not yet implemented");
return true;
}

void audioToFileDevice::waitUntilPlaybackStreamIsComplete()
{
yCError(AUDIOTOFILE, "waitUntilPlaybackStreamIsComplete() Not yet implemented");
return;
}
3 changes: 3 additions & 0 deletions src/devices/audioToFileDevice/audioToFileDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ class audioToFileDevice :
virtual bool startPlayback() override;
virtual bool stopPlayback()override;
virtual bool setHWGain(double gain) override;
virtual bool configureDeviceAndStart() override;
virtual bool interruptDeviceAndClose() override;
virtual void waitUntilPlaybackStreamIsComplete() override;

private:
yarp::sig::Sound m_audioFile;
Expand Down
39 changes: 15 additions & 24 deletions src/devices/fakeSpeaker/fakeSpeaker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,6 @@ bool fakeSpeaker::threadInit()
return true;
}

bool fakeSpeaker::startPlayback()
{
return true;
}

bool fakeSpeaker::stopPlayback()
{
return true;
}

void fakeSpeaker::run()
{
// when not playing, do nothing
Expand Down Expand Up @@ -121,25 +111,26 @@ void fakeSpeaker::run()
#endif
}

bool fakeSpeaker::renderSound(const yarp::sig::Sound& sound)
bool fakeSpeaker::setHWGain(double gain)
{
if (m_renderSoundImmediate) m_outputBuffer->clear();

// size_t num_bytes = sound.getBytesPerSample();
size_t num_channels = sound.getChannels();
size_t num_samples = sound.getSamples();
yCError(FAKESPEAKER, "setHWGain() Not yet implemented");
return false;
}

for (size_t i = 0; i<num_samples; i++)
for (size_t j = 0; j<num_channels; j++)
m_outputBuffer->write(sound.get(i, j));
auto debug_p = sound.getInterleavedAudioRawData();
bool fakeSpeaker::configureDeviceAndStart()
{
yCError(FAKESPEAKER, "configureDeviceAndStart() Not yet implemented");
return true;
}

m_isPlaying = true;
bool fakeSpeaker::interruptDeviceAndClose()
{
yCError(FAKESPEAKER, "interruptDeviceAndClose() Not yet implemented");
return true;
}

bool fakeSpeaker::setHWGain(double gain)
void fakeSpeaker::waitUntilPlaybackStreamIsComplete()
{
yCError(FAKESPEAKER, "Not yet implemented");
return false;
yCError(FAKESPEAKER, "waitUntilPlaybackStreamIsComplete() Not yet implemented");
return;
}
9 changes: 4 additions & 5 deletions src/devices/fakeSpeaker/fakeSpeaker.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@ class fakeSpeaker :
bool open(yarp::os::Searchable &config) override;
bool close() override;

virtual bool startPlayback() override;
virtual bool stopPlayback() override;
virtual bool renderSound(const yarp::sig::Sound& sound) override;
//interface
virtual bool setHWGain(double gain) override;
virtual bool configureDeviceAndStart() override;
virtual bool interruptDeviceAndClose() override;
virtual void waitUntilPlaybackStreamIsComplete() override;

private:
bool threadInit() override;
Expand All @@ -58,6 +59,4 @@ class fakeSpeaker :
size_t m_cfg_frequency = 0;
size_t m_cfg_bytesPerSample = 0;
double m_hw_gain = 1.0;

bool m_renderSoundImmediate = false;
};
Loading

0 comments on commit 5f1f6f7

Please # to comment.