diff options
Diffstat (limited to 'src/osd/modules/sound/pulse_sound.cpp')
-rw-r--r-- | src/osd/modules/sound/pulse_sound.cpp | 38 |
1 files changed, 24 insertions, 14 deletions
diff --git a/src/osd/modules/sound/pulse_sound.cpp b/src/osd/modules/sound/pulse_sound.cpp index fcee6c206e2..373913f9f91 100644 --- a/src/osd/modules/sound/pulse_sound.cpp +++ b/src/osd/modules/sound/pulse_sound.cpp @@ -20,11 +20,15 @@ #include <stdlib.h> #include <poll.h> +#include <mutex> #include <thread> #include <pulse/pulseaudio.h> #include "modules/lib/osdobj_common.h" +using osd::s16; +using osd::u32; + class sound_pulse : public osd_module, public sound_module { public: @@ -34,7 +38,7 @@ public: } virtual ~sound_pulse() { } - virtual int init(osd_options const &options) override; + virtual int init(osd_interface &osd, osd_options const &options) override; virtual void exit() override; virtual void update_audio_stream(bool is_throttled, const s16 *buffer, int samples_this_frame) override; virtual void set_mastervolume(int attenuation) override; @@ -108,7 +112,7 @@ char sound_pulse::peek_main() return -1; } generic_error("peek_main: read"); - } + } return c; } @@ -116,7 +120,7 @@ char sound_pulse::get_main() { pollfd pfds[1]; pfds[0].fd = m_pipe_to_main[0]; - pfds[0].events = POLL_IN; + pfds[0].events = POLLIN; pfds[0].revents = 0; int err = poll(pfds, 1, -1); if(err < 0) @@ -130,7 +134,7 @@ char sound_pulse::get_main() ::exit(1); } generic_error("get_main: read"); - } + } return c; } @@ -147,7 +151,7 @@ void sound_pulse::send_main(char c) ::exit(1); } generic_error("send_main: write"); - } + } } void sound_pulse::send_sub(char c) @@ -163,7 +167,7 @@ void sound_pulse::send_sub(char c) ::exit(1); } generic_error("send_sub: write"); - } + } } void sound_pulse::make_pipes() @@ -269,7 +273,7 @@ void sound_pulse::stop_mainloop(int err) pa_mainloop_quit(m_mainloop, err); } -int sound_pulse::init(osd_options const &options) +int sound_pulse::init(osd_interface &osd, osd_options const &options) { m_last_sample = 0; m_setting_volume = false; @@ -292,20 +296,26 @@ int sound_pulse::init(osd_options const &options) if(res != 'r') return 1; + const int sample_rate = options.sample_rate(); + pa_sample_spec ss; - ss.format = ENDIANNESS_NATIVE == ENDIANNESS_BIG ? PA_SAMPLE_S16BE : PA_SAMPLE_S16LE; - ss.rate = sample_rate(); +#ifdef LSB_FIRST + ss.format = PA_SAMPLE_S16LE; +#else + ss.format = PA_SAMPLE_S16BE; +#endif + ss.rate = sample_rate; ss.channels = 2; m_stream = pa_stream_new(m_context, "main output", &ss, nullptr); pa_stream_set_state_callback(m_stream, i_stream_notify, this); pa_stream_set_write_callback(m_stream, i_stream_write_request, this); pa_buffer_attr battr; - battr.fragsize = sample_rate() / 1000; + battr.fragsize = sample_rate / 1000; battr.maxlength = uint32_t(-1); - battr.minreq = sample_rate() / 1000; + battr.minreq = sample_rate / 1000; battr.prebuf = uint32_t(-1); - battr.tlength = sample_rate() / 1000; + battr.tlength = sample_rate / 1000; err = pa_stream_connect_playback(m_stream, nullptr, &battr, PA_STREAM_ADJUST_LATENCY, nullptr, nullptr); if(err) @@ -325,7 +335,7 @@ void sound_pulse::update_audio_stream(bool is_throttled, const s16 *buffer, int buf.cpos = 0; buf.data.resize(samples_this_frame); memcpy(buf.data.data(), buffer, samples_this_frame*4); - m_last_sample = buf.data.back(); + m_last_sample = buf.data.back(); if(m_buffers.size() > 10) // If there way too many buffers, drop some so only 10 are left (roughly 0.2s) @@ -360,7 +370,7 @@ void sound_pulse::set_mastervolume(int attenuation) if(!m_stream) return; - + std::unique_lock<std::mutex> lock(m_mutex); if(m_setting_volume) { m_new_volume = true; |