Skip to content

Commit

Permalink
Merge pull request #90 from BoysTownorg/ubuntu-refactoring
Browse files Browse the repository at this point in the history
Ubuntu refactoring
  • Loading branch information
sbashford authored Jun 30, 2022
2 parents f626bd2 + 9ee9f03 commit 539e978
Show file tree
Hide file tree
Showing 54 changed files with 950 additions and 910 deletions.
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ FetchContent_Declare(
FetchContent_MakeAvailable(GSL)

add_subdirectory(lib)
add_subdirectory(macos)
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
add_subdirectory(macos)
endif()

option(AV_SPEECH_IN_NOISE_ENABLE_TESTS
"Enables tests for av-speech-in-noise target" OFF)
Expand Down
4 changes: 3 additions & 1 deletion lib/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ add_library(
src/SubmittingFreeResponse.cpp
src/SubmittingPassFail.cpp
src/SubmittingKeywords.cpp
src/SubmittingConsonant.cpp)
src/SubmittingConsonant.cpp
src/AudioRecording.cpp
src/EyeTracking.cpp)
target_include_directories(
av-speech-in-noise-core-lib
PUBLIC include
Expand Down
36 changes: 36 additions & 0 deletions lib/core/include/av-speech-in-noise/core/AudioRecording.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#ifndef AV_SPEECH_IN_NOISE_LIB_CORE_INCLUDE_AVSPEECHINNOISE_CORE_AUDIORECORDINGHPP_
#define AV_SPEECH_IN_NOISE_LIB_CORE_INCLUDE_AVSPEECHINNOISE_CORE_AUDIORECORDINGHPP_

#include "IRecognitionTestModel.hpp"
#include "IOutputFile.hpp"

#include <av-speech-in-noise/Interface.hpp>

#include <string>

namespace av_speech_in_noise {
class AudioRecorder {
public:
AV_SPEECH_IN_NOISE_INTERFACE_SPECIAL_MEMBER_FUNCTIONS(AudioRecorder);
virtual void initialize(const LocalUrl &) = 0;
virtual void start() = 0;
virtual void stop() = 0;
};

class AudioRecording : public RunningATest::Observer {
public:
AudioRecording(AudioRecorder &, OutputFile &);
void notifyThatNewTestIsReady(std::string_view session) override;
void notifyThatTrialWillBegin(int trialNumber) override;
void notifyThatTargetWillPlayAt(const PlayerTimeWithDelay &) override;
void notifyThatStimulusHasEnded() override;
void notifyThatSubjectHasResponded() override;

private:
std::string session;
AudioRecorder &audioRecorder;
OutputFile &outputFile;
};
}

#endif
42 changes: 42 additions & 0 deletions lib/core/include/av-speech-in-noise/core/EyeTracking.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#ifndef AV_SPEECH_IN_NOISE_LIB_CORE_INCLUDE_AVSPEECHINNOISE_CORE_EYETRACKINGHPP_
#define AV_SPEECH_IN_NOISE_LIB_CORE_INCLUDE_AVSPEECHINNOISE_CORE_EYETRACKINGHPP_

#include "IMaskerPlayer.hpp"
#include "IOutputFile.hpp"
#include "IRecognitionTestModel.hpp"
#include "ITargetPlayer.hpp"

#include <av-speech-in-noise/Interface.hpp>
#include <av-speech-in-noise/Model.hpp>

namespace av_speech_in_noise {
class EyeTracker : public Writable {
public:
virtual void allocateRecordingTimeSeconds(double) = 0;
virtual void start() = 0;
virtual void stop() = 0;
virtual auto gazeSamples() -> BinocularGazeSamples = 0;
virtual auto currentSystemTime() -> EyeTrackerSystemTime = 0;
};

class EyeTracking : public RunningATest::Observer {
public:
EyeTracking(EyeTracker &, MaskerPlayer &, TargetPlayer &, OutputFile &);
void notifyThatNewTestIsReady(std::string_view session) override;
void notifyThatTrialWillBegin(int trialNumber) override;
void notifyThatTargetWillPlayAt(const PlayerTimeWithDelay &) override;
void notifyThatStimulusHasEnded() override;
void notifyThatSubjectHasResponded() override;

private:
EyeTrackerTargetPlayerSynchronization
lastEyeTrackerTargetPlayerSynchronization{};
TargetStartTime lastTargetStartTime{};
EyeTracker &eyeTracker;
MaskerPlayer &maskerPlayer;
TargetPlayer &targetPlayer;
OutputFile &outputFile;
};
}

#endif
3 changes: 3 additions & 0 deletions lib/core/include/av-speech-in-noise/core/IMaskerPlayer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
#define AV_SPEECH_IN_NOISE_LIB_CORE_INCLUDE_AVSPEECHINNOISE_CORE_IMASKERPLAYERHPP_

#include "Player.hpp"

#include <av-speech-in-noise/Model.hpp>
#include <av-speech-in-noise/Interface.hpp>

#include <gsl/gsl>

#include <string>
#include <vector>
#include <cstdint>
Expand Down
4 changes: 2 additions & 2 deletions lib/core/include/av-speech-in-noise/core/IModel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class Interactor {
};
}

