Skip to content

Commit

Permalink
Merge pull request #91 from BoysTownorg/audio-recording-file-name
Browse files Browse the repository at this point in the history
Audio recording file name
  • Loading branch information
sbashford authored Jun 30, 2022
2 parents 539e978 + dd30d4a commit 9c30ec7
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 68 deletions.
4 changes: 3 additions & 1 deletion lib/core/include/av-speech-in-noise/core/AudioRecording.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

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

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

Expand All @@ -19,7 +20,7 @@ class AudioRecorder {

class AudioRecording : public RunningATest::Observer {
public:
AudioRecording(AudioRecorder &, OutputFile &);
AudioRecording(AudioRecorder &, OutputFile &, TimeStamp &);
void notifyThatNewTestIsReady(std::string_view session) override;
void notifyThatTrialWillBegin(int trialNumber) override;
void notifyThatTargetWillPlayAt(const PlayerTimeWithDelay &) override;
Expand All @@ -30,6 +31,7 @@ class AudioRecording : public RunningATest::Observer {
std::string session;
AudioRecorder &audioRecorder;
OutputFile &outputFile;
TimeStamp &timeStamp;
};
}

Expand Down
16 changes: 13 additions & 3 deletions lib/core/src/AudioRecording.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
#include "AudioRecording.hpp"
#include "FileSystemPath.hpp"

#include <sstream>

namespace av_speech_in_noise {
AudioRecording::AudioRecording(
AudioRecorder &audioRecorder, OutputFile &outputFile)
: audioRecorder{audioRecorder}, outputFile{outputFile} {}
AudioRecorder &audioRecorder, OutputFile &outputFile, TimeStamp &timeStamp)
: audioRecorder{audioRecorder}, outputFile{outputFile}, timeStamp{
timeStamp} {}

void AudioRecording::notifyThatTrialWillBegin(int trialNumber) {
timeStamp.capture();
std::stringstream filename;
filename << trialNumber << '-' << session << ".wav";
filename << trialNumber << '-' << session;
filename << '-' << timeStamp.year();
filename << '-' << timeStamp.month();
filename << '-' << timeStamp.dayOfMonth();
filename << '-' << timeStamp.hour();
filename << '-' << timeStamp.minute();
filename << '-' << timeStamp.second();
filename << ".wav";
audioRecorder.initialize(
LocalUrl{outputFile.parentPath() / filename.str()});
}
Expand Down
2 changes: 1 addition & 1 deletion macos/run.mm
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ void initializeAppAndRunEventLoop(EyeTracker &eyeTracker,
&cyclicTargetsFactory, &directoryReader};
static PredeterminedTargetPlaylist predeterminedTargetPlaylist{
textFileReader};
static AudioRecording audioRecording{audioRecorder, outputFile};
static AudioRecording audioRecording{audioRecorder, outputFile, timeStamp};
static EyeTracking eyeTracking{
eyeTracker, maskerPlayer, targetPlayer, outputFile};
static RunningATestFacadeImpl model{adaptiveMethod, fixedLevelMethod,
Expand Down
19 changes: 16 additions & 3 deletions test/AudioRecording.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "AudioRecorderStub.hpp"
#include "OutputFileStub.hpp"
#include "TimeStampStub.hpp"
#include "assert-utility.hpp"

#include <av-speech-in-noise/core/AudioRecording.hpp>
Expand All @@ -11,17 +12,29 @@ class AudioRecordingTests : public ::testing::Test {
protected:
AudioRecorderStub audioRecorder;
OutputFileStub outputFile;
AudioRecording audioRecording{audioRecorder, outputFile};
TimeStampStub timeStamp;
AudioRecording audioRecording{audioRecorder, outputFile, timeStamp};
};

#define AUDIO_RECORDING_TEST(a) TEST_F(AudioRecordingTests, a)

AUDIO_RECORDING_TEST(initializesRecorderWhenTrialWillBegin) {
outputFile.setParentPath("/Users/user/data");
audioRecording.notifyThatNewTestIsReady("smile");
timeStamp.setYear(1);
timeStamp.setMonth(2);
timeStamp.setDayOfMonth(7);
timeStamp.setHour(4);
timeStamp.setMinute(5);
timeStamp.setSecond(6);
audioRecording.notifyThatTrialWillBegin(3);
AV_SPEECH_IN_NOISE_EXPECT_EQUAL(
"/Users/user/data/3-smile.wav", audioRecorder.fileUrl().path);
AV_SPEECH_IN_NOISE_EXPECT_EQUAL("/Users/user/data/3-smile-1-2-7-4-5-6.wav",
audioRecorder.fileUrl().path);
}

AUDIO_RECORDING_TEST(generateFileNameCapturesTimePriorToQueries) {
audioRecording.notifyThatTrialWillBegin(1);
AV_SPEECH_IN_NOISE_EXPECT_TRUE(beginsWith(timeStamp.log(), "capture"));
}

AUDIO_RECORDING_TEST(startsRecordingWhenStimulusEnds) {
Expand Down
64 changes: 4 additions & 60 deletions test/OutputFilePath.cpp
Original file line number Diff line number Diff line change
@@ -1,68 +1,12 @@
#include "LogString.hpp"
#include "TimeStampStub.hpp"
#include "assert-utility.hpp"
#include <gtest/gtest.h>

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

#include <gtest/gtest.h>

namespace av_speech_in_noise {
namespace {
class TimeStampStub : public TimeStamp {
public:
void capture() override { insert(log_, "capture "); }

auto log() const -> const std::stringstream & { return log_; }

void setYear(int y) { year_ = y; }

void setMonth(int y) { month_ = y; }

void setDayOfMonth(int y) { dayOfMonth_ = y; }

void setHour(int y) { hour_ = y; }

void setMinute(int y) { minute_ = y; }

void setSecond(int y) { second_ = y; }

auto year() -> int override {
insert(log_, "year ");
return year_;
}

auto month() -> int override {
insert(log_, "month ");
return month_;
}

auto dayOfMonth() -> int override {
insert(log_, "dayOfMonth ");
return dayOfMonth_;
}

auto hour() -> int override {
insert(log_, "hour ");
return hour_;
}

auto minute() -> int override {
insert(log_, "minute ");
return minute_;
}

auto second() -> int override {
insert(log_, "second ");
return second_;
}

private:
std::stringstream log_{};
int year_{};
int month_{};
int dayOfMonth_{};
int hour_{};
int minute_{};
int second_{};
};

class FileSystemPathStub : public FileSystemPath {
std::string homeDirectory_{};
std::string directoryCreated_{};
Expand Down
70 changes: 70 additions & 0 deletions test/TimeStampStub.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#ifndef AV_SPEECH_IN_NOISE_TESTS_TIMESTAMPSTUB_HPP_
#define AV_SPEECH_IN_NOISE_TESTS_TIMESTAMPSTUB_HPP_

#include "LogString.hpp"

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

#include <sstream>

namespace av_speech_in_noise {
class TimeStampStub : public TimeStamp {
public:
void capture() override { insert(log_, "capture "); }

auto log() const -> const std::stringstream & { return log_; }

void setYear(int y) { year_ = y; }

void setMonth(int y) { month_ = y; }

void setDayOfMonth(int y) { dayOfMonth_ = y; }

void setHour(int y) { hour_ = y; }

void setMinute(int y) { minute_ = y; }

void setSecond(int y) { second_ = y; }

auto year() -> int override {
insert(log_, "year ");
return year_;
}

auto month() -> int override {
insert(log_, "month ");
return month_;
}

auto dayOfMonth() -> int override {
insert(log_, "dayOfMonth ");
return dayOfMonth_;
}

auto hour() -> int override {
insert(log_, "hour ");
return hour_;
}

auto minute() -> int override {
insert(log_, "minute ");
return minute_;
}

auto second() -> int override {
insert(log_, "second ");
return second_;
}

private:
std::stringstream log_{};
int year_{};
int month_{};
int dayOfMonth_{};
int hour_{};
int minute_{};
int second_{};
};
}

#endif

0 comments on commit 9c30ec7

Please sign in to comment.