From 35fd3fb9bcfee6840fc3705481bf7cc5d468cd11 Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Fri, 11 Nov 2016 14:06:23 +0100 Subject: [PATCH] sco_util: move sine generation into sco_util --- example/sco_demo_util.c | 73 +++++++++++++++++++++++++++++++-------- platform/posix/wav_util.c | 43 ----------------------- platform/posix/wav_util.h | 4 --- 3 files changed, 59 insertions(+), 61 deletions(-) diff --git a/example/sco_demo_util.c b/example/sco_demo_util.c index c04e4e8ed..937be539b 100644 --- a/example/sco_demo_util.c +++ b/example/sco_demo_util.c @@ -44,12 +44,14 @@ #include "sco_demo_util.h" #include "btstack_debug.h" -#include "btstack_sbc.h" -#include "btstack_cvsd_plc.h" -#include "hfp_msbc.h" -#include "hfp.h" +#include "classic/btstack_sbc.h" +#include "classic/btstack_cvsd_plc.h" +#include "classic/hfp_msbc.h" +#include "classic/hfp.h" +#ifdef HAVE_POSIX_FILE_IO #include "wav_util.h" +#endif // configure test mode #define SCO_DEMO_MODE_SINE 0 @@ -115,6 +117,58 @@ FILE * msbc_file_out; #if SCO_DEMO_MODE == SCO_DEMO_MODE_SINE +// input signal: pre-computed sine wave, at 8000 kz +static const uint8_t sine_uint8[] = { + 0, 15, 31, 46, 61, 74, 86, 97, 107, 114, + 120, 124, 126, 126, 124, 120, 114, 107, 97, 86, + 74, 61, 46, 31, 15, 0, 241, 225, 210, 195, + 182, 170, 159, 149, 142, 136, 132, 130, 130, 132, + 136, 142, 149, 159, 170, 182, 195, 210, 225, 241, +}; + + +// input signal: pre-computed sine wave, 160 Hz at 16000 kHz +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 int phase = 0; +static void sco_demo_sine_wave_int8(int num_samples, int8_t * data){ + int i; + for (i=0; i= sizeof(sine_uint8)) phase = 0; + } +} + +static void sco_demo_sine_wave_int16(int num_samples, int16_t * data){ + int i; + for (i=0; i < num_samples; i++){ + data[i] = sine_int16[phase++]; + if (phase >= (sizeof(sine_int16) / sizeof(int16_t))){ + phase = 0; + } + } +} + +static void sco_demo_fill_audio_frame(void){ + if (!hfp_msbc_can_encode_audio_frame_now()) return; + int num_samples = hfp_msbc_num_audio_samples_per_frame(); + int16_t sample_buffer[num_samples]; + sco_demo_sine_wave_int16(num_samples, sample_buffer); + hfp_msbc_encode_audio_frame(sample_buffer); + num_audio_frames++; +} #ifdef SCO_WAV_FILENAME static btstack_sbc_decoder_state_t decoder_state; @@ -178,15 +232,6 @@ static void handle_pcm_data(int16_t * data, int num_samples, int num_channels, i } } -static void sco_demo_fill_audio_frame(void){ - if (!hfp_msbc_can_encode_audio_frame_now()) return; - int num_samples = hfp_msbc_num_audio_samples_per_frame(); - int16_t sample_buffer[num_samples]; - wav_synthesize_sine_wave_int16(num_samples, sample_buffer); - hfp_msbc_encode_audio_frame(sample_buffer); - num_audio_frames++; -} - static void sco_demo_init_mSBC(void){ int sample_rate = 16000; wav_writer_open(SCO_WAV_FILENAME, 1, sample_rate); @@ -447,7 +492,7 @@ void sco_demo_send(hci_con_handle_t sco_handle){ sco_demo_fill_audio_frame(); } else { - wav_synthesize_sine_wave_int8(audio_samples_per_packet, (int8_t *) (sco_packet+3)); + sco_demo_sine_wave_int8(audio_samples_per_packet, (int8_t *) (sco_packet+3)); } #else #if SCO_DEMO_MODE == SCO_DEMO_MODE_ASCII diff --git a/platform/posix/wav_util.c b/platform/posix/wav_util.c index d55766fd4..962284522 100644 --- a/platform/posix/wav_util.c +++ b/platform/posix/wav_util.c @@ -45,31 +45,6 @@ #include "wav_util.h" #include "btstack_util.h" -static const uint8_t sine_uint8[] = { - 0, 15, 31, 46, 61, 74, 86, 97, 107, 114, - 120, 124, 126, 126, 124, 120, 114, 107, 97, 86, - 74, 61, 46, 31, 15, 0, 241, 225, 210, 195, - 182, 170, 159, 149, 142, 136, 132, 130, 130, 132, - 136, 142, 149, 159, 170, 182, 195, 210, 225, 241, -}; - - -// input signal: pre-computed sine wave, 160 Hz at 16000 kHz -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 int phase = 0; - static int wav_reader_fd; static int bytes_per_sample = 2; @@ -242,22 +217,4 @@ int wav_reader_read_int16(int num_samples, int16_t * data){ return bytes_read == num_samples*bytes_per_sample; } -void wav_synthesize_sine_wave_int8(int num_samples, int8_t * data){ - int i; - for (i=0; i= sizeof(sine_uint8)) phase = 0; - } -} - -void wav_synthesize_sine_wave_int16(int num_samples, int16_t * data){ - int i; - for (i=0; i < num_samples; i++){ - data[i] = sine_int16[phase++]; - if (phase >= (sizeof(sine_int16) / sizeof(int16_t))){ - phase = 0; - } - } -} diff --git a/platform/posix/wav_util.h b/platform/posix/wav_util.h index a3b46288a..0ed413759 100644 --- a/platform/posix/wav_util.h +++ b/platform/posix/wav_util.h @@ -55,7 +55,3 @@ int wav_reader_read_int8(int num_samples, int8_t * data); int wav_reader_read_int16(int num_samples, int16_t * data); int wav_reader_close(void); -// -void wav_synthesize_sine_wave_int8(int num_samples, int8_t * data); -void wav_synthesize_sine_wave_int16(int num_samples, int16_t * data); -