some sound ...

This commit is contained in:
philippe44
2019-05-25 19:42:09 -07:00
parent c77085fda3
commit 21860614e8

View File

@@ -45,8 +45,13 @@ static int bytes_per_frame;
static int _bt_write_frames(frames_t out_frames, bool silence, s32_t gainL, s32_t gainR, static int _bt_write_frames(frames_t out_frames, bool silence, s32_t gainL, s32_t gainR,
s32_t cross_gain_in, s32_t cross_gain_out, s32_t **cross_ptr); s32_t cross_gain_in, s32_t cross_gain_out, s32_t **cross_ptr);
void set_volume(unsigned left, unsigned right) {} void set_volume(unsigned left, unsigned right) {
LOG_DEBUG("setting internal gain left: %u right: %u", left, right);
LOCK;
output.gainL = left;
output.gainR = right;
UNLOCK;
}
/* event for handler "bt_av_hdl_stack_up */ /* event for handler "bt_av_hdl_stack_up */
enum { enum {
@@ -198,7 +203,6 @@ void output_init_dac(log_level level, unsigned output_buf_size, char *params, un
* Bluetooth audio source init Start * Bluetooth audio source init Start
*/ */
output_init_common(level, "-", output_buf_size, rates, idle); output_init_common(level, "-", output_buf_size, rates, idle);
//#if LINUX || OSX || FREEBSD || POSIX //#if LINUX || OSX || FREEBSD || POSIX
@@ -224,11 +228,9 @@ void output_close_dac(void) {
free(buf); free(buf);
output_close_common(); output_close_common();
} }
static u8_t *optr;
static int _bt_write_frames(frames_t out_frames, bool silence, s32_t gainL, s32_t gainR, static int _bt_write_frames(frames_t out_frames, bool silence, s32_t gainL, s32_t gainR,
s32_t cross_gain_in, s32_t cross_gain_out, s32_t **cross_ptr) { s32_t cross_gain_in, s32_t cross_gain_out, s32_t **cross_ptr) {
@@ -492,17 +494,26 @@ static void bt_app_a2d_cb(esp_a2d_cb_event_t event, esp_a2d_cb_param_t *param)
static int32_t bt_app_a2d_data_cb(uint8_t *data, int32_t len) static int32_t bt_app_a2d_data_cb(uint8_t *data, int32_t len)
{ {
frames_t frames;
int32_t ret = 0; int i;
frames_t frames=0; s16_t *optr = (s16_t*) data;
frames_t frames_wanted = 0; s32_t *iptr = (s32_t*) buf;
if (len < 0 || data == NULL) { if (len < 0 || data == NULL) {
return 0; return 0;
} }
optr = (u8_t *)data;
LOCK; LOCK;
/* TODO
Normally, we would want BT to not call us back unless we have not in BUFFERING state.
That requires BT to not start until we are > OUTPUT_BUFFER
// come back later, we are buffering (or stopped, need to handle that case ...) but we don't want silence
if (output.state <= OUTPUT_BUFFER) {
UNLOCK;
return 0;
}
*/
switch (output.format) { switch (output.format) {
case S32_LE: case S32_LE:
@@ -516,36 +527,23 @@ static int32_t bt_app_a2d_data_cb(uint8_t *data, int32_t len)
break; break;
} }
UNLOCK; // TODO update with proper bytes_per_frame handling
frames = len / 4;
frames_wanted = len / bytes_per_frame; output.device_frames = 0;
ret = len; output.updated = gettime_ms();
output.frames_played_dmp = output.frames_played;
LOCK; frames = _output_frames(frames);
UNLOCK;
output.device_frames = 0;
output.updated = gettime_ms(); for (i = 0; i < frames*2; i++) {
output.frames_played_dmp = output.frames_played; *optr++ = *iptr++ >> 16;
*optr++ = *iptr++ >> 16;
do { }
frames = _output_frames(frames_wanted);
frames_wanted -= frames; buffill = 0;
} while (frames_wanted > 0 && frames != 0);
return frames * 4;
if (frames_wanted > 0) {
LOG_DEBUG("pad with silence");
memset(optr, 0, frames_wanted * bytes_per_frame);
}
if (output.state == OUTPUT_OFF) {
LOG_INFO("output off");
ret = 0;
}
UNLOCK;
return ret;
} }
static void a2d_app_heart_beat(void *arg) static void a2d_app_heart_beat(void *arg)