mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-03-29 22:20:37 +00:00
example/audio_duplex: add option to test start/stop audio driver
This commit is contained in:
parent
cbf638a901
commit
04cbc450ea
@ -42,6 +42,16 @@
|
|||||||
|
|
||||||
#include "btstack.h"
|
#include "btstack.h"
|
||||||
|
|
||||||
|
|
||||||
|
// uncomment to test start/stop of loopback / audio driver
|
||||||
|
// #define TEST_START_STOP_INTERVAL 5000
|
||||||
|
|
||||||
|
#ifdef TEST_START_STOP_INTERVAL
|
||||||
|
static void stop_loopback(btstack_timer_source_t * ts);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static btstack_timer_source_t start_stop_timer;
|
||||||
|
|
||||||
// samplerate
|
// samplerate
|
||||||
const uint32_t samplerate = 16000;
|
const uint32_t samplerate = 16000;
|
||||||
|
|
||||||
@ -106,6 +116,56 @@ static void audio_playback(int16_t * pcm_buffer, uint16_t num_samples_to_write){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void start_loopback(btstack_timer_source_t * ts){
|
||||||
|
|
||||||
|
const btstack_audio_sink_t * audio_sink = btstack_audio_sink_get_instance();
|
||||||
|
const btstack_audio_source_t * audio_source = btstack_audio_source_get_instance();
|
||||||
|
|
||||||
|
// prepare audio buffer
|
||||||
|
btstack_ring_buffer_init(&audio_buffer, (uint8_t*) &audio_buffer_storage[0], sizeof(audio_buffer_storage));
|
||||||
|
|
||||||
|
// setup audio: mono input -> stereo output
|
||||||
|
audio_sink->init(2, samplerate, &audio_playback);
|
||||||
|
audio_source->init(1, samplerate, &audio_recording);
|
||||||
|
|
||||||
|
// start duplex
|
||||||
|
audio_sink->start_stream();
|
||||||
|
audio_source->start_stream();
|
||||||
|
|
||||||
|
printf("Start Audio Loopback\n");
|
||||||
|
|
||||||
|
#ifdef TEST_START_STOP_INTERVAL
|
||||||
|
// schedule stop
|
||||||
|
btstack_run_loop_set_timer_handler(ts, &stop_loopback);
|
||||||
|
btstack_run_loop_set_timer(ts, TEST_START_STOP_INTERVAL);
|
||||||
|
btstack_run_loop_add_timer(ts);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef TEST_START_STOP_INTERVAL
|
||||||
|
static void stop_loopback(btstack_timer_source_t * ts){
|
||||||
|
const btstack_audio_sink_t * audio_sink = btstack_audio_sink_get_instance();
|
||||||
|
const btstack_audio_source_t * audio_source = btstack_audio_source_get_instance();
|
||||||
|
|
||||||
|
// stop streams
|
||||||
|
audio_sink->stop_stream();
|
||||||
|
audio_source->stop_stream();
|
||||||
|
|
||||||
|
// close audio
|
||||||
|
audio_sink->close();
|
||||||
|
audio_source->close();
|
||||||
|
|
||||||
|
playback_started = 0;
|
||||||
|
|
||||||
|
printf("Stop Audio Loopback\n");
|
||||||
|
|
||||||
|
// schedule stop
|
||||||
|
btstack_run_loop_set_timer_handler(ts, &start_loopback);
|
||||||
|
btstack_run_loop_set_timer(ts, TEST_START_STOP_INTERVAL);
|
||||||
|
btstack_run_loop_add_timer(ts);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
int btstack_main(int argc, const char * argv[]);
|
int btstack_main(int argc, const char * argv[]);
|
||||||
int btstack_main(int argc, const char * argv[]){
|
int btstack_main(int argc, const char * argv[]){
|
||||||
(void)argc;
|
(void)argc;
|
||||||
@ -124,16 +184,7 @@ int btstack_main(int argc, const char * argv[]){
|
|||||||
return 10;
|
return 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
// prepare audio buffer
|
start_loopback(&start_stop_timer);
|
||||||
btstack_ring_buffer_init(&audio_buffer, (uint8_t*) &audio_buffer_storage[0], sizeof(audio_buffer_storage));
|
|
||||||
|
|
||||||
// setup audio: mono input -> stereo output
|
|
||||||
audio_sink->init(2, samplerate, &audio_playback);
|
|
||||||
audio_source->init(1, samplerate, &audio_recording);
|
|
||||||
|
|
||||||
// start duplex
|
|
||||||
audio_sink->start_stream();
|
|
||||||
audio_source->start_stream();
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user