AppNodes.h 2.9 KB

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