diff options
author | 2020-09-17 13:46:55 -0700 | |
---|---|---|
committer | 2020-09-17 13:46:55 -0700 | |
commit | a7b46d0428b9c1c087afd6111fa23ad176b1583f (patch) | |
tree | 171de55b231d767ceeb51db9da22935441583054 /src/devices/sound | |
parent | aba8c220e89e5563c21aac3548a810adcdbfb71b (diff) |
dmadac/dspv: update to new stream callbacks
Diffstat (limited to 'src/devices/sound')
-rw-r--r-- | src/devices/sound/dmadac.cpp | 59 | ||||
-rw-r--r-- | src/devices/sound/dmadac.h | 7 | ||||
-rw-r--r-- | src/devices/sound/dspv.cpp | 2 | ||||
-rw-r--r-- | src/devices/sound/dspv.h | 2 |
4 files changed, 48 insertions, 22 deletions
diff --git a/src/devices/sound/dmadac.cpp b/src/devices/sound/dmadac.cpp index 3baba9b3c97..b3a7d84bbf5 100644 --- a/src/devices/sound/dmadac.cpp +++ b/src/devices/sound/dmadac.cpp @@ -21,7 +21,7 @@ * *************************************/ -#define DEFAULT_SAMPLE_RATE (44100) +#define DEFAULT_SAMPLE_RATE (48000) #define BUFFER_SIZE 32768 @@ -38,14 +38,11 @@ void dmadac_sound_device::device_start() { - /* allocate a clear a buffer */ - m_buffer = make_unique_clear<int16_t[]>(BUFFER_SIZE); - /* reset the state */ - m_volume = 0x100; + m_volume = 1.0; /* allocate a stream channel */ - m_channel = stream_alloc_legacy(0, 1, DEFAULT_SAMPLE_RATE); + m_channel = stream_alloc(0, 1, DEFAULT_SAMPLE_RATE); /* register with the save state system */ save_item(NAME(m_bufin)); @@ -53,7 +50,7 @@ void dmadac_sound_device::device_start() save_item(NAME(m_volume)); save_item(NAME(m_enabled)); save_item(NAME(m_frequency)); - save_pointer(NAME(m_buffer), BUFFER_SIZE); + save_item(NAME(m_buffer)); } @@ -91,6 +88,7 @@ void dmadac_sound_device::transfer(int channel, offs_t channel_spacing, offs_t f int j; /* loop over all channels and accumulate the data */ + constexpr stream_buffer::sample_t sample_scale = 1.0 / 32768.0; if (m_enabled) { int maxin = (m_bufout + BUFFER_SIZE - 1) % BUFFER_SIZE; @@ -100,6 +98,35 @@ void dmadac_sound_device::transfer(int channel, offs_t channel_spacing, offs_t f /* copy the data */ for (j = 0; j < total_frames && curin != maxin; j++) { + m_buffer[curin] = stream_buffer::sample_t(*src) * sample_scale; + curin = (curin + 1) % BUFFER_SIZE; + src += frame_spacing; + } + m_bufin = curin; + + /* log overruns */ + if (j != total_frames) + logerror("dmadac_transfer: buffer overrun (short %d frames)\n", total_frames - j); + } + + // FIXME: this line has rotted and can no longer compile - it should be fixed and uncommented or removed + //LOG("dmadac_transfer - %d samples, %d effective, %d in buffer\n", total_frames, int(total_frames * double(DEFAULT_SAMPLE_RATE) / dmadac[first_channel].frequency), dmadac[first_channel].curinpos - dmadac[first_channel].curoutpos); +} + +void dmadac_sound_device::transfer(int channel, offs_t channel_spacing, offs_t frame_spacing, offs_t total_frames, stream_buffer::sample_t *data) +{ + int j; + + /* loop over all channels and accumulate the data */ + if (m_enabled) + { + int maxin = (m_bufout + BUFFER_SIZE - 1) % BUFFER_SIZE; + stream_buffer::sample_t *src = data + channel * channel_spacing; + int curin = m_bufin; + + /* copy the data */ + for (j = 0; j < total_frames && curin != maxin; j++) + { m_buffer[curin] = *src; curin = (curin + 1) % BUFFER_SIZE; src += frame_spacing; @@ -187,7 +214,7 @@ void dmadac_set_volume(dmadac_sound_device **devlist, uint8_t num_channels, uint void dmadac_sound_device::set_volume(uint16_t volume) { m_channel->update(); - m_volume = volume; + m_volume = stream_buffer::sample_t(volume) * (1.0 / 256.0); } DEFINE_DEVICE_TYPE(DMADAC, dmadac_sound_device, "dmadac", "DMA-driven DAC") @@ -195,7 +222,7 @@ DEFINE_DEVICE_TYPE(DMADAC, dmadac_sound_device, "dmadac", "DMA-driven DAC") dmadac_sound_device::dmadac_sound_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) : device_t(mconfig, DMADAC, tag, owner, clock), device_sound_interface(mconfig, *this), - m_buffer(nullptr), + m_buffer(BUFFER_SIZE), m_bufin(0), m_bufout(0), m_volume(0), @@ -208,24 +235,22 @@ dmadac_sound_device::dmadac_sound_device(const machine_config &mconfig, const ch // sound_stream_update_legacy - handle a stream update //------------------------------------------------- -void dmadac_sound_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) +void dmadac_sound_device::sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs) { - stream_sample_t *output = outputs[0]; - int16_t *source = m_buffer.get(); + auto &output = outputs[0]; uint32_t curout = m_bufout; uint32_t curin = m_bufin; - int volume = m_volume; /* feed as much as we can */ - while (curout != curin && samples-- > 0) + int sampindex; + for (sampindex = 0; curout != curin && sampindex < output.samples(); sampindex++) { - *output++ = (source[curout] * volume) >> 8; + output.put(sampindex, stream_buffer::sample_t(m_buffer[curout]) * m_volume); curout = (curout + 1) % BUFFER_SIZE; } /* fill the rest with silence */ - while (samples-- > 0) - *output++ = 0; + output.fill(0, sampindex); /* save the new output pointer */ m_bufout = curout; diff --git a/src/devices/sound/dmadac.h b/src/devices/sound/dmadac.h index b3f5c8e05c0..eb73d338eb9 100644 --- a/src/devices/sound/dmadac.h +++ b/src/devices/sound/dmadac.h @@ -20,6 +20,7 @@ public: void flush(); void transfer(int channel, offs_t channel_spacing, offs_t frame_spacing, offs_t total_frames, int16_t *data); + void transfer(int channel, offs_t channel_spacing, offs_t frame_spacing, offs_t total_frames, stream_buffer::sample_t *data); void enable(uint8_t enable); void set_frequency(double frequency); void set_volume(uint16_t volume); @@ -29,18 +30,18 @@ protected: virtual void device_start() override; // sound stream update overrides - virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; + virtual void sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs) override; private: // internal state /* sound stream and buffers */ sound_stream * m_channel; - std::unique_ptr<int16_t[]> m_buffer; + std::vector<stream_buffer::sample_t> m_buffer; uint32_t m_bufin; uint32_t m_bufout; /* per-channel parameters */ - int16_t m_volume; + stream_buffer::sample_t m_volume; uint8_t m_enabled; double m_frequency; }; diff --git a/src/devices/sound/dspv.cpp b/src/devices/sound/dspv.cpp index 05c322db88e..7305c1c5298 100644 --- a/src/devices/sound/dspv.cpp +++ b/src/devices/sound/dspv.cpp @@ -93,7 +93,7 @@ void dspv_device::snd_w(offs_t offset, u16 data) logerror("w %02x, %04x %s\n", offset, data, machine().describe_context()); } -void dspv_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) +void dspv_device::sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs) { } diff --git a/src/devices/sound/dspv.h b/src/devices/sound/dspv.h index 4e37e225904..fb68acda569 100644 --- a/src/devices/sound/dspv.h +++ b/src/devices/sound/dspv.h @@ -29,7 +29,7 @@ protected: virtual void state_export(const device_state_entry &entry) override; virtual void state_string_export(const device_state_entry &entry, std::string &str) const override; virtual std::unique_ptr<util::disasm_interface> create_disassembler() override; - virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; + virtual void sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs) override; private: address_space_config m_program_config, m_data_config; |