avdpt: performance test for encoder, decoder

This commit is contained in:
Milanka Ringwald 2017-03-20 17:03:46 +01:00
parent 3f8ff0dcb6
commit 9344e45fa0
5 changed files with 156 additions and 7 deletions

View File

@ -37,3 +37,4 @@ spp_streamer
spp_streamer
sco_input*
sco_output*
le_streamer_client

View File

@ -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

View File

@ -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

View File

@ -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){

View File

@ -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 <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <portaudio.h>
#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<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;
btstack_sbc_decoder_init(&sbc_decoder_state, mode, handle_pcm_data, NULL);
int num_frames = 10000;
uint32_t timestamp_start;
uint32_t encoding_time = 0;
uint32_t decoding_time = 0;
timestamp_start = btstack_run_loop_get_time_ms();
for (i=0; i<num_frames; i++){
fill_sine_frame(&sin_data, 128);
btstack_sbc_encoder_process_data((int16_t *) pcm_frame);
}
encoding_time = btstack_run_loop_get_time_ms() - timestamp_start;
timestamp_start = btstack_run_loop_get_time_ms();
for (i=0; i<num_frames; i++){
fill_sine_frame(&sin_data, 128);
btstack_sbc_encoder_process_data((int16_t *) pcm_frame);
btstack_sbc_decoder_process_data(&sbc_decoder_state, 0, btstack_sbc_encoder_sbc_buffer(), btstack_sbc_encoder_sbc_buffer_length());
}
decoding_time = btstack_run_loop_get_time_ms() - timestamp_start - encoding_time;
printf("%d frames encoded in %dms\n", num_frames, encoding_time);
printf("%d frames decoded in %dms\n", num_frames, decoding_time);
exit(0);
}