FeatureQueue.cpp 1.2 KB
Newer Older
mayong's avatar
mayong committed
1
#include "precomp.h"
mayong's avatar
mayong committed
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
FeatureQueue::FeatureQueue()
{
    buff = new Tensor<float>(67, 80);
    window_size = 67;
    buff_idx = 0;
}

FeatureQueue::~FeatureQueue()
{
    delete buff;
}

void FeatureQueue::reinit(int size)
{
    delete buff;
    buff = new Tensor<float>(size, 80);
    buff_idx = 0;
    window_size = size;
}

void FeatureQueue::reset()
{
    buff_idx = 0;
}

void FeatureQueue::push(float *din, int flag)
{
    int offset = buff_idx * 80;
    memcpy(buff->buff + offset, din, 80 * sizeof(float));
    buff_idx++;

    if (flag == S_END) {
        Tensor<float> *tmp = new Tensor<float>(buff_idx, 80);
        memcpy(tmp->buff, buff->buff, buff_idx * 80 * sizeof(float));
        feature_queue.push(tmp);
        buff_idx = 0;
    } else if (buff_idx == window_size) {
        feature_queue.push(buff);
        Tensor<float> *tmp = new Tensor<float>(window_size, 80);
        memcpy(tmp->buff, buff->buff + (window_size - 3) * 80,
               3 * 80 * sizeof(float));
        buff_idx = 3;
        buff = tmp;
    }
}

Tensor<float> *FeatureQueue::pop()
{

    Tensor<float> *tmp = feature_queue.front();
    feature_queue.pop();
    return tmp;
}

int FeatureQueue::size()
{
    return feature_queue.size();
}