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.
74 lines
1.7 KiB
74 lines
1.7 KiB
2 years ago
|
/*
|
||
|
* Copyright 2023 jacqueline <me@jacqueline.id.au>
|
||
|
*
|
||
|
* SPDX-License-Identifier: GPL-3.0-only
|
||
|
*/
|
||
|
|
||
|
#pragma once
|
||
|
|
||
1 year ago
|
#include <stdint.h>
|
||
2 years ago
|
#include <cstdint>
|
||
|
#include <memory>
|
||
|
|
||
1 year ago
|
#include "audio_events.hpp"
|
||
2 years ago
|
#include "audio_sink.hpp"
|
||
|
#include "audio_source.hpp"
|
||
|
#include "codec.hpp"
|
||
2 years ago
|
#include "resample.hpp"
|
||
|
#include "sample.hpp"
|
||
2 years ago
|
|
||
|
namespace audio {
|
||
|
|
||
|
/*
|
||
2 years ago
|
* Handle to a persistent task that converts samples between formats (sample
|
||
|
* rate, channels, bits per sample), in order to put samples in the preferred
|
||
|
* format of the current output device. The resulting samples are forwarded
|
||
|
* to the output device's sink stream.
|
||
2 years ago
|
*/
|
||
2 years ago
|
class SampleConverter {
|
||
2 years ago
|
public:
|
||
2 years ago
|
SampleConverter();
|
||
|
~SampleConverter();
|
||
2 years ago
|
|
||
2 years ago
|
auto SetOutput(std::shared_ptr<IAudioOutput>) -> void;
|
||
|
|
||
1 year ago
|
auto beginStream(std::shared_ptr<TrackInfo>) -> void;
|
||
1 year ago
|
auto continueStream(std::span<sample::Sample>) -> void;
|
||
1 year ago
|
auto endStream() -> void;
|
||
2 years ago
|
|
||
|
private:
|
||
|
auto Main() -> void;
|
||
|
|
||
1 year ago
|
auto handleBeginStream(std::shared_ptr<TrackInfo>) -> void;
|
||
|
auto handleContinueStream(size_t samples_available) -> void;
|
||
|
auto handleEndStream() -> void;
|
||
2 years ago
|
|
||
1 year ago
|
auto handleSamples(std::span<sample::Sample>) -> size_t;
|
||
1 year ago
|
|
||
1 year ago
|
auto sendToSink(std::span<sample::Sample>) -> void;
|
||
1 year ago
|
|
||
2 years ago
|
struct Args {
|
||
1 year ago
|
std::shared_ptr<TrackInfo>* track;
|
||
2 years ago
|
size_t samples_available;
|
||
|
bool is_end_of_stream;
|
||
2 years ago
|
};
|
||
|
QueueHandle_t commands_;
|
||
|
|
||
2 years ago
|
std::unique_ptr<Resampler> resampler_;
|
||
2 years ago
|
|
||
|
StreamBufferHandle_t source_;
|
||
1 year ago
|
std::span<sample::Sample> input_buffer_;
|
||
|
std::span<std::byte> input_buffer_as_bytes_;
|
||
2 years ago
|
|
||
1 year ago
|
std::span<sample::Sample> resampled_buffer_;
|
||
2 years ago
|
|
||
2 years ago
|
std::shared_ptr<IAudioOutput> sink_;
|
||
|
IAudioOutput::Format source_format_;
|
||
|
IAudioOutput::Format target_format_;
|
||
2 years ago
|
size_t leftover_bytes_;
|
||
1 year ago
|
|
||
|
uint32_t samples_sunk_;
|
||
2 years ago
|
};
|
||
|
|
||
|
} // namespace audio
|