bsnes/ruby/audio/audio.hpp

106 lines
4.3 KiB
C++

struct Audio;
struct AudioDriver {
AudioDriver(Audio& super) : super(super) {}
virtual ~AudioDriver() = default;
virtual auto create() -> bool { return true; }
virtual auto driverName() -> string { return "None"; }
virtual auto ready() -> bool { return true; }
virtual auto hasExclusive() -> bool { return false; }
virtual auto hasContext() -> bool { return false; }
virtual auto hasDevices() -> vector<string> { return {"Default"}; }
virtual auto hasBlocking() -> bool { return false; }
virtual auto hasDynamic() -> bool { return false; }
virtual auto hasChannels() -> vector<uint> { return {0}; }
virtual auto hasFrequencies() -> vector<uint> { return {0}; }
virtual auto hasLatencies() -> vector<uint> { return {0}; }
auto hasDevice(string device) -> bool { return (bool)hasDevices().find(device); }
auto hasChannels(uint channels) -> bool { return (bool)hasChannels().find(channels); }
auto hasFrequency(uint frequency) -> bool { return (bool)hasFrequencies().find(frequency); }
auto hasLatency(uint latency) -> bool { return (bool)hasLatencies().find(latency); }
virtual auto setExclusive(bool exclusive) -> bool { return true; }
virtual auto setContext(uintptr context) -> bool { return true; }
virtual auto setDevice(string device) -> bool { return true; }
virtual auto setBlocking(bool blocking) -> bool { return true; }
virtual auto setDynamic(bool dynamic) -> bool { return true; }
virtual auto setChannels(uint channels) -> bool { return true; }
virtual auto setFrequency(uint frequency) -> bool { return true; }
virtual auto setLatency(uint latency) -> bool { return true; }
virtual auto clear() -> void {}
virtual auto level() -> double { return 0.5; }
virtual auto output(const double samples[]) -> void {}
protected:
Audio& super;
friend class Audio;
bool exclusive = false;
uintptr context = 0;
string device = "Default";
bool blocking = false;
bool dynamic = false;
uint channels = 0;
uint frequency = 0;
uint latency = 0;
};
struct Audio {
static auto hasDrivers() -> vector<string>;
static auto hasDriver(string driver) -> bool { return (bool)hasDrivers().find(driver); }
static auto optimalDriver() -> string;
static auto safestDriver() -> string;
Audio() : self(*this) {}
explicit operator bool() const { return (bool)driver; }
auto reset() -> void { driver.reset(); }
auto create(string driver = "") -> bool;
auto driverName() -> string { return driver->driverName(); }
auto ready() -> bool { return driver->ready(); }
auto hasExclusive() -> bool { return driver->hasExclusive(); }
auto hasContext() -> bool { return driver->hasContext(); }
auto hasDevices() -> vector<string> { return driver->hasDevices(); }
auto hasBlocking() -> bool { return driver->hasBlocking(); }
auto hasDynamic() -> bool { return driver->hasDynamic(); }
auto hasChannels() -> vector<uint> { return driver->hasChannels(); }
auto hasFrequencies() -> vector<uint> { return driver->hasFrequencies(); }
auto hasLatencies() -> vector<uint> { return driver->hasLatencies(); }
auto hasDevice(string device) -> bool { return driver->hasDevice(device); }
auto hasChannels(uint channels) -> bool { return driver->hasChannels(channels); }
auto hasFrequency(uint frequency) -> bool { return driver->hasFrequency(frequency); }
auto hasLatency(uint latency) -> bool { return driver->hasLatency(latency); }
auto exclusive() -> bool { return driver->exclusive; }
auto context() -> uintptr { return driver->context; }
auto device() -> string { return driver->device; }
auto blocking() -> bool { return driver->blocking; }
auto dynamic() -> bool { return driver->dynamic; }
auto channels() -> uint { return driver->channels; }
auto frequency() -> uint { return driver->frequency; }
auto latency() -> uint { return driver->latency; }
auto setExclusive(bool exclusive) -> bool;
auto setContext(uintptr context) -> bool;
auto setDevice(string device) -> bool;
auto setBlocking(bool blocking) -> bool;
auto setDynamic(bool dynamic) -> bool;
auto setChannels(uint channels) -> bool;
auto setFrequency(uint frequency) -> bool;
auto setLatency(uint latency) -> bool;
auto clear() -> void;
auto level() -> double;
auto output(const double samples[]) -> void;
protected:
Audio& self;
unique_pointer<AudioDriver> driver;
vector<nall::DSP::Resampler::Cubic> resamplers;
};