SlidingBuffer.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: SlidingBuffer.h
  4. * Description: Sliding buffer
  5. *
  6. * $Date: 25 October 2022
  7. * $Revision: V1.10.0
  8. *
  9. * Target Processor: Cortex-M and Cortex-A cores
  10. * -------------------------------------------------------------------- */
  11. /*
  12. * Copyright (C) 2010-2022 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 _SLIDINGBUFFER_H_
  29. #define _SLIDINGBUFFER_H_
  30. template<typename IN,int windowSize, int overlap>
  31. class SlidingBuffer: public GenericNode<IN,windowSize-overlap,IN,windowSize>
  32. {
  33. public:
  34. SlidingBuffer(FIFOBase<IN> &src,FIFOBase<IN> &dst):GenericNode<IN,windowSize-overlap,IN,windowSize>(src,dst)
  35. {
  36. static_assert((windowSize-overlap)>0, "Overlap is too big");
  37. memory.resize(overlap);
  38. };
  39. int prepareForRunning() override
  40. {
  41. if (this->willOverflow() ||
  42. this->willUnderflow()
  43. )
  44. {
  45. return(CG_SKIP_EXECUTION_ID_CODE); // Skip execution
  46. }
  47. return(0);
  48. };
  49. int run(){
  50. IN *a=this->getReadBuffer();
  51. IN *b=this->getWriteBuffer();
  52. memcpy((void*)b,(void*)memory.data(),overlap*sizeof(IN));
  53. memcpy((void*)(b+overlap),(void*)a,(windowSize-overlap)*sizeof(IN));
  54. memcpy((void*)memory.data(),(void*)(b+windowSize-overlap),overlap*sizeof(IN)) ;
  55. return(0);
  56. };
  57. protected:
  58. std::vector<IN> memory;
  59. };
  60. #endif