From 9344e45fa043156071e528e7b942c011a5e06618 Mon Sep 17 00:00:00 2001 From: Milanka Ringwald Date: Mon, 20 Mar 2017 17:03:46 +0100 Subject: [PATCH] avdpt: performance test for encoder, decoder --- port/libusb/.gitignore | 1 + test/avdtp/.gitignore | 1 + test/avdtp/Makefile | 6 +- test/avdtp/avdtp_source_test.c | 12 +- .../sine_encode_decode_performance_test.c | 143 ++++++++++++++++++ 5 files changed, 156 insertions(+), 7 deletions(-) create mode 100644 test/avdtp/sine_encode_decode_performance_test.c diff --git a/port/libusb/.gitignore b/port/libusb/.gitignore index f3950a0b7..ea8d1bf00 100644 --- a/port/libusb/.gitignore +++ b/port/libusb/.gitignore @@ -37,3 +37,4 @@ spp_streamer spp_streamer sco_input* sco_output* +le_streamer_client \ No newline at end of file diff --git a/test/avdtp/.gitignore b/test/avdtp/.gitignore index bf6f763fb..cf01bc6f6 100644 --- a/test/avdtp/.gitignore +++ b/test/avdtp/.gitignore @@ -3,6 +3,7 @@ avdtp_sink_test portaudio_test sine_encode_decode_test sine_encode_decode_ring_buffer_test +sine_encode_decode_performance_test *.sbc *.wav diff --git a/test/avdtp/Makefile b/test/avdtp/Makefile index 6c716ecfc..f8c4d449c 100644 --- a/test/avdtp/Makefile +++ b/test/avdtp/Makefile @@ -71,7 +71,7 @@ AVDTP_SINK += \ avdtp_sink.c \ btstack_ring_buffer.c \ -AVDTP_TESTS = avdtp_source_test avdtp_sink_test portaudio_test sine_encode_decode_ring_buffer_test sine_encode_decode_test +AVDTP_TESTS = avdtp_source_test avdtp_sink_test portaudio_test sine_encode_decode_ring_buffer_test sine_encode_decode_test sine_encode_decode_performance_test CORE_OBJ = $(CORE:.c=.o) COMMON_OBJ = $(COMMON:.c=.o) @@ -96,6 +96,10 @@ sine_encode_decode_test: ${CORE_OBJ} ${COMMON_OBJ} ${SBC_DECODER_OBJ} ${SBC_ENCO sine_encode_decode_ring_buffer_test: ${CORE_OBJ} ${COMMON_OBJ} ${SBC_DECODER_OBJ} ${SBC_ENCODER_OBJ} ${AVDTP_SINK_OBJ} sine_encode_decode_ring_buffer_test.c ${CC} $^ ${CFLAGS} ${LDFLAGS} -o $@ + +sine_encode_decode_performance_test: ${CORE_OBJ} ${COMMON_OBJ} ${SBC_DECODER_OBJ} ${SBC_ENCODER_OBJ} ${AVDTP_SINK_OBJ} sine_encode_decode_performance_test.c + ${CC} $^ ${CFLAGS} ${LDFLAGS} -o $@ + test: all diff --git a/test/avdtp/avdtp_source_test.c b/test/avdtp/avdtp_source_test.c index 5cf98e213..c372c5243 100644 --- a/test/avdtp/avdtp_source_test.c +++ b/test/avdtp/avdtp_source_test.c @@ -88,9 +88,9 @@ typedef struct { // pts: static bd_addr_t remote = {0x00, 0x1B, 0xDC, 0x08, 0x0A, 0xA5}; // mac 2013: static bd_addr_t remote = {0x84, 0x38, 0x35, 0x65, 0xd1, 0x15}; // phone 2013: static bd_addr_t remote = {0xD8, 0xBB, 0x2C, 0xDF, 0xF0, 0xF2}; -// minijambox: static bd_addr_t remote = {0x00, 0x21, 0x3c, 0xac, 0xf7, 0x38}; -// head phones: -static bd_addr_t remote = {0x00, 0x18, 0x09, 0x28, 0x50, 0x18}; +// minijambox: +static bd_addr_t remote = {0x00, 0x21, 0x3c, 0xac, 0xf7, 0x38}; +// head phones: static bd_addr_t remote = {0x00, 0x18, 0x09, 0x28, 0x50, 0x18}; // bt dongle: -u 02-04-01 // static bd_addr_t remote = {0x00, 0x15, 0x83, 0x5F, 0x9D, 0x46}; @@ -324,19 +324,19 @@ static void show_usage(void){ static const uint8_t media_sbc_codec_capabilities[] = { 0xFF,//(AVDTP_SBC_44100 << 4) | AVDTP_SBC_STEREO, 0xFF,//(AVDTP_SBC_BLOCK_LENGTH_16 << 4) | (AVDTP_SBC_SUBBANDS_8 << 2) | AVDTP_SBC_ALLOCATION_METHOD_LOUDNESS, - 2, 35 + 2, 53 }; static const uint8_t media_sbc_codec_configuration[] = { (AVDTP_SBC_44100 << 4) | AVDTP_SBC_STEREO, (AVDTP_SBC_BLOCK_LENGTH_16 << 4) | (AVDTP_SBC_SUBBANDS_8 << 2) | AVDTP_SBC_ALLOCATION_METHOD_LOUDNESS, - 2, 35 + 2, 53 }; static const uint8_t media_sbc_codec_reconfiguration[] = { (AVDTP_SBC_44100 << 4) | AVDTP_SBC_STEREO, (AVDTP_SBC_BLOCK_LENGTH_16 << 4) | (AVDTP_SBC_SUBBANDS_8 << 2) | AVDTP_SBC_ALLOCATION_METHOD_SNR, - 2, 35 + 2, 53 }; static void stdin_process(btstack_data_source_t *ds, btstack_data_source_callback_type_t callback_type){ diff --git a/test/avdtp/sine_encode_decode_performance_test.c b/test/avdtp/sine_encode_decode_performance_test.c new file mode 100644 index 000000000..323d4ee06 --- /dev/null +++ b/test/avdtp/sine_encode_decode_performance_test.c @@ -0,0 +1,143 @@ +/* + * Copyright (C) 2016 BlueKitchen GmbH + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holders nor the names of + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * 4. Any redistribution, use, or modification is done solely for + * personal benefit and not for any commercial purpose or for + * monetary gain. + * + * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS + * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF + * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * Please inquire about commercial licensing options at + * contact@bluekitchen-gmbh.com + * + */ + +#include +#include +#include +#include +#include + +#include "btstack_sbc.h" +#include "avdtp.h" +#include "avdtp_source.h" +#include "stdin_support.h" + +#define NUM_CHANNELS 2 +#define SAMPLE_RATE 44100 +#define BYTES_PER_AUDIO_SAMPLE (2*NUM_CHANNELS) +#define LATENCY 300 // ms + +#ifndef M_PI +#define M_PI 3.14159265 +#endif +#define TABLE_SIZE_441HZ 100 + +typedef struct { + int16_t source[TABLE_SIZE_441HZ]; + int left_phase; + int right_phase; +} paTestData; + +static uint8_t pcm_frame[2*8*16*2]; + +static paTestData sin_data; + +static btstack_sbc_mode_t mode = SBC_MODE_STANDARD; +static btstack_sbc_encoder_state_t sbc_encoder_state; +static btstack_sbc_decoder_state_t sbc_decoder_state; + +static void handle_pcm_data(int16_t * data, int num_samples, int num_channels, int sample_rate, void * context){ + UNUSED(sample_rate); + UNUSED(context); + UNUSED(data); + UNUSED(num_samples); + UNUSED(num_channels); +} + +static void fill_sine_frame(void *userData, int num_samples_to_write){ + paTestData *data = (paTestData*)userData; + int count = 0; + int offset = 0; + while (count < num_samples_to_write){ + uint8_t write_data[BYTES_PER_AUDIO_SAMPLE]; + *(int16_t*)&write_data[0] = data->source[data->left_phase]; + *(int16_t*)&write_data[2] = data->source[data->right_phase]; + + memcpy(pcm_frame+offset, write_data, BYTES_PER_AUDIO_SAMPLE); + offset += BYTES_PER_AUDIO_SAMPLE; + count++; + + data->left_phase += 1; + if (data->left_phase >= TABLE_SIZE_441HZ){ + data->left_phase -= TABLE_SIZE_441HZ; + } + data->right_phase += 1; + if (data->right_phase >= TABLE_SIZE_441HZ){ + data->right_phase -= TABLE_SIZE_441HZ; + } + } +} + +int btstack_main(int argc, const char * argv[]); +int btstack_main(int argc, const char * argv[]){ + (void) argc; + (void) argv; + btstack_sbc_encoder_init(&sbc_encoder_state, SBC_MODE_STANDARD, 16, 8, 2, 44100, 53); + + /* initialise sinusoidal wavetable */ + int i; + for (i=0; i