bsnes/ruby/audio/pulseaudiosimple.cpp
Tim Allen 5deba5cbc1 Update to 20180729 release.
byuu wrote:

Sigh ...

asio.hpp needs #include <nall/windows/registry.hpp>

[Since the last WIP, byuu also posted the following message. -Ed.]

ruby drivers have all been updated (but not tested outside of BSD), and
I redesigned the settings window. The driver functionality all exists on
a new "Drivers" panel, the emulator/hack settings go to a
"Configuration" panel, and the video/audio panels lose driver settings.
As does the settings menu and its synchronize options.

I want to start pushing toward a v107 release. Critically, I will need
DirectSound and ALSA to support dynamic rate control. I'd also like to
eliminate the other system manifest.bml files. I need to update the
cheat code database format, and bundle at least a few quark shaders --
although I still need to default to Direct3D on Windows.

Turbo keys would be nice, if it's not too much effort. Aside from
netplay, it's the last significant feature I'm missing.

I think for v107, higan is going to be a bit rough around the edges
compared to bsnes. And I don't think it's practical to finish the bsnes
localization support.

I'm thinking we probably want another WIP to iron out any critical
issues, but this time there should be a feature freeze with the next
WIP.
2018-07-29 23:24:38 +10:00

86 lines
2.2 KiB
C++

#include <pulse/simple.h>
#include <pulse/error.h>
struct AudioPulseAudioSimple : Audio {
AudioPulseAudioSimple() { initialize(); }
~AudioPulseAudioSimple() { terminate(); }
auto driver() -> string override { return "PulseAudioSimple"; }
auto ready() -> bool override { return _ready; }
auto hasFrequency() -> bool override { return true; }
auto availableFrequencies() -> vector<double> override {
return {44100.0, 48000.0, 96000.0};
}
auto setFrequency(double frequency) -> bool override {
if(frequency == Audio::frequency()) return true;
if(!Audio::setFrequency(frequency)) return false;
return initialize();
}
auto output(const double samples[]) -> void override {
if(!ready()) return;
_buffer[_offset] = (uint16_t)sclamp<16>(samples[0] * 32767.0) << 0;
_buffer[_offset] |= (uint16_t)sclamp<16>(samples[1] * 32767.0) << 16;
if(++_offset >= 64) {
int error;
pa_simple_write(_interface, (const void*)_buffer, _offset * sizeof(uint32_t), &error);
_offset = 0;
}
}
private:
auto initialize() -> bool {
terminate();
pa_sample_spec specification;
specification.format = PA_SAMPLE_S16LE;
specification.channels = 2;
specification.rate = (uint)_frequency;
int error = 0;
_interface = pa_simple_new(
0, //default server
"ruby::pulseAudioSimple", //application name
PA_STREAM_PLAYBACK, //direction
0, //default device
"audio", //stream description
&specification, //sample format
0, //default channel map
0, //default buffering attributes
&error //error code
);
if(!_interface) return false;
_buffer = new uint32_t[64]();
_offset = 0;
return _ready = true;
}
auto terminate() -> void {
_ready = false;
if(_interface) {
int error;
pa_simple_flush(_interface, &error);
pa_simple_free(_interface);
_interface = nullptr;
}
if(_buffer) {
delete[] _buffer;
_buffer = nullptr;
}
}
bool _ready = false;
pa_simple* _interface = nullptr;
uint32_t* _buffer = nullptr;
uint _offset = 0;
};