forked from Green-Sky/tomato
more refactoring, audio loopback kinda working
This commit is contained in:
@ -10,12 +10,14 @@
|
||||
#include <vector>
|
||||
#include <thread>
|
||||
|
||||
// we dont have to multiplex ourself, because sdl streams and virtual devices already do this, but we do it anyway
|
||||
using SDLAudioInputFrameStream2Multiplexer = QueuedFrameStream2Multiplexer<AudioFrame>;
|
||||
using SDLAudioInputFrameStream2 = SDLAudioInputFrameStream2Multiplexer::reader_type_t; // just use the default for now
|
||||
// we dont have to multicast ourself, because sdl streams and virtual devices already do this, but we do it anyway
|
||||
using AudioFrameStream2MultiStream = FrameStream2MultiStream<AudioFrame>;
|
||||
using AudioFrameStream2 = AudioFrameStream2MultiStream::sub_stream_type_t; // just use the default for now
|
||||
|
||||
// object components?
|
||||
struct SDLAudioInputDevice : protected SDLAudioInputFrameStream2Multiplexer {
|
||||
|
||||
// source
|
||||
struct SDLAudioInputDeviceDefault : protected AudioFrameStream2MultiStream {
|
||||
std::unique_ptr<SDL_AudioStream, decltype(&SDL_DestroyAudioStream)> _stream;
|
||||
|
||||
std::atomic<bool> _thread_should_quit {false};
|
||||
@ -23,15 +25,37 @@ struct SDLAudioInputDevice : protected SDLAudioInputFrameStream2Multiplexer {
|
||||
|
||||
// construct source and start thread
|
||||
// TODO: optimize so the thread is not always running
|
||||
SDLAudioInputDevice(void);
|
||||
SDLAudioInputDeviceDefault(void);
|
||||
|
||||
// stops the thread and closes the device?
|
||||
~SDLAudioInputDevice(void);
|
||||
~SDLAudioInputDeviceDefault(void);
|
||||
|
||||
using SDLAudioInputFrameStream2Multiplexer::aquireReader;
|
||||
using SDLAudioInputFrameStream2Multiplexer::releaseReader;
|
||||
using AudioFrameStream2MultiStream::aquireSubStream;
|
||||
using AudioFrameStream2MultiStream::releaseSubStream;
|
||||
};
|
||||
|
||||
struct SDLAudioOutputDevice {
|
||||
// sink
|
||||
struct SDLAudioOutputDeviceDefaultInstance : protected AudioFrameStream2I {
|
||||
std::unique_ptr<SDL_AudioStream, decltype(&SDL_DestroyAudioStream)> _stream;
|
||||
|
||||
uint32_t _last_sample_rate {48'000};
|
||||
size_t _last_channels {0};
|
||||
SDL_AudioFormat _last_format {0};
|
||||
|
||||
SDLAudioOutputDeviceDefaultInstance(void);
|
||||
SDLAudioOutputDeviceDefaultInstance(SDLAudioOutputDeviceDefaultInstance&& other);
|
||||
|
||||
~SDLAudioOutputDeviceDefaultInstance(void);
|
||||
|
||||
int32_t size(void) override;
|
||||
std::optional<AudioFrame> pop(void) override;
|
||||
bool push(const AudioFrame& value) override;
|
||||
};
|
||||
|
||||
// constructs entirely new streams, since sdl handles sync and mixing for us (or should)
|
||||
struct SDLAudioOutputDeviceDefaultFactory {
|
||||
// TODO: pause device?
|
||||
|
||||
SDLAudioOutputDeviceDefaultInstance create(void);
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user