+
+ if ((cur_buf[i] & fx2->trigger_mask[fx2->trigger_stage]) == fx2->trigger_value[fx2->trigger_stage]) {
+ /* Match on this trigger stage. */
+ fx2->trigger_buffer[fx2->trigger_stage] = cur_buf[i];
+ fx2->trigger_stage++;
+
+ if (fx2->trigger_stage == NUM_TRIGGER_STAGES || fx2->trigger_mask[fx2->trigger_stage] == 0) {
+ /* Match on all trigger stages, we're done. */
+ trigger_offset = i + 1;
+
+ /*
+ * TODO: Send pre-trigger buffer to session bus.
+ * Tell the frontend we hit the trigger here.
+ */
+ packet.type = SR_DF_TRIGGER;
+ packet.timeoffset = (num_samples + i) * fx2->period_ps;
+ packet.duration = 0;
+ packet.payload = NULL;
+ sr_session_bus(fx2->session_data, &packet);
+
+ /*
+ * Send the samples that triggered it, since we're
+ * skipping past them.
+ */
+ packet.type = SR_DF_LOGIC;
+ packet.timeoffset = (num_samples + i) * fx2->period_ps;
+ packet.duration = fx2->trigger_stage * fx2->period_ps;
+ packet.payload = &logic;
+ logic.length = fx2->trigger_stage;
+ logic.unitsize = 1;
+ logic.data = fx2->trigger_buffer;
+ sr_session_bus(fx2->session_data, &packet);
+
+ fx2->trigger_stage = TRIGGER_FIRED;
+ break;
+ }
+ return;
+ }
+
+ /*
+ * We had a match before, but not in the next sample. However, we may
+ * have a match on this stage in the next bit -- trigger on 0001 will
+ * fail on seeing 00001, so we need to go back to stage 0 -- but at
+ * the next sample from the one that matched originally, which the
+ * counter increment at the end of the loop takes care of.
+ */
+ if (fx2->trigger_stage > 0) {
+ i -= fx2->trigger_stage;
+ if (i < -1)
+ i = -1; /* Oops, went back past this buffer. */
+ /* Reset trigger stage. */
+ fx2->trigger_stage = 0;
+ }