mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-01-18 19:21:54 +00:00
sbc_decoder: prefix with btstack
This commit is contained in:
parent
6e046a3674
commit
2afeea7f2e
@ -128,7 +128,7 @@ static const int16_t sine_int16[] = {
|
||||
static int num_samples_to_write;
|
||||
static wav_writer_state_t wav_writer_state;
|
||||
|
||||
static sbc_decoder_state_t decoder_state;
|
||||
static btstack_sbc_decoder_state_t decoder_state;
|
||||
|
||||
static void little_endian_fstore_16(FILE * file, uint16_t value){
|
||||
uint8_t buf[2];
|
||||
@ -221,7 +221,7 @@ static void sco_demo_init_mSBC(void){
|
||||
wav_writer_state.frame_count = 0;
|
||||
wav_writer_state.total_num_samples = 0;
|
||||
|
||||
sbc_decoder_init(&decoder_state, SBC_MODE_mSBC, &handle_pcm_data, (void*)&wav_writer_state);
|
||||
btstack_sbc_decoder_init(&decoder_state, SBC_MODE_mSBC, &handle_pcm_data, (void*)&wav_writer_state);
|
||||
|
||||
const int sample_rate = 16000;
|
||||
const int num_samples = sample_rate * SCO_WAV_DURATION_IN_SECONDS;
|
||||
@ -264,7 +264,7 @@ static void sco_demo_init_CVSD(void){
|
||||
|
||||
static void sco_demo_receive_mSBC(uint8_t * packet, uint16_t size){
|
||||
if (num_samples_to_write){
|
||||
sbc_decoder_process_data(&decoder_state, (packet[1] >> 4) & 3, packet+3, size-3);
|
||||
btstack_sbc_decoder_process_data(&decoder_state, (packet[1] >> 4) & 3, packet+3, size-3);
|
||||
dump_data = 0;
|
||||
}
|
||||
}
|
||||
@ -302,7 +302,7 @@ void sco_demo_close(void){
|
||||
wav_writer_state_t * writer_state = &wav_writer_state;
|
||||
if (!writer_state->wav_file) return;
|
||||
rewind(writer_state->wav_file);
|
||||
write_wav_header(writer_state->wav_file, writer_state->total_num_samples, sbc_decoder_num_channels(&decoder_state), sbc_decoder_sample_rate(&decoder_state),2);
|
||||
write_wav_header(writer_state->wav_file, writer_state->total_num_samples, btstack_sbc_decoder_num_channels(&decoder_state), btstack_sbc_decoder_sample_rate(&decoder_state),2);
|
||||
fclose(writer_state->wav_file);
|
||||
writer_state->wav_file = NULL;
|
||||
}
|
||||
|
@ -63,7 +63,7 @@ typedef struct {
|
||||
int good_frames_nr;
|
||||
int bad_frames_nr;
|
||||
int zero_frames_nr;
|
||||
} sbc_decoder_state_t;
|
||||
} btstack_sbc_decoder_state_t;
|
||||
|
||||
/* API_START */
|
||||
|
||||
@ -75,7 +75,7 @@ typedef struct {
|
||||
* @param context provided in callback
|
||||
*/
|
||||
|
||||
void sbc_decoder_init(sbc_decoder_state_t * state, sbc_mode_t mode, void (*callback)(int16_t * data, int num_samples, int num_channels, int sample_rate, void * context), void * context);
|
||||
void btstack_sbc_decoder_init(btstack_sbc_decoder_state_t * state, sbc_mode_t mode, void (*callback)(int16_t * data, int num_samples, int num_channels, int sample_rate, void * context), void * context);
|
||||
|
||||
/**
|
||||
* @brief Process received SCO data
|
||||
@ -84,28 +84,28 @@ void sbc_decoder_init(sbc_decoder_state_t * state, sbc_mode_t mode, void (*callb
|
||||
* @param buffer
|
||||
* @param size
|
||||
*/
|
||||
void sbc_decoder_process_data(sbc_decoder_state_t * state, int packet_status_flag, uint8_t * buffer, int size);
|
||||
void btstack_sbc_decoder_process_data(btstack_sbc_decoder_state_t * state, int packet_status_flag, uint8_t * buffer, int size);
|
||||
|
||||
/**
|
||||
* @brief Get number of samples per SBC frame
|
||||
*/
|
||||
int sbc_decoder_num_samples_per_frame(sbc_decoder_state_t * state);
|
||||
int btstack_sbc_decoder_num_samples_per_frame(btstack_sbc_decoder_state_t * state);
|
||||
|
||||
/*
|
||||
* @brief Get number of channels
|
||||
*/
|
||||
int sbc_decoder_num_channels(sbc_decoder_state_t * state);
|
||||
int btstack_sbc_decoder_num_channels(btstack_sbc_decoder_state_t * state);
|
||||
|
||||
/*
|
||||
* @brief Get sample rate in hz
|
||||
*/
|
||||
int sbc_decoder_sample_rate(sbc_decoder_state_t * state);
|
||||
int btstack_sbc_decoder_sample_rate(btstack_sbc_decoder_state_t * state);
|
||||
|
||||
/* API_END */
|
||||
|
||||
// testing only
|
||||
void sbc_decoder_test_disable_plc(void);
|
||||
void sbc_decoder_test_simulate_corrupt_frames(int period);
|
||||
void btstack_sbc_decoder_test_disable_plc(void);
|
||||
void btstack_sbc_decoder_test_simulate_corrupt_frames(int period);
|
||||
|
||||
#if defined __cplusplus
|
||||
}
|
||||
|
@ -87,14 +87,14 @@ typedef struct {
|
||||
} bludroid_decoder_state_t;
|
||||
|
||||
|
||||
static sbc_decoder_state_t * sbc_state_singelton = NULL;
|
||||
static btstack_sbc_decoder_state_t * sbc_state_singelton = NULL;
|
||||
static bludroid_decoder_state_t bd_state;
|
||||
|
||||
void sbc_decoder_test_disable_plc(void){
|
||||
void btstack_sbc_decoder_test_disable_plc(void){
|
||||
plc_enabled = 0;
|
||||
}
|
||||
|
||||
void sbc_decoder_test_simulate_corrupt_frames(int period){
|
||||
void btstack_sbc_decoder_test_simulate_corrupt_frames(int period){
|
||||
corrupt_frame_period = period;
|
||||
}
|
||||
|
||||
@ -139,17 +139,17 @@ static int find_h2_syncword(const OI_BYTE *frame_data, OI_UINT32 frame_bytes, sb
|
||||
return ((hn & 0x04) >> 1) | (hn & 0x01);
|
||||
}
|
||||
|
||||
int sbc_decoder_num_samples_per_frame(sbc_decoder_state_t * state){
|
||||
int btstack_sbc_decoder_num_samples_per_frame(btstack_sbc_decoder_state_t * state){
|
||||
bludroid_decoder_state_t * decoder_state = (bludroid_decoder_state_t *) state->decoder_state;
|
||||
return decoder_state->decoder_context.common.frameInfo.nrof_blocks * decoder_state->decoder_context.common.frameInfo.nrof_subbands;
|
||||
}
|
||||
|
||||
int sbc_decoder_num_channels(sbc_decoder_state_t * state){
|
||||
int btstack_sbc_decoder_num_channels(btstack_sbc_decoder_state_t * state){
|
||||
bludroid_decoder_state_t * decoder_state = (bludroid_decoder_state_t *) state->decoder_state;
|
||||
return decoder_state->decoder_context.common.frameInfo.nrof_channels;
|
||||
}
|
||||
|
||||
int sbc_decoder_sample_rate(sbc_decoder_state_t * state){
|
||||
int btstack_sbc_decoder_sample_rate(btstack_sbc_decoder_state_t * state){
|
||||
bludroid_decoder_state_t * decoder_state = (bludroid_decoder_state_t *) state->decoder_state;
|
||||
return decoder_state->decoder_context.common.frameInfo.frequency;
|
||||
}
|
||||
@ -159,7 +159,7 @@ void OI_AssertFail(char* file, int line, char* reason){
|
||||
printf("AssertFail file %s, line %d, reason %s\n", file, line, reason);
|
||||
}
|
||||
|
||||
void sbc_decoder_init(sbc_decoder_state_t * state, sbc_mode_t mode, void (*callback)(int16_t * data, int num_samples, int num_channels, int sample_rate, void * context), void * context){
|
||||
void btstack_sbc_decoder_init(btstack_sbc_decoder_state_t * state, sbc_mode_t mode, void (*callback)(int16_t * data, int num_samples, int num_channels, int sample_rate, void * context), void * context){
|
||||
if (sbc_state_singelton && sbc_state_singelton != state ){
|
||||
log_error("SBC decoder: different sbc decoder state is allready registered");
|
||||
}
|
||||
@ -189,7 +189,7 @@ void sbc_decoder_init(sbc_decoder_state_t * state, sbc_mode_t mode, void (*callb
|
||||
}
|
||||
bd_state.first_good_frame_found = 0;
|
||||
|
||||
memset(state, 0, sizeof(sbc_decoder_state_t));
|
||||
memset(state, 0, sizeof(btstack_sbc_decoder_state_t));
|
||||
state->handle_pcm_data = callback;
|
||||
state->mode = mode;
|
||||
state->context = context;
|
||||
@ -208,7 +208,7 @@ static void append_received_sbc_data(bludroid_decoder_state_t * state, uint8_t *
|
||||
state->bytes_in_frame_buffer += size;
|
||||
}
|
||||
|
||||
void sbc_decoder_process_data(sbc_decoder_state_t * state, int packet_status_flag, uint8_t * buffer, int size){
|
||||
void btstack_sbc_decoder_process_data(btstack_sbc_decoder_state_t * state, int packet_status_flag, uint8_t * buffer, int size){
|
||||
|
||||
bludroid_decoder_state_t * bd_decoder_state = (bludroid_decoder_state_t*)state->decoder_state;
|
||||
int bytes_to_process = size;
|
||||
@ -294,9 +294,9 @@ void sbc_decoder_process_data(sbc_decoder_state_t * state, int packet_status_fla
|
||||
|
||||
sbc_plc_good_frame(&state->plc_state, bd_decoder_state->pcm_plc_data, bd_decoder_state->pcm_data);
|
||||
state->handle_pcm_data(bd_decoder_state->pcm_data,
|
||||
sbc_decoder_num_samples_per_frame(state),
|
||||
sbc_decoder_num_channels(state),
|
||||
sbc_decoder_sample_rate(state), state->context);
|
||||
btstack_sbc_decoder_num_samples_per_frame(state),
|
||||
btstack_sbc_decoder_num_channels(state),
|
||||
btstack_sbc_decoder_sample_rate(state), state->context);
|
||||
state->good_frames_nr++;
|
||||
continue;
|
||||
case OI_CODEC_SBC_NOT_ENOUGH_HEADER_DATA:
|
||||
@ -349,9 +349,9 @@ void sbc_decoder_process_data(sbc_decoder_state_t * state, int packet_status_fla
|
||||
if (status != 0) exit(10);
|
||||
sbc_plc_bad_frame(&state->plc_state, bd_decoder_state->pcm_plc_data, bd_decoder_state->pcm_data);
|
||||
state->handle_pcm_data(bd_decoder_state->pcm_data,
|
||||
sbc_decoder_num_samples_per_frame(state),
|
||||
sbc_decoder_num_channels(state),
|
||||
sbc_decoder_sample_rate(state), state->context);
|
||||
btstack_sbc_decoder_num_samples_per_frame(state),
|
||||
btstack_sbc_decoder_num_channels(state),
|
||||
btstack_sbc_decoder_sample_rate(state), state->context);
|
||||
|
||||
|
||||
break;
|
||||
|
@ -195,13 +195,13 @@ int main (int argc, const char * argv[]){
|
||||
wav_writer_state.frame_count = 0;
|
||||
wav_writer_state.total_num_samples = 0;
|
||||
|
||||
sbc_decoder_state_t state;
|
||||
sbc_decoder_init(&state, mode, &handle_pcm_data, (void*)&wav_writer_state);
|
||||
btstack_sbc_decoder_state_t state;
|
||||
btstack_sbc_decoder_init(&state, mode, &handle_pcm_data, (void*)&wav_writer_state);
|
||||
if (!plc_enabled){
|
||||
sbc_decoder_test_disable_plc();
|
||||
btstack_sbc_decoder_test_disable_plc();
|
||||
}
|
||||
if (corrupt_frame_period > 0){
|
||||
sbc_decoder_test_simulate_corrupt_frames(corrupt_frame_period);
|
||||
btstack_sbc_decoder_test_simulate_corrupt_frames(corrupt_frame_period);
|
||||
}
|
||||
|
||||
write_wav_header(wav_writer_state.wav_file, 0, 0, 0);
|
||||
@ -211,11 +211,11 @@ int main (int argc, const char * argv[]){
|
||||
int bytes_read = __read(fd, read_buffer, sizeof(read_buffer));
|
||||
if (0 >= bytes_read) break;
|
||||
// process chunk
|
||||
sbc_decoder_process_data(&state, 0, read_buffer, bytes_read);
|
||||
btstack_sbc_decoder_process_data(&state, 0, read_buffer, bytes_read);
|
||||
}
|
||||
|
||||
rewind(wav_file);
|
||||
write_wav_header(wav_writer_state.wav_file, wav_writer_state.total_num_samples, sbc_decoder_num_channels(&state), sbc_decoder_sample_rate(&state));
|
||||
write_wav_header(wav_writer_state.wav_file, wav_writer_state.total_num_samples, btstack_sbc_decoder_num_channels(&state), btstack_sbc_decoder_sample_rate(&state));
|
||||
|
||||
fclose(wav_file);
|
||||
close(fd);
|
||||
|
Loading…
x
Reference in New Issue
Block a user