mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-02-04 06:39:53 +00:00
move writter into callback
This commit is contained in:
parent
55863429e4
commit
e1df0eea7d
@ -21,7 +21,7 @@ SBC_ENCODER_OBJ = $(SBC_ENCODER:.c=.o)
|
|||||||
CFLAGS = -g -Wall -I. -I../ -I${BTSTACK_ROOT}/src -I${BTSTACK_ROOT}/src/classic -I${BTSTACK_ROOT}/platform/posix
|
CFLAGS = -g -Wall -I. -I../ -I${BTSTACK_ROOT}/src -I${BTSTACK_ROOT}/src/classic -I${BTSTACK_ROOT}/platform/posix
|
||||||
CFLAGS += -I${SBC_DECODER_ROOT}/include
|
CFLAGS += -I${SBC_DECODER_ROOT}/include
|
||||||
CFLAGS += -I${SBC_ENCODER_ROOT}/include
|
CFLAGS += -I${SBC_ENCODER_ROOT}/include
|
||||||
CFLAGS += -D PRINT_SAMPLES -D PRINT_SCALEFACTORS -D OI_DEBUG -D SBC_NO_PCM_CPY_OPTION
|
CFLAGS += -D PRINT_SAMPLES -D PRINT_SCALEFACTORS -D OI_DEBUG -D TRACE_EXECUTION
|
||||||
# -D TRACE_EXECUTION -D CODEC_DEBUG
|
# -D TRACE_EXECUTION -D CODEC_DEBUG
|
||||||
LDFLAGS += -lCppUTest -lCppUTestExt
|
LDFLAGS += -lCppUTest -lCppUTestExt
|
||||||
VPATH += ${SBC_DECODER_ROOT}/srce
|
VPATH += ${SBC_DECODER_ROOT}/srce
|
||||||
@ -47,8 +47,10 @@ sbc_encoder_test: ${SBC_DECODER_OBJ} ${SBC_ENCODER_OBJ} ${COMMON_OBJ} sbc_encode
|
|||||||
${CC} $^ ${CFLAGS} ${LDFLAGS} -o $@
|
${CC} $^ ${CFLAGS} ${LDFLAGS} -o $@
|
||||||
|
|
||||||
test: all
|
test: all
|
||||||
./sbc_decoder_test data/sine-4sb-mono msbc 1 100
|
./sbc_decoder_test data/avdtp_sink sbc 0 0
|
||||||
./sbc_encoder_test data/sine-mono.wav data/sine-4sb-mono.sbc
|
|
||||||
|
#./sbc_decoder_test data/sine-4sb-mono msbc 1 100
|
||||||
|
#./sbc_encoder_test data/sine-mono.wav data/sine-4sb-mono.sbc
|
||||||
|
|
||||||
pytest-sine:
|
pytest-sine:
|
||||||
./sbc_decoder_test.py data/sine-4sb-mono.sbc data/sine-4sb-decoded-mono.wav
|
./sbc_decoder_test.py data/sine-4sb-mono.sbc data/sine-4sb-decoded-mono.wav
|
||||||
|
@ -57,12 +57,14 @@
|
|||||||
|
|
||||||
#include "wav_util.h"
|
#include "wav_util.h"
|
||||||
|
|
||||||
static uint8_t read_buffer[24];
|
static uint8_t read_buffer[118];
|
||||||
static int total_num_samples = 0;
|
static int total_num_samples = 0;
|
||||||
static int frame_count = 0;
|
static int frame_count = 0;
|
||||||
|
static int wav_writer_opened = 0;
|
||||||
|
static char wav_filename[1000];
|
||||||
|
|
||||||
static void show_usage(void){
|
static void show_usage(void){
|
||||||
printf("\n\nUsage: ./sbc_decoder_test input_file msbc|sbc plc_enabled(0|1) corrupt_frame_period\n\n");
|
printf("\n\nUsage: ./sbc_decoder_test input_file msbc plc_enabled corrupt_frame_period \n\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
static ssize_t __read(int fd, void *buf, size_t count){
|
static ssize_t __read(int fd, void *buf, size_t count){
|
||||||
@ -80,62 +82,55 @@ static ssize_t __read(int fd, void *buf, size_t count){
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void handle_pcm_data(int16_t * data, int num_samples, int num_channels, int sample_rate, void * context){
|
static void handle_pcm_data(int16_t * data, int num_samples, int num_channels, int sample_rate, void * context){
|
||||||
wav_writer_write_int16(num_samples, data);
|
if (!wav_writer_opened){
|
||||||
total_num_samples+=num_samples;
|
wav_writer_opened = 1;
|
||||||
|
wav_writer_open(wav_filename, num_channels, sample_rate);
|
||||||
|
}
|
||||||
|
|
||||||
|
wav_writer_write_int16(num_samples*num_channels, data);
|
||||||
|
|
||||||
|
total_num_samples+=num_samples*num_channels;
|
||||||
frame_count++;
|
frame_count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main (int argc, const char * argv[]){
|
int main (int argc, const char * argv[]){
|
||||||
if (argc < 4){
|
if (argc < 5){
|
||||||
show_usage();
|
show_usage();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
btstack_sbc_mode_t mode = SBC_MODE_STANDARD;
|
|
||||||
|
|
||||||
const char * filename = argv[1];
|
|
||||||
|
|
||||||
char sbc_filename[1000];
|
char sbc_filename[1000];
|
||||||
char wav_filename[1000];
|
int argv_pos = 1;
|
||||||
|
const char * filename = argv[argv_pos++];
|
||||||
|
|
||||||
|
btstack_sbc_mode_t mode = atoi(argv[argv_pos++]) == 0? SBC_MODE_STANDARD : SBC_MODE_mSBC;
|
||||||
|
const int plc_enabled = atoi(argv[argv_pos++]);
|
||||||
|
const int corrupt_frame_period = atoi(argv[argv_pos++]);
|
||||||
|
|
||||||
strcpy(sbc_filename, filename);
|
strcpy(sbc_filename, filename);
|
||||||
strcpy(wav_filename, filename);
|
strcpy(wav_filename, filename);
|
||||||
|
|
||||||
const int plc_enabled = atoi(argv[3]);
|
|
||||||
const int corrupt_frame_period = atoi(argv[4]);
|
|
||||||
|
|
||||||
int sample_rate = 8000;
|
|
||||||
|
|
||||||
printf("\n");
|
printf("\n");
|
||||||
if (strncmp(argv[2], "msbc", 4) == 0 ){
|
|
||||||
mode = SBC_MODE_mSBC;
|
|
||||||
printf("Using SBC_MODE_mSBC mode.\n");
|
|
||||||
sample_rate = 16000;
|
|
||||||
} else {
|
|
||||||
printf("Using SBC_MODE_STANDARD mode.\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (plc_enabled){
|
|
||||||
printf("PLC enabled.\n");
|
|
||||||
} else {
|
|
||||||
printf("PLC disbled.\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (corrupt_frame_period > 0){
|
|
||||||
printf("Corrupt frame period: every %d frames.\n", corrupt_frame_period);
|
|
||||||
}
|
|
||||||
if (mode == SBC_MODE_mSBC){
|
if (mode == SBC_MODE_mSBC){
|
||||||
|
printf("Using SBC_MODE_mSBC mode.\n");
|
||||||
strcat(sbc_filename, ".msbc");
|
strcat(sbc_filename, ".msbc");
|
||||||
} else {
|
} else {
|
||||||
|
printf("Using SBC_MODE_STANDARD mode.\n");
|
||||||
strcat(sbc_filename, ".sbc");
|
strcat(sbc_filename, ".sbc");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (plc_enabled){
|
if (plc_enabled){
|
||||||
|
printf("PLC enabled.\n");
|
||||||
strcat(wav_filename, "_plc.wav");
|
strcat(wav_filename, "_plc.wav");
|
||||||
} else {
|
} else {
|
||||||
|
printf("PLC disbled.\n");
|
||||||
strcat(wav_filename, ".wav");
|
strcat(wav_filename, ".wav");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (corrupt_frame_period > 0){
|
||||||
|
printf("Corrupt frame period: every %d frames.\n", corrupt_frame_period);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int fd = open(sbc_filename, O_RDONLY);
|
int fd = open(sbc_filename, O_RDONLY);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
@ -147,11 +142,10 @@ int main (int argc, const char * argv[]){
|
|||||||
|
|
||||||
btstack_sbc_decoder_state_t state;
|
btstack_sbc_decoder_state_t state;
|
||||||
btstack_sbc_decoder_init(&state, mode, &handle_pcm_data, NULL);
|
btstack_sbc_decoder_init(&state, mode, &handle_pcm_data, NULL);
|
||||||
wav_writer_open(wav_filename, 1, sample_rate);
|
|
||||||
|
|
||||||
if (!plc_enabled){
|
//if (!plc_enabled){
|
||||||
btstack_sbc_decoder_test_disable_plc();
|
btstack_sbc_decoder_test_disable_plc();
|
||||||
}
|
//}
|
||||||
if (corrupt_frame_period > 0){
|
if (corrupt_frame_period > 0){
|
||||||
btstack_sbc_decoder_test_simulate_corrupt_frames(corrupt_frame_period);
|
btstack_sbc_decoder_test_simulate_corrupt_frames(corrupt_frame_period);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user