Skip to content

Commit

Permalink
Replay flagged targets 10 29 19 (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
sbashford authored Oct 30, 2019
1 parent 1c07b61 commit e5acf12
Show file tree
Hide file tree
Showing 43 changed files with 539 additions and 404 deletions.
2 changes: 1 addition & 1 deletion av-speech-in-noise/adaptive-track/src/AdaptiveTrack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ AdaptiveTrack::AdaptiveTrack(const Settings &p)
: x_{p.startingX}, ceiling_{p.ceiling}, floor_{p.floor},
bumpLimit_{p.bumpLimit}, bumpCount_{0} {
for (const auto &sequence : *p.rule)
if (sequence.runCount) {
if (sequence.runCount != 0) {
stepSizes.push_back(sequence.stepSize);
runCounts.push_back(sequence.runCount);
up_.push_back(sequence.up);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ struct Trial {
};

struct AdaptiveTrial : Trial {
int SNR_dB;
int reversals;
int SNR_dB{};
int reversals{};
};

struct FixedLevelTrial : Trial {};
Expand Down Expand Up @@ -82,7 +82,7 @@ struct AdaptiveTest : Test {
};

struct FixedLevelTest : Test {
int snr_dB;
int snr_dB{};
int trials{30};
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,6 @@ class Presenter : public Model::EventListener {
bool method(Method m);
int readMaskerLevel();
int readCalibrationLevel();
int readInteger(std::string x, std::string identifier);
bool auditoryOnly();

View::TestSetup *view;
Expand Down
39 changes: 19 additions & 20 deletions av-speech-in-noise/presentation/src/Presenter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,7 @@ auto Presenter::trialCompletionHandler() -> TrialCompletionHandler * {
return &adaptiveOpenSetTrialCompletionHandler;
if (fixedLevelClosedSet())
return &fixedLevelClosedSetTrialCompletionHandler;
else
return &fixedLevelOpenSetTrialCompletionHandler;
return &fixedLevelOpenSetTrialCompletionHandler;
}

void Presenter::showErrorMessage(std::string e) {
Expand Down Expand Up @@ -243,6 +242,19 @@ void Presenter::TestSetup::show() { view->show(); }

void Presenter::TestSetup::hide() { view->hide(); }

static int readInteger(const std::string &x, const std::string &identifier) {
try {
return std::stoi(x);
} catch (const std::invalid_argument &) {
std::stringstream stream;
stream << '\'' << x << '\'';
stream << " is not a valid ";
stream << identifier;
stream << '.';
throw BadInput{stream.str()};
}
}

FixedLevelTest Presenter::TestSetup::fixedLevelTest() {
FixedLevelTest p;
commonTest(p);
Expand Down Expand Up @@ -283,19 +295,6 @@ Condition Presenter::TestSetup::readCondition() {
return auditoryOnly() ? Condition::auditoryOnly : Condition::audioVisual;
}

int Presenter::TestSetup::readInteger(std::string x, std::string identifier) {
try {
return std::stoi(x);
} catch (const std::invalid_argument &) {
std::stringstream stream;
stream << '\'' << std::move(x) << '\'';
stream << " is not a valid ";
stream << std::move(identifier);
stream << '.';
throw BadInput{stream.str()};
}
}

bool Presenter::TestSetup::auditoryOnly() {
return view->condition() == conditionName(Condition::auditoryOnly);
}
Expand Down Expand Up @@ -410,7 +409,7 @@ void Presenter::Subject::hideResponseButtons() { view->hideResponseButtons(); }
void Presenter::Subject::showResponseButtons() { view->showResponseButtons(); }

coordinate_response_measure::Response Presenter::Subject::subjectResponse() {
coordinate_response_measure::Response p;
coordinate_response_measure::Response p{};
p.color = colorResponse();
p.number = std::stoi(view->numberResponse());
return p;
Expand All @@ -419,12 +418,12 @@ coordinate_response_measure::Response Presenter::Subject::subjectResponse() {
coordinate_response_measure::Color Presenter::Subject::colorResponse() {
if (view->greenResponse())
return coordinate_response_measure::Color::green;
else if (view->blueResponse())
if (view->blueResponse())
return coordinate_response_measure::Color::blue;
else if (view->whiteResponse())
if (view->whiteResponse())
return coordinate_response_measure::Color::white;
else
return coordinate_response_measure::Color::red;

return coordinate_response_measure::Color::red;
}

Presenter::Testing::Testing(View::Testing *view) : view{view} {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class TargetList {
virtual std::string next() = 0;
virtual std::string current() = 0;
virtual bool empty() = 0;
virtual void reinsertCurrent() = 0;
};

class ResponseEvaluator {
Expand Down
2 changes: 1 addition & 1 deletion av-speech-in-noise/recognition-test/src/AdaptiveMethod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ void AdaptiveMethodImpl::selectNextListAfter(void (AdaptiveMethodImpl::*f)()) {

void AdaptiveMethodImpl::makeSnrTracks() {
targetListsWithTracks.clear();
for (auto list : lists)
for (const auto& list : lists)
makeTrackWithList(list.get());
}

Expand Down
4 changes: 3 additions & 1 deletion av-speech-in-noise/recognition-test/src/FixedLevelMethod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ void FixedLevelMethodImpl::submitIncorrectResponse() {}

void FixedLevelMethodImpl::submitCorrectResponse() {}

void FixedLevelMethodImpl::submitResponse(const FreeResponse &) {
void FixedLevelMethodImpl::submitResponse(const FreeResponse &response) {
if (response.flagged)
targetList->reinsertCurrent();
complete_ = concluder->complete(targetList);
}
}
4 changes: 2 additions & 2 deletions av-speech-in-noise/recognition-test/src/OutputFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ class FormattedStream {
std::stringstream stream;

public:
template <typename T> void writeLabeledLine(std::string label, T thing) {
stream << std::move(label);
template <typename T> void writeLabeledLine(const std::string& label, T thing) {
stream << label;
stream << ": ";
stream << thing;
stream << '\n';
Expand Down
14 changes: 7 additions & 7 deletions av-speech-in-noise/recognition-test/src/ResponseEvaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ int ResponseEvaluatorImpl::correctNumber_(const std::string &filePath) {

unsigned long ResponseEvaluatorImpl::leadingPathLength(
const std::string &filePath) {
return filePath.find_last_of("/") + 1;
return filePath.find_last_of('/') + 1;
}

long ResponseEvaluatorImpl::colorNameLength(
const std::string &filePath, unsigned long leadingPathLength_) {
auto fileNameBeginning = filePath.begin() + leadingPathLength_;
auto notAlpha = std::find_if(fileNameBeginning, filePath.end(),
[](unsigned char c) { return !std::isalpha(c); });
[](unsigned char c) { return std::isalpha(c) == 0; });
return std::distance(fileNameBeginning, notAlpha);
}

Expand All @@ -54,14 +54,14 @@ coordinate_response_measure::Color ResponseEvaluatorImpl::color(
using coordinate_response_measure::Color;
if (colorName == "green")
return Color::green;
else if (colorName == "blue")
if (colorName == "blue")
return Color::blue;
else if (colorName == "red")
if (colorName == "red")
return Color::red;
else if (colorName == "white")
if (colorName == "white")
return Color::white;
else
return Color::notAColor;

return Color::notAColor;
}

std::string ResponseEvaluatorImpl::fileName(const std::string &filePath) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Stream {
bool failed_{};

public:
explicit Stream(std::string s) : stream{std::move(s)} {}
explicit Stream(const std::string& s) : stream{s} {}

bool nextLine() {
if (!std::getline(stream, lastLine_))
Expand Down Expand Up @@ -78,7 +78,7 @@ static void (*propertyApplication(const std::string &s))(

const TrackingRule *TrackSettingsInterpreterImpl::trackingRule(std::string s) {
rule_.clear();
auto stream = Stream{std::move(s)};
auto stream = Stream{s};
while (stream.nextLine()) {
auto sequenceCount{0U};
auto f = propertyApplication(stream.propertyName());
Expand Down
4 changes: 2 additions & 2 deletions av-speech-in-noise/stimulus-players/src/AudioReaderImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ AudioReaderImpl::AudioReaderImpl(BufferedAudioReader *reader)
std::vector<std::vector<float>> AudioReaderImpl::read(std::string filePath) {
loadFile(std::move(filePath));
std::vector<std::vector<float>> audio{};
float minimumSample = reader->minimumPossibleSample();
auto minimumSample = reader->minimumPossibleSample();
for (auto buffer = reader->readNextBuffer(); !buffer->empty();
buffer = reader->readNextBuffer()) {
audio.resize(buffer->channels());
for (int channel = 0; channel < buffer->channels(); ++channel)
for (auto x : buffer->channel(channel))
audio.at(channel).push_back(x / minimumSample);
audio.at(channel).push_back(1.F * x / minimumSample);
}
return audio;
}
Expand Down
14 changes: 8 additions & 6 deletions av-speech-in-noise/stimulus-players/src/MaskerPlayerImpl.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "MaskerPlayerImpl.hpp"
#include <cmath>
#include <gsl/gsl>

namespace stimulus_players {
MaskerPlayerImpl::MaskerPlayerImpl(
Expand Down Expand Up @@ -68,7 +69,7 @@ void MaskerPlayerImpl::setFadeInOutSeconds(double x) {
}

void MaskerPlayerImpl::setAudioDevice(std::string device) {
player->setDevice(findDeviceIndex(std::move(device)));
player->setDevice(findDeviceIndex(device));
}

int MaskerPlayerImpl::findDeviceIndex(const std::string &device) {
Expand Down Expand Up @@ -198,28 +199,29 @@ void MaskerPlayerImpl::AudioThread::prepareToFadeOut() {
}

int MaskerPlayerImpl::AudioThread::levelTransitionSamples() {
return sharedAtomics->fadeInOutSeconds.load() * player->sampleRateHz();
return gsl::narrow_cast<int>(
sharedAtomics->fadeInOutSeconds.load() * player->sampleRateHz());
}

void MaskerPlayerImpl::AudioThread::scaleAudio(
const std::vector<gsl::span<float>> &audio) {
if (audio.size() == 0)
if (audio.empty())
return;

auto firstChannel = audio.front();
auto levelScalar_ = sharedAtomics->levelScalar.load();
for (int i = 0; i < firstChannel.size(); ++i) {
auto fadeScalar_ = fadeScalar();
updateFadeState();
for (size_t channel = 0; channel < audio.size(); ++channel)
audio.at(channel).at(i) *= fadeScalar_ * levelScalar_;
for (auto channel : audio)
channel.at(i) *= fadeScalar_ * levelScalar_;
}
}

static const auto pi = std::acos(-1);

double MaskerPlayerImpl::AudioThread::fadeScalar() {
const auto squareRoot = halfWindowLength
const auto squareRoot = halfWindowLength != 0
? std::sin((pi * hannCounter) / (2 * halfWindowLength))
: 1;
return squareRoot * squareRoot;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class RandomizedTargetList : public av_speech_in_noise::TargetList {
std::string next() override;
std::string current() override;
bool empty() override;

void reinsertCurrent() override;
private:
std::string fullPath(std::string file);
void shuffle();
Expand Down Expand Up @@ -66,6 +66,7 @@ class RandomizedFiniteTargetList : public av_speech_in_noise::TargetList {
void loadFromDirectory(std::string directory) override;
std::string next() override;
std::string current() override;
void reinsertCurrent() override;

private:
bool empty_();
Expand Down
6 changes: 6 additions & 0 deletions av-speech-in-noise/target-list/src/RandomizedTargetList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ std::string RandomizedTargetList::fullPath(std::string file) {

std::string RandomizedTargetList::current() { return fullPath(currentFile_); }

void RandomizedTargetList::reinsertCurrent() {}

RandomizedFiniteTargetList::RandomizedFiniteTargetList(
DirectoryReader *reader, Randomizer *randomizer)
: reader{reader}, randomizer{randomizer} {}
Expand Down Expand Up @@ -72,4 +74,8 @@ std::string RandomizedFiniteTargetList::fullPath(std::string file) {
std::string RandomizedFiniteTargetList::current() {
return fullPath(currentFile_);
}

void RandomizedFiniteTargetList::reinsertCurrent() {
files.push_back(currentFile_);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ SubdirectoryTargetListReader::SubdirectoryTargetListReader(
auto SubdirectoryTargetListReader::read(std::string directory) -> lists_type {
lists_type lists{};
auto subDirectories_ = subDirectories(directory);
for (auto d : subDirectories_) {
for (const auto &subDirectory : subDirectories_) {
lists.push_back(targetListFactory->make());
lists.back()->loadFromDirectory(directory + "/" + d);
auto fullPath = directory;
fullPath.append("/" + subDirectory);
lists.back()->loadFromDirectory(std::move(fullPath));
}
if (subDirectories_.empty()) {
lists.push_back(targetListFactory->make());
Expand Down
6 changes: 3 additions & 3 deletions tests/AdaptiveMethodTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class TrackSettingsReaderStub : public TrackSettingsReader {
std::string filePath_{};

public:
auto filePath() const { return filePath_; }
[[nodiscard]] auto filePath() const { return filePath_; }

const TrackingRule *read(std::string s) override {
filePath_ = std::move(s);
Expand Down Expand Up @@ -195,7 +195,7 @@ class AdaptiveMethodTests : public ::testing::Test {
WritingCorrectResponse writingCorrectResponse{outputFile};
WritingIncorrectResponse writingIncorrectResponse{outputFile};
AdaptiveTest test;
coordinate_response_measure::Response coordinateResponse;
coordinate_response_measure::Response coordinateResponse{};
TrackingRule targetLevelRule_;
std::vector<std::shared_ptr<TargetListStub>> lists;
std::vector<std::shared_ptr<TrackStub>> tracks;
Expand Down Expand Up @@ -326,7 +326,7 @@ class AdaptiveMethodTests : public ::testing::Test {
assertEqual(4, useCase.writtenSnr(outputFile));
}

auto blueColor() { return coordinate_response_measure::Color::blue; }
static auto blueColor() { return coordinate_response_measure::Color::blue; }

bool writtenCoordinateResponseTrialCorrect() {
return writtenCoordinateResponseTrial().correct;
Expand Down
Loading

0 comments on commit e5acf12

Please sign in to comment.