class Model {
class RunningATestFacade {
public:
class Observer {
public:
Expand All @@ -74,7 +74,7 @@ class Model {
explicit RequestFailure(const std::string &s) : std::runtime_error{s} {}
};

AV_SPEECH_IN_NOISE_INTERFACE_SPECIAL_MEMBER_FUNCTIONS(Model);
AV_SPEECH_IN_NOISE_INTERFACE_SPECIAL_MEMBER_FUNCTIONS(RunningATestFacade);
virtual void attach(Observer *) = 0;
virtual void initialize(const AdaptiveTest &) = 0;
virtual void initializeWithTargetReplacement(
Expand Down
26 changes: 19 additions & 7 deletions lib/core/include/av-speech-in-noise/core/IRecognitionTestModel.hpp
Original file line number Diff line number Diff line change
@@ -1,20 +1,32 @@
#ifndef AV_SPEECH_IN_NOISE_LIB_CORE_INCLUDE_AVSPEECHINNOISE_CORE_IRECOGNITIONTESTMODELHPP_
#define AV_SPEECH_IN_NOISE_LIB_CORE_INCLUDE_AVSPEECHINNOISE_CORE_IRECOGNITIONTESTMODELHPP_

#include "TestMethod.hpp"
#include "Player.hpp"
#include "IModel.hpp"
#include "TestMethod.hpp"

#include <string>
#include <string_view>

namespace av_speech_in_noise {
class RecognitionTestModel {
class RunningATest {
public:
AV_SPEECH_IN_NOISE_INTERFACE_SPECIAL_MEMBER_FUNCTIONS(RecognitionTestModel);
virtual void attach(Model::Observer *) = 0;
virtual void initialize(TestMethod *, const Test &) = 0;
class Observer {
public:
AV_SPEECH_IN_NOISE_INTERFACE_SPECIAL_MEMBER_FUNCTIONS(Observer);
virtual void notifyThatNewTestIsReady(std::string_view session) = 0;
virtual void notifyThatTrialWillBegin(int trialNumber) = 0;
virtual void notifyThatTargetWillPlayAt(
const PlayerTimeWithDelay &) = 0;
virtual void notifyThatStimulusHasEnded() = 0;
virtual void notifyThatSubjectHasResponded() = 0;
};
AV_SPEECH_IN_NOISE_INTERFACE_SPECIAL_MEMBER_FUNCTIONS(RunningATest);
virtual void attach(RunningATestFacade::Observer *) = 0;
virtual void initialize(
TestMethod *, const Test &, Observer * = nullptr) = 0;
virtual void initializeWithSingleSpeaker(TestMethod *, const Test &) = 0;
virtual void initializeWithDelayedMasker(TestMethod *, const Test &) = 0;
virtual void initializeWithEyeTracking(TestMethod *, const Test &) = 0;
virtual void initializeWithAudioRecording(TestMethod *, const Test &) = 0;
virtual void playTrial(const AudioSettings &) = 0;
virtual void playCalibration(const Calibration &) = 0;
virtual void playLeftSpeakerCalibration(const Calibration &) = 0;
Expand Down
2 changes: 2 additions & 0 deletions lib/core/include/av-speech-in-noise/core/ITargetPlayer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
#define AV_SPEECH_IN_NOISE_LIB_CORE_INCLUDE_AVSPEECHINNOISE_CORE_ITARGETPLAYERHPP_

#include "Player.hpp"

#include <av-speech-in-noise/Model.hpp>
#include <av-speech-in-noise/Interface.hpp>

#include <string>

namespace av_speech_in_noise {
Expand Down
19 changes: 11 additions & 8 deletions lib/core/include/av-speech-in-noise/core/Model.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,27 @@
#define AV_SPEECH_IN_NOISE_LIB_CORE_INCLUDE_AVSPEECHINNOISE_CORE_MODELHPP_

#include "TargetPlaylist.hpp"
#include "TestMethod.hpp"
#include "IOutputFile.hpp"
#include "IAdaptiveMethod.hpp"
#include "IFixedLevelMethod.hpp"
#include "IRecognitionTestModel.hpp"
#include "IModel.hpp"
#include "IOutputFile.hpp"
#include "IRecognitionTestModel.hpp"
#include "TestMethod.hpp"

namespace av_speech_in_noise {
class ModelImpl : public Model {
class RunningATestFacadeImpl : public RunningATestFacade {
public:
ModelImpl(AdaptiveMethod &, FixedLevelMethod &,
RunningATestFacadeImpl(AdaptiveMethod &, FixedLevelMethod &,
TargetPlaylistReader &targetsWithReplacementReader,
TargetPlaylistReader &cyclicTargetsReader,
TargetPlaylist &targetsWithReplacement,
FiniteTargetPlaylistWithRepeatables &silentIntervalTargets,
FiniteTargetPlaylistWithRepeatables &everyTargetOnce,
RepeatableFiniteTargetPlaylist &eachTargetNTimes,
FiniteTargetPlaylistWithRepeatables &predeterminedTargets,
RecognitionTestModel &, OutputFile &);
void attach(Model::Observer *) override;
RunningATest &, OutputFile &, RunningATest::Observer &audioRecording,
RunningATest::Observer &eyeTracking);
void attach(RunningATestFacade::Observer *) override;
void initialize(const AdaptiveTest &) override;
void initializeWithTargetReplacement(
const FixedLevelFixedTrialsTest &) override;
Expand Down Expand Up @@ -60,6 +61,8 @@ class ModelImpl : public Model {
private:
void initializeTest_(const AdaptiveTest &);

RunningATest::Observer &audioRecording;
RunningATest::Observer &eyeTracking;
AdaptiveMethod &adaptiveMethod;
FixedLevelMethod &fixedLevelMethod;
TargetPlaylistReader &targetsWithReplacementReader;
Expand All @@ -69,7 +72,7 @@ class ModelImpl : public Model {
FiniteTargetPlaylistWithRepeatables &everyTargetOnce;
FiniteTargetPlaylistWithRepeatables &predeterminedTargets;
RepeatableFiniteTargetPlaylist &eachTargetNTimes;
RecognitionTestModel &model;
RunningATest &runningATest;
OutputFile &outputFile;
};
}
Expand Down
58 changes: 19 additions & 39 deletions lib/core/include/av-speech-in-noise/core/RecognitionTestModel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,51 +2,38 @@
#define AV_SPEECH_IN_NOISE_LIB_CORE_INCLUDE_AVSPEECHINNOISE_CORE_RECOGNITIONTESTMODELHPP_

#include "Randomizer.hpp"
#include "IResponseEvaluator.hpp"
#include "ITargetPlayer.hpp"
#include "IMaskerPlayer.hpp"
#include "IRecognitionTestModel.hpp"
#include "IOutputFile.hpp"
#include "av-speech-in-noise/Model.hpp"
#include "IRecognitionTestModel.hpp"
#include "IResponseEvaluator.hpp"
#include "ITargetPlayer.hpp"

#include <av-speech-in-noise/Interface.hpp>
#include <av-speech-in-noise/Model.hpp>

#include <string>
#include <string_view>

namespace av_speech_in_noise {
class EyeTracker : public Writable {
public:
virtual void allocateRecordingTimeSeconds(double) = 0;
virtual void start() = 0;
virtual void stop() = 0;
virtual auto gazeSamples() -> BinocularGazeSamples = 0;
virtual auto currentSystemTime() -> EyeTrackerSystemTime = 0;
};

class Clock {
public:
AV_SPEECH_IN_NOISE_INTERFACE_SPECIAL_MEMBER_FUNCTIONS(Clock);
virtual auto time() -> std::string = 0;
};

class AudioRecorder {
public:
AV_SPEECH_IN_NOISE_INTERFACE_SPECIAL_MEMBER_FUNCTIONS(AudioRecorder);
virtual void initialize(const LocalUrl &) = 0;
virtual void start() = 0;
virtual void stop() = 0;
};
auto trialDuration(TargetPlayer &target, MaskerPlayer &masker) -> Duration;

class RecognitionTestModelImpl : public TargetPlayer::Observer,
public MaskerPlayer::Observer,
public RecognitionTestModel {
class RunningATestImpl : public TargetPlayer::Observer,
public MaskerPlayer::Observer,
public RunningATest {
public:
RecognitionTestModelImpl(TargetPlayer &, MaskerPlayer &, AudioRecorder &,
ResponseEvaluator &, OutputFile &, Randomizer &, EyeTracker &, Clock &);
void attach(Model::Observer *) override;
void initialize(TestMethod *, const Test &) override;
RunningATestImpl(TargetPlayer &, MaskerPlayer &, ResponseEvaluator &,
OutputFile &, Randomizer &, Clock &);
void attach(RunningATestFacade::Observer *) override;
void initialize(
TestMethod *, const Test &, RunningATest::Observer *) override;
void initializeWithSingleSpeaker(TestMethod *, const Test &) override;
void initializeWithDelayedMasker(TestMethod *, const Test &) override;
void initializeWithEyeTracking(TestMethod *, const Test &) override;
void initializeWithAudioRecording(TestMethod *, const Test &) override;
void playTrial(const AudioSettings &) override;
void playCalibration(const Calibration &) override;
void playLeftSpeakerCalibration(const Calibration &) override;
Expand All @@ -67,30 +54,23 @@ class RecognitionTestModelImpl : public TargetPlayer::Observer,
targetOnsetFringeDuration};

private:
void initialize_(TestMethod *, const Test &);
void initialize_(TestMethod *, const Test &, RunningATest::Observer *);
void seekRandomMaskerPosition();

RunningATest::Observer *observer;
MaskerPlayer &maskerPlayer;
TargetPlayer &targetPlayer;
AudioRecorder &audioRecorder;
ResponseEvaluator &evaluator;
OutputFile &outputFile;
Randomizer &randomizer;
EyeTracker &eyeTracker;
Clock &clock;
EyeTrackerTargetPlayerSynchronization
lastEyeTrackerTargetPlayerSynchronization{};
TargetStartTime lastTargetStartTime{};
std::string playTrialTime_;
std::string session;
Model::Observer *listener_{};
RunningATestFacade::Observer *listener_{};
TestMethod *testMethod{};
RealLevel maskerLevel_{};
RealLevel fullScaleLevel_{};
int trialNumber_{};
Condition condition{};
bool eyeTracking{};
bool audioRecordingEnabled{};
bool trialInProgress_{};
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
namespace av_speech_in_noise::submitting_consonant {
class InteractorImpl : public Interactor {
public:
InteractorImpl(FixedLevelMethod &, RecognitionTestModel &, OutputFile &);
InteractorImpl(FixedLevelMethod &, RunningATest &, OutputFile &);
void submit(const ConsonantResponse &r) override;

private:
FixedLevelMethod &method;
RecognitionTestModel &model;
RunningATest &model;
OutputFile &outputFile;
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
namespace av_speech_in_noise::submitting_free_response {
class InteractorImpl : public Interactor {
public:
InteractorImpl(FixedLevelMethod &, RecognitionTestModel &, OutputFile &);
InteractorImpl(FixedLevelMethod &, RunningATest &, OutputFile &);
void submit(const FreeResponse &) override;

private:
FixedLevelMethod &method;
RecognitionTestModel &model;
RunningATest &model;
OutputFile &outputFile;
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
namespace av_speech_in_noise::submitting_keywords {
class InteractorImpl : public Interactor {
public:
InteractorImpl(FixedLevelMethod &, RecognitionTestModel &, OutputFile &);
InteractorImpl(FixedLevelMethod &, RunningATest &, OutputFile &);
void submit(const ThreeKeywordsResponse &p) override;

private:
FixedLevelMethod &method;
RecognitionTestModel &recognitionTestModel;
RunningATest &recognitionTestModel;
OutputFile &outputFile;
};
}
Expand Down
Loading

0 comments on commit 539e978

Please sign in to comment.