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

Method update

effect_delay.cpp:29–133  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

27#include "effect_delay.h"
28
29void AudioEffectDelay::update(void)
30{
31 audio_block_t *output;
32 uint32_t head, tail, count, channel, index, prev, offset;
33 const int16_t *src, *end;
34 int16_t *dst;
35
36 // grab incoming data and put it into the queue
37 head = headindex;
38 tail = tailindex;
39 if (++head >= DELAY_QUEUE_SIZE) head = 0;
40 if (head == tail) {
41 release(queue[tail]);
42 if (++tail >= DELAY_QUEUE_SIZE) tail = 0;
43 }
44 queue[head] = receiveReadOnly();
45 headindex = head;
46
47 // testing only.... don't allow null pointers into the queue
48 // instead, fill the empty times with blocks of zeros
49 //if (queue[head] == NULL) {
50 // queue[head] = allocate();
51 // if (queue[head]) {
52 // dst = queue[head]->data;
53 // end = dst + AUDIO_BLOCK_SAMPLES;
54 // do {
55 // *dst++ = 0;
56 // } while (dst < end);
57 // } else {
58 // digitalWriteFast(2, HIGH);
59 // delayMicroseconds(5);
60 // digitalWriteFast(2, LOW);
61 // }
62 //}
63
64 // discard unneeded blocks from the queue
65 if (head >= tail) {
66 count = head - tail;
67 } else {
68 count = DELAY_QUEUE_SIZE + head - tail;
69 }
70 if (count > maxblocks) {
71 count -= maxblocks;
72 do {
73 release(queue[tail]);
74 queue[tail] = NULL;
75 if (++tail >= DELAY_QUEUE_SIZE) tail = 0;
76 } while (--count > 0);
77 }
78 tailindex = tail;
79
80 // transmit the delayed outputs using queue data
81 for (channel = 0; channel < 8; channel++) {
82 if (!(activemask & (1<<channel))) continue;
83 index = position[channel] / AUDIO_BLOCK_SAMPLES;
84 offset = position[channel] % AUDIO_BLOCK_SAMPLES;
85 if (head >= index) {
86 index = head - index;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected