Renamed TimeSegment to TimeRange

This commit is contained in:
Daniel Wolf 2016-03-28 20:25:11 +02:00
parent 8c1e24e9c8
commit 2be3751a4f
7 changed files with 33 additions and 30 deletions

View File

@ -119,7 +119,7 @@ set(SOURCE_FILES
src/ProgressBar.cpp
src/logging.cpp
src/Timed.cpp
src/TimeSegment.cpp
src/TimeRange.cpp
)
add_executable(rhubarb ${SOURCE_FILES})
target_link_libraries(rhubarb ${Boost_LIBRARIES} cppFormat sphinxbase pocketSphinx)

21
src/TimeRange.cpp Normal file
View File

@ -0,0 +1,21 @@
#include "TimeRange.h"
#include <stdexcept>
TimeRange::TimeRange(centiseconds start, centiseconds end) :
start(start),
end(end)
{
if (start > end) throw std::invalid_argument("start must not be less than end.");
}
centiseconds TimeRange::getStart() const {
return start;
}
centiseconds TimeRange::getEnd() const {
return end;
}
centiseconds TimeRange::getLength() const {
return end - start;
}

View File

@ -1,9 +1,9 @@
#pragma once
#include "centiseconds.h"
class TimeSegment {
class TimeRange {
public:
TimeSegment(centiseconds start, centiseconds end);
TimeRange(centiseconds start, centiseconds end);
centiseconds getStart() const;
centiseconds getEnd() const;
centiseconds getLength() const;

View File

@ -1,18 +0,0 @@
#include "TimeSegment.h"
TimeSegment::TimeSegment(centiseconds start, centiseconds end) :
start(start),
end(end)
{}
centiseconds TimeSegment::getStart() const {
return start;
}
centiseconds TimeSegment::getEnd() const {
return end;
}
centiseconds TimeSegment::getLength() const {
return end - start;
}

View File

@ -1,12 +1,12 @@
#pragma once
#include <TimeSegment.h>
#include <TimeRange.h>
template<typename TValue>
class Timed : public TimeSegment {
class Timed : public TimeRange {
public:
Timed(centiseconds start, centiseconds end, TValue value) :
TimeSegment(start, end),
TimeRange(start, end),
value(value)
{}

View File

@ -17,7 +17,7 @@ float getRMS(AudioStream& audioStream, int maxSampleCount = numeric_limits<int>:
return sampleCount > 0 ? static_cast<float>(std::sqrt(sum / sampleCount)) : 0.0f;
}
vector<TimeSegment> detectVoiceActivity(std::unique_ptr<AudioStream> audioStream) {
vector<TimeRange> detectVoiceActivity(std::unique_ptr<AudioStream> audioStream) {
// Make sure audio stream has no DC offset
audioStream = removeDCOffset(std::move(audioStream));
@ -30,7 +30,7 @@ vector<TimeSegment> detectVoiceActivity(std::unique_ptr<AudioStream> audioStream
float cutoff = rms / 50;
centiseconds maxGap(10);
vector<TimeSegment> result;
vector<TimeRange> result;
optional<centiseconds> segmentStart, segmentEnd;
for (centiseconds time = centiseconds(0); !audioStream->endOfStream(); ++time) {
float currentPower = getRMS(*audioStream, sampleRate / 100);
@ -41,14 +41,14 @@ vector<TimeSegment> detectVoiceActivity(std::unique_ptr<AudioStream> audioStream
}
segmentEnd = time + centiseconds(1);
} else if (segmentEnd && time > segmentEnd.value() + maxGap) {
result.push_back(TimeSegment(segmentStart.value(), segmentEnd.value()));
result.push_back(TimeRange(segmentStart.value(), segmentEnd.value()));
logTimedEvent("utterance", segmentStart.value(), segmentEnd.value(), "");
segmentStart.reset();
segmentEnd.reset();
}
}
if (segmentEnd) {
result.push_back(TimeSegment(segmentStart.value(), segmentEnd.value()));
result.push_back(TimeRange(segmentStart.value(), segmentEnd.value()));
}
return result;

View File

@ -1,7 +1,7 @@
#pragma once
#include <vector>
#include <TimeSegment.h>
#include <TimeRange.h>
#include <memory>
#include "AudioStream.h"
std::vector<TimeSegment> detectVoiceActivity(std::unique_ptr<AudioStream> audioStream);
std::vector<TimeRange> detectVoiceActivity(std::unique_ptr<AudioStream> audioStream);