test-online-fbank.cc 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. #include <iostream>
  19. #include "online-feature.h"
  20. int main() {
  21. knf::FbankOptions opts;
  22. opts.frame_opts.dither = 0;
  23. opts.mel_opts.num_bins = 10;
  24. knf::OnlineFbank fbank(opts);
  25. for (int32_t i = 0; i < 1600; ++i) {
  26. float s = (i * i - i / 2) / 32767.;
  27. fbank.AcceptWaveform(16000, &s, 1);
  28. }
  29. std::ostringstream os;
  30. int32_t n = fbank.NumFramesReady();
  31. for (int32_t i = 0; i != n; ++i) {
  32. const float *frame = fbank.GetFrame(i);
  33. for (int32_t k = 0; k != opts.mel_opts.num_bins; ++k) {
  34. os << frame[k] << ", ";
  35. }
  36. os << "\n";
  37. }
  38. std::cout << os.str() << "\n";
  39. return 0;
  40. }