Fork of Tangara with customizations
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tangara-fw/src/audio/include/audio_sink.hpp

48 lines
1.2 KiB

/*
* Copyright 2023 jacqueline <me@jacqueline.id.au>
*
* SPDX-License-Identifier: GPL-3.0-only
*/
#pragma once
#include <stdint.h>
#include "audio_element.hpp"
#include "esp_heap_caps.h"
#include "freertos/FreeRTOS.h"
2 years ago
#include "idf_additions.h"
#include "stream_info.hpp"
2 years ago
namespace audio {
class IAudioSink {
private:
// TODO: tune. at least about 12KiB seems right for mp3
2 years ago
static const std::size_t kDrainBufferSize = 24 * 1024;
StreamBufferHandle_t stream_;
public:
IAudioSink()
2 years ago
: stream_(xStreamBufferCreateWithCaps(
kDrainBufferSize,
1,
MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT)) {}
virtual ~IAudioSink() { vStreamBufferDeleteWithCaps(stream_); }
virtual auto SetInUse(bool) -> void {}
virtual auto SetVolumeImbalance(int_fast8_t balance) -> void = 0;
virtual auto SetVolume(uint_fast8_t percent) -> void = 0;
virtual auto GetVolume() -> uint_fast8_t = 0;
virtual auto AdjustVolumeUp() -> bool = 0;
virtual auto AdjustVolumeDown() -> bool = 0;
virtual auto Configure(const StreamInfo::Pcm& format) -> bool = 0;
virtual auto Send(const cpp::span<std::byte>& data) -> void = 0;
2 years ago
auto stream() -> StreamBufferHandle_t { return stream_; }
};
} // namespace audio