编解码器播放接口

[English]

公共头文件: #include "brookesia/hal_interface/audio/codec_player.hpp"

类名: AudioCodecPlayerIface

API 参考

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.

参数

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.

参数

config[in] Dynamic playback configuration.

返回

true on success; otherwise false.

virtual void close() = 0

Close the playback backend.

virtual bool set_volume(uint8_t volume) = 0

Set playback volume.

参数

volume[in] Requested output volume percentage.

返回

true on success; otherwise false.

virtual bool get_volume(uint8_t &volume) = 0

Get current playback volume.

参数

volume[out] Current output volume percentage.

返回

true on success; otherwise false.

virtual bool mute() = 0

Set playback to mute.

备注

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

返回

true on success; otherwise false.

virtual bool unmute() = 0

Unmute playback.

备注

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.

返回

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.

参数
  • data[in] Buffer pointer containing audio payload.

  • size[in] Buffer size in bytes.

返回

true on success; otherwise false.

inline const Info &get_info() const

Get static playback capability information.

返回

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.