embedded/hal_audio: rename hal_audio -> hal_audio_sink

This commit is contained in:
Matthias Ringwald 2019-02-23 23:04:54 +01:00
parent 65ec5d42b5
commit ff0081ee81
3 changed files with 55 additions and 30 deletions

View File

@ -83,8 +83,7 @@ static void driver_timer_handler_sink(btstack_timer_source_t * ts){
// playback buffer ready to fill
if (output_buffer_to_play != output_buffer_to_fill){
// fill buffer
int16_t * buffer = hal_audio_get_output_buffer(output_buffer_to_fill);
int16_t * buffer = hal_audio_sink_get_output_buffer(output_buffer_to_fill);
(*playback_callback)(buffer, output_buffer_samples);
// next
@ -114,8 +113,7 @@ static int btstack_audio_embedded_sink_init(
playback_callback = playback;
// TODO: split HAL Audio API as well
hal_audio_init(channels, samplerate, &btstack_audio_audio_played, NULL);
hal_audio_sink_init(channels, samplerate, &btstack_audio_audio_played);
return 0;
}
@ -134,13 +132,13 @@ static int btstack_audio_embedded_source_init(
static void btstack_audio_embedded_sink_start_stream(void){
output_buffer_count = hal_audio_get_num_output_buffers();
output_buffer_samples = hal_audio_get_num_output_buffer_samples();
output_buffer_count = hal_audio_sink_get_num_output_buffers();
output_buffer_samples = hal_audio_sink_get_num_output_buffer_samples();
// pre-fill HAL buffers
uint16_t i;
for (i=0;i<output_buffer_count;i++){
int16_t * buffer = hal_audio_get_output_buffer(i);
int16_t * buffer = hal_audio_sink_get_output_buffer(i);
(*playback_callback)(buffer, output_buffer_samples);
}
@ -148,7 +146,7 @@ static void btstack_audio_embedded_sink_start_stream(void){
output_buffer_to_fill = 0;
// start playback
hal_audio_start();
hal_audio_sink_start();
// start timer
btstack_run_loop_set_timer_handler(&driver_timer_sink, &driver_timer_handler_sink);
@ -164,7 +162,7 @@ static void btstack_audio_embedded_sink_close(void){
// stop timer
btstack_run_loop_remove_timer(&driver_timer_sink);
// close HAL
hal_audio_close();
hal_audio_sink_close();
}
static void btstack_audio_embedded_source_close(void){

View File

@ -52,44 +52,73 @@
*/
/**
* @brief Setup audio codec for specified samplerate and number channels
* @brief Setup audio codec for playback using specified samplerate and number of channels
* @param Channels
* @param Sample rate
* @param Buffer played callback
* @param Buffer recorded callback (use NULL if no recording)
*/
void hal_audio_init(uint8_t channels,
uint32_t sample_rate,
void (*buffer_played_callback) (uint8_t buffer_index),
void (*buffer_recorded_callback)(const int16_t * buffer, uint16_t num_samples));
void hal_audio_sink_init(uint8_t channels,
uint32_t sample_rate,
void (*buffer_played_callback)(uint8_t buffer_index));
/**
* @brief Get number of output buffers in HAL
* @returns num buffers
*/
uint16_t hal_audio_get_num_output_buffers(void);
uint16_t hal_audio_sink_get_num_output_buffers(void);
/**
* @brief Get size of single output buffer in HAL
* @returns buffer size
*/
uint16_t hal_audio_get_num_output_buffer_samples(void);
uint16_t hal_audio_sink_get_num_output_buffer_samples(void);
/**
* @brief Gey output buffer
* @brief Get output buffer
* @param buffer index
* @returns buffer
*/
int16_t * hal_audio_get_output_buffer(uint8_t buffer_index);
int16_t * hal_audio_sink_get_output_buffer(uint8_t buffer_index);
/**
* @brief Start stream
*/
void hal_audio_start(void);
void hal_audio_sink_start(void);
/**
* @brief Stop stream
*/
void hal_audio_sink_stop(void);
/**
* @brief Close audio codec
*/
void hal_audio_close(void);
void hal_audio_sink_close(void);
/**
* @brief Setup audio codec for recording using specified samplerate and number of channels
* @param Channels
* @param Sample rate
* @param Buffer recorded callback
*/
void hal_audio_source_init(uint8_t channels,
uint32_t sample_rate,
void (*buffer_recorded_callback)(const int16_t * buffer, uint16_t num_samples));
/**
* @brief Start stream
*/
void hal_audio_source_start(void);
/**
* @brief Stop stream
*/
void hal_audio_source_stop(void);
/**
* @brief Close audio codec
*/
void hal_audio_source_close(void);
#endif

View File

@ -91,13 +91,11 @@ void BSP_AUDIO_OUT_TransferComplete_CallBack(void){
* @param Buffer played callback
* @param Buffer recorded callback (use NULL if no recording)
*/
void hal_audio_init(uint8_t channels,
void hal_audio_sink_init(uint8_t channels,
uint32_t sample_rate,
void (*buffer_played_callback) (uint8_t buffer_index),
void (*buffer_recorded_callback)(const int16_t * buffer, uint16_t num_samples)){
void (*buffer_played_callback) (uint8_t buffer_index)){
audio_played_handler = buffer_played_callback;
UNUSED(buffer_recorded_callback);
BSP_AUDIO_OUT_Init(OUTPUT_DEVICE_BOTH, 80, sample_rate);
}
@ -105,7 +103,7 @@ void hal_audio_init(uint8_t channels,
* @brief Get number of output buffers in HAL
* @returns num buffers
*/
uint16_t hal_audio_get_num_output_buffers(void){
uint16_t hal_audio_sink_get_num_output_buffers(void){
return NUM_OUTPUT_BUFFERS;
}
@ -113,7 +111,7 @@ uint16_t hal_audio_get_num_output_buffers(void){
* @brief Get size of single output buffer in HAL
* @returns buffer size
*/
uint16_t hal_audio_get_num_output_buffer_samples(void){
uint16_t hal_audio_sink_get_num_output_buffer_samples(void){
return OUTPUT_BUFFER_NUM_SAMPLES;
}
@ -121,7 +119,7 @@ uint16_t hal_audio_get_num_output_buffer_samples(void){
* @brief Reserve output buffer
* @returns buffer
*/
int16_t * hal_audio_get_output_buffer(uint8_t buffer_index){
int16_t * hal_audio_sink_get_output_buffer(uint8_t buffer_index){
switch (buffer_index){
case 0:
return output_buffer;
@ -135,7 +133,7 @@ int16_t * hal_audio_get_output_buffer(uint8_t buffer_index){
/**
* @brief Start stream
*/
void hal_audio_start(void){
void hal_audio_sink_start(void){
started = 1;
// BSP_AUDIO_OUT_Play gets number bytes -> 1 frame - 16 bit/stereo = 4 bytes
BSP_AUDIO_OUT_Play( (uint16_t*) output_buffer, NUM_OUTPUT_BUFFERS * OUTPUT_BUFFER_NUM_SAMPLES * 4);
@ -144,7 +142,7 @@ void hal_audio_start(void){
/**
* @brief Close audio codec
*/
void hal_audio_close(void){
void hal_audio_sink_close(void){
started = 0;
BSP_AUDIO_OUT_Stop(CODEC_PDWN_HW);
}