mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-01-26 12:35:25 +00:00
count good and bad frames in cvsd plc
This commit is contained in:
parent
82e01da097
commit
26463303c9
@ -272,34 +272,6 @@ static void sco_demo_receive_mSBC(uint8_t * packet, uint16_t size){
|
||||
}
|
||||
}
|
||||
|
||||
static int count_equal_bytes(int8_t * packet, uint16_t size){
|
||||
int count = 0;
|
||||
int temp_count = 1;
|
||||
int i;
|
||||
for (i = 0; i < size-1; i++){
|
||||
if (packet[i] == packet[i+1]){
|
||||
temp_count++;
|
||||
continue;
|
||||
}
|
||||
if (count < temp_count){
|
||||
count = temp_count;
|
||||
}
|
||||
temp_count = 1;
|
||||
}
|
||||
if (temp_count > count + 1){
|
||||
count = temp_count;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
static void btstack_cvsd_plc_process_data(btstack_cvsd_plc_state_t * state, int8_t * packet, uint16_t size, int8_t * out){
|
||||
if (count_equal_bytes(packet, size) > size/2){
|
||||
btstack_cvsd_plc_bad_frame(state, out);
|
||||
} else {
|
||||
btstack_cvsd_plc_good_frame(state, packet, out);
|
||||
}
|
||||
}
|
||||
|
||||
static void sco_demo_receive_CVSD(uint8_t * packet, uint16_t size){
|
||||
if (num_samples_to_write){
|
||||
const int num_samples = size - 3;
|
||||
@ -332,7 +304,18 @@ static void sco_demo_receive_CVSD(uint8_t * packet, uint16_t size){
|
||||
#endif
|
||||
#endif
|
||||
|
||||
void sco_demo_close(void){
|
||||
void sco_demo_close(void){
|
||||
#if SCO_DEMO_MODE == SCO_DEMO_MODE_SINE
|
||||
#if defined(SCO_WAV_FILENAME) || defined(SCO_SBC_FILENAME)
|
||||
printf("SCO demo statistics: ");
|
||||
if (negotiated_codec == HFP_CODEC_MSBC){
|
||||
printf("Used mSBC with PLC, number of processed frames: \n - %d good frames, \n - %d zero frames, \n - %d bad frames.", decoder_state.good_frames_nr, decoder_state.zero_frames_nr, decoder_state.bad_frames_nr);
|
||||
} else {
|
||||
printf("Used CVSD with PLC, number of proccesed frames: \n - %d good frames, \n - %d bad frames.", cvsd_plc_state.good_frames_nr, cvsd_plc_state.bad_frames_nr);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if SCO_DEMO_MODE == SCO_DEMO_MODE_SINE
|
||||
#ifdef SCO_WAV_FILENAME
|
||||
|
||||
|
@ -50,6 +50,7 @@
|
||||
#include <math.h>
|
||||
|
||||
#include "btstack_cvsd_plc.h"
|
||||
#include "btstack_debug.h"
|
||||
|
||||
static float rcos[CVSD_OLAL] = {
|
||||
0.99148655,0.96623611,0.92510857,0.86950446,
|
||||
@ -113,9 +114,7 @@ static int8_t crop_to_int8(float val){
|
||||
|
||||
|
||||
void btstack_cvsd_plc_init(btstack_cvsd_plc_state_t *plc_state){
|
||||
plc_state->nbf=0;
|
||||
plc_state->bestlag=0;
|
||||
memset(plc_state->hist, 0, sizeof(plc_state->hist));
|
||||
memset(plc_state, 0, sizeof(btstack_cvsd_plc_state_t));
|
||||
}
|
||||
|
||||
void btstack_cvsd_plc_bad_frame(btstack_cvsd_plc_state_t *plc_state, int8_t *out){
|
||||
@ -196,3 +195,36 @@ void btstack_cvsd_plc_good_frame(btstack_cvsd_plc_state_t *plc_state, int8_t *in
|
||||
}
|
||||
plc_state->nbf=0;
|
||||
}
|
||||
|
||||
static int count_equal_bytes(int8_t * packet, uint16_t size){
|
||||
int count = 0;
|
||||
int temp_count = 1;
|
||||
int i;
|
||||
for (i = 0; i < size-1; i++){
|
||||
if (packet[i] == packet[i+1]){
|
||||
temp_count++;
|
||||
continue;
|
||||
}
|
||||
if (count < temp_count){
|
||||
count = temp_count;
|
||||
}
|
||||
temp_count = 1;
|
||||
}
|
||||
if (temp_count > count + 1){
|
||||
count = temp_count;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
void btstack_cvsd_plc_process_data(btstack_cvsd_plc_state_t * state, int8_t * in, uint16_t size, int8_t * out){
|
||||
if (size != 24){
|
||||
log_error("btstack_cvsd_plc_process_data: audio frame size is incorrect. Expected %d, got %d", CVSD_FS, size);
|
||||
}
|
||||
if (count_equal_bytes(in, size) > size/2){
|
||||
btstack_cvsd_plc_bad_frame(state, out);
|
||||
state->bad_frames_nr++;
|
||||
} else {
|
||||
btstack_cvsd_plc_good_frame(state, in, out);
|
||||
state->good_frames_nr++;
|
||||
}
|
||||
}
|
@ -61,12 +61,17 @@ typedef struct cvsd_plc_state {
|
||||
int8_t hist[CVSD_LHIST+CVSD_FS+CVSD_RT+CVSD_OLAL];
|
||||
int16_t bestlag;
|
||||
int nbf;
|
||||
|
||||
// summary of processed good and bad frames
|
||||
int good_frames_nr;
|
||||
int bad_frames_nr;
|
||||
} btstack_cvsd_plc_state_t;
|
||||
|
||||
void btstack_cvsd_plc_init(btstack_cvsd_plc_state_t *plc_state);
|
||||
void btstack_cvsd_plc_bad_frame(btstack_cvsd_plc_state_t *plc_state, int8_t *out);
|
||||
void btstack_cvsd_plc_good_frame(btstack_cvsd_plc_state_t *plc_state, int8_t *in, int8_t *out);
|
||||
uint8_t * btstack_cvsd_plc_zero_signal_frame(void);
|
||||
void btstack_cvsd_plc_process_data(btstack_cvsd_plc_state_t * state, int8_t * in, uint16_t size, int8_t * out);
|
||||
|
||||
#if defined __cplusplus
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user