diff options
Diffstat (limited to 'src/devices/sound/samples.h')
-rw-r--r-- | src/devices/sound/samples.h | 38 |
1 files changed, 19 insertions, 19 deletions
diff --git a/src/devices/sound/samples.h b/src/devices/sound/samples.h index 798dccc588f..7b0c4cc3446 100644 --- a/src/devices/sound/samples.h +++ b/src/devices/sound/samples.h @@ -8,8 +8,8 @@ ***************************************************************************/ -#ifndef MAME_DEVICES_SOUND_SAMPLES_H -#define MAME_DEVICES_SOUND_SAMPLES_H +#ifndef MAME_SOUND_SAMPLES_H +#define MAME_SOUND_SAMPLES_H #pragma once @@ -19,7 +19,7 @@ //************************************************************************** // device type definition -extern const device_type SAMPLES; +DECLARE_DEVICE_TYPE(SAMPLES, samples_device) @@ -33,12 +33,10 @@ extern const device_type SAMPLES; #define MCFG_SAMPLES_NAMES(_names) \ samples_device::static_set_samples_names(*device, _names); -typedef device_delegate<void ()> samples_start_cb_delegate; - #define SAMPLES_START_CB_MEMBER(_name) void _name() #define MCFG_SAMPLES_START_CB(_class, _method) \ - samples_device::set_samples_start_callback(*device, samples_start_cb_delegate(&_class::_method, #_class "::" #_method, downcast<_class *>(owner))); + samples_device::set_samples_start_callback(*device, samples_device::start_cb_delegate(&_class::_method, #_class "::" #_method, downcast<_class *>(owner))); //************************************************************************** // TYPE DEFINITIONS @@ -50,13 +48,15 @@ class samples_device : public device_t, public device_sound_interface { public: + typedef device_delegate<void ()> start_cb_delegate; + // construction/destruction samples_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock); // static configuration helpers static void static_set_channels(device_t &device, uint8_t channels) { downcast<samples_device &>(device).m_channels = channels; } static void static_set_samples_names(device_t &device, const char *const *names) { downcast<samples_device &>(device).m_names = names; } - static void set_samples_start_callback(device_t &device, samples_start_cb_delegate callback) { downcast<samples_device &>(device).m_samples_start_cb = callback; } + static void set_samples_start_callback(device_t &device, start_cb_delegate &&cb) { downcast<samples_device &>(device).m_samples_start_cb = std::move(cb); } // getters bool playing(uint8_t channel) const; @@ -87,11 +87,10 @@ public: // interface uint8_t m_channels; // number of discrete audio channels needed const char *const *m_names; // array of sample names - samples_start_cb_delegate m_samples_start_cb; // optional callback protected: // subclasses can do it this way - samples_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, uint32_t clock, const char *shortname, const char *source); + samples_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock); // device-level overrides virtual void device_start() override; @@ -121,14 +120,16 @@ protected: static bool read_flac_sample(emu_file &file, sample_t &sample); bool load_samples(); + start_cb_delegate m_samples_start_cb; // optional callback + // internal state std::vector<channel_t> m_channel; std::vector<sample_t> m_sample; // internal constants - static const uint8_t FRAC_BITS = 24; - static const uint32_t FRAC_ONE = 1 << FRAC_BITS; - static const uint32_t FRAC_MASK = FRAC_ONE - 1; + static constexpr uint8_t FRAC_BITS = 24; + static constexpr uint32_t FRAC_ONE = 1 << FRAC_BITS; + static constexpr uint32_t FRAC_MASK = FRAC_ONE - 1; }; // iterator, since lots of people are interested in these devices @@ -148,12 +149,12 @@ public: } // getters - const char *altbasename() const { return (m_samples.m_names != nullptr && m_samples.m_names[0] != nullptr && m_samples.m_names[0][0] == '*') ? &m_samples.m_names[0][1] : nullptr; } + const char *altbasename() const { return (m_samples.m_names && m_samples.m_names[0] && m_samples.m_names[0][0] == '*') ? &m_samples.m_names[0][1] : nullptr; } // iteration const char *first() { - if (m_samples.m_names == nullptr || m_samples.m_names[0] == nullptr) + if (!m_samples.m_names || !m_samples.m_names[0]) return nullptr; m_current = 0; if (m_samples.m_names[0][0] == '*') @@ -163,7 +164,7 @@ public: const char *next() { - if (m_current == -1 || m_samples.m_names[m_current] == nullptr) + if (m_current == -1 || !m_samples.m_names[m_current]) return nullptr; return m_samples.m_names[m_current++]; } @@ -171,9 +172,9 @@ public: // counting int count() { - int save = m_current; + int const save = m_current; int result = 0; - for (const char *scan = first(); scan != nullptr; scan = next()) + for (const char *scan = first(); scan; scan = next()) result++; m_current = save; return result; @@ -185,5 +186,4 @@ private: int m_current; }; - -#endif // MAME_DEVICES_SOUND_SAMPLES_H +#endif // MAME_SOUND_SAMPLES_H |