mirror of
https://github.com/holub/mame
synced 2025-06-07 13:23:50 +03:00
bbd: Add support for a continuously-varying frequency to avoid abusing the sound manager.
This commit is contained in:
parent
1b25f944f3
commit
7b5e54a3df
@ -17,7 +17,9 @@ bbd_device_base<Entries, Outputs>::bbd_device_base(const machine_config &mconfig
|
|||||||
device_t(mconfig, type, tag, owner, clock),
|
device_t(mconfig, type, tag, owner, clock),
|
||||||
device_sound_interface(mconfig, *this),
|
device_sound_interface(mconfig, *this),
|
||||||
m_stream(nullptr),
|
m_stream(nullptr),
|
||||||
m_curpos(0)
|
m_curpos(0),
|
||||||
|
m_cv_handler(*this),
|
||||||
|
m_next_bbdtime(attotime::zero)
|
||||||
{
|
{
|
||||||
std::fill_n(&m_buffer[0], Entries, 0);
|
std::fill_n(&m_buffer[0], Entries, 0);
|
||||||
}
|
}
|
||||||
@ -30,8 +32,16 @@ bbd_device_base<Entries, Outputs>::bbd_device_base(const machine_config &mconfig
|
|||||||
template<int Entries, int Outputs>
|
template<int Entries, int Outputs>
|
||||||
void bbd_device_base<Entries, Outputs>::device_start()
|
void bbd_device_base<Entries, Outputs>::device_start()
|
||||||
{
|
{
|
||||||
|
m_cv_handler.resolve();
|
||||||
|
|
||||||
|
if (m_cv_handler.isnull())
|
||||||
m_stream = stream_alloc(1, Outputs, sample_rate());
|
m_stream = stream_alloc(1, Outputs, sample_rate());
|
||||||
|
else
|
||||||
|
m_stream = stream_alloc(1, Outputs, SAMPLE_RATE_OUTPUT_ADAPTIVE, STREAM_DISABLE_INPUT_RESAMPLING);
|
||||||
|
|
||||||
save_item(NAME(m_buffer));
|
save_item(NAME(m_buffer));
|
||||||
|
save_item(NAME(m_curpos));
|
||||||
|
save_item(NAME(m_next_bbdtime));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -56,6 +66,8 @@ void bbd_device_base<Entries, Outputs>::sound_stream_update(sound_stream &stream
|
|||||||
// BBDs that I've seen so far typically have 2 outputs, with the first outputting
|
// BBDs that I've seen so far typically have 2 outputs, with the first outputting
|
||||||
// sample n-1 and the second outputting sampe n; if chips with more outputs
|
// sample n-1 and the second outputting sampe n; if chips with more outputs
|
||||||
// or other taps turn up, this logic will need to be made more flexible
|
// or other taps turn up, this logic will need to be made more flexible
|
||||||
|
if (m_cv_handler.isnull())
|
||||||
|
{
|
||||||
for (int sampindex = 0; sampindex < outputs[0].samples(); sampindex++)
|
for (int sampindex = 0; sampindex < outputs[0].samples(); sampindex++)
|
||||||
{
|
{
|
||||||
for (int outnum = 0; outnum < Outputs; outnum++)
|
for (int outnum = 0; outnum < Outputs; outnum++)
|
||||||
@ -64,6 +76,41 @@ void bbd_device_base<Entries, Outputs>::sound_stream_update(sound_stream &stream
|
|||||||
m_curpos = (m_curpos + 1) % Entries;
|
m_curpos = (m_curpos + 1) % Entries;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
read_stream_view in(inputs[0], m_next_bbdtime);
|
||||||
|
attotime intime = in.start_time();
|
||||||
|
attotime outtime = outputs[0].start_time();
|
||||||
|
int inpos = 0;
|
||||||
|
|
||||||
|
// loop until all outputs generated
|
||||||
|
for (int sampindex = 0; sampindex < outputs[0].samples(); sampindex++)
|
||||||
|
{
|
||||||
|
// we need to process some more BBD input
|
||||||
|
while (outtime >= m_next_bbdtime)
|
||||||
|
{
|
||||||
|
// find the input sample that overlaps our start time
|
||||||
|
while (intime + in.sample_period() < m_next_bbdtime)
|
||||||
|
{
|
||||||
|
inpos++;
|
||||||
|
intime += in.sample_period();
|
||||||
|
}
|
||||||
|
|
||||||
|
// copy that to the buffer
|
||||||
|
m_buffer[m_curpos] = in.get(inpos);
|
||||||
|
m_curpos = (m_curpos + 1) % std::size(m_buffer);
|
||||||
|
|
||||||
|
// advance the end time of this BBD sample
|
||||||
|
m_next_bbdtime += attotime(0, m_cv_handler(m_next_bbdtime));
|
||||||
|
}
|
||||||
|
|
||||||
|
// copy the most recently-generated BBD data
|
||||||
|
for (int outnum = 0; outnum < Outputs; outnum++)
|
||||||
|
outputs[outnum].put(sampindex, outputval(outnum - (Outputs - 1)));
|
||||||
|
outtime += outputs[0].sample_period();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//**************************************************************************
|
//**************************************************************************
|
||||||
|
@ -14,13 +14,19 @@
|
|||||||
template<int Entries, int Outputs>
|
template<int Entries, int Outputs>
|
||||||
class bbd_device_base : public device_t, public device_sound_interface
|
class bbd_device_base : public device_t, public device_sound_interface
|
||||||
{
|
{
|
||||||
|
public:
|
||||||
|
// configuration
|
||||||
|
template <typename... T> void set_cv_handler(T &&... args)
|
||||||
|
{
|
||||||
|
m_cv_handler.set(std::forward<T>(args)...);
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
using cv_delegate = device_delegate<attoseconds_t (attotime const &)>;
|
||||||
|
|
||||||
// internal constructor
|
// internal constructor
|
||||||
bbd_device_base(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock, device_type type);
|
bbd_device_base(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock, device_type type);
|
||||||
|
|
||||||
// override to convert clock to sample rate
|
|
||||||
virtual u32 sample_rate() const { return clock(); }
|
|
||||||
|
|
||||||
// device-level overrides
|
// device-level overrides
|
||||||
virtual void device_start() override;
|
virtual void device_start() override;
|
||||||
virtual void device_clock_changed() override;
|
virtual void device_clock_changed() override;
|
||||||
@ -29,9 +35,15 @@ protected:
|
|||||||
virtual void sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs) override;
|
virtual void sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
// override to convert clock to sample rate
|
||||||
|
stream_buffer::sample_t outputval(s32 index) const { return m_buffer[m_curpos + Entries + index]; }
|
||||||
|
virtual u32 sample_rate() const { return clock(); }
|
||||||
|
|
||||||
sound_stream * m_stream;
|
sound_stream * m_stream;
|
||||||
u32 m_curpos;
|
u32 m_curpos;
|
||||||
stream_buffer::sample_t m_buffer[Entries];
|
cv_delegate m_cv_handler;
|
||||||
|
attotime m_next_bbdtime;
|
||||||
|
stream_buffer::sample_t m_buffer[Entries + 1];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user