mirror of
https://github.com/bsnes-emu/bsnes.git
synced 2025-02-23 22:52:34 +01:00
byuu says: This release provides several major improvements to Mega Drive emulation which enhances compatibility a good deal. It also includes important Super Famicom mosaic emulation improvements, plus a much-needed SuperFX save state issue fix. Changelog (since v104): - higan: many improvements to Emulator::Interface to support forks/frontends - higan: refreshed program icon - icarus: new program icon - Game Boy Advance: slight emulation speedup over v104 - Game Boy Advance: synchronize APU FIFO updates better - Mega Drive: added automatic region detection [hex_usr] - Mega Drive: support 8-bit SRAM - Game Boy Advance: fixed bug when changing to THUMB mode via MSR [MerryMage] - Master System: fix bug in backdrop color and background 0 priority [hex_usr] - Mega Drive: backgrounds always update output priority bit [Cydrak] - Mega Drive: emulated interlaced video output - Mega Drive: emulated shadow/highlight mode [Cydrak] - Super Famicom: auto joypad polling clears the shift register when starting - Super Famicom: added new low-entropy RAM initialization mode to more closely match hardware - Game Boy Advance: rumble will now time out after being left on for 500ms - ruby: improved rumble support in udev input driver [ma_rysia] - M68K: `move.b (a7)[+/-]` adjust a7 by two - M68K: illegal/lineA/lineF opcodes do not modify the stack register - Mega Drive: emulate VIP status bit - uPD7725: improved emulation of OV1/S1 flags [byuu, AWJ, Lord Nightmare] - uPD7725: improved handling of DP, RP updates [Jonas Quinn] - Super Famicom: improved emulation of mosaic effects in hires, interlace, and offset-per-tile modes [byuu, Cydrak] - ruby: improved Direct3D exclusive mode monitor selection [Cydrak] - Super Famicom: fixed save state bug affecting SuperFX games [Cydrak] - Mega Drive: added workaround for Clang compiler bug; allowing this core to work on macOS [Cydrak, Sintendo] - higan: hotkeys now also trigger when the main window lacks focus yet higan is set to allow input on focus loss - higan: fixed an edge case where `int16_t` ↔ `double` audio conversion could possibly result in overflows - higan: fixed a crash on macOS when choosing quit from the application menu [ncbncb] Changelog (since the previous WIP): - higan: restored `make console=true` - tomoko: if you allow input when main window focus is lost, hotkeys can now be triggered without focus as well - hiro/cocoa: fix crash on exit from menu [ncbncb] - ruby: smarter `double` → `int16_t` conversion to prevent underflow/overflow
100 lines
2.5 KiB
C++
100 lines
2.5 KiB
C++
#include <pulse/simple.h>
|
|
#include <pulse/error.h>
|
|
|
|
struct AudioPulseAudioSimple : Audio {
|
|
AudioPulseAudioSimple() { initialize(); }
|
|
~AudioPulseAudioSimple() { terminate(); }
|
|
|
|
auto availableDevices() -> string_vector {
|
|
return {"Default"};
|
|
}
|
|
|
|
auto availableFrequencies() -> vector<double> {
|
|
return {44100.0, 48000.0, 96000.0};
|
|
}
|
|
|
|
auto availableLatencies() -> vector<uint> {
|
|
return {40};
|
|
}
|
|
|
|
auto availableChannels() -> vector<uint> {
|
|
return {2};
|
|
}
|
|
|
|
auto ready() -> bool { return _ready; }
|
|
auto blocking() -> bool { return true; }
|
|
auto channels() -> uint { return 2; }
|
|
auto frequency() -> double { return _frequency; }
|
|
auto latency() -> uint { return 40; }
|
|
|
|
auto setFrequency(double frequency) -> bool {
|
|
if(_frequency == frequency) return true;
|
|
_frequency = frequency;
|
|
return initialize();
|
|
}
|
|
|
|
auto output(const double samples[]) -> void {
|
|
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;
|
|
double _frequency = 48000.0;
|
|
|
|
pa_simple* _interface = nullptr;
|
|
|
|
uint32_t* _buffer = nullptr;
|
|
uint _offset = 0;
|
|
};
|