Arduino A2DP
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
A2DPEncoderSBC Class Reference

SBC encode support for the managed A2DP encoder framework: wraps an audio_tools::SBCEncoder (codec-sbc / arduino-libsbc), advertises the SBC SEP capability and configures the encoder (subbands, blocks, allocation method and bitpool) with the parameters negotiated with the sink. Register it via BluetoothA2DPSource::add_encoder(). More...

#include <A2DPEncoderSBC.h>

Inheritance diagram for A2DPEncoderSBC:
A2DPEncoder

Public Member Functions

 A2DPEncoderSBC (audio_tools::SBCEncoder &encoder, int max_bitpool=53)
 
virtual bool begin (const esp_a2d_mcc_t &mcc)
 
void build_capability (esp_a2d_mcc_t &mcc) override
 Fills in the SEP capability advertised for this codec at registration.
 
esp_a2d_mct_t codec_type () override
 A2DP codec type this encoder handles (e.g. ESP_A2D_MCT_SBC)
 
virtual void end ()
 Closes the wrapped audio_tools encoder.
 
audio_tools::AudioInfo get_audio_info ()
 Negotiated sample rate/channels (the PCM is always provided as stereo)
 
int max_frames_per_packet () override
 Max number of encoded frames that can be combined in one media packet.
 
const char * mime () override
 MIME type of the codec this encoder produces (e.g. "audio/sbc")
 
uint16_t payload_header_size () override
 the stack adds a 1 byte SBC media payload header
 
int sample_rate ()
 Sample rate of the PCM provided by the data callbacks.
 
uint32_t samples_per_frame () override
 
void set_frame_sink (A2DPFrameSink *sink)
 Defines the target of the encoded frames.
 
void set_sample_rate (int rate)
 
virtual size_t write (const uint8_t *pcm, size_t len)
 

Protected Member Functions

void configure (const esp_a2d_mcc_t &mcc) override
 applies the negotiated SBC parameters to the encoder
 
void parse_audio_info (const esp_a2d_mcc_t &mcc) override
 
virtual void write_encoded (const uint8_t *data, size_t len)
 

Static Protected Member Functions

static uint8_t sample_rate_bit (int rate)
 

Protected Attributes

int blocks = 16
 
int channels_cfg = 2
 
FrameOutput frame_output
 
int input_sample_rate = 44100
 
int max_bitpool
 
audio_tools::AudioEncoder * p_encoder
 
audio_tools::SBCEncoder * p_sbc
 
A2DPFrameSink * p_sink = nullptr
 
int sample_rate_cfg = 44100
 
int subbands = 8
 

Detailed Description

SBC encode support for the managed A2DP encoder framework: wraps an audio_tools::SBCEncoder (codec-sbc / arduino-libsbc), advertises the SBC SEP capability and configures the encoder (subbands, blocks, allocation method and bitpool) with the parameters negotiated with the sink. Register it via BluetoothA2DPSource::add_encoder().

Author
Phil Schatzmann

Constructor & Destructor Documentation

◆ A2DPEncoderSBC()

A2DPEncoderSBC::A2DPEncoderSBC ( audio_tools::SBCEncoder &  encoder,
int  max_bitpool = 53 
)
inline

max_bitpool: upper limit for the bitpool (53 is the "high quality" setting for 44.1/48 kHz stereo)

Member Function Documentation

◆ begin()

virtual bool A2DPEncoder::begin ( const esp_a2d_mcc_t &  mcc)
inlinevirtualinherited

Opens the wrapped audio_tools encoder for the negotiated SEP configuration: calls parse_audio_info(mcc) and configure(mcc) (implemented per codec), then wires up the frame output and starts the encoder.

Reimplemented in A2DPEncoderAAC.

◆ build_capability()

void A2DPEncoderSBC::build_capability ( esp_a2d_mcc_t &  mcc)
inlineoverridevirtual

Fills in the SEP capability advertised for this codec at registration.

Implements A2DPEncoder.

◆ codec_type()

esp_a2d_mct_t A2DPEncoderSBC::codec_type ( )
inlineoverridevirtual

A2DP codec type this encoder handles (e.g. ESP_A2D_MCT_SBC)

Implements A2DPEncoder.

◆ configure()

void A2DPEncoderSBC::configure ( const esp_a2d_mcc_t &  mcc)
inlineoverrideprotectedvirtual

applies the negotiated SBC parameters to the encoder

Reimplemented from A2DPEncoder.

◆ max_frames_per_packet()

int A2DPEncoderSBC::max_frames_per_packet ( )
inlineoverridevirtual

Max number of encoded frames that can be combined in one media packet.

Reimplemented from A2DPEncoder.

◆ mime()

const char * A2DPEncoderSBC::mime ( )
inlineoverridevirtual

MIME type of the codec this encoder produces (e.g. "audio/sbc")

Implements A2DPEncoder.

◆ parse_audio_info()

void A2DPEncoderSBC::parse_audio_info ( const esp_a2d_mcc_t &  mcc)
inlineoverrideprotectedvirtual

determines sample_rate/channels from the negotiated SBC configuration (a single bit is set per field once negotiation completes)

Implements A2DPEncoder.

◆ payload_header_size()

uint16_t A2DPEncoderSBC::payload_header_size ( )
inlineoverridevirtual

the stack adds a 1 byte SBC media payload header

Reimplemented from A2DPEncoder.

◆ samples_per_frame()

uint32_t A2DPEncoderSBC::samples_per_frame ( )
inlineoverridevirtual

Number of samples (per channel) covered by one encoded frame: used for the media packet timestamps

Implements A2DPEncoder.

◆ set_sample_rate()

void A2DPEncoder::set_sample_rate ( int  rate)
inlineinherited

Defines the sample rate of the PCM provided by the data callbacks (default 44100). Call before BluetoothA2DPSource::start().

◆ write()

virtual size_t A2DPEncoder::write ( const uint8_t *  pcm,
size_t  len 
)
inlinevirtualinherited

Feeds 16 bit stereo PCM to the wrapped encoder (downmixed to mono if this was negotiated); the encoded frames are forwarded to the frame sink

◆ write_encoded()

virtual void A2DPEncoder::write_encoded ( const uint8_t *  data,
size_t  len 
)
inlineprotectedvirtualinherited

Receives the output of the wrapped encoder: by default each write is expected to be exactly one encoded frame

Reimplemented in A2DPEncoderAAC.


The documentation for this class was generated from the following file: