void THRESHOLD_GATE::analyze(SAMPLE_BUFFER* sbuf) { if (rms_rep == true) avolume_rep = SAMPLE_BUFFER_FUNCTIONS::RMS_volume(*sbuf) / SAMPLE_SPECS::max_amplitude; else avolume_rep = SAMPLE_BUFFER_FUNCTIONS::average_amplitude(*sbuf) / SAMPLE_SPECS::max_amplitude; if (is_opened_rep == false) { if (avolume_rep > openlevel_rep) { open_gate(); ECA_LOG_MSG(ECA_LOGGER::user_objects, "Threshold gate opened (reopen count = " + kvu_numtostr(reopens_left_rep) + ")"); is_opened_rep = true; is_closed_rep = false; } } else if (is_closed_rep == false) { if (avolume_rep < closelevel_rep) { close_gate(); ECA_LOG_MSG(ECA_LOGGER::user_objects, "Threshold gate closed (reopens left = " + kvu_numtostr(reopens_left_rep) + ")"); is_closed_rep = true; if (reopens_left_rep != 0) { is_opened_rep = false; if (reopens_left_rep > 0) --reopens_left_rep; } else { // - Could we stop the engine and exit here, maybe? -AL/2008-Jul // - Not from a chain operator, but the audio object // that writes the stream to a file could in // theory react in a special way to the 0-length // samplebuffers we generate when the gate is closed... -KV/2008-Jul } } } }
void TIME_CROP_GATE::analyze(SAMPLE_BUFFER* sbuf) { parameter_t etime = begtime_rep + durtime_rep; parameter_t curtime = static_cast<parameter_t>(position_in_samples_rep) / samples_per_second(); if (curtime >= begtime_rep) { /* note: handle the special case where a zero open time * has been requested */ if (begtime_rep == etime) open_gate(); else if (curtime < etime) open_gate(); else close_gate(); } else close_gate(); position_in_samples_rep += sbuf->length_in_samples(); }
void MANUAL_GATE::analyze(SAMPLE_BUFFER* sbuf) { if (is_open() == true && open_rep != true) { close_gate(); ECA_LOG_MSG(ECA_LOGGER::user_objects, "Manual gate closed"); } else if (is_open() != true && open_rep == true) { open_gate(); ECA_LOG_MSG(ECA_LOGGER::user_objects, "Manual gate opened"); } }
// get ball behaviour, should only occur at hopper approach void get_ball() { Layer& get = layers[LAYER_GET]; if (!get.active) return; if (LAYER_GET == active_layer) { SERIAL_PRINT(layers[LAYER_GET].speed); SERIAL_PRINT('|'); SERIAL_PRINTLN(layers[LAYER_GET].angle); } // either going forward or backward, always no angle // go forward until ball is detected or arbitrary additional distance travelled if (ball_status < CAUGHT_BALL) { if (caught_ball()) ++ball_status; get.speed = GET_SPEED; if (abs(boundaries[active_hopper].theta) < THETA_TOLERANCE) get.angle = 0; // turn slightly to face hopper else if (boundaries[active_hopper].theta < 0) get.angle = -GET_TURN; else get.angle = GET_TURN; if (ball_status == CAUGHT_BALL) { // got to the ball, can also correct for position to be near hopper correct_to_hopper(); // then close servo gate close_gate(); hard_break(LAYER_GET); get_initial_distance = tot_distance; } } // after securing ball, drive backwards else if (ball_status == SECURED_BALL) { // initial kick to go straight static int kick_cycle = 0; if (get.speed > -GET_SPEED) {get.angle = 13; } else if (get.angle > 0) { if (kick_cycle <= 0) { if (get.angle < 7) kick_cycle = 7 - get.angle; --get.angle; } else --kick_cycle; } get.speed = -GET_SPEED; // get.angle = 0; if (paused) resume_drive(LAYER_GET); // back up until you hit a line to correct position if (on_line(CENTER)) { corrected_while_backing_up = true; correct_to_grid(); SERIAL_PRINTLN("CWB"); } // backed up far enough if (tot_distance - get_initial_distance > 5*GET_DISTANCE) { // corrected_while_backing_up && // after getting ball, return to rendezvous point corrected_while_backing_up = false; layers[LAYER_GET].active = false; close_hoppers(); return_from_hopper(); // hard_break(LAYER_GET, 3); } } // in the middle of closing the gate, wait a couple cycles else { ++ball_status; } }