Skip to content

Commit 00fd57b

Browse files
committed
samples: update notes, fix new regression with start_raw at very low samplerate
1 parent e93a207 commit 00fd57b

File tree

3 files changed

+67
-64
lines changed

3 files changed

+67
-64
lines changed

src/devices/sound/samples.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ for tape loops and similar.
1414
- Only supports single channel samples!
1515
- Maybe this should be part of the presentation layer (artwork etc.)
1616
with samples specified in .lay files instead of in drivers?
17+
- Unless it's an infinitely looping sample, start_raw() is not compatible
18+
with savestates. Save state right after start_raw(), load state later,
19+
and the sample won't be playing.
20+
- No need for m_samples_start_cb, drivers that need to initialize after
21+
samples_device::device_start can just throw missing dependencies.
22+
- No need for set_volume, can just use set_output_gain, but it's harmless.
1723
1824
***************************************************************************/
1925

@@ -234,14 +240,17 @@ void samples_device::device_start()
234240
m_channel.resize(m_channels);
235241
for (int channel = 0; channel < m_channels; channel++)
236242
{
243+
// placeholder, changed to sample SR at start()
244+
const uint32_t rate = machine().sample_rate();
245+
237246
// initialize channel
238247
channel_t &chan = m_channel[channel];
239-
chan.stream = stream_alloc(0, 1, machine().sample_rate());
248+
chan.stream = stream_alloc(0, 1, rate);
240249
chan.source = nullptr;
241250
chan.source_num = -1;
242251
chan.pos = 0.0;
243-
chan.basefreq = machine().sample_rate();
244-
chan.curfreq = machine().sample_rate();
252+
chan.basefreq = rate;
253+
chan.curfreq = rate;
245254
chan.loop = false;
246255
chan.paused = false;
247256

src/mame/exidy/exidy.cpp

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -297,12 +297,14 @@ class spectar_state : public exidy_state
297297

298298
protected:
299299
virtual void machine_start() override ATTR_COLD;
300+
virtual void machine_reset() override ATTR_COLD { exidy_state::machine_reset(); init_tonegen(); }
300301

301302
void set_max_freq(int freq) { m_max_freq = freq; }
302303

303304
void spectar_audio_1_w(uint8_t data);
304305
void spectar_audio_2_w(uint8_t data);
305306

307+
void init_tonegen();
306308
void adjust_sample(uint8_t freq);
307309
bool RISING_EDGE(uint8_t data, uint8_t bit) const { return (data & bit) && !(m_port_1_last & bit); }
308310
bool FALLING_EDGE(uint8_t data, uint8_t bit) const { return !(data & bit) && (m_port_1_last & bit); }
@@ -1469,14 +1471,6 @@ void spectar_state::machine_start()
14691471
{
14701472
exidy_state::machine_start();
14711473

1472-
/* start_raw can't be called here: chan.source will be set by
1473-
samples_device::device_start and then nulled out by samples_device::device_reset
1474-
at the soft_reset stage of init_machine() and will never be set again.
1475-
Thus, I've moved it to exidy_state::adjust_sample() were it will be set after
1476-
machine initialization. */
1477-
//m_samples->set_volume(3, 0);
1478-
//m_samples->start_raw(3, sine_wave, 32, 1000, true);
1479-
14801474
save_item(NAME(m_port_1_last));
14811475
save_item(NAME(m_tone_freq));
14821476
save_item(NAME(m_tone_active));
@@ -1700,28 +1694,34 @@ void fax_state::fax(machine_config &config)
17001694
*************************************************************************/
17011695

17021696
/* Sound channel usage
1703-
0 = CPU music, Shoot
1697+
0 = CPU music, Shoot
17041698
1 = Crash
17051699
2 = Spectar sound
17061700
3 = Tone generator
17071701
*/
17081702

1709-
static const int16_t sine_wave[32] =
1710-
{
1711-
0x0f0f, 0x0f0f, 0x0f0f, 0x0606, 0x0606, 0x0909, 0x0909, 0x0606, 0x0606, 0x0909, 0x0606, 0x0d0d, 0x0f0f, 0x0f0f, 0x0d0d, 0x0000,
1712-
-0x191a, -0x2122, -0x1e1f, -0x191a, -0x1314, -0x191a, -0x1819, -0x1819, -0x1819, -0x1314, -0x1314, -0x1314, -0x1819, -0x1e1f, -0x1e1f, -0x1819
1713-
};
1714-
1715-
1716-
void spectar_state::adjust_sample(uint8_t freq)
1703+
void spectar_state::init_tonegen()
17171704
{
1718-
m_tone_freq = freq;
1705+
static const int16_t sine_wave[32] =
1706+
{
1707+
0x0f0f, 0x0f0f, 0x0f0f, 0x0606, 0x0606, 0x0909, 0x0909, 0x0606,
1708+
0x0606, 0x0909, 0x0606, 0x0d0d, 0x0f0f, 0x0f0f, 0x0d0d, 0x0000,
1709+
-0x191a, -0x2122, -0x1e1f, -0x191a, -0x1314, -0x191a, -0x1819, -0x1819,
1710+
-0x1819, -0x1314, -0x1314, -0x1314, -0x1819, -0x1e1f, -0x1e1f, -0x1819
1711+
};
17191712

1713+
// initialized after samples_device::device_reset
17201714
if (!m_samples->playing(3))
17211715
{
17221716
m_samples->set_volume(3, 0);
1723-
m_samples->start_raw(3, sine_wave, 32, 1000, true);
1717+
m_samples->start_raw(3, sine_wave, 32, m_max_freq, true);
17241718
}
1719+
}
1720+
1721+
1722+
void spectar_state::adjust_sample(uint8_t freq)
1723+
{
1724+
m_tone_freq = freq;
17251725

17261726
if ((m_tone_freq == 0xff) || (m_tone_freq == 0x00))
17271727
m_samples->set_volume(3, 0);

src/mame/meadows/meadows.cpp

Lines changed: 36 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,8 @@ namespace {
150150
class meadows_state : public driver_device
151151
{
152152
public:
153-
meadows_state(const machine_config &mconfig, device_type type, const char *tag)
154-
: driver_device(mconfig, type, tag),
153+
meadows_state(const machine_config &mconfig, device_type type, const char *tag) :
154+
driver_device(mconfig, type, tag),
155155
m_maincpu(*this, "maincpu"),
156156
m_audiocpu(*this, "audiocpu"),
157157
m_dac(*this, "dac"),
@@ -175,6 +175,7 @@ class meadows_state : public driver_device
175175

176176
protected:
177177
virtual void machine_start() override ATTR_COLD;
178+
virtual void machine_reset() override ATTR_COLD { sh_init(); }
178179
virtual void video_start() override ATTR_COLD;
179180

180181
private:
@@ -189,9 +190,7 @@ class meadows_state : public driver_device
189190
optional_shared_ptr<uint8_t> m_spriteram;
190191
required_shared_ptr<uint8_t> m_videoram;
191192

192-
uint8_t m_channel = 0; // TODO: always 0?
193-
uint32_t m_freq1 = 0;
194-
uint32_t m_freq2 = 0;
193+
uint32_t m_freq[2] = { };
195194
uint8_t m_latched_0c01 = 0;
196195
uint8_t m_latched_0c02 = 0;
197196
uint8_t m_latched_0c03 = 0;
@@ -203,6 +202,10 @@ class meadows_state : public driver_device
203202
uint8_t m_0c03 = 0;
204203

205204
tilemap_t *m_bg_tilemap = nullptr;
205+
206+
void sh_init();
207+
void sh_update();
208+
206209
uint8_t hsync_chain_r();
207210
uint8_t vsync_chain_hi_r();
208211
uint8_t vsync_chain_lo_r();
@@ -217,8 +220,7 @@ class meadows_state : public driver_device
217220
void minferno_vblank_irq(int state);
218221
INTERRUPT_GEN_MEMBER(audio_interrupt);
219222
void draw_sprites(bitmap_ind16 &bitmap, const rectangle &clip);
220-
void sh_update();
221-
SAMPLES_START_CB_MEMBER(sh_start);
223+
222224
void audio_map(address_map &map) ATTR_COLD;
223225
void bowl3d_main_map(address_map &map) ATTR_COLD;
224226
void meadows_main_map(address_map &map) ATTR_COLD;
@@ -227,6 +229,12 @@ class meadows_state : public driver_device
227229
};
228230

229231

232+
/*************************************
233+
*
234+
* Sound handler
235+
*
236+
*************************************/
237+
230238
static constexpr uint32_t BASE_CTR1 = (5'000'000 / 256);
231239
static constexpr uint32_t BASE_CTR2 = (5'000'000 / 32);
232240

@@ -237,25 +245,19 @@ static constexpr uint8_t ENABLE_CTR1 = 0x08;
237245

238246
static const int16_t waveform[2] = { -120*256, 120*256 };
239247

240-
/************************************/
241-
/* Sound handler start */
242-
/************************************/
243-
SAMPLES_START_CB_MEMBER(meadows_state::sh_start)
248+
void meadows_state::sh_init()
244249
{
245-
m_0c00 = m_0c01 = m_0c02 = m_0c03 = 0;
246-
m_channel = 0;
247-
m_freq1 = m_freq2 = 1000;
248-
m_latched_0c01 = m_latched_0c02 = m_latched_0c03 = 0;
249-
250-
m_samples->set_volume(0, 0);
251-
m_samples->start_raw(0, waveform, std::size(waveform), m_freq1, true);
252-
m_samples->set_volume(1, 0);
253-
m_samples->start_raw(1, waveform, std::size(waveform), m_freq2, true);
250+
// initialized after samples_device::device_reset
251+
for (int i = 0; i < 2; i++)
252+
if (!m_samples->playing(i))
253+
{
254+
m_freq[i] = machine().sample_rate();
255+
256+
m_samples->set_volume(i, 0);
257+
m_samples->start_raw(i, waveform, std::size(waveform), m_freq[i], true);
258+
}
254259
}
255260

256-
/************************************/
257-
/* Sound handler update */
258-
/************************************/
259261
void meadows_state::sh_update()
260262
{
261263
if (m_latched_0c01 != m_0c01 || m_latched_0c03 != m_0c03)
@@ -269,10 +271,10 @@ void meadows_state::sh_update()
269271
bit 0..3 of 0c01 are ctr preset */
270272
int const preset = (m_0c01 & 15) ^ 15;
271273
if (preset)
272-
m_freq1 = BASE_CTR1 / (preset + 1);
274+
m_freq[0] = BASE_CTR1 / (preset + 1);
273275
else amp = 0;
274-
LOGAUDIO("meadows ctr1 channel #%d preset:%3d freq:%5d amp:%d\n", m_channel, preset, m_freq1, amp);
275-
m_samples->set_frequency(0, m_freq1 * sizeof(waveform) / 2);
276+
LOGAUDIO("meadows ctr1 channel #0 preset:%3d freq:%5d amp:%d\n", preset, m_freq[0], amp);
277+
m_samples->set_frequency(0, m_freq[0] * sizeof(waveform) / 2);
276278
m_samples->set_volume(0, amp / 255.0);
277279
}
278280

@@ -284,13 +286,13 @@ void meadows_state::sh_update()
284286
int const preset = m_0c02 ^ 0xff;
285287
if (preset)
286288
{
287-
m_freq2 = BASE_CTR2 / (preset + 1) / 2;
289+
m_freq[1] = BASE_CTR2 / (preset + 1) / 2;
288290
if ((m_0c03 & DIV2OR4_CTR2) == 0)
289-
m_freq2 >>= 1;
291+
m_freq[1] >>= 1;
290292
}
291293
else amp = 0;
292-
LOGAUDIO("meadows ctr2 channel #%d preset:%3d freq:%5d amp:%d\n", m_channel + 1, preset, m_freq2, amp);
293-
m_samples->set_frequency(1, m_freq2 * sizeof(waveform));
294+
LOGAUDIO("meadows ctr2 channel #1 preset:%3d freq:%5d amp:%d\n", preset, m_freq[1], amp);
295+
m_samples->set_frequency(1, m_freq[1] * sizeof(waveform));
294296
m_samples->set_volume(1, amp / 255.0);
295297
}
296298

@@ -305,10 +307,6 @@ void meadows_state::sh_update()
305307
}
306308

307309

308-
// some constants to make life easier
309-
static constexpr int8_t SPR_ADJUST_X = -18;
310-
static constexpr int8_t SPR_ADJUST_Y = -14;
311-
312310

313311
/*************************************
314312
*
@@ -375,8 +373,8 @@ void meadows_state::draw_sprites(bitmap_ind16 &bitmap, const rectangle &clip)
375373
{
376374
for (int i = 0; i < 4; i++)
377375
{
378-
int const x = m_spriteram[i + 0] + SPR_ADJUST_X;
379-
int const y = m_spriteram[i + 4] + SPR_ADJUST_Y;
376+
int const x = m_spriteram[i + 0] - 18;
377+
int const y = m_spriteram[i + 4] - 14;
380378
int const code = m_spriteram[i + 8] & 0x0f; // bit #0 .. #3 select sprite
381379
// int const bank = (m_spriteram[i + 8] >> 4) & 1; bit #4 selects PROM ???
382380
int const bank = i; // that fixes it for now :-/
@@ -409,9 +407,7 @@ void meadows_state::machine_start()
409407
{
410408
m_main_sense_state = 0;
411409

412-
// save_item(NAME(m_channel)); // commented out as it's always 0 right now
413-
save_item(NAME(m_freq1));
414-
save_item(NAME(m_freq2));
410+
save_item(NAME(m_freq));
415411
save_item(NAME(m_latched_0c01));
416412
save_item(NAME(m_latched_0c02));
417413
save_item(NAME(m_latched_0c03));
@@ -421,7 +417,6 @@ void meadows_state::machine_start()
421417
save_item(NAME(m_0c01));
422418
save_item(NAME(m_0c02));
423419
save_item(NAME(m_0c03));
424-
425420
}
426421

427422

@@ -939,11 +934,10 @@ void meadows_state::meadows(machine_config &config)
939934

940935
// audio hardware
941936
SPEAKER(config, "speaker").front_center();
942-
DAC_8BIT_R2R(config, m_dac, 0).add_route(ALL_OUTPUTS, "speaker", 0.5); // unknown DAC
937+
DAC_8BIT_R2R(config, m_dac).add_route(ALL_OUTPUTS, "speaker", 0.5); // unknown DAC
943938

944939
SAMPLES(config, m_samples);
945940
m_samples->set_channels(2);
946-
m_samples->set_samples_start_callback(FUNC(meadows_state::sh_start));
947941
m_samples->add_route(ALL_OUTPUTS, "speaker", 1.0);
948942
}
949943

0 commit comments

Comments
 (0)