esp32-audio-player 0.1.0
Audio player engine for ESP32
Loading...
Searching...
No Matches
a2dp_sink.h File Reference

Bluetooth headphones as a player output, through the esp32-a2dp-xq library (https://github.com/olerast67/esp32-a2dp-xq; Arduino: install it from the Library Manager, ESP-IDF: add olerast67/esp32-a2dp-xq to your idf_component.yml). More...

#include "a2dp_xq.h"
#include "audio_player/player.h"
Include dependency graph for a2dp_sink.h:

Go to the source code of this file.

Functions

static int ap_a2dp_negotiate (audio_sink_t *s, const audio_format_t *src, audio_format_t *out)
 The player resamples everything to 44.1 kHz for this sink and keeps its DSP output at 32 bits; the sink adds the one TPDF dither to 16 bits.
 
static int ap_a2dp_open (audio_sink_t *s, const audio_format_t *fmt)
 
static int32_t ap_a2dp_write (audio_sink_t *s, const int32_t *pcm, uint32_t frames, uint32_t timeout_ms)
 
static void ap_a2dp_pause (audio_sink_t *s, bool paused)
 
static void ap_a2dp_flush (audio_sink_t *s)
 
static int ap_a2dp_set_volume_db (audio_sink_t *s, float db)
 
static uint32_t ap_a2dp_buffered_frames (audio_sink_t *s)
 
static void ap_a2dp_describe (audio_sink_t *s, char *out, size_t out_size)
 
static void ap_a2dp_close (audio_sink_t *s)
 
static audio_sink_t * audio_player_a2dp_sink (void)
 The sink. Call after a2dp_xq_init(); it stays valid until a2dp_xq_deinit().
 
static void audio_player_a2dp_remote (a2dp_xq_remote_t cmd, int value, void *user)
 a2dp_xq_config_t.remote_cb with remote_user = the player: the headphone buttons control the player, their own volume changes become the player volume, and a lost link pauses.
 

Detailed Description

Bluetooth headphones as a player output, through the esp32-a2dp-xq library (https://github.com/olerast67/esp32-a2dp-xq; Arduino: install it from the Library Manager, ESP-IDF: add olerast67/esp32-a2dp-xq to your idf_component.yml).

Header-only on purpose: include it in the one source file that sets up the player, so this library builds without esp32-a2dp-xq when you do not use Bluetooth.

a2dp_xq_config_t bt = A2DP_XQ_CONFIG_DEFAULT(); bt.remote_cb = audio_player_a2dp_remote; // buttons and volume on the headphones bt.remote_user = player; // set after audio_player_start() a2dp_xq_init(&bt); player_cmd_set_sink(player, audio_player_a2dp_sink());

Function Documentation

◆ ap_a2dp_buffered_frames()

static uint32_t ap_a2dp_buffered_frames ( audio_sink_t *  s)
inlinestatic

◆ ap_a2dp_close()

static void ap_a2dp_close ( audio_sink_t *  s)
inlinestatic

◆ ap_a2dp_describe()

static void ap_a2dp_describe ( audio_sink_t *  s,
char *  out,
size_t  out_size 
)
inlinestatic

◆ ap_a2dp_flush()

static void ap_a2dp_flush ( audio_sink_t *  s)
inlinestatic

◆ ap_a2dp_negotiate()

static int ap_a2dp_negotiate ( audio_sink_t *  s,
const audio_format_t *  src,
audio_format_t *  out 
)
inlinestatic

The player resamples everything to 44.1 kHz for this sink and keeps its DSP output at 32 bits; the sink adds the one TPDF dither to 16 bits.

Volume goes to the headphones over AVRCP absolute volume when they support it (SINK_CAP_HW_VOLUME), so it is never applied twice. DSD (DoP) cannot be sent over Bluetooth and is refused.

◆ ap_a2dp_open()

static int ap_a2dp_open ( audio_sink_t *  s,
const audio_format_t *  fmt 
)
inlinestatic

◆ ap_a2dp_pause()

static void ap_a2dp_pause ( audio_sink_t *  s,
bool  paused 
)
inlinestatic

◆ ap_a2dp_set_volume_db()

static int ap_a2dp_set_volume_db ( audio_sink_t *  s,
float  db 
)
inlinestatic

◆ ap_a2dp_write()

static int32_t ap_a2dp_write ( audio_sink_t *  s,
const int32_t *  pcm,
uint32_t  frames,
uint32_t  timeout_ms 
)
inlinestatic

◆ audio_player_a2dp_remote()

static void audio_player_a2dp_remote ( a2dp_xq_remote_t  cmd,
int  value,
void *  user 
)
inlinestatic

a2dp_xq_config_t.remote_cb with remote_user = the player: the headphone buttons control the player, their own volume changes become the player volume, and a lost link pauses.

< keeps the position, like most players

◆ audio_player_a2dp_sink()

static audio_sink_t * audio_player_a2dp_sink ( void  )
inlinestatic

The sink. Call after a2dp_xq_init(); it stays valid until a2dp_xq_deinit().