Unzip.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: Unzip.h
  4. * Description: Node to unzip a stream of pair
  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 _UNZIP_H_
  27. #define _UNZIP_H_
  28. /*
  29. Unzip a stream a1 a2 b1 b2 c1 c2 ...
  30. Into 2 streams:
  31. a1 b1 c1 ...
  32. a2 b2 c2 ...
  33. */
  34. template<typename IN, int inputSize,typename OUT1,int output1Size,typename OUT2,int output2Size>
  35. class Unzip;
  36. template<typename IN, int inputSize,int output1Size,int output2Size>
  37. class Unzip<IN,inputSize,IN,output1Size,IN,output2Size>: public GenericNode12<IN,inputSize,IN,output1Size,IN,output2Size>
  38. {
  39. public:
  40. Unzip(FIFOBase<IN> &src,FIFOBase<IN> &dst1,FIFOBase<IN> &dst2):
  41. GenericNode12<IN,inputSize,IN,output1Size,IN,output2Size>(src,dst1,dst2){};
  42. int prepareForRunning() final
  43. {
  44. if (this->willOverflow1() ||
  45. this->willOverflow2() ||
  46. this->willUnderflow()
  47. )
  48. {
  49. return(CG_SKIP_EXECUTION_ID_CODE); // Skip execution
  50. }
  51. return(0);
  52. };
  53. /*
  54. 2*outputSize1 == 2*outSize2 == inputSize
  55. */
  56. int run() final
  57. {
  58. IN *a=this->getReadBuffer();
  59. IN *b1=this->getWriteBuffer1();
  60. IN *b2=this->getWriteBuffer2();
  61. for(int i = 0; i<output1Size; i++)
  62. {
  63. b1[i] =(IN)a[2*i];
  64. b2[i] =(IN)a[2*i+1];
  65. }
  66. return(0);
  67. };
  68. };
  69. #endif