MCPcopy Create free account
hub / github.com/PaulStoffregen/Audio / update

Method update

effect_delay_ext.cpp:42–104  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

40#define MEMBOARD_CS2_PIN 4
41
42void AudioEffectDelayExternal::update(void)
43{
44 audio_block_t *block;
45 uint32_t n, channel, read_offset;
46
47 // grab incoming data and put it into the memory
48 block = receiveReadOnly();
49 if (memory_type >= AUDIO_MEMORY_UNDEFINED) {
50 // ignore input and do nothing if undefined memory type
51 release(block);
52 return;
53 }
54 if (block) {
55 if (head_offset + AUDIO_BLOCK_SAMPLES <= memory_length) {
56 // a single write is enough
57 write(head_offset, AUDIO_BLOCK_SAMPLES, block->data);
58 head_offset += AUDIO_BLOCK_SAMPLES;
59 } else {
60 // write wraps across end-of-memory
61 n = memory_length - head_offset;
62 write(head_offset, n, block->data);
63 head_offset = AUDIO_BLOCK_SAMPLES - n;
64 write(0, head_offset, block->data + n);
65 }
66 release(block);
67 } else {
68 // if no input, store zeros, so later playback will
69 // not be random garbage previously stored in memory
70 if (head_offset + AUDIO_BLOCK_SAMPLES <= memory_length) {
71 zero(head_offset, AUDIO_BLOCK_SAMPLES);
72 head_offset += AUDIO_BLOCK_SAMPLES;
73 } else {
74 n = memory_length - head_offset;
75 zero(head_offset, n);
76 head_offset = AUDIO_BLOCK_SAMPLES - n;
77 zero(0, head_offset);
78 }
79 }
80
81 // transmit the delayed outputs
82 for (channel = 0; channel < 8; channel++) {
83 if (!(activemask & (1<<channel))) continue;
84 block = allocate();
85 if (!block) continue;
86 // compute the delayed location where we read
87 if (delay_length[channel] <= head_offset) {
88 read_offset = head_offset - delay_length[channel];
89 } else {
90 read_offset = memory_length + head_offset - delay_length[channel];
91 }
92 if (read_offset + AUDIO_BLOCK_SAMPLES <= memory_length) {
93 // a single read will do it
94 read(read_offset, AUDIO_BLOCK_SAMPLES, block->data);
95 } else {
96 // read wraps across end-of-memory
97 n = memory_length - read_offset;
98 read(read_offset, n, block->data);
99 read(0, AUDIO_BLOCK_SAMPLES - n, block->data + n);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected