mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-03-14 01:27:41 +00:00
use sine table, fix sink
This commit is contained in:
parent
692c060596
commit
49dda2734b
@ -79,6 +79,7 @@ void avdtp_connect(bd_addr_t remote, avdtp_sep_type_t query_role, avdtp_context_
|
||||
sdp_query_context.avdtp_callback = avdtp_context->avdtp_callback;
|
||||
sdp_query_context.packet_handler = avdtp_context->packet_handler;
|
||||
|
||||
printf("packet handler %p, avdtp_callback %p\n", sdp_query_context.packet_handler, sdp_query_context.avdtp_callback);
|
||||
sdp_client_query_uuid16(&avdtp_handle_sdp_client_query_result, remote, BLUETOOTH_PROTOCOL_AVDTP);
|
||||
}
|
||||
|
||||
@ -234,6 +235,7 @@ avdtp_stream_endpoint_t * avdtp_create_stream_endpoint(avdtp_sep_type_t sep_type
|
||||
|
||||
static void handle_l2cap_data_packet_for_signaling_connection(avdtp_connection_t * connection, uint8_t *packet, uint16_t size, avdtp_context_t * context){
|
||||
int offset = avdtp_read_signaling_header(&connection->signaling_packet, packet, size);
|
||||
// printf("handle_l2cap_data_packet_for_signaling_connection \n");
|
||||
switch (connection->signaling_packet.message_type){
|
||||
case AVDTP_CMD_MSG:
|
||||
avdtp_acceptor_stream_config_subsm(connection, packet, size, offset, context);
|
||||
@ -387,16 +389,17 @@ static void avdtp_handle_sdp_client_query_result(uint8_t packet_type, uint16_t c
|
||||
if (!des_iterator_has_more(&prot_it)) continue;
|
||||
des_iterator_next(&prot_it);
|
||||
de_element_get_uint16(des_iterator_get_element(&prot_it), &avdtp_version);
|
||||
sdp_query_context.connection->state = AVDTP_SIGNALING_CONNECTION_W2_L2CAP_CONNECT;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
printf("l2cap_psm 0x%04x, avdtp_version 0x%04x\n", avdtp_l2cap_psm, avdtp_version);
|
||||
|
||||
/* Create AVDTP connection */
|
||||
printf("Create AVDTP connection, handler %p, addr %s\n", sdp_query_context.packet_handler, bd_addr_to_str(sdp_query_context.connection->remote_addr));
|
||||
sdp_query_context.connection->state = AVDTP_SIGNALING_CONNECTION_W4_L2CAP_CONNECTED;
|
||||
l2cap_create_channel(sdp_query_context.packet_handler, sdp_query_context.connection->remote_addr, avdtp_l2cap_psm, l2cap_max_mtu(), NULL);
|
||||
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@ -409,7 +412,7 @@ static void avdtp_handle_sdp_client_query_result(uint8_t packet_type, uint16_t c
|
||||
break;
|
||||
|
||||
case SDP_EVENT_QUERY_COMPLETE:
|
||||
fprintf(stderr, "General query done with status %d.\n", sdp_event_query_complete_get_status(packet));
|
||||
printf("General query done with status %d.\n", sdp_event_query_complete_get_status(packet));
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -469,9 +472,11 @@ void avdtp_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet
|
||||
local_cid = l2cap_event_incoming_connection_get_local_cid(packet);
|
||||
|
||||
connection = avdtp_connection_for_bd_addr(event_addr, context);
|
||||
if (!connection){
|
||||
|
||||
if (!connection || connection->state == AVDTP_SIGNALING_CONNECTION_W4_L2CAP_CONNECTED){
|
||||
connection = avdtp_create_connection(event_addr, context);
|
||||
connection->state = AVDTP_SIGNALING_CONNECTION_W4_L2CAP_CONNECTED;
|
||||
printf("L2CAP_EVENT_INCOMING_CONNECTION, connection %p, state connection %d\n", connection, connection->state);
|
||||
l2cap_accept_connection(local_cid);
|
||||
break;
|
||||
}
|
||||
@ -506,8 +511,8 @@ void avdtp_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet
|
||||
con_handle = l2cap_event_channel_opened_get_handle(packet);
|
||||
local_cid = l2cap_event_channel_opened_get_local_cid(packet);
|
||||
|
||||
// printf("L2CAP_EVENT_CHANNEL_OPENED: Channel successfully opened: %s, handle 0x%02x, psm 0x%02x, local cid 0x%02x, remote cid 0x%02x\n",
|
||||
// bd_addr_to_str(event_addr), con_handle, psm, local_cid, l2cap_event_channel_opened_get_remote_cid(packet));
|
||||
printf("L2CAP_EVENT_CHANNEL_OPENED: Channel successfully opened: %s, handle 0x%02x, psm 0x%02x, local cid 0x%02x, remote cid 0x%02x\n",
|
||||
bd_addr_to_str(event_addr), con_handle, psm, local_cid, l2cap_event_channel_opened_get_remote_cid(packet));
|
||||
|
||||
if (psm != BLUETOOTH_PROTOCOL_AVDTP) break;
|
||||
|
||||
|
@ -338,6 +338,7 @@ typedef struct {
|
||||
typedef enum {
|
||||
AVDTP_SIGNALING_CONNECTION_IDLE,
|
||||
AVDTP_SIGNALING_W4_SDP_QUERY_COMPLETE,
|
||||
AVDTP_SIGNALING_CONNECTION_W2_L2CAP_CONNECT,
|
||||
AVDTP_SIGNALING_CONNECTION_W4_L2CAP_CONNECTED,
|
||||
AVDTP_SIGNALING_CONNECTION_OPENED,
|
||||
AVDTP_SIGNALING_CONNECTION_W4_L2CAP_DISCONNECTED
|
||||
|
@ -86,7 +86,7 @@ static int avdtp_acceptor_validate_msg_length(avdtp_signal_identifier_t signal_i
|
||||
void avdtp_acceptor_stream_config_subsm(avdtp_connection_t * connection, uint8_t * packet, uint16_t size, int offset, avdtp_context_t * context){
|
||||
avdtp_stream_endpoint_t * stream_endpoint;
|
||||
connection->acceptor_transaction_label = connection->signaling_packet.transaction_label;
|
||||
|
||||
// printf("avdtp_acceptor_stream_config_subsm identifier %d\n", connection->signaling_packet.signal_identifier);
|
||||
if (!avdtp_acceptor_validate_msg_length(connection->signaling_packet.signal_identifier, size)) {
|
||||
connection->error_code = BAD_LENGTH;
|
||||
connection->acceptor_connection_state = AVDTP_SIGNALING_CONNECTION_ACCEPTOR_W2_REJECT_WITH_ERROR_CODE;
|
||||
|
@ -112,7 +112,7 @@ void avdtp_sink_init(void){
|
||||
avdtp_sink_context.stream_endpoints = NULL;
|
||||
avdtp_sink_context.connections = NULL;
|
||||
avdtp_sink_context.stream_endpoints_id_counter = 0;
|
||||
// TODO: assign dummy handlers;
|
||||
avdtp_sink_context.packet_handler = packet_handler;
|
||||
|
||||
l2cap_register_service(&packet_handler, BLUETOOTH_PROTOCOL_AVDTP, 0xffff, LEVEL_0);
|
||||
}
|
||||
|
@ -490,7 +490,6 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe
|
||||
break;
|
||||
}
|
||||
case AVDTP_SUBEVENT_STREAMING_CONNECTION_ESTABLISHED:
|
||||
// printf("AVDTP_SUBEVENT_STREAMING_CONNECTION_ESTABLISHED, local seid %d, remote seid index %d \n", local_stream_endpoint->sep.seid, );
|
||||
break;
|
||||
case AVDTP_SUBEVENT_SIGNALING_MEDIA_CODEC_OTHER_CAPABILITY:
|
||||
printf(" received non SBC codec. not implemented\n");
|
||||
|
@ -41,7 +41,6 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "btstack_config.h"
|
||||
#include "btstack_debug.h"
|
||||
@ -74,7 +73,6 @@
|
||||
#define TABLE_SIZE_441HZ 100
|
||||
|
||||
typedef struct {
|
||||
int16_t source[TABLE_SIZE_441HZ];
|
||||
int left_phase;
|
||||
int right_phase;
|
||||
} paTestData;
|
||||
@ -90,6 +88,19 @@ static uint8_t media_sbc_codec_capabilities[] = {
|
||||
2, 53
|
||||
};
|
||||
|
||||
static const int16_t sine_int16[] = {
|
||||
0, 2057, 4107, 6140, 8149, 10126, 12062, 13952, 15786, 17557,
|
||||
19260, 20886, 22431, 23886, 25247, 26509, 27666, 28714, 29648, 30466,
|
||||
31163, 31738, 32187, 32509, 32702, 32767, 32702, 32509, 32187, 31738,
|
||||
31163, 30466, 29648, 28714, 27666, 26509, 25247, 23886, 22431, 20886,
|
||||
19260, 17557, 15786, 13952, 12062, 10126, 8149, 6140, 4107, 2057,
|
||||
0, -2057, -4107, -6140, -8149, -10126, -12062, -13952, -15786, -17557,
|
||||
-19260, -20886, -22431, -23886, -25247, -26509, -27666, -28714, -29648, -30466,
|
||||
-31163, -31738, -32187, -32509, -32702, -32767, -32702, -32509, -32187, -31738,
|
||||
-31163, -30466, -29648, -28714, -27666, -26509, -25247, -23886, -22431, -20886,
|
||||
-19260, -17557, -15786, -13952, -12062, -10126, -8149, -6140, -4107, -2057,
|
||||
};
|
||||
|
||||
static char * device_name = "A2DP Source BTstack";
|
||||
|
||||
// mac 2011: static bd_addr_t remote = {0x04, 0x0C, 0xCE, 0xE4, 0x85, 0xD3};
|
||||
@ -221,8 +232,8 @@ static void produce_sine_audio(int16_t * pcm_buffer, void *user_data, int num_sa
|
||||
paTestData *data = (paTestData*)user_data;
|
||||
int count;
|
||||
for (count = 0; count < num_samples_to_write ; count++){
|
||||
pcm_buffer[count * 2] = data->source[data->left_phase];
|
||||
pcm_buffer[count * 2 + 1] = data->source[data->right_phase];
|
||||
pcm_buffer[count * 2] = sine_int16[data->left_phase];
|
||||
pcm_buffer[count * 2 + 1] = sine_int16[data->right_phase];
|
||||
|
||||
data->left_phase += 1;
|
||||
if (data->left_phase >= TABLE_SIZE_441HZ){
|
||||
@ -399,13 +410,6 @@ int btstack_main(int argc, const char * argv[]){
|
||||
gap_discoverable_control(1);
|
||||
gap_set_class_of_device(0x200408);
|
||||
|
||||
/* initialise sinusoidal wavetable */
|
||||
int i;
|
||||
for (i=0; i<TABLE_SIZE_441HZ; i++){
|
||||
sin_data.source[i] = sin(((double)i/(double)TABLE_SIZE_441HZ) * M_PI * 2.)*32767;
|
||||
}
|
||||
sin_data.left_phase = sin_data.right_phase = 0;
|
||||
|
||||
hxcmod_initialized = hxcmod_init(&mod_context);
|
||||
if (hxcmod_initialized){
|
||||
hxcmod_setcfg(&mod_context, A2DP_SAMPLE_RATE, 16, 1, 1, 1);
|
||||
|
Loading…
x
Reference in New Issue
Block a user