text stringlengths 0 2.2M |
|---|
#include "flashlight/lib/audio/feature/SpeechUtils.h"
|
namespace fl {
|
namespace lib {
|
namespace audio {
|
Derivatives::Derivatives(int deltawindow, int accwindow)
|
: deltaWindow_(deltawindow), accWindow_(accwindow) {}
|
std::vector<float> Derivatives::apply(
|
const std::vector<float>& input,
|
int numfeat) const {
|
if (input.size() % numfeat != 0) {
|
throw std::invalid_argument(
|
"Derivatives: input size is not divisible by numFeatures");
|
}
|
// Compute deltas
|
if (deltaWindow_ <= 0) {
|
return input;
|
}
|
auto deltas = computeDerivative(input, deltaWindow_, numfeat);
|
size_t szMul = 2;
|
std::vector<float> doubledeltas;
|
if (accWindow_ > 0) {
|
// Compute double deltas (only if required)
|
szMul = 3;
|
doubledeltas = computeDerivative(deltas, accWindow_, numfeat);
|
}
|
std::vector<float> output(input.size() * szMul);
|
int numframes = input.size() / numfeat;
|
for (size_t i = 0; i < numframes; ++i) {
|
size_t curInIdx = i * numfeat;
|
size_t curOutIdx = curInIdx * szMul;
|
// copy input
|
std::copy(
|
input.data() + curInIdx,
|
input.data() + curInIdx + numfeat,
|
output.data() + curOutIdx);
|
// copy deltas
|
std::copy(
|
deltas.data() + curInIdx,
|
deltas.data() + curInIdx + numfeat,
|
output.data() + curOutIdx + numfeat);
|
// copy double-deltas
|
if (accWindow_ > 0) {
|
std::copy(
|
doubledeltas.data() + curInIdx,
|
doubledeltas.data() + curInIdx + numfeat,
|
output.data() + curOutIdx + 2 * numfeat);
|
}
|
}
|
return output;
|
}
|
std::vector<float> Derivatives::computeDerivative(
|
const std::vector<float>& input,
|
int windowlen,
|
int numfeat) const {
|
int numframes = input.size() / numfeat;
|
std::vector<float> output(input.size(), 0.0);
|
float denominator = (windowlen * (windowlen + 1) * (2 * windowlen + 1)) / 3.0;
|
for (size_t i = 0; i < numframes; ++i) {
|
for (size_t j = 0; j < numfeat; ++j) {
|
size_t curIdx = i * numfeat + j;
|
for (size_t d = 1; d <= windowlen; ++d) {
|
output[curIdx] += d *
|
(input[curIdx + std::min((numframes - i - 1), d) * numfeat] -
|
input[curIdx - std::min(i, d) * numfeat]);
|
}
|
output[curIdx] /= denominator;
|
}
|
}
|
return output;
|
}
|
} // namespace audio
|
} // namespace lib
|
} // namespace fl
|
/////////////////////////////////////////////////////////////////////////////
|
// Copyright (c) Electronic Arts Inc. All rights reserved.
|
/////////////////////////////////////////////////////////////////////////////
|
#ifndef EASTLTEST_ALLOCATOR_H
|
#define EASTLTEST_ALLOCATOR_H
|
#include <EABase/eabase.h>
|
#include <EASTL/internal/config.h>
|
#include <new>
|
#include <stdio.h>
|
#if !EASTL_OPENSOURCE
|
#include <PPMalloc/EAGeneralAllocator.h>
|
#include <PPMalloc/EAGeneralAllocatorDebug.h>
|
#include <coreallocator/icoreallocator_interface.h>
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.