You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

90 lines
3.0KB

  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. #if defined(KINETISK)
  30. audio_block_t *blocka, *blockb;
  31. uint32_t *pa, *pb, *end;
  32. uint32_t a12, a34; //, a56, a78;
  33. uint32_t b12, b34; //, b56, b78;
  34. blocka = receiveWritable(0);
  35. blockb = receiveReadOnly(1);
  36. if (!blocka) {
  37. if (blockb) release(blockb);
  38. return;
  39. }
  40. if (!blockb) {
  41. release(blocka);
  42. return;
  43. }
  44. pa = (uint32_t *)(blocka->data);
  45. pb = (uint32_t *)(blockb->data);
  46. end = pa + AUDIO_BLOCK_SAMPLES/2;
  47. while (pa < end) {
  48. a12 = *pa;
  49. a34 = *(pa+1);
  50. //a56 = *(pa+2); // 8 samples/loop should work, but crashes.
  51. //a78 = *(pa+3); // why?! maybe a compiler bug??
  52. b12 = *pb++;
  53. b34 = *pb++;
  54. //b56 = *pb++;
  55. //b78 = *pb++;
  56. a12 = pack_16b_16b(
  57. signed_saturate_rshift(multiply_16tx16t(a12, b12), 16, 15),
  58. signed_saturate_rshift(multiply_16bx16b(a12, b12), 16, 15));
  59. a34 = pack_16b_16b(
  60. signed_saturate_rshift(multiply_16tx16t(a34, b34), 16, 15),
  61. signed_saturate_rshift(multiply_16bx16b(a34, b34), 16, 15));
  62. //a56 = pack_16b_16b(
  63. // signed_saturate_rshift(multiply_16tx16t(a56, b56), 16, 15),
  64. // signed_saturate_rshift(multiply_16bx16b(a56, b56), 16, 15));
  65. //a78 = pack_16b_16b(
  66. // signed_saturate_rshift(multiply_16tx16t(a78, b78), 16, 15),
  67. // signed_saturate_rshift(multiply_16bx16b(a78, b78), 16, 15));
  68. *pa++ = a12;
  69. *pa++ = a34;
  70. //*pa++ = a56;
  71. //*pa++ = a78;
  72. }
  73. transmit(blocka);
  74. release(blocka);
  75. release(blockb);
  76. #elif defined(KINETISL)
  77. audio_block_t *block;
  78. block = receiveReadOnly(0);
  79. if (block) release(block);
  80. block = receiveReadOnly(1);
  81. if (block) release(block);
  82. #endif
  83. }