mirror of https://github.com/bsnes-emu/bsnes.git
Update to v103r16 release.
byuu says: Changelog: - emulator/audio: added the ability to change the output frequency at run-time without emulator reset - tomoko: display video synchronize option again¹ - tomoko: Settings→Configuration expanded to Settings→{Video, Audio, Input, Hotkey, Advanced} Settings² - tomoko: fix default population of audio settings tab - ruby: Audio::frequency is a double now (to match both Emulator::Audio and ASIO)³ - tomoko: changing the audio device will repopulate the frequency and latency lists - tomoko: changing the audio frequency can now be done in real-time - ruby/audio/asio: added missing device() information, so devices can be changed now - ruby/audio/openal: ported to new API; added device selection support - ruby/audio/wasapi: ported to new API, but did not test yet (it's assuredly still broken)⁴ ¹: I'm uneasy about this ... but, I guess if people want to disable audio and just have smooth scrolling video ... so be it. With Screwtape's documentation, hopefully that'll help people understand that video synchronization always breaks audio synchronization. I may change this to a child menu that lets you pick between {no synchronization, video synchronization, audio synchronization} as a radio selection. ²: given how much more useful the video and audio tabs are now, I felt that four extra menu items were worth saving a click and going right to the tab you want. This also matches the behavior of the Tools menu displaying all tool options and taking you directly to each tab. This is kind of a hard change to get used to ... but I think it's for the better. ³: kind of stupid because I've never seen a hardware sound card where floor(frequency) != frequency, but whatever. Yay consistency. ⁴: I'm going to move it to be event-driven, and try to support 24-bit sample formats if possible. Who knows which cards that'll fix and which cards that'll break. I may end up making multiple WASAPI drivers so people can find one that actually works for them. We'll see.
This commit is contained in:
parent
4129630d97
commit
f87c6b7ecb
|
@ -31,6 +31,13 @@ auto Audio::setInterface(Interface* interface) -> void {
|
||||||
this->interface = interface;
|
this->interface = interface;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto Audio::setFrequency(double frequency) -> void {
|
||||||
|
this->frequency = frequency;
|
||||||
|
for(auto& stream : streams) {
|
||||||
|
stream->setFrequency(stream->inputFrequency, frequency);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
auto Audio::setVolume(double volume) -> void {
|
auto Audio::setVolume(double volume) -> void {
|
||||||
this->volume = volume;
|
this->volume = volume;
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,7 @@ struct Audio {
|
||||||
auto reset(maybe<uint> channels = nothing, maybe<double> frequency = nothing) -> void;
|
auto reset(maybe<uint> channels = nothing, maybe<double> frequency = nothing) -> void;
|
||||||
auto setInterface(Interface* interface) -> void;
|
auto setInterface(Interface* interface) -> void;
|
||||||
|
|
||||||
|
auto setFrequency(double frequency) -> void;
|
||||||
auto setVolume(double volume) -> void;
|
auto setVolume(double volume) -> void;
|
||||||
auto setBalance(double balance) -> void;
|
auto setBalance(double balance) -> void;
|
||||||
auto setReverb(bool enabled) -> void;
|
auto setReverb(bool enabled) -> void;
|
||||||
|
@ -51,11 +52,13 @@ struct Filter {
|
||||||
struct Stream {
|
struct Stream {
|
||||||
auto reset(uint channels, double inputFrequency, double outputFrequency) -> void;
|
auto reset(uint channels, double inputFrequency, double outputFrequency) -> void;
|
||||||
|
|
||||||
|
auto setFrequency(double inputFrequency, maybe<double> outputFrequency = nothing) -> void;
|
||||||
|
|
||||||
auto addFilter(Filter::Order order, Filter::Type type, double cutoffFrequency, uint passes = 1) -> void;
|
auto addFilter(Filter::Order order, Filter::Type type, double cutoffFrequency, uint passes = 1) -> void;
|
||||||
|
|
||||||
auto pending() const -> bool;
|
auto pending() const -> bool;
|
||||||
auto read(double* samples) -> uint;
|
auto read(double samples[]) -> uint;
|
||||||
auto write(const double* samples) -> void;
|
auto write(const double samples[]) -> void;
|
||||||
|
|
||||||
template<typename... P> auto sample(P&&... p) -> void {
|
template<typename... P> auto sample(P&&... p) -> void {
|
||||||
double samples[sizeof...(P)] = {forward<P>(p)...};
|
double samples[sizeof...(P)] = {forward<P>(p)...};
|
||||||
|
|
|
@ -11,6 +11,15 @@ auto Stream::reset(uint channels_, double inputFrequency, double outputFrequency
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto Stream::setFrequency(double inputFrequency, maybe<double> outputFrequency) -> void {
|
||||||
|
this->inputFrequency = inputFrequency;
|
||||||
|
if(outputFrequency) this->outputFrequency = outputFrequency();
|
||||||
|
|
||||||
|
for(auto& channel : channels) {
|
||||||
|
channel.resampler.reset(this->inputFrequency, this->outputFrequency);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
auto Stream::addFilter(Filter::Order order, Filter::Type type, double cutoffFrequency, uint passes) -> void {
|
auto Stream::addFilter(Filter::Order order, Filter::Type type, double cutoffFrequency, uint passes) -> void {
|
||||||
for(auto& channel : channels) {
|
for(auto& channel : channels) {
|
||||||
for(auto pass : range(passes)) {
|
for(auto pass : range(passes)) {
|
||||||
|
@ -40,12 +49,12 @@ auto Stream::pending() const -> bool {
|
||||||
return channels && channels[0].resampler.pending();
|
return channels && channels[0].resampler.pending();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto Stream::read(double* samples) -> uint {
|
auto Stream::read(double samples[]) -> uint {
|
||||||
for(auto c : range(channels)) samples[c] = channels[c].resampler.read();
|
for(auto c : range(channels)) samples[c] = channels[c].resampler.read();
|
||||||
return channels.size();
|
return channels.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto Stream::write(const double* samples) -> void {
|
auto Stream::write(const double samples[]) -> void {
|
||||||
for(auto c : range(channels)) {
|
for(auto c : range(channels)) {
|
||||||
double sample = samples[c] + 1e-25; //constant offset used to suppress denormals
|
double sample = samples[c] + 1e-25; //constant offset used to suppress denormals
|
||||||
for(auto& filter : channels[c].filters) {
|
for(auto& filter : channels[c].filters) {
|
||||||
|
|
|
@ -12,7 +12,7 @@ using namespace nall;
|
||||||
|
|
||||||
namespace Emulator {
|
namespace Emulator {
|
||||||
static const string Name = "higan";
|
static const string Name = "higan";
|
||||||
static const string Version = "103.15";
|
static const string Version = "103.16";
|
||||||
static const string Author = "byuu";
|
static const string Author = "byuu";
|
||||||
static const string License = "GPLv3";
|
static const string License = "GPLv3";
|
||||||
static const string Website = "http://byuu.org/";
|
static const string Website = "http://byuu.org/";
|
||||||
|
|
|
@ -23,15 +23,15 @@ ifeq ($(platform),windows)
|
||||||
ruby += input.windows
|
ruby += input.windows
|
||||||
else ifeq ($(platform),macosx)
|
else ifeq ($(platform),macosx)
|
||||||
ruby += #video.cgl
|
ruby += #video.cgl
|
||||||
ruby += #audio.openal
|
ruby += audio.openal
|
||||||
ruby += #input.quartz input.carbon
|
ruby += #input.quartz input.carbon
|
||||||
else ifeq ($(platform),linux)
|
else ifeq ($(platform),linux)
|
||||||
ruby += video.xshm #video.glx video.xv video.xshm video.sdl
|
ruby += video.xshm #video.glx video.xv video.xshm video.sdl
|
||||||
ruby += audio.oss #audio.alsa audio.openal audio.oss audio.pulseaudio audio.pulseaudiosimple audio.ao
|
ruby += audio.oss audio.openal #audio.alsa audio.oss audio.pulseaudio audio.pulseaudiosimple audio.ao
|
||||||
ruby += input.sdl input.xlib #input.udev input.sdl input.xlib
|
ruby += input.sdl input.xlib #input.udev input.sdl input.xlib
|
||||||
else ifeq ($(platform),bsd)
|
else ifeq ($(platform),bsd)
|
||||||
ruby += video.xshm #video.glx video.xv video.xshm video.sdl
|
ruby += video.xshm #video.glx video.xv video.xshm video.sdl
|
||||||
ruby += audio.oss #audio.alsa
|
ruby += audio.oss audio.openal
|
||||||
ruby += input.sdl input.xlib
|
ruby += input.sdl input.xlib
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
|
|
@ -50,7 +50,6 @@ Settings::Settings() {
|
||||||
set("Audio/Volume", 100);
|
set("Audio/Volume", 100);
|
||||||
set("Audio/Balance", 50);
|
set("Audio/Balance", 50);
|
||||||
set("Audio/Reverb/Enable", false);
|
set("Audio/Reverb/Enable", false);
|
||||||
set("Audio/Resampler", "Sinc");
|
|
||||||
|
|
||||||
set("Input/Driver", ruby::Input::optimalDriver());
|
set("Input/Driver", ruby::Input::optimalDriver());
|
||||||
set("Input/Frequency", 5);
|
set("Input/Frequency", 5);
|
||||||
|
|
|
@ -82,7 +82,7 @@ Presentation::Presentation() {
|
||||||
program->updateVideoShader();
|
program->updateVideoShader();
|
||||||
});
|
});
|
||||||
loadShaders();
|
loadShaders();
|
||||||
synchronizeVideo.setText("Synchronize Video").setChecked(settings["Video/Synchronize"].boolean()).setVisible(false).onToggle([&] {
|
synchronizeVideo.setText("Synchronize Video").setChecked(settings["Video/Synchronize"].boolean()).onToggle([&] {
|
||||||
settings["Video/Synchronize"].setValue(synchronizeVideo.checked());
|
settings["Video/Synchronize"].setValue(synchronizeVideo.checked());
|
||||||
video->setBlocking(synchronizeVideo.checked());
|
video->setBlocking(synchronizeVideo.checked());
|
||||||
});
|
});
|
||||||
|
@ -99,20 +99,23 @@ Presentation::Presentation() {
|
||||||
statusBar.setVisible(showStatusBar.checked());
|
statusBar.setVisible(showStatusBar.checked());
|
||||||
if(visible()) resizeViewport();
|
if(visible()) resizeViewport();
|
||||||
});
|
});
|
||||||
showConfiguration.setText("Configuration ...").onActivate([&] {
|
showVideoSettings.setText("Video Settings ...").onActivate([&] { settingsManager->show(0); });
|
||||||
//if no emulation core active; default to hotkeys panel
|
showAudioSettings.setText("Audio Settings ...").onActivate([&] { settingsManager->show(1); });
|
||||||
if(!emulator) return settingsManager->show(3);
|
showInputSettings.setText("Input Settings ...").onActivate([&] {
|
||||||
|
if(emulator) {
|
||||||
//default to input panel with current core's input settings active
|
//default input panel to current core's input settings
|
||||||
for(auto item : settingsManager->input.emulatorList.items()) {
|
for(auto item : settingsManager->input.emulatorList.items()) {
|
||||||
if(systemMenu.text() == item.text()) {
|
if(systemMenu.text() == item.text()) {
|
||||||
item.setSelected();
|
item.setSelected();
|
||||||
settingsManager->input.emulatorList.doChange();
|
settingsManager->input.emulatorList.doChange();
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
settingsManager->show(2);
|
settingsManager->show(2);
|
||||||
});
|
});
|
||||||
|
showHotkeySettings.setText("Hotkey Settings ...").onActivate([&] { settingsManager->show(3); });
|
||||||
|
showAdvancedSettings.setText("Advanced Settings ...").onActivate([&] { settingsManager->show(4); });
|
||||||
|
|
||||||
toolsMenu.setText("Tools").setVisible(false);
|
toolsMenu.setText("Tools").setVisible(false);
|
||||||
saveQuickStateMenu.setText("Save Quick State");
|
saveQuickStateMenu.setText("Save Quick State");
|
||||||
|
|
|
@ -43,8 +43,12 @@ struct Presentation : Window {
|
||||||
MenuCheckItem synchronizeAudio{&settingsMenu};
|
MenuCheckItem synchronizeAudio{&settingsMenu};
|
||||||
MenuCheckItem muteAudio{&settingsMenu};
|
MenuCheckItem muteAudio{&settingsMenu};
|
||||||
MenuCheckItem showStatusBar{&settingsMenu};
|
MenuCheckItem showStatusBar{&settingsMenu};
|
||||||
MenuSeparator showConfigurationSeparator{&settingsMenu};
|
MenuSeparator settingsSeparator{&settingsMenu};
|
||||||
MenuItem showConfiguration{&settingsMenu};
|
MenuItem showVideoSettings{&settingsMenu};
|
||||||
|
MenuItem showAudioSettings{&settingsMenu};
|
||||||
|
MenuItem showInputSettings{&settingsMenu};
|
||||||
|
MenuItem showHotkeySettings{&settingsMenu};
|
||||||
|
MenuItem showAdvancedSettings{&settingsMenu};
|
||||||
Menu toolsMenu{&menuBar};
|
Menu toolsMenu{&menuBar};
|
||||||
Menu saveQuickStateMenu{&toolsMenu};
|
Menu saveQuickStateMenu{&toolsMenu};
|
||||||
MenuItem saveSlot1{&saveQuickStateMenu};
|
MenuItem saveSlot1{&saveQuickStateMenu};
|
||||||
|
|
|
@ -38,13 +38,12 @@ Program::Program(string_vector args) {
|
||||||
video->setContext(presentation->viewport.handle());
|
video->setContext(presentation->viewport.handle());
|
||||||
video->setBlocking(settings["Video/Synchronize"].boolean());
|
video->setBlocking(settings["Video/Synchronize"].boolean());
|
||||||
if(!video->ready()) MessageDialog().setText("Failed to initialize video driver").warning();
|
if(!video->ready()) MessageDialog().setText("Failed to initialize video driver").warning();
|
||||||
|
|
||||||
presentation->clearViewport();
|
presentation->clearViewport();
|
||||||
|
|
||||||
audio = Audio::create(settings["Audio/Driver"].text());
|
audio = Audio::create(settings["Audio/Driver"].text());
|
||||||
audio->setContext(presentation->viewport.handle());
|
audio->setContext(presentation->viewport.handle());
|
||||||
|
audio->setDevice(settings["Audio/Device"].text());
|
||||||
audio->setBlocking(settings["Audio/Synchronize"].boolean());
|
audio->setBlocking(settings["Audio/Synchronize"].boolean());
|
||||||
audio->setFrequency(settings["Audio/Frequency"].natural());
|
|
||||||
audio->setChannels(2);
|
audio->setChannels(2);
|
||||||
if(!audio->ready()) MessageDialog().setText("Failed to initialize audio driver").warning();
|
if(!audio->ready()) MessageDialog().setText("Failed to initialize audio driver").warning();
|
||||||
|
|
||||||
|
|
|
@ -80,8 +80,9 @@ auto Program::updateAudioDriver() -> void {
|
||||||
audio->clear();
|
audio->clear();
|
||||||
audio->setDevice(settings["Audio/Device"].text());
|
audio->setDevice(settings["Audio/Device"].text());
|
||||||
audio->setExclusive(settings["Audio/Exclusive"].boolean());
|
audio->setExclusive(settings["Audio/Exclusive"].boolean());
|
||||||
//audio->setFrequency(settings["Audio/Frequency"].natural());
|
audio->setFrequency(settings["Audio/Frequency"].real());
|
||||||
audio->setLatency(settings["Audio/Latency"].natural());
|
audio->setLatency(settings["Audio/Latency"].natural());
|
||||||
|
Emulator::audio.setFrequency(settings["Audio/Frequency"].real());
|
||||||
}
|
}
|
||||||
|
|
||||||
auto Program::updateAudioEffects() -> void {
|
auto Program::updateAudioEffects() -> void {
|
||||||
|
|
|
@ -6,33 +6,13 @@ AudioSettings::AudioSettings(TabFrame* parent) : TabFrameItem(parent) {
|
||||||
|
|
||||||
driverLabel.setFont(Font().setBold()).setText("Driver Settings");
|
driverLabel.setFont(Font().setBold()).setText("Driver Settings");
|
||||||
|
|
||||||
auto information = audio->information();
|
|
||||||
|
|
||||||
deviceLabel.setText("Device:");
|
deviceLabel.setText("Device:");
|
||||||
for(auto& device : information.devices) {
|
deviceList.onChange([&] { updateDriver(); updateDriverLists(); });
|
||||||
deviceList.append(ComboButtonItem().setText(device));
|
|
||||||
if(device == settings["Audio/Device"].text()) {
|
|
||||||
deviceList.item(deviceList.itemCount() - 1).setSelected();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
deviceList.onChange([&] { updateDriver(); });
|
|
||||||
|
|
||||||
frequencyLabel.setText("Frequency:");
|
frequencyLabel.setText("Frequency:");
|
||||||
for(auto& frequency : information.frequencies) {
|
|
||||||
frequencyList.append(ComboButtonItem().setText(frequency));
|
|
||||||
if(frequency == settings["Audio/Frequency"].natural()) {
|
|
||||||
frequencyList.item(frequencyList.itemCount() - 1).setSelected();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
frequencyList.onChange([&] { updateDriver(); });
|
frequencyList.onChange([&] { updateDriver(); });
|
||||||
|
|
||||||
latencyLabel.setText("Latency:");
|
latencyLabel.setText("Latency:");
|
||||||
for(auto& latency : information.latencies) {
|
|
||||||
latencyList.append(ComboButtonItem().setText(latency));
|
|
||||||
if(latency == settings["Audio/Latency"].natural()) {
|
|
||||||
latencyList.item(latencyList.itemCount() - 1).setSelected();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
latencyList.onChange([&] { updateDriver(); });
|
latencyList.onChange([&] { updateDriver(); });
|
||||||
|
|
||||||
exclusiveMode.setText("Exclusive mode");
|
exclusiveMode.setText("Exclusive mode");
|
||||||
|
@ -50,19 +30,24 @@ AudioSettings::AudioSettings(TabFrame* parent) : TabFrameItem(parent) {
|
||||||
|
|
||||||
reverbEnable.setText("Reverb").setChecked(settings["Audio/Reverb/Enable"].boolean()).onToggle([&] { updateEffects(); });
|
reverbEnable.setText("Reverb").setChecked(settings["Audio/Reverb/Enable"].boolean()).onToggle([&] { updateEffects(); });
|
||||||
|
|
||||||
updateDriver();
|
updateDriverLists();
|
||||||
updateEffects();
|
updateDriver(true);
|
||||||
|
updateEffects(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto AudioSettings::updateDriver() -> void {
|
//when changing audio drivers, device/frequency/latency values may no longer be valid for new driver
|
||||||
|
//updateDriverLists() will try to select a match if one is found
|
||||||
|
//otherwise, this function will force now-invalid settings to the first setting in each list
|
||||||
|
auto AudioSettings::updateDriver(bool initializing) -> void {
|
||||||
settings["Audio/Device"].setValue(deviceList.selected().text());
|
settings["Audio/Device"].setValue(deviceList.selected().text());
|
||||||
settings["Audio/Frequency"].setValue(frequencyList.selected().text());
|
settings["Audio/Frequency"].setValue(frequencyList.selected().text());
|
||||||
settings["Audio/Latency"].setValue(latencyList.selected().text());
|
settings["Audio/Latency"].setValue(latencyList.selected().text());
|
||||||
settings["Audio/Exclusive"].setValue(exclusiveMode.checked());
|
settings["Audio/Exclusive"].setValue(exclusiveMode.checked());
|
||||||
program->updateAudioDriver();
|
|
||||||
|
if(!initializing) program->updateAudioDriver();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto AudioSettings::updateEffects() -> void {
|
auto AudioSettings::updateEffects(bool initializing) -> void {
|
||||||
settings["Audio/Volume"].setValue(volumeSlider.position());
|
settings["Audio/Volume"].setValue(volumeSlider.position());
|
||||||
volumeValue.setText({volumeSlider.position(), "%"});
|
volumeValue.setText({volumeSlider.position(), "%"});
|
||||||
|
|
||||||
|
@ -71,5 +56,35 @@ auto AudioSettings::updateEffects() -> void {
|
||||||
|
|
||||||
settings["Audio/Reverb/Enable"].setValue(reverbEnable.checked());
|
settings["Audio/Reverb/Enable"].setValue(reverbEnable.checked());
|
||||||
|
|
||||||
program->updateAudioEffects();
|
if(!initializing) program->updateAudioEffects();
|
||||||
|
}
|
||||||
|
|
||||||
|
//called during initialization, and after changing audio device
|
||||||
|
//each audio device may have separately supported frequencies and/or latencies
|
||||||
|
auto AudioSettings::updateDriverLists() -> void {
|
||||||
|
auto information = audio->information();
|
||||||
|
|
||||||
|
deviceList.reset();
|
||||||
|
for(auto& device : information.devices) {
|
||||||
|
deviceList.append(ComboButtonItem().setText(device));
|
||||||
|
if(device == settings["Audio/Device"].text()) {
|
||||||
|
deviceList.item(deviceList.itemCount() - 1).setSelected();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
frequencyList.reset();
|
||||||
|
for(auto& frequency : information.frequencies) {
|
||||||
|
frequencyList.append(ComboButtonItem().setText(frequency));
|
||||||
|
if(frequency == settings["Audio/Frequency"].real()) {
|
||||||
|
frequencyList.item(frequencyList.itemCount() - 1).setSelected();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
latencyList.reset();
|
||||||
|
for(auto& latency : information.latencies) {
|
||||||
|
latencyList.append(ComboButtonItem().setText(latency));
|
||||||
|
if(latency == settings["Audio/Latency"].natural()) {
|
||||||
|
latencyList.item(latencyList.itemCount() - 1).setSelected();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,26 +63,13 @@ struct AudioSettings : TabFrameItem {
|
||||||
HorizontalSlider balanceSlider{&balanceLayout, Size{~0, 0}};
|
HorizontalSlider balanceSlider{&balanceLayout, Size{~0, 0}};
|
||||||
CheckLabel reverbEnable{&layout, Size{~0, 0}};
|
CheckLabel reverbEnable{&layout, Size{~0, 0}};
|
||||||
|
|
||||||
auto updateDriver() -> void;
|
auto updateDriver(bool initializing = false) -> void;
|
||||||
auto updateEffects() -> void;
|
auto updateEffects(bool initializing = false) -> void;
|
||||||
|
auto updateDriverLists() -> void;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct InputSettings : TabFrameItem {
|
struct InputSettings : TabFrameItem {
|
||||||
InputSettings(TabFrame*);
|
InputSettings(TabFrame*);
|
||||||
auto updateControls() -> void;
|
|
||||||
auto activeEmulator() -> InputEmulator&;
|
|
||||||
auto activePort() -> InputPort&;
|
|
||||||
auto activeDevice() -> InputDevice&;
|
|
||||||
auto reloadPorts() -> void;
|
|
||||||
auto reloadDevices() -> void;
|
|
||||||
auto reloadMappings() -> void;
|
|
||||||
auto refreshMappings() -> void;
|
|
||||||
auto assignMapping() -> void;
|
|
||||||
auto assignMouseInput(uint id) -> void;
|
|
||||||
auto inputEvent(shared_pointer<HID::Device> device, uint group, uint input, int16 oldValue, int16 newValue, bool allowMouseInput = false) -> void;
|
|
||||||
|
|
||||||
InputMapping* activeMapping = nullptr;
|
|
||||||
Timer timer;
|
|
||||||
|
|
||||||
VerticalLayout layout{this};
|
VerticalLayout layout{this};
|
||||||
HorizontalLayout focusLayout{&layout, Size{~0, 0}};
|
HorizontalLayout focusLayout{&layout, Size{~0, 0}};
|
||||||
|
@ -101,17 +88,25 @@ struct InputSettings : TabFrameItem {
|
||||||
Widget spacer{&controlLayout, Size{~0, 0}};
|
Widget spacer{&controlLayout, Size{~0, 0}};
|
||||||
Button resetButton{&controlLayout, Size{80, 0}};
|
Button resetButton{&controlLayout, Size{80, 0}};
|
||||||
Button eraseButton{&controlLayout, Size{80, 0}};
|
Button eraseButton{&controlLayout, Size{80, 0}};
|
||||||
|
|
||||||
|
auto updateControls() -> void;
|
||||||
|
auto activeEmulator() -> InputEmulator&;
|
||||||
|
auto activePort() -> InputPort&;
|
||||||
|
auto activeDevice() -> InputDevice&;
|
||||||
|
auto reloadPorts() -> void;
|
||||||
|
auto reloadDevices() -> void;
|
||||||
|
auto reloadMappings() -> void;
|
||||||
|
auto refreshMappings() -> void;
|
||||||
|
auto assignMapping() -> void;
|
||||||
|
auto assignMouseInput(uint id) -> void;
|
||||||
|
auto inputEvent(shared_pointer<HID::Device> device, uint group, uint input, int16 oldValue, int16 newValue, bool allowMouseInput = false) -> void;
|
||||||
|
|
||||||
|
InputMapping* activeMapping = nullptr;
|
||||||
|
Timer timer;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct HotkeySettings : TabFrameItem {
|
struct HotkeySettings : TabFrameItem {
|
||||||
HotkeySettings(TabFrame*);
|
HotkeySettings(TabFrame*);
|
||||||
auto reloadMappings() -> void;
|
|
||||||
auto refreshMappings() -> void;
|
|
||||||
auto assignMapping() -> void;
|
|
||||||
auto inputEvent(shared_pointer<HID::Device> device, uint group, uint input, int16 oldValue, int16 newValue) -> void;
|
|
||||||
|
|
||||||
InputMapping* activeMapping = nullptr;
|
|
||||||
Timer timer;
|
|
||||||
|
|
||||||
VerticalLayout layout{this};
|
VerticalLayout layout{this};
|
||||||
TableView mappingList{&layout, Size{~0, ~0}};
|
TableView mappingList{&layout, Size{~0, ~0}};
|
||||||
|
@ -119,6 +114,14 @@ struct HotkeySettings : TabFrameItem {
|
||||||
Widget spacer{&controlLayout, Size{~0, 0}};
|
Widget spacer{&controlLayout, Size{~0, 0}};
|
||||||
Button resetButton{&controlLayout, Size{80, 0}};
|
Button resetButton{&controlLayout, Size{80, 0}};
|
||||||
Button eraseButton{&controlLayout, Size{80, 0}};
|
Button eraseButton{&controlLayout, Size{80, 0}};
|
||||||
|
|
||||||
|
auto reloadMappings() -> void;
|
||||||
|
auto refreshMappings() -> void;
|
||||||
|
auto assignMapping() -> void;
|
||||||
|
auto inputEvent(shared_pointer<HID::Device> device, uint group, uint input, int16 oldValue, int16 newValue) -> void;
|
||||||
|
|
||||||
|
InputMapping* activeMapping = nullptr;
|
||||||
|
Timer timer;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct AdvancedSettings : TabFrameItem {
|
struct AdvancedSettings : TabFrameItem {
|
||||||
|
@ -143,8 +146,6 @@ struct AdvancedSettings : TabFrameItem {
|
||||||
|
|
||||||
struct SettingsManager : Window {
|
struct SettingsManager : Window {
|
||||||
SettingsManager();
|
SettingsManager();
|
||||||
auto setVisible(bool visible = true) -> SettingsManager&;
|
|
||||||
auto show(uint setting) -> void;
|
|
||||||
|
|
||||||
VerticalLayout layout{this};
|
VerticalLayout layout{this};
|
||||||
TabFrame panel{&layout, Size{~0, ~0}};
|
TabFrame panel{&layout, Size{~0, ~0}};
|
||||||
|
@ -153,8 +154,10 @@ struct SettingsManager : Window {
|
||||||
InputSettings input{&panel};
|
InputSettings input{&panel};
|
||||||
HotkeySettings hotkeys{&panel};
|
HotkeySettings hotkeys{&panel};
|
||||||
AdvancedSettings advanced{&panel};
|
AdvancedSettings advanced{&panel};
|
||||||
|
|
||||||
StatusBar statusBar{this};
|
StatusBar statusBar{this};
|
||||||
|
|
||||||
|
auto setVisible(bool visible = true) -> SettingsManager&;
|
||||||
|
auto show(uint setting) -> void;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern unique_pointer<SettingsManager> settingsManager;
|
extern unique_pointer<SettingsManager> settingsManager;
|
||||||
|
|
|
@ -22,9 +22,10 @@ struct AudioASIO : Audio {
|
||||||
}
|
}
|
||||||
|
|
||||||
auto context() -> uintptr { return _context; }
|
auto context() -> uintptr { return _context; }
|
||||||
|
auto device() -> string { return _device; }
|
||||||
auto blocking() -> bool { return _blocking; }
|
auto blocking() -> bool { return _blocking; }
|
||||||
auto channels() -> uint { return _channels; }
|
auto channels() -> uint { return _channels; }
|
||||||
auto frequency() -> uint { return _frequency; }
|
auto frequency() -> double { return _frequency; }
|
||||||
auto latency() -> uint { return _latency; }
|
auto latency() -> uint { return _latency; }
|
||||||
|
|
||||||
auto setContext(uintptr context) -> bool {
|
auto setContext(uintptr context) -> bool {
|
||||||
|
@ -33,6 +34,12 @@ struct AudioASIO : Audio {
|
||||||
return initialize();
|
return initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto setDevice(string device) -> bool {
|
||||||
|
if(_device == device) return true;
|
||||||
|
_device = device;
|
||||||
|
return initialize();
|
||||||
|
}
|
||||||
|
|
||||||
auto setBlocking(bool blocking) -> bool {
|
auto setBlocking(bool blocking) -> bool {
|
||||||
if(_blocking == blocking) return true;
|
if(_blocking == blocking) return true;
|
||||||
_blocking = blocking;
|
_blocking = blocking;
|
||||||
|
@ -51,18 +58,6 @@ struct AudioASIO : Audio {
|
||||||
return initialize();
|
return initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto output(const double samples[]) -> void {
|
|
||||||
if(!_ready) return;
|
|
||||||
if(_blocking) {
|
|
||||||
while(_queue.count >= _latency);
|
|
||||||
}
|
|
||||||
for(uint n : range(_channels)) {
|
|
||||||
_queue.samples[_queue.write][n] = samples[n];
|
|
||||||
}
|
|
||||||
_queue.write++;
|
|
||||||
_queue.count++;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto clear() -> void {
|
auto clear() -> void {
|
||||||
if(!_ready) return;
|
if(!_ready) return;
|
||||||
for(uint n : range(_channels)) {
|
for(uint n : range(_channels)) {
|
||||||
|
@ -75,6 +70,18 @@ struct AudioASIO : Audio {
|
||||||
_queue.count = 0;
|
_queue.count = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto output(const double samples[]) -> void {
|
||||||
|
if(!_ready) return;
|
||||||
|
if(_blocking) {
|
||||||
|
while(_queue.count >= _latency);
|
||||||
|
}
|
||||||
|
for(uint n : range(_channels)) {
|
||||||
|
_queue.samples[_queue.write][n] = samples[n];
|
||||||
|
}
|
||||||
|
_queue.write++;
|
||||||
|
_queue.count++;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
auto initialize() -> bool {
|
auto initialize() -> bool {
|
||||||
terminate();
|
terminate();
|
||||||
|
@ -236,7 +243,7 @@ private:
|
||||||
string _device;
|
string _device;
|
||||||
bool _blocking = true;
|
bool _blocking = true;
|
||||||
uint _channels = 2;
|
uint _channels = 2;
|
||||||
uint _frequency = 48000;
|
double _frequency = 48000.0;
|
||||||
uint _latency = 0;
|
uint _latency = 0;
|
||||||
|
|
||||||
struct Queue {
|
struct Queue {
|
||||||
|
|
|
@ -7,188 +7,188 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct AudioOpenAL : Audio {
|
struct AudioOpenAL : Audio {
|
||||||
~AudioOpenAL() { term(); }
|
AudioOpenAL() { initialize(); }
|
||||||
|
~AudioOpenAL() { terminate(); }
|
||||||
|
|
||||||
struct {
|
auto ready() -> bool { return _ready; }
|
||||||
ALCdevice* handle = nullptr;
|
|
||||||
ALCcontext* context = nullptr;
|
|
||||||
ALuint source = 0;
|
|
||||||
ALenum format = AL_FORMAT_STEREO16;
|
|
||||||
unsigned latency = 0;
|
|
||||||
unsigned queueLength = 0;
|
|
||||||
} device;
|
|
||||||
|
|
||||||
struct {
|
auto information() -> Information {
|
||||||
uint32_t* data = nullptr;
|
Information information;
|
||||||
unsigned length = 0;
|
for(auto& device : queryDevices()) information.devices.append(device);
|
||||||
unsigned size = 0;
|
information.channels = {2};
|
||||||
} buffer;
|
information.frequencies = {44100.0, 48000.0, 96000.0};
|
||||||
|
information.latencies = {20, 40, 60, 80, 100};
|
||||||
struct {
|
return information;
|
||||||
bool synchronize = true;
|
|
||||||
unsigned frequency = 48000;
|
|
||||||
unsigned latency = 40;
|
|
||||||
} settings;
|
|
||||||
|
|
||||||
auto cap(const string& name) -> bool {
|
|
||||||
if(name == Audio::Synchronize) return true;
|
|
||||||
if(name == Audio::Frequency) return true;
|
|
||||||
if(name == Audio::Latency) return true;
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto get(const string& name) -> any {
|
auto device() -> string { return _device; }
|
||||||
if(name == Audio::Synchronize) return settings.synchronize;
|
auto blocking() -> bool { return _blocking; }
|
||||||
if(name == Audio::Frequency) return settings.frequency;
|
auto channels() -> uint { return _channels; }
|
||||||
if(name == Audio::Latency) return settings.latency;
|
auto frequency() -> double { return (double)_frequency; }
|
||||||
return {};
|
auto latency() -> uint { return _latency; }
|
||||||
|
|
||||||
|
auto setDevice(string device) -> bool {
|
||||||
|
if(_device == device) return true;
|
||||||
|
_device = device;
|
||||||
|
return initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto set(const string& name, const any& value) -> bool {
|
auto setBlocking(bool blocking) -> bool {
|
||||||
if(name == Audio::Synchronize && value.is<bool>()) {
|
if(_blocking == blocking) return true;
|
||||||
settings.synchronize = value.get<bool>();
|
_blocking = blocking;
|
||||||
return true;
|
return true;
|
||||||
}
|
|
||||||
|
|
||||||
if(name == Audio::Frequency && value.is<unsigned>()) {
|
|
||||||
settings.frequency = value.get<unsigned>();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(name == Audio::Latency && value.is<unsigned>()) {
|
|
||||||
if(settings.latency != value.get<unsigned>()) {
|
|
||||||
settings.latency = value.get<unsigned>();
|
|
||||||
updateLatency();
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto sample(int16_t left, int16_t right) -> void {
|
auto setFrequency(double frequency) -> bool {
|
||||||
buffer.data[buffer.length++] = (uint16_t)left << 0 | (uint16_t)right << 16;
|
if(_frequency == (uint)frequency) return true;
|
||||||
if(buffer.length < buffer.size) return;
|
_frequency = (uint)frequency;
|
||||||
|
return initialize();
|
||||||
|
}
|
||||||
|
|
||||||
ALuint albuffer = 0;
|
auto setLatency(uint latency) -> bool {
|
||||||
|
if(_latency == latency) return true;
|
||||||
|
_latency = latency;
|
||||||
|
if(_ready) updateLatency();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto output(const double samples[]) -> void {
|
||||||
|
_buffer[_bufferLength] = int16_t(samples[0] * 32768.0) << 0;
|
||||||
|
_buffer[_bufferLength] |= int16_t(samples[1] * 32768.0) << 16;
|
||||||
|
if(++_bufferLength < _bufferSize) return;
|
||||||
|
|
||||||
|
ALuint alBuffer = 0;
|
||||||
int processed = 0;
|
int processed = 0;
|
||||||
while(true) {
|
while(true) {
|
||||||
alGetSourcei(device.source, AL_BUFFERS_PROCESSED, &processed);
|
alGetSourcei(_source, AL_BUFFERS_PROCESSED, &processed);
|
||||||
while(processed--) {
|
while(processed--) {
|
||||||
alSourceUnqueueBuffers(device.source, 1, &albuffer);
|
alSourceUnqueueBuffers(_source, 1, &alBuffer);
|
||||||
alDeleteBuffers(1, &albuffer);
|
alDeleteBuffers(1, &alBuffer);
|
||||||
device.queueLength--;
|
_queueLength--;
|
||||||
}
|
}
|
||||||
//wait for buffer playback to catch up to sample generation if not synchronizing
|
//wait for buffer playback to catch up to sample generation if not synchronizing
|
||||||
if(settings.synchronize == false || device.queueLength < 3) break;
|
if(!_blocking || _queueLength < 3) break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(device.queueLength < 3) {
|
if(_queueLength < 3) {
|
||||||
alGenBuffers(1, &albuffer);
|
alGenBuffers(1, &alBuffer);
|
||||||
alBufferData(albuffer, device.format, buffer.data, buffer.size * 4, settings.frequency);
|
alBufferData(alBuffer, _format, _buffer, _bufferSize * 4, _frequency);
|
||||||
alSourceQueueBuffers(device.source, 1, &albuffer);
|
alSourceQueueBuffers(_source, 1, &alBuffer);
|
||||||
device.queueLength++;
|
_queueLength++;
|
||||||
}
|
}
|
||||||
|
|
||||||
ALint playing;
|
ALint playing;
|
||||||
alGetSourcei(device.source, AL_SOURCE_STATE, &playing);
|
alGetSourcei(_source, AL_SOURCE_STATE, &playing);
|
||||||
if(playing != AL_PLAYING) alSourcePlay(device.source);
|
if(playing != AL_PLAYING) alSourcePlay(_source);
|
||||||
buffer.length = 0;
|
_bufferLength = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto clear() -> void {
|
private:
|
||||||
}
|
auto initialize() -> bool {
|
||||||
|
terminate();
|
||||||
|
|
||||||
auto init() -> bool {
|
if(!queryDevices().find(_device)) _device = "";
|
||||||
|
_queueLength = 0;
|
||||||
updateLatency();
|
updateLatency();
|
||||||
device.queueLength = 0;
|
|
||||||
|
|
||||||
bool success = false;
|
bool success = false;
|
||||||
if(device.handle = alcOpenDevice(nullptr)) {
|
if(_openAL = alcOpenDevice(_device)) {
|
||||||
if(device.context = alcCreateContext(device.handle, nullptr)) {
|
if(_context = alcCreateContext(_openAL, nullptr)) {
|
||||||
alcMakeContextCurrent(device.context);
|
alcMakeContextCurrent(_context);
|
||||||
alGenSources(1, &device.source);
|
alGenSources(1, &_source);
|
||||||
|
|
||||||
//alSourcef (device.source, AL_PITCH, 1.0);
|
//alSourcef (_source, AL_PITCH, 1.0);
|
||||||
//alSourcef (device.source, AL_GAIN, 1.0);
|
//alSourcef (_source, AL_GAIN, 1.0);
|
||||||
//alSource3f(device.source, AL_POSITION, 0.0, 0.0, 0.0);
|
//alSource3f(_source, AL_POSITION, 0.0, 0.0, 0.0);
|
||||||
//alSource3f(device.source, AL_VELOCITY, 0.0, 0.0, 0.0);
|
//alSource3f(_source, AL_VELOCITY, 0.0, 0.0, 0.0);
|
||||||
//alSource3f(device.source, AL_DIRECTION, 0.0, 0.0, 0.0);
|
//alSource3f(_source, AL_DIRECTION, 0.0, 0.0, 0.0);
|
||||||
//alSourcef (device.source, AL_ROLLOFF_FACTOR, 0.0);
|
//alSourcef (_source, AL_ROLLOFF_FACTOR, 0.0);
|
||||||
//alSourcei (device.source, AL_SOURCE_RELATIVE, AL_TRUE);
|
//alSourcei (_source, AL_SOURCE_RELATIVE, AL_TRUE);
|
||||||
|
|
||||||
alListener3f(AL_POSITION, 0.0, 0.0, 0.0);
|
alListener3f(AL_POSITION, 0.0, 0.0, 0.0);
|
||||||
alListener3f(AL_VELOCITY, 0.0, 0.0, 0.0);
|
alListener3f(AL_VELOCITY, 0.0, 0.0, 0.0);
|
||||||
ALfloat listener_orientation[] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
|
ALfloat listenerOrientation[] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
|
||||||
alListenerfv(AL_ORIENTATION, listener_orientation);
|
alListenerfv(AL_ORIENTATION, listenerOrientation);
|
||||||
|
|
||||||
success = true;
|
success = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(success == false) {
|
if(!success) return terminate(), false;
|
||||||
term();
|
return _ready = true;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto term() -> void {
|
auto terminate() -> void {
|
||||||
if(alIsSource(device.source) == AL_TRUE) {
|
_ready = false;
|
||||||
|
|
||||||
|
if(alIsSource(_source) == AL_TRUE) {
|
||||||
int playing = 0;
|
int playing = 0;
|
||||||
alGetSourcei(device.source, AL_SOURCE_STATE, &playing);
|
alGetSourcei(_source, AL_SOURCE_STATE, &playing);
|
||||||
if(playing == AL_PLAYING) {
|
if(playing == AL_PLAYING) {
|
||||||
alSourceStop(device.source);
|
alSourceStop(_source);
|
||||||
int queued = 0;
|
int queued = 0;
|
||||||
alGetSourcei(device.source, AL_BUFFERS_QUEUED, &queued);
|
alGetSourcei(_source, AL_BUFFERS_QUEUED, &queued);
|
||||||
while(queued--) {
|
while(queued--) {
|
||||||
ALuint albuffer = 0;
|
ALuint alBuffer = 0;
|
||||||
alSourceUnqueueBuffers(device.source, 1, &albuffer);
|
alSourceUnqueueBuffers(_source, 1, &alBuffer);
|
||||||
alDeleteBuffers(1, &albuffer);
|
alDeleteBuffers(1, &alBuffer);
|
||||||
device.queueLength--;
|
_queueLength--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
alDeleteSources(1, &device.source);
|
alDeleteSources(1, &_source);
|
||||||
device.source = 0;
|
_source = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(device.context) {
|
if(_context) {
|
||||||
alcMakeContextCurrent(nullptr);
|
alcMakeContextCurrent(nullptr);
|
||||||
alcDestroyContext(device.context);
|
alcDestroyContext(_context);
|
||||||
device.context = 0;
|
_context = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(device.handle) {
|
if(_openAL) {
|
||||||
alcCloseDevice(device.handle);
|
alcCloseDevice(_openAL);
|
||||||
device.handle = 0;
|
_openAL = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(buffer.data) {
|
delete[] _buffer;
|
||||||
delete[] buffer.data;
|
_buffer = nullptr;
|
||||||
buffer.data = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
|
||||||
auto queryDevices() -> string_vector {
|
auto queryDevices() -> string_vector {
|
||||||
string_vector result;
|
string_vector result;
|
||||||
|
|
||||||
const char* buffer = alcGetString(nullptr, ALC_DEVICE_SPECIFIER);
|
const char* list = alcGetString(nullptr, ALC_DEVICE_SPECIFIER);
|
||||||
if(!buffer) return result;
|
if(!list) return result;
|
||||||
|
|
||||||
while(buffer[0] || buffer[1]) {
|
while(list[0] || list[1]) {
|
||||||
result.append(buffer);
|
result.append(list);
|
||||||
while(buffer[0]) buffer++;
|
while(list[0]) list++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto updateLatency() -> void {
|
auto updateLatency() -> void {
|
||||||
if(buffer.data) delete[] buffer.data;
|
delete[] _buffer;
|
||||||
buffer.size = settings.frequency * settings.latency / 1000.0 + 0.5;
|
_bufferSize = _frequency * _latency / 1000.0 + 0.5;
|
||||||
buffer.data = new uint32_t[buffer.size]();
|
_buffer = new uint32_t[_bufferSize]();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool _ready = false;
|
||||||
|
string _device;
|
||||||
|
bool _blocking = true;
|
||||||
|
uint _channels = 2;
|
||||||
|
uint _frequency = 48000;
|
||||||
|
uint _latency = 20;
|
||||||
|
|
||||||
|
ALCdevice* _openAL = nullptr;
|
||||||
|
ALCcontext* _context = nullptr;
|
||||||
|
ALuint _source = 0;
|
||||||
|
ALenum _format = AL_FORMAT_STEREO16;
|
||||||
|
uint _queueLength = 0;
|
||||||
|
|
||||||
|
uint32_t* _buffer = nullptr;
|
||||||
|
uint _bufferLength = 0;
|
||||||
|
uint _bufferSize = 0;
|
||||||
};
|
};
|
||||||
|
|
|
@ -23,7 +23,7 @@ struct AudioOSS : Audio {
|
||||||
Information information;
|
Information information;
|
||||||
information.devices = {"/dev/dsp"};
|
information.devices = {"/dev/dsp"};
|
||||||
for(auto& device : directory::files("/dev/", "dsp?*")) information.devices.append(string{"/dev/", device});
|
for(auto& device : directory::files("/dev/", "dsp?*")) information.devices.append(string{"/dev/", device});
|
||||||
information.frequencies = {44100, 48000, 96000};
|
information.frequencies = {44100.0, 48000.0, 96000.0};
|
||||||
information.latencies = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
|
information.latencies = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
|
||||||
information.channels = {1, 2};
|
information.channels = {1, 2};
|
||||||
return information;
|
return information;
|
||||||
|
@ -32,7 +32,7 @@ struct AudioOSS : Audio {
|
||||||
auto device() -> string { return _device; }
|
auto device() -> string { return _device; }
|
||||||
auto blocking() -> bool { return _blocking; }
|
auto blocking() -> bool { return _blocking; }
|
||||||
auto channels() -> uint { return _channels; }
|
auto channels() -> uint { return _channels; }
|
||||||
auto frequency() -> uint { return _frequency; }
|
auto frequency() -> double { return _frequency; }
|
||||||
auto latency() -> uint { return _latency; }
|
auto latency() -> uint { return _latency; }
|
||||||
|
|
||||||
auto setDevice(string device) -> bool {
|
auto setDevice(string device) -> bool {
|
||||||
|
@ -54,7 +54,7 @@ struct AudioOSS : Audio {
|
||||||
return initialize();
|
return initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto setFrequency(uint frequency) -> bool {
|
auto setFrequency(double frequency) -> bool {
|
||||||
if(_frequency == frequency) return true;
|
if(_frequency == frequency) return true;
|
||||||
_frequency = frequency;
|
_frequency = frequency;
|
||||||
return initialize();
|
return initialize();
|
||||||
|
@ -78,6 +78,10 @@ private:
|
||||||
auto initialize() -> bool {
|
auto initialize() -> bool {
|
||||||
terminate();
|
terminate();
|
||||||
|
|
||||||
|
if(!information().devices.find(_device)) {
|
||||||
|
_device = information().devices.left();
|
||||||
|
}
|
||||||
|
|
||||||
_fd = open(_device, O_WRONLY, O_NONBLOCK);
|
_fd = open(_device, O_WRONLY, O_NONBLOCK);
|
||||||
if(_fd < 0) return false;
|
if(_fd < 0) return false;
|
||||||
|
|
||||||
|
@ -86,9 +90,11 @@ private:
|
||||||
//policy: 0 = minimum latency (higher CPU usage); 10 = maximum latency (lower CPU usage)
|
//policy: 0 = minimum latency (higher CPU usage); 10 = maximum latency (lower CPU usage)
|
||||||
int policy = min(10, _latency);
|
int policy = min(10, _latency);
|
||||||
ioctl(_fd, SNDCTL_DSP_POLICY, &policy);
|
ioctl(_fd, SNDCTL_DSP_POLICY, &policy);
|
||||||
ioctl(_fd, SNDCTL_DSP_CHANNELS, &_channels);
|
int channels = _channels;
|
||||||
|
ioctl(_fd, SNDCTL_DSP_CHANNELS, &channels);
|
||||||
ioctl(_fd, SNDCTL_DSP_SETFMT, &_format);
|
ioctl(_fd, SNDCTL_DSP_SETFMT, &_format);
|
||||||
ioctl(_fd, SNDCTL_DSP_SPEED, &_frequency);
|
int frequency = _frequency;
|
||||||
|
ioctl(_fd, SNDCTL_DSP_SPEED, &frequency);
|
||||||
|
|
||||||
updateBlocking();
|
updateBlocking();
|
||||||
return _ready = true;
|
return _ready = true;
|
||||||
|
@ -110,11 +116,11 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
bool _ready = false;
|
bool _ready = false;
|
||||||
string _device = "/dev/dsp";
|
string _device;
|
||||||
bool _blocking = true;
|
bool _blocking = true;
|
||||||
int _channels = 2;
|
uint _channels = 2;
|
||||||
int _frequency = 48000;
|
double _frequency = 48000.0;
|
||||||
int _latency = 2;
|
uint _latency = 2;
|
||||||
|
|
||||||
int _fd = -1;
|
int _fd = -1;
|
||||||
int _format = AFMT_S16_LE;
|
int _format = AFMT_S16_LE;
|
||||||
|
|
|
@ -6,157 +6,161 @@
|
||||||
#include <endpointvolume.h>
|
#include <endpointvolume.h>
|
||||||
|
|
||||||
struct AudioWASAPI : Audio {
|
struct AudioWASAPI : Audio {
|
||||||
~AudioWASAPI() { term(); }
|
AudioWASAPI() { initialize(); }
|
||||||
|
~AudioWASAPI() { terminate(); }
|
||||||
|
|
||||||
struct {
|
auto ready() -> bool { return _ready; }
|
||||||
bool exclusive = false;
|
|
||||||
uint latency = 80;
|
|
||||||
bool synchronize = true;
|
|
||||||
} settings;
|
|
||||||
|
|
||||||
struct {
|
auto information() -> Information {
|
||||||
uint channels = 0;
|
Information information;
|
||||||
uint frequency = 0;
|
information.devices = {"Default"};
|
||||||
uint mode = 0;
|
information.channels = {2};
|
||||||
uint precision = 0;
|
information.frequencies = {};
|
||||||
} device;
|
information.latencies = {20, 40, 60, 80, 100};
|
||||||
|
return information;
|
||||||
auto cap(const string& name) -> bool {
|
|
||||||
if(name == Audio::Exclusive) return true;
|
|
||||||
if(name == Audio::Latency) return true;
|
|
||||||
if(name == Audio::Synchronize) return true;
|
|
||||||
if(name == Audio::Frequency) return true;
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto get(const string& name) -> any {
|
auto exclusive() -> bool { return _exclusive; }
|
||||||
if(name == Audio::Exclusive) return settings.exclusive;
|
auto blocking() -> bool { return _blocking; }
|
||||||
if(name == Audio::Latency) return settings.latency;
|
auto channels() -> uint { return _channels; }
|
||||||
if(name == Audio::Synchronize) return settings.synchronize;
|
auto frequency() -> double { return (double)_frequency; }
|
||||||
if(name == Audio::Frequency) return device.frequency;
|
auto latency() -> uint { return _latency; }
|
||||||
return {};
|
|
||||||
|
auto setExclusive(bool exclusive) -> bool {
|
||||||
|
if(_exclusive == exclusive) return true;
|
||||||
|
_exclusive = exclusive;
|
||||||
|
return initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto set(const string& name, const any& value) -> bool {
|
auto setBlocking(bool blocking) -> bool {
|
||||||
if(name == Audio::Exclusive && value.get<bool>()) {
|
if(_blocking == blocking) return true;
|
||||||
if(audioDevice) term(), init();
|
_blocking = blocking;
|
||||||
settings.exclusive = value.get<bool>();
|
return true;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(name == Audio::Latency && value.get<uint>()) {
|
|
||||||
if(audioDevice) term(), init();
|
|
||||||
settings.latency = value.get<uint>();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(name == Audio::Synchronize && value.is<bool>()) {
|
|
||||||
settings.synchronize = value.get<bool>();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto sample(int16_t left, int16_t right) -> void {
|
auto setFrequency(double frequency) -> bool {
|
||||||
queuedFrames.append((uint16_t)left << 0 | (uint16_t)right << 16);
|
if(_frequency == frequency) return true;
|
||||||
|
_frequency = frequency;
|
||||||
|
return initialize();
|
||||||
|
}
|
||||||
|
|
||||||
if(!available() && queuedFrames.size() >= bufferSize) {
|
auto setLatency(uint latency) -> bool {
|
||||||
if(settings.synchronize) while(!available()); //wait for free sample slot
|
if(_latency == latency) return true;
|
||||||
else queuedFrames.takeLeft(); //drop sample (run ahead)
|
_latency = latency;
|
||||||
|
return initialize();
|
||||||
|
}
|
||||||
|
|
||||||
|
auto clear() -> void {
|
||||||
|
_audioClient->Stop();
|
||||||
|
_audioClient->Reset();
|
||||||
|
for(auto n : range(available())) write(0, 0);
|
||||||
|
_audioClient->Start();
|
||||||
|
}
|
||||||
|
|
||||||
|
auto output(const double samples[]) -> void {
|
||||||
|
_queuedFrames.append(int16_t(samples[0] * 32768.0) << 0 | int16_t(samples[1] * 32768.0) << 16);
|
||||||
|
|
||||||
|
if(!available() && _queuedFrames.size() >= _bufferSize) {
|
||||||
|
if(_blocking) {
|
||||||
|
while(!available()); //wait for free sample slot
|
||||||
|
} else {
|
||||||
|
_queuedFrames.takeLeft(); //drop sample (run ahead)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t cachedFrame = 0;
|
uint32_t cachedFrame = 0;
|
||||||
for(auto n : range(available())) {
|
for(auto n : range(available())) {
|
||||||
if(queuedFrames) cachedFrame = queuedFrames.takeLeft();
|
if(_queuedFrames) cachedFrame = _queuedFrames.takeLeft();
|
||||||
write(cachedFrame >> 0, cachedFrame >> 16);
|
write(cachedFrame >> 0, cachedFrame >> 16);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto clear() -> void {
|
private:
|
||||||
audioClient->Stop();
|
auto initialize() -> bool {
|
||||||
audioClient->Reset();
|
if(CoCreateInstance(CLSID_MMDeviceEnumerator, nullptr, CLSCTX_ALL, IID_IMMDeviceEnumerator, (void**)&_enumerator) != S_OK) return false;
|
||||||
for(auto n : range(available())) write(0, 0);
|
if(_enumerator->GetDefaultAudioEndpoint(eRender, eConsole, &_audioDevice) != S_OK) return false;
|
||||||
audioClient->Start();
|
if(_audioDevice->Activate(IID_IAudioClient, CLSCTX_ALL, nullptr, (void**)&_audioClient) != S_OK) return false;
|
||||||
}
|
|
||||||
|
|
||||||
auto init() -> bool {
|
if(_exclusive) {
|
||||||
if(CoCreateInstance(CLSID_MMDeviceEnumerator, nullptr, CLSCTX_ALL, IID_IMMDeviceEnumerator, (void**)&enumerator) != S_OK) return false;
|
if(_audioDevice->OpenPropertyStore(STGM_READ, &_propertyStore) != S_OK) return false;
|
||||||
if(enumerator->GetDefaultAudioEndpoint(eRender, eConsole, &audioDevice) != S_OK) return false;
|
if(_propertyStore->GetValue(PKEY_AudioEngine_DeviceFormat, &_propVariant) != S_OK) return false;
|
||||||
if(audioDevice->Activate(IID_IAudioClient, CLSCTX_ALL, nullptr, (void**)&audioClient) != S_OK) return false;
|
_waveFormat = (WAVEFORMATEX*)_propVariant.blob.pBlobData;
|
||||||
|
if(_audioClient->GetDevicePeriod(nullptr, &_devicePeriod) != S_OK) return false;
|
||||||
if(settings.exclusive) {
|
auto latency = max(_devicePeriod, (REFERENCE_TIME)_latency * 10'000); //1ms to 100ns units
|
||||||
if(audioDevice->OpenPropertyStore(STGM_READ, &propertyStore) != S_OK) return false;
|
if(_audioClient->Initialize(AUDCLNT_SHAREMODE_EXCLUSIVE, 0, latency, latency, _waveFormat, nullptr) != S_OK) return false;
|
||||||
if(propertyStore->GetValue(PKEY_AudioEngine_DeviceFormat, &propVariant) != S_OK) return false;
|
|
||||||
waveFormat = (WAVEFORMATEX*)propVariant.blob.pBlobData;
|
|
||||||
if(audioClient->GetDevicePeriod(nullptr, &devicePeriod) != S_OK) return false;
|
|
||||||
auto latency = max(devicePeriod, (REFERENCE_TIME)settings.latency * 10'000); //1ms to 100ns units
|
|
||||||
if(audioClient->Initialize(AUDCLNT_SHAREMODE_EXCLUSIVE, 0, latency, latency, waveFormat, nullptr) != S_OK) return false;
|
|
||||||
DWORD taskIndex = 0;
|
DWORD taskIndex = 0;
|
||||||
taskHandle = AvSetMmThreadCharacteristics(L"Pro Audio", &taskIndex);
|
_taskHandle = AvSetMmThreadCharacteristics(L"Pro Audio", &taskIndex);
|
||||||
} else {
|
} else {
|
||||||
if(audioClient->GetMixFormat(&waveFormat) != S_OK) return false;
|
if(_audioClient->GetMixFormat(&waveFormat) != S_OK) return false;
|
||||||
if(audioClient->GetDevicePeriod(&devicePeriod, nullptr)) return false;
|
if(_audioClient->GetDevicePeriod(&_devicePeriod, nullptr)) return false;
|
||||||
auto latency = max(devicePeriod, (REFERENCE_TIME)settings.latency * 10'000); //1ms to 100ns units
|
auto latency = max(_devicePeriod, (REFERENCE_TIME)_latency * 10'000); //1ms to 100ns units
|
||||||
if(audioClient->Initialize(AUDCLNT_SHAREMODE_SHARED, 0, latency, 0, waveFormat, nullptr) != S_OK) return false;
|
if(_audioClient->Initialize(AUDCLNT_SHAREMODE_SHARED, 0, latency, 0, _waveFormat, nullptr) != S_OK) return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(audioClient->GetService(IID_IAudioRenderClient, (void**)&renderClient) != S_OK) return false;
|
if(_audioClient->GetService(IID_IAudioRenderClient, (void**)&_renderClient) != S_OK) return false;
|
||||||
if(audioClient->GetBufferSize(&bufferSize) != S_OK) return false;
|
if(_audioClient->GetBufferSize(&_bufferSize) != S_OK) return false;
|
||||||
|
|
||||||
device.channels = waveFormat->nChannels;
|
_channels = waveFormat->nChannels;
|
||||||
device.frequency = waveFormat->nSamplesPerSec;
|
_frequency = waveFormat->nSamplesPerSec;
|
||||||
device.mode = ((WAVEFORMATEXTENSIBLE*)waveFormat)->SubFormat.Data1;
|
_mode = ((WAVEFORMATEXTENSIBLE*)_waveFormat)->SubFormat.Data1;
|
||||||
device.precision = waveFormat->wBitsPerSample;
|
_precision = _waveFormat->wBitsPerSample;
|
||||||
|
|
||||||
audioClient->Start();
|
_audioClient->Start();
|
||||||
return true;
|
return _ready = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto term() -> void {
|
auto terminate() -> void {
|
||||||
if(audioClient) audioClient->Stop();
|
if(_audioClient) _audioClient->Stop();
|
||||||
if(renderClient) renderClient->Release(), renderClient = nullptr;
|
if(_renderClient) _renderClient->Release(), _renderClient = nullptr;
|
||||||
if(waveFormat) CoTaskMemFree(waveFormat), waveFormat = nullptr;
|
if(_waveFormat) CoTaskMemFree(_waveFormat), _waveFormat = nullptr;
|
||||||
if(audioClient) audioClient->Release(), audioClient = nullptr;
|
if(_audioClient) _audioClient->Release(), _audioClient = nullptr;
|
||||||
if(audioDevice) audioDevice->Release(), audioDevice = nullptr;
|
if(_audioDevice) _audioDevice->Release(), _audioDevice = nullptr;
|
||||||
if(taskHandle) AvRevertMmThreadCharacteristics(taskHandle), taskHandle = nullptr;
|
if(_taskHandle) AvRevertMmThreadCharacteristics(_taskHandle), _taskHandle = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
|
||||||
auto available() -> uint {
|
auto available() -> uint {
|
||||||
uint32_t padding = 0;
|
uint32_t padding = 0;
|
||||||
audioClient->GetCurrentPadding(&padding);
|
_audioClient->GetCurrentPadding(&padding);
|
||||||
return bufferSize - padding;
|
return bufferSize - padding;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto write(int16_t left, int16_t right) -> void {
|
auto write(int16_t left, int16_t right) -> void {
|
||||||
if(renderClient->GetBuffer(1, &bufferData) != S_OK) return;
|
if(_renderClient->GetBuffer(1, &_bufferData) != S_OK) return;
|
||||||
|
|
||||||
if(device.channels >= 2 && device.mode == 1 && device.precision == 16) {
|
if(_channels >= 2 && _mode == 1 && _precision == 16) {
|
||||||
auto buffer = (int16_t*)bufferData;
|
auto buffer = (int16_t*)_bufferData;
|
||||||
buffer[0] = left;
|
buffer[0] = left;
|
||||||
buffer[1] = right;
|
buffer[1] = right;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(device.channels >= 2 && device.mode == 3 && device.precision == 32) {
|
if(_channels >= 2 && _mode == 3 && _precision == 32) {
|
||||||
auto buffer = (float*)bufferData;
|
auto buffer = (float*)_bufferData;
|
||||||
buffer[0] = left / 32768.0;
|
buffer[0] = left / 32768.0;
|
||||||
buffer[1] = right / 32768.0;
|
buffer[1] = right / 32768.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
renderClient->ReleaseBuffer(1, 0);
|
_renderClient->ReleaseBuffer(1, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
IMMDeviceEnumerator* enumerator = nullptr;
|
bool _exclusive = false;
|
||||||
IMMDevice* audioDevice = nullptr;
|
bool _blocking = true;
|
||||||
IPropertyStore* propertyStore = nullptr;
|
uint _channels = 2;
|
||||||
IAudioClient* audioClient = nullptr;
|
uint _frequency = 48000;
|
||||||
IAudioRenderClient* renderClient = nullptr;
|
uint _latency = 20;
|
||||||
WAVEFORMATEX* waveFormat = nullptr;
|
|
||||||
PROPVARIANT propVariant;
|
uint _mode = 0;
|
||||||
HANDLE taskHandle = nullptr;
|
uint _precision = 0;
|
||||||
REFERENCE_TIME devicePeriod = 0;
|
|
||||||
uint32_t bufferSize = 0; //in frames
|
IMMDeviceEnumerator* _enumerator = nullptr;
|
||||||
uint8_t* bufferData = nullptr;
|
IMMDevice* _audioDevice = nullptr;
|
||||||
vector<uint32_t> queuedFrames;
|
IPropertyStore* _propertyStore = nullptr;
|
||||||
|
IAudioClient* _audioClient = nullptr;
|
||||||
|
IAudioRenderClient* _renderClient = nullptr;
|
||||||
|
WAVEFORMATEX* _waveFormat = nullptr;
|
||||||
|
PROPVARIANT _propVariant;
|
||||||
|
HANDLE _taskHandle = nullptr;
|
||||||
|
REFERENCE_TIME _devicePeriod = 0;
|
||||||
|
uint32_t _bufferSize = 0; //in frames
|
||||||
|
uint8_t* _bufferData = nullptr;
|
||||||
|
vector<uint32_t> _queuedFrames;
|
||||||
};
|
};
|
||||||
|
|
|
@ -54,8 +54,8 @@ struct Audio {
|
||||||
static auto availableDrivers() -> nall::string_vector;
|
static auto availableDrivers() -> nall::string_vector;
|
||||||
|
|
||||||
struct Information {
|
struct Information {
|
||||||
nall::vector<nall::string> devices;
|
nall::string_vector devices;
|
||||||
nall::vector<uint> frequencies;
|
nall::vector<double> frequencies;
|
||||||
nall::vector<uint> latencies;
|
nall::vector<uint> latencies;
|
||||||
nall::vector<uint> channels;
|
nall::vector<uint> channels;
|
||||||
};
|
};
|
||||||
|
@ -63,14 +63,14 @@ struct Audio {
|
||||||
virtual ~Audio() = default;
|
virtual ~Audio() = default;
|
||||||
|
|
||||||
virtual auto ready() -> bool { return true; }
|
virtual auto ready() -> bool { return true; }
|
||||||
virtual auto information() -> Information { return {{"None"}, {48000}, {0}, {2}}; }
|
virtual auto information() -> Information { return {{"None"}, {48000.0}, {0}, {2}}; }
|
||||||
|
|
||||||
virtual auto exclusive() -> bool { return false; }
|
virtual auto exclusive() -> bool { return false; }
|
||||||
virtual auto context() -> uintptr { return 0; }
|
virtual auto context() -> uintptr { return 0; }
|
||||||
virtual auto device() -> nall::string { return "None"; }
|
virtual auto device() -> nall::string { return "None"; }
|
||||||
virtual auto blocking() -> bool { return false; }
|
virtual auto blocking() -> bool { return false; }
|
||||||
virtual auto channels() -> uint { return 2; }
|
virtual auto channels() -> uint { return 2; }
|
||||||
virtual auto frequency() -> uint { return 48000; }
|
virtual auto frequency() -> double { return 48000.0; }
|
||||||
virtual auto latency() -> uint { return 0; }
|
virtual auto latency() -> uint { return 0; }
|
||||||
|
|
||||||
virtual auto setExclusive(bool exclusive) -> bool { return false; }
|
virtual auto setExclusive(bool exclusive) -> bool { return false; }
|
||||||
|
@ -78,7 +78,7 @@ struct Audio {
|
||||||
virtual auto setDevice(nall::string device) -> bool { return false; }
|
virtual auto setDevice(nall::string device) -> bool { return false; }
|
||||||
virtual auto setBlocking(bool blocking) -> bool { return false; }
|
virtual auto setBlocking(bool blocking) -> bool { return false; }
|
||||||
virtual auto setChannels(uint channels) -> bool { return false; }
|
virtual auto setChannels(uint channels) -> bool { return false; }
|
||||||
virtual auto setFrequency(uint frequency) -> bool { return false; }
|
virtual auto setFrequency(double frequency) -> bool { return false; }
|
||||||
virtual auto setLatency(uint latency) -> bool { return false; }
|
virtual auto setLatency(uint latency) -> bool { return false; }
|
||||||
|
|
||||||
virtual auto clear() -> void {}
|
virtual auto clear() -> void {}
|
||||||
|
|
Loading…
Reference in New Issue