add: (*chstats)[ch].avg_peak[(*chstats)[ch].avg_peak_ptr] = value; (*chstats)[ch].avg_peak_ptr = ((*chstats)[ch].avg_peak_ptr == avg_peak_buffer_sz-1)? 0 : (*chstats)[ch].avg_peak_ptr+1; vector<double>::iterator p=(*chstats)[ch].avg_peak.begin(); (*chstats)[ch].avg_peak_val=0; while (p!=(*chstats)[ch].avg_peak.end()) { (*chstats)[ch].avg_peak_val+=*p++;	} (*chstats)[ch].avg_peak_val/=avg_peak_buffer_sz;
context: void ecasv_update_chstats(vector<struct ecasv_channel_stats>* chstats, int ch, double value){  /* 1. in case a new channel is encoutered */  if (static_cast<int>(chstats->size()) <= ch) {    chstats->resize(ch + 1);  }    /* 2. update last_peak and drawn_peak */  (*chstats)[ch].last_peak = value;  if ((*chstats)[ch].last_peak < (*chstats)[ch].drawn_peak) {    (*chstats)[ch].drawn_peak *= ((*chstats)[ch].last_peak / (*chstats)[ch].drawn_peak);  }  else {    (*chstats)[ch].drawn_peak = (*chstats)[ch].last_peak;  }  /* 3. update max_peak */  if (value > (*chstats)[ch].max_peak) {    (*chstats)[ch].max_peak = value;  }  /* 4. update clipped_samples counter */  if (value > ecasv_clipped_threshold_const) {    (*chstats)[ch].clipped_samples++;  }}