Skip to content

Commit

Permalink
Merge pull request #121 from BoysTownOrg/vibro-split
Browse files Browse the repository at this point in the history
Vibro split
  • Loading branch information
sbashford authored Jul 9, 2024
2 parents 8e08d5a + 5684100 commit 9a38697
Show file tree
Hide file tree
Showing 8 changed files with 168 additions and 126 deletions.
7 changes: 6 additions & 1 deletion lib/core/include/av-speech-in-noise/core/Player.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,13 @@ struct Frequency {
double Hz;
};

struct VibrotactileStimulus {
struct Vibration {
Duration duration{};
};

struct VibrotactileStimulus {
std::vector<Vibration> vibrations;
Duration gap;
Delay targetStartRelativeDelay{};
Delay additionalPostFadeInDelay{};
Frequency frequency{};
Expand Down
86 changes: 47 additions & 39 deletions lib/core/src/OutputFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ enum class OutputFileImpl::Trial {
none
};

static auto operator<<(std::ostream &os, const std::vector<int> &v)
-> std::ostream & {
static auto operator<<(
std::ostream &os, const std::vector<int> &v) -> std::ostream & {
if (!v.empty()) {
auto first{true};
os << v.front();
Expand Down Expand Up @@ -82,63 +82,63 @@ static auto insertNewLine(std::ostream &stream) -> std::ostream & {
}

template <typename T>
auto insertLabeledLine(std::ostream &stream, const std::string &label, T thing)
-> std::ostream & {
auto insertLabeledLine(
std::ostream &stream, const std::string &label, T thing) -> std::ostream & {
return insertNewLine(insert(insert(insert(stream, label), ": "), thing));
}

static auto string(const std::stringstream &stream) -> std::string {
return stream.str();
}

static auto insertSubjectId(std::ostream &stream, const TestIdentity &p)
-> std::ostream & {
static auto insertSubjectId(
std::ostream &stream, const TestIdentity &p) -> std::ostream & {
return insertLabeledLine(stream, "subject", p.subjectId);
}

static auto insertTester(std::ostream &stream, const TestIdentity &p)
-> std::ostream & {
static auto insertTester(
std::ostream &stream, const TestIdentity &p) -> std::ostream & {
return insertLabeledLine(stream, "tester", p.testerId);
}

static auto insertSession(std::ostream &stream, const TestIdentity &p)
-> std::ostream & {
static auto insertSession(
std::ostream &stream, const TestIdentity &p) -> std::ostream & {
return insertLabeledLine(stream, "session", p.session);
}

static auto insertMethod(std::ostream &stream, const TestIdentity &p)
-> std::ostream & {
static auto insertMethod(
std::ostream &stream, const TestIdentity &p) -> std::ostream & {
return insertLabeledLine(stream, "method", p.method);
}

static auto insertRmeSetting(std::ostream &stream, const TestIdentity &p)
-> std::ostream & {
static auto insertRmeSetting(
std::ostream &stream, const TestIdentity &p) -> std::ostream & {
return insertLabeledLine(stream, "RME setting", p.rmeSetting);
}

static auto insertTransducer(std::ostream &stream, const TestIdentity &p)
-> std::ostream & {
static auto insertTransducer(
std::ostream &stream, const TestIdentity &p) -> std::ostream & {
return insertLabeledLine(stream, "transducer", p.transducer);
}

static auto insertMasker(std::ostream &stream, const Test &p)
-> std::ostream & {
static auto insertMasker(
std::ostream &stream, const Test &p) -> std::ostream & {
return insertLabeledLine(stream, "masker", p.maskerFileUrl.path);
}

static auto insertTargetPlaylist(std::ostream &stream, const Test &p)
-> std::ostream & {
static auto insertTargetPlaylist(
std::ostream &stream, const Test &p) -> std::ostream & {
return insertLabeledLine(stream, "targets", p.targetsUrl.path);
}

static auto insertMaskerLevel(std::ostream &stream, const Test &p)
-> std::ostream & {
static auto insertMaskerLevel(
std::ostream &stream, const Test &p) -> std::ostream & {
return insertLabeledLine(
stream, "masker level (dB SPL)", p.maskerLevel.dB_SPL);
}

static auto insertCondition(std::ostream &stream, const Test &p)
-> std::ostream & {
static auto insertCondition(
std::ostream &stream, const Test &p) -> std::ostream & {
return insertLabeledLine(stream, "condition", name(p.condition));
}

Expand All @@ -155,8 +155,8 @@ static auto evaluation(const Evaluative &trial) -> std::string {

static auto identity(const Test &test) -> TestIdentity { return test.identity; }

static auto operator<<(std::ostream &stream, const TestIdentity &identity)
-> std::ostream & {
static auto operator<<(
std::ostream &stream, const TestIdentity &identity) -> std::ostream & {
return insertTransducer(
insertRmeSetting(
insertMethod(
Expand All @@ -168,8 +168,8 @@ static auto operator<<(std::ostream &stream, const TestIdentity &identity)
identity);
}

static auto operator<<(std::ostream &stream, const AdaptiveTest &test)
-> std::ostream & {
static auto operator<<(
std::ostream &stream, const AdaptiveTest &test) -> std::ostream & {
stream << identity(test);
insertMasker(stream, test);
insertTargetPlaylist(stream, test);
Expand All @@ -194,8 +194,8 @@ static auto operator<<(std::ostream &stream, const AdaptiveTest &test)
return insertNewLine(stream);
}

static auto operator<<(std::ostream &stream, const FixedLevelTest &test)
-> std::ostream & {
static auto operator<<(
std::ostream &stream, const FixedLevelTest &test) -> std::ostream & {
stream << identity(test);
insertMasker(stream, test);
insertTargetPlaylist(stream, test);
Expand Down Expand Up @@ -264,8 +264,8 @@ static auto operator<<(std::ostream &stream,
return insertNewLine(stream);
}

static auto operator<<(std::ostream &stream, TargetStartTime t)
-> std::ostream & {
static auto operator<<(
std::ostream &stream, TargetStartTime t) -> std::ostream & {
return insertLabeledLine(stream, "target start time (ns)", t.nanoseconds);
}

Expand All @@ -281,14 +281,14 @@ static auto operator<<(std::ostream &stream,
return insertNewLine(stream);
}

static auto operator<<(std::ostream &stream, const AdaptiveTestResult &result)
-> std::ostream & {
static auto operator<<(
std::ostream &stream, const AdaptiveTestResult &result) -> std::ostream & {
return insertLabeledLine(
stream, "threshold for " + result.targetsUrl.path, result.threshold);
}

static auto operator<<(std::ostream &stream, const Flaggable &flaggable)
-> std::ostream & {
static auto operator<<(
std::ostream &stream, const Flaggable &flaggable) -> std::ostream & {
if (flaggable.flagged) {
insertCommaAndSpace(stream);
insert(stream, "FLAGGED");
Expand Down Expand Up @@ -652,7 +652,15 @@ class KeyPressTrialFormatter : public TrialFormatter {
insertCommaAndSpace(stream);
insert(stream, trial_.rt.milliseconds);
insertCommaAndSpace(stream);
insert(stream, trial_.vibrotactileStimulus.duration.seconds);
stream << '[';
auto first{true};
for (const auto &v : trial_.vibrotactileStimulus.vibrations) {
if (!first)
stream << "; ";
insert(stream, v.duration.seconds);
first = false;
}
stream << ']';
insertCommaAndSpace(stream);
insert(stream,
trial_.vibrotactileStimulus.targetStartRelativeDelay.seconds);
Expand Down Expand Up @@ -782,8 +790,8 @@ void OutputFileImpl::openNewFile(const TestIdentity &test) {
currentTrial = Trial::none;
}

auto OutputFileImpl::generateNewFilePath(const TestIdentity &test)
-> std::string {
auto OutputFileImpl::generateNewFilePath(
const TestIdentity &test) -> std::string {
path.setRelativeOutputDirectory(test.relativeOutputUrl.path);
return path.outputDirectory() + "/" + path.generateFileName(test) + ".txt";
}
Expand Down
19 changes: 13 additions & 6 deletions lib/core/src/SubmittingKeyPress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,28 @@ InteractorImpl::InteractorImpl(FixedLevelMethod &method, RunningATest &model,
maskerPlayer{maskerPlayer}, randomizer{randomizer} {}

template <std::size_t N>
auto randomSelection(Randomizer &randomizer, std::array<double, N> x)
-> double {
auto randomSelection(
Randomizer &randomizer, std::array<double, N> x) -> double {
return x.at(randomizer.betweenInclusive(0, x.size() - 1));
}

void InteractorImpl::notifyThatTrialWillBegin(int) {
const std::array<double, 4> delaysSeconds = {2.060, 2.110, 2.160, 2.190};
const std::array<double, 6> delaysSeconds = {
1.94, 2., 2.060, 2.110, 2.160, 2.190};
const std::array<double, 2> durationsSeconds = {.100, .250};

VibrotactileStimulus stimulus;
stimulus.targetStartRelativeDelay.seconds =
randomSelection(randomizer, delaysSeconds);
stimulus.additionalPostFadeInDelay.seconds =
RunningATest::targetOnsetFringeDuration.seconds;
stimulus.duration.seconds = randomSelection(randomizer, durationsSeconds);
stimulus.vibrations.resize(2);
const auto firstDurationIndex = randomizer.betweenInclusive(0, 1);
stimulus.vibrations.at(0).duration.seconds =
durationsSeconds.at(firstDurationIndex);
stimulus.vibrations.at(1).duration.seconds =
durationsSeconds.at((firstDurationIndex + 1) % 2);
stimulus.gap.seconds = 0.1;
stimulus.frequency.Hz = 250;
maskerPlayer.prepareVibrotactileStimulus(stimulus);
lastVibrotactileStimulus = stimulus;
Expand All @@ -46,8 +53,8 @@ void InteractorImpl::notifyThatTargetWillPlayAt(
1000;
}

auto InteractorImpl::submits(const std::vector<KeyPressResponse> &responses)
-> bool {
auto InteractorImpl::submits(
const std::vector<KeyPressResponse> &responses) -> bool {
if (!readyForResponse)
return false;
auto min{responses.end()};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,15 @@ class MaskerPlayerImpl : public MaskerPlayer,
static constexpr Delay callbackDelay{1. / 30};

struct SharedState {
audio_type sourceAudio{};
audio_type sourceAudio;
std::vector<sample_index_type> samplesToWaitPerChannel;
std::vector<sample_index_type> audioFrameHeadsPerChannel;
std::vector<sample_type> vibrotactileStimulus;
double levelScalar{1};
double vibrotactileTimeScalar{};
std::atomic<player_system_time_type> fadeInCompleteSystemTime{};
std::atomic<gsl::index> fadeInCompleteSystemTimeSampleOffset{};
gsl::index rampSamples{};
gsl::index steadyLevelSamples{};
gsl::index vibrotactileSamples{};
gsl::index vibrotactileSamplesToWait{};
bool firstChannelOnly{};
bool secondChannelOnly{};
Expand Down
Loading

0 comments on commit 9a38697

Please sign in to comment.