Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

effect_delay_ext.h 3.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. #ifndef effect_delay_ext_h_
  27. #define effect_delay_ext_h_
  28. #include "AudioStream.h"
  29. #include "spi_interrupt.h"
  30. enum AudioEffectDelayMemoryType_t {
  31. AUDIO_MEMORY_23LC1024 = 0,
  32. AUDIO_MEMORY_MEMORYBOARD = 1,
  33. AUDIO_MEMORY_UNDEFINED = 2
  34. };
  35. class AudioEffectDelayExternal : public AudioStream
  36. {
  37. public:
  38. AudioEffectDelayExternal() : AudioStream(1, inputQueueArray) {
  39. initialize(AUDIO_MEMORY_23LC1024, 65536);
  40. }
  41. AudioEffectDelayExternal(AudioEffectDelayMemoryType_t type, float milliseconds=1e6)
  42. : AudioStream(1, inputQueueArray) {
  43. uint32_t n = (milliseconds*(AUDIO_SAMPLE_RATE_EXACT/1000.0f))+0.5f;
  44. initialize(type, n);
  45. }
  46. void delay(uint8_t channel, float milliseconds) {
  47. if (channel >= 8 || memory_type >= AUDIO_MEMORY_UNDEFINED) return;
  48. if (milliseconds < 0.0) milliseconds = 0.0;
  49. uint32_t n = (milliseconds*(AUDIO_SAMPLE_RATE_EXACT/1000.0f))+0.5f;
  50. n += AUDIO_BLOCK_SAMPLES;
  51. if (n > memory_length - AUDIO_BLOCK_SAMPLES)
  52. n = memory_length - AUDIO_BLOCK_SAMPLES;
  53. delay_length[channel] = n;
  54. uint8_t mask = activemask;
  55. if (activemask == 0) AudioStartUsingSPI();
  56. activemask = mask | (1<<channel);
  57. }
  58. void disable(uint8_t channel) {
  59. if (channel >= 8) return;
  60. uint8_t mask = activemask & ~(1<<channel);
  61. activemask = mask;
  62. if (mask == 0) AudioStopUsingSPI();
  63. }
  64. virtual void update(void);
  65. private:
  66. void initialize(AudioEffectDelayMemoryType_t type, uint32_t samples);
  67. void read(uint32_t address, uint32_t count, int16_t *data);
  68. void write(uint32_t address, uint32_t count, const int16_t *data);
  69. void zero(uint32_t address, uint32_t count) {
  70. write(address, count, NULL);
  71. }
  72. uint32_t memory_begin; // the first address in the memory we're using
  73. uint32_t memory_length; // the amount of memory we're using
  74. uint32_t head_offset; // head index (incoming) data into external memory
  75. uint32_t delay_length[8]; // # of sample delay for each channel (128 = no delay)
  76. uint8_t activemask; // which output channels are active
  77. uint8_t memory_type; // 0=23LC1024, 1=Frank's Memoryboard
  78. static uint32_t allocated[2];
  79. audio_block_t *inputQueueArray[1];
  80. };
  81. #endif