|
@@ -33,8 +33,7 @@ std::string FeatureExtractorConfig::ToString() const {
|
|
|
|
|
|
os << "FeatureExtractorConfig(";
|
|
|
os << "sampling_rate=" << sampling_rate << ", ";
|
|
|
- os << "feature_dim=" << feature_dim << ", ";
|
|
|
- os << "max_feature_vectors=" << max_feature_vectors << ")";
|
|
|
+ os << "feature_dim=" << feature_dim << ")";
|
|
|
|
|
|
return os.str();
|
|
|
}
|
|
@@ -46,8 +45,6 @@ class FeatureExtractor::Impl {
|
|
|
opts_.frame_opts.snip_edges = false;
|
|
|
opts_.frame_opts.samp_freq = config.sampling_rate;
|
|
|
|
|
|
- opts_.frame_opts.max_feature_vectors = config.max_feature_vectors;
|
|
|
-
|
|
|
opts_.mel_opts.num_bins = config.feature_dim;
|
|
|
|
|
|
fbank_ = std::make_unique<knf::OnlineFbank>(opts_);
|
|
@@ -112,12 +109,21 @@ class FeatureExtractor::Impl {
|
|
|
return fbank_->IsLastFrame(frame);
|
|
|
}
|
|
|
|
|
|
- ncnn::Mat GetFrames(int32_t frame_index, int32_t n) const {
|
|
|
- if (frame_index + n > NumFramesReady()) {
|
|
|
- NCNN_LOGE("%d + %d > %d", frame_index, n, NumFramesReady());
|
|
|
+ ncnn::Mat GetFrames(int32_t frame_index, int32_t n) {
|
|
|
+ std::lock_guard<std::mutex> lock(mutex_);
|
|
|
+ if (frame_index + n > fbank_->NumFramesReady()) {
|
|
|
+ NCNN_LOGE("%d + %d > %d", frame_index, n, fbank_->NumFramesReady());
|
|
|
+ exit(-1);
|
|
|
+ }
|
|
|
+
|
|
|
+ int32_t discard_num = frame_index - last_frame_index_;
|
|
|
+ if (discard_num < 0) {
|
|
|
+ NCNN_LOGE("last_frame_index_: %d, frame_index_: %d", last_frame_index_,
|
|
|
+ frame_index);
|
|
|
exit(-1);
|
|
|
}
|
|
|
- std::lock_guard<std::mutex> lock(mutex_);
|
|
|
+
|
|
|
+ fbank_->Pop(discard_num);
|
|
|
|
|
|
int32_t feature_dim = fbank_->Dim();
|
|
|
ncnn::Mat features;
|
|
@@ -128,6 +134,8 @@ class FeatureExtractor::Impl {
|
|
|
std::copy(f, f + feature_dim, features.row(i));
|
|
|
}
|
|
|
|
|
|
+ last_frame_index_ = frame_index;
|
|
|
+
|
|
|
return features;
|
|
|
}
|
|
|
|
|
@@ -136,6 +144,7 @@ class FeatureExtractor::Impl {
|
|
|
knf::FbankOptions opts_;
|
|
|
mutable std::mutex mutex_;
|
|
|
std::unique_ptr<LinearResample> resampler_;
|
|
|
+ int32_t last_frame_index_ = 0;
|
|
|
};
|
|
|
|
|
|
FeatureExtractor::FeatureExtractor(const FeatureExtractorConfig &config)
|