AppNodes.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: AppNodes.h
  4. * Description: Application nodes for Example 2
  5. *
  6. *
  7. * Target Processor: Cortex-M and Cortex-A cores
  8. * --------------------------------------------------------------------
  9. *
  10. * Copyright (C) 2021-2023 ARM Limited or its affiliates. All rights reserved.
  11. *
  12. * SPDX-License-Identifier: Apache-2.0
  13. *
  14. * Licensed under the Apache License, Version 2.0 (the License); you may
  15. * not use this file except in compliance with the License.
  16. * You may obtain a copy of the License at
  17. *
  18. * www.apache.org/licenses/LICENSE-2.0
  19. *
  20. * Unless required by applicable law or agreed to in writing, software
  21. * distributed under the License is distributed on an AS IS BASIS, WITHOUT
  22. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  23. * See the License for the specific language governing permissions and
  24. * limitations under the License.
  25. */
  26. #ifndef _APPNODES_H_
  27. #define _APPNODES_H_
  28. #include <iostream>
  29. #include "Unzip.h"
  30. #include "SlidingBuffer.h"
  31. template<typename IN, int inputSize>
  32. class TFLite: public GenericSink<IN, inputSize>
  33. {
  34. public:
  35. TFLite(FIFOBase<IN> &src):GenericSink<IN,inputSize>(src){};
  36. int prepareForRunning() override
  37. {
  38. if (this->willUnderflow()
  39. )
  40. {
  41. return(CG_SKIP_EXECUTION_ID_CODE); // Skip execution
  42. }
  43. return(0);
  44. };
  45. int run()
  46. {
  47. IN *b=this->getReadBuffer();
  48. printf("TFLite\n");
  49. for(int i=0;i<inputSize;i++)
  50. {
  51. std::cout << (int)b[i] << std::endl;
  52. }
  53. return(0);
  54. };
  55. };
  56. template<typename OUT,int outputSize>
  57. class StereoSource: GenericSource<OUT,outputSize>
  58. {
  59. public:
  60. StereoSource(FIFOBase<OUT> &dst):GenericSource<OUT,outputSize>(dst),mCounter(0){};
  61. int prepareForRunning() override
  62. {
  63. if (this->willOverflow()
  64. )
  65. {
  66. return(CG_SKIP_EXECUTION_ID_CODE); // Skip execution
  67. }
  68. return(0);
  69. };
  70. int run(){
  71. OUT *b=this->getWriteBuffer();
  72. printf("StereoSource\n");
  73. for(int i=0;i<outputSize;i++)
  74. {
  75. b[i] = (OUT)mCounter++;
  76. }
  77. return(0);
  78. };
  79. int mCounter;
  80. };
  81. template<typename IN, int inputSize,typename OUT,int outputSize>
  82. class MFCC: public GenericNode<IN,inputSize,OUT,outputSize>
  83. {
  84. public:
  85. MFCC(FIFOBase<IN> &src,FIFOBase<OUT> &dst):GenericNode<IN,inputSize,OUT,outputSize>(src,dst){};
  86. int prepareForRunning() override
  87. {
  88. if (this->willOverflow() ||
  89. this->willUnderflow()
  90. )
  91. {
  92. return(CG_SKIP_EXECUTION_ID_CODE); // Skip execution
  93. }
  94. return(0);
  95. };
  96. int run(){
  97. printf("MFCC\n");
  98. IN *a=this->getReadBuffer();
  99. OUT *b=this->getWriteBuffer();
  100. b[0] =(OUT)a[0];
  101. return(0);
  102. };
  103. };
  104. #endif