mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-02-22 06:41:17 +00:00
btstack_cvsd_plc: count zero frames separately
This commit is contained in:
parent
9534a1bb52
commit
1db30a88d0
@ -242,21 +242,45 @@ static int count_equal_samples(BTSTACK_CVSD_PLC_SAMPLE_FORMAT * packet, uint16_t
|
|||||||
return count;
|
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
|
// 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){
|
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;
|
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){
|
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;
|
if (num_samples == 0) return;
|
||||||
|
|
||||||
plc_state->frame_count++;
|
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);
|
memcpy(out, in, num_samples * 2);
|
||||||
if (plc_state->good_samples > CVSD_LHIST){
|
if (plc_state->good_samples > CVSD_LHIST){
|
||||||
btstack_cvsd_plc_bad_frame(plc_state, num_samples, out);
|
btstack_cvsd_plc_bad_frame(plc_state, num_samples, out);
|
||||||
plc_state->bad_frames_nr++;
|
if (is_zero_frame){
|
||||||
|
plc_state->zero_frames_nr++;
|
||||||
|
} else {
|
||||||
|
plc_state->bad_frames_nr++;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
memset(out, 0, num_samples * 2);
|
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){
|
void btstack_cvsd_dump_statistics(btstack_cvsd_plc_state_t * state){
|
||||||
log_info("Good frames: %d\n", state->good_frames_nr);
|
log_info("Good frames: %d\n", state->good_frames_nr);
|
||||||
log_info("Bad frames: %d\n", state->bad_frames_nr);
|
log_info("Bad frames: %d\n", state->bad_frames_nr);
|
||||||
|
log_info("Zero frames: %d\n", state->zero_frames_nr);
|
||||||
}
|
}
|
||||||
|
@ -70,6 +70,7 @@ typedef struct cvsd_plc_state {
|
|||||||
// summary of processed good and bad frames
|
// summary of processed good and bad frames
|
||||||
int good_frames_nr;
|
int good_frames_nr;
|
||||||
int bad_frames_nr;
|
int bad_frames_nr;
|
||||||
|
int zero_frames_nr;
|
||||||
int frame_count;
|
int frame_count;
|
||||||
} btstack_cvsd_plc_state_t;
|
} btstack_cvsd_plc_state_t;
|
||||||
|
|
||||||
|
@ -157,4 +157,6 @@ int main (int argc, const char * argv[]){
|
|||||||
|
|
||||||
wav_writer_close();
|
wav_writer_close();
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
|
btstack_cvsd_dump_statistics(&plc_state);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user