ERIS CORE

◆ update()

void erisAudioAnalyzeScope::update ( void  )
virtual

Implements AudioStream.

Definition at line 52 of file eris_analyze_scope.cpp.

53 {
54  audio_block_t *block;
55  audio_block_t *blockb; //2nd channel (optional)
56  bool isDualChannel;
57 
58  uint32_t offset;
59  uint32_t remain;
60 
61  //capture only if channel 0 is connected
62  block = receiveReadOnly(0);
63  if (!block){
64  blockb = receiveReadOnly(1);
65  if (blockb) release(blockb);
66  return;
67  }
68 
69  blockb = receiveReadOnly(1);
70  if (!blockb) {
71  isDualChannel = false;
72  } else isDualChannel = true;
73 
74  offset = 0;
75  while (offset < AUDIO_BLOCK_SAMPLES) {
76  remain = AUDIO_BLOCK_SAMPLES - offset;
77  switch (state) {
78  case STATE_WAIT_TRIGGER:
79  // TODO: implement this....
80  offset = AUDIO_BLOCK_SAMPLES;
81  break;
82 
83  case STATE_DELAY:
84  //Serial.printf("STATE_DELAY, count = %u\n", count);
85  if (remain < count) {
86  count -= remain;
87  offset = AUDIO_BLOCK_SAMPLES;
88  } else {
89  offset += count;
90  count = mem_length;
91  state = STATE_PRINTING;
92  }
93  break;
94 
95  case STATE_PRINTING:
96  //wait for the zero crossing on ch1
97  if (count == mem_length){
98  dot = 0;
99  dotAvg = 0;
100  dotAvgSlow = 0;
101  dotDelta = 0;
102  dotDeltaMACD = 0;
103  dotAccel = 0;
104  dotMACD = 0;
105  edgeCount = 0;
106  edgeCount_ch2 = 0;
107  peakValue = 0;
108  edgeTimer=0;
109  edgeDelay=0;
110  edgeTimer2=0;
111  edgeDelay2=0;
112 
113  bool found = false;
114  for(int16_t i=1;i < AUDIO_BLOCK_SAMPLES-h_div;i++){
115  if(trigger_wait_count > SCOPE_MAX_TRIGGER_WAIT){
116  //force the trigger
117  found=true;
118  edgeTimer=0;
119  edgeTimer2=0;
120  break;
121  }
122  if (block->data[i] > 0 && block->data[i-1] < 0){
123  offset = i;
124  if(isDualChannel){
125  if (blockb->data[i] > 0 || 1){
126  found = true;
127  }
128  }else found = true;
129  if (found){
130  edgeTimer=0;
131  edgeTimer2=0;
132  break;
133  }
134  }
135  }
136  //skip to the next block
137  if(!found) {offset = AUDIO_BLOCK_SAMPLES;};
138 
139  }
140 
141  while ((offset < AUDIO_BLOCK_SAMPLES) && (count > 0)){
142  edgeTimer++;
143  edgeTimer2++;
144  //for every sample
145  if ((offset >= h_div) && block->data[offset] <= 0 && block->data[offset-h_div] >0){
146  if((edgeCount > 0) && (edgeTimer > 20)){
147  if (edgeDelay==0){edgeDelay = edgeTimer;
148  } else {
150  }
151  }
152  edgeTimer=0;
153  }
154  if (isDualChannel && (offset >= h_div) && blockb->data[offset] <= 0 && blockb->data[offset-h_div] >0){
155  if((edgeCount_ch2 > 0) && (edgeTimer2 > 20)){
156  if (edgeDelay2==0){edgeDelay2 = edgeTimer2;
157  } else {
159  }
160  }
161  edgeTimer2=0;
162  }
163 
164  h_div_count++;
165  //for the captured samples
166  if(h_div_count==h_div){
167  h_div_count=0;
168  count--;
169  _memory[0][mem_length - count - 1 ] = block->data[offset];
170  peakValue = max(peakValue,abs(block->data[offset]));
171  if (isDualChannel){
172  _memory[1][mem_length - count - 1 ] = blockb->data[offset];
173  //peakValue = max(peakValue,abs(blockb->data[offset]));
174  if ((offset >= h_div) && (blockb->data[offset] <= -10 ) && (blockb->data[offset-h_div] > 10)){
175  edgeCount_ch2++;
176  }
177  }else _memory[1][mem_length - count - 1 ] = 0;
178 
179  if ((offset >= h_div) && (block->data[offset] <= -10 ) && (block->data[offset-h_div] > 10)){
180  edgeCount++;
181  }
182  }
183  offset++;
184  }
185 
186 
187  if (count == 0){
188  //Serial.println(edgeCount);
189  //only update the values if data is available
190  if(peakValue >0){
191  if((edgeCount < 8) && (auto_h_div < 16)) auto_h_div++;
192  if((edgeCount > 11) && (auto_h_div > 1)) auto_h_div--;
193  //calculate the dot product if dual channel
194  if (isDualChannel ){
195  q63_t lastDelta;
196  lastDelta= dotDelta;
197  dotLast = dot/1000000;
198  arm_dot_prod_q15(&_memory[0][0],&_memory[1][0],mem_length,&dot);
199  dot = dot /1000000;
200  dotDelta = ((dot) - (dotLast));
201  dotAccel = ((dotDelta)-(lastDelta));
202  dotAvg = (dotAvg/2) + (dot/2);
203  dotAvgSlow = (dotAvg/2) + (dotAvgSlow/2);
204  dotMACD = ((dotAvg) - (dotAvgSlow));
205  //(dotMACD>0)?:dotMACD*=-1;
207  memcpy(&memory[1],&_memory[1],sizeof(_memory[1]));
208  }
209  //buffered outputs
210  memcpy(&memory[0],&_memory[0],sizeof(_memory[0]));
213  dot_output=dot;
224  }
225  isAvailable = true;
226  if (autoTrigger){
227  trigger();
228  }else state = STATE_IDLE;
229  trigger_wait_count = 0;
230  }
231  break;
232 
233  default: // STATE_IDLE
234  offset = AUDIO_BLOCK_SAMPLES;
235  break;
236  }
237  }
238  release(block);
239  if(isDualChannel) release(blockb);
240 }
static void release(audio_block_t *block)
audio_block_t * receiveReadOnly(unsigned int index=0)
volatile uint32_t edgeCount_output
volatile int32_t dotMACD_output
volatile int16_t peakValue_output
volatile q63_t dotLast_output
volatile int32_t dotAvgSlow_output
volatile uint32_t edgeDelay_output
volatile int32_t dotAccel_output
volatile int32_t dotDelta_output
volatile uint32_t edgeDelay2_output
volatile int32_t dotDeltaMACD_output
volatile uint32_t edgeCount_ch2_output
volatile int32_t dotAvg_output
int16_t data[AUDIO_BLOCK_SAMPLES]
Definition: AudioStream.h:78

References auto_h_div, autoTrigger, count, audio_block_struct::data, dot, dot_output, dotAccel, dotAccel_output, dotAvg, dotAvg_output, dotAvgSlow, dotAvgSlow_output, dotDelta, dotDelta_output, dotDeltaMACD, dotDeltaMACD_output, dotLast, dotLast_output, dotMACD, dotMACD_output, edgeCount, edgeCount_ch2, edgeCount_ch2_output, edgeCount_output, edgeDelay, edgeDelay2, edgeDelay2_output, edgeDelay_output, edgeTimer, edgeTimer2, h_div, h_div_count, isAvailable, mem_length, peakValue, peakValue_output, AudioStream::receiveReadOnly(), AudioStream::release(), state, trigger(), and trigger_wait_count.

+ Here is the call graph for this function: