From 1bbecc2b4973bbb4d11761d0d68c397fe5d59946 Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Mon, 20 Mar 2017 10:57:13 +0100 Subject: [PATCH] hfp: ENABLE_HFP_WIDE_BAND_SPEECH required for HFP mSBC --- doc/manual/docs/how_to.md | 3 +- example/hfp_ag_demo.c | 6 ++- example/hfp_hf_demo.c | 4 ++ example/sco_demo_util.c | 56 +++++++++++++++++++--------- port/libusb/btstack_config.h | 3 +- port/posix-h4/btstack_config.h | 3 +- port/posix-h5/btstack_config.h | 3 +- port/windows-h4/btstack_config.h | 3 +- port/windows-winusb/btstack_config.h | 3 +- 9 files changed, 60 insertions(+), 24 deletions(-) diff --git a/doc/manual/docs/how_to.md b/doc/manual/docs/how_to.md index 455cdb02e..8b305013e 100644 --- a/doc/manual/docs/how_to.md +++ b/doc/manual/docs/how_to.md @@ -72,7 +72,8 @@ ENABLE_EHCILL | Enable eHCILL low power mode on TI CC256x/WL18xx ENABLE_LOG_DEBUG | Enable log_debug messages ENABLE_LOG_ERROR | Enable log_error messages ENABLE_LOG_INFO | Enable log_info messages -ENABLE_SCO_OVER_HCI | Enable SCO over HCI for chipsets (only CC256x/WL18xx and USB CSR controllers) +ENABLE_SCO_OVER_HCI | Enable SCO over HCI for chipsets (only TI CC256x/WL18xx, CSR + Broadcom H2/USB)) +ENABLE_HFP_WIDE_BAND_SPEECH | Enable support for mSBC codec used in HFP profile for Wide-Band Speech ENBALE_LE_PERIPHERAL | Enable support for LE Peripheral Role in HCI and Security Manager ENBALE_LE_CENTRAL | Enable support for LE Central Role in HCI and Security Manager ENABLE_LE_SECURE_CONNECTIONS | Enable LE Secure Connections using [mbed TLS library](https://tls.mbed.org) diff --git a/example/hfp_ag_demo.c b/example/hfp_ag_demo.c index 328448dda..e48eb23fa 100644 --- a/example/hfp_ag_demo.c +++ b/example/hfp_ag_demo.c @@ -68,8 +68,12 @@ const char hfp_ag_service_name[] = "BTstack HFP AG Test"; static bd_addr_t device_addr; static const char * device_addr_string = "00:15:83:5F:9D:46"; +#ifdef ENABLE_HFP_WIDE_BAND_SPEECH static uint8_t codecs[] = {HFP_CODEC_CVSD, HFP_CODEC_MSBC}; -// static uint8_t codecs[] = {HFP_CODEC_CVSD}; +#else +static uint8_t codecs[] = {HFP_CODEC_CVSD}; +#endif + static uint8_t negotiated_codec = HFP_CODEC_CVSD; static hci_con_handle_t acl_handle = -1; diff --git a/example/hfp_hf_demo.c b/example/hfp_hf_demo.c index 98a957922..65b5d57ca 100644 --- a/example/hfp_hf_demo.c +++ b/example/hfp_hf_demo.c @@ -77,7 +77,11 @@ static void show_usage(void); #endif static hci_con_handle_t acl_handle = -1; static hci_con_handle_t sco_handle; +#ifdef ENABLE_HFP_WIDE_BAND_SPEECH static uint8_t codecs[] = {HFP_CODEC_CVSD, HFP_CODEC_MSBC}; +#else +static uint8_t codecs[] = {HFP_CODEC_CVSD}; +#endif static uint16_t indicators[1] = {0x01}; static uint8_t negotiated_codec = HFP_CODEC_CVSD; static btstack_packet_callback_registration_t hci_event_callback_registration; diff --git a/example/sco_demo_util.c b/example/sco_demo_util.c index 18f81a437..5f699e329 100644 --- a/example/sco_demo_util.c +++ b/example/sco_demo_util.c @@ -127,11 +127,16 @@ static int count_sent = 0; static int count_received = 0; static int negotiated_codec = -1; +#ifdef ENABLE_HFP_WIDE_BAND_SPEECH btstack_sbc_decoder_state_t decoder_state; +#endif + btstack_cvsd_plc_state_t cvsd_plc_state; +#ifdef ENABLE_HFP_WIDE_BAND_SPEECH FILE * msbc_file_in; FILE * msbc_file_out; +#endif int num_samples_to_write; int num_audio_frames; @@ -153,17 +158,6 @@ static const int16_t sine_int16_at_16000hz[] = { -19260, -17557, -15786, -13952, -12062, -10126, -8149, -6140, -4107, -2057, }; -// 16 kHz samples for mSBC encoder in host endianess -static void sco_demo_sine_wave_int16_at_16000_hz_host_endian(int num_samples, int16_t * data){ - int i; - for (i=0; i < num_samples; i++){ - data[i] = sine_int16_at_16000hz[phase++]; - if (phase >= (sizeof(sine_int16_at_16000hz) / sizeof(int16_t))){ - phase = 0; - } - } -} - // 8 kHz samples for CVSD/SCO packets in little endian static void sco_demo_sine_wave_int16_at_8000_hz_little_endian(int num_samples, int16_t * data){ int i; @@ -178,6 +172,18 @@ static void sco_demo_sine_wave_int16_at_8000_hz_little_endian(int num_samples, i } } +// 16 kHz samples for mSBC encoder in host endianess +#ifdef ENABLE_HFP_WIDE_BAND_SPEECH +static void sco_demo_sine_wave_int16_at_16000_hz_host_endian(int num_samples, int16_t * data){ + int i; + for (i=0; i < num_samples; i++){ + data[i] = sine_int16_at_16000hz[phase++]; + if (phase >= (sizeof(sine_int16_at_16000hz) / sizeof(int16_t))){ + phase = 0; + } + } +} + static void sco_demo_msbc_fill_sine_audio_frame(void){ if (!hfp_msbc_can_encode_audio_frame_now()) return; int num_samples = hfp_msbc_num_audio_samples_per_frame(); @@ -187,6 +193,7 @@ static void sco_demo_msbc_fill_sine_audio_frame(void){ num_audio_frames++; } #endif +#endif #ifdef USE_PORTAUDIO static int portaudio_callback( const void *inputBuffer, void *outputBuffer, @@ -350,6 +357,7 @@ static void portaudio_terminate(void){ #if (SCO_DEMO_MODE == SCO_DEMO_MODE_SINE) || (SCO_DEMO_MODE == SCO_DEMO_MODE_MICROPHONE) +#ifdef ENABLE_HFP_WIDE_BAND_SPEECH static void handle_pcm_data(int16_t * data, int num_samples, int num_channels, int sample_rate, void * context){ UNUSED(context); UNUSED(sample_rate); @@ -363,7 +371,7 @@ static void handle_pcm_data(int16_t * data, int num_samples, int num_channels, i #ifdef HAVE_PORTAUDIO // samples in callback in host endianess, ready for PortAudio playback btstack_ring_buffer_write(&pa_output_ring_buffer, (uint8_t *)data, num_samples*num_channels*2); -#endif +#endif /* HAVE_PORTAUDIO */ #ifdef SCO_WAV_FILENAME if (!num_samples_to_write) return; @@ -373,11 +381,14 @@ static void handle_pcm_data(int16_t * data, int num_samples, int num_channels, i if (num_samples_to_write == 0){ wav_writer_close(); } -#endif - -#endif +#endif /* SCO_WAV_FILENAME */ +#endif /* Demo mode sine or microphone */ } +#endif /* ENABLE_HFP_WIDE_BAND_SPEECH */ + + +#ifdef ENABLE_HFP_WIDE_BAND_SPEECH static void sco_demo_init_mSBC(void){ printf("SCO Demo: Init mSBC\n"); @@ -418,6 +429,7 @@ static void sco_demo_receive_mSBC(uint8_t * packet, uint16_t size){ } btstack_sbc_decoder_process_data(&decoder_state, (packet[1] >> 4) & 3, packet+3, size-3); } +#endif static void sco_demo_init_CVSD(void){ printf("SCO Demo: Init CVSD\n"); @@ -482,9 +494,12 @@ void sco_demo_close(void){ printf("SCO demo close\n"); printf("SCO demo statistics: "); +#ifdef ENABLE_HFP_WIDE_BAND_SPEECH 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.\n", decoder_state.good_frames_nr, decoder_state.zero_frames_nr, decoder_state.bad_frames_nr); - } else { + } else +#endif + { printf("Used CVSD with PLC, number of proccesed frames: \n - %d good frames, \n - %d bad frames.\n", cvsd_plc_state.good_frames_nr, cvsd_plc_state.bad_frames_nr); } @@ -509,7 +524,9 @@ void sco_demo_set_codec(uint8_t codec){ #if (SCO_DEMO_MODE == SCO_DEMO_MODE_SINE) || (SCO_DEMO_MODE == SCO_DEMO_MODE_MICROPHONE) if (negotiated_codec == HFP_CODEC_MSBC){ +#ifdef ENABLE_HFP_WIDE_BAND_SPEECH sco_demo_init_mSBC(); +#endif } else { sco_demo_init_CVSD(); } @@ -561,6 +578,7 @@ void sco_demo_send(hci_con_handle_t sco_handle){ hci_reserve_packet_buffer(); uint8_t * sco_packet = hci_get_outgoing_packet_buffer(); #if SCO_DEMO_MODE == SCO_DEMO_MODE_SINE +#ifdef ENABLE_HFP_WIDE_BAND_SPEECH if (negotiated_codec == HFP_CODEC_MSBC){ // overwrite sco_payload_length = 24; @@ -576,7 +594,9 @@ void sco_demo_send(hci_con_handle_t sco_handle){ } sco_demo_msbc_fill_sine_audio_frame(); - } else { + } else +#endif + { const int audio_samples_per_packet = sco_payload_length / CVSD_BYTES_PER_FRAME; sco_demo_sine_wave_int16_at_8000_hz_little_endian(audio_samples_per_packet, (int16_t *) (sco_packet+3)); } @@ -750,9 +770,11 @@ void sco_demo_receive(uint8_t * packet, uint16_t size){ #if (SCO_DEMO_MODE == SCO_DEMO_MODE_SINE) || (SCO_DEMO_MODE == SCO_DEMO_MODE_MICROPHONE) switch (negotiated_codec){ +#ifdef ENABLE_HFP_WIDE_BAND_SPEECH case HFP_CODEC_MSBC: sco_demo_receive_mSBC(packet, size); break; +#endif case HFP_CODEC_CVSD: sco_demo_receive_CVSD(packet, size); break; diff --git a/port/libusb/btstack_config.h b/port/libusb/btstack_config.h index a2f38b515..1053c80b4 100644 --- a/port/libusb/btstack_config.h +++ b/port/libusb/btstack_config.h @@ -14,8 +14,9 @@ // BTstack features that can be enabled #define ENABLE_BLE #define ENABLE_CLASSIC -#define ENABLE_LE_PERIPHERAL +#define ENABLE_HFP_WIDE_BAND_SPEECH #define ENABLE_LE_CENTRAL +#define ENABLE_LE_PERIPHERAL #define ENABLE_LE_SECURE_CONNECTIONS #define ENABLE_LOG_ERROR #define ENABLE_LOG_INFO diff --git a/port/posix-h4/btstack_config.h b/port/posix-h4/btstack_config.h index 4d94625d7..f5ac4d047 100644 --- a/port/posix-h4/btstack_config.h +++ b/port/posix-h4/btstack_config.h @@ -14,8 +14,9 @@ // BTstack features that can be enabled #define ENABLE_BLE #define ENABLE_CLASSIC -#define ENABLE_LE_PERIPHERAL +#define ENABLE_HFP_WIDE_BAND_SPEECH #define ENABLE_LE_CENTRAL +#define ENABLE_LE_PERIPHERAL #define ENABLE_LE_SECURE_CONNECTIONS #define ENABLE_LOG_ERROR #define ENABLE_LOG_INFO diff --git a/port/posix-h5/btstack_config.h b/port/posix-h5/btstack_config.h index 6534ee604..1832c7d2e 100644 --- a/port/posix-h5/btstack_config.h +++ b/port/posix-h5/btstack_config.h @@ -14,8 +14,9 @@ // BTstack features that can be enabled #define ENABLE_BLE #define ENABLE_CLASSIC -#define ENABLE_LE_PERIPHERAL +#define ENABLE_HFP_WIDE_BAND_SPEECH #define ENABLE_LE_CENTRAL +#define ENABLE_LE_PERIPHERAL #define ENABLE_LE_SECURE_CONNECTIONS #define ENABLE_LOG_ERROR #define ENABLE_LOG_INFO diff --git a/port/windows-h4/btstack_config.h b/port/windows-h4/btstack_config.h index a2f38b515..1053c80b4 100644 --- a/port/windows-h4/btstack_config.h +++ b/port/windows-h4/btstack_config.h @@ -14,8 +14,9 @@ // BTstack features that can be enabled #define ENABLE_BLE #define ENABLE_CLASSIC -#define ENABLE_LE_PERIPHERAL +#define ENABLE_HFP_WIDE_BAND_SPEECH #define ENABLE_LE_CENTRAL +#define ENABLE_LE_PERIPHERAL #define ENABLE_LE_SECURE_CONNECTIONS #define ENABLE_LOG_ERROR #define ENABLE_LOG_INFO diff --git a/port/windows-winusb/btstack_config.h b/port/windows-winusb/btstack_config.h index 1f58f58de..ab2633568 100644 --- a/port/windows-winusb/btstack_config.h +++ b/port/windows-winusb/btstack_config.h @@ -14,8 +14,9 @@ // BTstack features that can be enabled #define ENABLE_BLE #define ENABLE_CLASSIC -#define ENABLE_LE_PERIPHERAL +#define ENABLE_HFP_WIDE_BAND_SPEECH #define ENABLE_LE_CENTRAL +#define ENABLE_LE_PERIPHERAL #define ENABLE_LE_SECURE_CONNECTIONS #define ENABLE_LOG_ERROR #define ENABLE_LOG_INFO