test-online-fbank.cc (1552B)
1 /** 2 * Copyright (c) 2022 Xiaomi Corporation (authors: Fangjun Kuang) 3 * 4 * See LICENSE for clarification regarding multiple authors 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 19 #include <iostream> 20 #include <cstdint> 21 #include <sstream> 22 #include <string> 23 24 #include "kaldi-native-fbank/csrc/online-feature.h" 25 #include "kaldi-native-fbank/csrc/feature-fbank.h" 26 #include "kaldi-native-fbank/csrc/feature-window.h" 27 #include "kaldi-native-fbank/csrc/mel-computations.h" 28 29 int main() { 30 knf::FbankOptions opts; 31 opts.frame_opts.dither = 0; 32 opts.mel_opts.num_bins = 10; 33 34 knf::OnlineFbank fbank(opts); 35 for (int32_t i = 0; i < 1600; ++i) { 36 float s = (i * i - i / 2) / 32767.; 37 fbank.AcceptWaveform(16000, &s, 1); 38 } 39 40 std::ostringstream os; 41 42 int32_t n = fbank.NumFramesReady(); 43 for (int32_t i = 0; i != n; ++i) { 44 const float *frame = fbank.GetFrame(i); 45 for (int32_t k = 0; k != opts.mel_opts.num_bins; ++k) { 46 os << frame[k] << ", "; 47 } 48 os << "\n"; 49 } 50 51 std::cout << os.str() << "\n"; 52 53 return 0; 54 }