Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

effect_multiply.cpp 2.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /* Audio Library for Teensy 3.X
  2. * Copyright (c) 2014, Paul Stoffregen, paul@pjrc.com
  3. *
  4. * Development of this audio library was funded by PJRC.COM, LLC by sales of
  5. * Teensy and Audio Adaptor boards. Please support PJRC's efforts to develop
  6. * open source software by purchasing Teensy or other PJRC products.
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a copy
  9. * of this software and associated documentation files (the "Software"), to deal
  10. * in the Software without restriction, including without limitation the rights
  11. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  12. * copies of the Software, and to permit persons to whom the Software is
  13. * furnished to do so, subject to the following conditions:
  14. *
  15. * The above copyright notice, development funding notice, and this permission
  16. * notice shall be included in all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  21. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  23. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  24. * THE SOFTWARE.
  25. */
  26. #include "effect_multiply.h"
  27. void AudioEffectMultiply::update(void)
  28. {
  29. audio_block_t *blocka, *blockb;
  30. uint32_t *pa, *pb, *end;
  31. uint32_t a12, a34; //, a56, a78;
  32. uint32_t b12, b34; //, b56, b78;
  33. blocka = receiveWritable(0);
  34. blockb = receiveReadOnly(1);
  35. if (!blocka) {
  36. if (blockb) release(blockb);
  37. return;
  38. }
  39. if (!blockb) {
  40. release(blocka);
  41. return;
  42. }
  43. pa = (uint32_t *)(blocka->data);
  44. pb = (uint32_t *)(blockb->data);
  45. end = pa + AUDIO_BLOCK_SAMPLES/2;
  46. while (pa < end) {
  47. a12 = *pa;
  48. a34 = *(pa+1);
  49. //a56 = *(pa+2); // 8 samples/loop should work, but crashes.
  50. //a78 = *(pa+3); // why?! maybe a compiler bug??
  51. b12 = *pb++;
  52. b34 = *pb++;
  53. //b56 = *pb++;
  54. //b78 = *pb++;
  55. a12 = pack_16b_16b(
  56. signed_saturate_rshift(multiply_16tx16t(a12, b12), 16, 15),
  57. signed_saturate_rshift(multiply_16bx16b(a12, b12), 16, 15));
  58. a34 = pack_16b_16b(
  59. signed_saturate_rshift(multiply_16tx16t(a34, b34), 16, 15),
  60. signed_saturate_rshift(multiply_16bx16b(a34, b34), 16, 15));
  61. //a56 = pack_16b_16b(
  62. // signed_saturate_rshift(multiply_16tx16t(a56, b56), 16, 15),
  63. // signed_saturate_rshift(multiply_16bx16b(a56, b56), 16, 15));
  64. //a78 = pack_16b_16b(
  65. // signed_saturate_rshift(multiply_16tx16t(a78, b78), 16, 15),
  66. // signed_saturate_rshift(multiply_16bx16b(a78, b78), 16, 15));
  67. *pa++ = a12;
  68. *pa++ = a34;
  69. //*pa++ = a56;
  70. //*pa++ = a78;
  71. }
  72. transmit(blocka);
  73. release(blocka);
  74. release(blockb);
  75. }