mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
component/bt: fix typos and complier errors of the merged code
1. format the source code of A2DP sample 2. fix some compiler errors and warnings
This commit is contained in:
parent
73f00732cf
commit
2e8af3a8b7
@ -1454,7 +1454,7 @@ void bta_av_sig_chg(tBTA_AV_DATA *p_data)
|
|||||||
APPL_TRACE_DEBUG("start sig timer %d", p_data->hdr.offset);
|
APPL_TRACE_DEBUG("start sig timer %d", p_data->hdr.offset);
|
||||||
if (p_data->hdr.offset == AVDT_ACP)
|
if (p_data->hdr.offset == AVDT_ACP)
|
||||||
{
|
{
|
||||||
APPL_TRACE_DEBUG("Incoming L2CAP acquired, set state as incoming", NULL);
|
APPL_TRACE_DEBUG("Incoming L2CAP acquired, set state as incoming");
|
||||||
bdcpy(p_cb->p_scb[xx]->peer_addr, p_data->str_msg.bd_addr);
|
bdcpy(p_cb->p_scb[xx]->peer_addr, p_data->str_msg.bd_addr);
|
||||||
p_cb->p_scb[xx]->use_rc = TRUE; /* allowing RC for incoming connection */
|
p_cb->p_scb[xx]->use_rc = TRUE; /* allowing RC for incoming connection */
|
||||||
bta_av_ssm_execute(p_cb->p_scb[xx], BTA_AV_ACP_CONNECT_EVT, p_data);
|
bta_av_ssm_execute(p_cb->p_scb[xx], BTA_AV_ACP_CONNECT_EVT, p_data);
|
||||||
|
@ -697,7 +697,7 @@ void avct_lcb_msg_ind(tAVCT_LCB *p_lcb, tAVCT_LCB_EVT *p_data)
|
|||||||
/* check for invalid cr_ipid */
|
/* check for invalid cr_ipid */
|
||||||
if (cr_ipid == AVCT_CR_IPID_INVALID)
|
if (cr_ipid == AVCT_CR_IPID_INVALID)
|
||||||
{
|
{
|
||||||
AVCT_TRACE_WARNING("Invalid cr_ipid", cr_ipid);
|
AVCT_TRACE_WARNING("Invalid cr_ipid %d", cr_ipid);
|
||||||
GKI_freebuf(p_data->p_buf);
|
GKI_freebuf(p_data->p_buf);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -49,7 +49,7 @@ static tAVRC_STS avrc_bld_get_capability_rsp (tAVRC_GET_CAPS_RSP *p_rsp, BT_HDR
|
|||||||
|
|
||||||
if (!(AVRC_IS_VALID_CAP_ID(p_rsp->capability_id)))
|
if (!(AVRC_IS_VALID_CAP_ID(p_rsp->capability_id)))
|
||||||
{
|
{
|
||||||
AVRC_TRACE_ERROR("avrc_bld_get_capability_rsp bad parameter. p_rsp: %x", p_rsp);
|
AVRC_TRACE_ERROR("avrc_bld_get_capability_rsp bad parameter. p_rsp: %x", (int)p_rsp);
|
||||||
status = AVRC_STS_BAD_PARAM;
|
status = AVRC_STS_BAD_PARAM;
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
@ -331,7 +331,7 @@ static tAVRC_STS avrc_bld_app_setting_text_rsp (tAVRC_GET_APP_ATTR_TXT_RSP *p_rs
|
|||||||
{
|
{
|
||||||
if (len_left < (p_rsp->p_attrs[xx].str_len + 4))
|
if (len_left < (p_rsp->p_attrs[xx].str_len + 4))
|
||||||
{
|
{
|
||||||
AVRC_TRACE_ERROR("avrc_bld_app_setting_text_rsp out of room (str_len:%d, left:%d)",
|
AVRC_TRACE_ERROR("avrc_bld_app_setting_text_rsp out of room %d(str_len:%d, left:%d)",
|
||||||
xx, p_rsp->p_attrs[xx].str_len, len_left);
|
xx, p_rsp->p_attrs[xx].str_len, len_left);
|
||||||
p_rsp->num_attr = num_added;
|
p_rsp->num_attr = num_added;
|
||||||
sts = AVRC_STS_INTERNAL_ERR;
|
sts = AVRC_STS_INTERNAL_ERR;
|
||||||
|
44
examples/09_a2dp/components/bluedroid_demos/app_core/bt_app_core.c
Executable file → Normal file
44
examples/09_a2dp/components/bluedroid_demos/app_core/bt_app_core.c
Executable file → Normal file
@ -47,19 +47,21 @@ static void bt_app_task_handler(void *arg)
|
|||||||
|
|
||||||
static void bt_app_task_post(void)
|
static void bt_app_task_post(void)
|
||||||
{
|
{
|
||||||
BtTaskEvt_t *evt = (BtTaskEvt_t *)osi_malloc(sizeof(BtTaskEvt_t));
|
BtTaskEvt_t *evt = (BtTaskEvt_t *)osi_malloc(sizeof(BtTaskEvt_t));
|
||||||
if (evt == NULL)
|
if (evt == NULL) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
evt->sig = 0xff;
|
evt->sig = 0xff;
|
||||||
evt->par = 0;
|
evt->par = 0;
|
||||||
|
|
||||||
if (xQueueSend(xBtAppQueue, &evt, 10/portTICK_RATE_MS) != pdTRUE) {
|
if (xQueueSend(xBtAppQueue, &evt, 10 / portTICK_RATE_MS) != pdTRUE) {
|
||||||
ets_printf("btdm_post failed\n");
|
ets_printf("btdm_post failed\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void bta_app_msg_ready(fixed_queue_t *queue) {
|
static void bta_app_msg_ready(fixed_queue_t *queue)
|
||||||
|
{
|
||||||
BT_HDR *p_msg;
|
BT_HDR *p_msg;
|
||||||
while (!fixed_queue_is_empty(queue)) {
|
while (!fixed_queue_is_empty(queue)) {
|
||||||
p_msg = (BT_HDR *)fixed_queue_dequeue(queue);
|
p_msg = (BT_HDR *)fixed_queue_dequeue(queue);
|
||||||
@ -79,9 +81,10 @@ static void bta_app_msg_ready(fixed_queue_t *queue) {
|
|||||||
static void bt_app_context_switched(void *p_msg)
|
static void bt_app_context_switched(void *p_msg)
|
||||||
{
|
{
|
||||||
tBTAPP_CONTEXT_SWITCH_CBACK *p = (tBTAPP_CONTEXT_SWITCH_CBACK *) p_msg;
|
tBTAPP_CONTEXT_SWITCH_CBACK *p = (tBTAPP_CONTEXT_SWITCH_CBACK *) p_msg;
|
||||||
|
|
||||||
if (p->p_cb)
|
if (p->p_cb) {
|
||||||
p->p_cb(p->event, p->p_param);
|
p->p_cb(p->event, p->p_param);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void bt_app_send_msg(void *p_msg)
|
static void bt_app_send_msg(void *p_msg)
|
||||||
@ -92,35 +95,29 @@ static void bt_app_send_msg(void *p_msg)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bt_status_t bt_app_transfer_context (tBTAPP_CBACK *p_cback, UINT16 event, char* p_params, int param_len, tBTAPP_COPY_CBACK *p_copy_cback)
|
bt_status_t bt_app_transfer_context (tBTAPP_CBACK *p_cback, UINT16 event, char *p_params, int param_len, tBTAPP_COPY_CBACK *p_copy_cback)
|
||||||
{
|
{
|
||||||
tBTAPP_CONTEXT_SWITCH_CBACK *p_msg;
|
tBTAPP_CONTEXT_SWITCH_CBACK *p_msg;
|
||||||
|
|
||||||
LOG_ERROR("btapp_transfer_context evt %d, len %d\n", event, param_len);
|
LOG_ERROR("btapp_transfer_context evt %d, len %d\n", event, param_len);
|
||||||
|
|
||||||
/* allocate and send message that will be executed in btif context */
|
/* allocate and send message that will be executed in btif context */
|
||||||
if ((p_msg = (tBTAPP_CONTEXT_SWITCH_CBACK *) GKI_getbuf(sizeof(tBTAPP_CONTEXT_SWITCH_CBACK) + param_len)) != NULL)
|
if ((p_msg = (tBTAPP_CONTEXT_SWITCH_CBACK *) GKI_getbuf(sizeof(tBTAPP_CONTEXT_SWITCH_CBACK) + param_len)) != NULL) {
|
||||||
{
|
|
||||||
p_msg->hdr.event = BT_EVT_APP_CONTEXT_SWITCH; /* internal event */
|
p_msg->hdr.event = BT_EVT_APP_CONTEXT_SWITCH; /* internal event */
|
||||||
p_msg->p_cb = p_cback;
|
p_msg->p_cb = p_cback;
|
||||||
|
|
||||||
p_msg->event = event; /* callback event */
|
p_msg->event = event; /* callback event */
|
||||||
|
|
||||||
/* check if caller has provided a copy callback to do the deep copy */
|
/* check if caller has provided a copy callback to do the deep copy */
|
||||||
if (p_copy_cback)
|
if (p_copy_cback) {
|
||||||
{
|
|
||||||
p_copy_cback(event, p_msg->p_param, p_params);
|
p_copy_cback(event, p_msg->p_param, p_params);
|
||||||
}
|
} else if (p_params) {
|
||||||
else if (p_params)
|
|
||||||
{
|
|
||||||
memcpy(p_msg->p_param, p_params, param_len); /* callback parameter data */
|
memcpy(p_msg->p_param, p_params, param_len); /* callback parameter data */
|
||||||
}
|
}
|
||||||
|
|
||||||
bt_app_send_msg(p_msg);
|
bt_app_send_msg(p_msg);
|
||||||
return BT_STATUS_SUCCESS;
|
return BT_STATUS_SUCCESS;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
/* let caller deal with a failed allocation */
|
/* let caller deal with a failed allocation */
|
||||||
return BT_STATUS_NOMEM;
|
return BT_STATUS_NOMEM;
|
||||||
}
|
}
|
||||||
@ -129,8 +126,9 @@ bt_status_t bt_app_transfer_context (tBTAPP_CBACK *p_cback, UINT16 event, char*
|
|||||||
void bt_app_task_start_up(void)
|
void bt_app_task_start_up(void)
|
||||||
{
|
{
|
||||||
bt_app_msg_queue = fixed_queue_new(SIZE_MAX);
|
bt_app_msg_queue = fixed_queue_new(SIZE_MAX);
|
||||||
if (bt_app_msg_queue == NULL)
|
if (bt_app_msg_queue == NULL) {
|
||||||
goto error_exit;
|
goto error_exit;
|
||||||
|
}
|
||||||
//ke_event_callback_set(KE_EVENT_BT_APP_TASK, &bt_app_task_handler);
|
//ke_event_callback_set(KE_EVENT_BT_APP_TASK, &bt_app_task_handler);
|
||||||
|
|
||||||
xBtAppQueue = xQueueCreate(3, sizeof(void *));
|
xBtAppQueue = xQueueCreate(3, sizeof(void *));
|
||||||
@ -168,7 +166,7 @@ static void bt_app_upstreams_evt(UINT16 event, char *p_param)
|
|||||||
static void bt_stack_evt(tBTA_DM_SEC_EVT event, tBTA_DM_SEC* p_data)
|
static void bt_stack_evt(tBTA_DM_SEC_EVT event, tBTA_DM_SEC* p_data)
|
||||||
{
|
{
|
||||||
LOG_ERROR("bt_stack_evt: %d\n", (uint16_t)event);
|
LOG_ERROR("bt_stack_evt: %d\n", (uint16_t)event);
|
||||||
bt_app_transfer_context(bt_app_upstreams_evt, (uint16_t)event,
|
bt_app_transfer_context(bt_app_upstreams_evt, (uint16_t)event,
|
||||||
(void *)p_data, sizeof(tBTA_DM_SEC), NULL);
|
(void *)p_data, sizeof(tBTA_DM_SEC), NULL);
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
@ -3,14 +3,12 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
|
||||||
#include "freertos/FreeRTOS.h"
|
#include "freertos/FreeRTOS.h"
|
||||||
#include "freertos/task.h"
|
#include "freertos/task.h"
|
||||||
|
|
||||||
#include "bt_app_common.h"
|
#include "bt_app_common.h"
|
||||||
#include "btif_stack_manager.h"
|
#include "btif_stack_manager.h"
|
||||||
#include "btif_sdp.h"
|
#include "esp_gap_bt_api.h"
|
||||||
#include "esp_gap_api.h"
|
|
||||||
#include "bta_api.h"
|
#include "bta_api.h"
|
||||||
#include "bt_av.h"
|
#include "bt_av.h"
|
||||||
|
|
||||||
@ -34,7 +32,6 @@ static void bt_stack_evt(tBT_APP_EVT event, tBT_APP_EVT_DATA *p_data);
|
|||||||
static void bt_stack_state_changed(bt_state_t state);
|
static void bt_stack_state_changed(bt_state_t state);
|
||||||
|
|
||||||
static bt_bdaddr_t peer_bd_addr = {{0x00, 0x1b, 0xdc, 0x08, 0x0f, 0xe7}};
|
static bt_bdaddr_t peer_bd_addr = {{0x00, 0x1b, 0xdc, 0x08, 0x0f, 0xe7}};
|
||||||
// static bt_bdaddr_t peer_bd_addr = {{0xfc, 0x3f, 0x7c, 0xf1, 0x2c, 0x78}};
|
|
||||||
|
|
||||||
static bt_callbacks_t bt_callbacks = {
|
static bt_callbacks_t bt_callbacks = {
|
||||||
bt_stack_state_changed
|
bt_stack_state_changed
|
||||||
@ -43,7 +40,7 @@ static bt_callbacks_t bt_callbacks = {
|
|||||||
osi_alarm_t *app_alarm = NULL;
|
osi_alarm_t *app_alarm = NULL;
|
||||||
|
|
||||||
static void btav_conn_state_cb(btav_connection_state_t state,
|
static void btav_conn_state_cb(btav_connection_state_t state,
|
||||||
bt_bdaddr_t *bd_addr)
|
bt_bdaddr_t *bd_addr)
|
||||||
{
|
{
|
||||||
LOG_ERROR("===btav_conn_state_cb %d ===\n", state);
|
LOG_ERROR("===btav_conn_state_cb %d ===\n", state);
|
||||||
(void) bd_addr;
|
(void) bd_addr;
|
||||||
@ -90,25 +87,25 @@ static void bt_app_stack_evt(UINT16 event, char *p_param)
|
|||||||
{
|
{
|
||||||
switch (event) {
|
switch (event) {
|
||||||
case BT_APP_EVT_STACK_ON: {
|
case BT_APP_EVT_STACK_ON: {
|
||||||
char *dev_name = "SDP_SERVER_CLIENT";
|
char *dev_name = "SDP_SERVER_CLIENT";
|
||||||
BTM_SetTraceLevel(BT_TRACE_LEVEL_WARNING);
|
BTM_SetTraceLevel(BT_TRACE_LEVEL_WARNING);
|
||||||
btav_set_device_class();
|
btav_set_device_class();
|
||||||
BTA_DmSetDeviceName(dev_name);
|
BTA_DmSetDeviceName(dev_name);
|
||||||
esp_bt_gap_set_scan_mode(BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE);
|
esp_bt_gap_set_scan_mode(BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE);
|
||||||
btif_av_get_sink_interface()->init(&btav_cbs);
|
btif_av_get_sink_interface()->init(&btav_cbs);
|
||||||
|
|
||||||
// app_alarm = osi_alarm_new("app_alarm", bt_sdp_add_record_to, NULL, 1000, false);
|
// app_alarm = osi_alarm_new("app_alarm", bt_sdp_add_record_to, NULL, 1000, false);
|
||||||
app_alarm = osi_alarm_new("app_alarm", btav_open_to, NULL, 1000, false);
|
app_alarm = osi_alarm_new("app_alarm", btav_open_to, NULL, 1000, false);
|
||||||
osi_alarm_set(app_alarm, 1000);
|
osi_alarm_set(app_alarm, 1000);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case BT_APP_EVT_AV_OPEN_TO: {
|
case BT_APP_EVT_AV_OPEN_TO: {
|
||||||
LOG_ERROR("**BT_APP_EVT_AV_OPEN_TO\n");
|
LOG_ERROR("**BT_APP_EVT_AV_OPEN_TO\n");
|
||||||
// btif_av_get_sink_interface()->connect(&peer_bd_addr);
|
// btif_av_get_sink_interface()->connect(&peer_bd_addr);
|
||||||
osi_alarm_free(app_alarm);
|
osi_alarm_free(app_alarm);
|
||||||
app_alarm = NULL;
|
app_alarm = NULL;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -117,8 +114,8 @@ static void bt_app_stack_evt(UINT16 event, char *p_param)
|
|||||||
static void bt_stack_evt(tBT_APP_EVT event, tBT_APP_EVT_DATA *p_data)
|
static void bt_stack_evt(tBT_APP_EVT event, tBT_APP_EVT_DATA *p_data)
|
||||||
{
|
{
|
||||||
LOG_ERROR("bt_stack_evt: %d\n", (uint16_t)event);
|
LOG_ERROR("bt_stack_evt: %d\n", (uint16_t)event);
|
||||||
bt_app_transfer_context(bt_app_stack_evt, (uint16_t)event,
|
bt_app_transfer_context(bt_app_stack_evt, (uint16_t)event,
|
||||||
(void *)p_data, sizeof(tBT_APP_EVT_DATA), NULL);
|
(void *)p_data, sizeof(tBT_APP_EVT_DATA), NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void bt_stack_state_changed(bt_state_t state)
|
static void bt_stack_state_changed(bt_state_t state)
|
||||||
|
306
examples/09_a2dp/components/bluedroid_demos/audio_a2dp_hw/audio_a2dp_hw.c
Executable file → Normal file
306
examples/09_a2dp/components/bluedroid_demos/audio_a2dp_hw/audio_a2dp_hw.c
Executable file → Normal file
@ -138,17 +138,16 @@ static size_t out_get_buffer_size(const struct audio_stream *stream);
|
|||||||
** Miscellaneous helper functions
|
** Miscellaneous helper functions
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
static const char* dump_a2dp_ctrl_event(char event)
|
static const char *dump_a2dp_ctrl_event(char event)
|
||||||
{
|
{
|
||||||
switch(event)
|
switch (event) {
|
||||||
{
|
|
||||||
CASE_RETURN_STR(A2DP_CTRL_CMD_NONE)
|
CASE_RETURN_STR(A2DP_CTRL_CMD_NONE)
|
||||||
CASE_RETURN_STR(A2DP_CTRL_CMD_CHECK_READY)
|
CASE_RETURN_STR(A2DP_CTRL_CMD_CHECK_READY)
|
||||||
CASE_RETURN_STR(A2DP_CTRL_CMD_START)
|
CASE_RETURN_STR(A2DP_CTRL_CMD_START)
|
||||||
CASE_RETURN_STR(A2DP_CTRL_CMD_STOP)
|
CASE_RETURN_STR(A2DP_CTRL_CMD_STOP)
|
||||||
CASE_RETURN_STR(A2DP_CTRL_CMD_SUSPEND)
|
CASE_RETURN_STR(A2DP_CTRL_CMD_SUSPEND)
|
||||||
default:
|
default:
|
||||||
return "UNKNOWN MSG ID";
|
return "UNKNOWN MSG ID";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -157,7 +156,7 @@ static const char* dump_a2dp_ctrl_event(char event)
|
|||||||
static void ts_log(char *tag, int val, struct timespec *pprev_opt)
|
static void ts_log(char *tag, int val, struct timespec *pprev_opt)
|
||||||
{
|
{
|
||||||
struct timespec now;
|
struct timespec now;
|
||||||
static struct timespec prev = {0,0};
|
static struct timespec prev = {0, 0};
|
||||||
unsigned long long now_us;
|
unsigned long long now_us;
|
||||||
unsigned long long diff_us;
|
unsigned long long diff_us;
|
||||||
UNUSED(tag);
|
UNUSED(tag);
|
||||||
@ -165,17 +164,14 @@ static void ts_log(char *tag, int val, struct timespec *pprev_opt)
|
|||||||
|
|
||||||
clock_gettime(CLOCK_MONOTONIC, &now);
|
clock_gettime(CLOCK_MONOTONIC, &now);
|
||||||
|
|
||||||
now_us = now.tv_sec*USEC_PER_SEC + now.tv_nsec/1000;
|
now_us = now.tv_sec * USEC_PER_SEC + now.tv_nsec / 1000;
|
||||||
|
|
||||||
if (pprev_opt)
|
if (pprev_opt) {
|
||||||
{
|
diff_us = (now.tv_sec - prev.tv_sec) * USEC_PER_SEC + (now.tv_nsec - prev.tv_nsec) / 1000;
|
||||||
diff_us = (now.tv_sec - prev.tv_sec) * USEC_PER_SEC + (now.tv_nsec - prev.tv_nsec)/1000;
|
|
||||||
*pprev_opt = now;
|
*pprev_opt = now;
|
||||||
DEBUG("[%s] ts %08lld, *diff %08lld, val %d", tag, now_us, diff_us, val);
|
DEBUG("[%s] ts %08lld, *diff %08lld, val %d", tag, now_us, diff_us, val);
|
||||||
}
|
} else {
|
||||||
else
|
diff_us = (now.tv_sec - prev.tv_sec) * USEC_PER_SEC + (now.tv_nsec - prev.tv_nsec) / 1000;
|
||||||
{
|
|
||||||
diff_us = (now.tv_sec - prev.tv_sec) * USEC_PER_SEC + (now.tv_nsec - prev.tv_nsec)/1000;
|
|
||||||
prev = now;
|
prev = now;
|
||||||
DEBUG("[%s] ts %08lld, diff %08lld, val %d", tag, now_us, diff_us, val);
|
DEBUG("[%s] ts %08lld, diff %08lld, val %d", tag, now_us, diff_us, val);
|
||||||
}
|
}
|
||||||
@ -188,7 +184,7 @@ static int calc_audiotime(struct a2dp_config cfg, int bytes)
|
|||||||
ASSERTC(cfg.format == AUDIO_FORMAT_PCM_16_BIT,
|
ASSERTC(cfg.format == AUDIO_FORMAT_PCM_16_BIT,
|
||||||
"unsupported sample sz", cfg.format);
|
"unsupported sample sz", cfg.format);
|
||||||
|
|
||||||
return bytes*(1000000/(chan_count*2))/cfg.rate;
|
return bytes * (1000000 / (chan_count * 2)) / cfg.rate;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
@ -208,26 +204,27 @@ static int skt_connect(char *path, size_t buffer_sz)
|
|||||||
|
|
||||||
skt_fd = socket(AF_LOCAL, SOCK_STREAM, 0);
|
skt_fd = socket(AF_LOCAL, SOCK_STREAM, 0);
|
||||||
|
|
||||||
if(socket_local_client_connect(skt_fd, path,
|
if (socket_local_client_connect(skt_fd, path,
|
||||||
ANDROID_SOCKET_NAMESPACE_ABSTRACT, SOCK_STREAM) < 0)
|
ANDROID_SOCKET_NAMESPACE_ABSTRACT, SOCK_STREAM) < 0) {
|
||||||
{
|
|
||||||
ERROR("failed to connect (%s)", strerror(errno));
|
ERROR("failed to connect (%s)", strerror(errno));
|
||||||
close(skt_fd);
|
close(skt_fd);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
len = buffer_sz;
|
len = buffer_sz;
|
||||||
ret = setsockopt(skt_fd, SOL_SOCKET, SO_SNDBUF, (char*)&len, (int)sizeof(len));
|
ret = setsockopt(skt_fd, SOL_SOCKET, SO_SNDBUF, (char *)&len, (int)sizeof(len));
|
||||||
|
|
||||||
/* only issue warning if failed */
|
/* only issue warning if failed */
|
||||||
if (ret < 0)
|
if (ret < 0) {
|
||||||
ERROR("setsockopt failed (%s)", strerror(errno));
|
ERROR("setsockopt failed (%s)", strerror(errno));
|
||||||
|
}
|
||||||
|
|
||||||
ret = setsockopt(skt_fd, SOL_SOCKET, SO_RCVBUF, (char*)&len, (int)sizeof(len));
|
ret = setsockopt(skt_fd, SOL_SOCKET, SO_RCVBUF, (char *)&len, (int)sizeof(len));
|
||||||
|
|
||||||
/* only issue warning if failed */
|
/* only issue warning if failed */
|
||||||
if (ret < 0)
|
if (ret < 0) {
|
||||||
ERROR("setsockopt failed (%s)", strerror(errno));
|
ERROR("setsockopt failed (%s)", strerror(errno));
|
||||||
|
}
|
||||||
|
|
||||||
INFO("connected to stack fd = %d", skt_fd);
|
INFO("connected to stack fd = %d", skt_fd);
|
||||||
|
|
||||||
@ -244,8 +241,7 @@ static int skt_read(int fd, void *p, size_t len)
|
|||||||
|
|
||||||
ts_log("skt_read recv", len, NULL);
|
ts_log("skt_read recv", len, NULL);
|
||||||
|
|
||||||
if ((read = recv(fd, p, len, MSG_NOSIGNAL)) == -1)
|
if ((read = recv(fd, p, len, MSG_NOSIGNAL)) == -1) {
|
||||||
{
|
|
||||||
ERROR("write failed with errno=%d\n", errno);
|
ERROR("write failed with errno=%d\n", errno);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -266,13 +262,13 @@ static int skt_write(int fd, const void *p, size_t len)
|
|||||||
/* poll for 500 ms */
|
/* poll for 500 ms */
|
||||||
|
|
||||||
/* send time out */
|
/* send time out */
|
||||||
if (poll(&pfd, 1, 500) == 0)
|
if (poll(&pfd, 1, 500) == 0) {
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
ts_log("skt_write", len, NULL);
|
ts_log("skt_write", len, NULL);
|
||||||
|
|
||||||
if ((sent = send(fd, p, len, MSG_NOSIGNAL)) == -1)
|
if ((sent = send(fd, p, len, MSG_NOSIGNAL)) == -1) {
|
||||||
{
|
|
||||||
ERROR("write failed with errno=%d\n", errno);
|
ERROR("write failed with errno=%d\n", errno);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -284,8 +280,7 @@ static int skt_disconnect(int fd)
|
|||||||
{
|
{
|
||||||
INFO("fd %d", fd);
|
INFO("fd %d", fd);
|
||||||
|
|
||||||
if (fd != AUDIO_SKT_DISCONNECTED)
|
if (fd != AUDIO_SKT_DISCONNECTED) {
|
||||||
{
|
|
||||||
shutdown(fd, SHUT_RDWR);
|
shutdown(fd, SHUT_RDWR);
|
||||||
close(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
@ -300,29 +295,24 @@ static int skt_disconnect(int fd)
|
|||||||
**
|
**
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
|
||||||
static int a2dp_ctrl_receive(struct a2dp_stream_common *common, void* buffer, int length)
|
static int a2dp_ctrl_receive(struct a2dp_stream_common *common, void *buffer, int length)
|
||||||
{
|
{
|
||||||
int ret = recv(common->ctrl_fd, buffer, length, MSG_NOSIGNAL);
|
int ret = recv(common->ctrl_fd, buffer, length, MSG_NOSIGNAL);
|
||||||
if (ret < 0)
|
if (ret < 0) {
|
||||||
{
|
|
||||||
ERROR("ack failed (%s)", strerror(errno));
|
ERROR("ack failed (%s)", strerror(errno));
|
||||||
if (errno == EINTR)
|
if (errno == EINTR) {
|
||||||
{
|
|
||||||
/* retry again */
|
/* retry again */
|
||||||
ret = recv(common->ctrl_fd, buffer, length, MSG_NOSIGNAL);
|
ret = recv(common->ctrl_fd, buffer, length, MSG_NOSIGNAL);
|
||||||
if (ret < 0)
|
if (ret < 0) {
|
||||||
{
|
ERROR("ack failed (%s)", strerror(errno));
|
||||||
ERROR("ack failed (%s)", strerror(errno));
|
skt_disconnect(common->ctrl_fd);
|
||||||
skt_disconnect(common->ctrl_fd);
|
common->ctrl_fd = AUDIO_SKT_DISCONNECTED;
|
||||||
common->ctrl_fd = AUDIO_SKT_DISCONNECTED;
|
return -1;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
skt_disconnect(common->ctrl_fd);
|
||||||
{
|
common->ctrl_fd = AUDIO_SKT_DISCONNECTED;
|
||||||
skt_disconnect(common->ctrl_fd);
|
return -1;
|
||||||
common->ctrl_fd = AUDIO_SKT_DISCONNECTED;
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -336,8 +326,7 @@ static int a2dp_command(struct a2dp_stream_common *common, char cmd)
|
|||||||
DEBUG("A2DP COMMAND %s", dump_a2dp_ctrl_event(cmd));
|
DEBUG("A2DP COMMAND %s", dump_a2dp_ctrl_event(cmd));
|
||||||
|
|
||||||
/* send command */
|
/* send command */
|
||||||
if (send(common->ctrl_fd, &cmd, 1, MSG_NOSIGNAL) == -1)
|
if (send(common->ctrl_fd, &cmd, 1, MSG_NOSIGNAL) == -1) {
|
||||||
{
|
|
||||||
ERROR("cmd failed (%s)", strerror(errno));
|
ERROR("cmd failed (%s)", strerror(errno));
|
||||||
skt_disconnect(common->ctrl_fd);
|
skt_disconnect(common->ctrl_fd);
|
||||||
common->ctrl_fd = AUDIO_SKT_DISCONNECTED;
|
common->ctrl_fd = AUDIO_SKT_DISCONNECTED;
|
||||||
@ -345,23 +334,25 @@ static int a2dp_command(struct a2dp_stream_common *common, char cmd)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* wait for ack byte */
|
/* wait for ack byte */
|
||||||
if (a2dp_ctrl_receive(common, &ack, 1) < 0)
|
if (a2dp_ctrl_receive(common, &ack, 1) < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
DEBUG("A2DP COMMAND %s DONE STATUS %d", dump_a2dp_ctrl_event(cmd), ack);
|
DEBUG("A2DP COMMAND %s DONE STATUS %d", dump_a2dp_ctrl_event(cmd), ack);
|
||||||
|
|
||||||
if (ack == A2DP_CTRL_ACK_INCALL_FAILURE)
|
if (ack == A2DP_CTRL_ACK_INCALL_FAILURE) {
|
||||||
return ack;
|
return ack;
|
||||||
if (ack != A2DP_CTRL_ACK_SUCCESS)
|
}
|
||||||
|
if (ack != A2DP_CTRL_ACK_SUCCESS) {
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int check_a2dp_ready(struct a2dp_stream_common *common)
|
static int check_a2dp_ready(struct a2dp_stream_common *common)
|
||||||
{
|
{
|
||||||
if (a2dp_command(common, A2DP_CTRL_CMD_CHECK_READY) < 0)
|
if (a2dp_command(common, A2DP_CTRL_CMD_CHECK_READY) < 0) {
|
||||||
{
|
|
||||||
ERROR("check a2dp ready failed");
|
ERROR("check a2dp ready failed");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -374,16 +365,17 @@ static int a2dp_read_audio_config(struct a2dp_stream_common *common)
|
|||||||
uint32_t sample_rate;
|
uint32_t sample_rate;
|
||||||
uint8_t channel_count;
|
uint8_t channel_count;
|
||||||
|
|
||||||
if (a2dp_command(common, A2DP_CTRL_GET_AUDIO_CONFIG) < 0)
|
if (a2dp_command(common, A2DP_CTRL_GET_AUDIO_CONFIG) < 0) {
|
||||||
{
|
|
||||||
ERROR("check a2dp ready failed");
|
ERROR("check a2dp ready failed");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (a2dp_ctrl_receive(common, &sample_rate, 4) < 0)
|
if (a2dp_ctrl_receive(common, &sample_rate, 4) < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
if (a2dp_ctrl_receive(common, &channel_count, 1) < 0)
|
}
|
||||||
|
if (a2dp_ctrl_receive(common, &channel_count, 1) < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
common->cfg.channel_flags = (channel_count == 1 ? AUDIO_CHANNEL_IN_MONO : AUDIO_CHANNEL_IN_STEREO);
|
common->cfg.channel_flags = (channel_count == 1 ? AUDIO_CHANNEL_IN_MONO : AUDIO_CHANNEL_IN_STEREO);
|
||||||
common->cfg.format = AUDIO_STREAM_DEFAULT_FORMAT;
|
common->cfg.format = AUDIO_STREAM_DEFAULT_FORMAT;
|
||||||
@ -399,14 +391,13 @@ static void a2dp_open_ctrl_path(struct a2dp_stream_common *common)
|
|||||||
int i;
|
int i;
|
||||||
|
|
||||||
/* retry logic to catch any timing variations on control channel */
|
/* retry logic to catch any timing variations on control channel */
|
||||||
for (i = 0; i < CTRL_CHAN_RETRY_COUNT; i++)
|
for (i = 0; i < CTRL_CHAN_RETRY_COUNT; i++) {
|
||||||
{
|
|
||||||
/* connect control channel if not already connected */
|
/* connect control channel if not already connected */
|
||||||
if ((common->ctrl_fd = skt_connect(A2DP_CTRL_PATH, common->buffer_sz)) > 0)
|
if ((common->ctrl_fd = skt_connect(A2DP_CTRL_PATH, common->buffer_sz)) > 0) {
|
||||||
{
|
|
||||||
/* success, now check if stack is ready */
|
/* success, now check if stack is ready */
|
||||||
if (check_a2dp_ready(common) == 0)
|
if (check_a2dp_ready(common) == 0) {
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
ERROR("error : a2dp not ready, wait 250 ms and retry");
|
ERROR("error : a2dp not ready, wait 250 ms and retry");
|
||||||
usleep(250000);
|
usleep(250000);
|
||||||
@ -456,26 +447,21 @@ static int start_audio_datapath(struct a2dp_stream_common *common)
|
|||||||
common->state = AUDIO_A2DP_STATE_STARTING;
|
common->state = AUDIO_A2DP_STATE_STARTING;
|
||||||
|
|
||||||
int a2dp_status = a2dp_command(common, A2DP_CTRL_CMD_START);
|
int a2dp_status = a2dp_command(common, A2DP_CTRL_CMD_START);
|
||||||
if (a2dp_status < 0)
|
if (a2dp_status < 0) {
|
||||||
{
|
|
||||||
ERROR("%s Audiopath start failed (status %d)", __func__, a2dp_status);
|
ERROR("%s Audiopath start failed (status %d)", __func__, a2dp_status);
|
||||||
|
|
||||||
common->state = oldstate;
|
common->state = oldstate;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
} else if (a2dp_status == A2DP_CTRL_ACK_INCALL_FAILURE) {
|
||||||
else if (a2dp_status == A2DP_CTRL_ACK_INCALL_FAILURE)
|
|
||||||
{
|
|
||||||
ERROR("%s Audiopath start failed - in call, move to suspended", __func__);
|
ERROR("%s Audiopath start failed - in call, move to suspended", __func__);
|
||||||
common->state = oldstate;
|
common->state = oldstate;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* connect socket if not yet connected */
|
/* connect socket if not yet connected */
|
||||||
if (common->audio_fd == AUDIO_SKT_DISCONNECTED)
|
if (common->audio_fd == AUDIO_SKT_DISCONNECTED) {
|
||||||
{
|
|
||||||
common->audio_fd = skt_connect(A2DP_DATA_PATH, common->buffer_sz);
|
common->audio_fd = skt_connect(A2DP_DATA_PATH, common->buffer_sz);
|
||||||
if (common->audio_fd < 0)
|
if (common->audio_fd < 0) {
|
||||||
{
|
|
||||||
common->state = oldstate;
|
common->state = oldstate;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -492,15 +478,15 @@ static int stop_audio_datapath(struct a2dp_stream_common *common)
|
|||||||
|
|
||||||
INFO("state %d", common->state);
|
INFO("state %d", common->state);
|
||||||
|
|
||||||
if (common->ctrl_fd == AUDIO_SKT_DISCONNECTED)
|
if (common->ctrl_fd == AUDIO_SKT_DISCONNECTED) {
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
/* prevent any stray output writes from autostarting the stream
|
/* prevent any stray output writes from autostarting the stream
|
||||||
while stopping audiopath */
|
while stopping audiopath */
|
||||||
common->state = AUDIO_A2DP_STATE_STOPPING;
|
common->state = AUDIO_A2DP_STATE_STOPPING;
|
||||||
|
|
||||||
if (a2dp_command(common, A2DP_CTRL_CMD_STOP) < 0)
|
if (a2dp_command(common, A2DP_CTRL_CMD_STOP) < 0) {
|
||||||
{
|
|
||||||
ERROR("audiopath stop failed");
|
ERROR("audiopath stop failed");
|
||||||
common->state = oldstate;
|
common->state = oldstate;
|
||||||
return -1;
|
return -1;
|
||||||
@ -519,19 +505,23 @@ static int suspend_audio_datapath(struct a2dp_stream_common *common, bool standb
|
|||||||
{
|
{
|
||||||
INFO("state %d", common->state);
|
INFO("state %d", common->state);
|
||||||
|
|
||||||
if (common->ctrl_fd == AUDIO_SKT_DISCONNECTED)
|
if (common->ctrl_fd == AUDIO_SKT_DISCONNECTED) {
|
||||||
return -1;
|
|
||||||
|
|
||||||
if (common->state == AUDIO_A2DP_STATE_STOPPING)
|
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
if (a2dp_command(common, A2DP_CTRL_CMD_SUSPEND) < 0)
|
if (common->state == AUDIO_A2DP_STATE_STOPPING) {
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
if (standby)
|
if (a2dp_command(common, A2DP_CTRL_CMD_SUSPEND) < 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (standby) {
|
||||||
common->state = AUDIO_A2DP_STATE_STANDBY;
|
common->state = AUDIO_A2DP_STATE_STANDBY;
|
||||||
else
|
} else {
|
||||||
common->state = AUDIO_A2DP_STATE_SUSPENDED;
|
common->state = AUDIO_A2DP_STATE_SUSPENDED;
|
||||||
|
}
|
||||||
|
|
||||||
/* disconnect audio path */
|
/* disconnect audio path */
|
||||||
skt_disconnect(common->audio_fd);
|
skt_disconnect(common->audio_fd);
|
||||||
@ -548,7 +538,7 @@ static int suspend_audio_datapath(struct a2dp_stream_common *common, bool standb
|
|||||||
**
|
**
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
|
||||||
static ssize_t out_write(struct audio_stream_out *stream, const void* buffer,
|
static ssize_t out_write(struct audio_stream_out *stream, const void *buffer,
|
||||||
size_t bytes)
|
size_t bytes)
|
||||||
{
|
{
|
||||||
struct a2dp_stream_out *out = (struct a2dp_stream_out *)stream;
|
struct a2dp_stream_out *out = (struct a2dp_stream_out *)stream;
|
||||||
@ -558,8 +548,7 @@ static ssize_t out_write(struct audio_stream_out *stream, const void* buffer,
|
|||||||
|
|
||||||
pthread_mutex_lock(&out->common.lock);
|
pthread_mutex_lock(&out->common.lock);
|
||||||
|
|
||||||
if (out->common.state == AUDIO_A2DP_STATE_SUSPENDED)
|
if (out->common.state == AUDIO_A2DP_STATE_SUSPENDED) {
|
||||||
{
|
|
||||||
DEBUG("stream suspended");
|
DEBUG("stream suspended");
|
||||||
pthread_mutex_unlock(&out->common.lock);
|
pthread_mutex_unlock(&out->common.lock);
|
||||||
return -1;
|
return -1;
|
||||||
@ -567,10 +556,8 @@ static ssize_t out_write(struct audio_stream_out *stream, const void* buffer,
|
|||||||
|
|
||||||
/* only allow autostarting if we are in stopped or standby */
|
/* only allow autostarting if we are in stopped or standby */
|
||||||
if ((out->common.state == AUDIO_A2DP_STATE_STOPPED) ||
|
if ((out->common.state == AUDIO_A2DP_STATE_STOPPED) ||
|
||||||
(out->common.state == AUDIO_A2DP_STATE_STANDBY))
|
(out->common.state == AUDIO_A2DP_STATE_STANDBY)) {
|
||||||
{
|
if (start_audio_datapath(&out->common) < 0) {
|
||||||
if (start_audio_datapath(&out->common) < 0)
|
|
||||||
{
|
|
||||||
/* emulate time this write represents to avoid very fast write
|
/* emulate time this write represents to avoid very fast write
|
||||||
failures during transition periods or remote suspend */
|
failures during transition periods or remote suspend */
|
||||||
|
|
||||||
@ -582,9 +569,7 @@ static ssize_t out_write(struct audio_stream_out *stream, const void* buffer,
|
|||||||
pthread_mutex_unlock(&out->common.lock);
|
pthread_mutex_unlock(&out->common.lock);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
} else if (out->common.state != AUDIO_A2DP_STATE_STARTED) {
|
||||||
else if (out->common.state != AUDIO_A2DP_STATE_STARTED)
|
|
||||||
{
|
|
||||||
ERROR("stream not in stopped or standby");
|
ERROR("stream not in stopped or standby");
|
||||||
pthread_mutex_unlock(&out->common.lock);
|
pthread_mutex_unlock(&out->common.lock);
|
||||||
return -1;
|
return -1;
|
||||||
@ -596,10 +581,11 @@ static ssize_t out_write(struct audio_stream_out *stream, const void* buffer,
|
|||||||
if (sent == -1) {
|
if (sent == -1) {
|
||||||
skt_disconnect(out->common.audio_fd);
|
skt_disconnect(out->common.audio_fd);
|
||||||
out->common.audio_fd = AUDIO_SKT_DISCONNECTED;
|
out->common.audio_fd = AUDIO_SKT_DISCONNECTED;
|
||||||
if (out->common.state != AUDIO_A2DP_STATE_SUSPENDED)
|
if (out->common.state != AUDIO_A2DP_STATE_SUSPENDED) {
|
||||||
out->common.state = AUDIO_A2DP_STATE_STOPPED;
|
out->common.state = AUDIO_A2DP_STATE_STOPPED;
|
||||||
else
|
} else {
|
||||||
ERROR("write failed : stream suspended, avoid resetting state");
|
ERROR("write failed : stream suspended, avoid resetting state");
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
const size_t frames = bytes / audio_stream_out_frame_size(stream);
|
const size_t frames = bytes / audio_stream_out_frame_size(stream);
|
||||||
out->frames_rendered += frames;
|
out->frames_rendered += frames;
|
||||||
@ -615,7 +601,7 @@ static uint32_t out_get_sample_rate(const struct audio_stream *stream)
|
|||||||
{
|
{
|
||||||
struct a2dp_stream_out *out = (struct a2dp_stream_out *)stream;
|
struct a2dp_stream_out *out = (struct a2dp_stream_out *)stream;
|
||||||
|
|
||||||
DEBUG("rate %" PRIu32,out->common.cfg.rate);
|
DEBUG("rate %" PRIu32, out->common.cfg.rate);
|
||||||
|
|
||||||
return out->common.cfg.rate;
|
return out->common.cfg.rate;
|
||||||
}
|
}
|
||||||
@ -626,8 +612,7 @@ static int out_set_sample_rate(struct audio_stream *stream, uint32_t rate)
|
|||||||
|
|
||||||
DEBUG("out_set_sample_rate : %" PRIu32, rate);
|
DEBUG("out_set_sample_rate : %" PRIu32, rate);
|
||||||
|
|
||||||
if (rate != AUDIO_STREAM_DEFAULT_RATE)
|
if (rate != AUDIO_STREAM_DEFAULT_RATE) {
|
||||||
{
|
|
||||||
ERROR("only rate %d supported", AUDIO_STREAM_DEFAULT_RATE);
|
ERROR("only rate %d supported", AUDIO_STREAM_DEFAULT_RATE);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -679,8 +664,9 @@ static int out_standby(struct audio_stream *stream)
|
|||||||
|
|
||||||
pthread_mutex_lock(&out->common.lock);
|
pthread_mutex_lock(&out->common.lock);
|
||||||
// Do nothing in SUSPENDED state.
|
// Do nothing in SUSPENDED state.
|
||||||
if (out->common.state != AUDIO_A2DP_STATE_SUSPENDED)
|
if (out->common.state != AUDIO_A2DP_STATE_SUSPENDED) {
|
||||||
retVal = suspend_audio_datapath(&out->common, true);
|
retVal = suspend_audio_datapath(&out->common, true);
|
||||||
|
}
|
||||||
out->frames_rendered = 0; // rendered is reset, presented is not
|
out->frames_rendered = 0; // rendered is reset, presented is not
|
||||||
pthread_mutex_unlock (&out->common.lock);
|
pthread_mutex_unlock (&out->common.lock);
|
||||||
|
|
||||||
@ -712,10 +698,8 @@ static int out_set_parameters(struct audio_stream *stream, const char *kvpairs)
|
|||||||
|
|
||||||
retval = str_parms_get_str(parms, "closing", keyval, sizeof(keyval));
|
retval = str_parms_get_str(parms, "closing", keyval, sizeof(keyval));
|
||||||
|
|
||||||
if (retval >= 0)
|
if (retval >= 0) {
|
||||||
{
|
if (strcmp(keyval, "true") == 0) {
|
||||||
if (strcmp(keyval, "true") == 0)
|
|
||||||
{
|
|
||||||
DEBUG("stream closing, disallow any writes");
|
DEBUG("stream closing, disallow any writes");
|
||||||
pthread_mutex_lock(&out->common.lock);
|
pthread_mutex_lock(&out->common.lock);
|
||||||
out->common.state = AUDIO_A2DP_STATE_STOPPING;
|
out->common.state = AUDIO_A2DP_STATE_STOPPING;
|
||||||
@ -725,21 +709,19 @@ static int out_set_parameters(struct audio_stream *stream, const char *kvpairs)
|
|||||||
|
|
||||||
retval = str_parms_get_str(parms, "A2dpSuspended", keyval, sizeof(keyval));
|
retval = str_parms_get_str(parms, "A2dpSuspended", keyval, sizeof(keyval));
|
||||||
|
|
||||||
if (retval >= 0)
|
if (retval >= 0) {
|
||||||
{
|
|
||||||
pthread_mutex_lock(&out->common.lock);
|
pthread_mutex_lock(&out->common.lock);
|
||||||
if (strcmp(keyval, "true") == 0)
|
if (strcmp(keyval, "true") == 0) {
|
||||||
{
|
if (out->common.state == AUDIO_A2DP_STATE_STARTED) {
|
||||||
if (out->common.state == AUDIO_A2DP_STATE_STARTED)
|
|
||||||
status = suspend_audio_datapath(&out->common, false);
|
status = suspend_audio_datapath(&out->common, false);
|
||||||
}
|
}
|
||||||
else
|
} else {
|
||||||
{
|
|
||||||
/* Do not start the streaming automatically. If the phone was streaming
|
/* Do not start the streaming automatically. If the phone was streaming
|
||||||
* prior to being suspended, the next out_write shall trigger the
|
* prior to being suspended, the next out_write shall trigger the
|
||||||
* AVDTP start procedure */
|
* AVDTP start procedure */
|
||||||
if (out->common.state == AUDIO_A2DP_STATE_SUSPENDED)
|
if (out->common.state == AUDIO_A2DP_STATE_SUSPENDED) {
|
||||||
out->common.state = AUDIO_A2DP_STATE_STANDBY;
|
out->common.state = AUDIO_A2DP_STATE_STANDBY;
|
||||||
|
}
|
||||||
/* Irrespective of the state, return 0 */
|
/* Irrespective of the state, return 0 */
|
||||||
}
|
}
|
||||||
pthread_mutex_unlock(&out->common.lock);
|
pthread_mutex_unlock(&out->common.lock);
|
||||||
@ -750,7 +732,7 @@ static int out_set_parameters(struct audio_stream *stream, const char *kvpairs)
|
|||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char * out_get_parameters(const struct audio_stream *stream, const char *keys)
|
static char *out_get_parameters(const struct audio_stream *stream, const char *keys)
|
||||||
{
|
{
|
||||||
UNUSED(keys);
|
UNUSED(keys);
|
||||||
struct a2dp_stream_out *out = (struct a2dp_stream_out *)stream;
|
struct a2dp_stream_out *out = (struct a2dp_stream_out *)stream;
|
||||||
@ -771,8 +753,8 @@ static uint32_t out_get_latency(const struct audio_stream_out *stream)
|
|||||||
FNLOG();
|
FNLOG();
|
||||||
|
|
||||||
latency_us = ((out->common.buffer_sz * 1000 ) /
|
latency_us = ((out->common.buffer_sz * 1000 ) /
|
||||||
audio_stream_out_frame_size(&out->stream) /
|
audio_stream_out_frame_size(&out->stream) /
|
||||||
out->common.cfg.rate) * 1000;
|
out->common.cfg.rate) * 1000;
|
||||||
|
|
||||||
|
|
||||||
return (latency_us / 1000) + 200;
|
return (latency_us / 1000) + 200;
|
||||||
@ -793,13 +775,14 @@ static int out_set_volume(struct audio_stream_out *stream, float left,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int out_get_presentation_position(const struct audio_stream_out *stream,
|
static int out_get_presentation_position(const struct audio_stream_out *stream,
|
||||||
uint64_t *frames, struct timespec *timestamp)
|
uint64_t *frames, struct timespec *timestamp)
|
||||||
{
|
{
|
||||||
struct a2dp_stream_out *out = (struct a2dp_stream_out *)stream;
|
struct a2dp_stream_out *out = (struct a2dp_stream_out *)stream;
|
||||||
|
|
||||||
FNLOG();
|
FNLOG();
|
||||||
if (stream == NULL || frames == NULL || timestamp == NULL)
|
if (stream == NULL || frames == NULL || timestamp == NULL) {
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
int ret = -EWOULDBLOCK;
|
int ret = -EWOULDBLOCK;
|
||||||
pthread_mutex_lock(&out->common.lock);
|
pthread_mutex_lock(&out->common.lock);
|
||||||
@ -819,8 +802,9 @@ static int out_get_render_position(const struct audio_stream_out *stream,
|
|||||||
struct a2dp_stream_out *out = (struct a2dp_stream_out *)stream;
|
struct a2dp_stream_out *out = (struct a2dp_stream_out *)stream;
|
||||||
|
|
||||||
FNLOG();
|
FNLOG();
|
||||||
if (stream == NULL || dsp_frames == NULL)
|
if (stream == NULL || dsp_frames == NULL) {
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
pthread_mutex_lock(&out->common.lock);
|
pthread_mutex_lock(&out->common.lock);
|
||||||
uint64_t latency_frames = (uint64_t)out_get_latency(stream) * out->common.cfg.rate / 1000;
|
uint64_t latency_frames = (uint64_t)out_get_latency(stream) * out->common.cfg.rate / 1000;
|
||||||
@ -869,10 +853,11 @@ static int in_set_sample_rate(struct audio_stream *stream, uint32_t rate)
|
|||||||
|
|
||||||
FNLOG();
|
FNLOG();
|
||||||
|
|
||||||
if (in->common.cfg.rate > 0 && in->common.cfg.rate == rate)
|
if (in->common.cfg.rate > 0 && in->common.cfg.rate == rate) {
|
||||||
return 0;
|
return 0;
|
||||||
else
|
} else {
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static size_t in_get_buffer_size(const struct audio_stream *stream)
|
static size_t in_get_buffer_size(const struct audio_stream *stream)
|
||||||
@ -905,10 +890,11 @@ static int in_set_format(struct audio_stream *stream, audio_format_t format)
|
|||||||
UNUSED(format);
|
UNUSED(format);
|
||||||
|
|
||||||
FNLOG();
|
FNLOG();
|
||||||
if (format == AUDIO_FORMAT_PCM_16_BIT)
|
if (format == AUDIO_FORMAT_PCM_16_BIT) {
|
||||||
return 0;
|
return 0;
|
||||||
else
|
} else {
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int in_standby(struct audio_stream *stream)
|
static int in_standby(struct audio_stream *stream)
|
||||||
@ -937,8 +923,8 @@ static int in_set_parameters(struct audio_stream *stream, const char *kvpairs)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char * in_get_parameters(const struct audio_stream *stream,
|
static char *in_get_parameters(const struct audio_stream *stream,
|
||||||
const char *keys)
|
const char *keys)
|
||||||
{
|
{
|
||||||
UNUSED(stream);
|
UNUSED(stream);
|
||||||
UNUSED(keys);
|
UNUSED(keys);
|
||||||
@ -956,7 +942,7 @@ static int in_set_gain(struct audio_stream_in *stream, float gain)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static ssize_t in_read(struct audio_stream_in *stream, void* buffer,
|
static ssize_t in_read(struct audio_stream_in *stream, void *buffer,
|
||||||
size_t bytes)
|
size_t bytes)
|
||||||
{
|
{
|
||||||
struct a2dp_stream_in *in = (struct a2dp_stream_in *)stream;
|
struct a2dp_stream_in *in = (struct a2dp_stream_in *)stream;
|
||||||
@ -964,20 +950,17 @@ static ssize_t in_read(struct audio_stream_in *stream, void* buffer,
|
|||||||
|
|
||||||
DEBUG("read %zu bytes, state: %d", bytes, in->common.state);
|
DEBUG("read %zu bytes, state: %d", bytes, in->common.state);
|
||||||
|
|
||||||
if (in->common.state == AUDIO_A2DP_STATE_SUSPENDED)
|
if (in->common.state == AUDIO_A2DP_STATE_SUSPENDED) {
|
||||||
{
|
|
||||||
DEBUG("stream suspended");
|
DEBUG("stream suspended");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* only allow autostarting if we are in stopped or standby */
|
/* only allow autostarting if we are in stopped or standby */
|
||||||
if ((in->common.state == AUDIO_A2DP_STATE_STOPPED) ||
|
if ((in->common.state == AUDIO_A2DP_STATE_STOPPED) ||
|
||||||
(in->common.state == AUDIO_A2DP_STATE_STANDBY))
|
(in->common.state == AUDIO_A2DP_STATE_STANDBY)) {
|
||||||
{
|
|
||||||
pthread_mutex_lock(&in->common.lock);
|
pthread_mutex_lock(&in->common.lock);
|
||||||
|
|
||||||
if (start_audio_datapath(&in->common) < 0)
|
if (start_audio_datapath(&in->common) < 0) {
|
||||||
{
|
|
||||||
/* emulate time this write represents to avoid very fast write
|
/* emulate time this write represents to avoid very fast write
|
||||||
failures during transition periods or remote suspend */
|
failures during transition periods or remote suspend */
|
||||||
|
|
||||||
@ -991,17 +974,14 @@ static ssize_t in_read(struct audio_stream_in *stream, void* buffer,
|
|||||||
}
|
}
|
||||||
|
|
||||||
pthread_mutex_unlock(&in->common.lock);
|
pthread_mutex_unlock(&in->common.lock);
|
||||||
}
|
} else if (in->common.state != AUDIO_A2DP_STATE_STARTED) {
|
||||||
else if (in->common.state != AUDIO_A2DP_STATE_STARTED)
|
|
||||||
{
|
|
||||||
ERROR("stream not in stopped or standby");
|
ERROR("stream not in stopped or standby");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
read = skt_read(in->common.audio_fd, buffer, bytes);
|
read = skt_read(in->common.audio_fd, buffer, bytes);
|
||||||
|
|
||||||
if (read == -1)
|
if (read == -1) {
|
||||||
{
|
|
||||||
skt_disconnect(in->common.audio_fd);
|
skt_disconnect(in->common.audio_fd);
|
||||||
in->common.audio_fd = AUDIO_SKT_DISCONNECTED;
|
in->common.audio_fd = AUDIO_SKT_DISCONNECTED;
|
||||||
in->common.state = AUDIO_A2DP_STATE_STOPPED;
|
in->common.state = AUDIO_A2DP_STATE_STOPPED;
|
||||||
@ -1064,8 +1044,9 @@ static int adev_open_output_stream(struct audio_hw_device *dev,
|
|||||||
|
|
||||||
out = (struct a2dp_stream_out *)calloc(1, sizeof(struct a2dp_stream_out));
|
out = (struct a2dp_stream_out *)calloc(1, sizeof(struct a2dp_stream_out));
|
||||||
|
|
||||||
if (!out)
|
if (!out) {
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
}
|
||||||
|
|
||||||
out->stream.common.get_sample_rate = out_get_sample_rate;
|
out->stream.common.get_sample_rate = out_get_sample_rate;
|
||||||
out->stream.common.set_sample_rate = out_set_sample_rate;
|
out->stream.common.set_sample_rate = out_set_sample_rate;
|
||||||
@ -1093,19 +1074,17 @@ static int adev_open_output_stream(struct audio_hw_device *dev,
|
|||||||
out->common.cfg.format = AUDIO_STREAM_DEFAULT_FORMAT;
|
out->common.cfg.format = AUDIO_STREAM_DEFAULT_FORMAT;
|
||||||
out->common.cfg.rate = AUDIO_STREAM_DEFAULT_RATE;
|
out->common.cfg.rate = AUDIO_STREAM_DEFAULT_RATE;
|
||||||
|
|
||||||
/* set output config values */
|
/* set output config values */
|
||||||
if (config)
|
if (config) {
|
||||||
{
|
config->format = out_get_format((const struct audio_stream *)&out->stream);
|
||||||
config->format = out_get_format((const struct audio_stream *)&out->stream);
|
config->sample_rate = out_get_sample_rate((const struct audio_stream *)&out->stream);
|
||||||
config->sample_rate = out_get_sample_rate((const struct audio_stream *)&out->stream);
|
config->channel_mask = out_get_channels((const struct audio_stream *)&out->stream);
|
||||||
config->channel_mask = out_get_channels((const struct audio_stream *)&out->stream);
|
}
|
||||||
}
|
|
||||||
*stream_out = &out->stream;
|
*stream_out = &out->stream;
|
||||||
a2dp_dev->output = out;
|
a2dp_dev->output = out;
|
||||||
|
|
||||||
a2dp_open_ctrl_path(&out->common);
|
a2dp_open_ctrl_path(&out->common);
|
||||||
if (out->common.ctrl_fd == AUDIO_SKT_DISCONNECTED)
|
if (out->common.ctrl_fd == AUDIO_SKT_DISCONNECTED) {
|
||||||
{
|
|
||||||
ERROR("ctrl socket failed to connect (%s)", strerror(errno));
|
ERROR("ctrl socket failed to connect (%s)", strerror(errno));
|
||||||
ret = -1;
|
ret = -1;
|
||||||
goto err_open;
|
goto err_open;
|
||||||
@ -1134,8 +1113,9 @@ static void adev_close_output_stream(struct audio_hw_device *dev,
|
|||||||
INFO("closing output (state %d)", out->common.state);
|
INFO("closing output (state %d)", out->common.state);
|
||||||
|
|
||||||
pthread_mutex_lock(&out->common.lock);
|
pthread_mutex_lock(&out->common.lock);
|
||||||
if ((out->common.state == AUDIO_A2DP_STATE_STARTED) || (out->common.state == AUDIO_A2DP_STATE_STOPPING))
|
if ((out->common.state == AUDIO_A2DP_STATE_STARTED) || (out->common.state == AUDIO_A2DP_STATE_STOPPING)) {
|
||||||
stop_audio_datapath(&out->common);
|
stop_audio_datapath(&out->common);
|
||||||
|
}
|
||||||
|
|
||||||
skt_disconnect(out->common.ctrl_fd);
|
skt_disconnect(out->common.ctrl_fd);
|
||||||
free(stream);
|
free(stream);
|
||||||
@ -1151,8 +1131,9 @@ static int adev_set_parameters(struct audio_hw_device *dev, const char *kvpairs)
|
|||||||
struct a2dp_stream_out *out = a2dp_dev->output;
|
struct a2dp_stream_out *out = a2dp_dev->output;
|
||||||
int retval = 0;
|
int retval = 0;
|
||||||
|
|
||||||
if (out == NULL)
|
if (out == NULL) {
|
||||||
return retval;
|
return retval;
|
||||||
|
}
|
||||||
|
|
||||||
INFO("state %d", out->common.state);
|
INFO("state %d", out->common.state);
|
||||||
|
|
||||||
@ -1161,8 +1142,8 @@ static int adev_set_parameters(struct audio_hw_device *dev, const char *kvpairs)
|
|||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char * adev_get_parameters(const struct audio_hw_device *dev,
|
static char *adev_get_parameters(const struct audio_hw_device *dev,
|
||||||
const char *keys)
|
const char *keys)
|
||||||
{
|
{
|
||||||
struct str_parms *parms;
|
struct str_parms *parms;
|
||||||
UNUSED(dev);
|
UNUSED(dev);
|
||||||
@ -1180,7 +1161,7 @@ static char * adev_get_parameters(const struct audio_hw_device *dev,
|
|||||||
|
|
||||||
static int adev_init_check(const struct audio_hw_device *dev)
|
static int adev_init_check(const struct audio_hw_device *dev)
|
||||||
{
|
{
|
||||||
struct a2dp_audio_device *a2dp_dev = (struct a2dp_audio_device*)dev;
|
struct a2dp_audio_device *a2dp_dev = (struct a2dp_audio_device *)dev;
|
||||||
|
|
||||||
FNLOG();
|
FNLOG();
|
||||||
|
|
||||||
@ -1238,7 +1219,7 @@ static int adev_get_mic_mute(const struct audio_hw_device *dev, bool *state)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static size_t adev_get_input_buffer_size(const struct audio_hw_device *dev,
|
static size_t adev_get_input_buffer_size(const struct audio_hw_device *dev,
|
||||||
const struct audio_config *config)
|
const struct audio_config *config)
|
||||||
{
|
{
|
||||||
UNUSED(dev);
|
UNUSED(dev);
|
||||||
UNUSED(config);
|
UNUSED(config);
|
||||||
@ -1271,8 +1252,9 @@ static int adev_open_input_stream(struct audio_hw_device *dev,
|
|||||||
|
|
||||||
in = (struct a2dp_stream_in *)calloc(1, sizeof(struct a2dp_stream_in));
|
in = (struct a2dp_stream_in *)calloc(1, sizeof(struct a2dp_stream_in));
|
||||||
|
|
||||||
if (!in)
|
if (!in) {
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
}
|
||||||
|
|
||||||
in->stream.common.get_sample_rate = in_get_sample_rate;
|
in->stream.common.get_sample_rate = in_get_sample_rate;
|
||||||
in->stream.common.set_sample_rate = in_set_sample_rate;
|
in->stream.common.set_sample_rate = in_set_sample_rate;
|
||||||
@ -1297,8 +1279,7 @@ static int adev_open_input_stream(struct audio_hw_device *dev,
|
|||||||
a2dp_dev->input = in;
|
a2dp_dev->input = in;
|
||||||
|
|
||||||
a2dp_open_ctrl_path(&in->common);
|
a2dp_open_ctrl_path(&in->common);
|
||||||
if (in->common.ctrl_fd == AUDIO_SKT_DISCONNECTED)
|
if (in->common.ctrl_fd == AUDIO_SKT_DISCONNECTED) {
|
||||||
{
|
|
||||||
ERROR("ctrl socket failed to connect (%s)", strerror(errno));
|
ERROR("ctrl socket failed to connect (%s)", strerror(errno));
|
||||||
ret = -1;
|
ret = -1;
|
||||||
goto err_open;
|
goto err_open;
|
||||||
@ -1322,16 +1303,17 @@ err_open:
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void adev_close_input_stream(struct audio_hw_device *dev,
|
static void adev_close_input_stream(struct audio_hw_device *dev,
|
||||||
struct audio_stream_in *stream)
|
struct audio_stream_in *stream)
|
||||||
{
|
{
|
||||||
struct a2dp_audio_device *a2dp_dev = (struct a2dp_audio_device *)dev;
|
struct a2dp_audio_device *a2dp_dev = (struct a2dp_audio_device *)dev;
|
||||||
struct a2dp_stream_in* in = (struct a2dp_stream_in *)stream;
|
struct a2dp_stream_in *in = (struct a2dp_stream_in *)stream;
|
||||||
a2dp_state_t state = in->common.state;
|
a2dp_state_t state = in->common.state;
|
||||||
|
|
||||||
INFO("closing input (state %d)", state);
|
INFO("closing input (state %d)", state);
|
||||||
|
|
||||||
if ((state == AUDIO_A2DP_STATE_STARTED) || (state == AUDIO_A2DP_STATE_STOPPING))
|
if ((state == AUDIO_A2DP_STATE_STARTED) || (state == AUDIO_A2DP_STATE_STOPPING)) {
|
||||||
stop_audio_datapath(&in->common);
|
stop_audio_datapath(&in->common);
|
||||||
|
}
|
||||||
|
|
||||||
skt_disconnect(in->common.ctrl_fd);
|
skt_disconnect(in->common.ctrl_fd);
|
||||||
free(stream);
|
free(stream);
|
||||||
@ -1358,8 +1340,8 @@ static int adev_close(hw_device_t *device)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int adev_open(const hw_module_t* module, const char* name,
|
static int adev_open(const hw_module_t *module, const char *name,
|
||||||
hw_device_t** device)
|
hw_device_t **device)
|
||||||
{
|
{
|
||||||
struct a2dp_audio_device *adev;
|
struct a2dp_audio_device *adev;
|
||||||
int ret;
|
int ret;
|
||||||
@ -1367,16 +1349,16 @@ static int adev_open(const hw_module_t* module, const char* name,
|
|||||||
INFO(" adev_open in A2dp_hw module");
|
INFO(" adev_open in A2dp_hw module");
|
||||||
FNLOG();
|
FNLOG();
|
||||||
|
|
||||||
if (strcmp(name, AUDIO_HARDWARE_INTERFACE) != 0)
|
if (strcmp(name, AUDIO_HARDWARE_INTERFACE) != 0) {
|
||||||
{
|
|
||||||
ERROR("interface %s not matching [%s]", name, AUDIO_HARDWARE_INTERFACE);
|
ERROR("interface %s not matching [%s]", name, AUDIO_HARDWARE_INTERFACE);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
adev = calloc(1, sizeof(struct a2dp_audio_device));
|
adev = calloc(1, sizeof(struct a2dp_audio_device));
|
||||||
|
|
||||||
if (!adev)
|
if (!adev) {
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
}
|
||||||
|
|
||||||
adev->device.common.tag = HARDWARE_DEVICE_TAG;
|
adev->device.common.tag = HARDWARE_DEVICE_TAG;
|
||||||
adev->device.common.version = AUDIO_DEVICE_API_VERSION_2_0;
|
adev->device.common.version = AUDIO_DEVICE_API_VERSION_2_0;
|
||||||
|
File diff suppressed because it is too large
Load Diff
1082
examples/09_a2dp/components/bluedroid_demos/btif/btif_avk.c
Executable file → Normal file
1082
examples/09_a2dp/components/bluedroid_demos/btif/btif_avk.c
Executable file → Normal file
File diff suppressed because it is too large
Load Diff
52
examples/09_a2dp/components/bluedroid_demos/btif/btif_core.c
Executable file → Normal file
52
examples/09_a2dp/components/bluedroid_demos/btif/btif_core.c
Executable file → Normal file
@ -118,8 +118,9 @@ static void btif_context_switched(void *p_msg)
|
|||||||
tBTIF_CONTEXT_SWITCH_CBACK *p = (tBTIF_CONTEXT_SWITCH_CBACK *) p_msg;
|
tBTIF_CONTEXT_SWITCH_CBACK *p = (tBTIF_CONTEXT_SWITCH_CBACK *) p_msg;
|
||||||
|
|
||||||
/* each callback knows how to parse the data */
|
/* each callback knows how to parse the data */
|
||||||
if (p->p_cb)
|
if (p->p_cb) {
|
||||||
p->p_cb(p->event, p->p_param);
|
p->p_cb(p->event, p->p_param);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -139,35 +140,29 @@ static void btif_context_switched(void *p_msg)
|
|||||||
**
|
**
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
bt_status_t btif_transfer_context (tBTIF_CBACK *p_cback, UINT16 event, char* p_params, int param_len, tBTIF_COPY_CBACK *p_copy_cback)
|
bt_status_t btif_transfer_context (tBTIF_CBACK *p_cback, UINT16 event, char *p_params, int param_len, tBTIF_COPY_CBACK *p_copy_cback)
|
||||||
{
|
{
|
||||||
tBTIF_CONTEXT_SWITCH_CBACK *p_msg;
|
tBTIF_CONTEXT_SWITCH_CBACK *p_msg;
|
||||||
|
|
||||||
BTIF_TRACE_VERBOSE("btif_transfer_context event %d, len %d", event, param_len);
|
BTIF_TRACE_VERBOSE("btif_transfer_context event %d, len %d", event, param_len);
|
||||||
|
|
||||||
/* allocate and send message that will be executed in btif context */
|
/* allocate and send message that will be executed in btif context */
|
||||||
if ((p_msg = (tBTIF_CONTEXT_SWITCH_CBACK *) GKI_getbuf(sizeof(tBTIF_CONTEXT_SWITCH_CBACK) + param_len)) != NULL)
|
if ((p_msg = (tBTIF_CONTEXT_SWITCH_CBACK *) GKI_getbuf(sizeof(tBTIF_CONTEXT_SWITCH_CBACK) + param_len)) != NULL) {
|
||||||
{
|
|
||||||
p_msg->hdr.event = BT_EVT_CONTEXT_SWITCH_EVT; /* internal event */
|
p_msg->hdr.event = BT_EVT_CONTEXT_SWITCH_EVT; /* internal event */
|
||||||
p_msg->p_cb = p_cback;
|
p_msg->p_cb = p_cback;
|
||||||
|
|
||||||
p_msg->event = event; /* callback event */
|
p_msg->event = event; /* callback event */
|
||||||
|
|
||||||
/* check if caller has provided a copy callback to do the deep copy */
|
/* check if caller has provided a copy callback to do the deep copy */
|
||||||
if (p_copy_cback)
|
if (p_copy_cback) {
|
||||||
{
|
|
||||||
p_copy_cback(event, p_msg->p_param, p_params);
|
p_copy_cback(event, p_msg->p_param, p_params);
|
||||||
}
|
} else if (p_params) {
|
||||||
else if (p_params)
|
|
||||||
{
|
|
||||||
memcpy(p_msg->p_param, p_params, param_len); /* callback parameter data */
|
memcpy(p_msg->p_param, p_params, param_len); /* callback parameter data */
|
||||||
}
|
}
|
||||||
|
|
||||||
btif_sendmsg(p_msg);
|
btif_sendmsg(p_msg);
|
||||||
return BT_STATUS_SUCCESS;
|
return BT_STATUS_SUCCESS;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
/* let caller deal with a failed allocation */
|
/* let caller deal with a failed allocation */
|
||||||
return BT_STATUS_NOMEM;
|
return BT_STATUS_NOMEM;
|
||||||
}
|
}
|
||||||
@ -178,7 +173,8 @@ int btif_is_enabled(void)
|
|||||||
return (stack_manager_is_stack_running());
|
return (stack_manager_is_stack_running());
|
||||||
}
|
}
|
||||||
|
|
||||||
void btif_init_ok(void) {
|
void btif_init_ok(void)
|
||||||
|
{
|
||||||
BTIF_TRACE_DEBUG("btif_task: received trigger stack init event");
|
BTIF_TRACE_DEBUG("btif_task: received trigger stack init event");
|
||||||
future_ready(stack_manager_get_hack_future(), FUTURE_SUCCESS);
|
future_ready(stack_manager_get_hack_future(), FUTURE_SUCCESS);
|
||||||
}
|
}
|
||||||
@ -233,11 +229,12 @@ void btif_disable_bluetooth_evt(void)
|
|||||||
** Returns void
|
** Returns void
|
||||||
**
|
**
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
static void bt_jni_msg_ready(fixed_queue_t *queue) {
|
static void bt_jni_msg_ready(fixed_queue_t *queue)
|
||||||
|
{
|
||||||
BT_HDR *p_msg;
|
BT_HDR *p_msg;
|
||||||
while (!fixed_queue_is_empty(queue)) {
|
while (!fixed_queue_is_empty(queue)) {
|
||||||
p_msg = (BT_HDR *)fixed_queue_dequeue(queue);
|
p_msg = (BT_HDR *)fixed_queue_dequeue(queue);
|
||||||
BTIF_TRACE_VERBOSE("btif task fetched event %x", p_msg->event);
|
BTIF_TRACE_VERBOSE("btif task fetched event %x", p_msg->event);
|
||||||
switch (p_msg->event) {
|
switch (p_msg->event) {
|
||||||
case BT_EVT_CONTEXT_SWITCH_EVT:
|
case BT_EVT_CONTEXT_SWITCH_EVT:
|
||||||
btif_context_switched(p_msg);
|
btif_context_switched(p_msg);
|
||||||
@ -265,16 +262,18 @@ void btif_sendmsg(void *p_msg)
|
|||||||
btif_thread_post(SIG_BTIF_WORK);
|
btif_thread_post(SIG_BTIF_WORK);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void btif_thread_post(uint32_t sig) {
|
static void btif_thread_post(uint32_t sig)
|
||||||
|
{
|
||||||
BtTaskEvt_t *evt = (BtTaskEvt_t *)osi_malloc(sizeof(BtTaskEvt_t));
|
BtTaskEvt_t *evt = (BtTaskEvt_t *)osi_malloc(sizeof(BtTaskEvt_t));
|
||||||
if (evt == NULL)
|
if (evt == NULL) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
evt->sig = sig;
|
evt->sig = sig;
|
||||||
evt->par = 0;
|
evt->par = 0;
|
||||||
|
|
||||||
if (xQueueSend(xBtifQueue, &evt, 10/portTICK_RATE_MS) != pdTRUE) {
|
if (xQueueSend(xBtifQueue, &evt, 10 / portTICK_RATE_MS) != pdTRUE) {
|
||||||
ets_printf("xBtifQueue failed\n");
|
ets_printf("xBtifQueue failed\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -308,7 +307,8 @@ void btif_task_thread_handler(void *arg)
|
|||||||
** Returns bt_status_t
|
** Returns bt_status_t
|
||||||
**
|
**
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
bt_status_t btif_init_bluetooth(void) {
|
bt_status_t btif_init_bluetooth(void)
|
||||||
|
{
|
||||||
bte_main_boot_entry(btif_init_ok);
|
bte_main_boot_entry(btif_init_ok);
|
||||||
|
|
||||||
btif_msg_queue = fixed_queue_new(SIZE_MAX);
|
btif_msg_queue = fixed_queue_new(SIZE_MAX);
|
||||||
@ -318,7 +318,7 @@ bt_status_t btif_init_bluetooth(void) {
|
|||||||
xBtifQueue = xQueueCreate(60, sizeof(void *));
|
xBtifQueue = xQueueCreate(60, sizeof(void *));
|
||||||
xTaskCreate(btif_task_thread_handler, "BtifT", 4096, NULL, configMAX_PRIORITIES - 1, &xBtifTaskHandle);
|
xTaskCreate(btif_task_thread_handler, "BtifT", 4096, NULL, configMAX_PRIORITIES - 1, &xBtifTaskHandle);
|
||||||
fixed_queue_register_dequeue(btif_msg_queue, bt_jni_msg_ready);
|
fixed_queue_register_dequeue(btif_msg_queue, bt_jni_msg_ready);
|
||||||
|
|
||||||
return BT_STATUS_SUCCESS;
|
return BT_STATUS_SUCCESS;
|
||||||
|
|
||||||
error_exit:;
|
error_exit:;
|
||||||
@ -392,10 +392,10 @@ bt_status_t btif_shutdown_bluetooth(void)
|
|||||||
|
|
||||||
vTaskDelete(xBtifTaskHandle);
|
vTaskDelete(xBtifTaskHandle);
|
||||||
xBtifTaskHandle = NULL;
|
xBtifTaskHandle = NULL;
|
||||||
|
|
||||||
vQueueDelete(xBtifQueue);
|
vQueueDelete(xBtifQueue);
|
||||||
xBtifQueue = NULL;
|
xBtifQueue = NULL;
|
||||||
|
|
||||||
bte_main_shutdown();
|
bte_main_shutdown();
|
||||||
|
|
||||||
return BT_STATUS_SUCCESS;
|
return BT_STATUS_SUCCESS;
|
||||||
@ -444,7 +444,7 @@ bt_status_t btif_enable_service(tBTA_SERVICE_ID service_id)
|
|||||||
if (btif_is_enabled()) {
|
if (btif_is_enabled()) {
|
||||||
btif_transfer_context(btif_dm_execute_service_request,
|
btif_transfer_context(btif_dm_execute_service_request,
|
||||||
BTIF_DM_ENABLE_SERVICE,
|
BTIF_DM_ENABLE_SERVICE,
|
||||||
(char*)p_id, sizeof(tBTA_SERVICE_ID), NULL);
|
(char *)p_id, sizeof(tBTA_SERVICE_ID), NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
return BT_STATUS_SUCCESS;
|
return BT_STATUS_SUCCESS;
|
||||||
@ -469,14 +469,14 @@ bt_status_t btif_disable_service(tBTA_SERVICE_ID service_id)
|
|||||||
* be triggerred. Otherwise, we just need to clear the service_id in the mask
|
* be triggerred. Otherwise, we just need to clear the service_id in the mask
|
||||||
*/
|
*/
|
||||||
|
|
||||||
btif_enabled_services &= (tBTA_SERVICE_MASK)(~(1<<service_id));
|
btif_enabled_services &= (tBTA_SERVICE_MASK)(~(1 << service_id));
|
||||||
|
|
||||||
BTIF_TRACE_DEBUG("%s: Current Services:0x%x", __FUNCTION__, btif_enabled_services);
|
BTIF_TRACE_DEBUG("%s: Current Services:0x%x", __FUNCTION__, btif_enabled_services);
|
||||||
|
|
||||||
if (btif_is_enabled()) {
|
if (btif_is_enabled()) {
|
||||||
btif_transfer_context(btif_dm_execute_service_request,
|
btif_transfer_context(btif_dm_execute_service_request,
|
||||||
BTIF_DM_DISABLE_SERVICE,
|
BTIF_DM_DISABLE_SERVICE,
|
||||||
(char*)p_id, sizeof(tBTA_SERVICE_ID), NULL);
|
(char *)p_id, sizeof(tBTA_SERVICE_ID), NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
return BT_STATUS_SUCCESS;
|
return BT_STATUS_SUCCESS;
|
||||||
|
30
examples/09_a2dp/components/bluedroid_demos/btif/btif_dm.c
Executable file → Normal file
30
examples/09_a2dp/components/bluedroid_demos/btif/btif_dm.c
Executable file → Normal file
@ -73,7 +73,7 @@
|
|||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
** Externs
|
** Externs
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
extern bt_status_t btif_sdp_execute_service(BOOLEAN b_enable);
|
// extern bt_status_t btif_sdp_execute_service(BOOLEAN b_enable);
|
||||||
extern bt_status_t btif_av_execute_service(BOOLEAN b_enable);
|
extern bt_status_t btif_av_execute_service(BOOLEAN b_enable);
|
||||||
extern bt_status_t btif_av_sink_execute_service(BOOLEAN b_enable);
|
extern bt_status_t btif_av_sink_execute_service(BOOLEAN b_enable);
|
||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
@ -82,11 +82,12 @@ extern bt_status_t btif_av_sink_execute_service(BOOLEAN b_enable);
|
|||||||
|
|
||||||
static void btif_dm_data_copy(uint16_t event, char *dst, char *src)
|
static void btif_dm_data_copy(uint16_t event, char *dst, char *src)
|
||||||
{
|
{
|
||||||
tBTA_DM_SEC *dst_dm_sec = (tBTA_DM_SEC*)dst;
|
tBTA_DM_SEC *dst_dm_sec = (tBTA_DM_SEC *)dst;
|
||||||
tBTA_DM_SEC *src_dm_sec = (tBTA_DM_SEC*)src;
|
tBTA_DM_SEC *src_dm_sec = (tBTA_DM_SEC *)src;
|
||||||
|
|
||||||
if (!src_dm_sec)
|
if (!src_dm_sec) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
assert(dst_dm_sec);
|
assert(dst_dm_sec);
|
||||||
memcpy(dst_dm_sec, src_dm_sec, sizeof(tBTA_DM_SEC));
|
memcpy(dst_dm_sec, src_dm_sec, sizeof(tBTA_DM_SEC));
|
||||||
@ -107,14 +108,11 @@ static void btif_dm_data_free(uint16_t event, tBTA_DM_SEC *dm_sec)
|
|||||||
}
|
}
|
||||||
|
|
||||||
bt_status_t btif_in_execute_service_request(tBTA_SERVICE_ID service_id,
|
bt_status_t btif_in_execute_service_request(tBTA_SERVICE_ID service_id,
|
||||||
BOOLEAN b_enable)
|
BOOLEAN b_enable)
|
||||||
{
|
{
|
||||||
BTIF_TRACE_DEBUG("%s service_id: %d\n", __FUNCTION__, service_id);
|
BTIF_TRACE_DEBUG("%s service_id: %d\n", __FUNCTION__, service_id);
|
||||||
/* Check the service_ID and invoke the profile's BT state changed API */
|
/* Check the service_ID and invoke the profile's BT state changed API */
|
||||||
switch (service_id) {
|
switch (service_id) {
|
||||||
case BTA_SDP_SERVICE_ID:
|
|
||||||
btif_sdp_execute_service(b_enable);
|
|
||||||
break;
|
|
||||||
case BTA_A2DP_SOURCE_SERVICE_ID:
|
case BTA_A2DP_SOURCE_SERVICE_ID:
|
||||||
btif_av_execute_service(b_enable);
|
btif_av_execute_service(b_enable);
|
||||||
break;
|
break;
|
||||||
@ -135,7 +133,7 @@ void btif_dm_execute_service_request(UINT16 event, char *p_param)
|
|||||||
b_enable = TRUE;
|
b_enable = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
btif_in_execute_service_request(*((tBTA_SERVICE_ID*)p_param), b_enable);
|
btif_in_execute_service_request(*((tBTA_SERVICE_ID *)p_param), b_enable);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
@ -147,9 +145,9 @@ void btif_dm_execute_service_request(UINT16 event, char *p_param)
|
|||||||
** Returns void
|
** Returns void
|
||||||
**
|
**
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
static void btif_dm_upstreams_evt(UINT16 event, char* p_param)
|
static void btif_dm_upstreams_evt(UINT16 event, char *p_param)
|
||||||
{
|
{
|
||||||
tBTA_DM_SEC *p_data = (tBTA_DM_SEC*)p_param;
|
tBTA_DM_SEC *p_data = (tBTA_DM_SEC *)p_param;
|
||||||
tBTA_SERVICE_MASK service_mask;
|
tBTA_SERVICE_MASK service_mask;
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
BTIF_TRACE_EVENT("btif_dm_upstreams_cback ev: %d\n", event);
|
BTIF_TRACE_EVENT("btif_dm_upstreams_cback ev: %d\n", event);
|
||||||
@ -159,9 +157,9 @@ static void btif_dm_upstreams_evt(UINT16 event, char* p_param)
|
|||||||
/* for each of the enabled services in the mask, trigger the profile
|
/* for each of the enabled services in the mask, trigger the profile
|
||||||
* enable */
|
* enable */
|
||||||
service_mask = btif_get_enabled_services_mask();
|
service_mask = btif_get_enabled_services_mask();
|
||||||
for (i=0; i <= BTA_MAX_SERVICE_ID; i++) {
|
for (i = 0; i <= BTA_MAX_SERVICE_ID; i++) {
|
||||||
if (service_mask &
|
if (service_mask &
|
||||||
(tBTA_SERVICE_MASK)(BTA_SERVICE_ID_TO_SERVICE_MASK(i))) {
|
(tBTA_SERVICE_MASK)(BTA_SERVICE_ID_TO_SERVICE_MASK(i))) {
|
||||||
btif_in_execute_service_request(i, TRUE);
|
btif_in_execute_service_request(i, TRUE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -171,9 +169,9 @@ static void btif_dm_upstreams_evt(UINT16 event, char* p_param)
|
|||||||
/* for each of the enabled services in the mask, trigger the profile
|
/* for each of the enabled services in the mask, trigger the profile
|
||||||
* disable */
|
* disable */
|
||||||
service_mask = btif_get_enabled_services_mask();
|
service_mask = btif_get_enabled_services_mask();
|
||||||
for (i=0; i <= BTA_MAX_SERVICE_ID; i++) {
|
for (i = 0; i <= BTA_MAX_SERVICE_ID; i++) {
|
||||||
if (service_mask &
|
if (service_mask &
|
||||||
(tBTA_SERVICE_MASK)(BTA_SERVICE_ID_TO_SERVICE_MASK(i))) {
|
(tBTA_SERVICE_MASK)(BTA_SERVICE_ID_TO_SERVICE_MASK(i))) {
|
||||||
btif_in_execute_service_request(i, FALSE);
|
btif_in_execute_service_request(i, FALSE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -233,7 +231,7 @@ void bte_dm_evt(tBTA_DM_SEC_EVT event, tBTA_DM_SEC *p_data)
|
|||||||
{
|
{
|
||||||
/* switch context to btif task context (copy full union size for convenience) */
|
/* switch context to btif task context (copy full union size for convenience) */
|
||||||
bt_status_t status = btif_transfer_context(btif_dm_upstreams_evt, (uint16_t)event,
|
bt_status_t status = btif_transfer_context(btif_dm_upstreams_evt, (uint16_t)event,
|
||||||
(void*)p_data, sizeof(tBTA_DM_SEC), btif_dm_data_copy);
|
(void *)p_data, sizeof(tBTA_DM_SEC), btif_dm_data_copy);
|
||||||
|
|
||||||
/* catch any failed context transfers */
|
/* catch any failed context transfers */
|
||||||
ASSERTC(status == BT_STATUS_SUCCESS, "context transfer failed\n", status);
|
ASSERTC(status == BT_STATUS_SUCCESS, "context transfer failed\n", status);
|
||||||
|
File diff suppressed because it is too large
Load Diff
53
examples/09_a2dp/components/bluedroid_demos/btif/btif_profile_queue.c
Executable file → Normal file
53
examples/09_a2dp/components/bluedroid_demos/btif/btif_profile_queue.c
Executable file → Normal file
@ -44,8 +44,8 @@
|
|||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
BTIF_QUEUE_CONNECT_EVT,
|
BTIF_QUEUE_CONNECT_EVT,
|
||||||
BTIF_QUEUE_ADVANCE_EVT,
|
BTIF_QUEUE_ADVANCE_EVT,
|
||||||
} btif_queue_event_t;
|
} btif_queue_event_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@ -67,7 +67,8 @@ static const size_t MAX_REASONABLE_REQUESTS = 10;
|
|||||||
** Queue helper functions
|
** Queue helper functions
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
static void queue_int_add(connect_node_t *p_param) {
|
static void queue_int_add(connect_node_t *p_param)
|
||||||
|
{
|
||||||
if (!connect_queue) {
|
if (!connect_queue) {
|
||||||
connect_queue = list_new(osi_free);
|
connect_queue = list_new(osi_free);
|
||||||
assert(connect_queue != NULL);
|
assert(connect_queue != NULL);
|
||||||
@ -89,25 +90,29 @@ static void queue_int_add(connect_node_t *p_param) {
|
|||||||
list_append(connect_queue, p_node);
|
list_append(connect_queue, p_node);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void queue_int_advance() {
|
static void queue_int_advance()
|
||||||
if (connect_queue && !list_is_empty(connect_queue))
|
{
|
||||||
|
if (connect_queue && !list_is_empty(connect_queue)) {
|
||||||
list_remove(connect_queue, list_front(connect_queue));
|
list_remove(connect_queue, list_front(connect_queue));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void queue_int_handle_evt(UINT16 event, char *p_param) {
|
static void queue_int_handle_evt(UINT16 event, char *p_param)
|
||||||
switch(event) {
|
{
|
||||||
case BTIF_QUEUE_CONNECT_EVT:
|
switch (event) {
|
||||||
queue_int_add((connect_node_t *)p_param);
|
case BTIF_QUEUE_CONNECT_EVT:
|
||||||
break;
|
queue_int_add((connect_node_t *)p_param);
|
||||||
|
break;
|
||||||
|
|
||||||
case BTIF_QUEUE_ADVANCE_EVT:
|
case BTIF_QUEUE_ADVANCE_EVT:
|
||||||
queue_int_advance();
|
queue_int_advance();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (stack_manager_get_interface()->get_stack_is_running())
|
// if (stack_manager_get_interface()->get_stack_is_running())
|
||||||
if (stack_manager_is_stack_running())
|
if (stack_manager_is_stack_running()) {
|
||||||
btif_queue_connect_next();
|
btif_queue_connect_next();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
@ -120,7 +125,8 @@ static void queue_int_handle_evt(UINT16 event, char *p_param) {
|
|||||||
** Returns BT_STATUS_SUCCESS if successful
|
** Returns BT_STATUS_SUCCESS if successful
|
||||||
**
|
**
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
bt_status_t btif_queue_connect(uint16_t uuid, const bt_bdaddr_t *bda, btif_connect_cb_t connect_cb) {
|
bt_status_t btif_queue_connect(uint16_t uuid, const bt_bdaddr_t *bda, btif_connect_cb_t connect_cb)
|
||||||
|
{
|
||||||
connect_node_t node;
|
connect_node_t node;
|
||||||
memset(&node, 0, sizeof(connect_node_t));
|
memset(&node, 0, sizeof(connect_node_t));
|
||||||
memcpy(&node.bda, bda, sizeof(bt_bdaddr_t));
|
memcpy(&node.bda, bda, sizeof(bt_bdaddr_t));
|
||||||
@ -128,7 +134,7 @@ bt_status_t btif_queue_connect(uint16_t uuid, const bt_bdaddr_t *bda, btif_conne
|
|||||||
node.connect_cb = connect_cb;
|
node.connect_cb = connect_cb;
|
||||||
|
|
||||||
return btif_transfer_context(queue_int_handle_evt, BTIF_QUEUE_CONNECT_EVT,
|
return btif_transfer_context(queue_int_handle_evt, BTIF_QUEUE_CONNECT_EVT,
|
||||||
(char *)&node, sizeof(connect_node_t), NULL);
|
(char *)&node, sizeof(connect_node_t), NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
@ -141,23 +147,27 @@ bt_status_t btif_queue_connect(uint16_t uuid, const bt_bdaddr_t *bda, btif_conne
|
|||||||
** Returns void
|
** Returns void
|
||||||
**
|
**
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
void btif_queue_advance() {
|
void btif_queue_advance()
|
||||||
|
{
|
||||||
btif_transfer_context(queue_int_handle_evt, BTIF_QUEUE_ADVANCE_EVT,
|
btif_transfer_context(queue_int_handle_evt, BTIF_QUEUE_ADVANCE_EVT,
|
||||||
NULL, 0, NULL);
|
NULL, 0, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
// This function dispatches the next pending connect request. It is called from
|
// This function dispatches the next pending connect request. It is called from
|
||||||
// stack_manager when the stack comes up.
|
// stack_manager when the stack comes up.
|
||||||
bt_status_t btif_queue_connect_next(void) {
|
bt_status_t btif_queue_connect_next(void)
|
||||||
if (!connect_queue || list_is_empty(connect_queue))
|
{
|
||||||
|
if (!connect_queue || list_is_empty(connect_queue)) {
|
||||||
return BT_STATUS_FAIL;
|
return BT_STATUS_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
connect_node_t *p_head = list_front(connect_queue);
|
connect_node_t *p_head = list_front(connect_queue);
|
||||||
|
|
||||||
// If the queue is currently busy, we return success anyway,
|
// If the queue is currently busy, we return success anyway,
|
||||||
// since the connection has been queued...
|
// since the connection has been queued...
|
||||||
if (p_head->busy)
|
if (p_head->busy) {
|
||||||
return BT_STATUS_SUCCESS;
|
return BT_STATUS_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
p_head->busy = true;
|
p_head->busy = true;
|
||||||
return p_head->connect_cb(&p_head->bda, p_head->uuid);
|
return p_head->connect_cb(&p_head->bda, p_head->uuid);
|
||||||
@ -173,7 +183,8 @@ bt_status_t btif_queue_connect_next(void) {
|
|||||||
** Returns void
|
** Returns void
|
||||||
**
|
**
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
void btif_queue_release() {
|
void btif_queue_release()
|
||||||
|
{
|
||||||
list_free(connect_queue);
|
list_free(connect_queue);
|
||||||
connect_queue = NULL;
|
connect_queue = NULL;
|
||||||
}
|
}
|
||||||
|
@ -1,175 +0,0 @@
|
|||||||
/******************************************************************************
|
|
||||||
*
|
|
||||||
* Copyright (C) 2014 Samsung System LSI
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at:
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*
|
|
||||||
******************************************************************************/
|
|
||||||
|
|
||||||
/************************************************************************************
|
|
||||||
*
|
|
||||||
* Filename: btif_sdp.c
|
|
||||||
* Description: SDP Bluetooth Interface.
|
|
||||||
* Implements the generic message handling and search functionality.
|
|
||||||
* References btif_sdp_server.c for SDP record creation.
|
|
||||||
*
|
|
||||||
***********************************************************************************/
|
|
||||||
|
|
||||||
#include "btif_sdp.h"
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#define LOG_TAG "BTIF_SDP"
|
|
||||||
#include "btif_common.h"
|
|
||||||
#include "btif_util.h"
|
|
||||||
#include "bta_api.h"
|
|
||||||
|
|
||||||
#include "esp_sdp_api.h"
|
|
||||||
|
|
||||||
/*****************************************************************************
|
|
||||||
** Functions implemented in sdp_server.c
|
|
||||||
******************************************************************************/
|
|
||||||
bt_status_t sdp_server_init();
|
|
||||||
void sdp_server_cleanup();
|
|
||||||
void on_create_record_event(int handle);
|
|
||||||
void on_remove_record_event(int handle);
|
|
||||||
|
|
||||||
// Utility functions:
|
|
||||||
int get_sdp_records_size(bluetooth_sdp_record* in_record, int count);
|
|
||||||
void copy_sdp_records(bluetooth_sdp_record* in_records,
|
|
||||||
bluetooth_sdp_record* out_records, int count);
|
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************
|
|
||||||
** Static variables
|
|
||||||
******************************************************************************/
|
|
||||||
|
|
||||||
static btsdp_callbacks_t *bt_sdp_callbacks = NULL;
|
|
||||||
|
|
||||||
static void btif_sdp_search_comp_evt(UINT16 event, char *p_param)
|
|
||||||
{
|
|
||||||
bt_sdp_search_comp_t *evt_data = (bt_sdp_search_comp_t *) p_param;
|
|
||||||
bt_bdaddr_t addr;
|
|
||||||
BTIF_TRACE_DEBUG("%s: event = %d\n", __FUNCTION__, event);
|
|
||||||
|
|
||||||
if (event != BT_SDP_SEARCH_COMP_EVT)
|
|
||||||
return;
|
|
||||||
|
|
||||||
bdcpy(addr.address, evt_data->remote_addr);
|
|
||||||
|
|
||||||
HAL_CBACK(bt_sdp_callbacks, sdp_search_cb, evt_data->status,
|
|
||||||
&addr, (uint8_t*)(evt_data->uuid.uu.uuid128),
|
|
||||||
evt_data->record_count, evt_data->records);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void sdp_search_comp_copy_cb(UINT16 event, char *p_dest, char *p_src)
|
|
||||||
{
|
|
||||||
bt_sdp_search_comp_t *p_dest_data = (bt_sdp_search_comp_t *) p_dest;
|
|
||||||
bt_sdp_search_comp_t *p_src_data = (bt_sdp_search_comp_t *) p_src;
|
|
||||||
if (!p_src)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (event != BT_SDP_SEARCH_COMP_EVT)
|
|
||||||
return;
|
|
||||||
|
|
||||||
memcpy(p_dest_data, p_src_data, sizeof(bt_sdp_search_comp_t));
|
|
||||||
|
|
||||||
copy_sdp_records(p_src_data->records, p_dest_data->records, p_src_data->record_count);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void sdp_dm_cback(bt_sdp_evt_t event, bt_sdp_t *p_data, void * user_data)
|
|
||||||
{
|
|
||||||
switch (event)
|
|
||||||
{
|
|
||||||
case BT_SDP_SEARCH_COMP_EVT:
|
|
||||||
{
|
|
||||||
int size = sizeof(bt_sdp_t);
|
|
||||||
size += get_sdp_records_size(p_data->sdp_search_comp.records,
|
|
||||||
p_data->sdp_search_comp.record_count);
|
|
||||||
|
|
||||||
BTIF_TRACE_DEBUG("%s: stat %d, record_cnt = %d\n", __FUNCTION__, p_data->sdp_search_comp.status, p_data->sdp_search_comp.record_count);
|
|
||||||
/* need to deep copy the record content */
|
|
||||||
btif_transfer_context(btif_sdp_search_comp_evt, event,
|
|
||||||
(char*)p_data, size, sdp_search_comp_copy_cb);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case BT_SDP_CREATE_RECORD_USER_EVT:
|
|
||||||
{
|
|
||||||
on_create_record_event((int)user_data);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case BT_SDP_REMOVE_RECORD_USER_EVT:
|
|
||||||
{
|
|
||||||
on_remove_record_event((int)user_data);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bt_status_t BTIF_SdpInit(btsdp_callbacks_t *callbacks)
|
|
||||||
{
|
|
||||||
BTIF_TRACE_DEBUG("Sdp Search %s\n", __FUNCTION__);
|
|
||||||
|
|
||||||
bt_sdp_callbacks = callbacks;
|
|
||||||
sdp_server_init();
|
|
||||||
|
|
||||||
btif_enable_service(BTA_SDP_SERVICE_ID);
|
|
||||||
|
|
||||||
return BT_STATUS_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
bt_status_t BTIF_SdpDeinit(void)
|
|
||||||
{
|
|
||||||
BTIF_TRACE_DEBUG("Sdp Search %s\n", __FUNCTION__);
|
|
||||||
|
|
||||||
bt_sdp_callbacks = NULL;
|
|
||||||
sdp_server_cleanup();
|
|
||||||
btif_disable_service(BTA_SDP_SERVICE_ID);
|
|
||||||
|
|
||||||
return BT_STATUS_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
bt_status_t BTIF_SdpSearch(bt_bdaddr_t *bd_addr, const uint8_t* uuid)
|
|
||||||
{
|
|
||||||
esp_bt_uuid_t sdp_uuid;
|
|
||||||
sdp_uuid.len = 16;
|
|
||||||
memcpy(sdp_uuid.uu.uuid128, uuid, sizeof(sdp_uuid.uu.uuid128));
|
|
||||||
|
|
||||||
esp_bt_sdp_search(bd_addr->address, &sdp_uuid);
|
|
||||||
return BT_STATUS_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*******************************************************************************
|
|
||||||
**
|
|
||||||
** Function btif_sdp_execute_service
|
|
||||||
**
|
|
||||||
** Description Initializes/Shuts down the service
|
|
||||||
**
|
|
||||||
** Returns BT_STATUS_SUCCESS on success, BT_STATUS_FAIL otherwise
|
|
||||||
**
|
|
||||||
*******************************************************************************/
|
|
||||||
bt_status_t btif_sdp_execute_service(BOOLEAN b_enable)
|
|
||||||
{
|
|
||||||
BTIF_TRACE_DEBUG("%s enable:%d\n", __FUNCTION__, b_enable);
|
|
||||||
|
|
||||||
if (b_enable) {
|
|
||||||
esp_bt_sdp_enable(sdp_dm_cback);
|
|
||||||
} else {
|
|
||||||
/* This is called on BT disable so no need to extra cleanup */
|
|
||||||
}
|
|
||||||
return BT_STATUS_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
@ -1,777 +0,0 @@
|
|||||||
/******************************************************************************
|
|
||||||
*
|
|
||||||
* Copyright (C) 2014 Samsung System LSI
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at:
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*
|
|
||||||
******************************************************************************/
|
|
||||||
|
|
||||||
/************************************************************************************
|
|
||||||
*
|
|
||||||
* Filename: btif_sdp_server.c
|
|
||||||
* Description: SDP server Bluetooth Interface to create and remove SDP records.
|
|
||||||
* To be used in combination with the RFCOMM/L2CAP(LE) sockets.
|
|
||||||
*
|
|
||||||
*
|
|
||||||
***********************************************************************************/
|
|
||||||
|
|
||||||
#include "btif_sdp.h"
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#define LOG_TAG "BTIF_SDP_SERVER"
|
|
||||||
#include "allocator.h"
|
|
||||||
#include "btif_common.h"
|
|
||||||
#include "bta_sys.h"
|
|
||||||
#include "utl.h"
|
|
||||||
#include "esp_sdp_api.h"
|
|
||||||
|
|
||||||
static pthread_mutex_t sdp_lock;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The need for a state variable have been reduced to two states.
|
|
||||||
* The remaining state control is handled by program flow
|
|
||||||
*/
|
|
||||||
typedef enum {
|
|
||||||
SDP_RECORD_FREE = 0,
|
|
||||||
SDP_RECORD_ALLOCED,
|
|
||||||
} sdp_state_t;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
sdp_state_t state;
|
|
||||||
int sdp_handle;
|
|
||||||
bluetooth_sdp_record* record_data;
|
|
||||||
} sdp_slot_t;
|
|
||||||
|
|
||||||
#define MAX_SDP_SLOTS 128
|
|
||||||
static sdp_slot_t sdp_slots[MAX_SDP_SLOTS];
|
|
||||||
|
|
||||||
/*****************************************************************************
|
|
||||||
* LOCAL Functions
|
|
||||||
*****************************************************************************/
|
|
||||||
static int add_maps_sdp(const bluetooth_sdp_mas_record* rec);
|
|
||||||
static int add_mapc_sdp(const bluetooth_sdp_mns_record* rec);
|
|
||||||
static int add_pbaps_sdp(const bluetooth_sdp_pse_record* rec);
|
|
||||||
static int add_opps_sdp(const bluetooth_sdp_ops_record* rec);
|
|
||||||
static int add_saps_sdp(const bluetooth_sdp_sap_record* rec);
|
|
||||||
bt_status_t remove_sdp_record(int record_id);
|
|
||||||
static int free_sdp_slot(int id);
|
|
||||||
|
|
||||||
/******************************************************************************
|
|
||||||
* WARNING: Functions below are not called in BTU context.
|
|
||||||
* Introduced to make it possible to create SDP records from JAVA with both a
|
|
||||||
* RFCOMM channel and a L2CAP PSM.
|
|
||||||
* Overall architecture:
|
|
||||||
* 1) JAVA calls createRecord() which returns a pseudo ID which at a later
|
|
||||||
* point will be linked to a specific SDP handle.
|
|
||||||
* 2) createRecord() requests the BTU task(thread) to call a callback in SDP
|
|
||||||
* which creates the actual record, and updates the ID<->SDPHandle map
|
|
||||||
* based on the ID beeing passed to BTA as user_data.
|
|
||||||
*****************************************************************************/
|
|
||||||
|
|
||||||
static void init_sdp_slots()
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
memset(sdp_slots, 0, sizeof(sdp_slot_t)*MAX_SDP_SLOTS);
|
|
||||||
/* if SDP_RECORD_FREE is zero - no need to set the value */
|
|
||||||
if(SDP_RECORD_FREE != 0) {
|
|
||||||
for(i = 0; i < MAX_SDP_SLOTS; i++)
|
|
||||||
{
|
|
||||||
sdp_slots[i].state = SDP_RECORD_FREE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bt_status_t sdp_server_init()
|
|
||||||
{
|
|
||||||
BTIF_TRACE_DEBUG("Sdp Server %s\n", __FUNCTION__);
|
|
||||||
pthread_mutex_init(&sdp_lock, NULL);
|
|
||||||
init_sdp_slots();
|
|
||||||
return BT_STATUS_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
void sdp_server_cleanup()
|
|
||||||
{
|
|
||||||
BTIF_TRACE_DEBUG("Sdp Server %s\n", __FUNCTION__);
|
|
||||||
pthread_mutex_lock(&sdp_lock);
|
|
||||||
int i;
|
|
||||||
for(i = 0; i < MAX_SDP_SLOTS; i++)
|
|
||||||
{
|
|
||||||
/*remove_sdp_record(i); we cannot send messages to the other threads, since they might
|
|
||||||
* have been shut down already. Just do local cleanup.
|
|
||||||
*/
|
|
||||||
free_sdp_slot(i);
|
|
||||||
}
|
|
||||||
pthread_mutex_unlock(&sdp_lock);
|
|
||||||
pthread_mutex_destroy(&sdp_lock);
|
|
||||||
}
|
|
||||||
|
|
||||||
int get_sdp_records_size(bluetooth_sdp_record* in_record, int count) {
|
|
||||||
bluetooth_sdp_record* record = in_record;
|
|
||||||
int records_size = 0;
|
|
||||||
int i;
|
|
||||||
for(i=0; i<count; i++) {
|
|
||||||
record = &in_record[i];
|
|
||||||
records_size += sizeof(bluetooth_sdp_record);
|
|
||||||
records_size += record->hdr.service_name_length;
|
|
||||||
if(record->hdr.service_name_length > 0){
|
|
||||||
records_size++; /* + '\0' termination of string */
|
|
||||||
}
|
|
||||||
records_size += record->hdr.user1_ptr_len;
|
|
||||||
records_size += record->hdr.user2_ptr_len;
|
|
||||||
}
|
|
||||||
return records_size;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Deep copy all content of in_records into out_records.
|
|
||||||
* out_records must point to a chunk of memory large enough to contain all
|
|
||||||
* the data. Use getSdpRecordsSize() to calculate the needed size. */
|
|
||||||
void copy_sdp_records(bluetooth_sdp_record* in_records,
|
|
||||||
bluetooth_sdp_record* out_records, int count) {
|
|
||||||
int i;
|
|
||||||
bluetooth_sdp_record* in_record;
|
|
||||||
bluetooth_sdp_record* out_record;
|
|
||||||
char* free_ptr = (char*)(&out_records[count]); /* set pointer to after the last entry */
|
|
||||||
|
|
||||||
for(i=0; i<count; i++) {
|
|
||||||
in_record = &in_records[i];
|
|
||||||
out_record = &out_records[i];
|
|
||||||
*out_record = *in_record;
|
|
||||||
|
|
||||||
if(in_record->hdr.service_name == NULL || in_record->hdr.service_name_length == 0) {
|
|
||||||
out_record->hdr.service_name = NULL;
|
|
||||||
out_record->hdr.service_name_length = 0;
|
|
||||||
} else {
|
|
||||||
out_record->hdr.service_name = free_ptr; // Update service_name pointer
|
|
||||||
// Copy string
|
|
||||||
memcpy(free_ptr, in_record->hdr.service_name, in_record->hdr.service_name_length);
|
|
||||||
free_ptr += in_record->hdr.service_name_length;
|
|
||||||
*(free_ptr) = '\0'; // Set '\0' termination of string
|
|
||||||
free_ptr++;
|
|
||||||
}
|
|
||||||
if(in_record->hdr.user1_ptr != NULL) {
|
|
||||||
out_record->hdr.user1_ptr = (UINT8*)free_ptr; // Update pointer
|
|
||||||
memcpy(free_ptr, in_record->hdr.user1_ptr, in_record->hdr.user1_ptr_len); // Copy content
|
|
||||||
free_ptr += in_record->hdr.user1_ptr_len;
|
|
||||||
}
|
|
||||||
if(in_record->hdr.user2_ptr != NULL) {
|
|
||||||
out_record->hdr.user2_ptr = (UINT8*)free_ptr; // Update pointer
|
|
||||||
memcpy(free_ptr, in_record->hdr.user2_ptr, in_record->hdr.user2_ptr_len); // Copy content
|
|
||||||
free_ptr += in_record->hdr.user2_ptr_len;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Reserve a slot in sdp_slots, copy data and set a reference to the copy.
|
|
||||||
* The record_data will contain both the record and any data pointed to by
|
|
||||||
* the record.
|
|
||||||
* Currently this covers:
|
|
||||||
* service_name string,
|
|
||||||
* user1_ptr and
|
|
||||||
* user2_ptr. */
|
|
||||||
static int alloc_sdp_slot(bluetooth_sdp_record* in_record) {
|
|
||||||
int i;
|
|
||||||
int record_size = get_sdp_records_size(in_record, 1);
|
|
||||||
bluetooth_sdp_record* record = osi_malloc(record_size);
|
|
||||||
|
|
||||||
copy_sdp_records(in_record, record, 1);
|
|
||||||
|
|
||||||
/* We are optimists here, and preallocate the record.
|
|
||||||
* This is to reduce the time we hold the sdp_lock. */
|
|
||||||
pthread_mutex_lock(&sdp_lock);
|
|
||||||
for(i = 0; i < MAX_SDP_SLOTS; i++)
|
|
||||||
{
|
|
||||||
if(sdp_slots[i].state == SDP_RECORD_FREE) {
|
|
||||||
sdp_slots[i].state = SDP_RECORD_ALLOCED;
|
|
||||||
sdp_slots[i].record_data = record;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pthread_mutex_unlock(&sdp_lock);
|
|
||||||
if(i >= MAX_SDP_SLOTS) {
|
|
||||||
APPL_TRACE_ERROR("%s() failed - no more free slots!\n", __func__);
|
|
||||||
/* Rearly the optimist is too optimistic, and cleanup is needed...*/
|
|
||||||
osi_free(record);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int free_sdp_slot(int id) {
|
|
||||||
int handle = -1;
|
|
||||||
bluetooth_sdp_record* record = NULL;
|
|
||||||
if(id >= MAX_SDP_SLOTS) {
|
|
||||||
APPL_TRACE_ERROR("%s() failed - id %d is invalid\n", __func__, id);
|
|
||||||
return handle;
|
|
||||||
}
|
|
||||||
pthread_mutex_lock(&sdp_lock);
|
|
||||||
handle = sdp_slots[id].sdp_handle;
|
|
||||||
sdp_slots[id].sdp_handle = 0;
|
|
||||||
if(sdp_slots[id].state != SDP_RECORD_FREE)
|
|
||||||
{
|
|
||||||
/* safe a copy of the pointer, and free after unlock() */
|
|
||||||
record = sdp_slots[id].record_data;
|
|
||||||
}
|
|
||||||
sdp_slots[id].state = SDP_RECORD_FREE;
|
|
||||||
pthread_mutex_unlock(&sdp_lock);
|
|
||||||
|
|
||||||
if(record != NULL) {
|
|
||||||
osi_free(record);
|
|
||||||
} else {
|
|
||||||
// Record have already been freed
|
|
||||||
handle = -1;
|
|
||||||
}
|
|
||||||
return handle;
|
|
||||||
}
|
|
||||||
|
|
||||||
/***
|
|
||||||
* Use this to get a reference to a SDP slot AND change the state to
|
|
||||||
* SDP_RECORD_CREATE_INITIATED.
|
|
||||||
*/
|
|
||||||
static const sdp_slot_t* start_create_sdp(int id) {
|
|
||||||
sdp_slot_t* sdp_slot;
|
|
||||||
if(id >= MAX_SDP_SLOTS) {
|
|
||||||
APPL_TRACE_ERROR("%s() failed - id %d is invalid\n", __func__, id);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
pthread_mutex_lock(&sdp_lock);
|
|
||||||
if(sdp_slots[id].state == SDP_RECORD_ALLOCED) {
|
|
||||||
sdp_slot = &(sdp_slots[id]);
|
|
||||||
} else {
|
|
||||||
/* The record have been removed before this event occurred - e.g. deinit */
|
|
||||||
sdp_slot = NULL;
|
|
||||||
}
|
|
||||||
pthread_mutex_unlock(&sdp_lock);
|
|
||||||
if(sdp_slot == NULL) {
|
|
||||||
APPL_TRACE_ERROR("%s() failed - state for id %d is \n"
|
|
||||||
"sdp_slots[id].state = %d expected %d\n", __func__,
|
|
||||||
id, sdp_slots[id].state, SDP_RECORD_ALLOCED);
|
|
||||||
}
|
|
||||||
return sdp_slot;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void set_sdp_handle(int id, int handle) {
|
|
||||||
pthread_mutex_lock(&sdp_lock);
|
|
||||||
sdp_slots[id].sdp_handle = handle;
|
|
||||||
pthread_mutex_unlock(&sdp_lock);
|
|
||||||
BTIF_TRACE_DEBUG("%s() id=%d to handle=0x%08x\n", __FUNCTION__, id, handle);
|
|
||||||
}
|
|
||||||
|
|
||||||
bt_status_t BTIF_SdpCreateRecord(bluetooth_sdp_record *record, int* record_handle) {
|
|
||||||
int handle;
|
|
||||||
|
|
||||||
handle = alloc_sdp_slot(record);
|
|
||||||
BTIF_TRACE_DEBUG("%s() handle = 0x%08x\n", __FUNCTION__, handle);
|
|
||||||
|
|
||||||
if(handle < 0)
|
|
||||||
return BT_STATUS_FAIL;
|
|
||||||
|
|
||||||
esp_bt_sdp_create_record_by_user((void*) handle);
|
|
||||||
|
|
||||||
*record_handle = handle;
|
|
||||||
|
|
||||||
return BT_STATUS_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
bt_status_t BTIF_SdpRemoveRecord(int record_handle) {
|
|
||||||
int handle;
|
|
||||||
|
|
||||||
/* Get the Record handle, and free the slot */
|
|
||||||
handle = free_sdp_slot(record_handle);
|
|
||||||
BTIF_TRACE_DEBUG("Sdp Server %s id=%d to handle=0x%08x\n",
|
|
||||||
__FUNCTION__, record_handle, handle);
|
|
||||||
|
|
||||||
/* Pass the actual record handle */
|
|
||||||
if(handle > 0) {
|
|
||||||
esp_bt_sdp_remove_record_by_user((void *)handle);
|
|
||||||
return BT_STATUS_SUCCESS;
|
|
||||||
}
|
|
||||||
BTIF_TRACE_DEBUG("Sdp Server %s - record already removed - or never created\n", __FUNCTION__);
|
|
||||||
return BT_STATUS_FAIL;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/******************************************************************************
|
|
||||||
* CALLBACK FUNCTIONS
|
|
||||||
* Called in BTA context to create/remove SDP records.
|
|
||||||
******************************************************************************/
|
|
||||||
|
|
||||||
void on_create_record_event(int id) {
|
|
||||||
/*
|
|
||||||
* 1) Fetch the record pointer, and change its state?
|
|
||||||
* 2) switch on the type to create the correct record
|
|
||||||
* 3) Update state on completion
|
|
||||||
* 4) What to do at fail?
|
|
||||||
* */
|
|
||||||
BTIF_TRACE_DEBUG("Sdp Server %s\n", __FUNCTION__);
|
|
||||||
const sdp_slot_t* sdp_slot = start_create_sdp(id);
|
|
||||||
/* In the case we are shutting down, sdp_slot is NULL */
|
|
||||||
if(sdp_slot != NULL) {
|
|
||||||
bluetooth_sdp_record* record = sdp_slot->record_data;
|
|
||||||
int handle = -1;
|
|
||||||
switch(record->hdr.type) {
|
|
||||||
case SDP_TYPE_MAP_MAS:
|
|
||||||
handle = add_maps_sdp(&record->mas);
|
|
||||||
break;
|
|
||||||
case SDP_TYPE_MAP_MNS:
|
|
||||||
handle = add_mapc_sdp(&record->mns);
|
|
||||||
break;
|
|
||||||
case SDP_TYPE_PBAP_PSE:
|
|
||||||
handle = add_pbaps_sdp(&record->pse);
|
|
||||||
break;
|
|
||||||
case SDP_TYPE_OPP_SERVER:
|
|
||||||
handle = add_opps_sdp(&record->ops);
|
|
||||||
break;
|
|
||||||
case SDP_TYPE_SAP_SERVER:
|
|
||||||
handle = add_saps_sdp(&record->sap);
|
|
||||||
break;
|
|
||||||
case SDP_TYPE_PBAP_PCE:
|
|
||||||
// break; not yet supported
|
|
||||||
default:
|
|
||||||
BTIF_TRACE_DEBUG("Record type %d is not supported\n",record->hdr.type);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if(handle != -1) {
|
|
||||||
set_sdp_handle(id, handle);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void on_remove_record_event(int handle) {
|
|
||||||
BTIF_TRACE_DEBUG("Sdp Server %s\n", __FUNCTION__);
|
|
||||||
|
|
||||||
// User data carries the actual SDP handle, not the ID.
|
|
||||||
if(handle != -1 && handle != 0) {
|
|
||||||
BOOLEAN result;
|
|
||||||
result = SDP_DeleteRecord( handle );
|
|
||||||
if(result == FALSE) {
|
|
||||||
BTIF_TRACE_ERROR(" Unable to remove handle 0x%08x\n", handle);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/****
|
|
||||||
* Below the actual functions accessing BTA context data - hence only call from BTA context!
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* Create a MAP MAS SDP record based on information stored in a bluetooth_sdp_mas_record */
|
|
||||||
static int add_maps_sdp(const bluetooth_sdp_mas_record* rec)
|
|
||||||
{
|
|
||||||
|
|
||||||
sdp_proto_elem_t protoList[3];
|
|
||||||
UINT16 service = UUID_SERVCLASS_MESSAGE_ACCESS;
|
|
||||||
UINT16 browse = UUID_SERVCLASS_PUBLIC_BROWSE_GROUP;
|
|
||||||
BOOLEAN status = TRUE;
|
|
||||||
UINT32 sdp_handle = 0;
|
|
||||||
UINT8 temp[4];
|
|
||||||
UINT8* p_temp = temp;
|
|
||||||
|
|
||||||
APPL_TRACE_DEBUG("%s(): MASID = 0x%02x, scn 0x%02x, psm = 0x%04x\n service name %s\n", __func__,
|
|
||||||
rec->mas_instance_id, rec->hdr.rfcomm_channel_number,
|
|
||||||
rec->hdr.l2cap_psm, rec->hdr.service_name);
|
|
||||||
|
|
||||||
APPL_TRACE_DEBUG(" msg_types: 0x%02x, feature_bits: 0x%08x\n",
|
|
||||||
rec->supported_message_types, rec->supported_features);
|
|
||||||
|
|
||||||
if ((sdp_handle = esp_bt_sdp_create_record()) == 0)
|
|
||||||
{
|
|
||||||
APPL_TRACE_ERROR("%s() - Unable to register MAPS Service\n", __func__);
|
|
||||||
return sdp_handle;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* add service class */
|
|
||||||
status &= esp_bt_sdp_add_service_class_id_list(sdp_handle, 1, &service);
|
|
||||||
memset( protoList, 0 , 3*sizeof(sdp_proto_elem_t) );
|
|
||||||
|
|
||||||
/* add protocol list, including RFCOMM scn */
|
|
||||||
protoList[0].protocol_uuid = UUID_PROTOCOL_L2CAP;
|
|
||||||
protoList[0].num_params = 0;
|
|
||||||
protoList[1].protocol_uuid = UUID_PROTOCOL_RFCOMM;
|
|
||||||
protoList[1].num_params = 1;
|
|
||||||
protoList[1].params[0] = rec->hdr.rfcomm_channel_number;
|
|
||||||
protoList[2].protocol_uuid = UUID_PROTOCOL_OBEX;
|
|
||||||
protoList[2].num_params = 0;
|
|
||||||
status &= esp_bt_sdp_add_protocol_list(sdp_handle, 3, protoList);
|
|
||||||
|
|
||||||
/* Add a name entry */
|
|
||||||
status &= esp_bt_sdp_add_attribute(sdp_handle,
|
|
||||||
(UINT16)ATTR_ID_SERVICE_NAME,
|
|
||||||
(UINT8)TEXT_STR_DESC_TYPE,
|
|
||||||
(UINT32)(rec->hdr.service_name_length + 1),
|
|
||||||
(UINT8 *)rec->hdr.service_name);
|
|
||||||
|
|
||||||
/* Add in the Bluetooth Profile Descriptor List */
|
|
||||||
status &= esp_bt_sdp_add_profile_dscp_list(sdp_handle,
|
|
||||||
UUID_SERVCLASS_MAP_PROFILE,
|
|
||||||
rec->hdr.profile_version);
|
|
||||||
|
|
||||||
/* Add MAS instance ID */
|
|
||||||
status &= esp_bt_sdp_add_attribute(sdp_handle, ATTR_ID_MAS_INSTANCE_ID, UINT_DESC_TYPE,
|
|
||||||
(UINT32)1, (UINT8*)&rec->mas_instance_id);
|
|
||||||
|
|
||||||
/* Add supported message types */
|
|
||||||
status &= esp_bt_sdp_add_attribute(sdp_handle, ATTR_ID_SUPPORTED_MSG_TYPE, UINT_DESC_TYPE,
|
|
||||||
(UINT32)1, (UINT8*)&rec->supported_message_types);
|
|
||||||
|
|
||||||
/* Add supported feature */
|
|
||||||
UINT32_TO_BE_STREAM(p_temp, rec->supported_features);
|
|
||||||
status &= esp_bt_sdp_add_attribute(sdp_handle, ATTR_ID_MAP_SUPPORTED_FEATURES,
|
|
||||||
UINT_DESC_TYPE, (UINT32)4, temp);
|
|
||||||
|
|
||||||
/* Add the L2CAP PSM if present */
|
|
||||||
if(rec->hdr.l2cap_psm != -1) {
|
|
||||||
p_temp = temp;// The macro modifies p_temp, hence rewind.
|
|
||||||
UINT16_TO_BE_STREAM(p_temp, rec->hdr.l2cap_psm);
|
|
||||||
status &= esp_bt_sdp_add_attribute(sdp_handle, ATTR_ID_GOEP_L2CAP_PSM,
|
|
||||||
UINT_DESC_TYPE, (UINT32)2, temp);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Make the service browseable */
|
|
||||||
status &= esp_bt_sdp_add_uuid_sequence (sdp_handle, ATTR_ID_BROWSE_GROUP_LIST, 1, &browse);
|
|
||||||
|
|
||||||
if (!status)
|
|
||||||
{
|
|
||||||
esp_bt_sdp_delete_record(sdp_handle);
|
|
||||||
sdp_handle = 0;
|
|
||||||
APPL_TRACE_ERROR("%s() FAILED\n", __func__);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
bta_sys_add_uuid(service); /* UUID_SERVCLASS_MESSAGE_ACCESS */
|
|
||||||
APPL_TRACE_DEBUG("%s(): SDP Registered (handle 0x%08x)\n", __func__, sdp_handle);
|
|
||||||
}
|
|
||||||
return sdp_handle;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* Create a MAP MNS SDP record based on information stored in a bluetooth_sdp_mns_record */
|
|
||||||
static int add_mapc_sdp(const bluetooth_sdp_mns_record* rec)
|
|
||||||
{
|
|
||||||
|
|
||||||
sdp_proto_elem_t protoList [3];
|
|
||||||
UINT16 service = UUID_SERVCLASS_MESSAGE_NOTIFICATION;
|
|
||||||
UINT16 browse = UUID_SERVCLASS_PUBLIC_BROWSE_GROUP;
|
|
||||||
BOOLEAN status = TRUE;
|
|
||||||
UINT32 sdp_handle = 0;
|
|
||||||
UINT8 temp[4];
|
|
||||||
UINT8* p_temp = temp;
|
|
||||||
|
|
||||||
APPL_TRACE_DEBUG("%s(): scn 0x%02x, psm = 0x%04x\n service name %s\n", __func__,
|
|
||||||
rec->hdr.rfcomm_channel_number, rec->hdr.l2cap_psm, rec->hdr.service_name);
|
|
||||||
|
|
||||||
APPL_TRACE_DEBUG(" feature_bits: 0x%08x\n", rec->supported_features);
|
|
||||||
|
|
||||||
if ((sdp_handle = esp_bt_sdp_create_record()) == 0)
|
|
||||||
{
|
|
||||||
APPL_TRACE_ERROR("%s(): Unable to register MAP Notification Service\n", __func__);
|
|
||||||
return sdp_handle;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* add service class */
|
|
||||||
status &= esp_bt_sdp_add_service_class_id_list(sdp_handle, 1, &service);
|
|
||||||
memset( protoList, 0 , 3*sizeof(sdp_proto_elem_t) );
|
|
||||||
|
|
||||||
/* add protocol list, including RFCOMM scn */
|
|
||||||
protoList[0].protocol_uuid = UUID_PROTOCOL_L2CAP;
|
|
||||||
protoList[0].num_params = 0;
|
|
||||||
protoList[1].protocol_uuid = UUID_PROTOCOL_RFCOMM;
|
|
||||||
protoList[1].num_params = 1;
|
|
||||||
protoList[1].params[0] = rec->hdr.rfcomm_channel_number;
|
|
||||||
protoList[2].protocol_uuid = UUID_PROTOCOL_OBEX;
|
|
||||||
protoList[2].num_params = 0;
|
|
||||||
status &= esp_bt_sdp_add_protocol_list(sdp_handle, 3, protoList);
|
|
||||||
|
|
||||||
/* Add a name entry */
|
|
||||||
status &= esp_bt_sdp_add_attribute(sdp_handle,
|
|
||||||
(UINT16)ATTR_ID_SERVICE_NAME,
|
|
||||||
(UINT8)TEXT_STR_DESC_TYPE,
|
|
||||||
(UINT32)(rec->hdr.service_name_length + 1),
|
|
||||||
(UINT8 *)rec->hdr.service_name);
|
|
||||||
|
|
||||||
/* Add in the Bluetooth Profile Descriptor List */
|
|
||||||
status &= esp_bt_sdp_add_profile_dscp_list(sdp_handle,
|
|
||||||
UUID_SERVCLASS_MAP_PROFILE,
|
|
||||||
rec->hdr.profile_version);
|
|
||||||
|
|
||||||
/* Add supported feature */
|
|
||||||
UINT32_TO_BE_STREAM(p_temp, rec->supported_features);
|
|
||||||
status &= esp_bt_sdp_add_attribute(sdp_handle, ATTR_ID_MAP_SUPPORTED_FEATURES,
|
|
||||||
UINT_DESC_TYPE, (UINT32)4, temp);
|
|
||||||
|
|
||||||
/* Add the L2CAP PSM if present */
|
|
||||||
if(rec->hdr.l2cap_psm != -1) {
|
|
||||||
p_temp = temp;// The macro modifies p_temp, hence rewind.
|
|
||||||
UINT16_TO_BE_STREAM(p_temp, rec->hdr.l2cap_psm);
|
|
||||||
status &= esp_bt_sdp_add_attribute(sdp_handle, ATTR_ID_GOEP_L2CAP_PSM,
|
|
||||||
UINT_DESC_TYPE, (UINT32)2, temp);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Make the service browseable */
|
|
||||||
status &= esp_bt_sdp_add_uuid_sequence (sdp_handle, ATTR_ID_BROWSE_GROUP_LIST, 1, &browse);
|
|
||||||
|
|
||||||
if (!status)
|
|
||||||
{
|
|
||||||
esp_bt_sdp_delete_record(sdp_handle);
|
|
||||||
sdp_handle = 0;
|
|
||||||
APPL_TRACE_ERROR("%s() FAILED\n", __func__);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
bta_sys_add_uuid(service); /* UUID_SERVCLASS_MESSAGE_ACCESS */
|
|
||||||
APPL_TRACE_DEBUG("%s(): SDP Registered (handle 0x%08x)\n", __func__, sdp_handle);
|
|
||||||
}
|
|
||||||
return sdp_handle;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Create a PBAP Server SDP record based on information stored in a bluetooth_sdp_pse_record */
|
|
||||||
static int add_pbaps_sdp(const bluetooth_sdp_pse_record* rec)
|
|
||||||
{
|
|
||||||
|
|
||||||
sdp_proto_elem_t protoList [3];
|
|
||||||
UINT16 service = UUID_SERVCLASS_PBAP_PSE;
|
|
||||||
UINT16 browse = UUID_SERVCLASS_PUBLIC_BROWSE_GROUP;
|
|
||||||
BOOLEAN status = TRUE;
|
|
||||||
UINT32 sdp_handle = 0;
|
|
||||||
UINT8 temp[4];
|
|
||||||
UINT8* p_temp = temp;
|
|
||||||
|
|
||||||
APPL_TRACE_DEBUG("%s(): scn 0x%02x, psm = 0x%04x\n service name %s\n", __func__,
|
|
||||||
rec->hdr.rfcomm_channel_number, rec->hdr.l2cap_psm, rec->hdr.service_name);
|
|
||||||
|
|
||||||
APPL_TRACE_DEBUG(" supported_repositories: 0x%08x, feature_bits: 0x%08x\n",
|
|
||||||
rec->supported_repositories, rec->supported_features);
|
|
||||||
|
|
||||||
if ((sdp_handle = esp_bt_sdp_create_record()) == 0)
|
|
||||||
{
|
|
||||||
APPL_TRACE_ERROR("%s(): Unable to register PBAP Server Service\n", __func__);
|
|
||||||
return sdp_handle;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* add service class */
|
|
||||||
status &= esp_bt_sdp_add_service_class_id_list(sdp_handle, 1, &service);
|
|
||||||
memset( protoList, 0 , 3*sizeof(sdp_proto_elem_t) );
|
|
||||||
|
|
||||||
/* add protocol list, including RFCOMM scn */
|
|
||||||
protoList[0].protocol_uuid = UUID_PROTOCOL_L2CAP;
|
|
||||||
protoList[0].num_params = 0;
|
|
||||||
protoList[1].protocol_uuid = UUID_PROTOCOL_RFCOMM;
|
|
||||||
protoList[1].num_params = 1;
|
|
||||||
protoList[1].params[0] = rec->hdr.rfcomm_channel_number;
|
|
||||||
protoList[2].protocol_uuid = UUID_PROTOCOL_OBEX;
|
|
||||||
protoList[2].num_params = 0;
|
|
||||||
status &= esp_bt_sdp_add_protocol_list(sdp_handle, 3, protoList);
|
|
||||||
|
|
||||||
/* Add a name entry */
|
|
||||||
status &= esp_bt_sdp_add_attribute(sdp_handle,
|
|
||||||
(UINT16)ATTR_ID_SERVICE_NAME,
|
|
||||||
(UINT8)TEXT_STR_DESC_TYPE,
|
|
||||||
(UINT32)(rec->hdr.service_name_length + 1),
|
|
||||||
(UINT8 *)rec->hdr.service_name);
|
|
||||||
|
|
||||||
/* Add in the Bluetooth Profile Descriptor List */
|
|
||||||
status &= esp_bt_sdp_add_profile_dscp_list(sdp_handle,
|
|
||||||
UUID_SERVCLASS_PHONE_ACCESS,
|
|
||||||
rec->hdr.profile_version);
|
|
||||||
|
|
||||||
/* Add supported repositories 1 byte */
|
|
||||||
status &= esp_bt_sdp_add_attribute(sdp_handle, ATTR_ID_SUPPORTED_REPOSITORIES,
|
|
||||||
UINT_DESC_TYPE, (UINT32)1, (UINT8*)&rec->supported_repositories);
|
|
||||||
|
|
||||||
/* Add supported feature 4 bytes*/
|
|
||||||
UINT32_TO_BE_STREAM(p_temp, rec->supported_features);
|
|
||||||
status &= esp_bt_sdp_add_attribute(sdp_handle, ATTR_ID_PBAP_SUPPORTED_FEATURES,
|
|
||||||
UINT_DESC_TYPE, (UINT32)4, temp);
|
|
||||||
|
|
||||||
/* Add the L2CAP PSM if present */
|
|
||||||
if(rec->hdr.l2cap_psm != -1) {
|
|
||||||
p_temp = temp;// The macro modifies p_temp, hence rewind.
|
|
||||||
UINT16_TO_BE_STREAM(p_temp, rec->hdr.l2cap_psm);
|
|
||||||
status &= esp_bt_sdp_add_attribute(sdp_handle, ATTR_ID_GOEP_L2CAP_PSM,
|
|
||||||
UINT_DESC_TYPE, (UINT32)2, temp);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Make the service browseable */
|
|
||||||
status &= esp_bt_sdp_add_uuid_sequence (sdp_handle, ATTR_ID_BROWSE_GROUP_LIST, 1, &browse);
|
|
||||||
|
|
||||||
if (!status)
|
|
||||||
{
|
|
||||||
esp_bt_sdp_delete_record(sdp_handle);
|
|
||||||
sdp_handle = 0;
|
|
||||||
APPL_TRACE_ERROR("%s() FAILED\n", __func__);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
bta_sys_add_uuid(service); /* UUID_SERVCLASS_MESSAGE_ACCESS */
|
|
||||||
APPL_TRACE_DEBUG("%s(): SDP Registered (handle 0x%08x)\n", __func__, sdp_handle);
|
|
||||||
}
|
|
||||||
return sdp_handle;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* Create a OPP Server SDP record based on information stored in a bluetooth_sdp_ops_record */
|
|
||||||
static int add_opps_sdp(const bluetooth_sdp_ops_record* rec)
|
|
||||||
{
|
|
||||||
|
|
||||||
sdp_proto_elem_t protoList [3];
|
|
||||||
UINT16 service = UUID_SERVCLASS_OBEX_OBJECT_PUSH;
|
|
||||||
UINT16 browse = UUID_SERVCLASS_PUBLIC_BROWSE_GROUP;
|
|
||||||
UINT8 type_len[rec->supported_formats_list_len];
|
|
||||||
UINT8 desc_type[rec->supported_formats_list_len];
|
|
||||||
UINT8 *type_value[rec->supported_formats_list_len];
|
|
||||||
BOOLEAN status = TRUE;
|
|
||||||
UINT32 sdp_handle = 0;
|
|
||||||
UINT8 temp[4];
|
|
||||||
UINT8* p_temp = temp;
|
|
||||||
tBTA_UTL_COD cod;
|
|
||||||
int i,j;
|
|
||||||
|
|
||||||
APPL_TRACE_DEBUG("%s(): scn 0x%02x, psm = 0x%04x\n service name %s\n", __func__,
|
|
||||||
rec->hdr.rfcomm_channel_number, rec->hdr.l2cap_psm, rec->hdr.service_name);
|
|
||||||
|
|
||||||
APPL_TRACE_DEBUG(" supported formats count: %d\n",
|
|
||||||
rec->supported_formats_list_len);
|
|
||||||
|
|
||||||
if ((sdp_handle = esp_bt_sdp_create_record()) == 0)
|
|
||||||
{
|
|
||||||
APPL_TRACE_ERROR("%s(): Unable to register Object Push Server Service\n", __func__);
|
|
||||||
return sdp_handle;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* add service class */
|
|
||||||
status &= esp_bt_sdp_add_service_class_id_list(sdp_handle, 1, &service);
|
|
||||||
memset( protoList, 0 , 3*sizeof(sdp_proto_elem_t) );
|
|
||||||
|
|
||||||
/* add protocol list, including RFCOMM scn */
|
|
||||||
protoList[0].protocol_uuid = UUID_PROTOCOL_L2CAP;
|
|
||||||
protoList[0].num_params = 0;
|
|
||||||
protoList[1].protocol_uuid = UUID_PROTOCOL_RFCOMM;
|
|
||||||
protoList[1].num_params = 1;
|
|
||||||
protoList[1].params[0] = rec->hdr.rfcomm_channel_number;
|
|
||||||
protoList[2].protocol_uuid = UUID_PROTOCOL_OBEX;
|
|
||||||
protoList[2].num_params = 0;
|
|
||||||
status &= esp_bt_sdp_add_protocol_list(sdp_handle, 3, protoList);
|
|
||||||
|
|
||||||
/* Add a name entry */
|
|
||||||
status &= esp_bt_sdp_add_attribute(sdp_handle,
|
|
||||||
(UINT16)ATTR_ID_SERVICE_NAME,
|
|
||||||
(UINT8)TEXT_STR_DESC_TYPE,
|
|
||||||
(UINT32)(rec->hdr.service_name_length + 1),
|
|
||||||
(UINT8 *)rec->hdr.service_name);
|
|
||||||
|
|
||||||
/* Add in the Bluetooth Profile Descriptor List */
|
|
||||||
status &= esp_bt_sdp_add_profile_dscp_list(sdp_handle,
|
|
||||||
UUID_SERVCLASS_OBEX_OBJECT_PUSH,
|
|
||||||
rec->hdr.profile_version);
|
|
||||||
|
|
||||||
/* add sequence for supported types */
|
|
||||||
for (i = 0, j = 0; i < rec->supported_formats_list_len; i++)
|
|
||||||
{
|
|
||||||
type_value[j] = (UINT8 *) &rec->supported_formats_list[i];
|
|
||||||
desc_type[j] = UINT_DESC_TYPE;
|
|
||||||
type_len[j++] = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
status &= esp_bt_sdp_add_sequence(sdp_handle, (UINT16) ATTR_ID_SUPPORTED_FORMATS_LIST,
|
|
||||||
(UINT8) rec->supported_formats_list_len, desc_type, type_len, type_value);
|
|
||||||
|
|
||||||
/* Add the L2CAP PSM if present */
|
|
||||||
if(rec->hdr.l2cap_psm != -1) {
|
|
||||||
p_temp = temp;// The macro modifies p_temp, hence rewind.
|
|
||||||
UINT16_TO_BE_STREAM(p_temp, rec->hdr.l2cap_psm);
|
|
||||||
status &= esp_bt_sdp_add_attribute(sdp_handle, ATTR_ID_GOEP_L2CAP_PSM,
|
|
||||||
UINT_DESC_TYPE, (UINT32)2, temp);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Make the service browseable */
|
|
||||||
status &= esp_bt_sdp_add_uuid_sequence (sdp_handle, ATTR_ID_BROWSE_GROUP_LIST, 1, &browse);
|
|
||||||
|
|
||||||
if (!status)
|
|
||||||
{
|
|
||||||
esp_bt_sdp_delete_record(sdp_handle);
|
|
||||||
sdp_handle = 0;
|
|
||||||
APPL_TRACE_ERROR("%s() FAILED\n", __func__);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* set class of device */
|
|
||||||
cod.service = BTM_COD_SERVICE_OBJ_TRANSFER;
|
|
||||||
utl_set_device_class(&cod, BTA_UTL_SET_COD_SERVICE_CLASS);
|
|
||||||
|
|
||||||
bta_sys_add_uuid(service); /* UUID_SERVCLASS_OBEX_OBJECT_PUSH */
|
|
||||||
APPL_TRACE_DEBUG("%s(): SDP Registered (handle 0x%08x)\n", __func__, sdp_handle);
|
|
||||||
}
|
|
||||||
return sdp_handle;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create a Sim Access Profile SDP record based on information stored in a bluetooth_sdp_sap_record.
|
|
||||||
static int add_saps_sdp(const bluetooth_sdp_sap_record* rec)
|
|
||||||
{
|
|
||||||
sdp_proto_elem_t protoList [2];
|
|
||||||
UINT16 services[2];
|
|
||||||
UINT16 browse = UUID_SERVCLASS_PUBLIC_BROWSE_GROUP;
|
|
||||||
BOOLEAN status = TRUE;
|
|
||||||
UINT32 sdp_handle = 0;
|
|
||||||
|
|
||||||
APPL_TRACE_DEBUG("%s(): scn 0x%02x, service name %s\n", __func__,
|
|
||||||
rec->hdr.rfcomm_channel_number, rec->hdr.service_name);
|
|
||||||
|
|
||||||
if ((sdp_handle = esp_bt_sdp_create_record()) == 0)
|
|
||||||
{
|
|
||||||
APPL_TRACE_ERROR("%s(): Unable to register SAPS Service\n", __func__);
|
|
||||||
return sdp_handle;
|
|
||||||
}
|
|
||||||
|
|
||||||
services[0] = UUID_SERVCLASS_SAP;
|
|
||||||
services[1] = UUID_SERVCLASS_GENERIC_TELEPHONY;
|
|
||||||
|
|
||||||
// add service class
|
|
||||||
status &= esp_bt_sdp_add_service_class_id_list(sdp_handle, 2, services);
|
|
||||||
memset(protoList, 0, 2 * sizeof(sdp_proto_elem_t));
|
|
||||||
|
|
||||||
// add protocol list, including RFCOMM scn
|
|
||||||
protoList[0].protocol_uuid = UUID_PROTOCOL_L2CAP;
|
|
||||||
protoList[0].num_params = 0;
|
|
||||||
protoList[1].protocol_uuid = UUID_PROTOCOL_RFCOMM;
|
|
||||||
protoList[1].num_params = 1;
|
|
||||||
protoList[1].params[0] = rec->hdr.rfcomm_channel_number;
|
|
||||||
status &= esp_bt_sdp_add_protocol_list(sdp_handle, 2, protoList);
|
|
||||||
|
|
||||||
// Add a name entry
|
|
||||||
status &= esp_bt_sdp_add_attribute(sdp_handle,
|
|
||||||
(UINT16)ATTR_ID_SERVICE_NAME,
|
|
||||||
(UINT8)TEXT_STR_DESC_TYPE,
|
|
||||||
(UINT32)(rec->hdr.service_name_length + 1),
|
|
||||||
(UINT8 *)rec->hdr.service_name);
|
|
||||||
|
|
||||||
// Add in the Bluetooth Profile Descriptor List
|
|
||||||
status &= esp_bt_sdp_add_profile_dscp_list(sdp_handle,
|
|
||||||
UUID_SERVCLASS_SAP,
|
|
||||||
rec->hdr.profile_version);
|
|
||||||
|
|
||||||
// Make the service browseable
|
|
||||||
status &= esp_bt_sdp_add_uuid_sequence (sdp_handle, ATTR_ID_BROWSE_GROUP_LIST, 1, &browse);
|
|
||||||
|
|
||||||
if (!status)
|
|
||||||
{
|
|
||||||
esp_bt_sdp_delete_record(sdp_handle);
|
|
||||||
sdp_handle = 0;
|
|
||||||
APPL_TRACE_ERROR("%s(): FAILED deleting record\n", __func__);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
bta_sys_add_uuid(UUID_SERVCLASS_SAP);
|
|
||||||
APPL_TRACE_DEBUG("%s(): SDP Registered (handle 0x%08x)\n", __func__, sdp_handle);
|
|
||||||
}
|
|
||||||
return sdp_handle;
|
|
||||||
}
|
|
||||||
|
|
36
examples/09_a2dp/components/bluedroid_demos/btif/btif_sm.c
Executable file → Normal file
36
examples/09_a2dp/components/bluedroid_demos/btif/btif_sm.c
Executable file → Normal file
@ -80,15 +80,14 @@ btif_sm_handle_t btif_sm_init(const btif_sm_handler_t *p_handlers, btif_sm_state
|
|||||||
{
|
{
|
||||||
btif_sm_cb_t *p_cb;
|
btif_sm_cb_t *p_cb;
|
||||||
|
|
||||||
if (p_handlers == NULL)
|
if (p_handlers == NULL) {
|
||||||
{
|
|
||||||
BTIF_TRACE_ERROR("%s : p_handlers is NULL", __FUNCTION__);
|
BTIF_TRACE_ERROR("%s : p_handlers is NULL", __FUNCTION__);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
p_cb = (btif_sm_cb_t *)osi_malloc(sizeof(btif_sm_cb_t));
|
p_cb = (btif_sm_cb_t *)osi_malloc(sizeof(btif_sm_cb_t));
|
||||||
p_cb->state = initial_state;
|
p_cb->state = initial_state;
|
||||||
p_cb->p_handlers = (btif_sm_handler_t*)p_handlers;
|
p_cb->p_handlers = (btif_sm_handler_t *)p_handlers;
|
||||||
|
|
||||||
/* Send BTIF_SM_ENTER_EVT to the initial state */
|
/* Send BTIF_SM_ENTER_EVT to the initial state */
|
||||||
p_cb->p_handlers[initial_state](BTIF_SM_ENTER_EVT, NULL);
|
p_cb->p_handlers[initial_state](BTIF_SM_ENTER_EVT, NULL);
|
||||||
@ -107,10 +106,9 @@ btif_sm_handle_t btif_sm_init(const btif_sm_handler_t *p_handlers, btif_sm_state
|
|||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
void btif_sm_shutdown(btif_sm_handle_t handle)
|
void btif_sm_shutdown(btif_sm_handle_t handle)
|
||||||
{
|
{
|
||||||
btif_sm_cb_t *p_cb = (btif_sm_cb_t*)handle;
|
btif_sm_cb_t *p_cb = (btif_sm_cb_t *)handle;
|
||||||
|
|
||||||
if (p_cb == NULL)
|
if (p_cb == NULL) {
|
||||||
{
|
|
||||||
BTIF_TRACE_ERROR("%s : Invalid handle", __FUNCTION__);
|
BTIF_TRACE_ERROR("%s : Invalid handle", __FUNCTION__);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -128,10 +126,9 @@ void btif_sm_shutdown(btif_sm_handle_t handle)
|
|||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
btif_sm_state_t btif_sm_get_state(btif_sm_handle_t handle)
|
btif_sm_state_t btif_sm_get_state(btif_sm_handle_t handle)
|
||||||
{
|
{
|
||||||
btif_sm_cb_t *p_cb = (btif_sm_cb_t*)handle;
|
btif_sm_cb_t *p_cb = (btif_sm_cb_t *)handle;
|
||||||
|
|
||||||
if (p_cb == NULL)
|
if (p_cb == NULL) {
|
||||||
{
|
|
||||||
BTIF_TRACE_ERROR("%s : Invalid handle", __FUNCTION__);
|
BTIF_TRACE_ERROR("%s : Invalid handle", __FUNCTION__);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -151,20 +148,20 @@ btif_sm_state_t btif_sm_get_state(btif_sm_handle_t handle)
|
|||||||
**
|
**
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
bt_status_t btif_sm_dispatch(btif_sm_handle_t handle, btif_sm_event_t event,
|
bt_status_t btif_sm_dispatch(btif_sm_handle_t handle, btif_sm_event_t event,
|
||||||
void *data)
|
void *data)
|
||||||
{
|
{
|
||||||
bt_status_t status = BT_STATUS_SUCCESS;
|
bt_status_t status = BT_STATUS_SUCCESS;
|
||||||
|
|
||||||
btif_sm_cb_t *p_cb = (btif_sm_cb_t*)handle;
|
btif_sm_cb_t *p_cb = (btif_sm_cb_t *)handle;
|
||||||
|
|
||||||
if (p_cb == NULL)
|
if (p_cb == NULL) {
|
||||||
{
|
|
||||||
BTIF_TRACE_ERROR("%s : Invalid handle", __FUNCTION__);
|
BTIF_TRACE_ERROR("%s : Invalid handle", __FUNCTION__);
|
||||||
return BT_STATUS_FAIL;
|
return BT_STATUS_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (p_cb->p_handlers[p_cb->state](event, data) == FALSE)
|
if (p_cb->p_handlers[p_cb->state](event, data) == FALSE) {
|
||||||
return BT_STATUS_UNHANDLED;
|
return BT_STATUS_UNHANDLED;
|
||||||
|
}
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
@ -185,24 +182,25 @@ bt_status_t btif_sm_dispatch(btif_sm_handle_t handle, btif_sm_event_t event,
|
|||||||
bt_status_t btif_sm_change_state(btif_sm_handle_t handle, btif_sm_state_t state)
|
bt_status_t btif_sm_change_state(btif_sm_handle_t handle, btif_sm_state_t state)
|
||||||
{
|
{
|
||||||
bt_status_t status = BT_STATUS_SUCCESS;
|
bt_status_t status = BT_STATUS_SUCCESS;
|
||||||
btif_sm_cb_t *p_cb = (btif_sm_cb_t*)handle;
|
btif_sm_cb_t *p_cb = (btif_sm_cb_t *)handle;
|
||||||
|
|
||||||
if (p_cb == NULL)
|
if (p_cb == NULL) {
|
||||||
{
|
|
||||||
BTIF_TRACE_ERROR("%s : Invalid handle", __FUNCTION__);
|
BTIF_TRACE_ERROR("%s : Invalid handle", __FUNCTION__);
|
||||||
return BT_STATUS_FAIL;
|
return BT_STATUS_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Send exit event to the current state */
|
/* Send exit event to the current state */
|
||||||
if (p_cb->p_handlers[p_cb->state](BTIF_SM_EXIT_EVT, NULL) == FALSE)
|
if (p_cb->p_handlers[p_cb->state](BTIF_SM_EXIT_EVT, NULL) == FALSE) {
|
||||||
status = BT_STATUS_UNHANDLED;
|
status = BT_STATUS_UNHANDLED;
|
||||||
|
}
|
||||||
|
|
||||||
/* Change to the new state */
|
/* Change to the new state */
|
||||||
p_cb->state = state;
|
p_cb->state = state;
|
||||||
|
|
||||||
/* Send enter event to the new state */
|
/* Send enter event to the new state */
|
||||||
if (p_cb->p_handlers[p_cb->state](BTIF_SM_ENTER_EVT, NULL) == FALSE)
|
if (p_cb->p_handlers[p_cb->state](BTIF_SM_ENTER_EVT, NULL) == FALSE) {
|
||||||
status = BT_STATUS_UNHANDLED;
|
status = BT_STATUS_UNHANDLED;
|
||||||
|
}
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
36
examples/09_a2dp/components/bluedroid_demos/btif/btif_util.c
Executable file → Normal file
36
examples/09_a2dp/components/bluedroid_demos/btif/btif_util.c
Executable file → Normal file
@ -82,7 +82,7 @@
|
|||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
const char *dump_rc_event(UINT8 event)
|
const char *dump_rc_event(UINT8 event)
|
||||||
{
|
{
|
||||||
switch(event) {
|
switch (event) {
|
||||||
CASE_RETURN_STR(BTA_AV_RC_OPEN_EVT)
|
CASE_RETURN_STR(BTA_AV_RC_OPEN_EVT)
|
||||||
CASE_RETURN_STR(BTA_AV_RC_CLOSE_EVT)
|
CASE_RETURN_STR(BTA_AV_RC_CLOSE_EVT)
|
||||||
CASE_RETURN_STR(BTA_AV_REMOTE_CMD_EVT)
|
CASE_RETURN_STR(BTA_AV_REMOTE_CMD_EVT)
|
||||||
@ -91,15 +91,14 @@ const char *dump_rc_event(UINT8 event)
|
|||||||
CASE_RETURN_STR(BTA_AV_VENDOR_RSP_EVT)
|
CASE_RETURN_STR(BTA_AV_VENDOR_RSP_EVT)
|
||||||
CASE_RETURN_STR(BTA_AV_META_MSG_EVT)
|
CASE_RETURN_STR(BTA_AV_META_MSG_EVT)
|
||||||
CASE_RETURN_STR(BTA_AV_RC_FEAT_EVT)
|
CASE_RETURN_STR(BTA_AV_RC_FEAT_EVT)
|
||||||
default:
|
default:
|
||||||
return "UNKNOWN_EVENT";
|
return "UNKNOWN_EVENT";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const char * dump_rc_notification_event_id(UINT8 event_id)
|
const char *dump_rc_notification_event_id(UINT8 event_id)
|
||||||
{
|
{
|
||||||
switch(event_id)
|
switch (event_id) {
|
||||||
{
|
|
||||||
CASE_RETURN_STR(AVRC_EVT_PLAY_STATUS_CHANGE)
|
CASE_RETURN_STR(AVRC_EVT_PLAY_STATUS_CHANGE)
|
||||||
CASE_RETURN_STR(AVRC_EVT_TRACK_CHANGE)
|
CASE_RETURN_STR(AVRC_EVT_TRACK_CHANGE)
|
||||||
CASE_RETURN_STR(AVRC_EVT_TRACK_REACHED_END)
|
CASE_RETURN_STR(AVRC_EVT_TRACK_REACHED_END)
|
||||||
@ -110,15 +109,14 @@ const char * dump_rc_notification_event_id(UINT8 event_id)
|
|||||||
CASE_RETURN_STR(AVRC_EVT_APP_SETTING_CHANGE)
|
CASE_RETURN_STR(AVRC_EVT_APP_SETTING_CHANGE)
|
||||||
CASE_RETURN_STR(AVRC_EVT_VOLUME_CHANGE)
|
CASE_RETURN_STR(AVRC_EVT_VOLUME_CHANGE)
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return "Unhandled Event ID";
|
return "Unhandled Event ID";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* dump_rc_pdu(UINT8 pdu)
|
const char *dump_rc_pdu(UINT8 pdu)
|
||||||
{
|
{
|
||||||
switch(pdu)
|
switch (pdu) {
|
||||||
{
|
|
||||||
CASE_RETURN_STR(AVRC_PDU_LIST_PLAYER_APP_ATTR)
|
CASE_RETURN_STR(AVRC_PDU_LIST_PLAYER_APP_ATTR)
|
||||||
CASE_RETURN_STR(AVRC_PDU_LIST_PLAYER_APP_VALUES)
|
CASE_RETURN_STR(AVRC_PDU_LIST_PLAYER_APP_VALUES)
|
||||||
CASE_RETURN_STR(AVRC_PDU_GET_CUR_PLAYER_APP_VALUE)
|
CASE_RETURN_STR(AVRC_PDU_GET_CUR_PLAYER_APP_VALUE)
|
||||||
@ -133,8 +131,8 @@ const char* dump_rc_pdu(UINT8 pdu)
|
|||||||
CASE_RETURN_STR(AVRC_PDU_REQUEST_CONTINUATION_RSP)
|
CASE_RETURN_STR(AVRC_PDU_REQUEST_CONTINUATION_RSP)
|
||||||
CASE_RETURN_STR(AVRC_PDU_ABORT_CONTINUATION_RSP)
|
CASE_RETURN_STR(AVRC_PDU_ABORT_CONTINUATION_RSP)
|
||||||
CASE_RETURN_STR(AVRC_PDU_SET_ABSOLUTE_VOLUME)
|
CASE_RETURN_STR(AVRC_PDU_SET_ABSOLUTE_VOLUME)
|
||||||
default:
|
default:
|
||||||
return "Unknown PDU";
|
return "Unknown PDU";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -142,8 +140,7 @@ UINT32 devclass2uint(DEV_CLASS dev_class)
|
|||||||
{
|
{
|
||||||
UINT32 cod = 0;
|
UINT32 cod = 0;
|
||||||
|
|
||||||
if(dev_class != NULL)
|
if (dev_class != NULL) {
|
||||||
{
|
|
||||||
/* if COD is 0, irrespective of the device type set it to Unclassified device */
|
/* if COD is 0, irrespective of the device type set it to Unclassified device */
|
||||||
cod = (dev_class[2]) | (dev_class[1] << 8) | (dev_class[0] << 16);
|
cod = (dev_class[2]) | (dev_class[1] << 8) | (dev_class[0] << 16);
|
||||||
}
|
}
|
||||||
@ -157,9 +154,10 @@ void uint2devclass(UINT32 cod, DEV_CLASS dev_class)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static const UINT8 sdp_base_uuid[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,
|
static const UINT8 sdp_base_uuid[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,
|
||||||
0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB};
|
0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB
|
||||||
|
};
|
||||||
|
|
||||||
void uuid16_to_uuid128(uint16_t uuid16, bt_uuid_t* uuid128)
|
void uuid16_to_uuid128(uint16_t uuid16, bt_uuid_t *uuid128)
|
||||||
{
|
{
|
||||||
uint16_t uuid16_bo;
|
uint16_t uuid16_bo;
|
||||||
memset(uuid128, 0, sizeof(bt_uuid_t));
|
memset(uuid128, 0, sizeof(bt_uuid_t));
|
||||||
@ -175,7 +173,7 @@ void string_to_uuid(char *str, bt_uuid_t *p_uuid)
|
|||||||
uint16_t uuid1, uuid2, uuid3, uuid5;
|
uint16_t uuid1, uuid2, uuid3, uuid5;
|
||||||
|
|
||||||
sscanf(str, "%08x-%04hx-%04hx-%04hx-%08x%04hx",
|
sscanf(str, "%08x-%04hx-%04hx-%04hx-%08x%04hx",
|
||||||
&uuid0, &uuid1, &uuid2, &uuid3, &uuid4, &uuid5);
|
&uuid0, &uuid1, &uuid2, &uuid3, &uuid4, &uuid5);
|
||||||
|
|
||||||
uuid0 = htonl(uuid0);
|
uuid0 = htonl(uuid0);
|
||||||
uuid1 = htons(uuid1);
|
uuid1 = htons(uuid1);
|
||||||
|
507
examples/09_a2dp/components/bluedroid_demos/btif/co/bta_av_co.c
Executable file → Normal file
507
examples/09_a2dp/components/bluedroid_demos/btif/co/bta_av_co.c
Executable file → Normal file
File diff suppressed because it is too large
Load Diff
14
examples/09_a2dp/components/bluedroid_demos/btif/include/btif_av_api.h
Executable file → Normal file
14
examples/09_a2dp/components/bluedroid_demos/btif/include/btif_av_api.h
Executable file → Normal file
@ -175,8 +175,7 @@ typedef UINT8 tBTIF_AV_CHANNEL_MODE;
|
|||||||
/**
|
/**
|
||||||
* Structure used to configure the AV codec capabilities/config
|
* Structure used to configure the AV codec capabilities/config
|
||||||
*/
|
*/
|
||||||
typedef struct
|
typedef struct {
|
||||||
{
|
|
||||||
tBTIF_AV_CODEC_ID id; /* Codec ID (in terms of BTIF) */
|
tBTIF_AV_CODEC_ID id; /* Codec ID (in terms of BTIF) */
|
||||||
UINT8 info[AVDT_CODEC_SIZE]; /* Codec info (can be config or capabilities) */
|
UINT8 info[AVDT_CODEC_SIZE]; /* Codec info (can be config or capabilities) */
|
||||||
} tBTIF_AV_CODEC_INFO;
|
} tBTIF_AV_CODEC_INFO;
|
||||||
@ -184,20 +183,17 @@ typedef struct
|
|||||||
/**
|
/**
|
||||||
* Structure used to configure the AV media feeding
|
* Structure used to configure the AV media feeding
|
||||||
*/
|
*/
|
||||||
typedef struct
|
typedef struct {
|
||||||
{
|
|
||||||
UINT16 sampling_freq; /* 44100, 48000 etc */
|
UINT16 sampling_freq; /* 44100, 48000 etc */
|
||||||
UINT16 num_channel; /* 1 for mono or 2 stereo */
|
UINT16 num_channel; /* 1 for mono or 2 stereo */
|
||||||
UINT8 bit_per_sample; /* Number of bits per sample (8, 16) */
|
UINT8 bit_per_sample; /* Number of bits per sample (8, 16) */
|
||||||
} tBTIF_AV_MEDIA_FEED_CFG_PCM;
|
} tBTIF_AV_MEDIA_FEED_CFG_PCM;
|
||||||
|
|
||||||
typedef union
|
typedef union {
|
||||||
{
|
|
||||||
tBTIF_AV_MEDIA_FEED_CFG_PCM pcm; /* Raw PCM feeding format */
|
tBTIF_AV_MEDIA_FEED_CFG_PCM pcm; /* Raw PCM feeding format */
|
||||||
}tBTIF_AV_MEDIA_FEED_CFG;
|
} tBTIF_AV_MEDIA_FEED_CFG;
|
||||||
|
|
||||||
typedef struct
|
typedef struct {
|
||||||
{
|
|
||||||
tBTIF_AV_CODEC_ID format; /* Media codec identifier */
|
tBTIF_AV_CODEC_ID format; /* Media codec identifier */
|
||||||
tBTIF_AV_MEDIA_FEED_CFG cfg; /* Media codec configuration */
|
tBTIF_AV_MEDIA_FEED_CFG cfg; /* Media codec configuration */
|
||||||
} tBTIF_AV_MEDIA_FEEDINGS;
|
} tBTIF_AV_MEDIA_FEEDINGS;
|
||||||
|
3
examples/09_a2dp/components/bluedroid_demos/btif/include/btif_av_co.h
Executable file → Normal file
3
examples/09_a2dp/components/bluedroid_demos/btif/include/btif_av_co.h
Executable file → Normal file
@ -25,8 +25,7 @@
|
|||||||
** Constants & Macros
|
** Constants & Macros
|
||||||
********************************************************************************/
|
********************************************************************************/
|
||||||
|
|
||||||
enum
|
enum {
|
||||||
{
|
|
||||||
BTIF_SV_AV_AA_SBC_INDEX = 0,
|
BTIF_SV_AV_AA_SBC_INDEX = 0,
|
||||||
BTIF_SV_AV_AA_SBC_SINK_INDEX,
|
BTIF_SV_AV_AA_SBC_SINK_INDEX,
|
||||||
BTIF_SV_AV_AA_SEP_INDEX /* Last index */
|
BTIF_SV_AV_AA_SEP_INDEX /* Last index */
|
||||||
|
16
examples/09_a2dp/components/bluedroid_demos/btif/include/btif_common.h
Executable file → Normal file
16
examples/09_a2dp/components/bluedroid_demos/btif/include/btif_common.h
Executable file → Normal file
@ -63,8 +63,7 @@
|
|||||||
* BTIF events for requests that require context switch to btif task
|
* BTIF events for requests that require context switch to btif task
|
||||||
* on downstreams path
|
* on downstreams path
|
||||||
*/
|
*/
|
||||||
enum
|
enum {
|
||||||
{
|
|
||||||
BTIF_CORE_API_START = BTIF_SIG_START(BTIF_CORE),
|
BTIF_CORE_API_START = BTIF_SIG_START(BTIF_CORE),
|
||||||
/* add here */
|
/* add here */
|
||||||
|
|
||||||
@ -72,12 +71,12 @@ enum
|
|||||||
BTIF_DM_ENABLE_SERVICE,
|
BTIF_DM_ENABLE_SERVICE,
|
||||||
BTIF_DM_DISABLE_SERVICE,
|
BTIF_DM_DISABLE_SERVICE,
|
||||||
/* add here */
|
/* add here */
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
SIG_BTIF_WORK = 0xff
|
SIG_BTIF_WORK = 0xff
|
||||||
};
|
};
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
** Type definitions for callback functions
|
** Type definitions for callback functions
|
||||||
@ -92,10 +91,9 @@ typedef void (tBTIF_COPY_CBACK) (UINT16 event, char *p_dest, char *p_src);
|
|||||||
********************************************************************************/
|
********************************************************************************/
|
||||||
|
|
||||||
/* this type handles all btif context switches between BTU and HAL */
|
/* this type handles all btif context switches between BTU and HAL */
|
||||||
typedef struct
|
typedef struct {
|
||||||
{
|
|
||||||
BT_HDR hdr;
|
BT_HDR hdr;
|
||||||
tBTIF_CBACK* p_cb; /* context switch callback */
|
tBTIF_CBACK *p_cb; /* context switch callback */
|
||||||
|
|
||||||
/* parameters passed to callback */
|
/* parameters passed to callback */
|
||||||
UINT16 event; /* message event id */
|
UINT16 event; /* message event id */
|
||||||
@ -107,8 +105,8 @@ typedef struct
|
|||||||
** Functions
|
** Functions
|
||||||
********************************************************************************/
|
********************************************************************************/
|
||||||
|
|
||||||
bt_status_t btif_transfer_context (tBTIF_CBACK *p_cback, UINT16 event, char* p_params,
|
bt_status_t btif_transfer_context (tBTIF_CBACK *p_cback, UINT16 event, char *p_params,
|
||||||
int param_len, tBTIF_COPY_CBACK *p_copy_cback);
|
int param_len, tBTIF_COPY_CBACK *p_copy_cback);
|
||||||
tBTA_SERVICE_MASK btif_get_enabled_services_mask(void);
|
tBTA_SERVICE_MASK btif_get_enabled_services_mask(void);
|
||||||
bt_status_t btif_enable_service(tBTA_SERVICE_ID service_id);
|
bt_status_t btif_enable_service(tBTA_SERVICE_ID service_id);
|
||||||
bt_status_t btif_disable_service(tBTA_SERVICE_ID service_id);
|
bt_status_t btif_disable_service(tBTA_SERVICE_ID service_id);
|
||||||
|
52
examples/09_a2dp/components/bluedroid_demos/btif/include/btif_media.h
Executable file → Normal file
52
examples/09_a2dp/components/bluedroid_demos/btif/include/btif_media.h
Executable file → Normal file
@ -63,39 +63,35 @@
|
|||||||
typedef int tBTIF_STATUS;
|
typedef int tBTIF_STATUS;
|
||||||
|
|
||||||
/* tBTIF_MEDIA_INIT_AUDIO msg structure */
|
/* tBTIF_MEDIA_INIT_AUDIO msg structure */
|
||||||
typedef struct
|
typedef struct {
|
||||||
{
|
BT_HDR hdr;
|
||||||
BT_HDR hdr;
|
UINT16 SamplingFreq; /* 16k, 32k, 44.1k or 48k*/
|
||||||
UINT16 SamplingFreq; /* 16k, 32k, 44.1k or 48k*/
|
UINT8 ChannelMode; /* mono, dual, stereo or joint stereo*/
|
||||||
UINT8 ChannelMode; /* mono, dual, stereo or joint stereo*/
|
UINT8 NumOfSubBands; /* 4 or 8 */
|
||||||
UINT8 NumOfSubBands; /* 4 or 8 */
|
UINT8 NumOfBlocks; /* 4, 8, 12 or 16*/
|
||||||
UINT8 NumOfBlocks; /* 4, 8, 12 or 16*/
|
UINT8 AllocationMethod; /* loudness or SNR*/
|
||||||
UINT8 AllocationMethod; /* loudness or SNR*/
|
UINT16 MtuSize; /* peer mtu size */
|
||||||
UINT16 MtuSize; /* peer mtu size */
|
|
||||||
} tBTIF_MEDIA_INIT_AUDIO;
|
} tBTIF_MEDIA_INIT_AUDIO;
|
||||||
|
|
||||||
#if (BTA_AV_INCLUDED == TRUE)
|
#if (BTA_AV_INCLUDED == TRUE)
|
||||||
/* tBTIF_MEDIA_UPDATE_AUDIO msg structure */
|
/* tBTIF_MEDIA_UPDATE_AUDIO msg structure */
|
||||||
typedef struct
|
typedef struct {
|
||||||
{
|
BT_HDR hdr;
|
||||||
BT_HDR hdr;
|
UINT16 MinMtuSize; /* Minimum peer mtu size */
|
||||||
UINT16 MinMtuSize; /* Minimum peer mtu size */
|
UINT8 MaxBitPool; /* Maximum peer bitpool */
|
||||||
UINT8 MaxBitPool; /* Maximum peer bitpool */
|
UINT8 MinBitPool; /* Minimum peer bitpool */
|
||||||
UINT8 MinBitPool; /* Minimum peer bitpool */
|
|
||||||
} tBTIF_MEDIA_UPDATE_AUDIO;
|
} tBTIF_MEDIA_UPDATE_AUDIO;
|
||||||
|
|
||||||
/* tBTIF_MEDIA_INIT_AUDIO_FEEDING msg structure */
|
/* tBTIF_MEDIA_INIT_AUDIO_FEEDING msg structure */
|
||||||
typedef struct
|
typedef struct {
|
||||||
{
|
BT_HDR hdr;
|
||||||
BT_HDR hdr;
|
tBTIF_AV_FEEDING_MODE feeding_mode;
|
||||||
tBTIF_AV_FEEDING_MODE feeding_mode;
|
tBTIF_AV_MEDIA_FEEDINGS feeding;
|
||||||
tBTIF_AV_MEDIA_FEEDINGS feeding;
|
|
||||||
} tBTIF_MEDIA_INIT_AUDIO_FEEDING;
|
} tBTIF_MEDIA_INIT_AUDIO_FEEDING;
|
||||||
|
|
||||||
typedef struct
|
typedef struct {
|
||||||
{
|
BT_HDR hdr;
|
||||||
BT_HDR hdr;
|
UINT8 codec_info[AVDT_CODEC_SIZE];
|
||||||
UINT8 codec_info[AVDT_CODEC_SIZE];
|
|
||||||
} tBTIF_MEDIA_SINK_CFG_UPDATE;
|
} tBTIF_MEDIA_SINK_CFG_UPDATE;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -123,7 +119,7 @@ extern void btif_media_task(void);
|
|||||||
** Returns TRUE is success
|
** Returns TRUE is success
|
||||||
**
|
**
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
extern BOOLEAN btif_media_task_enc_init_req(tBTIF_MEDIA_INIT_AUDIO * p_msg);
|
extern BOOLEAN btif_media_task_enc_init_req(tBTIF_MEDIA_INIT_AUDIO *p_msg);
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
**
|
**
|
||||||
@ -135,7 +131,7 @@ extern BOOLEAN btif_media_task_enc_init_req(tBTIF_MEDIA_INIT_AUDIO * p_msg);
|
|||||||
**
|
**
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
#if (BTA_AV_INCLUDED == TRUE)
|
#if (BTA_AV_INCLUDED == TRUE)
|
||||||
extern BOOLEAN btif_media_task_enc_update_req(tBTIF_MEDIA_UPDATE_AUDIO * p_msg);
|
extern BOOLEAN btif_media_task_enc_update_req(tBTIF_MEDIA_UPDATE_AUDIO *p_msg);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
@ -201,7 +197,7 @@ extern BT_HDR *btif_media_aa_readbuf(void);
|
|||||||
**
|
**
|
||||||
** Returns size of the queue
|
** Returns size of the queue
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
UINT8 btif_media_sink_enque_buf(BT_HDR *p_buf);
|
UINT8 btif_media_sink_enque_buf(BT_HDR *p_buf);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -226,7 +222,7 @@ extern void btif_media_aa_writebuf(BT_HDR *pBuf, UINT32 timestamp, UINT16 seq_nu
|
|||||||
**
|
**
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
extern BOOLEAN btif_media_av_writebuf(UINT8 *p_media, UINT32 media_len,
|
extern BOOLEAN btif_media_av_writebuf(UINT8 *p_media, UINT32 media_len,
|
||||||
UINT32 timestamp, UINT16 seq_num);
|
UINT32 timestamp, UINT16 seq_num);
|
||||||
|
|
||||||
#if (BTA_AV_INCLUDED == TRUE)
|
#if (BTA_AV_INCLUDED == TRUE)
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
|
@ -1,38 +0,0 @@
|
|||||||
#ifndef __BTIF_SDP_H__
|
|
||||||
#define __BTIF_SDP_H__
|
|
||||||
|
|
||||||
#include "bt_sdp.h"
|
|
||||||
|
|
||||||
/** Callback for SDP search */
|
|
||||||
typedef void (*btsdp_search_callback)(bt_status_t status, bt_bdaddr_t *bd_addr, uint8_t* uuid, int num_records, bluetooth_sdp_record *records);
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
btsdp_search_callback sdp_search_cb;
|
|
||||||
} btsdp_callbacks_t;
|
|
||||||
|
|
||||||
/** Register BT SDP search callbacks */
|
|
||||||
bt_status_t BTIF_SdpInit(btsdp_callbacks_t *callbacks);
|
|
||||||
|
|
||||||
/** Unregister BT SDP */
|
|
||||||
bt_status_t BTIF_SdpDeinit(void);
|
|
||||||
|
|
||||||
/** Search for SDP records with specific uuid on remote device */
|
|
||||||
bt_status_t BTIF_SdpSearch(bt_bdaddr_t *bd_addr, const uint8_t* uuid);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Use listen in the socket interface to create rfcomm and/or l2cap PSM channels,
|
|
||||||
* (without UUID and service_name and set the BTSOCK_FLAG_NO_SDP flag in flags).
|
|
||||||
* Then use createSdpRecord to create the SDP record associated with the rfcomm/l2cap channels.
|
|
||||||
*
|
|
||||||
* Returns a handle to the SDP record, which can be parsed to remove_sdp_record.
|
|
||||||
*
|
|
||||||
* record (in) The SDP record to create
|
|
||||||
* record_handle (out)The corresponding record handle will be written to this pointer.
|
|
||||||
*/
|
|
||||||
bt_status_t BTIF_SdpCreateRecord(bluetooth_sdp_record *record, int* record_handle);
|
|
||||||
|
|
||||||
/** Remove a SDP record created by BTIF_SdpCreateRecord */
|
|
||||||
bt_status_t BTIF_SdpRemoveRecord(int record_handle);
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* __BTIF_SDP_H__ */
|
|
6
examples/09_a2dp/components/bluedroid_demos/btif/include/btif_sm.h
Executable file → Normal file
6
examples/09_a2dp/components/bluedroid_demos/btif/include/btif_sm.h
Executable file → Normal file
@ -41,7 +41,7 @@
|
|||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
typedef UINT32 btif_sm_state_t;
|
typedef UINT32 btif_sm_state_t;
|
||||||
typedef UINT32 btif_sm_event_t;
|
typedef UINT32 btif_sm_event_t;
|
||||||
typedef void* btif_sm_handle_t;
|
typedef void *btif_sm_handle_t;
|
||||||
typedef BOOLEAN(*btif_sm_handler_t)(btif_sm_event_t event, void *data);
|
typedef BOOLEAN(*btif_sm_handler_t)(btif_sm_event_t event, void *data);
|
||||||
|
|
||||||
|
|
||||||
@ -65,7 +65,7 @@ typedef BOOLEAN(*btif_sm_handler_t)(btif_sm_event_t event, void *data);
|
|||||||
**
|
**
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
btif_sm_handle_t btif_sm_init(const btif_sm_handler_t *p_handlers,
|
btif_sm_handle_t btif_sm_init(const btif_sm_handler_t *p_handlers,
|
||||||
btif_sm_state_t initial_state);
|
btif_sm_state_t initial_state);
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
**
|
**
|
||||||
@ -99,7 +99,7 @@ btif_sm_state_t btif_sm_get_state(btif_sm_handle_t handle);
|
|||||||
**
|
**
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
bt_status_t btif_sm_dispatch(btif_sm_handle_t handle, btif_sm_event_t event,
|
bt_status_t btif_sm_dispatch(btif_sm_handle_t handle, btif_sm_event_t event,
|
||||||
void *data);
|
void *data);
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
**
|
**
|
||||||
|
8
examples/09_a2dp/components/bluedroid_demos/btif/include/btif_util.h
Executable file → Normal file
8
examples/09_a2dp/components/bluedroid_demos/btif/include/btif_util.h
Executable file → Normal file
@ -43,13 +43,13 @@ typedef char bdstr_t[18];
|
|||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
** Functions
|
** Functions
|
||||||
********************************************************************************/
|
********************************************************************************/
|
||||||
const char* dump_rc_event(UINT8 event);
|
const char *dump_rc_event(UINT8 event);
|
||||||
const char* dump_rc_notification_event_id(UINT8 event_id);
|
const char *dump_rc_notification_event_id(UINT8 event_id);
|
||||||
const char* dump_rc_pdu(UINT8 pdu);
|
const char *dump_rc_pdu(UINT8 pdu);
|
||||||
|
|
||||||
UINT32 devclass2uint(DEV_CLASS dev_class);
|
UINT32 devclass2uint(DEV_CLASS dev_class);
|
||||||
void uint2devclass(UINT32 dev, DEV_CLASS dev_class);
|
void uint2devclass(UINT32 dev, DEV_CLASS dev_class);
|
||||||
void uuid16_to_uuid128(uint16_t uuid16, bt_uuid_t* uuid128);
|
void uuid16_to_uuid128(uint16_t uuid16, bt_uuid_t *uuid128);
|
||||||
|
|
||||||
void uuid_to_string_legacy(bt_uuid_t *p_uuid, char *str);
|
void uuid_to_string_legacy(bt_uuid_t *p_uuid, char *str);
|
||||||
void string_to_uuid(char *str, bt_uuid_t *p_uuid);
|
void string_to_uuid(char *str, bt_uuid_t *p_uuid);
|
||||||
|
6
examples/09_a2dp/components/bluedroid_demos/btif/include/uinput.h
Executable file → Normal file
6
examples/09_a2dp/components/bluedroid_demos/btif/include/uinput.h
Executable file → Normal file
@ -24,8 +24,8 @@ extern "C" {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
// #include <sys/time.h>
|
// #include <sys/time.h>
|
||||||
// #include <sys/ioctl.h>
|
// #include <sys/ioctl.h>
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
** Constants & Macros
|
** Constants & Macros
|
||||||
@ -580,7 +580,7 @@ struct uinput_dev {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct uinput_event {
|
struct uinput_event {
|
||||||
// struct timeval time; // temporarily remove this part;
|
// struct timeval time; // temporarily remove this part;
|
||||||
uint16_t type;
|
uint16_t type;
|
||||||
uint16_t code;
|
uint16_t code;
|
||||||
int32_t value;
|
int32_t value;
|
||||||
|
@ -40,12 +40,11 @@ static bt_status_t event_init_stack(bt_callbacks_t *cb)
|
|||||||
return BT_STATUS_FAIL;
|
return BT_STATUS_FAIL;
|
||||||
}
|
}
|
||||||
if (ret == BT_STATUS_SUCCESS) {
|
if (ret == BT_STATUS_SUCCESS) {
|
||||||
bt_hal_cbacks = cb;
|
bt_hal_cbacks = cb;
|
||||||
stack_is_initialized = true;
|
stack_is_initialized = true;
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
return BT_STATUS_DONE;
|
return BT_STATUS_DONE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -56,7 +55,7 @@ static bt_status_t event_start_up_stack(void)
|
|||||||
LOG_DEBUG("%s stack not initialized yet.\n", __func__);
|
LOG_DEBUG("%s stack not initialized yet.\n", __func__);
|
||||||
return BT_STATUS_NOT_READY;
|
return BT_STATUS_NOT_READY;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stack_is_running) {
|
if (stack_is_running) {
|
||||||
LOG_DEBUG("%s stack already brought up.\n", __func__);
|
LOG_DEBUG("%s stack already brought up.\n", __func__);
|
||||||
return BT_STATUS_DONE;
|
return BT_STATUS_DONE;
|
||||||
@ -109,9 +108,9 @@ static bt_status_t event_clean_up_stack(void)
|
|||||||
if (stack_is_running) {
|
if (stack_is_running) {
|
||||||
event_shut_down_stack();
|
event_shut_down_stack();
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG_DEBUG("%s is cleaning up the stack.\n", __func__);
|
LOG_DEBUG("%s is cleaning up the stack.\n", __func__);
|
||||||
|
|
||||||
stack_is_initialized = false;
|
stack_is_initialized = false;
|
||||||
|
|
||||||
btif_shutdown_bluetooth();
|
btif_shutdown_bluetooth();
|
||||||
|
2
examples/09_a2dp/components/bluedroid_demos/embdrv/sbc/decoder/include/oi_assert.h
Executable file → Normal file
2
examples/09_a2dp/components/bluedroid_demos/embdrv/sbc/decoder/include/oi_assert.h
Executable file → Normal file
@ -44,7 +44,7 @@ extern "C" {
|
|||||||
does not evaluate to true, the OI_ASSERT macro calls the host-dependent function,
|
does not evaluate to true, the OI_ASSERT macro calls the host-dependent function,
|
||||||
OI_AssertFail(), which reports the failure and generates a runtime error.
|
OI_AssertFail(), which reports the failure and generates a runtime error.
|
||||||
*/
|
*/
|
||||||
void OI_AssertFail(char* file, int line, char* reason);
|
void OI_AssertFail(char *file, int line, char *reason);
|
||||||
|
|
||||||
|
|
||||||
#define OI_ASSERT(condition) \
|
#define OI_ASSERT(condition) \
|
||||||
|
6
examples/09_a2dp/components/bluedroid_demos/embdrv/sbc/decoder/include/oi_bitstream.h
Executable file → Normal file
6
examples/09_a2dp/components/bluedroid_demos/embdrv/sbc/decoder/include/oi_bitstream.h
Executable file → Normal file
@ -58,14 +58,14 @@ INLINE void OI_BITSTREAM_WriteUINT(OI_BITSTREAM *bs,
|
|||||||
* Use knowledge that the bitstream is aligned to optimize the write of a byte
|
* Use knowledge that the bitstream is aligned to optimize the write of a byte
|
||||||
*/
|
*/
|
||||||
PRIVATE void OI_BITSTREAM_WriteUINT8Aligned(OI_BITSTREAM *bs,
|
PRIVATE void OI_BITSTREAM_WriteUINT8Aligned(OI_BITSTREAM *bs,
|
||||||
OI_UINT8 datum);
|
OI_UINT8 datum);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Use knowledge that the bitstream is aligned to optimize the write pair of nibbles
|
* Use knowledge that the bitstream is aligned to optimize the write pair of nibbles
|
||||||
*/
|
*/
|
||||||
PRIVATE void OI_BITSTREAM_Write2xUINT4Aligned(OI_BITSTREAM *bs,
|
PRIVATE void OI_BITSTREAM_Write2xUINT4Aligned(OI_BITSTREAM *bs,
|
||||||
OI_UINT8 datum1,
|
OI_UINT8 datum1,
|
||||||
OI_UINT8 datum2);
|
OI_UINT8 datum2);
|
||||||
|
|
||||||
/** Internally the bitstream looks ahead in the stream. When
|
/** Internally the bitstream looks ahead in the stream. When
|
||||||
* OI_SBC_ReadScalefactors() goes to temporarily break the abstraction, it will
|
* OI_SBC_ReadScalefactors() goes to temporarily break the abstraction, it will
|
||||||
|
30
examples/09_a2dp/components/bluedroid_demos/embdrv/sbc/decoder/include/oi_codec_sbc.h
Executable file → Normal file
30
examples/09_a2dp/components/bluedroid_demos/embdrv/sbc/decoder/include/oi_codec_sbc.h
Executable file → Normal file
@ -154,7 +154,7 @@ typedef struct {
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
const OI_CHAR *codecInfo;
|
const OI_CHAR *codecInfo;
|
||||||
OI_CODEC_SBC_FRAME_INFO frameInfo;
|
OI_CODEC_SBC_FRAME_INFO frameInfo;
|
||||||
OI_INT8 scale_factor[SBC_MAX_CHANNELS*SBC_MAX_BANDS];
|
OI_INT8 scale_factor[SBC_MAX_CHANNELS * SBC_MAX_BANDS];
|
||||||
OI_UINT32 frameCount;
|
OI_UINT32 frameCount;
|
||||||
OI_INT32 *subdata;
|
OI_INT32 *subdata;
|
||||||
|
|
||||||
@ -163,8 +163,8 @@ typedef struct {
|
|||||||
OI_UINT filterBufferOffset;
|
OI_UINT filterBufferOffset;
|
||||||
|
|
||||||
union {
|
union {
|
||||||
OI_UINT8 uint8[SBC_MAX_CHANNELS*SBC_MAX_BANDS];
|
OI_UINT8 uint8[SBC_MAX_CHANNELS * SBC_MAX_BANDS];
|
||||||
OI_UINT32 uint32[SBC_MAX_CHANNELS*SBC_MAX_BANDS/4];
|
OI_UINT32 uint32[SBC_MAX_CHANNELS * SBC_MAX_BANDS / 4];
|
||||||
} bits;
|
} bits;
|
||||||
OI_UINT8 maxBitneed; /**< Running maximum bitneed */
|
OI_UINT8 maxBitneed; /**< Running maximum bitneed */
|
||||||
OI_BYTE formatByte;
|
OI_BYTE formatByte;
|
||||||
@ -287,13 +287,13 @@ OI_STATUS OI_CODEC_SBC_DecoderLimit(OI_CODEC_SBC_DECODER_CONTEXT *context,
|
|||||||
* @param maxBitpool The maximum bitpool size for this context
|
* @param maxBitpool The maximum bitpool size for this context
|
||||||
*/
|
*/
|
||||||
OI_STATUS OI_CODEC_SBC_DecoderConfigureRaw(OI_CODEC_SBC_DECODER_CONTEXT *context,
|
OI_STATUS OI_CODEC_SBC_DecoderConfigureRaw(OI_CODEC_SBC_DECODER_CONTEXT *context,
|
||||||
OI_BOOL enhanced,
|
OI_BOOL enhanced,
|
||||||
OI_UINT8 frequency,
|
OI_UINT8 frequency,
|
||||||
OI_UINT8 mode,
|
OI_UINT8 mode,
|
||||||
OI_UINT8 subbands,
|
OI_UINT8 subbands,
|
||||||
OI_UINT8 blocks,
|
OI_UINT8 blocks,
|
||||||
OI_UINT8 alloc,
|
OI_UINT8 alloc,
|
||||||
OI_UINT8 maxBitpool);
|
OI_UINT8 maxBitpool);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Decode one SBC frame. The frame has no header bytes. The context must have been previously
|
* Decode one SBC frame. The frame has no header bytes. The context must have been previously
|
||||||
@ -451,11 +451,11 @@ OI_CHAR *OI_CODEC_Version(void);
|
|||||||
@{
|
@{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
extern const OI_CHAR* const OI_CODEC_SBC_FreqText[];
|
extern const OI_CHAR *const OI_CODEC_SBC_FreqText[];
|
||||||
extern const OI_CHAR* const OI_CODEC_SBC_ModeText[];
|
extern const OI_CHAR *const OI_CODEC_SBC_ModeText[];
|
||||||
extern const OI_CHAR* const OI_CODEC_SBC_SubbandsText[];
|
extern const OI_CHAR *const OI_CODEC_SBC_SubbandsText[];
|
||||||
extern const OI_CHAR* const OI_CODEC_SBC_BlocksText[];
|
extern const OI_CHAR *const OI_CODEC_SBC_BlocksText[];
|
||||||
extern const OI_CHAR* const OI_CODEC_SBC_AllocText[];
|
extern const OI_CHAR *const OI_CODEC_SBC_AllocText[];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@}
|
@}
|
||||||
|
32
examples/09_a2dp/components/bluedroid_demos/embdrv/sbc/decoder/include/oi_codec_sbc_private.h
Executable file → Normal file
32
examples/09_a2dp/components/bluedroid_demos/embdrv/sbc/decoder/include/oi_codec_sbc_private.h
Executable file → Normal file
@ -127,21 +127,21 @@ typedef struct {
|
|||||||
#define DCTIII_8_SHIFT_OUT 14
|
#define DCTIII_8_SHIFT_OUT 14
|
||||||
|
|
||||||
OI_UINT computeBitneed(OI_CODEC_SBC_COMMON_CONTEXT *common,
|
OI_UINT computeBitneed(OI_CODEC_SBC_COMMON_CONTEXT *common,
|
||||||
OI_UINT8 *bitneeds,
|
OI_UINT8 *bitneeds,
|
||||||
OI_UINT ch,
|
OI_UINT ch,
|
||||||
OI_UINT *preferredBitpool);
|
OI_UINT *preferredBitpool);
|
||||||
|
|
||||||
void oneChannelBitAllocation(OI_CODEC_SBC_COMMON_CONTEXT *common,
|
void oneChannelBitAllocation(OI_CODEC_SBC_COMMON_CONTEXT *common,
|
||||||
BITNEED_UNION1 *bitneeds,
|
BITNEED_UNION1 *bitneeds,
|
||||||
OI_UINT ch,
|
OI_UINT ch,
|
||||||
OI_UINT bitcount);
|
OI_UINT bitcount);
|
||||||
|
|
||||||
|
|
||||||
OI_INT adjustToFitBitpool(const OI_UINT bitpool,
|
OI_INT adjustToFitBitpool(const OI_UINT bitpool,
|
||||||
OI_UINT32 *bitneeds,
|
OI_UINT32 *bitneeds,
|
||||||
const OI_UINT subbands,
|
const OI_UINT subbands,
|
||||||
OI_UINT bitcount,
|
OI_UINT bitcount,
|
||||||
OI_UINT *excess);
|
OI_UINT *excess);
|
||||||
|
|
||||||
INLINE OI_INT allocAdjustedBits(OI_UINT8 *dest,
|
INLINE OI_INT allocAdjustedBits(OI_UINT8 *dest,
|
||||||
OI_INT bits,
|
OI_INT bits,
|
||||||
@ -181,16 +181,16 @@ PRIVATE OI_UINT8 OI_SBC_CalculateChecksum(OI_CODEC_SBC_FRAME_INFO *frame, OI_BYT
|
|||||||
|
|
||||||
/* Transform functions */
|
/* Transform functions */
|
||||||
PRIVATE void shift_buffer(SBC_BUFFER_T *dest, SBC_BUFFER_T *src, OI_UINT wordCount);
|
PRIVATE void shift_buffer(SBC_BUFFER_T *dest, SBC_BUFFER_T *src, OI_UINT wordCount);
|
||||||
PRIVATE void cosineModulateSynth4(SBC_BUFFER_T * RESTRICT out, OI_INT32 const * RESTRICT in);
|
PRIVATE void cosineModulateSynth4(SBC_BUFFER_T *RESTRICT out, OI_INT32 const *RESTRICT in);
|
||||||
PRIVATE void SynthWindow40_int32_int32_symmetry_with_sum(OI_INT16 *pcm, SBC_BUFFER_T buffer[80], OI_UINT strideShift);
|
PRIVATE void SynthWindow40_int32_int32_symmetry_with_sum(OI_INT16 *pcm, SBC_BUFFER_T buffer[80], OI_UINT strideShift);
|
||||||
|
|
||||||
INLINE void dct3_4(OI_INT32 * RESTRICT out, OI_INT32 const * RESTRICT in);
|
INLINE void dct3_4(OI_INT32 *RESTRICT out, OI_INT32 const *RESTRICT in);
|
||||||
PRIVATE void analyze4_generated(SBC_BUFFER_T analysisBuffer[RESTRICT 40],
|
PRIVATE void analyze4_generated(SBC_BUFFER_T analysisBuffer[RESTRICT 40],
|
||||||
OI_INT16 *pcm,
|
OI_INT16 *pcm,
|
||||||
OI_UINT strideShift,
|
OI_UINT strideShift,
|
||||||
OI_INT32 subband[4]);
|
OI_INT32 subband[4]);
|
||||||
|
|
||||||
INLINE void dct3_8(OI_INT32 * RESTRICT out, OI_INT32 const * RESTRICT in);
|
INLINE void dct3_8(OI_INT32 *RESTRICT out, OI_INT32 const *RESTRICT in);
|
||||||
|
|
||||||
PRIVATE void analyze8_generated(SBC_BUFFER_T analysisBuffer[RESTRICT 80],
|
PRIVATE void analyze8_generated(SBC_BUFFER_T analysisBuffer[RESTRICT 80],
|
||||||
OI_INT16 *pcm,
|
OI_INT16 *pcm,
|
||||||
@ -199,9 +199,9 @@ PRIVATE void analyze8_generated(SBC_BUFFER_T analysisBuffer[RESTRICT 80],
|
|||||||
|
|
||||||
#ifdef SBC_ENHANCED
|
#ifdef SBC_ENHANCED
|
||||||
PRIVATE void analyze8_enhanced_generated(SBC_BUFFER_T analysisBuffer[RESTRICT 112],
|
PRIVATE void analyze8_enhanced_generated(SBC_BUFFER_T analysisBuffer[RESTRICT 112],
|
||||||
OI_INT16 *pcm,
|
OI_INT16 *pcm,
|
||||||
OI_UINT strideShift,
|
OI_UINT strideShift,
|
||||||
OI_INT32 subband[8]);
|
OI_INT32 subband[8]);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Decoder functions */
|
/* Decoder functions */
|
||||||
|
14
examples/09_a2dp/components/bluedroid_demos/embdrv/sbc/decoder/include/oi_cpu_dep.h
Executable file → Normal file
14
examples/09_a2dp/components/bluedroid_demos/embdrv/sbc/decoder/include/oi_cpu_dep.h
Executable file → Normal file
@ -78,7 +78,7 @@ extern "C" {
|
|||||||
#define OI_CPU_TYPE 12
|
#define OI_CPU_TYPE 12
|
||||||
|
|
||||||
#ifndef OI_CPU_TYPE
|
#ifndef OI_CPU_TYPE
|
||||||
#error "OI_CPU_TYPE type not defined"
|
#error "OI_CPU_TYPE type not defined"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**@}*/
|
/**@}*/
|
||||||
@ -151,11 +151,11 @@ typedef OI_UINT32 OI_ELEMENT_UNION; /**< Type for first element of a union to su
|
|||||||
/* The Hitachi SH C compiler defines _LIT or _BIG, depending on the endianness
|
/* The Hitachi SH C compiler defines _LIT or _BIG, depending on the endianness
|
||||||
specified to the compiler on the command line. */
|
specified to the compiler on the command line. */
|
||||||
#if defined(_LIT)
|
#if defined(_LIT)
|
||||||
#define OI_CPU_BYTE_ORDER OI_LITTLE_ENDIAN_BYTE_ORDER /**< If _LIT is defined, SH-3 platform byte ordering is little-endian. */
|
#define OI_CPU_BYTE_ORDER OI_LITTLE_ENDIAN_BYTE_ORDER /**< If _LIT is defined, SH-3 platform byte ordering is little-endian. */
|
||||||
#elif defined(_BIG)
|
#elif defined(_BIG)
|
||||||
#define OI_CPU_BYTE_ORDER OI_BIG_ENDIAN_BYTE_ORDER /**< If _BIG is defined, SH-3 platform byte ordering is big-endian. */
|
#define OI_CPU_BYTE_ORDER OI_BIG_ENDIAN_BYTE_ORDER /**< If _BIG is defined, SH-3 platform byte ordering is big-endian. */
|
||||||
#else
|
#else
|
||||||
#error SH compiler endianness undefined
|
#error SH compiler endianness undefined
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/** @name CPU/compiler-dependent primitive data type definitions for SH-3 processor family
|
/** @name CPU/compiler-dependent primitive data type definitions for SH-3 processor family
|
||||||
@ -313,7 +313,7 @@ typedef unsigned char OI_UINT8; /**< 8-bit unsigned integer values use native
|
|||||||
typedef unsigned short OI_UINT16; /**< 16-bit unsigned integer values use native unsigned short integer data type for ARM7 processor. */
|
typedef unsigned short OI_UINT16; /**< 16-bit unsigned integer values use native unsigned short integer data type for ARM7 processor. */
|
||||||
typedef unsigned long OI_UINT32; /**< 32-bit unsigned integer values use native unsigned long integer data type for ARM7 processor. */
|
typedef unsigned long OI_UINT32; /**< 32-bit unsigned integer values use native unsigned long integer data type for ARM7 processor. */
|
||||||
|
|
||||||
typedef void * OI_ELEMENT_UNION; /**< Type for first element of a union to support all data types up to pointer width. */
|
typedef void *OI_ELEMENT_UNION; /**< Type for first element of a union to support all data types up to pointer width. */
|
||||||
|
|
||||||
/**@}*/
|
/**@}*/
|
||||||
|
|
||||||
@ -333,7 +333,7 @@ typedef unsigned char OI_UINT8; /**< 8-bit unsigned integer values use native
|
|||||||
typedef unsigned short OI_UINT16; /**< 16-bit unsigned integer values use native unsigned short integer data type for ARM7 processor. */
|
typedef unsigned short OI_UINT16; /**< 16-bit unsigned integer values use native unsigned short integer data type for ARM7 processor. */
|
||||||
typedef unsigned long OI_UINT32; /**< 32-bit unsigned integer values use native unsigned long integer data type for ARM7 processor. */
|
typedef unsigned long OI_UINT32; /**< 32-bit unsigned integer values use native unsigned long integer data type for ARM7 processor. */
|
||||||
|
|
||||||
typedef void * OI_ELEMENT_UNION; /**< Type for first element of a union to support all data types up to pointer width. */
|
typedef void *OI_ELEMENT_UNION; /**< Type for first element of a union to support all data types up to pointer width. */
|
||||||
|
|
||||||
/**@}*/
|
/**@}*/
|
||||||
|
|
||||||
@ -491,7 +491,7 @@ typedef OI_UINT32 OI_ELEMENT_UNION; /**< Type for first element of a union to su
|
|||||||
|
|
||||||
|
|
||||||
#ifndef OI_CPU_BYTE_ORDER
|
#ifndef OI_CPU_BYTE_ORDER
|
||||||
#error "Byte order (endian-ness) not defined"
|
#error "Byte order (endian-ness) not defined"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
2
examples/09_a2dp/components/bluedroid_demos/embdrv/sbc/decoder/include/oi_modules.h
Executable file → Normal file
2
examples/09_a2dp/components/bluedroid_demos/embdrv/sbc/decoder/include/oi_modules.h
Executable file → Normal file
@ -54,7 +54,7 @@ extern "C" {
|
|||||||
typedef enum {
|
typedef enum {
|
||||||
/* profiles and protocols --> Updates to oi_debug.c and oi_config_table.c */
|
/* profiles and protocols --> Updates to oi_debug.c and oi_config_table.c */
|
||||||
|
|
||||||
/* XX --> Keep Enum values up-to-date! */
|
/* XX --> Keep Enum values up-to-date! */
|
||||||
OI_MODULE_AT, /**< 00 AT command processing */
|
OI_MODULE_AT, /**< 00 AT command processing */
|
||||||
OI_MODULE_A2DP, /**< 01 Advanced Audio Distribution Profile */
|
OI_MODULE_A2DP, /**< 01 Advanced Audio Distribution Profile */
|
||||||
OI_MODULE_AVCTP, /**< 02 Audio-Visual Control Transport Profile */
|
OI_MODULE_AVCTP, /**< 02 Audio-Visual Control Transport Profile */
|
||||||
|
6
examples/09_a2dp/components/bluedroid_demos/embdrv/sbc/decoder/include/oi_status.h
Executable file → Normal file
6
examples/09_a2dp/components/bluedroid_demos/embdrv/sbc/decoder/include/oi_status.h
Executable file → Normal file
@ -33,7 +33,7 @@ extern "C" {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/** test it **/
|
/** test it **/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* OI_STATUS must fit in 16 bits, so status codes can range from 0 to 66535, inclusive.
|
* OI_STATUS must fit in 16 bits, so status codes can range from 0 to 66535, inclusive.
|
||||||
@ -129,7 +129,7 @@ typedef enum {
|
|||||||
OI_L2CAP_CONNECT_REFUSED_NO_RESOURCES = 454, /**< L2CAP: Connect refused no resources */
|
OI_L2CAP_CONNECT_REFUSED_NO_RESOURCES = 454, /**< L2CAP: Connect refused no resources */
|
||||||
|
|
||||||
OI_L2CAP_CONFIG_BASE = 460, /**< L2CAP: Config base */
|
OI_L2CAP_CONFIG_BASE = 460, /**< L2CAP: Config base */
|
||||||
OI_L2CAP_CONFIG_FAIL_INVALID_PARAMETERS= 461, /**< L2CAP: Config fail invalid parameters */
|
OI_L2CAP_CONFIG_FAIL_INVALID_PARAMETERS = 461, /**< L2CAP: Config fail invalid parameters */
|
||||||
OI_L2CAP_CONFIG_FAIL_NO_REASON = 462, /**< L2CAP: Config fail no reason */
|
OI_L2CAP_CONFIG_FAIL_NO_REASON = 462, /**< L2CAP: Config fail no reason */
|
||||||
OI_L2CAP_CONFIG_FAIL_UNKNOWN_OPTIONS = 463, /**< L2CAP: Config fail unknown options */
|
OI_L2CAP_CONFIG_FAIL_UNKNOWN_OPTIONS = 463, /**< L2CAP: Config fail unknown options */
|
||||||
|
|
||||||
@ -541,7 +541,7 @@ typedef enum {
|
|||||||
OI_STATUS_RESERVED_FOR_BHAPI = 9200,
|
OI_STATUS_RESERVED_FOR_BHAPI = 9200,
|
||||||
|
|
||||||
/* Status code values reserved for Soundabout products */
|
/* Status code values reserved for Soundabout products */
|
||||||
OI_STATUS_RESERVED_FOR_SOUNDABOUT= 9400,
|
OI_STATUS_RESERVED_FOR_SOUNDABOUT = 9400,
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Status code values greater than or equal to this value are reserved for use by applications.
|
* Status code values greater than or equal to this value are reserved for use by applications.
|
||||||
|
14
examples/09_a2dp/components/bluedroid_demos/embdrv/sbc/decoder/include/oi_stddefs.h
Executable file → Normal file
14
examples/09_a2dp/components/bluedroid_demos/embdrv/sbc/decoder/include/oi_stddefs.h
Executable file → Normal file
@ -46,14 +46,14 @@ extern "C" {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HEW_TOOLCHAIN
|
#ifdef HEW_TOOLCHAIN
|
||||||
#ifdef NULL
|
#ifdef NULL
|
||||||
#undef NULL /**< Override HEW toolchain NULL definition */
|
#undef NULL /**< Override HEW toolchain NULL definition */
|
||||||
#endif
|
#endif
|
||||||
#define NULL 0 /**< HEW toolchain does not allow us to compare (void*) type to function pointer */
|
#define NULL 0 /**< HEW toolchain does not allow us to compare (void*) type to function pointer */
|
||||||
#else
|
#else
|
||||||
#ifndef NULL
|
#ifndef NULL
|
||||||
#define NULL ((void*)0) /**< This define statement sets NULL as a preprocessor alias for (void*)0 */
|
#define NULL ((void*)0) /**< This define statement sets NULL as a preprocessor alias for (void*)0 */
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
4
examples/09_a2dp/components/bluedroid_demos/embdrv/sbc/decoder/include/oi_string.h
Executable file → Normal file
4
examples/09_a2dp/components/bluedroid_demos/embdrv/sbc/decoder/include/oi_string.h
Executable file → Normal file
@ -112,7 +112,7 @@ OI_INT OI_MemCmp(void const *s1, void const *s2, OI_UINT32 n);
|
|||||||
* returns pDest.
|
* returns pDest.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
OI_CHAR* OI_Strcpy(OI_CHAR *pDest,
|
OI_CHAR *OI_Strcpy(OI_CHAR *pDest,
|
||||||
OI_CHAR const *pStr);
|
OI_CHAR const *pStr);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -122,7 +122,7 @@ OI_CHAR* OI_Strcpy(OI_CHAR *pDest,
|
|||||||
* returns pDest.
|
* returns pDest.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
OI_CHAR* OI_Strcat(OI_CHAR *pDest,
|
OI_CHAR *OI_Strcat(OI_CHAR *pDest,
|
||||||
OI_CHAR const *pStr) ;
|
OI_CHAR const *pStr) ;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
18
examples/09_a2dp/components/bluedroid_demos/embdrv/sbc/decoder/include/oi_utils.h
Executable file → Normal file
18
examples/09_a2dp/components/bluedroid_demos/embdrv/sbc/decoder/include/oi_utils.h
Executable file → Normal file
@ -232,8 +232,8 @@ void OI_VPrintf(const OI_CHAR *format, va_list argp);
|
|||||||
* @return Number of characters written or -1 in the case of an error.
|
* @return Number of characters written or -1 in the case of an error.
|
||||||
*/
|
*/
|
||||||
OI_INT32 OI_SNPrintf(OI_CHAR *buffer,
|
OI_INT32 OI_SNPrintf(OI_CHAR *buffer,
|
||||||
OI_UINT16 bufLen,
|
OI_UINT16 bufLen,
|
||||||
const OI_CHAR* format, ...);
|
const OI_CHAR *format, ...);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -250,8 +250,8 @@ OI_INT32 OI_SNPrintf(OI_CHAR *buffer,
|
|||||||
* @return Number of characters written or -1 in the case of an error.
|
* @return Number of characters written or -1 in the case of an error.
|
||||||
*/
|
*/
|
||||||
OI_INT32 OI_VSNPrintf(OI_CHAR *buffer,
|
OI_INT32 OI_VSNPrintf(OI_CHAR *buffer,
|
||||||
OI_UINT16 bufLen,
|
OI_UINT16 bufLen,
|
||||||
const OI_CHAR *format, va_list argp);
|
const OI_CHAR *format, va_list argp);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -277,7 +277,7 @@ OI_INT OI_atoi(const OI_CHAR *str);
|
|||||||
*
|
*
|
||||||
* @return A pointer to the first character following the integer or the pointer passed in.
|
* @return A pointer to the first character following the integer or the pointer passed in.
|
||||||
*/
|
*/
|
||||||
const OI_CHAR* OI_ScanInt(const OI_CHAR *str,
|
const OI_CHAR *OI_ScanInt(const OI_CHAR *str,
|
||||||
OI_INT32 *val);
|
OI_INT32 *val);
|
||||||
|
|
||||||
|
|
||||||
@ -294,7 +294,7 @@ const OI_CHAR* OI_ScanInt(const OI_CHAR *str,
|
|||||||
*
|
*
|
||||||
* @return A pointer to the first character following the unsigned integer or the pointer passed in.
|
* @return A pointer to the first character following the unsigned integer or the pointer passed in.
|
||||||
*/
|
*/
|
||||||
const OI_CHAR* OI_ScanUInt(const OI_CHAR *str,
|
const OI_CHAR *OI_ScanUInt(const OI_CHAR *str,
|
||||||
OI_UINT32 *val);
|
OI_UINT32 *val);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -307,7 +307,7 @@ const OI_CHAR* OI_ScanUInt(const OI_CHAR *str,
|
|||||||
*
|
*
|
||||||
* @return A pointer to the first character following the substring or the pointer passed in.
|
* @return A pointer to the first character following the substring or the pointer passed in.
|
||||||
*/
|
*/
|
||||||
const OI_CHAR* OI_ScanStr(const OI_CHAR *str,
|
const OI_CHAR *OI_ScanStr(const OI_CHAR *str,
|
||||||
OI_CHAR *outStr,
|
OI_CHAR *outStr,
|
||||||
OI_UINT16 len);
|
OI_UINT16 len);
|
||||||
|
|
||||||
@ -327,7 +327,7 @@ const OI_CHAR* OI_ScanStr(const OI_CHAR *str,
|
|||||||
* @return A pointer to the first character following the matched value or the pointer passed in
|
* @return A pointer to the first character following the matched value or the pointer passed in
|
||||||
* if there was no matching text.
|
* if there was no matching text.
|
||||||
*/
|
*/
|
||||||
const OI_CHAR* OI_ScanAlt(const OI_CHAR *str,
|
const OI_CHAR *OI_ScanAlt(const OI_CHAR *str,
|
||||||
const OI_CHAR *alts,
|
const OI_CHAR *alts,
|
||||||
OI_INT *index);
|
OI_INT *index);
|
||||||
|
|
||||||
@ -342,7 +342,7 @@ const OI_CHAR* OI_ScanAlt(const OI_CHAR *str,
|
|||||||
*
|
*
|
||||||
* @return A pointer to the first character following the BD Addr or the pointer passed in.
|
* @return A pointer to the first character following the BD Addr or the pointer passed in.
|
||||||
*/
|
*/
|
||||||
const OI_CHAR* OI_ScanBdAddr(const OI_CHAR *str,
|
const OI_CHAR *OI_ScanBdAddr(const OI_CHAR *str,
|
||||||
OI_BD_ADDR *addr);
|
OI_BD_ADDR *addr);
|
||||||
|
|
||||||
|
|
||||||
|
6
examples/09_a2dp/components/bluedroid_demos/embdrv/sbc/decoder/srce/alloc.c
Executable file → Normal file
6
examples/09_a2dp/components/bluedroid_demos/embdrv/sbc/decoder/srce/alloc.c
Executable file → Normal file
@ -33,7 +33,7 @@ PRIVATE OI_STATUS OI_CODEC_SBC_Alloc(OI_CODEC_SBC_COMMON_CONTEXT *common,
|
|||||||
int i;
|
int i;
|
||||||
size_t filterBufferCount;
|
size_t filterBufferCount;
|
||||||
size_t subdataSize;
|
size_t subdataSize;
|
||||||
OI_BYTE *codecData = (OI_BYTE*)codecDataAligned;
|
OI_BYTE *codecData = (OI_BYTE *)codecDataAligned;
|
||||||
|
|
||||||
if (maxChannels < 1 || maxChannels > 2) {
|
if (maxChannels < 1 || maxChannels > 2) {
|
||||||
return OI_STATUS_INVALID_PARAMETERS;
|
return OI_STATUS_INVALID_PARAMETERS;
|
||||||
@ -60,7 +60,7 @@ PRIVATE OI_STATUS OI_CODEC_SBC_Alloc(OI_CODEC_SBC_COMMON_CONTEXT *common,
|
|||||||
common->filterBufferLen = filterBufferCount * SBC_MAX_BANDS;
|
common->filterBufferLen = filterBufferCount * SBC_MAX_BANDS;
|
||||||
|
|
||||||
/* Allocate memory for the subband data */
|
/* Allocate memory for the subband data */
|
||||||
common->subdata = (OI_INT32*)codecData;
|
common->subdata = (OI_INT32 *)codecData;
|
||||||
codecData += subdataSize;
|
codecData += subdataSize;
|
||||||
OI_ASSERT(codecDataBytes >= subdataSize);
|
OI_ASSERT(codecDataBytes >= subdataSize);
|
||||||
codecDataBytes -= subdataSize;
|
codecDataBytes -= subdataSize;
|
||||||
@ -68,7 +68,7 @@ PRIVATE OI_STATUS OI_CODEC_SBC_Alloc(OI_CODEC_SBC_COMMON_CONTEXT *common,
|
|||||||
/* Allocate memory for the synthesis buffers */
|
/* Allocate memory for the synthesis buffers */
|
||||||
for (i = 0; i < maxChannels; ++i) {
|
for (i = 0; i < maxChannels; ++i) {
|
||||||
size_t allocSize = common->filterBufferLen * sizeof(common->filterBuffer[0][0]);
|
size_t allocSize = common->filterBufferLen * sizeof(common->filterBuffer[0][0]);
|
||||||
common->filterBuffer[i] = (SBC_BUFFER_T*)codecData;
|
common->filterBuffer[i] = (SBC_BUFFER_T *)codecData;
|
||||||
OI_ASSERT(codecDataBytes >= allocSize);
|
OI_ASSERT(codecDataBytes >= allocSize);
|
||||||
codecData += allocSize;
|
codecData += allocSize;
|
||||||
codecDataBytes -= allocSize;
|
codecDataBytes -= allocSize;
|
||||||
|
48
examples/09_a2dp/components/bluedroid_demos/embdrv/sbc/decoder/srce/bitalloc.c
Executable file → Normal file
48
examples/09_a2dp/components/bluedroid_demos/embdrv/sbc/decoder/srce/bitalloc.c
Executable file → Normal file
@ -42,12 +42,12 @@ frame length and bitrate.
|
|||||||
OI_UINT32 OI_SBC_MaxBitpool(OI_CODEC_SBC_FRAME_INFO *frame)
|
OI_UINT32 OI_SBC_MaxBitpool(OI_CODEC_SBC_FRAME_INFO *frame)
|
||||||
{
|
{
|
||||||
switch (frame->mode) {
|
switch (frame->mode) {
|
||||||
case SBC_MONO:
|
case SBC_MONO:
|
||||||
case SBC_DUAL_CHANNEL:
|
case SBC_DUAL_CHANNEL:
|
||||||
return 16 * frame->nrof_subbands;
|
return 16 * frame->nrof_subbands;
|
||||||
case SBC_STEREO:
|
case SBC_STEREO:
|
||||||
case SBC_JOINT_STEREO:
|
case SBC_JOINT_STEREO:
|
||||||
return 32 * frame->nrof_subbands;
|
return 32 * frame->nrof_subbands;
|
||||||
}
|
}
|
||||||
|
|
||||||
ERROR(("Invalid frame mode %d", frame->mode));
|
ERROR(("Invalid frame mode %d", frame->mode));
|
||||||
@ -65,8 +65,14 @@ PRIVATE OI_UINT16 internal_CalculateFramelen(OI_CODEC_SBC_FRAME_INFO *frame)
|
|||||||
if (frame->mode == SBC_JOINT_STEREO) {
|
if (frame->mode == SBC_JOINT_STEREO) {
|
||||||
result += nrof_subbands + (8 * nrof_subbands);
|
result += nrof_subbands + (8 * nrof_subbands);
|
||||||
} else {
|
} else {
|
||||||
if (frame->mode == SBC_DUAL_CHANNEL) { result += nbits; }
|
if (frame->mode == SBC_DUAL_CHANNEL) {
|
||||||
if (frame->mode == SBC_MONO) { result += 4*nrof_subbands; } else { result += 8*nrof_subbands; }
|
result += nbits;
|
||||||
|
}
|
||||||
|
if (frame->mode == SBC_MONO) {
|
||||||
|
result += 4 * nrof_subbands;
|
||||||
|
} else {
|
||||||
|
result += 8 * nrof_subbands;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return SBC_HEADER_LEN + (result + 7) / 8;
|
return SBC_HEADER_LEN + (result + 7) / 8;
|
||||||
}
|
}
|
||||||
@ -83,9 +89,11 @@ PRIVATE OI_UINT32 internal_CalculateBitrate(OI_CODEC_SBC_FRAME_INFO *frame)
|
|||||||
|
|
||||||
INLINE OI_UINT16 OI_SBC_CalculateFrameAndHeaderlen(OI_CODEC_SBC_FRAME_INFO *frame, OI_UINT *headerLen_)
|
INLINE OI_UINT16 OI_SBC_CalculateFrameAndHeaderlen(OI_CODEC_SBC_FRAME_INFO *frame, OI_UINT *headerLen_)
|
||||||
{
|
{
|
||||||
OI_UINT headerLen = SBC_HEADER_LEN + frame->nrof_subbands * frame->nrof_channels/2;
|
OI_UINT headerLen = SBC_HEADER_LEN + frame->nrof_subbands * frame->nrof_channels / 2;
|
||||||
|
|
||||||
if (frame->mode == SBC_JOINT_STEREO) { headerLen++; }
|
if (frame->mode == SBC_JOINT_STEREO) {
|
||||||
|
headerLen++;
|
||||||
|
}
|
||||||
|
|
||||||
*headerLen_ = headerLen;
|
*headerLen_ = headerLen;
|
||||||
return internal_CalculateFramelen(frame);
|
return internal_CalculateFramelen(frame);
|
||||||
@ -116,9 +124,9 @@ INLINE OI_UINT16 OI_SBC_CalculateFrameAndHeaderlen(OI_CODEC_SBC_FRAME_INFO *fram
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
OI_UINT computeBitneed(OI_CODEC_SBC_COMMON_CONTEXT *common,
|
OI_UINT computeBitneed(OI_CODEC_SBC_COMMON_CONTEXT *common,
|
||||||
OI_UINT8 *bitneeds,
|
OI_UINT8 *bitneeds,
|
||||||
OI_UINT ch,
|
OI_UINT ch,
|
||||||
OI_UINT *preferredBitpool)
|
OI_UINT *preferredBitpool)
|
||||||
{
|
{
|
||||||
static const OI_INT8 offset4[4][4] = {
|
static const OI_INT8 offset4[4][4] = {
|
||||||
{ -1, 0, 0, 0 },
|
{ -1, 0, 0, 0 },
|
||||||
@ -244,10 +252,10 @@ OI_UINT computeBitneed(OI_CODEC_SBC_COMMON_CONTEXT *common,
|
|||||||
* @return The adjustment.
|
* @return The adjustment.
|
||||||
*/
|
*/
|
||||||
OI_INT adjustToFitBitpool(const OI_UINT bitpool,
|
OI_INT adjustToFitBitpool(const OI_UINT bitpool,
|
||||||
OI_UINT32 *bitneeds,
|
OI_UINT32 *bitneeds,
|
||||||
const OI_UINT subbands,
|
const OI_UINT subbands,
|
||||||
OI_UINT bitcount,
|
OI_UINT bitcount,
|
||||||
OI_UINT *excess)
|
OI_UINT *excess)
|
||||||
{
|
{
|
||||||
OI_INT maxBitadjust = 0;
|
OI_INT maxBitadjust = 0;
|
||||||
OI_INT bitadjust = (bitcount > bitpool) ? -8 : 8;
|
OI_INT bitadjust = (bitcount > bitpool) ? -8 : 8;
|
||||||
@ -340,9 +348,9 @@ INLINE OI_INT allocExcessBits(OI_UINT8 *dest,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void oneChannelBitAllocation(OI_CODEC_SBC_COMMON_CONTEXT *common,
|
void oneChannelBitAllocation(OI_CODEC_SBC_COMMON_CONTEXT *common,
|
||||||
BITNEED_UNION1 *bitneeds,
|
BITNEED_UNION1 *bitneeds,
|
||||||
OI_UINT ch,
|
OI_UINT ch,
|
||||||
OI_UINT bitcount)
|
OI_UINT bitcount)
|
||||||
{
|
{
|
||||||
const OI_UINT8 nrof_subbands = common->frameInfo.nrof_subbands;
|
const OI_UINT8 nrof_subbands = common->frameInfo.nrof_subbands;
|
||||||
OI_UINT excess;
|
OI_UINT excess;
|
||||||
|
23
examples/09_a2dp/components/bluedroid_demos/embdrv/sbc/decoder/srce/decoder-oina.c
Executable file → Normal file
23
examples/09_a2dp/components/bluedroid_demos/embdrv/sbc/decoder/srce/decoder-oina.c
Executable file → Normal file
@ -37,13 +37,13 @@ This file exposes OINA-specific interfaces to decoder functions.
|
|||||||
#include <oi_codec_sbc_private.h>
|
#include <oi_codec_sbc_private.h>
|
||||||
|
|
||||||
OI_STATUS OI_CODEC_SBC_DecoderConfigureRaw(OI_CODEC_SBC_DECODER_CONTEXT *context,
|
OI_STATUS OI_CODEC_SBC_DecoderConfigureRaw(OI_CODEC_SBC_DECODER_CONTEXT *context,
|
||||||
OI_BOOL enhanced,
|
OI_BOOL enhanced,
|
||||||
OI_UINT8 frequency,
|
OI_UINT8 frequency,
|
||||||
OI_UINT8 mode,
|
OI_UINT8 mode,
|
||||||
OI_UINT8 subbands,
|
OI_UINT8 subbands,
|
||||||
OI_UINT8 blocks,
|
OI_UINT8 blocks,
|
||||||
OI_UINT8 alloc,
|
OI_UINT8 alloc,
|
||||||
OI_UINT8 maxBitpool)
|
OI_UINT8 maxBitpool)
|
||||||
{
|
{
|
||||||
if (frequency > SBC_FREQ_48000) {
|
if (frequency > SBC_FREQ_48000) {
|
||||||
return OI_STATUS_INVALID_PARAMETERS;
|
return OI_STATUS_INVALID_PARAMETERS;
|
||||||
@ -117,18 +117,15 @@ OI_STATUS OI_CODEC_SBC_DecoderLimit(OI_CODEC_SBC_DECODER_CONTEXT *context,
|
|||||||
OI_BOOL enhanced,
|
OI_BOOL enhanced,
|
||||||
OI_UINT8 subbands)
|
OI_UINT8 subbands)
|
||||||
{
|
{
|
||||||
if (enhanced)
|
if (enhanced) {
|
||||||
{
|
|
||||||
#ifdef SBC_ENHANCED
|
#ifdef SBC_ENHANCED
|
||||||
context->enhancedEnabled = TRUE;
|
context->enhancedEnabled = TRUE;
|
||||||
#else
|
#else
|
||||||
context->enhancedEnabled = FALSE;
|
context->enhancedEnabled = FALSE;
|
||||||
#endif
|
#endif
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
context->enhancedEnabled = FALSE;
|
context->enhancedEnabled = FALSE;
|
||||||
}
|
}
|
||||||
context->restrictSubbands = subbands;
|
context->restrictSubbands = subbands;
|
||||||
context->limitFrameFormat = TRUE;
|
context->limitFrameFormat = TRUE;
|
||||||
return OI_OK;
|
return OI_OK;
|
||||||
|
12
examples/09_a2dp/components/bluedroid_demos/embdrv/sbc/decoder/srce/decoder-private.c
Executable file → Normal file
12
examples/09_a2dp/components/bluedroid_demos/embdrv/sbc/decoder/srce/decoder-private.c
Executable file → Normal file
@ -37,7 +37,7 @@ This file drives SBC decoding.
|
|||||||
#include "oi_bitstream.h"
|
#include "oi_bitstream.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
OI_CHAR * const OI_Codec_Copyright = "Copyright 2002-2007 Open Interface North America, Inc. All rights reserved";
|
OI_CHAR *const OI_Codec_Copyright = "Copyright 2002-2007 Open Interface North America, Inc. All rights reserved";
|
||||||
|
|
||||||
INLINE OI_STATUS internal_DecoderReset(OI_CODEC_SBC_DECODER_CONTEXT *context,
|
INLINE OI_STATUS internal_DecoderReset(OI_CODEC_SBC_DECODER_CONTEXT *context,
|
||||||
OI_UINT32 *decoderData,
|
OI_UINT32 *decoderData,
|
||||||
@ -57,7 +57,7 @@ INLINE OI_STATUS internal_DecoderReset(OI_CODEC_SBC_DECODER_CONTEXT *context,
|
|||||||
context->enhancedEnabled = enhanced ? TRUE : FALSE;
|
context->enhancedEnabled = enhanced ? TRUE : FALSE;
|
||||||
#else
|
#else
|
||||||
context->enhancedEnabled = FALSE;
|
context->enhancedEnabled = FALSE;
|
||||||
if (enhanced){
|
if (enhanced) {
|
||||||
return OI_STATUS_INVALID_PARAMETERS;
|
return OI_STATUS_INVALID_PARAMETERS;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -132,8 +132,8 @@ INLINE void OI_SBC_ReadHeader(OI_CODEC_SBC_COMMON_CONTEXT *common, const OI_BYTE
|
|||||||
* Read scalefactor values and prepare the bitstream for OI_SBC_ReadSamples
|
* Read scalefactor values and prepare the bitstream for OI_SBC_ReadSamples
|
||||||
*/
|
*/
|
||||||
PRIVATE void OI_SBC_ReadScalefactors(OI_CODEC_SBC_COMMON_CONTEXT *common,
|
PRIVATE void OI_SBC_ReadScalefactors(OI_CODEC_SBC_COMMON_CONTEXT *common,
|
||||||
const OI_BYTE *b,
|
const OI_BYTE *b,
|
||||||
OI_BITSTREAM *bs)
|
OI_BITSTREAM *bs)
|
||||||
{
|
{
|
||||||
OI_UINT i = common->frameInfo.nrof_subbands * common->frameInfo.nrof_channels;
|
OI_UINT i = common->frameInfo.nrof_subbands * common->frameInfo.nrof_channels;
|
||||||
OI_INT8 *scale_factor = common->scale_factor;
|
OI_INT8 *scale_factor = common->scale_factor;
|
||||||
@ -179,7 +179,7 @@ PRIVATE void OI_SBC_ReadSamples(OI_CODEC_SBC_DECODER_CONTEXT *context, OI_BITSTR
|
|||||||
{
|
{
|
||||||
OI_CODEC_SBC_COMMON_CONTEXT *common = &context->common;
|
OI_CODEC_SBC_COMMON_CONTEXT *common = &context->common;
|
||||||
OI_UINT nrof_blocks = common->frameInfo.nrof_blocks;
|
OI_UINT nrof_blocks = common->frameInfo.nrof_blocks;
|
||||||
OI_INT32 * RESTRICT s = common->subdata;
|
OI_INT32 *RESTRICT s = common->subdata;
|
||||||
OI_UINT8 *ptr = global_bs->ptr.w;
|
OI_UINT8 *ptr = global_bs->ptr.w;
|
||||||
OI_UINT32 value = global_bs->value;
|
OI_UINT32 value = global_bs->value;
|
||||||
OI_UINT bitPtr = global_bs->bitPtr;
|
OI_UINT bitPtr = global_bs->bitPtr;
|
||||||
@ -188,7 +188,7 @@ PRIVATE void OI_SBC_ReadSamples(OI_CODEC_SBC_DECODER_CONTEXT *context, OI_BITSTR
|
|||||||
do {
|
do {
|
||||||
OI_UINT i;
|
OI_UINT i;
|
||||||
for (i = 0; i < iter_count; ++i) {
|
for (i = 0; i < iter_count; ++i) {
|
||||||
OI_UINT32 sf_by4 = ((OI_UINT32*)common->scale_factor)[i];
|
OI_UINT32 sf_by4 = ((OI_UINT32 *)common->scale_factor)[i];
|
||||||
OI_UINT32 bits_by4 = common->bits.uint32[i];
|
OI_UINT32 bits_by4 = common->bits.uint32[i];
|
||||||
OI_UINT n;
|
OI_UINT n;
|
||||||
for (n = 0; n < 4; ++n) {
|
for (n = 0; n < 4; ++n) {
|
||||||
|
36
examples/09_a2dp/components/bluedroid_demos/embdrv/sbc/decoder/srce/decoder-sbc.c
Executable file → Normal file
36
examples/09_a2dp/components/bluedroid_demos/embdrv/sbc/decoder/srce/decoder-sbc.c
Executable file → Normal file
@ -52,7 +52,7 @@ PRIVATE OI_STATUS FindSyncword(OI_CODEC_SBC_DECODER_CONTEXT *context,
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef SBC_ENHANCED
|
#ifdef SBC_ENHANCED
|
||||||
if (context->limitFrameFormat && context->enhancedEnabled){
|
if (context->limitFrameFormat && context->enhancedEnabled) {
|
||||||
/* If the context is restricted, only search for specified SYNCWORD */
|
/* If the context is restricted, only search for specified SYNCWORD */
|
||||||
search1 = search2;
|
search1 = search2;
|
||||||
} else if (context->enhancedEnabled == FALSE) {
|
} else if (context->enhancedEnabled == FALSE) {
|
||||||
@ -164,7 +164,7 @@ static OI_STATUS DecodeBody(OI_CODEC_SBC_DECODER_CONTEXT *context,
|
|||||||
if (context->common.frameInfo.nrof_channels == 1 && context->common.pcmStride == 2) {
|
if (context->common.frameInfo.nrof_channels == 1 && context->common.pcmStride == 2) {
|
||||||
OI_UINT i;
|
OI_UINT i;
|
||||||
for (i = 0; i < frameSamples; ++i) {
|
for (i = 0; i < frameSamples; ++i) {
|
||||||
pcmData[2*i+1] = pcmData[2*i];
|
pcmData[2 * i + 1] = pcmData[2 * i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -371,8 +371,8 @@ OI_UINT8 OI_CODEC_SBC_FrameCount(OI_BYTE *frameData,
|
|||||||
OI_UINT8 frameCount = 0;
|
OI_UINT8 frameCount = 0;
|
||||||
OI_UINT frameLen;
|
OI_UINT frameLen;
|
||||||
|
|
||||||
while (frameBytes){
|
while (frameBytes) {
|
||||||
while (frameBytes && ((frameData[0] & 0xFE) != 0x9C)){
|
while (frameBytes && ((frameData[0] & 0xFE) != 0x9C)) {
|
||||||
frameData++;
|
frameData++;
|
||||||
frameBytes--;
|
frameBytes--;
|
||||||
}
|
}
|
||||||
@ -389,26 +389,26 @@ OI_UINT8 OI_CODEC_SBC_FrameCount(OI_BYTE *frameData,
|
|||||||
|
|
||||||
/* Inline logic to avoid corrupting context */
|
/* Inline logic to avoid corrupting context */
|
||||||
frameLen = blocks * frameData[2];
|
frameLen = blocks * frameData[2];
|
||||||
switch (mode){
|
switch (mode) {
|
||||||
case SBC_JOINT_STEREO:
|
case SBC_JOINT_STEREO:
|
||||||
frameLen += subbands + (8 * subbands);
|
frameLen += subbands + (8 * subbands);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SBC_DUAL_CHANNEL:
|
case SBC_DUAL_CHANNEL:
|
||||||
frameLen *= 2;
|
frameLen *= 2;
|
||||||
/* fall through */
|
/* fall through */
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if (mode == SBC_MONO){
|
if (mode == SBC_MONO) {
|
||||||
frameLen += 4*subbands;
|
frameLen += 4 * subbands;
|
||||||
} else {
|
} else {
|
||||||
frameLen += 8*subbands;
|
frameLen += 8 * subbands;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
frameCount++;
|
frameCount++;
|
||||||
frameLen = SBC_HEADER_LEN + (frameLen + 7) / 8;
|
frameLen = SBC_HEADER_LEN + (frameLen + 7) / 8;
|
||||||
if (frameBytes > frameLen){
|
if (frameBytes > frameLen) {
|
||||||
frameBytes -= frameLen;
|
frameBytes -= frameLen;
|
||||||
frameData += frameLen;
|
frameData += frameLen;
|
||||||
} else {
|
} else {
|
||||||
|
4
examples/09_a2dp/components/bluedroid_demos/embdrv/sbc/decoder/srce/dequant.c
Executable file → Normal file
4
examples/09_a2dp/components/bluedroid_demos/embdrv/sbc/decoder/srce/dequant.c
Executable file → Normal file
@ -124,7 +124,7 @@ const OI_UINT32 dequant_long_unscaled[17];
|
|||||||
|
|
||||||
INLINE float dequant_float(OI_UINT32 raw, OI_UINT scale_factor, OI_UINT bits)
|
INLINE float dequant_float(OI_UINT32 raw, OI_UINT scale_factor, OI_UINT bits)
|
||||||
{
|
{
|
||||||
float result = (1 << (scale_factor+1)) * ((raw * 2.0f + 1.0f) / ((1 << bits) - 1.0f) - 1.0f);
|
float result = (1 << (scale_factor + 1)) * ((raw * 2.0f + 1.0f) / ((1 << bits) - 1.0f) - 1.0f);
|
||||||
|
|
||||||
result /= SBC_DEQUANT_SCALING_FACTOR;
|
result /= SBC_DEQUANT_SCALING_FACTOR;
|
||||||
|
|
||||||
@ -163,7 +163,7 @@ INLINE OI_INT32 OI_SBC_Dequant(OI_UINT32 raw, OI_UINT scale_factor, OI_UINT bits
|
|||||||
float float_result;
|
float float_result;
|
||||||
|
|
||||||
float_result = dequant_float(raw, scale_factor, bits);
|
float_result = dequant_float(raw, scale_factor, bits);
|
||||||
integerized_float_result = (OI_INT32)floor(0.5f+float_result * (1 << 15));
|
integerized_float_result = (OI_INT32)floor(0.5f + float_result * (1 << 15));
|
||||||
|
|
||||||
/* This detects overflow */
|
/* This detects overflow */
|
||||||
OI_ASSERT(((result >= 0) && (integerized_float_result >= 0)) ||
|
OI_ASSERT(((result >= 0) && (integerized_float_result >= 0)) ||
|
||||||
|
10
examples/09_a2dp/components/bluedroid_demos/embdrv/sbc/decoder/srce/framing-sbc.c
Executable file → Normal file
10
examples/09_a2dp/components/bluedroid_demos/embdrv/sbc/decoder/srce/framing-sbc.c
Executable file → Normal file
@ -30,11 +30,11 @@
|
|||||||
|
|
||||||
#include "oi_codec_sbc_private.h"
|
#include "oi_codec_sbc_private.h"
|
||||||
|
|
||||||
const OI_CHAR* const OI_CODEC_SBC_FreqText[] = { "SBC_FREQ_16000", "SBC_FREQ_32000", "SBC_FREQ_44100", "SBC_FREQ_48000" };
|
const OI_CHAR *const OI_CODEC_SBC_FreqText[] = { "SBC_FREQ_16000", "SBC_FREQ_32000", "SBC_FREQ_44100", "SBC_FREQ_48000" };
|
||||||
const OI_CHAR* const OI_CODEC_SBC_ModeText[] = { "SBC_MONO", "SBC_DUAL_CHANNEL", "SBC_STEREO", "SBC_JOINT_STEREO" };
|
const OI_CHAR *const OI_CODEC_SBC_ModeText[] = { "SBC_MONO", "SBC_DUAL_CHANNEL", "SBC_STEREO", "SBC_JOINT_STEREO" };
|
||||||
const OI_CHAR* const OI_CODEC_SBC_SubbandsText[] = { "SBC_SUBBANDS_4", "SBC_SUBBANDS_8" };
|
const OI_CHAR *const OI_CODEC_SBC_SubbandsText[] = { "SBC_SUBBANDS_4", "SBC_SUBBANDS_8" };
|
||||||
const OI_CHAR* const OI_CODEC_SBC_BlocksText[] = { "SBC_BLOCKS_4", "SBC_BLOCKS_8", "SBC_BLOCKS_12", "SBC_BLOCKS_16" };
|
const OI_CHAR *const OI_CODEC_SBC_BlocksText[] = { "SBC_BLOCKS_4", "SBC_BLOCKS_8", "SBC_BLOCKS_12", "SBC_BLOCKS_16" };
|
||||||
const OI_CHAR* const OI_CODEC_SBC_AllocText[] = { "SBC_LOUDNESS", "SBC_SNR" };
|
const OI_CHAR *const OI_CODEC_SBC_AllocText[] = { "SBC_LOUDNESS", "SBC_SNR" };
|
||||||
|
|
||||||
#ifdef OI_DEBUG
|
#ifdef OI_DEBUG
|
||||||
void OI_CODEC_SBC_DumpConfig(OI_CODEC_SBC_FRAME_INFO *frameInfo)
|
void OI_CODEC_SBC_DumpConfig(OI_CODEC_SBC_FRAME_INFO *frameInfo)
|
||||||
|
28
examples/09_a2dp/components/bluedroid_demos/embdrv/sbc/decoder/srce/framing.c
Executable file → Normal file
28
examples/09_a2dp/components/bluedroid_demos/embdrv/sbc/decoder/srce/framing.c
Executable file → Normal file
@ -112,9 +112,9 @@ INLINE OI_CHAR crc_iterate(OI_UINT8 oldcrc, OI_UINT8 next)
|
|||||||
{
|
{
|
||||||
OI_UINT crc;
|
OI_UINT crc;
|
||||||
OI_UINT idx;
|
OI_UINT idx;
|
||||||
idx = oldcrc^next;
|
idx = oldcrc ^ next;
|
||||||
crc = crc8_wide[idx >> 1];
|
crc = crc8_wide[idx >> 1];
|
||||||
if (idx%2) {
|
if (idx % 2) {
|
||||||
crc &= 0xff;
|
crc &= 0xff;
|
||||||
} else {
|
} else {
|
||||||
crc >>= 8;
|
crc >>= 8;
|
||||||
@ -128,8 +128,8 @@ INLINE OI_CHAR crc_iterate_top4(OI_UINT8 oldcrc, OI_UINT8 next)
|
|||||||
OI_UINT crc;
|
OI_UINT crc;
|
||||||
OI_UINT idx;
|
OI_UINT idx;
|
||||||
idx = (oldcrc ^ next) >> 4;
|
idx = (oldcrc ^ next) >> 4;
|
||||||
crc = crc8_wide[idx>>1];
|
crc = crc8_wide[idx >> 1];
|
||||||
if (idx%2) {
|
if (idx % 2) {
|
||||||
crc &= 0xff;
|
crc &= 0xff;
|
||||||
} else {
|
} else {
|
||||||
crc >>= 8;
|
crc >>= 8;
|
||||||
@ -142,14 +142,14 @@ INLINE OI_CHAR crc_iterate_top4(OI_UINT8 oldcrc, OI_UINT8 next)
|
|||||||
|
|
||||||
INLINE OI_UINT8 crc_iterate_top4(OI_UINT8 oldcrc, OI_UINT8 next)
|
INLINE OI_UINT8 crc_iterate_top4(OI_UINT8 oldcrc, OI_UINT8 next)
|
||||||
{
|
{
|
||||||
return (oldcrc << 4) ^ crc8_narrow[(oldcrc^next) >> 4];
|
return (oldcrc << 4) ^ crc8_narrow[(oldcrc ^ next) >> 4];
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef USE_NIBBLEWISE_CRC
|
#ifdef USE_NIBBLEWISE_CRC
|
||||||
INLINE OI_UINT8 crc_iterate(OI_UINT8 crc, OI_UINT8 next)
|
INLINE OI_UINT8 crc_iterate(OI_UINT8 crc, OI_UINT8 next)
|
||||||
{
|
{
|
||||||
crc = (crc << 4) ^ crc8_narrow[(crc^next) >> 4];
|
crc = (crc << 4) ^ crc8_narrow[(crc ^ next) >> 4];
|
||||||
crc = (crc << 4) ^ crc8_narrow[((crc>>4)^next)&0xf];
|
crc = (crc << 4) ^ crc8_narrow[((crc >> 4)^next) & 0xf];
|
||||||
|
|
||||||
return crc;
|
return crc;
|
||||||
}
|
}
|
||||||
@ -157,7 +157,7 @@ INLINE OI_UINT8 crc_iterate(OI_UINT8 crc, OI_UINT8 next)
|
|||||||
#else // USE_NIBBLEWISE_CRC
|
#else // USE_NIBBLEWISE_CRC
|
||||||
INLINE OI_UINT8 crc_iterate(OI_UINT8 crc, OI_UINT8 next)
|
INLINE OI_UINT8 crc_iterate(OI_UINT8 crc, OI_UINT8 next)
|
||||||
{
|
{
|
||||||
return crc8_narrow[crc^next];
|
return crc8_narrow[crc ^ next];
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // USE_NIBBLEWISE_CRC
|
#endif // USE_NIBBLEWISE_CRC
|
||||||
@ -182,7 +182,7 @@ PRIVATE OI_UINT8 OI_SBC_CalculateChecksum(OI_CODEC_SBC_FRAME_INFO *frame, OI_BYT
|
|||||||
|
|
||||||
for (i = 1; i < count; i++) {
|
for (i = 1; i < count; i++) {
|
||||||
if (i != 3) {
|
if (i != 3) {
|
||||||
crc = crc_iterate(crc,data[i]);
|
crc = crc_iterate(crc, data[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -227,17 +227,17 @@ PRIVATE void shift_buffer(SBC_BUFFER_T *dest, SBC_BUFFER_T *src, OI_UINT wordCou
|
|||||||
#ifdef USE_PLATFORM_MEMMOVE
|
#ifdef USE_PLATFORM_MEMMOVE
|
||||||
memmove(dest, src, wordCount * sizeof(SBC_BUFFER_T));
|
memmove(dest, src, wordCount * sizeof(SBC_BUFFER_T));
|
||||||
#elif defined(USE_PLATFORM_MEMCPY)
|
#elif defined(USE_PLATFORM_MEMCPY)
|
||||||
OI_ASSERT(((OI_CHAR *)(dest) - (OI_CHAR *)(src)) >= wordCount*sizeof(*dest));
|
OI_ASSERT(((OI_CHAR *)(dest) - (OI_CHAR *)(src)) >= wordCount * sizeof(*dest));
|
||||||
memcpy(dest, src, wordCount * sizeof(SBC_BUFFER_T));
|
memcpy(dest, src, wordCount * sizeof(SBC_BUFFER_T));
|
||||||
#else
|
#else
|
||||||
OI_UINT n;
|
OI_UINT n;
|
||||||
OI_INT32 *d;
|
OI_INT32 *d;
|
||||||
OI_INT32 *s;
|
OI_INT32 *s;
|
||||||
n = wordCount / 4 / (sizeof(OI_INT32)/sizeof(*dest));
|
n = wordCount / 4 / (sizeof(OI_INT32) / sizeof(*dest));
|
||||||
OI_ASSERT((n * 4 * (sizeof(OI_INT32)/sizeof(*dest))) == wordCount);
|
OI_ASSERT((n * 4 * (sizeof(OI_INT32) / sizeof(*dest))) == wordCount);
|
||||||
|
|
||||||
d = (void*)(dest + wordCount);
|
d = (void *)(dest + wordCount);
|
||||||
s = (void*)(src + wordCount);
|
s = (void *)(src + wordCount);
|
||||||
|
|
||||||
do {
|
do {
|
||||||
COPY4WORDS_BACK(d, s);
|
COPY4WORDS_BACK(d, s);
|
||||||
|
9
examples/09_a2dp/components/bluedroid_demos/embdrv/sbc/decoder/srce/oi_codec_version.c
Executable file → Normal file
9
examples/09_a2dp/components/bluedroid_demos/embdrv/sbc/decoder/srce/oi_codec_version.c
Executable file → Normal file
@ -38,15 +38,16 @@ version number of the eSBC codec
|
|||||||
#include "oi_codec_sbc_private.h"
|
#include "oi_codec_sbc_private.h"
|
||||||
|
|
||||||
/** Version string for the BLUEmagic 3.0 protocol stack and profiles */
|
/** Version string for the BLUEmagic 3.0 protocol stack and profiles */
|
||||||
PRIVATE OI_CHAR * const codecVersion = "v1.5"
|
PRIVATE OI_CHAR *const codecVersion = "v1.5"
|
||||||
#ifdef OI_SBC_EVAL
|
#ifdef OI_SBC_EVAL
|
||||||
" (Evaluation version)"
|
" (Evaluation version)"
|
||||||
#endif
|
#endif
|
||||||
;
|
;
|
||||||
|
|
||||||
/** This function returns the version string for the BLUEmagic 3.0 protocol stack
|
/** This function returns the version string for the BLUEmagic 3.0 protocol stack
|
||||||
and profiles */
|
and profiles */
|
||||||
OI_CHAR *OI_CODEC_Version(void) {
|
OI_CHAR *OI_CODEC_Version(void)
|
||||||
|
{
|
||||||
return codecVersion;
|
return codecVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
166
examples/09_a2dp/components/bluedroid_demos/embdrv/sbc/decoder/srce/synthesis-8-generated.c
Executable file → Normal file
166
examples/09_a2dp/components/bluedroid_demos/embdrv/sbc/decoder/srce/synthesis-8-generated.c
Executable file → Normal file
@ -39,97 +39,97 @@
|
|||||||
|
|
||||||
#define MUL_16S_16S(_x, _y) ((_x) * (_y))
|
#define MUL_16S_16S(_x, _y) ((_x) * (_y))
|
||||||
|
|
||||||
PRIVATE void SynthWindow80_generated(OI_INT16 *pcm, SBC_BUFFER_T const * RESTRICT buffer, OI_UINT strideShift)
|
PRIVATE void SynthWindow80_generated(OI_INT16 *pcm, SBC_BUFFER_T const *RESTRICT buffer, OI_UINT strideShift)
|
||||||
{
|
{
|
||||||
OI_INT32 pcm_a, pcm_b;
|
OI_INT32 pcm_a, pcm_b;
|
||||||
/* 1 - stage 0 */ pcm_b = 0;
|
/* 1 - stage 0 */ pcm_b = 0;
|
||||||
/* 1 - stage 0 */ pcm_b +=(MUL_16S_16S(8235, buffer[ 12]))>> 3;
|
/* 1 - stage 0 */ pcm_b += (MUL_16S_16S(8235, buffer[ 12])) >> 3;
|
||||||
/* 1 - stage 0 */ pcm_b +=(MUL_16S_16S(-23167, buffer[ 20]))>> 3;
|
/* 1 - stage 0 */ pcm_b += (MUL_16S_16S(-23167, buffer[ 20])) >> 3;
|
||||||
/* 1 - stage 0 */ pcm_b +=(MUL_16S_16S(26479, buffer[ 28]))>> 2;
|
/* 1 - stage 0 */ pcm_b += (MUL_16S_16S(26479, buffer[ 28])) >> 2;
|
||||||
/* 1 - stage 0 */ pcm_b +=(MUL_16S_16S(-17397, buffer[ 36]))<< 1;
|
/* 1 - stage 0 */ pcm_b += (MUL_16S_16S(-17397, buffer[ 36])) << 1;
|
||||||
/* 1 - stage 0 */ pcm_b +=(MUL_16S_16S(9399, buffer[ 44]))<< 3;
|
/* 1 - stage 0 */ pcm_b += (MUL_16S_16S(9399, buffer[ 44])) << 3;
|
||||||
/* 1 - stage 0 */ pcm_b +=(MUL_16S_16S(17397, buffer[ 52]))<< 1;
|
/* 1 - stage 0 */ pcm_b += (MUL_16S_16S(17397, buffer[ 52])) << 1;
|
||||||
/* 1 - stage 0 */ pcm_b +=(MUL_16S_16S(26479, buffer[ 60]))>> 2;
|
/* 1 - stage 0 */ pcm_b += (MUL_16S_16S(26479, buffer[ 60])) >> 2;
|
||||||
/* 1 - stage 0 */ pcm_b +=(MUL_16S_16S(23167, buffer[ 68]))>> 3;
|
/* 1 - stage 0 */ pcm_b += (MUL_16S_16S(23167, buffer[ 68])) >> 3;
|
||||||
/* 1 - stage 0 */ pcm_b +=(MUL_16S_16S(8235, buffer[ 76]))>> 3;
|
/* 1 - stage 0 */ pcm_b += (MUL_16S_16S(8235, buffer[ 76])) >> 3;
|
||||||
/* 1 - stage 0 */ pcm_b /= 32768; CLIP_INT16(pcm_b); pcm[0<<strideShift] = (OI_INT16)pcm_b;
|
/* 1 - stage 0 */ pcm_b /= 32768; CLIP_INT16(pcm_b); pcm[0 << strideShift] = (OI_INT16)pcm_b;
|
||||||
/* 1 - stage 1 */ pcm_a = 0;
|
/* 1 - stage 1 */ pcm_a = 0;
|
||||||
/* 1 - stage 1 */ pcm_b = 0;
|
/* 1 - stage 1 */ pcm_b = 0;
|
||||||
/* 1 - stage 1 */ pcm_a +=(MUL_16S_16S(-3263, buffer[ 5]))>> 5;
|
/* 1 - stage 1 */ pcm_a += (MUL_16S_16S(-3263, buffer[ 5])) >> 5;
|
||||||
/* 1 - stage 1 */ pcm_b +=(MUL_16S_16S(9293, buffer[ 5]))>> 3;
|
/* 1 - stage 1 */ pcm_b += (MUL_16S_16S(9293, buffer[ 5])) >> 3;
|
||||||
/* 1 - stage 1 */ pcm_a +=(MUL_16S_16S(29293, buffer[ 11]))>> 5;
|
/* 1 - stage 1 */ pcm_a += (MUL_16S_16S(29293, buffer[ 11])) >> 5;
|
||||||
/* 1 - stage 1 */ pcm_b +=(MUL_16S_16S(-6087, buffer[ 11]))>> 2;
|
/* 1 - stage 1 */ pcm_b += (MUL_16S_16S(-6087, buffer[ 11])) >> 2;
|
||||||
/* 1 - stage 1 */ pcm_a +=(MUL_16S_16S(-5229, buffer[ 21]));
|
/* 1 - stage 1 */ pcm_a += (MUL_16S_16S(-5229, buffer[ 21]));
|
||||||
/* 1 - stage 1 */ pcm_b +=(MUL_16S_16S(1247, buffer[ 21]))<< 3;
|
/* 1 - stage 1 */ pcm_b += (MUL_16S_16S(1247, buffer[ 21])) << 3;
|
||||||
/* 1 - stage 1 */ pcm_a +=(MUL_16S_16S(30835, buffer[ 27]))>> 3;
|
/* 1 - stage 1 */ pcm_a += (MUL_16S_16S(30835, buffer[ 27])) >> 3;
|
||||||
/* 1 - stage 1 */ pcm_b +=(MUL_16S_16S(-2893, buffer[ 27]))<< 3;
|
/* 1 - stage 1 */ pcm_b += (MUL_16S_16S(-2893, buffer[ 27])) << 3;
|
||||||
/* 1 - stage 1 */ pcm_a +=(MUL_16S_16S(-27021, buffer[ 37]))<< 1;
|
/* 1 - stage 1 */ pcm_a += (MUL_16S_16S(-27021, buffer[ 37])) << 1;
|
||||||
/* 1 - stage 1 */ pcm_b +=(MUL_16S_16S(23671, buffer[ 37]))<< 2;
|
/* 1 - stage 1 */ pcm_b += (MUL_16S_16S(23671, buffer[ 37])) << 2;
|
||||||
/* 1 - stage 1 */ pcm_a +=(MUL_16S_16S(31633, buffer[ 43]))<< 1;
|
/* 1 - stage 1 */ pcm_a += (MUL_16S_16S(31633, buffer[ 43])) << 1;
|
||||||
/* 1 - stage 1 */ pcm_b +=(MUL_16S_16S(18055, buffer[ 43]))<< 1;
|
/* 1 - stage 1 */ pcm_b += (MUL_16S_16S(18055, buffer[ 43])) << 1;
|
||||||
/* 1 - stage 1 */ pcm_a +=(MUL_16S_16S(17319, buffer[ 53]))<< 1;
|
/* 1 - stage 1 */ pcm_a += (MUL_16S_16S(17319, buffer[ 53])) << 1;
|
||||||
/* 1 - stage 1 */ pcm_b +=(MUL_16S_16S(11537, buffer[ 53]))>> 1;
|
/* 1 - stage 1 */ pcm_b += (MUL_16S_16S(11537, buffer[ 53])) >> 1;
|
||||||
/* 1 - stage 1 */ pcm_a +=(MUL_16S_16S(26663, buffer[ 59]))>> 2;
|
/* 1 - stage 1 */ pcm_a += (MUL_16S_16S(26663, buffer[ 59])) >> 2;
|
||||||
/* 1 - stage 1 */ pcm_b +=(MUL_16S_16S(1747, buffer[ 59]))<< 1;
|
/* 1 - stage 1 */ pcm_b += (MUL_16S_16S(1747, buffer[ 59])) << 1;
|
||||||
/* 1 - stage 1 */ pcm_a +=(MUL_16S_16S(4555, buffer[ 69]))>> 1;
|
/* 1 - stage 1 */ pcm_a += (MUL_16S_16S(4555, buffer[ 69])) >> 1;
|
||||||
/* 1 - stage 1 */ pcm_b +=(MUL_16S_16S(685, buffer[ 69]))<< 1;
|
/* 1 - stage 1 */ pcm_b += (MUL_16S_16S(685, buffer[ 69])) << 1;
|
||||||
/* 1 - stage 1 */ pcm_a +=(MUL_16S_16S(12419, buffer[ 75]))>> 4;
|
/* 1 - stage 1 */ pcm_a += (MUL_16S_16S(12419, buffer[ 75])) >> 4;
|
||||||
/* 1 - stage 1 */ pcm_b +=(MUL_16S_16S(8721, buffer[ 75]))>> 7;
|
/* 1 - stage 1 */ pcm_b += (MUL_16S_16S(8721, buffer[ 75])) >> 7;
|
||||||
/* 1 - stage 1 */ pcm_a /= 32768; CLIP_INT16(pcm_a); pcm[1<<strideShift] = (OI_INT16)pcm_a;
|
/* 1 - stage 1 */ pcm_a /= 32768; CLIP_INT16(pcm_a); pcm[1 << strideShift] = (OI_INT16)pcm_a;
|
||||||
/* 1 - stage 1 */ pcm_b /= 32768; CLIP_INT16(pcm_b); pcm[7<<strideShift] = (OI_INT16)pcm_b;
|
/* 1 - stage 1 */ pcm_b /= 32768; CLIP_INT16(pcm_b); pcm[7 << strideShift] = (OI_INT16)pcm_b;
|
||||||
/* 1 - stage 2 */ pcm_a = 0;
|
/* 1 - stage 2 */ pcm_a = 0;
|
||||||
/* 1 - stage 2 */ pcm_b = 0;
|
/* 1 - stage 2 */ pcm_b = 0;
|
||||||
/* 1 - stage 2 */ pcm_a +=(MUL_16S_16S(-10385, buffer[ 6]))>> 6;
|
/* 1 - stage 2 */ pcm_a += (MUL_16S_16S(-10385, buffer[ 6])) >> 6;
|
||||||
/* 1 - stage 2 */ pcm_b +=(MUL_16S_16S(11167, buffer[ 6]))>> 4;
|
/* 1 - stage 2 */ pcm_b += (MUL_16S_16S(11167, buffer[ 6])) >> 4;
|
||||||
/* 1 - stage 2 */ pcm_a +=(MUL_16S_16S(24995, buffer[ 10]))>> 5;
|
/* 1 - stage 2 */ pcm_a += (MUL_16S_16S(24995, buffer[ 10])) >> 5;
|
||||||
/* 1 - stage 2 */ pcm_b +=(MUL_16S_16S(-10337, buffer[ 10]))>> 4;
|
/* 1 - stage 2 */ pcm_b += (MUL_16S_16S(-10337, buffer[ 10])) >> 4;
|
||||||
/* 1 - stage 2 */ pcm_a +=(MUL_16S_16S(-309, buffer[ 22]))<< 4;
|
/* 1 - stage 2 */ pcm_a += (MUL_16S_16S(-309, buffer[ 22])) << 4;
|
||||||
/* 1 - stage 2 */ pcm_b +=(MUL_16S_16S(1917, buffer[ 22]))<< 2;
|
/* 1 - stage 2 */ pcm_b += (MUL_16S_16S(1917, buffer[ 22])) << 2;
|
||||||
/* 1 - stage 2 */ pcm_a +=(MUL_16S_16S(9161, buffer[ 26]))>> 3;
|
/* 1 - stage 2 */ pcm_a += (MUL_16S_16S(9161, buffer[ 26])) >> 3;
|
||||||
/* 1 - stage 2 */ pcm_b +=(MUL_16S_16S(-30605, buffer[ 26]))>> 1;
|
/* 1 - stage 2 */ pcm_b += (MUL_16S_16S(-30605, buffer[ 26])) >> 1;
|
||||||
/* 1 - stage 2 */ pcm_a +=(MUL_16S_16S(-23063, buffer[ 38]))<< 1;
|
/* 1 - stage 2 */ pcm_a += (MUL_16S_16S(-23063, buffer[ 38])) << 1;
|
||||||
/* 1 - stage 2 */ pcm_b +=(MUL_16S_16S(8317, buffer[ 38]))<< 3;
|
/* 1 - stage 2 */ pcm_b += (MUL_16S_16S(8317, buffer[ 38])) << 3;
|
||||||
/* 1 - stage 2 */ pcm_a +=(MUL_16S_16S(27561, buffer[ 42]))<< 1;
|
/* 1 - stage 2 */ pcm_a += (MUL_16S_16S(27561, buffer[ 42])) << 1;
|
||||||
/* 1 - stage 2 */ pcm_b +=(MUL_16S_16S(9553, buffer[ 42]))<< 2;
|
/* 1 - stage 2 */ pcm_b += (MUL_16S_16S(9553, buffer[ 42])) << 2;
|
||||||
/* 1 - stage 2 */ pcm_a +=(MUL_16S_16S(2309, buffer[ 54]))<< 3;
|
/* 1 - stage 2 */ pcm_a += (MUL_16S_16S(2309, buffer[ 54])) << 3;
|
||||||
/* 1 - stage 2 */ pcm_b +=(MUL_16S_16S(22117, buffer[ 54]))>> 4;
|
/* 1 - stage 2 */ pcm_b += (MUL_16S_16S(22117, buffer[ 54])) >> 4;
|
||||||
/* 1 - stage 2 */ pcm_a +=(MUL_16S_16S(12705, buffer[ 58]))>> 1;
|
/* 1 - stage 2 */ pcm_a += (MUL_16S_16S(12705, buffer[ 58])) >> 1;
|
||||||
/* 1 - stage 2 */ pcm_b +=(MUL_16S_16S(16383, buffer[ 58]))>> 2;
|
/* 1 - stage 2 */ pcm_b += (MUL_16S_16S(16383, buffer[ 58])) >> 2;
|
||||||
/* 1 - stage 2 */ pcm_a +=(MUL_16S_16S(6239, buffer[ 70]))>> 3;
|
/* 1 - stage 2 */ pcm_a += (MUL_16S_16S(6239, buffer[ 70])) >> 3;
|
||||||
/* 1 - stage 2 */ pcm_b +=(MUL_16S_16S(7543, buffer[ 70]))>> 3;
|
/* 1 - stage 2 */ pcm_b += (MUL_16S_16S(7543, buffer[ 70])) >> 3;
|
||||||
/* 1 - stage 2 */ pcm_a +=(MUL_16S_16S(9251, buffer[ 74]))>> 4;
|
/* 1 - stage 2 */ pcm_a += (MUL_16S_16S(9251, buffer[ 74])) >> 4;
|
||||||
/* 1 - stage 2 */ pcm_b +=(MUL_16S_16S(8603, buffer[ 74]))>> 6;
|
/* 1 - stage 2 */ pcm_b += (MUL_16S_16S(8603, buffer[ 74])) >> 6;
|
||||||
/* 1 - stage 2 */ pcm_a /= 32768; CLIP_INT16(pcm_a); pcm[2<<strideShift] = (OI_INT16)pcm_a;
|
/* 1 - stage 2 */ pcm_a /= 32768; CLIP_INT16(pcm_a); pcm[2 << strideShift] = (OI_INT16)pcm_a;
|
||||||
/* 1 - stage 2 */ pcm_b /= 32768; CLIP_INT16(pcm_b); pcm[6<<strideShift] = (OI_INT16)pcm_b;
|
/* 1 - stage 2 */ pcm_b /= 32768; CLIP_INT16(pcm_b); pcm[6 << strideShift] = (OI_INT16)pcm_b;
|
||||||
/* 1 - stage 3 */ pcm_a = 0;
|
/* 1 - stage 3 */ pcm_a = 0;
|
||||||
/* 1 - stage 3 */ pcm_b = 0;
|
/* 1 - stage 3 */ pcm_b = 0;
|
||||||
/* 1 - stage 3 */ pcm_a +=(MUL_16S_16S(-16457, buffer[ 7]))>> 6;
|
/* 1 - stage 3 */ pcm_a += (MUL_16S_16S(-16457, buffer[ 7])) >> 6;
|
||||||
/* 1 - stage 3 */ pcm_b +=(MUL_16S_16S(16913, buffer[ 7]))>> 5;
|
/* 1 - stage 3 */ pcm_b += (MUL_16S_16S(16913, buffer[ 7])) >> 5;
|
||||||
/* 1 - stage 3 */ pcm_a +=(MUL_16S_16S(19083, buffer[ 9]))>> 5;
|
/* 1 - stage 3 */ pcm_a += (MUL_16S_16S(19083, buffer[ 9])) >> 5;
|
||||||
/* 1 - stage 3 */ pcm_b +=(MUL_16S_16S(-8443, buffer[ 9]))>> 7;
|
/* 1 - stage 3 */ pcm_b += (MUL_16S_16S(-8443, buffer[ 9])) >> 7;
|
||||||
/* 1 - stage 3 */ pcm_a +=(MUL_16S_16S(-23641, buffer[ 23]))>> 2;
|
/* 1 - stage 3 */ pcm_a += (MUL_16S_16S(-23641, buffer[ 23])) >> 2;
|
||||||
/* 1 - stage 3 */ pcm_b +=(MUL_16S_16S(3687, buffer[ 23]))<< 1;
|
/* 1 - stage 3 */ pcm_b += (MUL_16S_16S(3687, buffer[ 23])) << 1;
|
||||||
/* 1 - stage 3 */ pcm_a +=(MUL_16S_16S(-29015, buffer[ 25]))>> 4;
|
/* 1 - stage 3 */ pcm_a += (MUL_16S_16S(-29015, buffer[ 25])) >> 4;
|
||||||
/* 1 - stage 3 */ pcm_b +=(MUL_16S_16S(-301, buffer[ 25]))<< 5;
|
/* 1 - stage 3 */ pcm_b += (MUL_16S_16S(-301, buffer[ 25])) << 5;
|
||||||
/* 1 - stage 3 */ pcm_a +=(MUL_16S_16S(-12889, buffer[ 39]))<< 2;
|
/* 1 - stage 3 */ pcm_a += (MUL_16S_16S(-12889, buffer[ 39])) << 2;
|
||||||
/* 1 - stage 3 */ pcm_b +=(MUL_16S_16S(15447, buffer[ 39]))<< 2;
|
/* 1 - stage 3 */ pcm_b += (MUL_16S_16S(15447, buffer[ 39])) << 2;
|
||||||
/* 1 - stage 3 */ pcm_a +=(MUL_16S_16S(6145, buffer[ 41]))<< 3;
|
/* 1 - stage 3 */ pcm_a += (MUL_16S_16S(6145, buffer[ 41])) << 3;
|
||||||
/* 1 - stage 3 */ pcm_b +=(MUL_16S_16S(10255, buffer[ 41]))<< 2;
|
/* 1 - stage 3 */ pcm_b += (MUL_16S_16S(10255, buffer[ 41])) << 2;
|
||||||
/* 1 - stage 3 */ pcm_a +=(MUL_16S_16S(24211, buffer[ 55]))>> 1;
|
/* 1 - stage 3 */ pcm_a += (MUL_16S_16S(24211, buffer[ 55])) >> 1;
|
||||||
/* 1 - stage 3 */ pcm_b +=(MUL_16S_16S(-18233, buffer[ 55]))>> 3;
|
/* 1 - stage 3 */ pcm_b += (MUL_16S_16S(-18233, buffer[ 55])) >> 3;
|
||||||
/* 1 - stage 3 */ pcm_a +=(MUL_16S_16S(23469, buffer[ 57]))>> 2;
|
/* 1 - stage 3 */ pcm_a += (MUL_16S_16S(23469, buffer[ 57])) >> 2;
|
||||||
/* 1 - stage 3 */ pcm_b +=(MUL_16S_16S(9405, buffer[ 57]))>> 1;
|
/* 1 - stage 3 */ pcm_b += (MUL_16S_16S(9405, buffer[ 57])) >> 1;
|
||||||
/* 1 - stage 3 */ pcm_a +=(MUL_16S_16S(21223, buffer[ 71]))>> 8;
|
/* 1 - stage 3 */ pcm_a += (MUL_16S_16S(21223, buffer[ 71])) >> 8;
|
||||||
/* 1 - stage 3 */ pcm_b +=(MUL_16S_16S(1499, buffer[ 71]))>> 1;
|
/* 1 - stage 3 */ pcm_b += (MUL_16S_16S(1499, buffer[ 71])) >> 1;
|
||||||
/* 1 - stage 3 */ pcm_a +=(MUL_16S_16S(26913, buffer[ 73]))>> 6;
|
/* 1 - stage 3 */ pcm_a += (MUL_16S_16S(26913, buffer[ 73])) >> 6;
|
||||||
/* 1 - stage 3 */ pcm_b +=(MUL_16S_16S(26189, buffer[ 73]))>> 7;
|
/* 1 - stage 3 */ pcm_b += (MUL_16S_16S(26189, buffer[ 73])) >> 7;
|
||||||
/* 1 - stage 3 */ pcm_a /= 32768; CLIP_INT16(pcm_a); pcm[3<<strideShift] = (OI_INT16)pcm_a;
|
/* 1 - stage 3 */ pcm_a /= 32768; CLIP_INT16(pcm_a); pcm[3 << strideShift] = (OI_INT16)pcm_a;
|
||||||
/* 1 - stage 3 */ pcm_b /= 32768; CLIP_INT16(pcm_b); pcm[5<<strideShift] = (OI_INT16)pcm_b;
|
/* 1 - stage 3 */ pcm_b /= 32768; CLIP_INT16(pcm_b); pcm[5 << strideShift] = (OI_INT16)pcm_b;
|
||||||
/* 1 - stage 4 */ pcm_a = 0;
|
/* 1 - stage 4 */ pcm_a = 0;
|
||||||
/* 1 - stage 4 */ pcm_a +=(MUL_16S_16S(10445, buffer[ 8]))>> 4;
|
/* 1 - stage 4 */ pcm_a += (MUL_16S_16S(10445, buffer[ 8])) >> 4;
|
||||||
/* 1 - stage 4 */ pcm_a +=(MUL_16S_16S(-5297, buffer[ 24]))<< 1;
|
/* 1 - stage 4 */ pcm_a += (MUL_16S_16S(-5297, buffer[ 24])) << 1;
|
||||||
/* 1 - stage 4 */ pcm_a +=(MUL_16S_16S(22299, buffer[ 40]))<< 2;
|
/* 1 - stage 4 */ pcm_a += (MUL_16S_16S(22299, buffer[ 40])) << 2;
|
||||||
/* 1 - stage 4 */ pcm_a +=(MUL_16S_16S(10603, buffer[ 56]));
|
/* 1 - stage 4 */ pcm_a += (MUL_16S_16S(10603, buffer[ 56]));
|
||||||
/* 1 - stage 4 */ pcm_a +=(MUL_16S_16S(9539, buffer[ 72]))>> 4;
|
/* 1 - stage 4 */ pcm_a += (MUL_16S_16S(9539, buffer[ 72])) >> 4;
|
||||||
/* 1 - stage 4 */ pcm_a /= 32768; CLIP_INT16(pcm_a); pcm[4<<strideShift] = (OI_INT16)pcm_a;
|
/* 1 - stage 4 */ pcm_a /= 32768; CLIP_INT16(pcm_a); pcm[4 << strideShift] = (OI_INT16)pcm_a;
|
||||||
}
|
}
|
||||||
|
56
examples/09_a2dp/components/bluedroid_demos/embdrv/sbc/decoder/srce/synthesis-dct8.c
Executable file → Normal file
56
examples/09_a2dp/components/bluedroid_demos/embdrv/sbc/decoder/srce/synthesis-dct8.c
Executable file → Normal file
@ -67,30 +67,30 @@ INLINE OI_INT32 default_mul_32s_32s_hi(OI_INT32 u, OI_INT32 v)
|
|||||||
|
|
||||||
u0 = u & 0xFFFF; u1 = u >> 16;
|
u0 = u & 0xFFFF; u1 = u >> 16;
|
||||||
v0 = v & 0xFFFF; v1 = v >> 16;
|
v0 = v & 0xFFFF; v1 = v >> 16;
|
||||||
t = u0*v0;
|
t = u0 * v0;
|
||||||
t = u1*v0 + ((OI_UINT32)t >> 16);
|
t = u1 * v0 + ((OI_UINT32)t >> 16);
|
||||||
w1 = t & 0xFFFF;
|
w1 = t & 0xFFFF;
|
||||||
w2 = t >> 16;
|
w2 = t >> 16;
|
||||||
w1 = u0*v1 + w1;
|
w1 = u0 * v1 + w1;
|
||||||
return u1*v1 + w2 + (w1 >> 16);
|
return u1 * v1 + w2 + (w1 >> 16);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define MUL_32S_32S_HI(_x, _y) default_mul_32s_32s_hi(_x, _y)
|
#define MUL_32S_32S_HI(_x, _y) default_mul_32s_32s_hi(_x, _y)
|
||||||
|
|
||||||
|
|
||||||
#ifdef DEBUG_DCT
|
#ifdef DEBUG_DCT
|
||||||
PRIVATE void float_dct2_8(float * RESTRICT out, OI_INT32 const *RESTRICT in)
|
PRIVATE void float_dct2_8(float *RESTRICT out, OI_INT32 const *RESTRICT in)
|
||||||
{
|
{
|
||||||
#define FIX(x,bits) (((int)floor(0.5f+((x)*((float)(1<<bits)))))/((float)(1<<bits)))
|
#define FIX(x,bits) (((int)floor(0.5f+((x)*((float)(1<<bits)))))/((float)(1<<bits)))
|
||||||
#define FLOAT_BUTTERFLY(x,y) x += y; y = x - (y*2); OI_ASSERT(VALID_INT32(x)); OI_ASSERT(VALID_INT32(y));
|
#define FLOAT_BUTTERFLY(x,y) x += y; y = x - (y*2); OI_ASSERT(VALID_INT32(x)); OI_ASSERT(VALID_INT32(y));
|
||||||
#define FLOAT_MULT_DCT(K, sample) (FIX(K,20) * sample)
|
#define FLOAT_MULT_DCT(K, sample) (FIX(K,20) * sample)
|
||||||
#define FLOAT_SCALE(x, y) (((x) / (double)(1 << (y))))
|
#define FLOAT_SCALE(x, y) (((x) / (double)(1 << (y))))
|
||||||
|
|
||||||
double L00,L01,L02,L03,L04,L05,L06,L07;
|
double L00, L01, L02, L03, L04, L05, L06, L07;
|
||||||
double L25;
|
double L25;
|
||||||
|
|
||||||
double in0,in1,in2,in3;
|
double in0, in1, in2, in3;
|
||||||
double in4,in5,in6,in7;
|
double in4, in5, in6, in7;
|
||||||
|
|
||||||
in0 = FLOAT_SCALE(in[0], DCTII_8_SHIFT_IN); OI_ASSERT(VALID_INT32(in0));
|
in0 = FLOAT_SCALE(in[0], DCTII_8_SHIFT_IN); OI_ASSERT(VALID_INT32(in0));
|
||||||
in1 = FLOAT_SCALE(in[1], DCTII_8_SHIFT_IN); OI_ASSERT(VALID_INT32(in1));
|
in1 = FLOAT_SCALE(in[1], DCTII_8_SHIFT_IN); OI_ASSERT(VALID_INT32(in1));
|
||||||
@ -131,10 +131,10 @@ PRIVATE void float_dct2_8(float * RESTRICT out, OI_INT32 const *RESTRICT in)
|
|||||||
L05 += L06; OI_ASSERT(VALID_INT32(L05));
|
L05 += L06; OI_ASSERT(VALID_INT32(L05));
|
||||||
L06 += L07; OI_ASSERT(VALID_INT32(L06));
|
L06 += L07; OI_ASSERT(VALID_INT32(L06));
|
||||||
|
|
||||||
L04/=2;
|
L04 /= 2;
|
||||||
L05/=2;
|
L05 /= 2;
|
||||||
L06/=2;
|
L06 /= 2;
|
||||||
L07/=2;
|
L07 /= 2;
|
||||||
|
|
||||||
L05 = FLOAT_MULT_DCT(AAN_C4_FLOAT, L05); OI_ASSERT(VALID_INT32(L05));
|
L05 = FLOAT_MULT_DCT(AAN_C4_FLOAT, L05); OI_ASSERT(VALID_INT32(L05));
|
||||||
|
|
||||||
@ -150,12 +150,12 @@ PRIVATE void float_dct2_8(float * RESTRICT out, OI_INT32 const *RESTRICT in)
|
|||||||
FLOAT_BUTTERFLY(L07, L05);
|
FLOAT_BUTTERFLY(L07, L05);
|
||||||
|
|
||||||
FLOAT_BUTTERFLY(L05, L04);
|
FLOAT_BUTTERFLY(L05, L04);
|
||||||
out[3] = (float)(FLOAT_SCALE(L04, DCTII_8_SHIFT_3-1)); OI_ASSERT(VALID_INT16(out[3]));
|
out[3] = (float)(FLOAT_SCALE(L04, DCTII_8_SHIFT_3 - 1)); OI_ASSERT(VALID_INT16(out[3]));
|
||||||
out[5] = (float)(FLOAT_SCALE(L05, DCTII_8_SHIFT_5-1)); OI_ASSERT(VALID_INT16(out[5]));
|
out[5] = (float)(FLOAT_SCALE(L05, DCTII_8_SHIFT_5 - 1)); OI_ASSERT(VALID_INT16(out[5]));
|
||||||
|
|
||||||
FLOAT_BUTTERFLY(L07, L06);
|
FLOAT_BUTTERFLY(L07, L06);
|
||||||
out[7] = (float)(FLOAT_SCALE(L06, DCTII_8_SHIFT_7-1)); OI_ASSERT(VALID_INT16(out[7]));
|
out[7] = (float)(FLOAT_SCALE(L06, DCTII_8_SHIFT_7 - 1)); OI_ASSERT(VALID_INT16(out[7]));
|
||||||
out[1] = (float)(FLOAT_SCALE(L07, DCTII_8_SHIFT_1-1)); OI_ASSERT(VALID_INT16(out[1]));
|
out[1] = (float)(FLOAT_SCALE(L07, DCTII_8_SHIFT_1 - 1)); OI_ASSERT(VALID_INT16(out[1]));
|
||||||
}
|
}
|
||||||
#undef BUTTERFLY
|
#undef BUTTERFLY
|
||||||
#endif
|
#endif
|
||||||
@ -206,16 +206,16 @@ PRIVATE void float_dct2_8(float * RESTRICT out, OI_INT32 const *RESTRICT in)
|
|||||||
* [ 0 0 0 0 0 0 1 2 ]
|
* [ 0 0 0 0 0 0 1 2 ]
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
PRIVATE void dct2_8(SBC_BUFFER_T * RESTRICT out, OI_INT32 const *RESTRICT in)
|
PRIVATE void dct2_8(SBC_BUFFER_T *RESTRICT out, OI_INT32 const *RESTRICT in)
|
||||||
{
|
{
|
||||||
#define BUTTERFLY(x,y) x += y; y = x - (y<<1);
|
#define BUTTERFLY(x,y) x += y; y = x - (y<<1);
|
||||||
#define FIX_MULT_DCT(K, x) (MUL_32S_32S_HI(K,x)<<2)
|
#define FIX_MULT_DCT(K, x) (MUL_32S_32S_HI(K,x)<<2)
|
||||||
|
|
||||||
OI_INT32 L00,L01,L02,L03,L04,L05,L06,L07;
|
OI_INT32 L00, L01, L02, L03, L04, L05, L06, L07;
|
||||||
OI_INT32 L25;
|
OI_INT32 L25;
|
||||||
|
|
||||||
OI_INT32 in0,in1,in2,in3;
|
OI_INT32 in0, in1, in2, in3;
|
||||||
OI_INT32 in4,in5,in6,in7;
|
OI_INT32 in4, in5, in6, in7;
|
||||||
|
|
||||||
#if DCTII_8_SHIFT_IN != 0
|
#if DCTII_8_SHIFT_IN != 0
|
||||||
in0 = SCALE(in[0], DCTII_8_SHIFT_IN);
|
in0 = SCALE(in[0], DCTII_8_SHIFT_IN);
|
||||||
@ -267,10 +267,10 @@ PRIVATE void dct2_8(SBC_BUFFER_T * RESTRICT out, OI_INT32 const *RESTRICT in)
|
|||||||
L05 += L06;
|
L05 += L06;
|
||||||
L06 += L07;
|
L06 += L07;
|
||||||
|
|
||||||
L04/=2;
|
L04 /= 2;
|
||||||
L05/=2;
|
L05 /= 2;
|
||||||
L06/=2;
|
L06 /= 2;
|
||||||
L07/=2;
|
L07 /= 2;
|
||||||
|
|
||||||
L05 = FIX_MULT_DCT(AAN_C4_FIX, L05);
|
L05 = FIX_MULT_DCT(AAN_C4_FIX, L05);
|
||||||
|
|
||||||
@ -286,12 +286,12 @@ PRIVATE void dct2_8(SBC_BUFFER_T * RESTRICT out, OI_INT32 const *RESTRICT in)
|
|||||||
BUTTERFLY(L07, L05);
|
BUTTERFLY(L07, L05);
|
||||||
|
|
||||||
BUTTERFLY(L05, L04);
|
BUTTERFLY(L05, L04);
|
||||||
out[3] = (OI_INT16)SCALE(L04, DCTII_8_SHIFT_3-1);
|
out[3] = (OI_INT16)SCALE(L04, DCTII_8_SHIFT_3 - 1);
|
||||||
out[5] = (OI_INT16)SCALE(L05, DCTII_8_SHIFT_5-1);
|
out[5] = (OI_INT16)SCALE(L05, DCTII_8_SHIFT_5 - 1);
|
||||||
|
|
||||||
BUTTERFLY(L07, L06);
|
BUTTERFLY(L07, L06);
|
||||||
out[7] = (OI_INT16)SCALE(L06, DCTII_8_SHIFT_7-1);
|
out[7] = (OI_INT16)SCALE(L06, DCTII_8_SHIFT_7 - 1);
|
||||||
out[1] = (OI_INT16)SCALE(L07, DCTII_8_SHIFT_1-1);
|
out[1] = (OI_INT16)SCALE(L07, DCTII_8_SHIFT_1 - 1);
|
||||||
#undef BUTTERFLY
|
#undef BUTTERFLY
|
||||||
|
|
||||||
#ifdef DEBUG_DCT
|
#ifdef DEBUG_DCT
|
||||||
|
72
examples/09_a2dp/components/bluedroid_demos/embdrv/sbc/decoder/srce/synthesis-sbc.c
Executable file → Normal file
72
examples/09_a2dp/components/bluedroid_demos/embdrv/sbc/decoder/srce/synthesis-sbc.c
Executable file → Normal file
@ -162,27 +162,27 @@ The output samples X[0..7] are defined as sums of W:
|
|||||||
#include "oi_codec_sbc_private.h"
|
#include "oi_codec_sbc_private.h"
|
||||||
|
|
||||||
const OI_INT32 dec_window_4[21] = {
|
const OI_INT32 dec_window_4[21] = {
|
||||||
0, /* +0.00000000E+00 */
|
0, /* +0.00000000E+00 */
|
||||||
97, /* +5.36548976E-04 */
|
97, /* +5.36548976E-04 */
|
||||||
270, /* +1.49188357E-03 */
|
270, /* +1.49188357E-03 */
|
||||||
495, /* +2.73370904E-03 */
|
495, /* +2.73370904E-03 */
|
||||||
694, /* +3.83720193E-03 */
|
694, /* +3.83720193E-03 */
|
||||||
704, /* +3.89205149E-03 */
|
704, /* +3.89205149E-03 */
|
||||||
338, /* +1.86581691E-03 */
|
338, /* +1.86581691E-03 */
|
||||||
-554, /* -3.06012286E-03 */
|
-554, /* -3.06012286E-03 */
|
||||||
1974, /* +1.09137620E-02 */
|
1974, /* +1.09137620E-02 */
|
||||||
3697, /* +2.04385087E-02 */
|
3697, /* +2.04385087E-02 */
|
||||||
5224, /* +2.88757392E-02 */
|
5224, /* +2.88757392E-02 */
|
||||||
5824, /* +3.21939290E-02 */
|
5824, /* +3.21939290E-02 */
|
||||||
4681, /* +2.58767811E-02 */
|
4681, /* +2.58767811E-02 */
|
||||||
1109, /* +6.13245186E-03 */
|
1109, /* +6.13245186E-03 */
|
||||||
-5214, /* -2.88217274E-02 */
|
-5214, /* -2.88217274E-02 */
|
||||||
-14047, /* -7.76463494E-02 */
|
-14047, /* -7.76463494E-02 */
|
||||||
24529, /* +1.35593274E-01 */
|
24529, /* +1.35593274E-01 */
|
||||||
35274, /* +1.94987841E-01 */
|
35274, /* +1.94987841E-01 */
|
||||||
44618, /* +2.46636662E-01 */
|
44618, /* +2.46636662E-01 */
|
||||||
50984, /* +2.81828203E-01 */
|
50984, /* +2.81828203E-01 */
|
||||||
53243, /* +2.94315332E-01 */
|
53243, /* +2.94315332E-01 */
|
||||||
};
|
};
|
||||||
|
|
||||||
#define DCTII_4_K06_FIX ( 11585)/* S1.14 11585 0.707107*/
|
#define DCTII_4_K06_FIX ( 11585)/* S1.14 11585 0.707107*/
|
||||||
@ -218,7 +218,7 @@ INLINE OI_INT32 default_mul_16s_32s_hi(OI_INT16 u, OI_INT32 v)
|
|||||||
OI_UINT16 v0;
|
OI_UINT16 v0;
|
||||||
OI_INT16 v1;
|
OI_INT16 v1;
|
||||||
|
|
||||||
OI_INT32 w,x;
|
OI_INT32 w, x;
|
||||||
|
|
||||||
v0 = (OI_UINT16)(v & 0xffff);
|
v0 = (OI_UINT16)(v & 0xffff);
|
||||||
v1 = (OI_INT16) (v >> 16);
|
v1 = (OI_INT16) (v >> 16);
|
||||||
@ -233,9 +233,9 @@ INLINE OI_INT32 default_mul_16s_32s_hi(OI_INT16 u, OI_INT32 v)
|
|||||||
|
|
||||||
#define LONG_MULT_DCT(K, sample) (MUL_16S_32S_HI(K, sample)<<2)
|
#define LONG_MULT_DCT(K, sample) (MUL_16S_32S_HI(K, sample)<<2)
|
||||||
|
|
||||||
PRIVATE void SynthWindow80_generated(OI_INT16 *pcm, SBC_BUFFER_T const * RESTRICT buffer, OI_UINT strideShift);
|
PRIVATE void SynthWindow80_generated(OI_INT16 *pcm, SBC_BUFFER_T const *RESTRICT buffer, OI_UINT strideShift);
|
||||||
PRIVATE void SynthWindow112_generated(OI_INT16 *pcm, SBC_BUFFER_T const * RESTRICT buffer, OI_UINT strideShift);
|
PRIVATE void SynthWindow112_generated(OI_INT16 *pcm, SBC_BUFFER_T const *RESTRICT buffer, OI_UINT strideShift);
|
||||||
PRIVATE void dct2_8(SBC_BUFFER_T * RESTRICT out, OI_INT32 const * RESTRICT x);
|
PRIVATE void dct2_8(SBC_BUFFER_T *RESTRICT out, OI_INT32 const *RESTRICT x);
|
||||||
|
|
||||||
typedef void (*SYNTH_FRAME)(OI_CODEC_SBC_DECODER_CONTEXT *context, OI_INT16 *pcm, OI_UINT blkstart, OI_UINT blkcount);
|
typedef void (*SYNTH_FRAME)(OI_CODEC_SBC_DECODER_CONTEXT *context, OI_INT16 *pcm, OI_UINT blkstart, OI_UINT blkcount);
|
||||||
|
|
||||||
@ -273,7 +273,7 @@ PRIVATE void OI_SBC_SynthFrame_80(OI_CODEC_SBC_DECODER_CONTEXT *context, OI_INT1
|
|||||||
}
|
}
|
||||||
offset = context->common.filterBufferLen - 80;
|
offset = context->common.filterBufferLen - 80;
|
||||||
} else {
|
} else {
|
||||||
offset -= 1*8;
|
offset -= 1 * 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (ch = 0; ch < nrof_channels; ch++) {
|
for (ch = 0; ch < nrof_channels; ch++) {
|
||||||
@ -298,19 +298,19 @@ PRIVATE void OI_SBC_SynthFrame_4SB(OI_CODEC_SBC_DECODER_CONTEXT *context, OI_INT
|
|||||||
|
|
||||||
for (blk = blkstart; blk < blkstop; blk++) {
|
for (blk = blkstart; blk < blkstop; blk++) {
|
||||||
if (offset == 0) {
|
if (offset == 0) {
|
||||||
COPY_BACKWARD_32BIT_ALIGNED_72_HALFWORDS(context->common.filterBuffer[0] + context->common.filterBufferLen - 72,context->common.filterBuffer[0]);
|
COPY_BACKWARD_32BIT_ALIGNED_72_HALFWORDS(context->common.filterBuffer[0] + context->common.filterBufferLen - 72, context->common.filterBuffer[0]);
|
||||||
if (nrof_channels == 2) {
|
if (nrof_channels == 2) {
|
||||||
COPY_BACKWARD_32BIT_ALIGNED_72_HALFWORDS(context->common.filterBuffer[1] + context->common.filterBufferLen - 72,context->common.filterBuffer[1]);
|
COPY_BACKWARD_32BIT_ALIGNED_72_HALFWORDS(context->common.filterBuffer[1] + context->common.filterBufferLen - 72, context->common.filterBuffer[1]);
|
||||||
}
|
}
|
||||||
offset =context->common.filterBufferLen - 80;
|
offset = context->common.filterBufferLen - 80;
|
||||||
} else {
|
} else {
|
||||||
offset -= 8;
|
offset -= 8;
|
||||||
}
|
}
|
||||||
for (ch = 0; ch < nrof_channels; ch++) {
|
for (ch = 0; ch < nrof_channels; ch++) {
|
||||||
cosineModulateSynth4(context->common.filterBuffer[ch] + offset, s);
|
cosineModulateSynth4(context->common.filterBuffer[ch] + offset, s);
|
||||||
SynthWindow40_int32_int32_symmetry_with_sum(pcm + ch,
|
SynthWindow40_int32_int32_symmetry_with_sum(pcm + ch,
|
||||||
context->common.filterBuffer[ch] + offset,
|
context->common.filterBuffer[ch] + offset,
|
||||||
pcmStrideShift);
|
pcmStrideShift);
|
||||||
s += 4;
|
s += 4;
|
||||||
}
|
}
|
||||||
pcm += (4 << pcmStrideShift);
|
pcm += (4 << pcmStrideShift);
|
||||||
@ -332,7 +332,7 @@ PRIVATE void OI_SBC_SynthFrame_Enhanced(OI_CODEC_SBC_DECODER_CONTEXT *context, O
|
|||||||
|
|
||||||
for (blk = blkstart; blk < blkstop; blk++) {
|
for (blk = blkstart; blk < blkstop; blk++) {
|
||||||
if (offset == 0) {
|
if (offset == 0) {
|
||||||
COPY_BACKWARD_32BIT_ALIGNED_104_HALFWORDS(context->common.filterBuffer[0] +context->common.filterBufferLen - 104, context->common.filterBuffer[0]);
|
COPY_BACKWARD_32BIT_ALIGNED_104_HALFWORDS(context->common.filterBuffer[0] + context->common.filterBufferLen - 104, context->common.filterBuffer[0]);
|
||||||
if (nrof_channels == 2) {
|
if (nrof_channels == 2) {
|
||||||
COPY_BACKWARD_32BIT_ALIGNED_104_HALFWORDS(context->common.filterBuffer[1] + context->common.filterBufferLen - 104, context->common.filterBuffer[1]);
|
COPY_BACKWARD_32BIT_ALIGNED_104_HALFWORDS(context->common.filterBuffer[1] + context->common.filterBufferLen - 104, context->common.filterBuffer[1]);
|
||||||
}
|
}
|
||||||
@ -383,7 +383,7 @@ PRIVATE void OI_SBC_SynthFrame(OI_CODEC_SBC_DECODER_CONTEXT *context, OI_INT16 *
|
|||||||
} else if (context->common.frameInfo.enhanced) {
|
} else if (context->common.frameInfo.enhanced) {
|
||||||
SynthFrameEnhanced[nrof_channels](context, pcm, start_block, nrof_blocks);
|
SynthFrameEnhanced[nrof_channels](context, pcm, start_block, nrof_blocks);
|
||||||
#endif /* SBC_ENHANCED */
|
#endif /* SBC_ENHANCED */
|
||||||
} else {
|
} else {
|
||||||
SynthFrame8SB[nrof_channels](context, pcm, start_block, nrof_blocks);
|
SynthFrame8SB[nrof_channels](context, pcm, start_block, nrof_blocks);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -472,7 +472,7 @@ void SynthWindow40_int32_int32_symmetry_with_sum(OI_INT16 *pcm, SBC_BUFFER_T buf
|
|||||||
algebra system, manually converted to fixed-point arithmetic. S4 can be
|
algebra system, manually converted to fixed-point arithmetic. S4 can be
|
||||||
implemented using only assignment and negation.
|
implemented using only assignment and negation.
|
||||||
*/
|
*/
|
||||||
PRIVATE void cosineModulateSynth4(SBC_BUFFER_T * RESTRICT out, OI_INT32 const * RESTRICT in)
|
PRIVATE void cosineModulateSynth4(SBC_BUFFER_T *RESTRICT out, OI_INT32 const *RESTRICT in)
|
||||||
{
|
{
|
||||||
OI_INT32 f0, f1, f2, f3, f4, f7, f8, f9, f10;
|
OI_INT32 f0, f1, f2, f3, f4, f7, f8, f9, f10;
|
||||||
OI_INT32 y0, y1, y2, y3;
|
OI_INT32 y0, y1, y2, y3;
|
||||||
@ -493,8 +493,8 @@ PRIVATE void cosineModulateSynth4(SBC_BUFFER_T * RESTRICT out, OI_INT32 const *
|
|||||||
y3 = -SCALE(f8 + f9, DCT_SHIFT);
|
y3 = -SCALE(f8 + f9, DCT_SHIFT);
|
||||||
y1 = -SCALE(f10 - f9, DCT_SHIFT);
|
y1 = -SCALE(f10 - f9, DCT_SHIFT);
|
||||||
|
|
||||||
out[0] = (OI_INT16)-y2;
|
out[0] = (OI_INT16) - y2;
|
||||||
out[1] = (OI_INT16)-y3;
|
out[1] = (OI_INT16) - y3;
|
||||||
out[2] = (OI_INT16)0;
|
out[2] = (OI_INT16)0;
|
||||||
out[3] = (OI_INT16)y3;
|
out[3] = (OI_INT16)y3;
|
||||||
out[4] = (OI_INT16)y2;
|
out[4] = (OI_INT16)y2;
|
||||||
|
10
examples/09_a2dp/components/bluedroid_demos/embdrv/sbc/encoder/include/sbc_dct.h
Executable file → Normal file
10
examples/09_a2dp/components/bluedroid_demos/embdrv/sbc/encoder/include/sbc_dct.h
Executable file → Normal file
@ -26,12 +26,12 @@
|
|||||||
#define SBC_DCT_H
|
#define SBC_DCT_H
|
||||||
|
|
||||||
#if (SBC_ARM_ASM_OPT==TRUE)
|
#if (SBC_ARM_ASM_OPT==TRUE)
|
||||||
#define SBC_MULT_32_16_SIMPLIFIED(s16In2, s32In1, s32OutLow) \
|
#define SBC_MULT_32_16_SIMPLIFIED(s16In2, s32In1, s32OutLow) \
|
||||||
{ \
|
{ \
|
||||||
__asm \
|
__asm \
|
||||||
{ \
|
{ \
|
||||||
MUL s32OutLow,(SINT32)s16In2, (s32In1>>15) \
|
MUL s32OutLow,(SINT32)s16In2, (s32In1>>15) \
|
||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
#if (SBC_DSP_OPT==TRUE)
|
#if (SBC_DSP_OPT==TRUE)
|
||||||
|
2
examples/09_a2dp/components/bluedroid_demos/embdrv/sbc/encoder/include/sbc_enc_func_declare.h
Executable file → Normal file
2
examples/09_a2dp/components/bluedroid_demos/embdrv/sbc/encoder/include/sbc_enc_func_declare.h
Executable file → Normal file
@ -51,7 +51,7 @@ extern void SBC_FastIDCT4 (SINT32 *x0, SINT32 *pOutVect);
|
|||||||
extern void EncPacking(SBC_ENC_PARAMS *strEncParams);
|
extern void EncPacking(SBC_ENC_PARAMS *strEncParams);
|
||||||
extern void EncQuantizer(SBC_ENC_PARAMS *);
|
extern void EncQuantizer(SBC_ENC_PARAMS *);
|
||||||
#if (SBC_DSP_OPT==TRUE)
|
#if (SBC_DSP_OPT==TRUE)
|
||||||
SINT32 SBC_Multiply_32_16_Simplified(SINT32 s32In2Temp,SINT32 s32In1Temp);
|
SINT32 SBC_Multiply_32_16_Simplified(SINT32 s32In2Temp, SINT32 s32In1Temp);
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
13
examples/09_a2dp/components/bluedroid_demos/embdrv/sbc/encoder/include/sbc_encoder.h
Executable file → Normal file
13
examples/09_a2dp/components/bluedroid_demos/embdrv/sbc/encoder/include/sbc_encoder.h
Executable file → Normal file
@ -28,7 +28,7 @@
|
|||||||
#define ENCODER_VERSION "0025"
|
#define ENCODER_VERSION "0025"
|
||||||
|
|
||||||
#ifdef BUILDCFG
|
#ifdef BUILDCFG
|
||||||
#include "bt_target.h"
|
#include "bt_target.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*DEFINES*/
|
/*DEFINES*/
|
||||||
@ -151,8 +151,7 @@
|
|||||||
|
|
||||||
#include "sbc_types.h"
|
#include "sbc_types.h"
|
||||||
|
|
||||||
typedef struct SBC_ENC_PARAMS_TAG
|
typedef struct SBC_ENC_PARAMS_TAG {
|
||||||
{
|
|
||||||
SINT16 s16SamplingFreq; /* 16k, 32k, 44.1k or 48k*/
|
SINT16 s16SamplingFreq; /* 16k, 32k, 44.1k or 48k*/
|
||||||
SINT16 s16ChannelMode; /* mono, dual, streo or joint streo*/
|
SINT16 s16ChannelMode; /* mono, dual, streo or joint streo*/
|
||||||
SINT16 s16NumOfSubBands; /* 4 or 8 */
|
SINT16 s16NumOfSubBands; /* 4 or 8 */
|
||||||
@ -168,27 +167,27 @@ typedef struct SBC_ENC_PARAMS_TAG
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
SINT16 s16MaxBitNeed;
|
SINT16 s16MaxBitNeed;
|
||||||
SINT16 as16ScaleFactor[SBC_MAX_NUM_OF_CHANNELS*SBC_MAX_NUM_OF_SUBBANDS];
|
SINT16 as16ScaleFactor[SBC_MAX_NUM_OF_CHANNELS * SBC_MAX_NUM_OF_SUBBANDS];
|
||||||
|
|
||||||
SINT16 *ps16NextPcmBuffer;
|
SINT16 *ps16NextPcmBuffer;
|
||||||
#if (SBC_NO_PCM_CPY_OPTION == TRUE)
|
#if (SBC_NO_PCM_CPY_OPTION == TRUE)
|
||||||
SINT16 *ps16PcmBuffer;
|
SINT16 *ps16PcmBuffer;
|
||||||
#else
|
#else
|
||||||
SINT16 as16PcmBuffer[SBC_MAX_NUM_FRAME*SBC_MAX_NUM_OF_BLOCKS * SBC_MAX_NUM_OF_CHANNELS * SBC_MAX_NUM_OF_SUBBANDS];
|
SINT16 as16PcmBuffer[SBC_MAX_NUM_FRAME * SBC_MAX_NUM_OF_BLOCKS * SBC_MAX_NUM_OF_CHANNELS * SBC_MAX_NUM_OF_SUBBANDS];
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
SINT16 s16ScartchMemForBitAlloc[16];
|
SINT16 s16ScartchMemForBitAlloc[16];
|
||||||
|
|
||||||
SINT32 s32SbBuffer[SBC_MAX_NUM_OF_CHANNELS * SBC_MAX_NUM_OF_SUBBANDS * SBC_MAX_NUM_OF_BLOCKS];
|
SINT32 s32SbBuffer[SBC_MAX_NUM_OF_CHANNELS * SBC_MAX_NUM_OF_SUBBANDS * SBC_MAX_NUM_OF_BLOCKS];
|
||||||
|
|
||||||
SINT16 as16Bits[SBC_MAX_NUM_OF_CHANNELS*SBC_MAX_NUM_OF_SUBBANDS];
|
SINT16 as16Bits[SBC_MAX_NUM_OF_CHANNELS * SBC_MAX_NUM_OF_SUBBANDS];
|
||||||
|
|
||||||
UINT8 *pu8Packet;
|
UINT8 *pu8Packet;
|
||||||
UINT8 *pu8NextPacket;
|
UINT8 *pu8NextPacket;
|
||||||
UINT16 FrameHeader;
|
UINT16 FrameHeader;
|
||||||
UINT16 u16PacketLength;
|
UINT16 u16PacketLength;
|
||||||
|
|
||||||
}SBC_ENC_PARAMS;
|
} SBC_ENC_PARAMS;
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C"
|
extern "C"
|
||||||
|
2
examples/09_a2dp/components/bluedroid_demos/embdrv/sbc/encoder/include/sbc_if.h
Executable file → Normal file
2
examples/09_a2dp/components/bluedroid_demos/embdrv/sbc/encoder/include/sbc_if.h
Executable file → Normal file
@ -34,7 +34,7 @@ int SBC_init(int pcm_sample_freq, int channels, int bits_per_sample);
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
SBC_write - called repeatedly with pcm_in pointer
|
SBC_write - called repeatedly with pcm_in pointer
|
||||||
increasing by length until track is finished.
|
increasing by length until track is finished.
|
||||||
|
|
||||||
pcm_in - pointer to PCM buffer
|
pcm_in - pointer to PCM buffer
|
||||||
length - any
|
length - any
|
||||||
|
212
examples/09_a2dp/components/bluedroid_demos/embdrv/sbc/encoder/srce/sbc_analysis.c
Executable file → Normal file
212
examples/09_a2dp/components/bluedroid_demos/embdrv/sbc/encoder/srce/sbc_analysis.c
Executable file → Normal file
@ -157,8 +157,8 @@
|
|||||||
#pragma arm section zidata = "sbc_s32_analysis_section"
|
#pragma arm section zidata = "sbc_s32_analysis_section"
|
||||||
#endif
|
#endif
|
||||||
static SINT32 s32DCTY[16] = {0};
|
static SINT32 s32DCTY[16] = {0};
|
||||||
static SINT32 s32X[ENC_VX_BUFFER_SIZE/2];
|
static SINT32 s32X[ENC_VX_BUFFER_SIZE / 2];
|
||||||
static SINT16 *s16X=(SINT16*) s32X; /* s16X must be 32 bits aligned cf SHIFTUP_X8_2*/
|
static SINT16 *s16X = (SINT16 *) s32X; /* s16X must be 32 bits aligned cf SHIFTUP_X8_2*/
|
||||||
#if (SBC_USE_ARM_PRAGMA==TRUE)
|
#if (SBC_USE_ARM_PRAGMA==TRUE)
|
||||||
#pragma arm section zidata
|
#pragma arm section zidata
|
||||||
#endif
|
#endif
|
||||||
@ -830,7 +830,7 @@ static SINT16 *s16X=(SINT16*) s32X; /* s16X must be 32 bits aligned cf S
|
|||||||
s64Temp+=((SINT64)gas32CoeffFor4SBs[(i+24)] * (SINT64)s16X[ChOffset+i+24]); \
|
s64Temp+=((SINT64)gas32CoeffFor4SBs[(i+24)] * (SINT64)s16X[ChOffset+i+24]); \
|
||||||
s64Temp+=((SINT64)gas32CoeffFor4SBs[(i+32)] * (SINT64)s16X[ChOffset+i+32]); \
|
s64Temp+=((SINT64)gas32CoeffFor4SBs[(i+32)] * (SINT64)s16X[ChOffset+i+32]); \
|
||||||
s32DCTY[i]=(SINT32)(s64Temp>>16);\
|
s32DCTY[i]=(SINT32)(s64Temp>>16);\
|
||||||
/*printf("s32DCTY4: 0x%x \n", s32DCTY[i]);*/\
|
/*printf("s32DCTY4: 0x%x \n", s32DCTY[i]);*/\
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
#define WINDOW_ACCU_4(i) \
|
#define WINDOW_ACCU_4(i) \
|
||||||
@ -863,7 +863,7 @@ static SINT16 *s16X=(SINT16*) s32X; /* s16X must be 32 bits aligned cf S
|
|||||||
s64Temp+= ((((SINT64)gas32CoeffFor8SBs[(i+32)] * (SINT64)s16X[ChOffset+i+32]))); \
|
s64Temp+= ((((SINT64)gas32CoeffFor8SBs[(i+32)] * (SINT64)s16X[ChOffset+i+32]))); \
|
||||||
s64Temp+= ((((SINT64)gas32CoeffFor8SBs[(i+48)] * (SINT64)s16X[ChOffset+i+48]))); \
|
s64Temp+= ((((SINT64)gas32CoeffFor8SBs[(i+48)] * (SINT64)s16X[ChOffset+i+48]))); \
|
||||||
s64Temp+= ((((SINT64)gas32CoeffFor8SBs[(i+64)] * (SINT64)s16X[ChOffset+i+64]))); \
|
s64Temp+= ((((SINT64)gas32CoeffFor8SBs[(i+64)] * (SINT64)s16X[ChOffset+i+64]))); \
|
||||||
/*printf("s32DCTY8: %d= 0x%x * %d\n", s32DCTY[i], gas32CoeffFor8SBs[i], s16X[ChOffset+i]);*/ \
|
/*printf("s32DCTY8: %d= 0x%x * %d\n", s32DCTY[i], gas32CoeffFor8SBs[i], s16X[ChOffset+i]);*/ \
|
||||||
s32DCTY[i]=(SINT32)(s64Temp>>16);\
|
s32DCTY[i]=(SINT32)(s64Temp>>16);\
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
@ -879,7 +879,7 @@ static SINT16 *s16X=(SINT16*) s32X; /* s16X must be 32 bits aligned cf S
|
|||||||
+ (((SINT32)(UINT16)(gas32CoeffFor8SBs[((i+48) * 2) + 1]) * s16X[ChOffset+i+48]) >> 16); \
|
+ (((SINT32)(UINT16)(gas32CoeffFor8SBs[((i+48) * 2) + 1]) * s16X[ChOffset+i+48]) >> 16); \
|
||||||
s32DCTY[i]+=(gas32CoeffFor8SBs[(i+64) * 2] * s16X[ChOffset+i+64]) \
|
s32DCTY[i]+=(gas32CoeffFor8SBs[(i+64) * 2] * s16X[ChOffset+i+64]) \
|
||||||
+ (((SINT32)(UINT16)(gas32CoeffFor8SBs[((i+64) * 2) + 1]) * s16X[ChOffset+i+64]) >> 16); \
|
+ (((SINT32)(UINT16)(gas32CoeffFor8SBs[((i+64) * 2) + 1]) * s16X[ChOffset+i+64]) >> 16); \
|
||||||
/*printf("s32DCTY8: %d = 0x%4x%4x * %d\n", s32DCTY[i], gas32CoeffFor8SBs[i * 2], (gas32CoeffFor8SBs[(i * 2) + 1]), s16X[ChOffset+i]);*/\
|
/*printf("s32DCTY8: %d = 0x%4x%4x * %d\n", s32DCTY[i], gas32CoeffFor8SBs[i * 2], (gas32CoeffFor8SBs[(i * 2) + 1]), s16X[ChOffset+i]);*/\
|
||||||
/*s32DCTY[i]=(SINT32)(s64Temp>>16);*/\
|
/*s32DCTY[i]=(SINT32)(s64Temp>>16);*/\
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -897,7 +897,7 @@ static SINT16 *s16X=(SINT16*) s32X; /* s16X must be 32 bits aligned cf S
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static SINT16 ShiftCounter=0;
|
static SINT16 ShiftCounter = 0;
|
||||||
extern SINT16 EncMaxShiftCounter;
|
extern SINT16 EncMaxShiftCounter;
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* SbcAnalysisFilter - performs Analysis of the input audio stream
|
* SbcAnalysisFilter - performs Analysis of the input audio stream
|
||||||
@ -908,18 +908,18 @@ void SbcAnalysisFilter4(SBC_ENC_PARAMS *pstrEncParams)
|
|||||||
{
|
{
|
||||||
SINT16 *ps16PcmBuf;
|
SINT16 *ps16PcmBuf;
|
||||||
SINT32 *ps32SbBuf;
|
SINT32 *ps32SbBuf;
|
||||||
SINT32 s32Blk,s32Ch;
|
SINT32 s32Blk, s32Ch;
|
||||||
SINT32 s32NumOfChannels, s32NumOfBlocks;
|
SINT32 s32NumOfChannels, s32NumOfBlocks;
|
||||||
SINT32 i,*ps32X,*ps32X2;
|
SINT32 i, *ps32X, *ps32X2;
|
||||||
SINT32 Offset,Offset2,ChOffset;
|
SINT32 Offset, Offset2, ChOffset;
|
||||||
#if (SBC_ARM_ASM_OPT==TRUE)
|
#if (SBC_ARM_ASM_OPT==TRUE)
|
||||||
register SINT32 s32Hi,s32Hi2;
|
register SINT32 s32Hi, s32Hi2;
|
||||||
#else
|
#else
|
||||||
#if (SBC_IPAQ_OPT==TRUE)
|
#if (SBC_IPAQ_OPT==TRUE)
|
||||||
#if (SBC_IS_64_MULT_IN_WINDOW_ACCU == TRUE)
|
#if (SBC_IS_64_MULT_IN_WINDOW_ACCU == TRUE)
|
||||||
register SINT64 s64Temp,s64Temp2;
|
register SINT64 s64Temp, s64Temp2;
|
||||||
#else
|
#else
|
||||||
register SINT32 s32Temp,s32Temp2;
|
register SINT32 s32Temp, s32Temp2;
|
||||||
#endif
|
#endif
|
||||||
#else
|
#else
|
||||||
|
|
||||||
@ -936,61 +936,47 @@ void SbcAnalysisFilter4(SBC_ENC_PARAMS *pstrEncParams)
|
|||||||
ps16PcmBuf = pstrEncParams->ps16NextPcmBuffer;
|
ps16PcmBuf = pstrEncParams->ps16NextPcmBuffer;
|
||||||
|
|
||||||
ps32SbBuf = pstrEncParams->s32SbBuffer;
|
ps32SbBuf = pstrEncParams->s32SbBuffer;
|
||||||
Offset2=(SINT32)(EncMaxShiftCounter+40);
|
Offset2 = (SINT32)(EncMaxShiftCounter + 40);
|
||||||
for (s32Blk=0; s32Blk <s32NumOfBlocks; s32Blk++)
|
for (s32Blk = 0; s32Blk < s32NumOfBlocks; s32Blk++) {
|
||||||
{
|
Offset = (SINT32)(EncMaxShiftCounter - ShiftCounter);
|
||||||
Offset=(SINT32)(EncMaxShiftCounter-ShiftCounter);
|
|
||||||
/* Store new samples */
|
/* Store new samples */
|
||||||
if (s32NumOfChannels==1)
|
if (s32NumOfChannels == 1) {
|
||||||
{
|
s16X[3 + Offset] = *ps16PcmBuf; ps16PcmBuf++;
|
||||||
s16X[3+Offset] = *ps16PcmBuf; ps16PcmBuf++;
|
s16X[2 + Offset] = *ps16PcmBuf; ps16PcmBuf++;
|
||||||
s16X[2+Offset] = *ps16PcmBuf; ps16PcmBuf++;
|
s16X[1 + Offset] = *ps16PcmBuf; ps16PcmBuf++;
|
||||||
s16X[1+Offset] = *ps16PcmBuf; ps16PcmBuf++;
|
s16X[0 + Offset] = *ps16PcmBuf; ps16PcmBuf++;
|
||||||
s16X[0+Offset] = *ps16PcmBuf; ps16PcmBuf++;
|
} else {
|
||||||
|
s16X[3 + Offset] = *ps16PcmBuf; ps16PcmBuf++;
|
||||||
|
s16X[Offset2 + 3 + Offset] = *ps16PcmBuf; ps16PcmBuf++;
|
||||||
|
s16X[2 + Offset] = *ps16PcmBuf; ps16PcmBuf++;
|
||||||
|
s16X[Offset2 + 2 + Offset] = *ps16PcmBuf; ps16PcmBuf++;
|
||||||
|
s16X[1 + Offset] = *ps16PcmBuf; ps16PcmBuf++;
|
||||||
|
s16X[Offset2 + 1 + Offset] = *ps16PcmBuf; ps16PcmBuf++;
|
||||||
|
s16X[0 + Offset] = *ps16PcmBuf; ps16PcmBuf++;
|
||||||
|
s16X[Offset2 + 0 + Offset] = *ps16PcmBuf; ps16PcmBuf++;
|
||||||
}
|
}
|
||||||
else
|
for (s32Ch = 0; s32Ch < s32NumOfChannels; s32Ch++) {
|
||||||
{
|
ChOffset = s32Ch * Offset2 + Offset;
|
||||||
s16X[3+Offset] = *ps16PcmBuf; ps16PcmBuf++;
|
|
||||||
s16X[Offset2+3+Offset] = *ps16PcmBuf; ps16PcmBuf++;
|
|
||||||
s16X[2+Offset] = *ps16PcmBuf; ps16PcmBuf++;
|
|
||||||
s16X[Offset2+2+Offset] = *ps16PcmBuf; ps16PcmBuf++;
|
|
||||||
s16X[1+Offset] = *ps16PcmBuf; ps16PcmBuf++;
|
|
||||||
s16X[Offset2+1+Offset] = *ps16PcmBuf; ps16PcmBuf++;
|
|
||||||
s16X[0+Offset] = *ps16PcmBuf; ps16PcmBuf++;
|
|
||||||
s16X[Offset2+0+Offset] = *ps16PcmBuf; ps16PcmBuf++;
|
|
||||||
}
|
|
||||||
for (s32Ch=0;s32Ch<s32NumOfChannels;s32Ch++)
|
|
||||||
{
|
|
||||||
ChOffset=s32Ch*Offset2+Offset;
|
|
||||||
|
|
||||||
WINDOW_PARTIAL_4
|
WINDOW_PARTIAL_4
|
||||||
|
|
||||||
SBC_FastIDCT4(s32DCTY, ps32SbBuf);
|
SBC_FastIDCT4(s32DCTY, ps32SbBuf);
|
||||||
|
|
||||||
ps32SbBuf +=SUB_BANDS_4;
|
ps32SbBuf += SUB_BANDS_4;
|
||||||
}
|
}
|
||||||
if (s32NumOfChannels==1)
|
if (s32NumOfChannels == 1) {
|
||||||
{
|
if (ShiftCounter >= EncMaxShiftCounter) {
|
||||||
if (ShiftCounter>=EncMaxShiftCounter)
|
|
||||||
{
|
|
||||||
SHIFTUP_X4;
|
SHIFTUP_X4;
|
||||||
ShiftCounter=0;
|
ShiftCounter = 0;
|
||||||
|
} else {
|
||||||
|
ShiftCounter += SUB_BANDS_4;
|
||||||
}
|
}
|
||||||
else
|
} else {
|
||||||
{
|
if (ShiftCounter >= EncMaxShiftCounter) {
|
||||||
ShiftCounter+=SUB_BANDS_4;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (ShiftCounter>=EncMaxShiftCounter)
|
|
||||||
{
|
|
||||||
SHIFTUP_X4_2;
|
SHIFTUP_X4_2;
|
||||||
ShiftCounter=0;
|
ShiftCounter = 0;
|
||||||
}
|
} else {
|
||||||
else
|
ShiftCounter += SUB_BANDS_4;
|
||||||
{
|
|
||||||
ShiftCounter+=SUB_BANDS_4;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1001,19 +987,19 @@ void SbcAnalysisFilter8 (SBC_ENC_PARAMS *pstrEncParams)
|
|||||||
{
|
{
|
||||||
SINT16 *ps16PcmBuf;
|
SINT16 *ps16PcmBuf;
|
||||||
SINT32 *ps32SbBuf;
|
SINT32 *ps32SbBuf;
|
||||||
SINT32 s32Blk,s32Ch; /* counter for block*/
|
SINT32 s32Blk, s32Ch; /* counter for block*/
|
||||||
SINT32 Offset,Offset2;
|
SINT32 Offset, Offset2;
|
||||||
SINT32 s32NumOfChannels, s32NumOfBlocks;
|
SINT32 s32NumOfChannels, s32NumOfBlocks;
|
||||||
SINT32 i,*ps32X,*ps32X2;
|
SINT32 i, *ps32X, *ps32X2;
|
||||||
SINT32 ChOffset;
|
SINT32 ChOffset;
|
||||||
#if (SBC_ARM_ASM_OPT==TRUE)
|
#if (SBC_ARM_ASM_OPT==TRUE)
|
||||||
register SINT32 s32Hi,s32Hi2;
|
register SINT32 s32Hi, s32Hi2;
|
||||||
#else
|
#else
|
||||||
#if (SBC_IPAQ_OPT==TRUE)
|
#if (SBC_IPAQ_OPT==TRUE)
|
||||||
#if (SBC_IS_64_MULT_IN_WINDOW_ACCU == TRUE)
|
#if (SBC_IS_64_MULT_IN_WINDOW_ACCU == TRUE)
|
||||||
register SINT64 s64Temp,s64Temp2;
|
register SINT64 s64Temp, s64Temp2;
|
||||||
#else
|
#else
|
||||||
register SINT32 s32Temp,s32Temp2;
|
register SINT32 s32Temp, s32Temp2;
|
||||||
#endif
|
#endif
|
||||||
#else
|
#else
|
||||||
#if (SBC_IS_64_MULT_IN_WINDOW_ACCU == TRUE)
|
#if (SBC_IS_64_MULT_IN_WINDOW_ACCU == TRUE)
|
||||||
@ -1028,73 +1014,59 @@ void SbcAnalysisFilter8 (SBC_ENC_PARAMS *pstrEncParams)
|
|||||||
ps16PcmBuf = pstrEncParams->ps16NextPcmBuffer;
|
ps16PcmBuf = pstrEncParams->ps16NextPcmBuffer;
|
||||||
|
|
||||||
ps32SbBuf = pstrEncParams->s32SbBuffer;
|
ps32SbBuf = pstrEncParams->s32SbBuffer;
|
||||||
Offset2=(SINT32)(EncMaxShiftCounter+80);
|
Offset2 = (SINT32)(EncMaxShiftCounter + 80);
|
||||||
for (s32Blk=0; s32Blk <s32NumOfBlocks; s32Blk++)
|
for (s32Blk = 0; s32Blk < s32NumOfBlocks; s32Blk++) {
|
||||||
{
|
Offset = (SINT32)(EncMaxShiftCounter - ShiftCounter);
|
||||||
Offset=(SINT32)(EncMaxShiftCounter-ShiftCounter);
|
|
||||||
/* Store new samples */
|
/* Store new samples */
|
||||||
if (s32NumOfChannels==1)
|
if (s32NumOfChannels == 1) {
|
||||||
{
|
s16X[7 + Offset] = *ps16PcmBuf; ps16PcmBuf++;
|
||||||
s16X[7+Offset] = *ps16PcmBuf; ps16PcmBuf++;
|
s16X[6 + Offset] = *ps16PcmBuf; ps16PcmBuf++;
|
||||||
s16X[6+Offset] = *ps16PcmBuf; ps16PcmBuf++;
|
s16X[5 + Offset] = *ps16PcmBuf; ps16PcmBuf++;
|
||||||
s16X[5+Offset] = *ps16PcmBuf; ps16PcmBuf++;
|
s16X[4 + Offset] = *ps16PcmBuf; ps16PcmBuf++;
|
||||||
s16X[4+Offset] = *ps16PcmBuf; ps16PcmBuf++;
|
s16X[3 + Offset] = *ps16PcmBuf; ps16PcmBuf++;
|
||||||
s16X[3+Offset] = *ps16PcmBuf; ps16PcmBuf++;
|
s16X[2 + Offset] = *ps16PcmBuf; ps16PcmBuf++;
|
||||||
s16X[2+Offset] = *ps16PcmBuf; ps16PcmBuf++;
|
s16X[1 + Offset] = *ps16PcmBuf; ps16PcmBuf++;
|
||||||
s16X[1+Offset] = *ps16PcmBuf; ps16PcmBuf++;
|
s16X[0 + Offset] = *ps16PcmBuf; ps16PcmBuf++;
|
||||||
s16X[0+Offset] = *ps16PcmBuf; ps16PcmBuf++;
|
} else {
|
||||||
|
s16X[7 + Offset] = *ps16PcmBuf; ps16PcmBuf++;
|
||||||
|
s16X[Offset2 + 7 + Offset] = *ps16PcmBuf; ps16PcmBuf++;
|
||||||
|
s16X[6 + Offset] = *ps16PcmBuf; ps16PcmBuf++;
|
||||||
|
s16X[Offset2 + 6 + Offset] = *ps16PcmBuf; ps16PcmBuf++;
|
||||||
|
s16X[5 + Offset] = *ps16PcmBuf; ps16PcmBuf++;
|
||||||
|
s16X[Offset2 + 5 + Offset] = *ps16PcmBuf; ps16PcmBuf++;
|
||||||
|
s16X[4 + Offset] = *ps16PcmBuf; ps16PcmBuf++;
|
||||||
|
s16X[Offset2 + 4 + Offset] = *ps16PcmBuf; ps16PcmBuf++;
|
||||||
|
s16X[3 + Offset] = *ps16PcmBuf; ps16PcmBuf++;
|
||||||
|
s16X[Offset2 + 3 + Offset] = *ps16PcmBuf; ps16PcmBuf++;
|
||||||
|
s16X[2 + Offset] = *ps16PcmBuf; ps16PcmBuf++;
|
||||||
|
s16X[Offset2 + 2 + Offset] = *ps16PcmBuf; ps16PcmBuf++;
|
||||||
|
s16X[1 + Offset] = *ps16PcmBuf; ps16PcmBuf++;
|
||||||
|
s16X[Offset2 + 1 + Offset] = *ps16PcmBuf; ps16PcmBuf++;
|
||||||
|
s16X[0 + Offset] = *ps16PcmBuf; ps16PcmBuf++;
|
||||||
|
s16X[Offset2 + 0 + Offset] = *ps16PcmBuf; ps16PcmBuf++;
|
||||||
}
|
}
|
||||||
else
|
for (s32Ch = 0; s32Ch < s32NumOfChannels; s32Ch++) {
|
||||||
{
|
ChOffset = s32Ch * Offset2 + Offset;
|
||||||
s16X[7+Offset] = *ps16PcmBuf; ps16PcmBuf++;
|
|
||||||
s16X[Offset2+7+Offset] = *ps16PcmBuf; ps16PcmBuf++;
|
|
||||||
s16X[6+Offset] = *ps16PcmBuf; ps16PcmBuf++;
|
|
||||||
s16X[Offset2+6+Offset] = *ps16PcmBuf; ps16PcmBuf++;
|
|
||||||
s16X[5+Offset] = *ps16PcmBuf; ps16PcmBuf++;
|
|
||||||
s16X[Offset2+5+Offset] = *ps16PcmBuf; ps16PcmBuf++;
|
|
||||||
s16X[4+Offset] = *ps16PcmBuf; ps16PcmBuf++;
|
|
||||||
s16X[Offset2+4+Offset] = *ps16PcmBuf; ps16PcmBuf++;
|
|
||||||
s16X[3+Offset] = *ps16PcmBuf; ps16PcmBuf++;
|
|
||||||
s16X[Offset2+3+Offset] = *ps16PcmBuf; ps16PcmBuf++;
|
|
||||||
s16X[2+Offset] = *ps16PcmBuf; ps16PcmBuf++;
|
|
||||||
s16X[Offset2+2+Offset] = *ps16PcmBuf; ps16PcmBuf++;
|
|
||||||
s16X[1+Offset] = *ps16PcmBuf; ps16PcmBuf++;
|
|
||||||
s16X[Offset2+1+Offset] = *ps16PcmBuf; ps16PcmBuf++;
|
|
||||||
s16X[0+Offset] = *ps16PcmBuf; ps16PcmBuf++;
|
|
||||||
s16X[Offset2+0+Offset] = *ps16PcmBuf; ps16PcmBuf++;
|
|
||||||
}
|
|
||||||
for (s32Ch=0;s32Ch<s32NumOfChannels;s32Ch++)
|
|
||||||
{
|
|
||||||
ChOffset=s32Ch*Offset2+Offset;
|
|
||||||
|
|
||||||
WINDOW_PARTIAL_8
|
WINDOW_PARTIAL_8
|
||||||
|
|
||||||
SBC_FastIDCT8 (s32DCTY, ps32SbBuf);
|
SBC_FastIDCT8 (s32DCTY, ps32SbBuf);
|
||||||
|
|
||||||
ps32SbBuf +=SUB_BANDS_8;
|
ps32SbBuf += SUB_BANDS_8;
|
||||||
}
|
}
|
||||||
if (s32NumOfChannels==1)
|
if (s32NumOfChannels == 1) {
|
||||||
{
|
if (ShiftCounter >= EncMaxShiftCounter) {
|
||||||
if (ShiftCounter>=EncMaxShiftCounter)
|
|
||||||
{
|
|
||||||
SHIFTUP_X8;
|
SHIFTUP_X8;
|
||||||
ShiftCounter=0;
|
ShiftCounter = 0;
|
||||||
|
} else {
|
||||||
|
ShiftCounter += SUB_BANDS_8;
|
||||||
}
|
}
|
||||||
else
|
} else {
|
||||||
{
|
if (ShiftCounter >= EncMaxShiftCounter) {
|
||||||
ShiftCounter+=SUB_BANDS_8;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (ShiftCounter>=EncMaxShiftCounter)
|
|
||||||
{
|
|
||||||
SHIFTUP_X8_2;
|
SHIFTUP_X8_2;
|
||||||
ShiftCounter=0;
|
ShiftCounter = 0;
|
||||||
}
|
} else {
|
||||||
else
|
ShiftCounter += SUB_BANDS_8;
|
||||||
{
|
|
||||||
ShiftCounter+=SUB_BANDS_8;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1102,6 +1074,6 @@ void SbcAnalysisFilter8 (SBC_ENC_PARAMS *pstrEncParams)
|
|||||||
|
|
||||||
void SbcAnalysisInit (void)
|
void SbcAnalysisInit (void)
|
||||||
{
|
{
|
||||||
memset(s16X,0,ENC_VX_BUFFER_SIZE*sizeof(SINT16));
|
memset(s16X, 0, ENC_VX_BUFFER_SIZE * sizeof(SINT16));
|
||||||
ShiftCounter=0;
|
ShiftCounter = 0;
|
||||||
}
|
}
|
||||||
|
100
examples/09_a2dp/components/bluedroid_demos/embdrv/sbc/encoder/srce/sbc_dct.c
Executable file → Normal file
100
examples/09_a2dp/components/bluedroid_demos/embdrv/sbc/encoder/srce/sbc_dct.c
Executable file → Normal file
@ -84,19 +84,19 @@ void SBC_FastIDCT8(SINT32 *pInVect, SINT32 *pOutVect)
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
register SINT32 x0, x1, x2, x3, x4, x5, x6, x7,temp;
|
register SINT32 x0, x1, x2, x3, x4, x5, x6, x7, temp;
|
||||||
SINT32 res_even[4], res_odd[4];
|
SINT32 res_even[4], res_odd[4];
|
||||||
/*x0= (pInVect[4])/2 ;*/
|
/*x0= (pInVect[4])/2 ;*/
|
||||||
SBC_IDCT_MULT(SBC_COS_PI_SUR_4,pInVect[4], x0);
|
SBC_IDCT_MULT(SBC_COS_PI_SUR_4, pInVect[4], x0);
|
||||||
/*printf("x0 0x%x = %d = %d * %d\n", x0, x0, SBC_COS_PI_SUR_4, pInVect[4]);*/
|
/*printf("x0 0x%x = %d = %d * %d\n", x0, x0, SBC_COS_PI_SUR_4, pInVect[4]);*/
|
||||||
|
|
||||||
x1 = (pInVect[3] + pInVect[5]) >>1;
|
x1 = (pInVect[3] + pInVect[5]) >> 1;
|
||||||
x2 = (pInVect[2] + pInVect[6]) >>1;
|
x2 = (pInVect[2] + pInVect[6]) >> 1;
|
||||||
x3 = (pInVect[1] + pInVect[7]) >>1;
|
x3 = (pInVect[1] + pInVect[7]) >> 1;
|
||||||
x4 = (pInVect[0] + pInVect[8]) >>1;
|
x4 = (pInVect[0] + pInVect[8]) >> 1;
|
||||||
x5 = (pInVect[9] - pInVect[15]) >>1;
|
x5 = (pInVect[9] - pInVect[15]) >> 1;
|
||||||
x6 = (pInVect[10] - pInVect[14])>>1;
|
x6 = (pInVect[10] - pInVect[14]) >> 1;
|
||||||
x7 = (pInVect[11] - pInVect[13])>>1;
|
x7 = (pInVect[11] - pInVect[13]) >> 1;
|
||||||
|
|
||||||
/* 2-point IDCT of x0 and x4 as in (11) */
|
/* 2-point IDCT of x0 and x4 as in (11) */
|
||||||
temp = x0 ;
|
temp = x0 ;
|
||||||
@ -104,14 +104,14 @@ void SBC_FastIDCT8(SINT32 *pInVect, SINT32 *pOutVect)
|
|||||||
SBC_IDCT_MULT(SBC_COS_PI_SUR_4, ( temp - x4 ), x4); /*x4 = ( temp - x4 ) * cos(1*pi/4) ; */
|
SBC_IDCT_MULT(SBC_COS_PI_SUR_4, ( temp - x4 ), x4); /*x4 = ( temp - x4 ) * cos(1*pi/4) ; */
|
||||||
|
|
||||||
/* rearrangement of x2 and x6 as in (15) */
|
/* rearrangement of x2 and x6 as in (15) */
|
||||||
x2 -=x6;
|
x2 -= x6;
|
||||||
x6 <<= 1 ;
|
x6 <<= 1 ;
|
||||||
|
|
||||||
/* 2-point IDCT of x2 and x6 and post-multiplication as in (15) */
|
/* 2-point IDCT of x2 and x6 and post-multiplication as in (15) */
|
||||||
SBC_IDCT_MULT(SBC_COS_PI_SUR_4,x6, x6); /*x6 = x6 * cos(1*pi/4) ; */
|
SBC_IDCT_MULT(SBC_COS_PI_SUR_4, x6, x6); /*x6 = x6 * cos(1*pi/4) ; */
|
||||||
temp = x2 ;
|
temp = x2 ;
|
||||||
SBC_IDCT_MULT(SBC_COS_PI_SUR_8,( x2 + x6 ), x2); /*x2 = ( x2 + x6 ) * cos(1*pi/8) ; */
|
SBC_IDCT_MULT(SBC_COS_PI_SUR_8, ( x2 + x6 ), x2); /*x2 = ( x2 + x6 ) * cos(1*pi/8) ; */
|
||||||
SBC_IDCT_MULT(SBC_COS_3PI_SUR_8,( temp - x6 ), x6); /*x6 = ( temp - x6 ) * cos(3*pi/8) ;*/
|
SBC_IDCT_MULT(SBC_COS_3PI_SUR_8, ( temp - x6 ), x6); /*x6 = ( temp - x6 ) * cos(3*pi/8) ;*/
|
||||||
|
|
||||||
/* 4-point IDCT of x0,x2,x4 and x6 as in (11) */
|
/* 4-point IDCT of x0,x2,x4 and x6 as in (11) */
|
||||||
res_even[ 0 ] = x0 + x2 ;
|
res_even[ 0 ] = x0 + x2 ;
|
||||||
@ -122,9 +122,9 @@ void SBC_FastIDCT8(SINT32 *pInVect, SINT32 *pOutVect)
|
|||||||
|
|
||||||
/* rearrangement of x1,x3,x5,x7 as in (15) */
|
/* rearrangement of x1,x3,x5,x7 as in (15) */
|
||||||
x7 <<= 1 ;
|
x7 <<= 1 ;
|
||||||
x5 = ( x5 <<1 ) - x7 ;
|
x5 = ( x5 << 1 ) - x7 ;
|
||||||
x3 = ( x3 <<1 ) - x5 ;
|
x3 = ( x3 << 1 ) - x5 ;
|
||||||
x1 -= x3 >>1 ;
|
x1 -= x3 >> 1 ;
|
||||||
|
|
||||||
/* two-dimensional IDCT of x1 and x5 */
|
/* two-dimensional IDCT of x1 and x5 */
|
||||||
SBC_IDCT_MULT(SBC_COS_PI_SUR_4, x5, x5); /*x5 = x5 * cos(1*pi/4) ; */
|
SBC_IDCT_MULT(SBC_COS_PI_SUR_4, x5, x5); /*x5 = x5 * cos(1*pi/4) ; */
|
||||||
@ -139,8 +139,8 @@ void SBC_FastIDCT8(SINT32 *pInVect, SINT32 *pOutVect)
|
|||||||
|
|
||||||
/* 2-point IDCT of x3 and x7 and post-multiplication as in (15) */
|
/* 2-point IDCT of x3 and x7 and post-multiplication as in (15) */
|
||||||
temp = x3 ;
|
temp = x3 ;
|
||||||
SBC_IDCT_MULT( SBC_COS_PI_SUR_8,( x3 + x7 ), x3); /*x3 = ( x3 + x7 ) * cos(1*pi/8) ; */
|
SBC_IDCT_MULT( SBC_COS_PI_SUR_8, ( x3 + x7 ), x3); /*x3 = ( x3 + x7 ) * cos(1*pi/8) ; */
|
||||||
SBC_IDCT_MULT( SBC_COS_3PI_SUR_8,( temp - x7 ), x7); /*x7 = ( temp - x7 ) * cos(3*pi/8) ;*/
|
SBC_IDCT_MULT( SBC_COS_3PI_SUR_8, ( temp - x7 ), x7); /*x7 = ( temp - x7 ) * cos(3*pi/8) ;*/
|
||||||
|
|
||||||
/* 4-point IDCT of x1,x3,x5 and x7 and post multiplication by diagonal matrix as in (14) */
|
/* 4-point IDCT of x1,x3,x5 and x7 and post multiplication by diagonal matrix as in (14) */
|
||||||
SBC_IDCT_MULT((SBC_COS_PI_SUR_16), ( x1 + x3 ) , res_odd[0]); /*res_odd[ 0 ] = ( x1 + x3 ) * cos(1*pi/16) ; */
|
SBC_IDCT_MULT((SBC_COS_PI_SUR_16), ( x1 + x3 ) , res_odd[0]); /*res_odd[ 0 ] = ( x1 + x3 ) * cos(1*pi/16) ; */
|
||||||
@ -160,21 +160,19 @@ void SBC_FastIDCT8(SINT32 *pInVect, SINT32 *pOutVect)
|
|||||||
#else
|
#else
|
||||||
UINT8 Index, k;
|
UINT8 Index, k;
|
||||||
SINT32 temp;
|
SINT32 temp;
|
||||||
/*Calculate 4 subband samples by matrixing*/
|
/*Calculate 4 subband samples by matrixing*/
|
||||||
for(Index=0; Index<8; Index++)
|
for (Index = 0; Index < 8; Index++) {
|
||||||
{
|
|
||||||
temp = 0;
|
temp = 0;
|
||||||
for(k=0; k<16; k++)
|
for (k = 0; k < 16; k++) {
|
||||||
{
|
|
||||||
/*temp += (SINT32)(((SINT64)M[(Index*strEncParams->numOfSubBands*2)+k] * Y[k]) >> 16 );*/
|
/*temp += (SINT32)(((SINT64)M[(Index*strEncParams->numOfSubBands*2)+k] * Y[k]) >> 16 );*/
|
||||||
temp += (gas16AnalDCTcoeff8[(Index*8*2)+k] * (pInVect[k] >> 16));
|
temp += (gas16AnalDCTcoeff8[(Index * 8 * 2) + k] * (pInVect[k] >> 16));
|
||||||
temp += ((gas16AnalDCTcoeff8[(Index*8*2)+k] * (pInVect[k] & 0xFFFF)) >> 16);
|
temp += ((gas16AnalDCTcoeff8[(Index * 8 * 2) + k] * (pInVect[k] & 0xFFFF)) >> 16);
|
||||||
}
|
}
|
||||||
pOutVect[Index] = temp;
|
pOutVect[Index] = temp;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
/* printf("pOutVect: 0x%x;0x%x;0x%x;0x%x;0x%x;0x%x;0x%x;0x%x\n",\
|
/* printf("pOutVect: 0x%x;0x%x;0x%x;0x%x;0x%x;0x%x;0x%x;0x%x\n",\
|
||||||
pOutVect[0],pOutVect[1],pOutVect[2],pOutVect[3],pOutVect[4],pOutVect[5],pOutVect[6],pOutVect[7]);*/
|
pOutVect[0],pOutVect[1],pOutVect[2],pOutVect[3],pOutVect[4],pOutVect[5],pOutVect[6],pOutVect[7]);*/
|
||||||
}
|
}
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
@ -206,38 +204,36 @@ void SBC_FastIDCT4(SINT32 *pInVect, SINT32 *pOutVect)
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
SINT32 temp,x2;
|
SINT32 temp, x2;
|
||||||
SINT32 tmp[8];
|
SINT32 tmp[8];
|
||||||
|
|
||||||
x2=pInVect[2]>>1;
|
x2 = pInVect[2] >> 1;
|
||||||
temp=(pInVect[0]+pInVect[4]);
|
temp = (pInVect[0] + pInVect[4]);
|
||||||
SBC_IDCT_MULT((SBC_COS_PI_SUR_4>>1), temp , tmp[0]);
|
SBC_IDCT_MULT((SBC_COS_PI_SUR_4 >> 1), temp , tmp[0]);
|
||||||
tmp[1]=x2-tmp[0];
|
tmp[1] = x2 - tmp[0];
|
||||||
tmp[0]+=x2;
|
tmp[0] += x2;
|
||||||
temp=(pInVect[1]+pInVect[3]);
|
temp = (pInVect[1] + pInVect[3]);
|
||||||
SBC_IDCT_MULT((SBC_COS_3PI_SUR_8>>1), temp , tmp[3]);
|
SBC_IDCT_MULT((SBC_COS_3PI_SUR_8 >> 1), temp , tmp[3]);
|
||||||
SBC_IDCT_MULT((SBC_COS_PI_SUR_8>>1), temp , tmp[2]);
|
SBC_IDCT_MULT((SBC_COS_PI_SUR_8 >> 1), temp , tmp[2]);
|
||||||
temp=(pInVect[5]-pInVect[7]);
|
temp = (pInVect[5] - pInVect[7]);
|
||||||
SBC_IDCT_MULT((SBC_COS_3PI_SUR_8>>1), temp , tmp[5]);
|
SBC_IDCT_MULT((SBC_COS_3PI_SUR_8 >> 1), temp , tmp[5]);
|
||||||
SBC_IDCT_MULT((SBC_COS_PI_SUR_8>>1), temp , tmp[4]);
|
SBC_IDCT_MULT((SBC_COS_PI_SUR_8 >> 1), temp , tmp[4]);
|
||||||
tmp[6]=tmp[2]+tmp[5];
|
tmp[6] = tmp[2] + tmp[5];
|
||||||
tmp[7]=tmp[3]-tmp[4];
|
tmp[7] = tmp[3] - tmp[4];
|
||||||
pOutVect[0] = (tmp[0]+tmp[6]);
|
pOutVect[0] = (tmp[0] + tmp[6]);
|
||||||
pOutVect[1] = (tmp[1]+tmp[7]);
|
pOutVect[1] = (tmp[1] + tmp[7]);
|
||||||
pOutVect[2] = (tmp[1]-tmp[7]);
|
pOutVect[2] = (tmp[1] - tmp[7]);
|
||||||
pOutVect[3] = (tmp[0]-tmp[6]);
|
pOutVect[3] = (tmp[0] - tmp[6]);
|
||||||
#else
|
#else
|
||||||
UINT8 Index, k;
|
UINT8 Index, k;
|
||||||
SINT32 temp;
|
SINT32 temp;
|
||||||
/*Calculate 4 subband samples by matrixing*/
|
/*Calculate 4 subband samples by matrixing*/
|
||||||
for(Index=0; Index<4; Index++)
|
for (Index = 0; Index < 4; Index++) {
|
||||||
{
|
|
||||||
temp = 0;
|
temp = 0;
|
||||||
for(k=0; k<8; k++)
|
for (k = 0; k < 8; k++) {
|
||||||
{
|
|
||||||
/*temp += (SINT32)(((SINT64)M[(Index*strEncParams->numOfSubBands*2)+k] * Y[k]) >> 16 ); */
|
/*temp += (SINT32)(((SINT64)M[(Index*strEncParams->numOfSubBands*2)+k] * Y[k]) >> 16 ); */
|
||||||
temp += (gas16AnalDCTcoeff4[(Index*4*2)+k] * (pInVect[k] >> 16));
|
temp += (gas16AnalDCTcoeff4[(Index * 4 * 2) + k] * (pInVect[k] >> 16));
|
||||||
temp += ((gas16AnalDCTcoeff4[(Index*4*2)+k] * (pInVect[k] & 0xFFFF)) >> 16);
|
temp += ((gas16AnalDCTcoeff4[(Index * 4 * 2) + k] * (pInVect[k] & 0xFFFF)) >> 16);
|
||||||
}
|
}
|
||||||
pOutVect[Index] = temp;
|
pOutVect[Index] = temp;
|
||||||
}
|
}
|
||||||
|
326
examples/09_a2dp/components/bluedroid_demos/embdrv/sbc/encoder/srce/sbc_dct_coeffs.c
Executable file → Normal file
326
examples/09_a2dp/components/bluedroid_demos/embdrv/sbc/encoder/srce/sbc_dct_coeffs.c
Executable file → Normal file
@ -26,175 +26,173 @@
|
|||||||
#include "sbc_encoder.h"
|
#include "sbc_encoder.h"
|
||||||
/*DCT coeff for 4 sub-band case.*/
|
/*DCT coeff for 4 sub-band case.*/
|
||||||
#if (SBC_FAST_DCT == FALSE)
|
#if (SBC_FAST_DCT == FALSE)
|
||||||
const SINT16 gas16AnalDCTcoeff4[] =
|
const SINT16 gas16AnalDCTcoeff4[] = {
|
||||||
{
|
(SINT16)(0.7071 * 32768),
|
||||||
(SINT16)(0.7071*32768),
|
(SINT16)(0.9239 * 32768),
|
||||||
(SINT16)(0.9239*32768),
|
(SINT16)(1.0000 * 32767),
|
||||||
(SINT16)(1.0000*32767),
|
(SINT16)(0.9239 * 32768),
|
||||||
(SINT16)(0.9239*32768),
|
(SINT16)(0.7071 * 32768),
|
||||||
(SINT16)(0.7071*32768),
|
(SINT16)(0.3827 * 32768),
|
||||||
(SINT16)(0.3827*32768),
|
(SINT16)(0.0000 * 32768),
|
||||||
(SINT16)(0.0000*32768),
|
(SINT16)(-0.3827 * 32768),
|
||||||
(SINT16)(-0.3827*32768),
|
|
||||||
|
|
||||||
(SINT16)(-0.7071*32768),
|
(SINT16)(-0.7071 * 32768),
|
||||||
(SINT16)(0.3827*32768),
|
(SINT16)(0.3827 * 32768),
|
||||||
(SINT16)(1.0000*32767),
|
(SINT16)(1.0000 * 32767),
|
||||||
(SINT16)(0.3827*32768),
|
(SINT16)(0.3827 * 32768),
|
||||||
(SINT16)(-0.7071*32768),
|
(SINT16)(-0.7071 * 32768),
|
||||||
(SINT16)(-0.9239*32768),
|
(SINT16)(-0.9239 * 32768),
|
||||||
(SINT16)(-0.0000*32768),
|
(SINT16)(-0.0000 * 32768),
|
||||||
(SINT16)(0.9239*32768),
|
(SINT16)(0.9239 * 32768),
|
||||||
|
|
||||||
(SINT16)(-0.7071*32768),
|
(SINT16)(-0.7071 * 32768),
|
||||||
(SINT16)(-0.3827*32768),
|
(SINT16)(-0.3827 * 32768),
|
||||||
(SINT16)(1.0000*32767),
|
(SINT16)(1.0000 * 32767),
|
||||||
(SINT16)(-0.3827*32768),
|
(SINT16)(-0.3827 * 32768),
|
||||||
(SINT16)(-0.7071*32768),
|
(SINT16)(-0.7071 * 32768),
|
||||||
(SINT16)(0.9239*32768),
|
(SINT16)(0.9239 * 32768),
|
||||||
(SINT16)(0.0000*32768),
|
(SINT16)(0.0000 * 32768),
|
||||||
(SINT16)(-0.9239*32768),
|
(SINT16)(-0.9239 * 32768),
|
||||||
|
|
||||||
(SINT16)(0.7071*32768),
|
(SINT16)(0.7071 * 32768),
|
||||||
(SINT16)(-0.9239*32768),
|
(SINT16)(-0.9239 * 32768),
|
||||||
(SINT16)(1.0000*32767),
|
(SINT16)(1.0000 * 32767),
|
||||||
(SINT16)(-0.9239*32768),
|
(SINT16)(-0.9239 * 32768),
|
||||||
(SINT16)(0.7071*32768),
|
(SINT16)(0.7071 * 32768),
|
||||||
(SINT16)(-0.3827*32768),
|
(SINT16)(-0.3827 * 32768),
|
||||||
(SINT16)(-0.0000*32768),
|
(SINT16)(-0.0000 * 32768),
|
||||||
(SINT16)(0.3827*32768)
|
(SINT16)(0.3827 * 32768)
|
||||||
};
|
};
|
||||||
|
|
||||||
/*DCT coeff for 8 sub-band case.*/
|
/*DCT coeff for 8 sub-band case.*/
|
||||||
const SINT16 gas16AnalDCTcoeff8[] =
|
const SINT16 gas16AnalDCTcoeff8[] = {
|
||||||
{
|
(SINT16)(0.7071 * 32768),
|
||||||
(SINT16)(0.7071*32768),
|
(SINT16)(0.8315 * 32768),
|
||||||
(SINT16)(0.8315*32768),
|
(SINT16)(0.9239 * 32768),
|
||||||
(SINT16)(0.9239*32768),
|
(SINT16)(0.9808 * 32768),
|
||||||
(SINT16)(0.9808*32768),
|
(SINT16)(1.0000 * 32767),
|
||||||
(SINT16)(1.0000*32767),
|
(SINT16)(0.9808 * 32768),
|
||||||
(SINT16)(0.9808*32768),
|
(SINT16)(0.9239 * 32768),
|
||||||
(SINT16)(0.9239*32768),
|
(SINT16)(0.8315 * 32768),
|
||||||
(SINT16)(0.8315*32768),
|
(SINT16)(0.7071 * 32768),
|
||||||
(SINT16)(0.7071*32768),
|
(SINT16)(0.5556 * 32768),
|
||||||
(SINT16)(0.5556*32768),
|
(SINT16)(0.3827 * 32768),
|
||||||
(SINT16)(0.3827*32768),
|
(SINT16)(0.1951 * 32768),
|
||||||
(SINT16)(0.1951*32768),
|
(SINT16)(0.0000 * 32768),
|
||||||
(SINT16)(0.0000*32768),
|
(SINT16)(-0.1951 * 32768),
|
||||||
(SINT16)(-0.1951*32768),
|
(SINT16)(-0.3827 * 32768),
|
||||||
(SINT16)(-0.3827*32768),
|
(SINT16)(-0.5556 * 32768),
|
||||||
(SINT16)(-0.5556*32768),
|
(SINT16)(-0.7071 * 32768),
|
||||||
(SINT16)(-0.7071*32768),
|
(SINT16)(-0.1951 * 32768),
|
||||||
(SINT16)(-0.1951*32768),
|
(SINT16)(0.3827 * 32768),
|
||||||
(SINT16)(0.3827*32768),
|
(SINT16)(0.8315 * 32768),
|
||||||
(SINT16)(0.8315*32768),
|
(SINT16)(1.0000 * 32767),
|
||||||
(SINT16)(1.0000*32767),
|
(SINT16)(0.8315 * 32768),
|
||||||
(SINT16)(0.8315*32768),
|
(SINT16)(0.3827 * 32768),
|
||||||
(SINT16)(0.3827*32768),
|
(SINT16)(-0.1951 * 32768),
|
||||||
(SINT16)(-0.1951*32768),
|
(SINT16)(-0.7071 * 32768),
|
||||||
(SINT16)(-0.7071*32768),
|
(SINT16)(-0.9808 * 32768),
|
||||||
(SINT16)(-0.9808*32768),
|
(SINT16)(-0.9239 * 32768),
|
||||||
(SINT16)(-0.9239*32768),
|
(SINT16)(-0.5556 * 32768),
|
||||||
(SINT16)(-0.5556*32768),
|
(SINT16)(-0.0000 * 32768),
|
||||||
(SINT16)(-0.0000*32768),
|
(SINT16)(0.5556 * 32768),
|
||||||
(SINT16)(0.5556*32768),
|
(SINT16)(0.9239 * 32768),
|
||||||
(SINT16)(0.9239*32768),
|
(SINT16)(0.9808 * 32768),
|
||||||
(SINT16)(0.9808*32768),
|
(SINT16)(-0.7071 * 32768),
|
||||||
(SINT16)(-0.7071*32768),
|
(SINT16)(-0.9808 * 32768),
|
||||||
(SINT16)(-0.9808*32768),
|
(SINT16)(-0.3827 * 32768),
|
||||||
(SINT16)(-0.3827*32768),
|
(SINT16)(0.5556 * 32768),
|
||||||
(SINT16)(0.5556*32768),
|
(SINT16)(1.0000 * 32767),
|
||||||
(SINT16)(1.0000*32767),
|
(SINT16)(0.5556 * 32768),
|
||||||
(SINT16)(0.5556*32768),
|
(SINT16)(-0.3827 * 32768),
|
||||||
(SINT16)(-0.3827*32768),
|
(SINT16)(-0.9808 * 32768),
|
||||||
(SINT16)(-0.9808*32768),
|
(SINT16)(-0.7071 * 32768),
|
||||||
(SINT16)(-0.7071*32768),
|
(SINT16)(0.1951 * 32768),
|
||||||
(SINT16)(0.1951*32768),
|
(SINT16)(0.9239 * 32768),
|
||||||
(SINT16)(0.9239*32768),
|
(SINT16)(0.8315 * 32768),
|
||||||
(SINT16)(0.8315*32768),
|
(SINT16)(0.0000 * 32768),
|
||||||
(SINT16)(0.0000*32768),
|
(SINT16)(-0.8315 * 32768),
|
||||||
(SINT16)(-0.8315*32768),
|
(SINT16)(-0.9239 * 32768),
|
||||||
(SINT16)(-0.9239*32768),
|
(SINT16)(-0.1951 * 32768),
|
||||||
(SINT16)(-0.1951*32768),
|
(SINT16)(0.7071 * 32768),
|
||||||
(SINT16)(0.7071*32768),
|
(SINT16)(-0.5556 * 32768),
|
||||||
(SINT16)(-0.5556*32768),
|
(SINT16)(-0.9239 * 32768),
|
||||||
(SINT16)(-0.9239*32768),
|
(SINT16)(0.1951 * 32768),
|
||||||
(SINT16)(0.1951*32768),
|
(SINT16)(1.0000 * 32767),
|
||||||
(SINT16)(1.0000*32767),
|
(SINT16)(0.1951 * 32768),
|
||||||
(SINT16)(0.1951*32768),
|
(SINT16)(-0.9239 * 32768),
|
||||||
(SINT16)(-0.9239*32768),
|
(SINT16)(-0.5556 * 32768),
|
||||||
(SINT16)(-0.5556*32768),
|
(SINT16)(0.7071 * 32768),
|
||||||
(SINT16)(0.7071*32768),
|
(SINT16)(0.8315 * 32768),
|
||||||
(SINT16)(0.8315*32768),
|
(SINT16)(-0.3827 * 32768),
|
||||||
(SINT16)(-0.3827*32768),
|
(SINT16)(-0.9808 * 32768),
|
||||||
(SINT16)(-0.9808*32768),
|
(SINT16)(-0.0000 * 32768),
|
||||||
(SINT16)(-0.0000*32768),
|
(SINT16)(0.9808 * 32768),
|
||||||
(SINT16)(0.9808*32768),
|
(SINT16)(0.3827 * 32768),
|
||||||
(SINT16)(0.3827*32768),
|
(SINT16)(-0.8315 * 32768),
|
||||||
(SINT16)(-0.8315*32768),
|
(SINT16)(0.7071 * 32768),
|
||||||
(SINT16)(0.7071*32768),
|
(SINT16)(0.5556 * 32768),
|
||||||
(SINT16)(0.5556*32768),
|
(SINT16)(-0.9239 * 32768),
|
||||||
(SINT16)(-0.9239*32768),
|
(SINT16)(-0.1951 * 32768),
|
||||||
(SINT16)(-0.1951*32768),
|
(SINT16)(1.0000 * 32767),
|
||||||
(SINT16)(1.0000*32767),
|
(SINT16)(-0.1951 * 32768),
|
||||||
(SINT16)(-0.1951*32768),
|
(SINT16)(-0.9239 * 32768),
|
||||||
(SINT16)(-0.9239*32768),
|
(SINT16)(0.5556 * 32768),
|
||||||
(SINT16)(0.5556*32768),
|
(SINT16)(0.7071 * 32768),
|
||||||
(SINT16)(0.7071*32768),
|
(SINT16)(-0.8315 * 32768),
|
||||||
(SINT16)(-0.8315*32768),
|
(SINT16)(-0.3827 * 32768),
|
||||||
(SINT16)(-0.3827*32768),
|
(SINT16)(0.9808 * 32768),
|
||||||
(SINT16)(0.9808*32768),
|
(SINT16)(0.0000 * 32768),
|
||||||
(SINT16)(0.0000*32768),
|
(SINT16)(-0.9808 * 32768),
|
||||||
(SINT16)(-0.9808*32768),
|
(SINT16)(0.3827 * 32768),
|
||||||
(SINT16)(0.3827*32768),
|
(SINT16)(0.8315 * 32768),
|
||||||
(SINT16)(0.8315*32768),
|
(SINT16)(-0.7071 * 32768),
|
||||||
(SINT16)(-0.7071*32768),
|
(SINT16)(0.9808 * 32768),
|
||||||
(SINT16)(0.9808*32768),
|
(SINT16)(-0.3827 * 32768),
|
||||||
(SINT16)(-0.3827*32768),
|
(SINT16)(-0.5556 * 32768),
|
||||||
(SINT16)(-0.5556*32768),
|
(SINT16)(1.0000 * 32767),
|
||||||
(SINT16)(1.0000*32767),
|
(SINT16)(-0.5556 * 32768),
|
||||||
(SINT16)(-0.5556*32768),
|
(SINT16)(-0.3827 * 32768),
|
||||||
(SINT16)(-0.3827*32768),
|
(SINT16)(0.9808 * 32768),
|
||||||
(SINT16)(0.9808*32768),
|
(SINT16)(-0.7071 * 32768),
|
||||||
(SINT16)(-0.7071*32768),
|
(SINT16)(-0.1951 * 32768),
|
||||||
(SINT16)(-0.1951*32768),
|
(SINT16)(0.9239 * 32768),
|
||||||
(SINT16)(0.9239*32768),
|
(SINT16)(-0.8315 * 32768),
|
||||||
(SINT16)(-0.8315*32768),
|
(SINT16)(-0.0000 * 32768),
|
||||||
(SINT16)(-0.0000*32768),
|
(SINT16)(0.8315 * 32768),
|
||||||
(SINT16)(0.8315*32768),
|
(SINT16)(-0.9239 * 32768),
|
||||||
(SINT16)(-0.9239*32768),
|
(SINT16)(0.1951 * 32768),
|
||||||
(SINT16)(0.1951*32768),
|
(SINT16)(-0.7071 * 32768),
|
||||||
(SINT16)(-0.7071*32768),
|
(SINT16)(0.1951 * 32768),
|
||||||
(SINT16)(0.1951*32768),
|
(SINT16)(0.3827 * 32768),
|
||||||
(SINT16)(0.3827*32768),
|
(SINT16)(-0.8315 * 32768),
|
||||||
(SINT16)(-0.8315*32768),
|
(SINT16)(1.0000 * 32767),
|
||||||
(SINT16)(1.0000*32767),
|
(SINT16)(-0.8315 * 32768),
|
||||||
(SINT16)(-0.8315*32768),
|
(SINT16)(0.3827 * 32768),
|
||||||
(SINT16)(0.3827*32768),
|
(SINT16)(0.1951 * 32768),
|
||||||
(SINT16)(0.1951*32768),
|
(SINT16)(-0.7071 * 32768),
|
||||||
(SINT16)(-0.7071*32768),
|
(SINT16)(0.9808 * 32768),
|
||||||
(SINT16)(0.9808*32768),
|
(SINT16)(-0.9239 * 32768),
|
||||||
(SINT16)(-0.9239*32768),
|
(SINT16)(0.5556 * 32768),
|
||||||
(SINT16)(0.5556*32768),
|
(SINT16)(-0.0000 * 32768),
|
||||||
(SINT16)(-0.0000*32768),
|
(SINT16)(-0.5556 * 32768),
|
||||||
(SINT16)(-0.5556*32768),
|
(SINT16)(0.9239 * 32768),
|
||||||
(SINT16)(0.9239*32768),
|
(SINT16)(-0.9808 * 32768),
|
||||||
(SINT16)(-0.9808*32768),
|
(SINT16)(0.7071 * 32768),
|
||||||
(SINT16)(0.7071*32768),
|
(SINT16)(-0.8315 * 32768),
|
||||||
(SINT16)(-0.8315*32768),
|
(SINT16)(0.9239 * 32768),
|
||||||
(SINT16)(0.9239*32768),
|
(SINT16)(-0.9808 * 32768),
|
||||||
(SINT16)(-0.9808*32768),
|
(SINT16)(1.0000 * 32767),
|
||||||
(SINT16)(1.0000*32767),
|
(SINT16)(-0.9808 * 32768),
|
||||||
(SINT16)(-0.9808*32768),
|
(SINT16)(0.9239 * 32768),
|
||||||
(SINT16)(0.9239*32768),
|
(SINT16)(-0.8315 * 32768),
|
||||||
(SINT16)(-0.8315*32768),
|
(SINT16)(0.7071 * 32768),
|
||||||
(SINT16)(0.7071*32768),
|
(SINT16)(-0.5556 * 32768),
|
||||||
(SINT16)(-0.5556*32768),
|
(SINT16)(0.3827 * 32768),
|
||||||
(SINT16)(0.3827*32768),
|
(SINT16)(-0.1951 * 32768),
|
||||||
(SINT16)(-0.1951*32768),
|
(SINT16)(-0.0000 * 32768),
|
||||||
(SINT16)(-0.0000*32768),
|
(SINT16)(0.1951 * 32768),
|
||||||
(SINT16)(0.1951*32768),
|
(SINT16)(-0.3827 * 32768),
|
||||||
(SINT16)(-0.3827*32768),
|
(SINT16)(0.5556 * 32768)
|
||||||
(SINT16)(0.5556*32768)
|
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
136
examples/09_a2dp/components/bluedroid_demos/embdrv/sbc/encoder/srce/sbc_enc_bit_alloc_mono.c
Executable file → Normal file
136
examples/09_a2dp/components/bluedroid_demos/embdrv/sbc/encoder/srce/sbc_enc_bit_alloc_mono.c
Executable file → Normal file
@ -28,12 +28,14 @@
|
|||||||
#include "sbc_enc_func_declare.h"
|
#include "sbc_enc_func_declare.h"
|
||||||
|
|
||||||
/*global arrays*/
|
/*global arrays*/
|
||||||
const SINT16 sbc_enc_as16Offset4[4][4] = { {-1, 0, 0, 0}, {-2, 0, 0, 1},
|
const SINT16 sbc_enc_as16Offset4[4][4] = { { -1, 0, 0, 0}, { -2, 0, 0, 1},
|
||||||
{-2, 0, 0, 1}, {-2, 0, 0, 1} };
|
{ -2, 0, 0, 1}, { -2, 0, 0, 1}
|
||||||
const SINT16 sbc_enc_as16Offset8[4][8] = { {-2, 0, 0, 0, 0, 0, 0, 1},
|
};
|
||||||
{-3, 0, 0, 0, 0, 0, 1, 2},
|
const SINT16 sbc_enc_as16Offset8[4][8] = { { -2, 0, 0, 0, 0, 0, 0, 1},
|
||||||
{-4, 0, 0, 0, 0, 0, 1, 2},
|
{ -3, 0, 0, 0, 0, 0, 1, 2},
|
||||||
{-4, 0, 0, 0, 0, 0, 1, 2} };
|
{ -4, 0, 0, 0, 0, 0, 1, 2},
|
||||||
|
{ -4, 0, 0, 0, 0, 0, 1, 2}
|
||||||
|
};
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* BitAlloc - Calculates the required number of bits for the given scale factor
|
* BitAlloc - Calculates the required number of bits for the given scale factor
|
||||||
@ -59,43 +61,35 @@ void sbc_enc_bit_alloc_mono(SBC_ENC_PARAMS *pstrCodecParams)
|
|||||||
|
|
||||||
ps16BitNeed = pstrCodecParams->s16ScartchMemForBitAlloc;
|
ps16BitNeed = pstrCodecParams->s16ScartchMemForBitAlloc;
|
||||||
|
|
||||||
for (s32Ch = 0; s32Ch < pstrCodecParams->s16NumOfChannels; s32Ch++)
|
for (s32Ch = 0; s32Ch < pstrCodecParams->s16NumOfChannels; s32Ch++) {
|
||||||
{
|
ps16GenBufPtr = ps16BitNeed + s32Ch * s32NumOfSubBands;
|
||||||
ps16GenBufPtr = ps16BitNeed + s32Ch*s32NumOfSubBands;
|
ps16GenArrPtr = pstrCodecParams->as16Bits + s32Ch * SBC_MAX_NUM_OF_SUBBANDS;
|
||||||
ps16GenArrPtr = pstrCodecParams->as16Bits+s32Ch*SBC_MAX_NUM_OF_SUBBANDS;
|
|
||||||
|
|
||||||
/* bitneed values are derived from scale factor */
|
/* bitneed values are derived from scale factor */
|
||||||
if (pstrCodecParams->s16AllocationMethod == SBC_SNR)
|
if (pstrCodecParams->s16AllocationMethod == SBC_SNR) {
|
||||||
{
|
|
||||||
ps16BitNeed = pstrCodecParams->as16ScaleFactor;
|
ps16BitNeed = pstrCodecParams->as16ScaleFactor;
|
||||||
ps16GenBufPtr = ps16BitNeed + s32Ch * s32NumOfSubBands;
|
ps16GenBufPtr = ps16BitNeed + s32Ch * s32NumOfSubBands;
|
||||||
}
|
} else {
|
||||||
else
|
ps16GenBufPtr = ps16BitNeed + s32Ch * s32NumOfSubBands;
|
||||||
{
|
if (s32NumOfSubBands == 4) {
|
||||||
ps16GenBufPtr = ps16BitNeed + s32Ch*s32NumOfSubBands;
|
|
||||||
if(s32NumOfSubBands == 4)
|
|
||||||
{
|
|
||||||
ps16GenTabPtr = (SINT16 *)
|
ps16GenTabPtr = (SINT16 *)
|
||||||
sbc_enc_as16Offset4[pstrCodecParams->s16SamplingFreq];
|
sbc_enc_as16Offset4[pstrCodecParams->s16SamplingFreq];
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
ps16GenTabPtr = (SINT16 *)
|
ps16GenTabPtr = (SINT16 *)
|
||||||
sbc_enc_as16Offset8[pstrCodecParams->s16SamplingFreq];
|
sbc_enc_as16Offset8[pstrCodecParams->s16SamplingFreq];
|
||||||
}
|
}
|
||||||
for(s32Sb=0; s32Sb<s32NumOfSubBands; s32Sb++)
|
for (s32Sb = 0; s32Sb < s32NumOfSubBands; s32Sb++) {
|
||||||
{
|
if (pstrCodecParams->as16ScaleFactor[s32Ch * s32NumOfSubBands + s32Sb] == 0) {
|
||||||
if(pstrCodecParams->as16ScaleFactor[s32Ch*s32NumOfSubBands+s32Sb] == 0)
|
|
||||||
*(ps16GenBufPtr) = -5;
|
*(ps16GenBufPtr) = -5;
|
||||||
else
|
} else {
|
||||||
{
|
|
||||||
s32Loudness =
|
s32Loudness =
|
||||||
(SINT32)(pstrCodecParams->as16ScaleFactor[s32Ch*s32NumOfSubBands+s32Sb]
|
(SINT32)(pstrCodecParams->as16ScaleFactor[s32Ch * s32NumOfSubBands + s32Sb]
|
||||||
- *ps16GenTabPtr);
|
- *ps16GenTabPtr);
|
||||||
if(s32Loudness > 0)
|
if (s32Loudness > 0) {
|
||||||
*(ps16GenBufPtr) = (SINT16)(s32Loudness >>1);
|
*(ps16GenBufPtr) = (SINT16)(s32Loudness >> 1);
|
||||||
else
|
} else {
|
||||||
*(ps16GenBufPtr) = (SINT16)s32Loudness;
|
*(ps16GenBufPtr) = (SINT16)s32Loudness;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ps16GenBufPtr++;
|
ps16GenBufPtr++;
|
||||||
ps16GenTabPtr++;
|
ps16GenTabPtr++;
|
||||||
@ -105,74 +99,66 @@ void sbc_enc_bit_alloc_mono(SBC_ENC_PARAMS *pstrCodecParams)
|
|||||||
|
|
||||||
/* max bitneed index is searched*/
|
/* max bitneed index is searched*/
|
||||||
s32MaxBitNeed = 0;
|
s32MaxBitNeed = 0;
|
||||||
ps16GenBufPtr = ps16BitNeed + s32Ch*s32NumOfSubBands;
|
ps16GenBufPtr = ps16BitNeed + s32Ch * s32NumOfSubBands;
|
||||||
for(s32Sb=0; s32Sb<s32NumOfSubBands; s32Sb++)
|
for (s32Sb = 0; s32Sb < s32NumOfSubBands; s32Sb++) {
|
||||||
{
|
if ( *(ps16GenBufPtr) > s32MaxBitNeed) {
|
||||||
if( *(ps16GenBufPtr) > s32MaxBitNeed)
|
|
||||||
s32MaxBitNeed = *(ps16GenBufPtr);
|
s32MaxBitNeed = *(ps16GenBufPtr);
|
||||||
|
}
|
||||||
|
|
||||||
ps16GenBufPtr++;
|
ps16GenBufPtr++;
|
||||||
}
|
}
|
||||||
ps16GenBufPtr = ps16BitNeed + s32Ch*s32NumOfSubBands;
|
ps16GenBufPtr = ps16BitNeed + s32Ch * s32NumOfSubBands;
|
||||||
/*iterative process to find hwo many bitslices fit into the bitpool*/
|
/*iterative process to find hwo many bitslices fit into the bitpool*/
|
||||||
s32BitSlice = s32MaxBitNeed + 1;
|
s32BitSlice = s32MaxBitNeed + 1;
|
||||||
s32BitCount = pstrCodecParams->s16BitPool;
|
s32BitCount = pstrCodecParams->s16BitPool;
|
||||||
s32SliceCount = 0;
|
s32SliceCount = 0;
|
||||||
do
|
do {
|
||||||
{
|
|
||||||
s32BitSlice --;
|
s32BitSlice --;
|
||||||
s32BitCount -= s32SliceCount;
|
s32BitCount -= s32SliceCount;
|
||||||
s32SliceCount = 0;
|
s32SliceCount = 0;
|
||||||
|
|
||||||
for(s32Sb=0; s32Sb<s32NumOfSubBands; s32Sb++)
|
for (s32Sb = 0; s32Sb < s32NumOfSubBands; s32Sb++) {
|
||||||
{
|
if ( (((*ps16GenBufPtr - s32BitSlice) < 16) && (*ps16GenBufPtr - s32BitSlice) >= 1)) {
|
||||||
if( (((*ps16GenBufPtr-s32BitSlice)< 16) && (*ps16GenBufPtr-s32BitSlice) >= 1))
|
if ((*ps16GenBufPtr - s32BitSlice) == 1) {
|
||||||
{
|
s32SliceCount += 2;
|
||||||
if((*ps16GenBufPtr-s32BitSlice) == 1)
|
} else {
|
||||||
s32SliceCount+=2;
|
|
||||||
else
|
|
||||||
s32SliceCount++;
|
s32SliceCount++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ps16GenBufPtr++;
|
ps16GenBufPtr++;
|
||||||
|
|
||||||
}/*end of for*/
|
}/*end of for*/
|
||||||
ps16GenBufPtr = ps16BitNeed + s32Ch*s32NumOfSubBands;
|
ps16GenBufPtr = ps16BitNeed + s32Ch * s32NumOfSubBands;
|
||||||
}while(s32BitCount-s32SliceCount>0);
|
} while (s32BitCount - s32SliceCount > 0);
|
||||||
|
|
||||||
if(s32BitCount == 0)
|
if (s32BitCount == 0) {
|
||||||
{
|
|
||||||
s32BitCount -= s32SliceCount;
|
s32BitCount -= s32SliceCount;
|
||||||
s32BitSlice --;
|
s32BitSlice --;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*Bits are distributed until the last bitslice is reached*/
|
/*Bits are distributed until the last bitslice is reached*/
|
||||||
ps16GenArrPtr = pstrCodecParams->as16Bits+s32Ch*s32NumOfSubBands;
|
ps16GenArrPtr = pstrCodecParams->as16Bits + s32Ch * s32NumOfSubBands;
|
||||||
ps16GenBufPtr = ps16BitNeed + s32Ch*s32NumOfSubBands;
|
ps16GenBufPtr = ps16BitNeed + s32Ch * s32NumOfSubBands;
|
||||||
for(s32Sb=0; s32Sb<s32NumOfSubBands; s32Sb++)
|
for (s32Sb = 0; s32Sb < s32NumOfSubBands; s32Sb++) {
|
||||||
{
|
if (*(ps16GenBufPtr) < s32BitSlice + 2) {
|
||||||
if(*(ps16GenBufPtr) < s32BitSlice+2)
|
|
||||||
*(ps16GenArrPtr) = 0;
|
*(ps16GenArrPtr) = 0;
|
||||||
else
|
} else
|
||||||
*(ps16GenArrPtr) = ((*(ps16GenBufPtr)-s32BitSlice)<16) ?
|
*(ps16GenArrPtr) = ((*(ps16GenBufPtr) - s32BitSlice) < 16) ?
|
||||||
(SINT16)(*(ps16GenBufPtr)-s32BitSlice) : 16;
|
(SINT16)(*(ps16GenBufPtr) - s32BitSlice) : 16;
|
||||||
|
|
||||||
ps16GenBufPtr++;
|
ps16GenBufPtr++;
|
||||||
ps16GenArrPtr++;
|
ps16GenArrPtr++;
|
||||||
}
|
}
|
||||||
ps16GenArrPtr = pstrCodecParams->as16Bits+s32Ch*s32NumOfSubBands;
|
ps16GenArrPtr = pstrCodecParams->as16Bits + s32Ch * s32NumOfSubBands;
|
||||||
ps16GenBufPtr = ps16BitNeed + s32Ch*s32NumOfSubBands;
|
ps16GenBufPtr = ps16BitNeed + s32Ch * s32NumOfSubBands;
|
||||||
/*the remaining bits are allocated starting at subband 0*/
|
/*the remaining bits are allocated starting at subband 0*/
|
||||||
s32Sb=0;
|
s32Sb = 0;
|
||||||
while( (s32BitCount > 0) && (s32Sb < s32NumOfSubBands) )
|
while ( (s32BitCount > 0) && (s32Sb < s32NumOfSubBands) ) {
|
||||||
{
|
if ( (*(ps16GenArrPtr) >= 2) && (*(ps16GenArrPtr) < 16) ) {
|
||||||
if( (*(ps16GenArrPtr) >= 2) && (*(ps16GenArrPtr) < 16) )
|
|
||||||
{
|
|
||||||
(*(ps16GenArrPtr))++;
|
(*(ps16GenArrPtr))++;
|
||||||
s32BitCount--;
|
s32BitCount--;
|
||||||
}
|
} else if ( (*(ps16GenBufPtr) == s32BitSlice + 1) &&
|
||||||
else if( (*(ps16GenBufPtr) == s32BitSlice+1) &&
|
(s32BitCount > 1) ) {
|
||||||
(s32BitCount > 1) )
|
|
||||||
{
|
|
||||||
*(ps16GenArrPtr) = 2;
|
*(ps16GenArrPtr) = 2;
|
||||||
s32BitCount -= 2;
|
s32BitCount -= 2;
|
||||||
}
|
}
|
||||||
@ -180,14 +166,12 @@ void sbc_enc_bit_alloc_mono(SBC_ENC_PARAMS *pstrCodecParams)
|
|||||||
ps16GenArrPtr++;
|
ps16GenArrPtr++;
|
||||||
ps16GenBufPtr++;
|
ps16GenBufPtr++;
|
||||||
}
|
}
|
||||||
ps16GenArrPtr = pstrCodecParams->as16Bits+s32Ch*s32NumOfSubBands;
|
ps16GenArrPtr = pstrCodecParams->as16Bits + s32Ch * s32NumOfSubBands;
|
||||||
|
|
||||||
|
|
||||||
s32Sb=0;
|
s32Sb = 0;
|
||||||
while( (s32BitCount > 0) && (s32Sb < s32NumOfSubBands) )
|
while ( (s32BitCount > 0) && (s32Sb < s32NumOfSubBands) ) {
|
||||||
{
|
if ( *(ps16GenArrPtr) < 16) {
|
||||||
if( *(ps16GenArrPtr) < 16)
|
|
||||||
{
|
|
||||||
(*(ps16GenArrPtr))++;
|
(*(ps16GenArrPtr))++;
|
||||||
s32BitCount--;
|
s32BitCount--;
|
||||||
}
|
}
|
||||||
|
128
examples/09_a2dp/components/bluedroid_demos/embdrv/sbc/encoder/srce/sbc_enc_bit_alloc_ste.c
Executable file → Normal file
128
examples/09_a2dp/components/bluedroid_demos/embdrv/sbc/encoder/srce/sbc_enc_bit_alloc_ste.c
Executable file → Normal file
@ -40,8 +40,8 @@ extern const SINT16 sbc_enc_as16Offset8[4][8];
|
|||||||
|
|
||||||
void sbc_enc_bit_alloc_ste(SBC_ENC_PARAMS *pstrCodecParams)
|
void sbc_enc_bit_alloc_ste(SBC_ENC_PARAMS *pstrCodecParams)
|
||||||
{
|
{
|
||||||
/* CAUTIOM -> mips optim for arm 32 require to use SINT32 instead of SINT16 */
|
/* CAUTIOM -> mips optim for arm 32 require to use SINT32 instead of SINT16 */
|
||||||
/* Do not change variable type or name */
|
/* Do not change variable type or name */
|
||||||
SINT32 s32MaxBitNeed; /*to store the max bits needed per sb*/
|
SINT32 s32MaxBitNeed; /*to store the max bits needed per sb*/
|
||||||
SINT32 s32BitCount; /*the used number of bits*/
|
SINT32 s32BitCount; /*the used number of bits*/
|
||||||
SINT32 s32SliceCount; /*to store hwo many slices can be put in bitpool*/
|
SINT32 s32SliceCount; /*to store hwo many slices can be put in bitpool*/
|
||||||
@ -50,51 +50,44 @@ void sbc_enc_bit_alloc_ste(SBC_ENC_PARAMS *pstrCodecParams)
|
|||||||
SINT32 s32Ch; /*counter for channel*/
|
SINT32 s32Ch; /*counter for channel*/
|
||||||
SINT16 *ps16BitNeed; /*temp memory to store required number of bits*/
|
SINT16 *ps16BitNeed; /*temp memory to store required number of bits*/
|
||||||
SINT32 s32Loudness; /*used in Loudness calculation*/
|
SINT32 s32Loudness; /*used in Loudness calculation*/
|
||||||
SINT16 *ps16GenBufPtr,*pas16ScaleFactor;
|
SINT16 *ps16GenBufPtr, *pas16ScaleFactor;
|
||||||
SINT16 *ps16GenArrPtr;
|
SINT16 *ps16GenArrPtr;
|
||||||
SINT16 *ps16GenTabPtr;
|
SINT16 *ps16GenTabPtr;
|
||||||
SINT32 s32NumOfSubBands = pstrCodecParams->s16NumOfSubBands;
|
SINT32 s32NumOfSubBands = pstrCodecParams->s16NumOfSubBands;
|
||||||
SINT32 s32BitPool = pstrCodecParams->s16BitPool;
|
SINT32 s32BitPool = pstrCodecParams->s16BitPool;
|
||||||
|
|
||||||
/* bitneed values are derived from scale factor */
|
/* bitneed values are derived from scale factor */
|
||||||
if (pstrCodecParams->s16AllocationMethod == SBC_SNR)
|
if (pstrCodecParams->s16AllocationMethod == SBC_SNR) {
|
||||||
{
|
|
||||||
ps16BitNeed = pstrCodecParams->as16ScaleFactor;
|
ps16BitNeed = pstrCodecParams->as16ScaleFactor;
|
||||||
s32MaxBitNeed = pstrCodecParams->s16MaxBitNeed;
|
s32MaxBitNeed = pstrCodecParams->s16MaxBitNeed;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
ps16BitNeed = pstrCodecParams->s16ScartchMemForBitAlloc;
|
ps16BitNeed = pstrCodecParams->s16ScartchMemForBitAlloc;
|
||||||
pas16ScaleFactor=pstrCodecParams->as16ScaleFactor;
|
pas16ScaleFactor = pstrCodecParams->as16ScaleFactor;
|
||||||
s32MaxBitNeed = 0;
|
s32MaxBitNeed = 0;
|
||||||
ps16GenBufPtr = ps16BitNeed;
|
ps16GenBufPtr = ps16BitNeed;
|
||||||
for (s32Ch = 0; s32Ch < 2; s32Ch++)
|
for (s32Ch = 0; s32Ch < 2; s32Ch++) {
|
||||||
{
|
if (s32NumOfSubBands == 4) {
|
||||||
if (s32NumOfSubBands == 4)
|
|
||||||
{
|
|
||||||
ps16GenTabPtr = (SINT16 *)sbc_enc_as16Offset4[pstrCodecParams->s16SamplingFreq];
|
ps16GenTabPtr = (SINT16 *)sbc_enc_as16Offset4[pstrCodecParams->s16SamplingFreq];
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
ps16GenTabPtr = (SINT16 *)sbc_enc_as16Offset8[pstrCodecParams->s16SamplingFreq];
|
ps16GenTabPtr = (SINT16 *)sbc_enc_as16Offset8[pstrCodecParams->s16SamplingFreq];
|
||||||
}
|
}
|
||||||
|
|
||||||
for (s32Sb = 0; s32Sb < s32NumOfSubBands; s32Sb++)
|
for (s32Sb = 0; s32Sb < s32NumOfSubBands; s32Sb++) {
|
||||||
{
|
if (*pas16ScaleFactor == 0) {
|
||||||
if (*pas16ScaleFactor == 0)
|
|
||||||
*ps16GenBufPtr = -5;
|
*ps16GenBufPtr = -5;
|
||||||
else
|
} else {
|
||||||
{
|
|
||||||
s32Loudness = (SINT32)(*pas16ScaleFactor - *ps16GenTabPtr);
|
s32Loudness = (SINT32)(*pas16ScaleFactor - *ps16GenTabPtr);
|
||||||
|
|
||||||
if (s32Loudness > 0)
|
if (s32Loudness > 0) {
|
||||||
*ps16GenBufPtr = (SINT16)(s32Loudness >> 1);
|
*ps16GenBufPtr = (SINT16)(s32Loudness >> 1);
|
||||||
else
|
} else {
|
||||||
*ps16GenBufPtr = (SINT16)s32Loudness;
|
*ps16GenBufPtr = (SINT16)s32Loudness;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*ps16GenBufPtr > s32MaxBitNeed)
|
if (*ps16GenBufPtr > s32MaxBitNeed) {
|
||||||
s32MaxBitNeed = *ps16GenBufPtr;
|
s32MaxBitNeed = *ps16GenBufPtr;
|
||||||
|
}
|
||||||
pas16ScaleFactor++;
|
pas16ScaleFactor++;
|
||||||
ps16GenBufPtr++;
|
ps16GenBufPtr++;
|
||||||
ps16GenTabPtr++;
|
ps16GenTabPtr++;
|
||||||
@ -106,28 +99,25 @@ void sbc_enc_bit_alloc_ste(SBC_ENC_PARAMS *pstrCodecParams)
|
|||||||
s32BitSlice = s32MaxBitNeed + 1;
|
s32BitSlice = s32MaxBitNeed + 1;
|
||||||
s32BitCount = s32BitPool;
|
s32BitCount = s32BitPool;
|
||||||
s32SliceCount = 0;
|
s32SliceCount = 0;
|
||||||
do
|
do {
|
||||||
{
|
|
||||||
s32BitSlice --;
|
s32BitSlice --;
|
||||||
s32BitCount -= s32SliceCount;
|
s32BitCount -= s32SliceCount;
|
||||||
s32SliceCount = 0;
|
s32SliceCount = 0;
|
||||||
ps16GenBufPtr = ps16BitNeed;
|
ps16GenBufPtr = ps16BitNeed;
|
||||||
|
|
||||||
for (s32Sb = 0; s32Sb < 2*s32NumOfSubBands; s32Sb++)
|
for (s32Sb = 0; s32Sb < 2 * s32NumOfSubBands; s32Sb++) {
|
||||||
{
|
if ( (*ps16GenBufPtr >= s32BitSlice + 1) && (*ps16GenBufPtr < s32BitSlice + 16) ) {
|
||||||
if ( (*ps16GenBufPtr >= s32BitSlice + 1) && (*ps16GenBufPtr < s32BitSlice + 16) )
|
if (*(ps16GenBufPtr) == s32BitSlice + 1) {
|
||||||
{
|
|
||||||
if (*(ps16GenBufPtr) == s32BitSlice+1)
|
|
||||||
s32SliceCount += 2;
|
s32SliceCount += 2;
|
||||||
else
|
} else {
|
||||||
s32SliceCount++;
|
s32SliceCount++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ps16GenBufPtr++;
|
ps16GenBufPtr++;
|
||||||
}
|
}
|
||||||
} while (s32BitCount-s32SliceCount>0);
|
} while (s32BitCount - s32SliceCount > 0);
|
||||||
|
|
||||||
if (s32BitCount-s32SliceCount == 0)
|
if (s32BitCount - s32SliceCount == 0) {
|
||||||
{
|
|
||||||
s32BitCount -= s32SliceCount;
|
s32BitCount -= s32SliceCount;
|
||||||
s32BitSlice --;
|
s32BitSlice --;
|
||||||
}
|
}
|
||||||
@ -135,75 +125,61 @@ void sbc_enc_bit_alloc_ste(SBC_ENC_PARAMS *pstrCodecParams)
|
|||||||
/* Bits are distributed until the last bitslice is reached */
|
/* Bits are distributed until the last bitslice is reached */
|
||||||
ps16GenBufPtr = ps16BitNeed;
|
ps16GenBufPtr = ps16BitNeed;
|
||||||
ps16GenArrPtr = pstrCodecParams->as16Bits;
|
ps16GenArrPtr = pstrCodecParams->as16Bits;
|
||||||
for (s32Ch = 0; s32Ch < 2; s32Ch++)
|
for (s32Ch = 0; s32Ch < 2; s32Ch++) {
|
||||||
{
|
for (s32Sb = 0; s32Sb < s32NumOfSubBands; s32Sb++) {
|
||||||
for (s32Sb = 0; s32Sb < s32NumOfSubBands; s32Sb++)
|
if (*ps16GenBufPtr < s32BitSlice + 2) {
|
||||||
{
|
|
||||||
if (*ps16GenBufPtr < s32BitSlice+2)
|
|
||||||
*ps16GenArrPtr = 0;
|
*ps16GenArrPtr = 0;
|
||||||
else
|
} else
|
||||||
*ps16GenArrPtr = ((*(ps16GenBufPtr)-s32BitSlice) < 16) ?
|
*ps16GenArrPtr = ((*(ps16GenBufPtr) - s32BitSlice) < 16) ?
|
||||||
(SINT16)(*(ps16GenBufPtr)-s32BitSlice):16;
|
(SINT16)(*(ps16GenBufPtr) - s32BitSlice) : 16;
|
||||||
ps16GenBufPtr++;
|
ps16GenBufPtr++;
|
||||||
ps16GenArrPtr++;
|
ps16GenArrPtr++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* the remaining bits are allocated starting at subband 0 */
|
/* the remaining bits are allocated starting at subband 0 */
|
||||||
s32Ch=0;
|
s32Ch = 0;
|
||||||
s32Sb=0;
|
s32Sb = 0;
|
||||||
ps16GenBufPtr = ps16BitNeed;
|
ps16GenBufPtr = ps16BitNeed;
|
||||||
ps16GenArrPtr -= 2*s32NumOfSubBands;
|
ps16GenArrPtr -= 2 * s32NumOfSubBands;
|
||||||
|
|
||||||
while ( (s32BitCount > 0) && (s32Sb < s32NumOfSubBands) )
|
while ( (s32BitCount > 0) && (s32Sb < s32NumOfSubBands) ) {
|
||||||
{
|
if ( (*(ps16GenArrPtr) >= 2) && (*(ps16GenArrPtr) < 16) ) {
|
||||||
if ( (*(ps16GenArrPtr) >= 2) && (*(ps16GenArrPtr) < 16) )
|
|
||||||
{
|
|
||||||
(*(ps16GenArrPtr))++;
|
(*(ps16GenArrPtr))++;
|
||||||
s32BitCount--;
|
s32BitCount--;
|
||||||
}
|
} else if ((*ps16GenBufPtr == s32BitSlice + 1) && (s32BitCount > 1)) {
|
||||||
else if ((*ps16GenBufPtr == s32BitSlice+1) && (s32BitCount > 1))
|
|
||||||
{
|
|
||||||
*(ps16GenArrPtr) = 2;
|
*(ps16GenArrPtr) = 2;
|
||||||
s32BitCount -= 2;
|
s32BitCount -= 2;
|
||||||
}
|
}
|
||||||
if(s32Ch == 1)
|
if (s32Ch == 1) {
|
||||||
{
|
|
||||||
s32Ch = 0;
|
s32Ch = 0;
|
||||||
s32Sb++;
|
s32Sb++;
|
||||||
ps16GenBufPtr = ps16BitNeed+s32Sb;
|
ps16GenBufPtr = ps16BitNeed + s32Sb;
|
||||||
ps16GenArrPtr = pstrCodecParams->as16Bits+s32Sb;
|
ps16GenArrPtr = pstrCodecParams->as16Bits + s32Sb;
|
||||||
|
|
||||||
}
|
} else {
|
||||||
else
|
s32Ch = 1;
|
||||||
{
|
ps16GenBufPtr = ps16BitNeed + s32NumOfSubBands + s32Sb;
|
||||||
s32Ch =1;
|
ps16GenArrPtr = pstrCodecParams->as16Bits + s32NumOfSubBands + s32Sb;
|
||||||
ps16GenBufPtr = ps16BitNeed+s32NumOfSubBands+s32Sb;
|
|
||||||
ps16GenArrPtr = pstrCodecParams->as16Bits+s32NumOfSubBands+s32Sb;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
s32Ch=0;
|
s32Ch = 0;
|
||||||
s32Sb=0;
|
s32Sb = 0;
|
||||||
ps16GenArrPtr = pstrCodecParams->as16Bits;
|
ps16GenArrPtr = pstrCodecParams->as16Bits;
|
||||||
|
|
||||||
while ((s32BitCount >0) && (s32Sb < s32NumOfSubBands))
|
while ((s32BitCount > 0) && (s32Sb < s32NumOfSubBands)) {
|
||||||
{
|
if (*(ps16GenArrPtr) < 16) {
|
||||||
if(*(ps16GenArrPtr) < 16)
|
|
||||||
{
|
|
||||||
(*(ps16GenArrPtr))++;
|
(*(ps16GenArrPtr))++;
|
||||||
s32BitCount--;
|
s32BitCount--;
|
||||||
}
|
}
|
||||||
if (s32Ch == 1)
|
if (s32Ch == 1) {
|
||||||
{
|
|
||||||
s32Ch = 0;
|
s32Ch = 0;
|
||||||
s32Sb++;
|
s32Sb++;
|
||||||
ps16GenArrPtr = pstrCodecParams->as16Bits+s32Sb;
|
ps16GenArrPtr = pstrCodecParams->as16Bits + s32Sb;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
s32Ch = 1;
|
s32Ch = 1;
|
||||||
ps16GenArrPtr = pstrCodecParams->as16Bits+s32NumOfSubBands+s32Sb;
|
ps16GenArrPtr = pstrCodecParams->as16Bits + s32NumOfSubBands + s32Sb;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
488
examples/09_a2dp/components/bluedroid_demos/embdrv/sbc/encoder/srce/sbc_enc_coeffs.c
Executable file → Normal file
488
examples/09_a2dp/components/bluedroid_demos/embdrv/sbc/encoder/srce/sbc_enc_coeffs.c
Executable file → Normal file
@ -27,291 +27,287 @@
|
|||||||
#if (SBC_ARM_ASM_OPT==FALSE && SBC_IPAQ_OPT==FALSE)
|
#if (SBC_ARM_ASM_OPT==FALSE && SBC_IPAQ_OPT==FALSE)
|
||||||
#if (SBC_IS_64_MULT_IN_WINDOW_ACCU == FALSE)
|
#if (SBC_IS_64_MULT_IN_WINDOW_ACCU == FALSE)
|
||||||
/*Window coeff for 4 sub band case*/
|
/*Window coeff for 4 sub band case*/
|
||||||
const SINT16 gas32CoeffFor4SBs[] =
|
const SINT16 gas32CoeffFor4SBs[] = {
|
||||||
{
|
(SINT16)((SINT32)0x00000000 >> 16), (SINT16)0x00000000,
|
||||||
(SINT16)((SINT32)0x00000000 >> 16), (SINT16)0x00000000,
|
(SINT16)((SINT32)0x001194E6 >> 16), (SINT16)0x001194E6,
|
||||||
(SINT16)((SINT32)0x001194E6 >> 16), (SINT16)0x001194E6,
|
(SINT16)((SINT32)0x0030E2D3 >> 16), (SINT16)0x0030E2D3,
|
||||||
(SINT16)((SINT32)0x0030E2D3 >> 16), (SINT16)0x0030E2D3,
|
(SINT16)((SINT32)0x00599403 >> 16), (SINT16)0x00599403,
|
||||||
(SINT16)((SINT32)0x00599403 >> 16), (SINT16)0x00599403,
|
(SINT16)((SINT32)0x007DBCC8 >> 16), (SINT16)0x007DBCC8,
|
||||||
(SINT16)((SINT32)0x007DBCC8 >> 16), (SINT16)0x007DBCC8,
|
(SINT16)((SINT32)0x007F88E4 >> 16), (SINT16)0x007F88E4,
|
||||||
(SINT16)((SINT32)0x007F88E4 >> 16), (SINT16)0x007F88E4,
|
(SINT16)((SINT32)0x003D239B >> 16), (SINT16)0x003D239B,
|
||||||
(SINT16)((SINT32)0x003D239B >> 16), (SINT16)0x003D239B,
|
(SINT16)((SINT32)0xFF9BB9D5 >> 16), (SINT16)0xFF9BB9D5,
|
||||||
(SINT16)((SINT32)0xFF9BB9D5 >> 16), (SINT16)0xFF9BB9D5,
|
|
||||||
|
|
||||||
(SINT16)((SINT32)0x01659F45 >> 16), (SINT16)0x01659F45,
|
(SINT16)((SINT32)0x01659F45 >> 16), (SINT16)0x01659F45,
|
||||||
(SINT16)((SINT32)0x029DBAA3 >> 16), (SINT16)0x029DBAA3,
|
(SINT16)((SINT32)0x029DBAA3 >> 16), (SINT16)0x029DBAA3,
|
||||||
(SINT16)((SINT32)0x03B23341 >> 16), (SINT16)0x03B23341,
|
(SINT16)((SINT32)0x03B23341 >> 16), (SINT16)0x03B23341,
|
||||||
(SINT16)((SINT32)0x041EEE40 >> 16), (SINT16)0x041EEE40,
|
(SINT16)((SINT32)0x041EEE40 >> 16), (SINT16)0x041EEE40,
|
||||||
(SINT16)((SINT32)0x034FEE2C >> 16), (SINT16)0x034FEE2C,
|
(SINT16)((SINT32)0x034FEE2C >> 16), (SINT16)0x034FEE2C,
|
||||||
(SINT16)((SINT32)0x00C8F2BC >> 16), (SINT16)0x00C8F2BC,
|
(SINT16)((SINT32)0x00C8F2BC >> 16), (SINT16)0x00C8F2BC,
|
||||||
(SINT16)((SINT32)0xFC4F91D4 >> 16), (SINT16)0xFC4F91D4,
|
(SINT16)((SINT32)0xFC4F91D4 >> 16), (SINT16)0xFC4F91D4,
|
||||||
(SINT16)((SINT32)0xF60FAF37 >> 16), (SINT16)0xF60FAF37,
|
(SINT16)((SINT32)0xF60FAF37 >> 16), (SINT16)0xF60FAF37,
|
||||||
|
|
||||||
(SINT16)((SINT32)0x115B1ED2 >> 16), (SINT16)0x115B1ED2,
|
(SINT16)((SINT32)0x115B1ED2 >> 16), (SINT16)0x115B1ED2,
|
||||||
(SINT16)((SINT32)0x18F55C90 >> 16), (SINT16)0x18F55C90,
|
(SINT16)((SINT32)0x18F55C90 >> 16), (SINT16)0x18F55C90,
|
||||||
(SINT16)((SINT32)0x1F91CA46 >> 16), (SINT16)0x1F91CA46,
|
(SINT16)((SINT32)0x1F91CA46 >> 16), (SINT16)0x1F91CA46,
|
||||||
(SINT16)((SINT32)0x2412F251 >> 16), (SINT16)0x2412F251,
|
(SINT16)((SINT32)0x2412F251 >> 16), (SINT16)0x2412F251,
|
||||||
(SINT16)((SINT32)0x25AC1FF2 >> 16), (SINT16)0x25AC1FF2,
|
(SINT16)((SINT32)0x25AC1FF2 >> 16), (SINT16)0x25AC1FF2,
|
||||||
(SINT16)((SINT32)0x2412F251 >> 16), (SINT16)0x2412F251,
|
(SINT16)((SINT32)0x2412F251 >> 16), (SINT16)0x2412F251,
|
||||||
(SINT16)((SINT32)0x1F91CA46 >> 16), (SINT16)0x1F91CA46,
|
(SINT16)((SINT32)0x1F91CA46 >> 16), (SINT16)0x1F91CA46,
|
||||||
(SINT16)((SINT32)0x18F55C90 >> 16), (SINT16)0x18F55C90,
|
(SINT16)((SINT32)0x18F55C90 >> 16), (SINT16)0x18F55C90,
|
||||||
|
|
||||||
(SINT16)((SINT32)0xEEA4E12E >> 16), (SINT16)0xEEA4E12E,
|
(SINT16)((SINT32)0xEEA4E12E >> 16), (SINT16)0xEEA4E12E,
|
||||||
(SINT16)((SINT32)0xF60FAF37 >> 16), (SINT16)0xF60FAF37,
|
(SINT16)((SINT32)0xF60FAF37 >> 16), (SINT16)0xF60FAF37,
|
||||||
(SINT16)((SINT32)0xFC4F91D4 >> 16), (SINT16)0xFC4F91D4,
|
(SINT16)((SINT32)0xFC4F91D4 >> 16), (SINT16)0xFC4F91D4,
|
||||||
(SINT16)((SINT32)0x00C8F2BC >> 16), (SINT16)0x00C8F2BC,
|
(SINT16)((SINT32)0x00C8F2BC >> 16), (SINT16)0x00C8F2BC,
|
||||||
(SINT16)((SINT32)0x034FEE2C >> 16), (SINT16)0x034FEE2C,
|
(SINT16)((SINT32)0x034FEE2C >> 16), (SINT16)0x034FEE2C,
|
||||||
(SINT16)((SINT32)0x041EEE40 >> 16), (SINT16)0x041EEE40,
|
(SINT16)((SINT32)0x041EEE40 >> 16), (SINT16)0x041EEE40,
|
||||||
(SINT16)((SINT32)0x03B23341 >> 16), (SINT16)0x03B23341,
|
(SINT16)((SINT32)0x03B23341 >> 16), (SINT16)0x03B23341,
|
||||||
(SINT16)((SINT32)0x029DBAA3 >> 16), (SINT16)0x029DBAA3,
|
(SINT16)((SINT32)0x029DBAA3 >> 16), (SINT16)0x029DBAA3,
|
||||||
|
|
||||||
(SINT16)((SINT32)0xFE9A60BB >> 16), (SINT16)0xFE9A60BB,
|
(SINT16)((SINT32)0xFE9A60BB >> 16), (SINT16)0xFE9A60BB,
|
||||||
(SINT16)((SINT32)0xFF9BB9D5 >> 16), (SINT16)0xFF9BB9D5,
|
(SINT16)((SINT32)0xFF9BB9D5 >> 16), (SINT16)0xFF9BB9D5,
|
||||||
(SINT16)((SINT32)0x003D239B >> 16), (SINT16)0x003D239B,
|
(SINT16)((SINT32)0x003D239B >> 16), (SINT16)0x003D239B,
|
||||||
(SINT16)((SINT32)0x007F88E4 >> 16), (SINT16)0x007F88E4,
|
(SINT16)((SINT32)0x007F88E4 >> 16), (SINT16)0x007F88E4,
|
||||||
(SINT16)((SINT32)0x007DBCC8 >> 16), (SINT16)0x007DBCC8,
|
(SINT16)((SINT32)0x007DBCC8 >> 16), (SINT16)0x007DBCC8,
|
||||||
(SINT16)((SINT32)0x00599403 >> 16), (SINT16)0x00599403,
|
(SINT16)((SINT32)0x00599403 >> 16), (SINT16)0x00599403,
|
||||||
(SINT16)((SINT32)0x0030E2D3 >> 16), (SINT16)0x0030E2D3,
|
(SINT16)((SINT32)0x0030E2D3 >> 16), (SINT16)0x0030E2D3,
|
||||||
(SINT16)((SINT32)0x001194E6 >> 16), (SINT16)0x001194E6
|
(SINT16)((SINT32)0x001194E6 >> 16), (SINT16)0x001194E6
|
||||||
};
|
};
|
||||||
|
|
||||||
/*Window coeff for 8 sub band case*/
|
/*Window coeff for 8 sub band case*/
|
||||||
const SINT16 gas32CoeffFor8SBs[] =
|
const SINT16 gas32CoeffFor8SBs[] = {
|
||||||
{
|
(SINT16)((SINT32)0x00000000 >> 16), (SINT16)0x00000000,
|
||||||
(SINT16)((SINT32)0x00000000 >>16), (SINT16)0x00000000,
|
(SINT16)((SINT32)0x00052173 >> 16), (SINT16)0x00052173,
|
||||||
(SINT16)((SINT32)0x00052173 >>16), (SINT16)0x00052173,
|
(SINT16)((SINT32)0x000B3F71 >> 16), (SINT16)0x000B3F71,
|
||||||
(SINT16)((SINT32)0x000B3F71 >>16), (SINT16)0x000B3F71,
|
(SINT16)((SINT32)0x00122C7D >> 16), (SINT16)0x00122C7D,
|
||||||
(SINT16)((SINT32)0x00122C7D >>16), (SINT16)0x00122C7D,
|
(SINT16)((SINT32)0x001AFF89 >> 16), (SINT16)0x001AFF89,
|
||||||
(SINT16)((SINT32)0x001AFF89 >>16), (SINT16)0x001AFF89,
|
(SINT16)((SINT32)0x00255A62 >> 16), (SINT16)0x00255A62,
|
||||||
(SINT16)((SINT32)0x00255A62 >>16), (SINT16)0x00255A62,
|
(SINT16)((SINT32)0x003060F4 >> 16), (SINT16)0x003060F4,
|
||||||
(SINT16)((SINT32)0x003060F4 >>16), (SINT16)0x003060F4,
|
(SINT16)((SINT32)0x003A72E7 >> 16), (SINT16)0x003A72E7,
|
||||||
(SINT16)((SINT32)0x003A72E7 >>16), (SINT16)0x003A72E7,
|
|
||||||
|
|
||||||
(SINT16)((SINT32)0x0041EC6A >>16), (SINT16)0x0041EC6A, /* 8 */
|
(SINT16)((SINT32)0x0041EC6A >> 16), (SINT16)0x0041EC6A, /* 8 */
|
||||||
(SINT16)((SINT32)0x0044EF48 >>16), (SINT16)0x0044EF48,
|
(SINT16)((SINT32)0x0044EF48 >> 16), (SINT16)0x0044EF48,
|
||||||
(SINT16)((SINT32)0x00415B75 >>16), (SINT16)0x00415B75,
|
(SINT16)((SINT32)0x00415B75 >> 16), (SINT16)0x00415B75,
|
||||||
(SINT16)((SINT32)0x0034F8B6 >>16), (SINT16)0x0034F8B6,
|
(SINT16)((SINT32)0x0034F8B6 >> 16), (SINT16)0x0034F8B6,
|
||||||
(SINT16)((SINT32)0x001D8FD2 >>16), (SINT16)0x001D8FD2,
|
(SINT16)((SINT32)0x001D8FD2 >> 16), (SINT16)0x001D8FD2,
|
||||||
(SINT16)((SINT32)0xFFFA2413 >>16), (SINT16)0xFFFA2413,
|
(SINT16)((SINT32)0xFFFA2413 >> 16), (SINT16)0xFFFA2413,
|
||||||
(SINT16)((SINT32)0xFFC9F10E >>16), (SINT16)0xFFC9F10E,
|
(SINT16)((SINT32)0xFFC9F10E >> 16), (SINT16)0xFFC9F10E,
|
||||||
(SINT16)((SINT32)0xFF8D6793 >>16), (SINT16)0xFF8D6793,
|
(SINT16)((SINT32)0xFF8D6793 >> 16), (SINT16)0xFF8D6793,
|
||||||
|
|
||||||
(SINT16)((SINT32)0x00B97348 >>16), (SINT16)0x00B97348, /* 16 */
|
(SINT16)((SINT32)0x00B97348 >> 16), (SINT16)0x00B97348, /* 16 */
|
||||||
(SINT16)((SINT32)0x01071B96 >>16), (SINT16)0x01071B96,
|
(SINT16)((SINT32)0x01071B96 >> 16), (SINT16)0x01071B96,
|
||||||
(SINT16)((SINT32)0x0156B3CA >>16), (SINT16)0x0156B3CA,
|
(SINT16)((SINT32)0x0156B3CA >> 16), (SINT16)0x0156B3CA,
|
||||||
(SINT16)((SINT32)0x01A1B38B >>16), (SINT16)0x01A1B38B,
|
(SINT16)((SINT32)0x01A1B38B >> 16), (SINT16)0x01A1B38B,
|
||||||
(SINT16)((SINT32)0x01E0224C >>16), (SINT16)0x01E0224C,
|
(SINT16)((SINT32)0x01E0224C >> 16), (SINT16)0x01E0224C,
|
||||||
(SINT16)((SINT32)0x0209291F >>16), (SINT16)0x0209291F,
|
(SINT16)((SINT32)0x0209291F >> 16), (SINT16)0x0209291F,
|
||||||
(SINT16)((SINT32)0x02138653 >>16), (SINT16)0x02138653,
|
(SINT16)((SINT32)0x02138653 >> 16), (SINT16)0x02138653,
|
||||||
(SINT16)((SINT32)0x01F5F424 >>16), (SINT16)0x01F5F424,
|
(SINT16)((SINT32)0x01F5F424 >> 16), (SINT16)0x01F5F424,
|
||||||
|
|
||||||
(SINT16)((SINT32)0x01A7ECEF >>16), (SINT16)0x01A7ECEF, /* 24 */
|
(SINT16)((SINT32)0x01A7ECEF >> 16), (SINT16)0x01A7ECEF, /* 24 */
|
||||||
(SINT16)((SINT32)0x01223EBA >>16), (SINT16)0x01223EBA,
|
(SINT16)((SINT32)0x01223EBA >> 16), (SINT16)0x01223EBA,
|
||||||
(SINT16)((SINT32)0x005FD0FF >>16), (SINT16)0x005FD0FF,
|
(SINT16)((SINT32)0x005FD0FF >> 16), (SINT16)0x005FD0FF,
|
||||||
(SINT16)((SINT32)0xFF5EEB73 >>16), (SINT16)0xFF5EEB73,
|
(SINT16)((SINT32)0xFF5EEB73 >> 16), (SINT16)0xFF5EEB73,
|
||||||
(SINT16)((SINT32)0xFE20435D >>16), (SINT16)0xFE20435D,
|
(SINT16)((SINT32)0xFE20435D >> 16), (SINT16)0xFE20435D,
|
||||||
(SINT16)((SINT32)0xFCA86E7E >>16), (SINT16)0xFCA86E7E,
|
(SINT16)((SINT32)0xFCA86E7E >> 16), (SINT16)0xFCA86E7E,
|
||||||
(SINT16)((SINT32)0xFAFF95FC >>16), (SINT16)0xFAFF95FC,
|
(SINT16)((SINT32)0xFAFF95FC >> 16), (SINT16)0xFAFF95FC,
|
||||||
(SINT16)((SINT32)0xF9312891 >>16), (SINT16)0xF9312891,
|
(SINT16)((SINT32)0xF9312891 >> 16), (SINT16)0xF9312891,
|
||||||
|
|
||||||
(SINT16)((SINT32)0x08B4307A >>16), (SINT16)0x08B4307A, /* 32 */
|
(SINT16)((SINT32)0x08B4307A >> 16), (SINT16)0x08B4307A, /* 32 */
|
||||||
(SINT16)((SINT32)0x0A9F3E9A >>16), (SINT16)0x0A9F3E9A,
|
(SINT16)((SINT32)0x0A9F3E9A >> 16), (SINT16)0x0A9F3E9A,
|
||||||
(SINT16)((SINT32)0x0C7D59B6 >>16), (SINT16)0x0C7D59B6,
|
(SINT16)((SINT32)0x0C7D59B6 >> 16), (SINT16)0x0C7D59B6,
|
||||||
(SINT16)((SINT32)0x0E3BB16F >>16), (SINT16)0x0E3BB16F,
|
(SINT16)((SINT32)0x0E3BB16F >> 16), (SINT16)0x0E3BB16F,
|
||||||
(SINT16)((SINT32)0x0FC721F9 >>16), (SINT16)0x0FC721F9,
|
(SINT16)((SINT32)0x0FC721F9 >> 16), (SINT16)0x0FC721F9,
|
||||||
(SINT16)((SINT32)0x110ECEF0 >>16), (SINT16)0x110ECEF0,
|
(SINT16)((SINT32)0x110ECEF0 >> 16), (SINT16)0x110ECEF0,
|
||||||
(SINT16)((SINT32)0x120435FA >>16), (SINT16)0x120435FA,
|
(SINT16)((SINT32)0x120435FA >> 16), (SINT16)0x120435FA,
|
||||||
(SINT16)((SINT32)0x129C226F >>16), (SINT16)0x129C226F,
|
(SINT16)((SINT32)0x129C226F >> 16), (SINT16)0x129C226F,
|
||||||
|
|
||||||
(SINT16)((SINT32)0x12CF6C75 >>16), (SINT16)0x12CF6C75, /* 40 */
|
(SINT16)((SINT32)0x12CF6C75 >> 16), (SINT16)0x12CF6C75, /* 40 */
|
||||||
(SINT16)((SINT32)0x129C226F >>16), (SINT16)0x129C226F,
|
(SINT16)((SINT32)0x129C226F >> 16), (SINT16)0x129C226F,
|
||||||
(SINT16)((SINT32)0x120435FA >>16), (SINT16)0x120435FA,
|
(SINT16)((SINT32)0x120435FA >> 16), (SINT16)0x120435FA,
|
||||||
(SINT16)((SINT32)0x110ECEF0 >>16), (SINT16)0x110ECEF0,
|
(SINT16)((SINT32)0x110ECEF0 >> 16), (SINT16)0x110ECEF0,
|
||||||
(SINT16)((SINT32)0x0FC721F9 >>16), (SINT16)0x0FC721F9,
|
(SINT16)((SINT32)0x0FC721F9 >> 16), (SINT16)0x0FC721F9,
|
||||||
(SINT16)((SINT32)0x0E3BB16F >>16), (SINT16)0x0E3BB16F,
|
(SINT16)((SINT32)0x0E3BB16F >> 16), (SINT16)0x0E3BB16F,
|
||||||
(SINT16)((SINT32)0x0C7D59B6 >>16), (SINT16)0x0C7D59B6,
|
(SINT16)((SINT32)0x0C7D59B6 >> 16), (SINT16)0x0C7D59B6,
|
||||||
(SINT16)((SINT32)0x0A9F3E9A >>16), (SINT16)0x0A9F3E9A,
|
(SINT16)((SINT32)0x0A9F3E9A >> 16), (SINT16)0x0A9F3E9A,
|
||||||
|
|
||||||
(SINT16)((SINT32)0xF74BCF86 >>16), (SINT16)0xF74BCF86, /* 48 */
|
(SINT16)((SINT32)0xF74BCF86 >> 16), (SINT16)0xF74BCF86, /* 48 */
|
||||||
(SINT16)((SINT32)0xF9312891 >>16), (SINT16)0xF9312891,
|
(SINT16)((SINT32)0xF9312891 >> 16), (SINT16)0xF9312891,
|
||||||
(SINT16)((SINT32)0xFAFF95FC >>16), (SINT16)0xFAFF95FC,
|
(SINT16)((SINT32)0xFAFF95FC >> 16), (SINT16)0xFAFF95FC,
|
||||||
(SINT16)((SINT32)0xFCA86E7E >>16), (SINT16)0xFCA86E7E,
|
(SINT16)((SINT32)0xFCA86E7E >> 16), (SINT16)0xFCA86E7E,
|
||||||
(SINT16)((SINT32)0xFE20435D >>16), (SINT16)0xFE20435D,
|
(SINT16)((SINT32)0xFE20435D >> 16), (SINT16)0xFE20435D,
|
||||||
(SINT16)((SINT32)0xFF5EEB73 >>16), (SINT16)0xFF5EEB73,
|
(SINT16)((SINT32)0xFF5EEB73 >> 16), (SINT16)0xFF5EEB73,
|
||||||
(SINT16)((SINT32)0x005FD0FF >>16), (SINT16)0x005FD0FF,
|
(SINT16)((SINT32)0x005FD0FF >> 16), (SINT16)0x005FD0FF,
|
||||||
(SINT16)((SINT32)0x01223EBA >>16), (SINT16)0x01223EBA,
|
(SINT16)((SINT32)0x01223EBA >> 16), (SINT16)0x01223EBA,
|
||||||
|
|
||||||
(SINT16)((SINT32)0x01A7ECEF >>16), (SINT16)0x01A7ECEF, /* 56 */
|
(SINT16)((SINT32)0x01A7ECEF >> 16), (SINT16)0x01A7ECEF, /* 56 */
|
||||||
(SINT16)((SINT32)0x01F5F424 >>16), (SINT16)0x01F5F424,
|
(SINT16)((SINT32)0x01F5F424 >> 16), (SINT16)0x01F5F424,
|
||||||
(SINT16)((SINT32)0x02138653 >>16), (SINT16)0x02138653,
|
(SINT16)((SINT32)0x02138653 >> 16), (SINT16)0x02138653,
|
||||||
(SINT16)((SINT32)0x0209291F >>16), (SINT16)0x0209291F,
|
(SINT16)((SINT32)0x0209291F >> 16), (SINT16)0x0209291F,
|
||||||
(SINT16)((SINT32)0x01E0224C >>16), (SINT16)0x01E0224C,
|
(SINT16)((SINT32)0x01E0224C >> 16), (SINT16)0x01E0224C,
|
||||||
(SINT16)((SINT32)0x01A1B38B >>16), (SINT16)0x01A1B38B,
|
(SINT16)((SINT32)0x01A1B38B >> 16), (SINT16)0x01A1B38B,
|
||||||
(SINT16)((SINT32)0x0156B3CA >>16), (SINT16)0x0156B3CA,
|
(SINT16)((SINT32)0x0156B3CA >> 16), (SINT16)0x0156B3CA,
|
||||||
(SINT16)((SINT32)0x01071B96 >>16), (SINT16)0x01071B96,
|
(SINT16)((SINT32)0x01071B96 >> 16), (SINT16)0x01071B96,
|
||||||
|
|
||||||
(SINT16)((SINT32)0xFF468CB8 >>16), (SINT16)0xFF468CB8, /* 64 */
|
(SINT16)((SINT32)0xFF468CB8 >> 16), (SINT16)0xFF468CB8, /* 64 */
|
||||||
(SINT16)((SINT32)0xFF8D6793 >>16), (SINT16)0xFF8D6793,
|
(SINT16)((SINT32)0xFF8D6793 >> 16), (SINT16)0xFF8D6793,
|
||||||
(SINT16)((SINT32)0xFFC9F10E >>16), (SINT16)0xFFC9F10E,
|
(SINT16)((SINT32)0xFFC9F10E >> 16), (SINT16)0xFFC9F10E,
|
||||||
(SINT16)((SINT32)0xFFFA2413 >>16), (SINT16)0xFFFA2413,
|
(SINT16)((SINT32)0xFFFA2413 >> 16), (SINT16)0xFFFA2413,
|
||||||
(SINT16)((SINT32)0x001D8FD2 >>16), (SINT16)0x001D8FD2,
|
(SINT16)((SINT32)0x001D8FD2 >> 16), (SINT16)0x001D8FD2,
|
||||||
(SINT16)((SINT32)0x0034F8B6 >>16), (SINT16)0x0034F8B6,
|
(SINT16)((SINT32)0x0034F8B6 >> 16), (SINT16)0x0034F8B6,
|
||||||
(SINT16)((SINT32)0x00415B75 >>16), (SINT16)0x00415B75,
|
(SINT16)((SINT32)0x00415B75 >> 16), (SINT16)0x00415B75,
|
||||||
(SINT16)((SINT32)0x0044EF48 >>16), (SINT16)0x0044EF48,
|
(SINT16)((SINT32)0x0044EF48 >> 16), (SINT16)0x0044EF48,
|
||||||
|
|
||||||
(SINT16)((SINT32)0x0041EC6A >>16), (SINT16)0x0041EC6A, /* 72 */
|
(SINT16)((SINT32)0x0041EC6A >> 16), (SINT16)0x0041EC6A, /* 72 */
|
||||||
(SINT16)((SINT32)0x003A72E7 >>16), (SINT16)0x003A72E7,
|
(SINT16)((SINT32)0x003A72E7 >> 16), (SINT16)0x003A72E7,
|
||||||
(SINT16)((SINT32)0x003060F4 >>16), (SINT16)0x003060F4,
|
(SINT16)((SINT32)0x003060F4 >> 16), (SINT16)0x003060F4,
|
||||||
(SINT16)((SINT32)0x00255A62 >>16), (SINT16)0x00255A62,
|
(SINT16)((SINT32)0x00255A62 >> 16), (SINT16)0x00255A62,
|
||||||
(SINT16)((SINT32)0x001AFF89 >>16), (SINT16)0x001AFF89,
|
(SINT16)((SINT32)0x001AFF89 >> 16), (SINT16)0x001AFF89,
|
||||||
(SINT16)((SINT32)0x00122C7D >>16), (SINT16)0x00122C7D,
|
(SINT16)((SINT32)0x00122C7D >> 16), (SINT16)0x00122C7D,
|
||||||
(SINT16)((SINT32)0x000B3F71 >>16), (SINT16)0x000B3F71,
|
(SINT16)((SINT32)0x000B3F71 >> 16), (SINT16)0x000B3F71,
|
||||||
(SINT16)((SINT32)0x00052173 >>16), (SINT16)0x00052173
|
(SINT16)((SINT32)0x00052173 >> 16), (SINT16)0x00052173
|
||||||
};
|
};
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
/*Window coeff for 4 sub band case*/
|
/*Window coeff for 4 sub band case*/
|
||||||
const SINT32 gas32CoeffFor4SBs[] =
|
const SINT32 gas32CoeffFor4SBs[] = {
|
||||||
{
|
|
||||||
(SINT32)0x00000000,
|
(SINT32)0x00000000,
|
||||||
(SINT32)0x001194E6,
|
(SINT32)0x001194E6,
|
||||||
(SINT32)0x0030E2D3,
|
(SINT32)0x0030E2D3,
|
||||||
(SINT32)0x00599403,
|
(SINT32)0x00599403,
|
||||||
(SINT32)0x007DBCC8,
|
(SINT32)0x007DBCC8,
|
||||||
(SINT32)0x007F88E4,
|
(SINT32)0x007F88E4,
|
||||||
(SINT32)0x003D239B,
|
(SINT32)0x003D239B,
|
||||||
(SINT32)0xFF9BB9D5,
|
(SINT32)0xFF9BB9D5,
|
||||||
|
|
||||||
(SINT32)0x01659F45,
|
(SINT32)0x01659F45,
|
||||||
(SINT32)0x029DBAA3,
|
(SINT32)0x029DBAA3,
|
||||||
(SINT32)0x03B23341,
|
(SINT32)0x03B23341,
|
||||||
(SINT32)0x041EEE40,
|
(SINT32)0x041EEE40,
|
||||||
(SINT32)0x034FEE2C,
|
(SINT32)0x034FEE2C,
|
||||||
(SINT32)0x00C8F2BC,
|
(SINT32)0x00C8F2BC,
|
||||||
(SINT32)0xFC4F91D4,
|
(SINT32)0xFC4F91D4,
|
||||||
(SINT32)0xF60FAF37,
|
(SINT32)0xF60FAF37,
|
||||||
|
|
||||||
(SINT32)0x115B1ED2,
|
(SINT32)0x115B1ED2,
|
||||||
(SINT32)0x18F55C90,
|
(SINT32)0x18F55C90,
|
||||||
(SINT32)0x1F91CA46,
|
(SINT32)0x1F91CA46,
|
||||||
(SINT32)0x2412F251,
|
(SINT32)0x2412F251,
|
||||||
(SINT32)0x25AC1FF2,
|
(SINT32)0x25AC1FF2,
|
||||||
(SINT32)0x2412F251,
|
(SINT32)0x2412F251,
|
||||||
(SINT32)0x1F91CA46,
|
(SINT32)0x1F91CA46,
|
||||||
(SINT32)0x18F55C90,
|
(SINT32)0x18F55C90,
|
||||||
|
|
||||||
(SINT32)0xEEA4E12E,
|
(SINT32)0xEEA4E12E,
|
||||||
(SINT32)0xF60FAF37,
|
(SINT32)0xF60FAF37,
|
||||||
(SINT32)0xFC4F91D4,
|
(SINT32)0xFC4F91D4,
|
||||||
(SINT32)0x00C8F2BC,
|
(SINT32)0x00C8F2BC,
|
||||||
(SINT32)0x034FEE2C,
|
(SINT32)0x034FEE2C,
|
||||||
(SINT32)0x041EEE40,
|
(SINT32)0x041EEE40,
|
||||||
(SINT32)0x03B23341,
|
(SINT32)0x03B23341,
|
||||||
(SINT32)0x029DBAA3,
|
(SINT32)0x029DBAA3,
|
||||||
|
|
||||||
(SINT32)0xFE9A60BB,
|
(SINT32)0xFE9A60BB,
|
||||||
(SINT32)0xFF9BB9D5,
|
(SINT32)0xFF9BB9D5,
|
||||||
(SINT32)0x003D239B,
|
(SINT32)0x003D239B,
|
||||||
(SINT32)0x007F88E4,
|
(SINT32)0x007F88E4,
|
||||||
(SINT32)0x007DBCC8,
|
(SINT32)0x007DBCC8,
|
||||||
(SINT32)0x00599403,
|
(SINT32)0x00599403,
|
||||||
(SINT32)0x0030E2D3,
|
(SINT32)0x0030E2D3,
|
||||||
(SINT32)0x001194E6
|
(SINT32)0x001194E6
|
||||||
};
|
};
|
||||||
|
|
||||||
/*Window coeff for 8 sub band case*/
|
/*Window coeff for 8 sub band case*/
|
||||||
const SINT32 gas32CoeffFor8SBs[] =
|
const SINT32 gas32CoeffFor8SBs[] = {
|
||||||
{
|
|
||||||
(SINT32)0x00000000,
|
(SINT32)0x00000000,
|
||||||
(SINT32)0x00052173,
|
(SINT32)0x00052173,
|
||||||
(SINT32)0x000B3F71,
|
(SINT32)0x000B3F71,
|
||||||
(SINT32)0x00122C7D,
|
(SINT32)0x00122C7D,
|
||||||
(SINT32)0x001AFF89,
|
(SINT32)0x001AFF89,
|
||||||
(SINT32)0x00255A62,
|
(SINT32)0x00255A62,
|
||||||
(SINT32)0x003060F4,
|
(SINT32)0x003060F4,
|
||||||
(SINT32)0x003A72E7,
|
(SINT32)0x003A72E7,
|
||||||
|
|
||||||
(SINT32)0x0041EC6A, /* 8 */
|
(SINT32)0x0041EC6A, /* 8 */
|
||||||
(SINT32)0x0044EF48,
|
(SINT32)0x0044EF48,
|
||||||
(SINT32)0x00415B75,
|
(SINT32)0x00415B75,
|
||||||
(SINT32)0x0034F8B6,
|
(SINT32)0x0034F8B6,
|
||||||
(SINT32)0x001D8FD2,
|
(SINT32)0x001D8FD2,
|
||||||
(SINT32)0xFFFA2413,
|
(SINT32)0xFFFA2413,
|
||||||
(SINT32)0xFFC9F10E,
|
(SINT32)0xFFC9F10E,
|
||||||
(SINT32)0xFF8D6793,
|
(SINT32)0xFF8D6793,
|
||||||
|
|
||||||
(SINT32)0x00B97348, /* 16 */
|
(SINT32)0x00B97348, /* 16 */
|
||||||
(SINT32)0x01071B96,
|
(SINT32)0x01071B96,
|
||||||
(SINT32)0x0156B3CA,
|
(SINT32)0x0156B3CA,
|
||||||
(SINT32)0x01A1B38B,
|
(SINT32)0x01A1B38B,
|
||||||
(SINT32)0x01E0224C,
|
(SINT32)0x01E0224C,
|
||||||
(SINT32)0x0209291F,
|
(SINT32)0x0209291F,
|
||||||
(SINT32)0x02138653,
|
(SINT32)0x02138653,
|
||||||
(SINT32)0x01F5F424,
|
(SINT32)0x01F5F424,
|
||||||
|
|
||||||
(SINT32)0x01A7ECEF, /* 24 */
|
(SINT32)0x01A7ECEF, /* 24 */
|
||||||
(SINT32)0x01223EBA,
|
(SINT32)0x01223EBA,
|
||||||
(SINT32)0x005FD0FF,
|
(SINT32)0x005FD0FF,
|
||||||
(SINT32)0xFF5EEB73,
|
(SINT32)0xFF5EEB73,
|
||||||
(SINT32)0xFE20435D,
|
(SINT32)0xFE20435D,
|
||||||
(SINT32)0xFCA86E7E,
|
(SINT32)0xFCA86E7E,
|
||||||
(SINT32)0xFAFF95FC,
|
(SINT32)0xFAFF95FC,
|
||||||
(SINT32)0xF9312891,
|
(SINT32)0xF9312891,
|
||||||
|
|
||||||
(SINT32)0x08B4307A, /* 32 */
|
(SINT32)0x08B4307A, /* 32 */
|
||||||
(SINT32)0x0A9F3E9A,
|
(SINT32)0x0A9F3E9A,
|
||||||
(SINT32)0x0C7D59B6,
|
(SINT32)0x0C7D59B6,
|
||||||
(SINT32)0x0E3BB16F,
|
(SINT32)0x0E3BB16F,
|
||||||
(SINT32)0x0FC721F9,
|
(SINT32)0x0FC721F9,
|
||||||
(SINT32)0x110ECEF0,
|
(SINT32)0x110ECEF0,
|
||||||
(SINT32)0x120435FA,
|
(SINT32)0x120435FA,
|
||||||
(SINT32)0x129C226F,
|
(SINT32)0x129C226F,
|
||||||
|
|
||||||
(SINT32)0x12CF6C75, /* 40 */
|
(SINT32)0x12CF6C75, /* 40 */
|
||||||
(SINT32)0x129C226F,
|
(SINT32)0x129C226F,
|
||||||
(SINT32)0x120435FA,
|
(SINT32)0x120435FA,
|
||||||
(SINT32)0x110ECEF0,
|
(SINT32)0x110ECEF0,
|
||||||
(SINT32)0x0FC721F9,
|
(SINT32)0x0FC721F9,
|
||||||
(SINT32)0x0E3BB16F,
|
(SINT32)0x0E3BB16F,
|
||||||
(SINT32)0x0C7D59B6,
|
(SINT32)0x0C7D59B6,
|
||||||
(SINT32)0x0A9F3E9A,
|
(SINT32)0x0A9F3E9A,
|
||||||
|
|
||||||
(SINT32)0xF74BCF86, /* 48 */
|
(SINT32)0xF74BCF86, /* 48 */
|
||||||
(SINT32)0xF9312891,
|
(SINT32)0xF9312891,
|
||||||
(SINT32)0xFAFF95FC,
|
(SINT32)0xFAFF95FC,
|
||||||
(SINT32)0xFCA86E7E,
|
(SINT32)0xFCA86E7E,
|
||||||
(SINT32)0xFE20435D,
|
(SINT32)0xFE20435D,
|
||||||
(SINT32)0xFF5EEB73,
|
(SINT32)0xFF5EEB73,
|
||||||
(SINT32)0x005FD0FF,
|
(SINT32)0x005FD0FF,
|
||||||
(SINT32)0x01223EBA,
|
(SINT32)0x01223EBA,
|
||||||
|
|
||||||
(SINT32)0x01A7ECEF, /* 56 */
|
(SINT32)0x01A7ECEF, /* 56 */
|
||||||
(SINT32)0x01F5F424,
|
(SINT32)0x01F5F424,
|
||||||
(SINT32)0x02138653,
|
(SINT32)0x02138653,
|
||||||
(SINT32)0x0209291F,
|
(SINT32)0x0209291F,
|
||||||
(SINT32)0x01E0224C,
|
(SINT32)0x01E0224C,
|
||||||
(SINT32)0x01A1B38B,
|
(SINT32)0x01A1B38B,
|
||||||
(SINT32)0x0156B3CA,
|
(SINT32)0x0156B3CA,
|
||||||
(SINT32)0x01071B96,
|
(SINT32)0x01071B96,
|
||||||
|
|
||||||
(SINT32)0xFF468CB8, /* 64 */
|
(SINT32)0xFF468CB8, /* 64 */
|
||||||
(SINT32)0xFF8D6793,
|
(SINT32)0xFF8D6793,
|
||||||
(SINT32)0xFFC9F10E,
|
(SINT32)0xFFC9F10E,
|
||||||
(SINT32)0xFFFA2413,
|
(SINT32)0xFFFA2413,
|
||||||
(SINT32)0x001D8FD2,
|
(SINT32)0x001D8FD2,
|
||||||
(SINT32)0x0034F8B6,
|
(SINT32)0x0034F8B6,
|
||||||
(SINT32)0x00415B75,
|
(SINT32)0x00415B75,
|
||||||
(SINT32)0x0044EF48,
|
(SINT32)0x0044EF48,
|
||||||
|
|
||||||
(SINT32)0x0041EC6A, /* 72 */
|
(SINT32)0x0041EC6A, /* 72 */
|
||||||
(SINT32)0x003A72E7,
|
(SINT32)0x003A72E7,
|
||||||
(SINT32)0x003060F4,
|
(SINT32)0x003060F4,
|
||||||
(SINT32)0x00255A62,
|
(SINT32)0x00255A62,
|
||||||
(SINT32)0x001AFF89,
|
(SINT32)0x001AFF89,
|
||||||
(SINT32)0x00122C7D,
|
(SINT32)0x00122C7D,
|
||||||
(SINT32)0x000B3F71,
|
(SINT32)0x000B3F71,
|
||||||
(SINT32)0x00052173
|
(SINT32)0x00052173
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
241
examples/09_a2dp/components/bluedroid_demos/embdrv/sbc/encoder/srce/sbc_encoder.c
Executable file → Normal file
241
examples/09_a2dp/components/bluedroid_demos/embdrv/sbc/encoder/srce/sbc_encoder.c
Executable file → Normal file
@ -83,14 +83,12 @@ SINT16 EncMaxShiftCounter;
|
|||||||
#define SBC_PRTC_SYNC_MASK 0x10
|
#define SBC_PRTC_SYNC_MASK 0x10
|
||||||
#define SBC_PRTC_CIDX 0
|
#define SBC_PRTC_CIDX 0
|
||||||
#define SBC_PRTC_LIDX 1
|
#define SBC_PRTC_LIDX 1
|
||||||
typedef struct
|
typedef struct {
|
||||||
{
|
|
||||||
UINT8 use;
|
UINT8 use;
|
||||||
UINT8 idx;
|
UINT8 idx;
|
||||||
} tSBC_FR_CB;
|
} tSBC_FR_CB;
|
||||||
|
|
||||||
typedef struct
|
typedef struct {
|
||||||
{
|
|
||||||
tSBC_FR_CB fr[2];
|
tSBC_FR_CB fr[2];
|
||||||
UINT8 init;
|
UINT8 init;
|
||||||
UINT8 index;
|
UINT8 index;
|
||||||
@ -127,7 +125,7 @@ void SBC_Encoder(SBC_ENC_PARAMS *pstrEncParams)
|
|||||||
SINT32 s32NumOfBlocks = pstrEncParams->s16NumOfBlocks;
|
SINT32 s32NumOfBlocks = pstrEncParams->s16NumOfBlocks;
|
||||||
#if (SBC_JOINT_STE_INCLUDED == TRUE)
|
#if (SBC_JOINT_STE_INCLUDED == TRUE)
|
||||||
SINT32 s32MaxValue2;
|
SINT32 s32MaxValue2;
|
||||||
UINT32 u32CountSum,u32CountDiff;
|
UINT32 u32CountSum, u32CountDiff;
|
||||||
SINT32 *pSum, *pDiff;
|
SINT32 *pSum, *pDiff;
|
||||||
#endif
|
#endif
|
||||||
UINT8 *pu8;
|
UINT8 *pu8;
|
||||||
@ -142,113 +140,110 @@ void SBC_Encoder(SBC_ENC_PARAMS *pstrEncParams)
|
|||||||
#else
|
#else
|
||||||
pstrEncParams->ps16NextPcmBuffer = pstrEncParams->as16PcmBuffer;
|
pstrEncParams->ps16NextPcmBuffer = pstrEncParams->as16PcmBuffer;
|
||||||
#endif
|
#endif
|
||||||
do
|
do {
|
||||||
{
|
|
||||||
/* SBC ananlysis filter*/
|
/* SBC ananlysis filter*/
|
||||||
if (s32NumOfSubBands == 4)
|
if (s32NumOfSubBands == 4) {
|
||||||
SbcAnalysisFilter4(pstrEncParams);
|
SbcAnalysisFilter4(pstrEncParams);
|
||||||
else
|
} else {
|
||||||
SbcAnalysisFilter8(pstrEncParams);
|
SbcAnalysisFilter8(pstrEncParams);
|
||||||
|
}
|
||||||
|
|
||||||
/* compute the scale factor, and save the max */
|
/* compute the scale factor, and save the max */
|
||||||
ps16ScfL = pstrEncParams->as16ScaleFactor;
|
ps16ScfL = pstrEncParams->as16ScaleFactor;
|
||||||
s32Ch=pstrEncParams->s16NumOfChannels*s32NumOfSubBands;
|
s32Ch = pstrEncParams->s16NumOfChannels * s32NumOfSubBands;
|
||||||
|
|
||||||
pstrEncParams->ps16NextPcmBuffer+=s32Ch*s32NumOfBlocks; /* in case of multible sbc frame to encode update the pcm pointer */
|
pstrEncParams->ps16NextPcmBuffer += s32Ch * s32NumOfBlocks; /* in case of multible sbc frame to encode update the pcm pointer */
|
||||||
|
|
||||||
for (s32Sb=0; s32Sb<s32Ch; s32Sb++)
|
for (s32Sb = 0; s32Sb < s32Ch; s32Sb++) {
|
||||||
{
|
SbBuffer = pstrEncParams->s32SbBuffer + s32Sb;
|
||||||
SbBuffer=pstrEncParams->s32SbBuffer+s32Sb;
|
s32MaxValue = 0;
|
||||||
s32MaxValue=0;
|
for (s32Blk = s32NumOfBlocks; s32Blk > 0; s32Blk--) {
|
||||||
for (s32Blk=s32NumOfBlocks;s32Blk>0;s32Blk--)
|
if (s32MaxValue < abs32(*SbBuffer)) {
|
||||||
{
|
s32MaxValue = abs32(*SbBuffer);
|
||||||
if (s32MaxValue<abs32(*SbBuffer))
|
}
|
||||||
s32MaxValue=abs32(*SbBuffer);
|
SbBuffer += s32Ch;
|
||||||
SbBuffer+=s32Ch;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
u32Count = (s32MaxValue > 0x800000) ? 9 : 0;
|
u32Count = (s32MaxValue > 0x800000) ? 9 : 0;
|
||||||
|
|
||||||
for ( ; u32Count < 15; u32Count++)
|
for ( ; u32Count < 15; u32Count++) {
|
||||||
{
|
if (s32MaxValue <= (SINT32)(0x8000 << u32Count)) {
|
||||||
if (s32MaxValue <= (SINT32)(0x8000 << u32Count))
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
*ps16ScfL++ = (SINT16)u32Count;
|
*ps16ScfL++ = (SINT16)u32Count;
|
||||||
|
|
||||||
if (u32Count > maxBit)
|
if (u32Count > maxBit) {
|
||||||
maxBit = u32Count;
|
maxBit = u32Count;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/* In case of JS processing,check whether to use JS */
|
/* In case of JS processing,check whether to use JS */
|
||||||
#if (SBC_JOINT_STE_INCLUDED == TRUE)
|
#if (SBC_JOINT_STE_INCLUDED == TRUE)
|
||||||
if (pstrEncParams->s16ChannelMode == SBC_JOINT_STEREO)
|
if (pstrEncParams->s16ChannelMode == SBC_JOINT_STEREO) {
|
||||||
{
|
|
||||||
/* Calculate sum and differance scale factors for making JS decision */
|
/* Calculate sum and differance scale factors for making JS decision */
|
||||||
ps16ScfL = pstrEncParams->as16ScaleFactor ;
|
ps16ScfL = pstrEncParams->as16ScaleFactor ;
|
||||||
/* calculate the scale factor of Joint stereo max sum and diff */
|
/* calculate the scale factor of Joint stereo max sum and diff */
|
||||||
for (s32Sb = 0; s32Sb < s32NumOfSubBands-1; s32Sb++)
|
for (s32Sb = 0; s32Sb < s32NumOfSubBands - 1; s32Sb++) {
|
||||||
{
|
SbBuffer = pstrEncParams->s32SbBuffer + s32Sb;
|
||||||
SbBuffer=pstrEncParams->s32SbBuffer+s32Sb;
|
s32MaxValue2 = 0;
|
||||||
s32MaxValue2=0;
|
s32MaxValue = 0;
|
||||||
s32MaxValue=0;
|
|
||||||
pSum = s32LRSum;
|
pSum = s32LRSum;
|
||||||
pDiff = s32LRDiff;
|
pDiff = s32LRDiff;
|
||||||
for (s32Blk=0;s32Blk<s32NumOfBlocks;s32Blk++)
|
for (s32Blk = 0; s32Blk < s32NumOfBlocks; s32Blk++) {
|
||||||
{
|
*pSum = (*SbBuffer + * (SbBuffer + s32NumOfSubBands)) >> 1;
|
||||||
*pSum=(*SbBuffer+*(SbBuffer+s32NumOfSubBands))>>1;
|
if (abs32(*pSum) > s32MaxValue) {
|
||||||
if (abs32(*pSum)>s32MaxValue)
|
s32MaxValue = abs32(*pSum);
|
||||||
s32MaxValue=abs32(*pSum);
|
}
|
||||||
pSum++;
|
pSum++;
|
||||||
*pDiff=(*SbBuffer-*(SbBuffer+s32NumOfSubBands))>>1;
|
*pDiff = (*SbBuffer - * (SbBuffer + s32NumOfSubBands)) >> 1;
|
||||||
if (abs32(*pDiff)>s32MaxValue2)
|
if (abs32(*pDiff) > s32MaxValue2) {
|
||||||
s32MaxValue2=abs32(*pDiff);
|
s32MaxValue2 = abs32(*pDiff);
|
||||||
|
}
|
||||||
pDiff++;
|
pDiff++;
|
||||||
SbBuffer+=s32Ch;
|
SbBuffer += s32Ch;
|
||||||
}
|
}
|
||||||
u32Count = (s32MaxValue > 0x800000) ? 9 : 0;
|
u32Count = (s32MaxValue > 0x800000) ? 9 : 0;
|
||||||
for ( ; u32Count < 15; u32Count++)
|
for ( ; u32Count < 15; u32Count++) {
|
||||||
{
|
if (s32MaxValue <= (SINT32)(0x8000 << u32Count)) {
|
||||||
if (s32MaxValue <= (SINT32)(0x8000 << u32Count))
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
u32CountSum=u32Count;
|
u32CountSum = u32Count;
|
||||||
u32Count = (s32MaxValue2 > 0x800000) ? 9 : 0;
|
u32Count = (s32MaxValue2 > 0x800000) ? 9 : 0;
|
||||||
for ( ; u32Count < 15; u32Count++)
|
for ( ; u32Count < 15; u32Count++) {
|
||||||
{
|
if (s32MaxValue2 <= (SINT32)(0x8000 << u32Count)) {
|
||||||
if (s32MaxValue2 <= (SINT32)(0x8000 << u32Count))
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
u32CountDiff=u32Count;
|
u32CountDiff = u32Count;
|
||||||
if ( (*ps16ScfL + *(ps16ScfL+s32NumOfSubBands)) > (SINT16)(u32CountSum + u32CountDiff) )
|
if ( (*ps16ScfL + * (ps16ScfL + s32NumOfSubBands)) > (SINT16)(u32CountSum + u32CountDiff) ) {
|
||||||
{
|
|
||||||
|
|
||||||
if (u32CountSum > maxBit)
|
if (u32CountSum > maxBit) {
|
||||||
maxBit = u32CountSum;
|
maxBit = u32CountSum;
|
||||||
|
}
|
||||||
|
|
||||||
if (u32CountDiff > maxBit)
|
if (u32CountDiff > maxBit) {
|
||||||
maxBit = u32CountDiff;
|
maxBit = u32CountDiff;
|
||||||
|
}
|
||||||
|
|
||||||
*ps16ScfL = (SINT16)u32CountSum;
|
*ps16ScfL = (SINT16)u32CountSum;
|
||||||
*(ps16ScfL+s32NumOfSubBands) = (SINT16)u32CountDiff;
|
*(ps16ScfL + s32NumOfSubBands) = (SINT16)u32CountDiff;
|
||||||
|
|
||||||
SbBuffer=pstrEncParams->s32SbBuffer+s32Sb;
|
SbBuffer = pstrEncParams->s32SbBuffer + s32Sb;
|
||||||
pSum = s32LRSum;
|
pSum = s32LRSum;
|
||||||
pDiff = s32LRDiff;
|
pDiff = s32LRDiff;
|
||||||
|
|
||||||
for (s32Blk = 0; s32Blk < s32NumOfBlocks; s32Blk++)
|
for (s32Blk = 0; s32Blk < s32NumOfBlocks; s32Blk++) {
|
||||||
{
|
|
||||||
*SbBuffer = *pSum;
|
*SbBuffer = *pSum;
|
||||||
*(SbBuffer+s32NumOfSubBands) = *pDiff;
|
*(SbBuffer + s32NumOfSubBands) = *pDiff;
|
||||||
|
|
||||||
SbBuffer += s32NumOfSubBands<<1;
|
SbBuffer += s32NumOfSubBands << 1;
|
||||||
pSum++;
|
pSum++;
|
||||||
pDiff++;
|
pDiff++;
|
||||||
}
|
}
|
||||||
|
|
||||||
pstrEncParams->as16Join[s32Sb] = 1;
|
pstrEncParams->as16Join[s32Sb] = 1;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
pstrEncParams->as16Join[s32Sb] = 0;
|
pstrEncParams->as16Join[s32Sb] = 0;
|
||||||
}
|
}
|
||||||
ps16ScfL++;
|
ps16ScfL++;
|
||||||
@ -260,10 +255,11 @@ void SBC_Encoder(SBC_ENC_PARAMS *pstrEncParams)
|
|||||||
pstrEncParams->s16MaxBitNeed = (SINT16)maxBit;
|
pstrEncParams->s16MaxBitNeed = (SINT16)maxBit;
|
||||||
|
|
||||||
/* bit allocation */
|
/* bit allocation */
|
||||||
if ((pstrEncParams->s16ChannelMode == SBC_STEREO) || (pstrEncParams->s16ChannelMode == SBC_JOINT_STEREO))
|
if ((pstrEncParams->s16ChannelMode == SBC_STEREO) || (pstrEncParams->s16ChannelMode == SBC_JOINT_STEREO)) {
|
||||||
sbc_enc_bit_alloc_ste(pstrEncParams);
|
sbc_enc_bit_alloc_ste(pstrEncParams);
|
||||||
else
|
} else {
|
||||||
sbc_enc_bit_alloc_mono(pstrEncParams);
|
sbc_enc_bit_alloc_mono(pstrEncParams);
|
||||||
|
}
|
||||||
|
|
||||||
/* save the beginning of the frame. pu8NextPacket is modified in EncPacking() */
|
/* save the beginning of the frame. pu8NextPacket is modified in EncPacking() */
|
||||||
pu8 = pstrEncParams->pu8NextPacket;
|
pu8 = pstrEncParams->pu8NextPacket;
|
||||||
@ -274,14 +270,14 @@ void SBC_Encoder(SBC_ENC_PARAMS *pstrEncParams)
|
|||||||
SBC_PRTC_CHK_INIT(pu8);
|
SBC_PRTC_CHK_INIT(pu8);
|
||||||
SBC_PRTC_CHK_CRC(pu8);
|
SBC_PRTC_CHK_CRC(pu8);
|
||||||
#if 0
|
#if 0
|
||||||
if(pstrEncParams->u16PacketLength > ((sbc_prtc_cb.fr[sbc_prtc_cb.index].idx * 2) + sbc_prtc_cb.base))
|
if (pstrEncParams->u16PacketLength > ((sbc_prtc_cb.fr[sbc_prtc_cb.index].idx * 2) + sbc_prtc_cb.base)) {
|
||||||
printf("len: %d, idx: %d\n", pstrEncParams->u16PacketLength, sbc_prtc_cb.fr[sbc_prtc_cb.index].idx);
|
printf("len: %d, idx: %d\n", pstrEncParams->u16PacketLength, sbc_prtc_cb.fr[sbc_prtc_cb.index].idx);
|
||||||
else
|
} else {
|
||||||
printf("len: %d, idx: %d!!!!\n", pstrEncParams->u16PacketLength, sbc_prtc_cb.fr[sbc_prtc_cb.index].idx);
|
printf("len: %d, idx: %d!!!!\n", pstrEncParams->u16PacketLength, sbc_prtc_cb.fr[sbc_prtc_cb.index].idx);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
SBC_PRTC_SCRMB((&pu8[sbc_prtc_cb.base]));
|
SBC_PRTC_SCRMB((&pu8[sbc_prtc_cb.base]));
|
||||||
}
|
} while (--(pstrEncParams->u8NumPacketToEncode));
|
||||||
while(--(pstrEncParams->u8NumPacketToEncode));
|
|
||||||
|
|
||||||
pstrEncParams->u8NumPacketToEncode = 1; /* default is one for retrocompatibility purpose */
|
pstrEncParams->u8NumPacketToEncode = 1; /* default is one for retrocompatibility purpose */
|
||||||
|
|
||||||
@ -303,100 +299,101 @@ void SBC_Encoder_Init(SBC_ENC_PARAMS *pstrEncParams)
|
|||||||
pstrEncParams->u8NumPacketToEncode = 1; /* default is one for retrocompatibility purpose */
|
pstrEncParams->u8NumPacketToEncode = 1; /* default is one for retrocompatibility purpose */
|
||||||
|
|
||||||
/* Required number of channels */
|
/* Required number of channels */
|
||||||
if (pstrEncParams->s16ChannelMode == SBC_MONO)
|
if (pstrEncParams->s16ChannelMode == SBC_MONO) {
|
||||||
pstrEncParams->s16NumOfChannels = 1;
|
pstrEncParams->s16NumOfChannels = 1;
|
||||||
else
|
} else {
|
||||||
pstrEncParams->s16NumOfChannels = 2;
|
pstrEncParams->s16NumOfChannels = 2;
|
||||||
|
}
|
||||||
|
|
||||||
/* Bit pool calculation */
|
/* Bit pool calculation */
|
||||||
if (pstrEncParams->s16SamplingFreq == SBC_sf16000)
|
if (pstrEncParams->s16SamplingFreq == SBC_sf16000) {
|
||||||
s16SamplingFreq = 16000;
|
s16SamplingFreq = 16000;
|
||||||
else if (pstrEncParams->s16SamplingFreq == SBC_sf32000)
|
} else if (pstrEncParams->s16SamplingFreq == SBC_sf32000) {
|
||||||
s16SamplingFreq = 32000;
|
s16SamplingFreq = 32000;
|
||||||
else if (pstrEncParams->s16SamplingFreq == SBC_sf44100)
|
} else if (pstrEncParams->s16SamplingFreq == SBC_sf44100) {
|
||||||
s16SamplingFreq = 44100;
|
s16SamplingFreq = 44100;
|
||||||
else
|
} else {
|
||||||
s16SamplingFreq = 48000;
|
s16SamplingFreq = 48000;
|
||||||
|
}
|
||||||
|
|
||||||
if ( (pstrEncParams->s16ChannelMode == SBC_JOINT_STEREO)
|
if ( (pstrEncParams->s16ChannelMode == SBC_JOINT_STEREO)
|
||||||
|| (pstrEncParams->s16ChannelMode == SBC_STEREO) )
|
|| (pstrEncParams->s16ChannelMode == SBC_STEREO) ) {
|
||||||
{
|
|
||||||
s16Bitpool = (SINT16)( (pstrEncParams->u16BitRate *
|
s16Bitpool = (SINT16)( (pstrEncParams->u16BitRate *
|
||||||
pstrEncParams->s16NumOfSubBands * 1000 / s16SamplingFreq)
|
pstrEncParams->s16NumOfSubBands * 1000 / s16SamplingFreq)
|
||||||
-( (32 + (4 * pstrEncParams->s16NumOfSubBands *
|
- ( (32 + (4 * pstrEncParams->s16NumOfSubBands *
|
||||||
pstrEncParams->s16NumOfChannels)
|
pstrEncParams->s16NumOfChannels)
|
||||||
+ ( (pstrEncParams->s16ChannelMode - 2) *
|
+ ( (pstrEncParams->s16ChannelMode - 2) *
|
||||||
pstrEncParams->s16NumOfSubBands ) )
|
pstrEncParams->s16NumOfSubBands ) )
|
||||||
/ pstrEncParams->s16NumOfBlocks) );
|
/ pstrEncParams->s16NumOfBlocks) );
|
||||||
|
|
||||||
s16FrameLen = 4 + (4*pstrEncParams->s16NumOfSubBands*
|
s16FrameLen = 4 + (4 * pstrEncParams->s16NumOfSubBands *
|
||||||
pstrEncParams->s16NumOfChannels)/8
|
pstrEncParams->s16NumOfChannels) / 8
|
||||||
+ ( ((pstrEncParams->s16ChannelMode - 2) *
|
+ ( ((pstrEncParams->s16ChannelMode - 2) *
|
||||||
pstrEncParams->s16NumOfSubBands)
|
pstrEncParams->s16NumOfSubBands)
|
||||||
+ (pstrEncParams->s16NumOfBlocks * s16Bitpool) ) / 8;
|
+ (pstrEncParams->s16NumOfBlocks * s16Bitpool) ) / 8;
|
||||||
|
|
||||||
s16BitRate = (8 * s16FrameLen * s16SamplingFreq)
|
s16BitRate = (8 * s16FrameLen * s16SamplingFreq)
|
||||||
/ (pstrEncParams->s16NumOfSubBands *
|
/ (pstrEncParams->s16NumOfSubBands *
|
||||||
pstrEncParams->s16NumOfBlocks * 1000);
|
pstrEncParams->s16NumOfBlocks * 1000);
|
||||||
|
|
||||||
if (s16BitRate > pstrEncParams->u16BitRate)
|
if (s16BitRate > pstrEncParams->u16BitRate) {
|
||||||
s16Bitpool--;
|
s16Bitpool--;
|
||||||
|
}
|
||||||
|
|
||||||
if(pstrEncParams->s16NumOfSubBands == 8)
|
if (pstrEncParams->s16NumOfSubBands == 8) {
|
||||||
pstrEncParams->s16BitPool = (s16Bitpool > 255) ? 255 : s16Bitpool;
|
pstrEncParams->s16BitPool = (s16Bitpool > 255) ? 255 : s16Bitpool;
|
||||||
else
|
} else {
|
||||||
pstrEncParams->s16BitPool = (s16Bitpool > 128) ? 128 : s16Bitpool;
|
pstrEncParams->s16BitPool = (s16Bitpool > 128) ? 128 : s16Bitpool;
|
||||||
}
|
}
|
||||||
else
|
} else {
|
||||||
{
|
|
||||||
s16Bitpool = (SINT16)( ((pstrEncParams->s16NumOfSubBands *
|
s16Bitpool = (SINT16)( ((pstrEncParams->s16NumOfSubBands *
|
||||||
pstrEncParams->u16BitRate * 1000)
|
pstrEncParams->u16BitRate * 1000)
|
||||||
/ (s16SamplingFreq * pstrEncParams->s16NumOfChannels))
|
/ (s16SamplingFreq * pstrEncParams->s16NumOfChannels))
|
||||||
-( ( (32 / pstrEncParams->s16NumOfChannels) +
|
- ( ( (32 / pstrEncParams->s16NumOfChannels) +
|
||||||
(4 * pstrEncParams->s16NumOfSubBands) )
|
(4 * pstrEncParams->s16NumOfSubBands) )
|
||||||
/ pstrEncParams->s16NumOfBlocks ) );
|
/ pstrEncParams->s16NumOfBlocks ) );
|
||||||
|
|
||||||
pstrEncParams->s16BitPool = (s16Bitpool >
|
pstrEncParams->s16BitPool = (s16Bitpool >
|
||||||
(16 * pstrEncParams->s16NumOfSubBands))
|
(16 * pstrEncParams->s16NumOfSubBands))
|
||||||
? (16*pstrEncParams->s16NumOfSubBands) : s16Bitpool;
|
? (16 * pstrEncParams->s16NumOfSubBands) : s16Bitpool;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pstrEncParams->s16BitPool < 0)
|
if (pstrEncParams->s16BitPool < 0) {
|
||||||
pstrEncParams->s16BitPool = 0;
|
pstrEncParams->s16BitPool = 0;
|
||||||
|
}
|
||||||
/* sampling freq */
|
/* sampling freq */
|
||||||
HeaderParams = ((pstrEncParams->s16SamplingFreq & 3)<< 6);
|
HeaderParams = ((pstrEncParams->s16SamplingFreq & 3) << 6);
|
||||||
|
|
||||||
/* number of blocks*/
|
/* number of blocks*/
|
||||||
HeaderParams |= (((pstrEncParams->s16NumOfBlocks -4) & 12) << 2);
|
HeaderParams |= (((pstrEncParams->s16NumOfBlocks - 4) & 12) << 2);
|
||||||
|
|
||||||
/* channel mode: mono, dual...*/
|
/* channel mode: mono, dual...*/
|
||||||
HeaderParams |= ((pstrEncParams->s16ChannelMode & 3)<< 2);
|
HeaderParams |= ((pstrEncParams->s16ChannelMode & 3) << 2);
|
||||||
|
|
||||||
/* Loudness or SNR */
|
/* Loudness or SNR */
|
||||||
HeaderParams |= ((pstrEncParams->s16AllocationMethod & 1)<< 1);
|
HeaderParams |= ((pstrEncParams->s16AllocationMethod & 1) << 1);
|
||||||
HeaderParams |= ((pstrEncParams->s16NumOfSubBands >> 3) & 1); /*4 or 8*/
|
HeaderParams |= ((pstrEncParams->s16NumOfSubBands >> 3) & 1); /*4 or 8*/
|
||||||
pstrEncParams->FrameHeader=HeaderParams;
|
pstrEncParams->FrameHeader = HeaderParams;
|
||||||
|
|
||||||
if (pstrEncParams->s16NumOfSubBands==4)
|
if (pstrEncParams->s16NumOfSubBands == 4) {
|
||||||
{
|
if (pstrEncParams->s16NumOfChannels == 1) {
|
||||||
if (pstrEncParams->s16NumOfChannels==1)
|
EncMaxShiftCounter = ((ENC_VX_BUFFER_SIZE - 4 * 10) >> 2) << 2;
|
||||||
EncMaxShiftCounter=((ENC_VX_BUFFER_SIZE-4*10)>>2)<<2;
|
} else {
|
||||||
else
|
EncMaxShiftCounter = ((ENC_VX_BUFFER_SIZE - 4 * 10 * 2) >> 3) << 2;
|
||||||
EncMaxShiftCounter=((ENC_VX_BUFFER_SIZE-4*10*2)>>3)<<2;
|
}
|
||||||
}
|
} else {
|
||||||
else
|
if (pstrEncParams->s16NumOfChannels == 1) {
|
||||||
{
|
EncMaxShiftCounter = ((ENC_VX_BUFFER_SIZE - 8 * 10) >> 3) << 3;
|
||||||
if (pstrEncParams->s16NumOfChannels==1)
|
} else {
|
||||||
EncMaxShiftCounter=((ENC_VX_BUFFER_SIZE-8*10)>>3)<<3;
|
EncMaxShiftCounter = ((ENC_VX_BUFFER_SIZE - 8 * 10 * 2) >> 4) << 3;
|
||||||
else
|
}
|
||||||
EncMaxShiftCounter=((ENC_VX_BUFFER_SIZE-8*10*2)>>4)<<3;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
APPL_TRACE_EVENT("SBC_Encoder_Init : bitrate %d, bitpool %d",
|
APPL_TRACE_EVENT("SBC_Encoder_Init : bitrate %d, bitpool %d",
|
||||||
pstrEncParams->u16BitRate, pstrEncParams->s16BitPool);
|
pstrEncParams->u16BitRate, pstrEncParams->s16BitPool);
|
||||||
|
|
||||||
SbcAnalysisInit();
|
SbcAnalysisInit();
|
||||||
|
|
||||||
memset(&sbc_prtc_cb, 0, sizeof(tSBC_PRTC_CB));
|
memset(&sbc_prtc_cb, 0, sizeof(tSBC_PRTC_CB));
|
||||||
sbc_prtc_cb.base = 6 + pstrEncParams->s16NumOfChannels*pstrEncParams->s16NumOfSubBands/2;
|
sbc_prtc_cb.base = 6 + pstrEncParams->s16NumOfChannels * pstrEncParams->s16NumOfSubBands / 2;
|
||||||
}
|
}
|
||||||
|
137
examples/09_a2dp/components/bluedroid_demos/embdrv/sbc/encoder/srce/sbc_packing.c
Executable file → Normal file
137
examples/09_a2dp/components/bluedroid_demos/embdrv/sbc/encoder/srce/sbc_packing.c
Executable file → Normal file
@ -35,21 +35,21 @@
|
|||||||
}
|
}
|
||||||
#define Mult64(s32In1, s32In2, s32OutLow, s32OutHi) \
|
#define Mult64(s32In1, s32In2, s32OutLow, s32OutHi) \
|
||||||
{ \
|
{ \
|
||||||
__asm \
|
__asm \
|
||||||
{ \
|
{ \
|
||||||
SMULL s32OutLow,s32OutHi,s32In1,s32In2 \
|
SMULL s32OutLow,s32OutHi,s32In1,s32In2 \
|
||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
#define Mult32(s32In1,s32In2,s32OutLow) s32OutLow=(SINT32)s32In1*(SINT32)s32In2;
|
#define Mult32(s32In1,s32In2,s32OutLow) s32OutLow=(SINT32)s32In1*(SINT32)s32In2;
|
||||||
#define Mult64(s32In1, s32In2, s32OutLow, s32OutHi) \
|
#define Mult64(s32In1, s32In2, s32OutLow, s32OutHi) \
|
||||||
{ \
|
{ \
|
||||||
s32OutLow = ((SINT32)(UINT16)s32In1 * (UINT16)s32In2); \
|
s32OutLow = ((SINT32)(UINT16)s32In1 * (UINT16)s32In2); \
|
||||||
s32TempVal2 = (SINT32)((s32In1 >> 16) * (UINT16)s32In2); \
|
s32TempVal2 = (SINT32)((s32In1 >> 16) * (UINT16)s32In2); \
|
||||||
s32Carry = ( (((UINT32)(s32OutLow)>>16)&0xFFFF) + \
|
s32Carry = ( (((UINT32)(s32OutLow)>>16)&0xFFFF) + \
|
||||||
+ (s32TempVal2 & 0xFFFF) ) >> 16; \
|
+ (s32TempVal2 & 0xFFFF) ) >> 16; \
|
||||||
s32OutLow += (s32TempVal2 << 16); \
|
s32OutLow += (s32TempVal2 << 16); \
|
||||||
s32OutHi = (s32TempVal2 >> 16) + s32Carry; \
|
s32OutHi = (s32TempVal2 >> 16) + s32Carry; \
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -63,7 +63,7 @@ void EncPacking(SBC_ENC_PARAMS *pstrEncParams)
|
|||||||
SINT32 s32PresentBit; /* represents bit to be stored*/
|
SINT32 s32PresentBit; /* represents bit to be stored*/
|
||||||
/*SINT32 s32LoopCountI; loop counter*/
|
/*SINT32 s32LoopCountI; loop counter*/
|
||||||
SINT32 s32LoopCountJ; /* loop counter*/
|
SINT32 s32LoopCountJ; /* loop counter*/
|
||||||
UINT32 u32QuantizedSbValue,u32QuantizedSbValue0; /* temp variable to store quantized sb val*/
|
UINT32 u32QuantizedSbValue, u32QuantizedSbValue0; /* temp variable to store quantized sb val*/
|
||||||
SINT32 s32LoopCount; /* loop counter*/
|
SINT32 s32LoopCount; /* loop counter*/
|
||||||
UINT8 u8XoredVal; /* to store XORed value in CRC calculation*/
|
UINT8 u8XoredVal; /* to store XORed value in CRC calculation*/
|
||||||
UINT8 u8CRC; /* to store CRC value*/
|
UINT8 u8CRC; /* to store CRC value*/
|
||||||
@ -71,44 +71,39 @@ void EncPacking(SBC_ENC_PARAMS *pstrEncParams)
|
|||||||
SINT32 s32NumOfBlocks;
|
SINT32 s32NumOfBlocks;
|
||||||
SINT32 s32NumOfSubBands = pstrEncParams->s16NumOfSubBands;
|
SINT32 s32NumOfSubBands = pstrEncParams->s16NumOfSubBands;
|
||||||
SINT32 s32NumOfChannels = pstrEncParams->s16NumOfChannels;
|
SINT32 s32NumOfChannels = pstrEncParams->s16NumOfChannels;
|
||||||
UINT32 u32SfRaisedToPow2; /*scale factor raised to power 2*/
|
UINT32 u32SfRaisedToPow2; /*scale factor raised to power 2*/
|
||||||
SINT16 *ps16ScfPtr;
|
SINT16 *ps16ScfPtr;
|
||||||
SINT32 *ps32SbPtr;
|
SINT32 *ps32SbPtr;
|
||||||
UINT16 u16Levels; /*to store levels*/
|
UINT16 u16Levels; /*to store levels*/
|
||||||
SINT32 s32Temp1; /*used in 64-bit multiplication*/
|
SINT32 s32Temp1; /*used in 64-bit multiplication*/
|
||||||
SINT32 s32Low; /*used in 64-bit multiplication*/
|
SINT32 s32Low; /*used in 64-bit multiplication*/
|
||||||
#if (SBC_IS_64_MULT_IN_QUANTIZER==TRUE)
|
#if (SBC_IS_64_MULT_IN_QUANTIZER==TRUE)
|
||||||
SINT32 s32Hi1,s32Low1,s32Carry,s32TempVal2,s32Hi, s32Temp2;
|
SINT32 s32Hi1, s32Low1, s32Carry, s32TempVal2, s32Hi, s32Temp2;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
pu8PacketPtr = pstrEncParams->pu8NextPacket; /*Initialize the ptr*/
|
pu8PacketPtr = pstrEncParams->pu8NextPacket; /*Initialize the ptr*/
|
||||||
*pu8PacketPtr++ = (UINT8)0x9C; /*Sync word*/
|
*pu8PacketPtr++ = (UINT8)0x9C; /*Sync word*/
|
||||||
*pu8PacketPtr++=(UINT8)(pstrEncParams->FrameHeader);
|
*pu8PacketPtr++ = (UINT8)(pstrEncParams->FrameHeader);
|
||||||
|
|
||||||
*pu8PacketPtr = (UINT8)(pstrEncParams->s16BitPool & 0x00FF);
|
*pu8PacketPtr = (UINT8)(pstrEncParams->s16BitPool & 0x00FF);
|
||||||
pu8PacketPtr += 2; /*skip for CRC*/
|
pu8PacketPtr += 2; /*skip for CRC*/
|
||||||
|
|
||||||
/*here it indicate if it is byte boundary or nibble boundary*/
|
/*here it indicate if it is byte boundary or nibble boundary*/
|
||||||
s32PresentBit = 8;
|
s32PresentBit = 8;
|
||||||
Temp=0;
|
Temp = 0;
|
||||||
#if (SBC_JOINT_STE_INCLUDED == TRUE)
|
#if (SBC_JOINT_STE_INCLUDED == TRUE)
|
||||||
if (pstrEncParams->s16ChannelMode == SBC_JOINT_STEREO)
|
if (pstrEncParams->s16ChannelMode == SBC_JOINT_STEREO) {
|
||||||
{
|
|
||||||
/* pack join stero parameters */
|
/* pack join stero parameters */
|
||||||
for (s32Sb = 0; s32Sb < s32NumOfSubBands; s32Sb++)
|
for (s32Sb = 0; s32Sb < s32NumOfSubBands; s32Sb++) {
|
||||||
{
|
|
||||||
Temp <<= 1;
|
Temp <<= 1;
|
||||||
Temp |= pstrEncParams->as16Join[s32Sb];
|
Temp |= pstrEncParams->as16Join[s32Sb];
|
||||||
}
|
}
|
||||||
|
|
||||||
/* pack RFA */
|
/* pack RFA */
|
||||||
if (s32NumOfSubBands == SUB_BANDS_4)
|
if (s32NumOfSubBands == SUB_BANDS_4) {
|
||||||
{
|
|
||||||
s32PresentBit = 4;
|
s32PresentBit = 4;
|
||||||
}
|
} else {
|
||||||
else
|
*(pu8PacketPtr++) = Temp;
|
||||||
{
|
|
||||||
*(pu8PacketPtr++)=Temp;
|
|
||||||
Temp = 0;
|
Temp = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -116,21 +111,17 @@ void EncPacking(SBC_ENC_PARAMS *pstrEncParams)
|
|||||||
|
|
||||||
/* Pack Scale factor */
|
/* Pack Scale factor */
|
||||||
ps16GenPtr = pstrEncParams->as16ScaleFactor;
|
ps16GenPtr = pstrEncParams->as16ScaleFactor;
|
||||||
s32Sb=s32NumOfChannels*s32NumOfSubBands;
|
s32Sb = s32NumOfChannels * s32NumOfSubBands;
|
||||||
/*Temp=*pu8PacketPtr;*/
|
/*Temp=*pu8PacketPtr;*/
|
||||||
for (s32Ch = s32Sb; s32Ch >0; s32Ch--)
|
for (s32Ch = s32Sb; s32Ch > 0; s32Ch--) {
|
||||||
{
|
Temp <<= 4;
|
||||||
Temp<<= 4;
|
|
||||||
Temp |= *ps16GenPtr++;
|
Temp |= *ps16GenPtr++;
|
||||||
|
|
||||||
if(s32PresentBit == 4)
|
if (s32PresentBit == 4) {
|
||||||
{
|
|
||||||
s32PresentBit = 8;
|
s32PresentBit = 8;
|
||||||
*(pu8PacketPtr++)=Temp;
|
*(pu8PacketPtr++) = Temp;
|
||||||
Temp = 0;
|
Temp = 0;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
s32PresentBit = 4;
|
s32PresentBit = 4;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -138,19 +129,16 @@ void EncPacking(SBC_ENC_PARAMS *pstrEncParams)
|
|||||||
/* Pack samples */
|
/* Pack samples */
|
||||||
ps32SbPtr = pstrEncParams->s32SbBuffer;
|
ps32SbPtr = pstrEncParams->s32SbBuffer;
|
||||||
/*Temp=*pu8PacketPtr;*/
|
/*Temp=*pu8PacketPtr;*/
|
||||||
s32NumOfBlocks= pstrEncParams->s16NumOfBlocks;
|
s32NumOfBlocks = pstrEncParams->s16NumOfBlocks;
|
||||||
for (s32Blk = s32NumOfBlocks-1; s32Blk >=0; s32Blk--)
|
for (s32Blk = s32NumOfBlocks - 1; s32Blk >= 0; s32Blk--) {
|
||||||
{
|
|
||||||
ps16GenPtr = pstrEncParams->as16Bits;
|
ps16GenPtr = pstrEncParams->as16Bits;
|
||||||
ps16ScfPtr = pstrEncParams->as16ScaleFactor;
|
ps16ScfPtr = pstrEncParams->as16ScaleFactor;
|
||||||
for (s32Ch = s32Sb-1; s32Ch >= 0; s32Ch--)
|
for (s32Ch = s32Sb - 1; s32Ch >= 0; s32Ch--) {
|
||||||
{
|
|
||||||
s32LoopCount = *ps16GenPtr++;
|
s32LoopCount = *ps16GenPtr++;
|
||||||
if (s32LoopCount != 0)
|
if (s32LoopCount != 0) {
|
||||||
{
|
|
||||||
#if (SBC_IS_64_MULT_IN_QUANTIZER==TRUE)
|
#if (SBC_IS_64_MULT_IN_QUANTIZER==TRUE)
|
||||||
/* finding level from reconstruction part of decoder */
|
/* finding level from reconstruction part of decoder */
|
||||||
u32SfRaisedToPow2 = ((UINT32)1 << ((*ps16ScfPtr)+1));
|
u32SfRaisedToPow2 = ((UINT32)1 << ((*ps16ScfPtr) + 1));
|
||||||
u16Levels = (UINT16)(((UINT32)1 << s32LoopCount) - 1);
|
u16Levels = (UINT16)(((UINT32)1 << s32LoopCount) - 1);
|
||||||
|
|
||||||
/* quantizer */
|
/* quantizer */
|
||||||
@ -159,36 +147,32 @@ void EncPacking(SBC_ENC_PARAMS *pstrEncParams)
|
|||||||
|
|
||||||
Mult64 (s32Temp1, s32Temp2, s32Low, s32Hi);
|
Mult64 (s32Temp1, s32Temp2, s32Low, s32Hi);
|
||||||
|
|
||||||
s32Low1 = s32Low >> ((*ps16ScfPtr)+2);
|
s32Low1 = s32Low >> ((*ps16ScfPtr) + 2);
|
||||||
s32Low1 &= ((UINT32)1 << (32 - ((*ps16ScfPtr)+2))) - 1;
|
s32Low1 &= ((UINT32)1 << (32 - ((*ps16ScfPtr) + 2))) - 1;
|
||||||
s32Hi1 = s32Hi << (32 - ((*ps16ScfPtr) +2));
|
s32Hi1 = s32Hi << (32 - ((*ps16ScfPtr) + 2));
|
||||||
|
|
||||||
u32QuantizedSbValue0 = (UINT16)((s32Low1 | s32Hi1) >> 12);
|
u32QuantizedSbValue0 = (UINT16)((s32Low1 | s32Hi1) >> 12);
|
||||||
#else
|
#else
|
||||||
/* finding level from reconstruction part of decoder */
|
/* finding level from reconstruction part of decoder */
|
||||||
u32SfRaisedToPow2 = ((UINT32)1 << *ps16ScfPtr);
|
u32SfRaisedToPow2 = ((UINT32)1 << *ps16ScfPtr);
|
||||||
u16Levels = (UINT16)(((UINT32)1 << s32LoopCount)-1);
|
u16Levels = (UINT16)(((UINT32)1 << s32LoopCount) - 1);
|
||||||
|
|
||||||
/* quantizer */
|
/* quantizer */
|
||||||
s32Temp1 = (*ps32SbPtr >> 15) + u32SfRaisedToPow2;
|
s32Temp1 = (*ps32SbPtr >> 15) + u32SfRaisedToPow2;
|
||||||
Mult32(s32Temp1,u16Levels,s32Low);
|
Mult32(s32Temp1, u16Levels, s32Low);
|
||||||
s32Low>>= (*ps16ScfPtr+1);
|
s32Low >>= (*ps16ScfPtr + 1);
|
||||||
u32QuantizedSbValue0 = (UINT16)s32Low;
|
u32QuantizedSbValue0 = (UINT16)s32Low;
|
||||||
#endif
|
#endif
|
||||||
/*store the number of bits required and the quantized s32Sb
|
/*store the number of bits required and the quantized s32Sb
|
||||||
sample to ease the coding*/
|
sample to ease the coding*/
|
||||||
u32QuantizedSbValue = u32QuantizedSbValue0;
|
u32QuantizedSbValue = u32QuantizedSbValue0;
|
||||||
|
|
||||||
if(s32PresentBit >= s32LoopCount)
|
if (s32PresentBit >= s32LoopCount) {
|
||||||
{
|
|
||||||
Temp <<= s32LoopCount;
|
Temp <<= s32LoopCount;
|
||||||
Temp |= u32QuantizedSbValue;
|
Temp |= u32QuantizedSbValue;
|
||||||
s32PresentBit -= s32LoopCount;
|
s32PresentBit -= s32LoopCount;
|
||||||
}
|
} else {
|
||||||
else
|
while (s32PresentBit < s32LoopCount) {
|
||||||
{
|
|
||||||
while (s32PresentBit < s32LoopCount)
|
|
||||||
{
|
|
||||||
s32LoopCount -= s32PresentBit;
|
s32LoopCount -= s32PresentBit;
|
||||||
u32QuantizedSbValue >>= s32LoopCount;
|
u32QuantizedSbValue >>= s32LoopCount;
|
||||||
|
|
||||||
@ -200,9 +184,9 @@ void EncPacking(SBC_ENC_PARAMS *pstrEncParams)
|
|||||||
|
|
||||||
Temp |= u32QuantizedSbValue ;
|
Temp |= u32QuantizedSbValue ;
|
||||||
/*restore the original*/
|
/*restore the original*/
|
||||||
u32QuantizedSbValue=u32QuantizedSbValue0;
|
u32QuantizedSbValue = u32QuantizedSbValue0;
|
||||||
|
|
||||||
*(pu8PacketPtr++)=Temp;
|
*(pu8PacketPtr++) = Temp;
|
||||||
Temp = 0;
|
Temp = 0;
|
||||||
s32PresentBit = 8;
|
s32PresentBit = 8;
|
||||||
}
|
}
|
||||||
@ -223,10 +207,10 @@ void EncPacking(SBC_ENC_PARAMS *pstrEncParams)
|
|||||||
}
|
}
|
||||||
|
|
||||||
Temp <<= s32PresentBit;
|
Temp <<= s32PresentBit;
|
||||||
*pu8PacketPtr=Temp;
|
*pu8PacketPtr = Temp;
|
||||||
pstrEncParams->u16PacketLength=pu8PacketPtr-pstrEncParams->pu8NextPacket+1;
|
pstrEncParams->u16PacketLength = pu8PacketPtr - pstrEncParams->pu8NextPacket + 1;
|
||||||
/*find CRC*/
|
/*find CRC*/
|
||||||
pu8PacketPtr = pstrEncParams->pu8NextPacket+1; /*Initialize the ptr*/
|
pu8PacketPtr = pstrEncParams->pu8NextPacket + 1; /*Initialize the ptr*/
|
||||||
u8CRC = 0x0F;
|
u8CRC = 0x0F;
|
||||||
s32LoopCount = s32Sb >> 1;
|
s32LoopCount = s32Sb >> 1;
|
||||||
|
|
||||||
@ -235,28 +219,23 @@ void EncPacking(SBC_ENC_PARAMS *pstrEncParams)
|
|||||||
parameters. In case of JS, 'join' parameter is included in the packet
|
parameters. In case of JS, 'join' parameter is included in the packet
|
||||||
so that many more bytes are included in CRC calculation.
|
so that many more bytes are included in CRC calculation.
|
||||||
*/
|
*/
|
||||||
Temp=*pu8PacketPtr;
|
Temp = *pu8PacketPtr;
|
||||||
for (s32Ch=1; s32Ch < (s32LoopCount+4); s32Ch++)
|
for (s32Ch = 1; s32Ch < (s32LoopCount + 4); s32Ch++) {
|
||||||
{
|
|
||||||
/* skip sync word and CRC bytes */
|
/* skip sync word and CRC bytes */
|
||||||
if (s32Ch != 3)
|
if (s32Ch != 3) {
|
||||||
{
|
for (s32LoopCountJ = 7; s32LoopCountJ >= 0; s32LoopCountJ--) {
|
||||||
for (s32LoopCountJ=7; s32LoopCountJ>=0; s32LoopCountJ--)
|
u8XoredVal = ((u8CRC >> 7) & 0x01) ^ ((Temp >> s32LoopCountJ) & 0x01);
|
||||||
{
|
|
||||||
u8XoredVal = ((u8CRC >> 7) & 0x01) ^((Temp >> s32LoopCountJ) & 0x01);
|
|
||||||
u8CRC <<= 1;
|
u8CRC <<= 1;
|
||||||
u8CRC ^= (u8XoredVal * 0x1D);
|
u8CRC ^= (u8XoredVal * 0x1D);
|
||||||
u8CRC &= 0xFF;
|
u8CRC &= 0xFF;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Temp=*(++pu8PacketPtr);
|
Temp = *(++pu8PacketPtr);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pstrEncParams->s16ChannelMode == SBC_JOINT_STEREO)
|
if (pstrEncParams->s16ChannelMode == SBC_JOINT_STEREO) {
|
||||||
{
|
for (s32LoopCountJ = 7; s32LoopCountJ >= (8 - s32NumOfSubBands); s32LoopCountJ--) {
|
||||||
for (s32LoopCountJ = 7; s32LoopCountJ >= (8 - s32NumOfSubBands); s32LoopCountJ--)
|
u8XoredVal = ((u8CRC >> 7) & 0x01) ^ ((Temp >> s32LoopCountJ) & 0x01);
|
||||||
{
|
|
||||||
u8XoredVal = ((u8CRC >> 7) & 0x01) ^((Temp >> s32LoopCountJ) & 0x01);
|
|
||||||
u8CRC <<= 1;
|
u8CRC <<= 1;
|
||||||
u8CRC ^= (u8XoredVal * 0x1D);
|
u8CRC ^= (u8XoredVal * 0x1D);
|
||||||
u8CRC &= 0xFF;
|
u8CRC &= 0xFF;
|
||||||
@ -269,6 +248,6 @@ void EncPacking(SBC_ENC_PARAMS *pstrEncParams)
|
|||||||
pu8PacketPtr = pstrEncParams->pu8NextPacket; /*Initialize the ptr*/
|
pu8PacketPtr = pstrEncParams->pu8NextPacket; /*Initialize the ptr*/
|
||||||
pu8PacketPtr += 3;
|
pu8PacketPtr += 3;
|
||||||
*pu8PacketPtr = u8CRC;
|
*pu8PacketPtr = u8CRC;
|
||||||
pstrEncParams->pu8NextPacket+=pstrEncParams->u16PacketLength; /* move the pointer to the end in case there is more than one frame to encode */
|
pstrEncParams->pu8NextPacket += pstrEncParams->u16PacketLength; /* move the pointer to the end in case there is more than one frame to encode */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
9
examples/09_a2dp/components/bluedroid_demos/include/bt_app_common.h
Executable file → Normal file
9
examples/09_a2dp/components/bluedroid_demos/include/bt_app_common.h
Executable file → Normal file
@ -5,7 +5,7 @@
|
|||||||
#include "osi.h"
|
#include "osi.h"
|
||||||
#include "bt_common_types.h"
|
#include "bt_common_types.h"
|
||||||
#include "bt_defs.h"
|
#include "bt_defs.h"
|
||||||
|
|
||||||
/* BT APP Events */
|
/* BT APP Events */
|
||||||
#define BT_EVT_APP (0xB000)
|
#define BT_EVT_APP (0xB000)
|
||||||
#define BT_EVT_APP_CONTEXT_SWITCH (0x0001 | BT_EVT_APP)
|
#define BT_EVT_APP_CONTEXT_SWITCH (0x0001 | BT_EVT_APP)
|
||||||
@ -13,17 +13,16 @@
|
|||||||
typedef void (tBTAPP_CBACK) (uint16_t event, char *p_param);
|
typedef void (tBTAPP_CBACK) (uint16_t event, char *p_param);
|
||||||
typedef void (tBTAPP_COPY_CBACK) (uint16_t event, char *p_dest, char *p_src);
|
typedef void (tBTAPP_COPY_CBACK) (uint16_t event, char *p_dest, char *p_src);
|
||||||
|
|
||||||
typedef struct
|
typedef struct {
|
||||||
{
|
|
||||||
BT_HDR hdr;
|
BT_HDR hdr;
|
||||||
tBTAPP_CBACK* p_cb; /* context switch callback */
|
tBTAPP_CBACK *p_cb; /* context switch callback */
|
||||||
|
|
||||||
/* parameters passed to callback */
|
/* parameters passed to callback */
|
||||||
UINT16 event; /* message event id */
|
UINT16 event; /* message event id */
|
||||||
char p_param[0]; /* parameter area needs to be last */
|
char p_param[0]; /* parameter area needs to be last */
|
||||||
} tBTAPP_CONTEXT_SWITCH_CBACK;
|
} tBTAPP_CONTEXT_SWITCH_CBACK;
|
||||||
|
|
||||||
bt_status_t bt_app_transfer_context (tBTAPP_CBACK *p_cback, UINT16 event, char* p_params, int param_len, tBTAPP_COPY_CBACK *p_copy_cback);
|
bt_status_t bt_app_transfer_context (tBTAPP_CBACK *p_cback, UINT16 event, char *p_params, int param_len, tBTAPP_COPY_CBACK *p_copy_cback);
|
||||||
|
|
||||||
void bt_app_task_start_up(void);
|
void bt_app_task_start_up(void);
|
||||||
|
|
||||||
|
20
examples/09_a2dp/components/bluedroid_demos/include/bt_av.h
Executable file → Normal file
20
examples/09_a2dp/components/bluedroid_demos/include/bt_av.h
Executable file → Normal file
@ -38,14 +38,14 @@ typedef enum {
|
|||||||
/** Callback for connection state change.
|
/** Callback for connection state change.
|
||||||
* state will have one of the values from btav_connection_state_t
|
* state will have one of the values from btav_connection_state_t
|
||||||
*/
|
*/
|
||||||
typedef void (* btav_connection_state_callback)(btav_connection_state_t state,
|
typedef void (* btav_connection_state_callback)(btav_connection_state_t state,
|
||||||
bt_bdaddr_t *bd_addr);
|
bt_bdaddr_t *bd_addr);
|
||||||
|
|
||||||
/** Callback for audiopath state change.
|
/** Callback for audiopath state change.
|
||||||
* state will have one of the values from btav_audio_state_t
|
* state will have one of the values from btav_audio_state_t
|
||||||
*/
|
*/
|
||||||
typedef void (* btav_audio_state_callback)(btav_audio_state_t state,
|
typedef void (* btav_audio_state_callback)(btav_audio_state_t state,
|
||||||
bt_bdaddr_t *bd_addr);
|
bt_bdaddr_t *bd_addr);
|
||||||
|
|
||||||
/** Callback for audio configuration change.
|
/** Callback for audio configuration change.
|
||||||
* Used only for the A2DP sink interface.
|
* Used only for the A2DP sink interface.
|
||||||
@ -54,8 +54,8 @@ typedef void (* btav_audio_state_callback)(btav_audio_state_t state,
|
|||||||
* channel_count: number of channels (1 for mono, 2 for stereo)
|
* channel_count: number of channels (1 for mono, 2 for stereo)
|
||||||
*/
|
*/
|
||||||
typedef void (* btav_audio_config_callback)(bt_bdaddr_t *bd_addr,
|
typedef void (* btav_audio_config_callback)(bt_bdaddr_t *bd_addr,
|
||||||
uint32_t sample_rate,
|
uint32_t sample_rate,
|
||||||
uint8_t channel_count);
|
uint8_t channel_count);
|
||||||
|
|
||||||
/** BT-AV callback structure. */
|
/** BT-AV callback structure. */
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@ -66,15 +66,15 @@ typedef struct {
|
|||||||
btav_audio_config_callback audio_config_cb;
|
btav_audio_config_callback audio_config_cb;
|
||||||
} btav_callbacks_t;
|
} btav_callbacks_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* NOTE:
|
* NOTE:
|
||||||
*
|
*
|
||||||
* 1. AVRCP 1.0 shall be supported initially. AVRCP passthrough commands
|
* 1. AVRCP 1.0 shall be supported initially. AVRCP passthrough commands
|
||||||
* shall be handled internally via uinput
|
* shall be handled internally via uinput
|
||||||
*
|
*
|
||||||
* 2. A2DP data path shall be handled via a socket pipe between the AudioFlinger
|
* 2. A2DP data path shall be handled via a socket pipe between the AudioFlinger
|
||||||
* android_audio_hw library and the Bluetooth stack.
|
* android_audio_hw library and the Bluetooth stack.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
/** Represents the standard BT-AV interface.
|
/** Represents the standard BT-AV interface.
|
||||||
* Used for both the A2DP source and sink interfaces.
|
* Used for both the A2DP source and sink interfaces.
|
||||||
@ -86,7 +86,7 @@ typedef struct {
|
|||||||
/**
|
/**
|
||||||
* Register the BtAv callbacks
|
* Register the BtAv callbacks
|
||||||
*/
|
*/
|
||||||
bt_status_t (*init)( btav_callbacks_t* callbacks );
|
bt_status_t (*init)( btav_callbacks_t *callbacks );
|
||||||
|
|
||||||
/** connect to headset */
|
/** connect to headset */
|
||||||
bt_status_t (*connect)( bt_bdaddr_t *bd_addr );
|
bt_status_t (*connect)( bt_bdaddr_t *bd_addr );
|
||||||
|
13
examples/09_a2dp/components/bluedroid_demos/include/bt_rc.h
Executable file → Normal file
13
examples/09_a2dp/components/bluedroid_demos/include/bt_rc.h
Executable file → Normal file
@ -103,8 +103,7 @@ typedef struct {
|
|||||||
uint8_t attr_values[BTRC_MAX_APP_SETTINGS];
|
uint8_t attr_values[BTRC_MAX_APP_SETTINGS];
|
||||||
} btrc_player_settings_t;
|
} btrc_player_settings_t;
|
||||||
|
|
||||||
typedef union
|
typedef union {
|
||||||
{
|
|
||||||
btrc_play_status_t play_status;
|
btrc_play_status_t play_status;
|
||||||
btrc_uid_t track; /* queue position in NowPlaying */
|
btrc_uid_t track; /* queue position in NowPlaying */
|
||||||
uint32_t song_pos;
|
uint32_t song_pos;
|
||||||
@ -123,7 +122,7 @@ typedef struct {
|
|||||||
|
|
||||||
/** Callback for the controller's supported feautres */
|
/** Callback for the controller's supported feautres */
|
||||||
typedef void (* btrc_remote_features_callback)(bt_bdaddr_t *bd_addr,
|
typedef void (* btrc_remote_features_callback)(bt_bdaddr_t *bd_addr,
|
||||||
btrc_remote_features_t features);
|
btrc_remote_features_t features);
|
||||||
|
|
||||||
/** Callback for play status request */
|
/** Callback for play status request */
|
||||||
typedef void (* btrc_get_play_status_callback)();
|
typedef void (* btrc_get_play_status_callback)();
|
||||||
@ -197,7 +196,7 @@ typedef struct {
|
|||||||
/**
|
/**
|
||||||
* Register the BtRc callbacks
|
* Register the BtRc callbacks
|
||||||
*/
|
*/
|
||||||
bt_status_t (*init)( btrc_callbacks_t* callbacks );
|
bt_status_t (*init)( btrc_callbacks_t *callbacks );
|
||||||
|
|
||||||
/** Respose to GetPlayStatus request. Contains the current
|
/** Respose to GetPlayStatus request. Contains the current
|
||||||
** 1. Play status
|
** 1. Play status
|
||||||
@ -245,8 +244,8 @@ typedef struct {
|
|||||||
** p_params: Based on the event_id, this parameter should be populated
|
** p_params: Based on the event_id, this parameter should be populated
|
||||||
*/
|
*/
|
||||||
bt_status_t (*register_notification_rsp)(btrc_event_id_t event_id,
|
bt_status_t (*register_notification_rsp)(btrc_event_id_t event_id,
|
||||||
btrc_notification_type_t type,
|
btrc_notification_type_t type,
|
||||||
btrc_register_notification_t *p_param);
|
btrc_register_notification_t *p_param);
|
||||||
|
|
||||||
/* AVRCP 1.4 enhancements */
|
/* AVRCP 1.4 enhancements */
|
||||||
|
|
||||||
@ -282,7 +281,7 @@ typedef struct {
|
|||||||
/**
|
/**
|
||||||
* Register the BtRc callbacks
|
* Register the BtRc callbacks
|
||||||
*/
|
*/
|
||||||
bt_status_t (*init)( btrc_ctrl_callbacks_t* callbacks );
|
bt_status_t (*init)( btrc_ctrl_callbacks_t *callbacks );
|
||||||
|
|
||||||
/** send pass through command to target */
|
/** send pass through command to target */
|
||||||
bt_status_t (*send_pass_through_cmd) ( bt_bdaddr_t *bd_addr, uint8_t key_code, uint8_t key_state );
|
bt_status_t (*send_pass_through_cmd) ( bt_bdaddr_t *bd_addr, uint8_t key_code, uint8_t key_state );
|
||||||
|
2
examples/09_a2dp/components/bluedroid_demos/udrv/include/uipc.h
Executable file → Normal file
2
examples/09_a2dp/components/bluedroid_demos/udrv/include/uipc.h
Executable file → Normal file
@ -50,7 +50,7 @@ typedef enum {
|
|||||||
|
|
||||||
typedef void (tUIPC_RCV_CBACK)(tUIPC_CH_ID ch_id, tUIPC_EVENT event); /* points to BT_HDR which describes event type and length of data; len contains the number of bytes of entire message (sizeof(BT_HDR) + offset + size of data) */
|
typedef void (tUIPC_RCV_CBACK)(tUIPC_CH_ID ch_id, tUIPC_EVENT event); /* points to BT_HDR which describes event type and length of data; len contains the number of bytes of entire message (sizeof(BT_HDR) + offset + size of data) */
|
||||||
|
|
||||||
const char* dump_uipc_event(tUIPC_EVENT event);
|
const char *dump_uipc_event(tUIPC_EVENT event);
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
**
|
**
|
||||||
|
36
examples/09_a2dp/components/bluedroid_demos/udrv/ulinux/uipc.c
Executable file → Normal file
36
examples/09_a2dp/components/bluedroid_demos/udrv/ulinux/uipc.c
Executable file → Normal file
@ -42,7 +42,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
const char* dump_uipc_event(tUIPC_EVENT event)
|
const char *dump_uipc_event(tUIPC_EVENT event)
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -62,14 +62,14 @@ void UIPC_Init(void *dummy)
|
|||||||
// EspAudio_Init();
|
// EspAudio_Init();
|
||||||
|
|
||||||
{
|
{
|
||||||
int volumn;
|
int volumn;
|
||||||
// TODO: review the stream param config parameter here
|
// TODO: review the stream param config parameter here
|
||||||
EspAudioPlayerStreamCfg(StreamSampleRate_44k, 2, StreamBitLen_16BIT);
|
EspAudioPlayerStreamCfg(StreamSampleRate_44k, 2, StreamBitLen_16BIT);
|
||||||
EspAudio_SetupStream("stream.pcm", InputSrcType_Stream);
|
EspAudio_SetupStream("stream.pcm", InputSrcType_Stream);
|
||||||
EspAudio_GetVolume(&volumn);
|
EspAudio_GetVolume(&volumn);
|
||||||
LOG_ERROR("UIPC: Vol: %d\n", volumn);
|
LOG_ERROR("UIPC: Vol: %d\n", volumn);
|
||||||
EspAudio_SetVolume(99);
|
EspAudio_SetVolume(99);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,16 +85,16 @@ void UIPC_Init(void *dummy)
|
|||||||
BOOLEAN UIPC_Open(tUIPC_CH_ID ch_id, tUIPC_RCV_CBACK *p_cback)
|
BOOLEAN UIPC_Open(tUIPC_CH_ID ch_id, tUIPC_RCV_CBACK *p_cback)
|
||||||
{
|
{
|
||||||
LOG_ERROR("UIPC_Open\n");
|
LOG_ERROR("UIPC_Open\n");
|
||||||
|
|
||||||
//if (ch_id == UIPC_CH_ID_AV_AUDIO) {
|
//if (ch_id == UIPC_CH_ID_AV_AUDIO) {
|
||||||
int volumn;
|
int volumn;
|
||||||
// TODO: review the stream param config parameter here
|
// TODO: review the stream param config parameter here
|
||||||
EspAudioPlayerStreamCfg(StreamSampleRate_44k, StreamChannel_Two, StreamBitLen_16BIT);
|
EspAudioPlayerStreamCfg(StreamSampleRate_44k, StreamChannel_Two, StreamBitLen_16BIT);
|
||||||
EspAudio_SetupStream("stream.pcm", InputSrcType_Stream);
|
EspAudio_SetupStream("stream.pcm", InputSrcType_Stream);
|
||||||
EspAudio_GetVolume(&volumn);
|
EspAudio_GetVolume(&volumn);
|
||||||
LOG_ERROR("UIPC_Open: Vol: %d\n", volumn);
|
LOG_ERROR("UIPC_Open: Vol: %d\n", volumn);
|
||||||
EspAudio_SetVolume(99);
|
EspAudio_SetVolume(99);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
/*
|
/*
|
||||||
if (p_cback) {
|
if (p_cback) {
|
||||||
@ -145,9 +145,9 @@ BOOLEAN UIPC_SendBuf(tUIPC_CH_ID ch_id, BT_HDR *p_msg)
|
|||||||
BOOLEAN UIPC_Send(tUIPC_CH_ID ch_id, UINT16 msg_evt, UINT8 *p_buf, UINT16 msglen)
|
BOOLEAN UIPC_Send(tUIPC_CH_ID ch_id, UINT16 msg_evt, UINT8 *p_buf, UINT16 msglen)
|
||||||
{
|
{
|
||||||
if (ch_id == UIPC_CH_ID_AV_AUDIO) {
|
if (ch_id == UIPC_CH_ID_AV_AUDIO) {
|
||||||
uint32_t t_now = system_get_time();
|
uint32_t t_now = system_get_time();
|
||||||
printf("t: %u, l %d\n", t_now, msglen);
|
printf("t: %u, l %d\n", t_now, msglen);
|
||||||
EspAudioPlayerStreamWrite(p_buf, msglen);
|
EspAudioPlayerStreamWrite(p_buf, msglen);
|
||||||
}
|
}
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
@ -7,4 +7,4 @@
|
|||||||
# please read the ESP-IDF documents if you need to do this.
|
# please read the ESP-IDF documents if you need to do this.
|
||||||
#
|
#
|
||||||
|
|
||||||
include $(IDF_PATH)/make/component_common.mk
|
#include $(IDF_PATH)/make/component_common.mk
|
||||||
|
Loading…
x
Reference in New Issue
Block a user