StereoToMono.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: StereoToMonoQ15.h
  4. * Description: Stereo to mno stream in Q15
  5. *
  6. * $Date: 06 August 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 _STEREOTOMONO_H_
  29. #define _STEREOTOMONO_H_
  30. template<typename IN, int inputSize,typename OUT,int outputSize>
  31. class StereoToMono;
  32. template<int inputSize,int outputSize>
  33. class StereoToMono<q15_t,inputSize,q15_t,outputSize>: public GenericNode<q15_t,inputSize,q15_t,outputSize>
  34. {
  35. public:
  36. StereoToMono(FIFOBase<q15_t> &src,FIFOBase<q15_t> &dst):
  37. GenericNode<q15_t,inputSize,q15_t,outputSize>(src,dst){};
  38. int run(){
  39. q15_t *a=this->getReadBuffer();
  40. q15_t *b=this->getWriteBuffer();
  41. for(int i = 0; i<outputSize; i++)
  42. {
  43. b[i] = (a[2*i]>>1) + (a[2*i+1]>>1);
  44. }
  45. return(0);
  46. };
  47. };
  48. template<int inputSize,int outputSize>
  49. class StereoToMono<q31_t,inputSize,q31_t,outputSize>: public GenericNode<q31_t,inputSize,q31_t,outputSize>
  50. {
  51. public:
  52. StereoToMono(FIFOBase<q31_t> &src,FIFOBase<q31_t> &dst):
  53. GenericNode<q31_t,inputSize,q31_t,outputSize>(src,dst){};
  54. int run(){
  55. q31_t *a=this->getReadBuffer();
  56. q31_t *b=this->getWriteBuffer();
  57. for(int i = 0; i<outputSize; i++)
  58. {
  59. b[i] = (a[2*i]>>1) + (a[2*i+1]>>1);
  60. }
  61. return(0);
  62. };
  63. };
  64. template<int inputSize,int outputSize>
  65. class StereoToMono<float32_t,inputSize,float32_t,outputSize>: public GenericNode<float32_t,inputSize,float32_t,outputSize>
  66. {
  67. public:
  68. StereoToMono(FIFOBase<float32_t> &src,FIFOBase<float32_t> &dst):
  69. GenericNode<float32_t,inputSize,float32_t,outputSize>(src,dst){};
  70. int run(){
  71. float32_t *a=this->getReadBuffer();
  72. float32_t *b=this->getWriteBuffer();
  73. for(int i = 0; i<outputSize; i++)
  74. {
  75. b[i] = 0.5f * (a[2*i] + a[2*i+1]);
  76. }
  77. return(0);
  78. };
  79. };
  80. #endif