SlidingBuffer.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: SlidingBuffer.h
  4. * Description: Sliding buffer
  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 _SLIDINGBUFFER_H_
  27. #define _SLIDINGBUFFER_H_
  28. template<typename IN,int windowSize, int overlap>
  29. class SlidingBuffer: public GenericNode<IN,windowSize-overlap,IN,windowSize>
  30. {
  31. public:
  32. SlidingBuffer(FIFOBase<IN> &src,FIFOBase<IN> &dst):GenericNode<IN,windowSize-overlap,IN,windowSize>(src,dst)
  33. {
  34. static_assert((windowSize-overlap)>0, "Overlap is too big");
  35. memory.resize(overlap);
  36. };
  37. int prepareForRunning() final
  38. {
  39. if (this->willOverflow() ||
  40. this->willUnderflow()
  41. )
  42. {
  43. return(CG_SKIP_EXECUTION_ID_CODE); // Skip execution
  44. }
  45. return(0);
  46. };
  47. int run() final
  48. {
  49. IN *a=this->getReadBuffer();
  50. IN *b=this->getWriteBuffer();
  51. memcpy((void*)b,(void*)memory.data(),overlap*sizeof(IN));
  52. memcpy((void*)(b+overlap),(void*)a,(windowSize-overlap)*sizeof(IN));
  53. memcpy((void*)memory.data(),(void*)(b+windowSize-overlap),overlap*sizeof(IN)) ;
  54. return(0);
  55. };
  56. protected:
  57. std::vector<IN> memory;
  58. };
  59. #endif