mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-01-25 09:35:42 +00:00
Merge branch 'a2dp' of https://github.com/bluekitchen/btstack into a2dp
Conflicts: src/classic/btstack_sbc_decoder.h
This commit is contained in:
commit
1e98a36782
@ -59,7 +59,7 @@
|
||||
#include <unistd.h>
|
||||
|
||||
#include "btstack.h"
|
||||
#include "sbc_decoder.h"
|
||||
#include "btstack_sbc_decoder.h"
|
||||
|
||||
#include "sco_demo_util.h"
|
||||
#ifdef HAVE_POSIX_STDIN
|
||||
|
@ -242,7 +242,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+3, size-3);
|
||||
sbc_decoder_process_data(&decoder_state, packet[2], packet+3, size-3);
|
||||
dump_data = 0;
|
||||
}
|
||||
}
|
||||
|
@ -65,13 +65,44 @@ typedef struct {
|
||||
int zero_frames_nr;
|
||||
} sbc_decoder_state_t;
|
||||
|
||||
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 sbc_decoder_process_data(sbc_decoder_state_t * state, uint8_t * buffer, int size);
|
||||
/* API_START */
|
||||
|
||||
/**
|
||||
* @brief Init SBC decoder
|
||||
* @param state
|
||||
* @param mode
|
||||
* @param callback for decoded PCM data
|
||||
* @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);
|
||||
|
||||
/**
|
||||
* @brief Process received SCO data
|
||||
* @param state
|
||||
* @param packet_status_flag from SCO packet: 0 = OK, 1 = possibly invalid data, 2 = no data received, 3 = data partially lost
|
||||
* @param buffer
|
||||
* @param size
|
||||
*/
|
||||
void sbc_decoder_process_data(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);
|
||||
|
||||
/*
|
||||
* @brief Get number of channels
|
||||
*/
|
||||
int sbc_decoder_num_channels(sbc_decoder_state_t * state);
|
||||
|
||||
/*
|
||||
* @brief Get sample rate in hz
|
||||
*/
|
||||
int sbc_decoder_sample_rate(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);
|
||||
|
@ -208,8 +208,8 @@ 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 sbc_decoder_process_data(sbc_decoder_state_t * state, uint8_t * buffer, int size){
|
||||
bludroid_decoder_state_t * bd_decoder_state = (bludroid_decoder_state_t*)state->decoder_state;
|
||||
int bytes_to_process = size;
|
||||
int msbc_frame_size = 57;
|
||||
@ -250,13 +250,15 @@ void sbc_decoder_process_data(sbc_decoder_state_t * state, uint8_t * buffer, int
|
||||
}
|
||||
|
||||
OI_STATUS status = 0;
|
||||
int bad_frame = 0;
|
||||
int zero_seq_found = 0;
|
||||
|
||||
|
||||
if (bd_decoder_state->first_good_frame_found){
|
||||
zero_seq_found = find_sequence_of_zeros(frame_data, bd_decoder_state->bytes_in_frame_buffer, 20);
|
||||
bad_frame = zero_seq_found || packet_status_flag;
|
||||
}
|
||||
|
||||
if (zero_seq_found){
|
||||
if (bad_frame){
|
||||
status = OI_CODEC_SBC_CHECKSUM_MISMATCH;
|
||||
bd_decoder_state->bytes_in_frame_buffer = 0;
|
||||
} else {
|
||||
|
@ -50,32 +50,44 @@
|
||||
#include "hfp_msbc.h"
|
||||
|
||||
#define MSBC_FRAME_SIZE 57
|
||||
#define MSBC_HEADER_H2_SIZE 2
|
||||
#define MSBC_PADDING_SIZE 1
|
||||
#define MSBC_EXTRA_SIZE (MSBC_HEADER_H2_SIZE + MSBC_PADDING_SIZE)
|
||||
|
||||
static const uint8_t msbc_header_h2_byte_0 = 1;
|
||||
static const uint8_t msbc_header_h2_byte_1_table[] = { 0x08, 0x38, 0xc8, 0xf8 };
|
||||
|
||||
static btstack_sbc_encoder_state_t state;
|
||||
static uint8_t msbc_padding[] = {0,0,0};
|
||||
static int msbc_sequence_number;
|
||||
|
||||
static uint8_t msbc_buffer[2*(MSBC_FRAME_SIZE + sizeof(msbc_padding))];
|
||||
static uint8_t msbc_buffer[2*(MSBC_FRAME_SIZE + MSBC_EXTRA_SIZE)];
|
||||
static int msbc_buffer_offset = 0;
|
||||
|
||||
void hfp_msbc_init(void){
|
||||
btstack_sbc_encoder_init(&state, SBC_MODE_mSBC, 16, 8, 0, 16000, 26);
|
||||
msbc_buffer_offset = 0;
|
||||
msbc_sequence_number = 0;
|
||||
}
|
||||
|
||||
int hfp_msbc_can_encode_audio_frame_now(void){
|
||||
return sizeof(msbc_buffer) - msbc_buffer_offset >= MSBC_FRAME_SIZE + sizeof(msbc_padding);
|
||||
return sizeof(msbc_buffer) - msbc_buffer_offset >= MSBC_FRAME_SIZE + MSBC_EXTRA_SIZE;
|
||||
}
|
||||
|
||||
void hfp_msbc_encode_audio_frame(int16_t * pcm_samples){
|
||||
if (!hfp_msbc_can_encode_audio_frame_now()) return;
|
||||
|
||||
btstack_sbc_encoder_process_data(pcm_samples);
|
||||
|
||||
memcpy(msbc_buffer + msbc_buffer_offset, msbc_padding, sizeof(msbc_padding));
|
||||
msbc_buffer_offset += sizeof(msbc_padding);
|
||||
// Synchronization Header H2
|
||||
msbc_buffer[msbc_buffer_offset++] = msbc_header_h2_byte_0;
|
||||
msbc_buffer[msbc_buffer_offset++] = msbc_header_h2_byte_1_table[msbc_sequence_number];
|
||||
msbc_sequence_number = (msbc_sequence_number + 1) & 3;
|
||||
|
||||
// SBC Frame
|
||||
btstack_sbc_encoder_process_data(pcm_samples);
|
||||
memcpy(msbc_buffer + msbc_buffer_offset, btstack_sbc_encoder_sbc_buffer(), MSBC_FRAME_SIZE);
|
||||
msbc_buffer_offset += MSBC_FRAME_SIZE;
|
||||
|
||||
// Final padding to use 60 bytes for 120 audio samples
|
||||
msbc_buffer[msbc_buffer_offset++] = 0;
|
||||
}
|
||||
|
||||
void hfp_msbc_read_from_stream(uint8_t * buf, int size){
|
||||
|
@ -211,7 +211,7 @@ 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, read_buffer, bytes_read);
|
||||
sbc_decoder_process_data(&state, 0, read_buffer, bytes_read);
|
||||
}
|
||||
|
||||
rewind(wav_file);
|
||||
|
@ -94,7 +94,8 @@ static void read_wav_header(int wav_fd){
|
||||
}
|
||||
|
||||
int main (int argc, const char * argv[]){
|
||||
if (argc < 2){
|
||||
if (argc < 3){
|
||||
printf("Usage: %s WAV_FILE mSBC_FILE\n", argv[0]);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user