Codec Player Interface

[中文]

Public header: #include "brookesia/hal_interface/audio/codec_player.hpp"

Class: AudioCodecPlayerIface

API Reference

Header File

Classes

class AudioCodecPlayerIface : public esp_brookesia::hal::Interface

Playback interface exposed by audio-capable devices.

Public Functions

inline AudioCodecPlayerIface(Info info)

Construct an audio playback interface.

Parameters

info[in] Static playback capability information.

virtual ~AudioCodecPlayerIface() = default

Virtual destructor for polymorphic playback interfaces.

virtual bool open(const Config &config) = 0

Open the playback backend.

Parameters

config[in] Dynamic playback configuration.

Returns

true on success; otherwise false.

virtual void close() = 0

Close the playback backend.

virtual bool set_volume(uint8_t volume) = 0

Set playback volume.

Parameters

volume[in] Requested output volume percentage.

Returns

true on success; otherwise false.

virtual bool get_volume(uint8_t &volume) = 0

Get current playback volume.

Parameters

volume[out] Current output volume percentage.

Returns

true on success; otherwise false.

virtual bool mute() = 0

Set playback to mute.

Note

Calling this interface will mute the playback. Even if the minimum volume is not zero, the volume will be muted to zero.

Returns

true on success; otherwise false.

virtual bool unmute() = 0

Unmute playback.

Note

Calling this interface will set the volume to the last set value. If the last set value is zero, the volume will be restored to the default value.

Returns

true on success; otherwise false.

virtual bool write_data(const uint8_t *data, size_t size) = 0

Write PCM/encoded payload to the playback backend.

Parameters
  • data[in] Buffer pointer containing audio payload.

  • size[in] Buffer size in bytes.

Returns

true on success; otherwise false.

inline const Info &get_info() const

Get static playback capability information.

Returns

Playback information.

Public Static Attributes

static constexpr const char *NAME = "AudioCodecPlayer"

Interface registry name.

struct Config

Dynamic playback configuration.

Public Members

uint8_t bits

Sample bit width.

uint8_t channels

Number of output channels.

uint32_t sample_rate

Output sample rate in Hz.

struct Info

Static playback capability information.

Public Members

uint8_t volume_default

Default volume percentage.

uint8_t volume_min

Minimum supported volume percentage.

uint8_t volume_max

Maximum supported volume percentage.