You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_spectrogram.cpp 2.0 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // Tencent is pleased to support the open source community by making ncnn available.
  2. //
  3. // Copyright (C) 2024 THL A29 Limited, a Tencent company. All rights reserved.
  4. //
  5. // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
  6. // in compliance with the License. You may obtain a copy of the License at
  7. //
  8. // https://opensource.org/licenses/BSD-3-Clause
  9. //
  10. // Unless required by applicable law or agreed to in writing, software distributed
  11. // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
  12. // CONDITIONS OF ANY KIND, either express or implied. See the License for the
  13. // specific language governing permissions and limitations under the License.
  14. #include "testutil.h"
  15. static int test_spectrogram(int size, int n_fft, int power, int hoplen, int winlen, int window_type, int center, int pad_type, int normalized, int onesided)
  16. {
  17. ncnn::Mat a = RandomMat(size);
  18. ncnn::ParamDict pd;
  19. pd.set(0, n_fft);
  20. pd.set(1, power);
  21. pd.set(2, hoplen);
  22. pd.set(3, winlen);
  23. pd.set(4, window_type);
  24. pd.set(5, center);
  25. pd.set(6, pad_type);
  26. pd.set(7, normalized);
  27. pd.set(8, onesided);
  28. std::vector<ncnn::Mat> weights(0);
  29. int ret = test_layer("Spectrogram", pd, weights, a);
  30. if (ret != 0)
  31. {
  32. fprintf(stderr, "test_spectrogram failed size=%d n_fft=%d power=%d hoplen=%d winlen=%d window_type=%d center=%d pad_type=%d normalized=%d onesided=%d\n", size, n_fft, power, hoplen, winlen, window_type, center, pad_type, normalized, onesided);
  33. }
  34. return ret;
  35. }
  36. static int test_spectrogram_0()
  37. {
  38. return 0
  39. || test_spectrogram(17, 1, 0, 1, 1, 0, 1, 0, 0, 0)
  40. || test_spectrogram(39, 17, 0, 7, 15, 0, 0, 0, 1, 0)
  41. || test_spectrogram(128, 10, 0, 2, 7, 1, 1, 1, 1, 1)
  42. || test_spectrogram(255, 17, 1, 14, 17, 2, 0, 0, 0, 1)
  43. || test_spectrogram(124, 55, 2, 12, 55, 1, 1, 2, 2, 0);
  44. }
  45. int main()
  46. {
  47. SRAND(7767517);
  48. return test_spectrogram_0();
  49. }