btstack_cvsd_plc: count zero frames separately

This commit is contained in:
Matthias Ringwald 2018-12-17 23:19:03 +01:00
parent 9534a1bb52
commit 1db30a88d0
3 changed files with 30 additions and 2 deletions

View File

@ -242,21 +242,45 @@ static int count_equal_samples(BTSTACK_CVSD_PLC_SAMPLE_FORMAT * packet, uint16_t
return count;
}
static int count_zeros(BTSTACK_CVSD_PLC_SAMPLE_FORMAT * frame, uint16_t size){
int nr_zeros = 0;
int i;
for (i = 0; i < size-1; i++){
if (frame[i] == 0){
nr_zeros++;
}
}
return nr_zeros;
}
// note: a zero_frame is currently also a 'bad_frame'
static int zero_frame(BTSTACK_CVSD_PLC_SAMPLE_FORMAT * frame, uint16_t size){
return count_zeros(frame, size) > (size/2);
}
// more than half the samples are the same -> bad frame
static int bad_frame(btstack_cvsd_plc_state_t *plc_state, BTSTACK_CVSD_PLC_SAMPLE_FORMAT * frame, uint16_t size){
return count_equal_samples(frame, size) > size / 2;
}
void btstack_cvsd_plc_process_data(btstack_cvsd_plc_state_t * plc_state, BTSTACK_CVSD_PLC_SAMPLE_FORMAT * in, uint16_t num_samples, BTSTACK_CVSD_PLC_SAMPLE_FORMAT * out){
if (num_samples == 0) return;
plc_state->frame_count++;
if (bad_frame(plc_state, in, num_samples)){
int is_zero_frame = zero_frame(in, num_samples);
int is_bad_frame = bad_frame(plc_state, in, num_samples);
if (is_bad_frame){
memcpy(out, in, num_samples * 2);
if (plc_state->good_samples > CVSD_LHIST){
btstack_cvsd_plc_bad_frame(plc_state, num_samples, out);
if (is_zero_frame){
plc_state->zero_frames_nr++;
} else {
plc_state->bad_frames_nr++;
}
} else {
memset(out, 0, num_samples * 2);
}
@ -273,4 +297,5 @@ void btstack_cvsd_plc_process_data(btstack_cvsd_plc_state_t * plc_state, BTSTACK
void btstack_cvsd_dump_statistics(btstack_cvsd_plc_state_t * state){
log_info("Good frames: %d\n", state->good_frames_nr);
log_info("Bad frames: %d\n", state->bad_frames_nr);
log_info("Zero frames: %d\n", state->zero_frames_nr);
}

View File

@ -70,6 +70,7 @@ typedef struct cvsd_plc_state {
// summary of processed good and bad frames
int good_frames_nr;
int bad_frames_nr;
int zero_frames_nr;
int frame_count;
} btstack_cvsd_plc_state_t;

View File

@ -157,4 +157,6 @@ int main (int argc, const char * argv[]){
wav_writer_close();
close(fd);
btstack_cvsd_dump_statistics(&plc_state);
}