|
-
-
- #ifndef effect_delay_ext_h_
- #define effect_delay_ext_h_
- #include "AudioStream.h"
- #include "spi_interrupt.h"
-
- enum AudioEffectDelayMemoryType_t {
- AUDIO_MEMORY_23LC1024 = 0,
- AUDIO_MEMORY_MEMORYBOARD = 1,
- AUDIO_MEMORY_UNDEFINED = 2
- };
-
- class AudioEffectDelayExternal : public AudioStream
- {
- public:
- AudioEffectDelayExternal() : AudioStream(1, inputQueueArray) {
- initialize(AUDIO_MEMORY_23LC1024, 65536);
- }
- AudioEffectDelayExternal(AudioEffectDelayMemoryType_t type, float milliseconds=1e6)
- : AudioStream(1, inputQueueArray) {
- uint32_t n = (milliseconds*(AUDIO_SAMPLE_RATE_EXACT/1000.0f))+0.5f;
- initialize(type, n);
- }
-
- void delay(uint8_t channel, float milliseconds) {
- if (channel >= 8 || memory_type >= AUDIO_MEMORY_UNDEFINED) return;
- if (milliseconds < 0.0) milliseconds = 0.0;
- uint32_t n = (milliseconds*(AUDIO_SAMPLE_RATE_EXACT/1000.0f))+0.5f;
- n += AUDIO_BLOCK_SAMPLES;
- if (n > memory_length - AUDIO_BLOCK_SAMPLES)
- n = memory_length - AUDIO_BLOCK_SAMPLES;
- delay_length[channel] = n;
- uint8_t mask = activemask;
- if (activemask == 0) AudioStartUsingSPI();
- activemask = mask | (1<<channel);
- }
- void disable(uint8_t channel) {
- if (channel >= 8) return;
- uint8_t mask = activemask & ~(1<<channel);
- activemask = mask;
- if (mask == 0) AudioStopUsingSPI();
- }
- virtual void update(void);
- private:
- void initialize(AudioEffectDelayMemoryType_t type, uint32_t samples);
- void read(uint32_t address, uint32_t count, int16_t *data);
- void write(uint32_t address, uint32_t count, const int16_t *data);
- void zero(uint32_t address, uint32_t count) {
- write(address, count, NULL);
- }
- uint32_t memory_begin;
- uint32_t memory_length;
- uint32_t head_offset;
- uint32_t delay_length[8];
- uint8_t activemask;
- uint8_t memory_type;
- static uint32_t allocated[2];
- audio_block_t *inputQueueArray[1];
- };
-
- #endif
|