diff options
| author | jacqueline <me@jacqueline.id.au> | 2023-08-15 13:53:30 +1000 |
|---|---|---|
| committer | jacqueline <me@jacqueline.id.au> | 2023-08-15 13:53:30 +1000 |
| commit | d6b83fcf4a1a3039c06e0b1d1a1f7e2af2351efb (patch) | |
| tree | 03c6a534931736a2755aacef86e271ecc5b8e87c /src/audio/bt_audio_output.cpp | |
| parent | 205e3053506191fab69d01e7523e733dccc09d77 (diff) | |
| download | tangara-fw-d6b83fcf4a1a3039c06e0b1d1a1f7e2af2351efb.tar.gz | |
Flesh out basic bluetooth support
No ui yet, and performance isn't great. It kinda works though!!
Diffstat (limited to 'src/audio/bt_audio_output.cpp')
| -rw-r--r-- | src/audio/bt_audio_output.cpp | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/src/audio/bt_audio_output.cpp b/src/audio/bt_audio_output.cpp new file mode 100644 index 00000000..71e40d02 --- /dev/null +++ b/src/audio/bt_audio_output.cpp @@ -0,0 +1,79 @@ +/* + * Copyright 2023 jacqueline <me@jacqueline.id.au> + * + * SPDX-License-Identifier: GPL-3.0-only + */ + +#include "bt_audio_output.hpp" +#include <stdint.h> +#include <sys/_stdint.h> + +#include <algorithm> +#include <cstddef> +#include <cstdint> +#include <memory> +#include <variant> + +#include "esp_err.h" +#include "esp_heap_caps.h" +#include "freertos/portmacro.h" + +#include "audio_element.hpp" +#include "freertos/projdefs.h" +#include "gpios.hpp" +#include "i2c.hpp" +#include "i2s_dac.hpp" +#include "result.hpp" +#include "stream_info.hpp" +#include "wm8523.hpp" + +static const char* kTag = "BTOUT"; + +namespace audio { + +static constexpr size_t kDrainBufferSize = 48 * 1024; + +BluetoothAudioOutput::BluetoothAudioOutput(drivers::Bluetooth* bt) + : IAudioSink(kDrainBufferSize, MALLOC_CAP_SPIRAM), bluetooth_(bt) {} + +BluetoothAudioOutput::~BluetoothAudioOutput() {} + +auto BluetoothAudioOutput::SetInUse(bool in_use) -> void { + if (in_use) { + bluetooth_->SetSource(stream()); + } else { + bluetooth_->SetSource(nullptr); + } +} + +auto BluetoothAudioOutput::SetVolumeImbalance(int_fast8_t balance) -> void {} + +auto BluetoothAudioOutput::SetVolume(uint_fast8_t percent) -> void {} + +auto BluetoothAudioOutput::GetVolume() -> uint_fast8_t { + return 50; +} + +auto BluetoothAudioOutput::AdjustVolumeUp() -> bool { + return false; +} + +auto BluetoothAudioOutput::AdjustVolumeDown() -> bool { + return false; +} + +auto BluetoothAudioOutput::PrepareFormat(const Format& orig) -> Format { + // ESP-IDF's current Bluetooth implementation currently handles SBC encoding, + // but requires a fixed input format. + return Format{ + .sample_rate = 44100, + .num_channels = 2, + .bits_per_sample = 16, + }; +} + +auto BluetoothAudioOutput::Configure(const Format& fmt) -> void { + // No configuration necessary; the output format is fixed. +} + +} // namespace audio |
