PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

89 行
3.5KB

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