diff options
Diffstat (limited to 'src/osd/modules/sound/coreaudio_sound.cpp')
-rw-r--r-- | src/osd/modules/sound/coreaudio_sound.cpp | 77 |
1 files changed, 28 insertions, 49 deletions
diff --git a/src/osd/modules/sound/coreaudio_sound.cpp b/src/osd/modules/sound/coreaudio_sound.cpp index 2cdb9291168..7e9814af117 100644 --- a/src/osd/modules/sound/coreaudio_sound.cpp +++ b/src/osd/modules/sound/coreaudio_sound.cpp @@ -46,7 +46,6 @@ public: m_playpos(0), m_writepos(0), m_in_underrun(false), - m_scale(128), m_overflows(0), m_underflows(0) { @@ -60,8 +59,7 @@ public: // sound_module - virtual void update_audio_stream(bool is_throttled, int16_t const *buffer, int samples_this_frame) override; - virtual void set_mastervolume(int attenuation) override; + virtual void stream_sink_update(uint32_t, int16_t const *buffer, int samples_this_frame) override; private: struct node_detail @@ -83,14 +81,6 @@ private: uint32_t buffer_avail() const { return ((m_writepos >= m_playpos) ? m_buffer_size : 0) + m_playpos - m_writepos; } uint32_t buffer_used() const { return ((m_playpos > m_writepos) ? m_buffer_size : 0) + m_writepos - m_playpos; } - void copy_scaled(void *dst, void const *src, uint32_t bytes) const - { - bytes /= sizeof(int16_t); - int16_t const *s = (int16_t const *)src; - for (int16_t *d = (int16_t *)dst; bytes > 0; bytes--, s++, d++) - *d = (*s * m_scale) >> 7; - } - bool create_graph(osd_options const &options); bool add_output(char const *name); bool add_device_output(char const *name); @@ -178,7 +168,6 @@ private: uint32_t m_playpos; uint32_t m_writepos; bool m_in_underrun; - int32_t m_scale; unsigned m_overflows; unsigned m_underflows; }; @@ -240,7 +229,6 @@ int sound_coreaudio::init(osd_interface &osd, const osd_options &options) m_playpos = 0; m_writepos = m_headroom; m_in_underrun = false; - m_scale = 128; m_overflows = m_underflows = 0; // Initialise and start @@ -290,7 +278,7 @@ void sound_coreaudio::exit() } -void sound_coreaudio::update_audio_stream(bool is_throttled, int16_t const *buffer, int samples_this_frame) +void sound_coreaudio::stream_sink_update(uint32_t, int16_t const *buffer, int samples_this_frame) { if ((m_sample_rate == 0) || !m_buffer) return; @@ -318,13 +306,6 @@ void sound_coreaudio::update_audio_stream(bool is_throttled, int16_t const *buff } -void sound_coreaudio::set_mastervolume(int attenuation) -{ - int const clamped_attenuation = std::clamp(attenuation, -32, 0); - m_scale = (-32 == clamped_attenuation) ? 0 : (int32_t)(pow(10.0, clamped_attenuation / 20.0) * 128); -} - - bool sound_coreaudio::create_graph(osd_options const &options) { OSStatus err; @@ -902,43 +883,40 @@ CFPropertyListRef sound_coreaudio::load_property_list(char const *name) const (UInt8 const *)name, strlen(name), false); - if (nullptr == url) - { + if (!url) return nullptr; - } - CFDataRef data = nullptr; - SInt32 err; - Boolean const status = CFURLCreateDataAndPropertiesFromResource( - nullptr, - url, - &data, - nullptr, - nullptr, - &err); + CFReadStreamRef const stream = CFReadStreamCreateWithFile(nullptr, url); CFRelease(url); - if (!status) + if (!stream) { - osd_printf_error( - "Error reading data from %s (%ld)\n", - name, - (long)err); - if (nullptr != data) CFRelease(data); + osd_printf_error("Error opening file %s\n", name); + return nullptr; + } + if (!CFReadStreamOpen(stream)) + { + CFRelease(stream); + osd_printf_error("Error opening file %s\n", name); return nullptr; } CFErrorRef msg = nullptr; - CFPropertyListRef const result = CFPropertyListCreateWithData( + CFPropertyListRef const result = CFPropertyListCreateWithStream( nullptr, - data, + stream, + 0, kCFPropertyListImmutable, nullptr, &msg); - CFRelease(data); - if ((nullptr == result) || (nullptr != msg)) - { - std::unique_ptr<char []> const buf = (nullptr != msg) ? convert_cfstring_to_utf8(CFErrorCopyDescription(msg)) : nullptr; - if (nullptr != msg) + CFReadStreamClose(stream); + CFRelease(stream); + if (!result || msg) + { + CFStringRef const desc = msg ? CFErrorCopyDescription(msg) : nullptr; + std::unique_ptr<char []> const buf = desc ? convert_cfstring_to_utf8(desc) : nullptr; + if (desc) + CFRelease(desc); + if (msg) CFRelease(msg); if (buf) @@ -954,7 +932,8 @@ CFPropertyListRef sound_coreaudio::load_property_list(char const *name) const "Error creating property list from %s\n", name); } - if (nullptr != result) CFRelease(result); + if (result) + CFRelease(result); return nullptr; } @@ -986,7 +965,7 @@ OSStatus sound_coreaudio::render( } uint32_t const chunk = std::min(m_buffer_size - m_playpos, number_bytes); - copy_scaled((int8_t *)data->mBuffers[0].mData, &m_buffer[m_playpos], chunk); + memcpy((int8_t *)data->mBuffers[0].mData, &m_buffer[m_playpos], chunk); m_playpos += chunk; if (m_playpos >= m_buffer_size) m_playpos = 0; @@ -995,7 +974,7 @@ OSStatus sound_coreaudio::render( { assert(0U == m_playpos); assert(m_writepos >= (number_bytes - chunk)); - copy_scaled((int8_t *)data->mBuffers[0].mData + chunk, &m_buffer[0], number_bytes - chunk); + memcpy((int8_t *)data->mBuffers[0].mData + chunk, &m_buffer[0], number_bytes - chunk); m_playpos += number_bytes - chunk; } |