okim6376: fix regression, small cleanup

This commit is contained in:
hap 2025-05-18 10:07:55 +02:00
parent 1fbfb5752e
commit f52a3fa1d1
2 changed files with 57 additions and 58 deletions

View File

@ -80,10 +80,10 @@ static void compute_tables()
for (nib = 0; nib < 16; nib++)
{
diff_lookup[step*16 + nib] = nbl2bit[nib][0] *
(stepval * nbl2bit[nib][1] +
stepval/2 * nbl2bit[nib][2] +
stepval/4 * nbl2bit[nib][3] +
stepval/8);
(stepval * nbl2bit[nib][1] +
stepval/2 * nbl2bit[nib][2] +
stepval/4 * nbl2bit[nib][3] +
stepval/8);
}
}
@ -113,24 +113,24 @@ void okim6376_device::ADPCMVoice::reset()
DEFINE_DEVICE_TYPE(OKIM6376, okim6376_device, "okim6376", "OKI MSM6376 ADPCM")
DEFINE_DEVICE_TYPE(OKIM6650, okim6650_device, "okim6650", "OKI MSM6650 ADPCM")
okim6376_device::okim6376_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock, int addrbits)
: device_t(mconfig, type, tag, owner, clock),
device_sound_interface(mconfig, *this),
device_rom_interface(mconfig, *this),
//m_command[OKIM6376_VOICES],
m_latch(0),
//m_stage[OKIM6376_VOICES],
m_stream(nullptr),
m_divisor(8),
m_channel(0),
m_nar(0),
m_nartimer(0),
m_busy(0),
m_ch2(0),
m_st(0),
m_st_pulses(0),
m_ch2_update(0),
m_st_update(0)
okim6376_device::okim6376_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock, int addrbits) :
device_t(mconfig, type, tag, owner, clock),
device_sound_interface(mconfig, *this),
device_rom_interface(mconfig, *this),
//m_command[OKIM6376_VOICES],
m_latch(0),
//m_stage[OKIM6376_VOICES],
m_stream(nullptr),
m_divisor(8),
m_channel(0),
m_nar(0),
m_nartimer(0),
m_busy(0),
m_ch2(0),
m_st(0),
m_st_pulses(0),
m_ch2_update(0),
m_st_update(0)
{
override_address_width(addrbits);
}
@ -188,10 +188,8 @@ void okim6376_device::device_start()
void okim6376_device::device_reset()
{
int i;
m_stream->update();
for (i = 0; i < OKIM6376_VOICES; i++)
for (int i = 0; i < OKIM6376_VOICES; i++)
m_voice[i].playing = 0;
}
@ -304,7 +302,7 @@ void okim6376_device::oki_process(int channel, int command)
}
else
{
if (((m_nar)&&(channel == 0))||(channel == 1))//Store the request, for later processing (channel 2 ignores NAR)
if ((m_nar && (channel == 0)) || (channel == 1)) // Store the request, for later processing (channel 2 ignores NAR)
{
m_stage[channel] = 1;
}
@ -318,10 +316,9 @@ void okim6376_device::oki_process(int channel, int command)
/* update the stream, then turn it off */
m_stream->update();
if (command ==0)
if (command == 0)
{
int i;
for (i = 0; i < OKIM6376_VOICES; i++)
for (int i = 0; i < OKIM6376_VOICES; i++)
{
struct ADPCMVoice *voice = &m_voice[i];
voice->playing = 0;
@ -349,8 +346,6 @@ void okim6376_device::generate_adpcm(struct ADPCMVoice *voice, int16_t *buffer,
/* loop while we still have samples to generate */
while (samples)
{
int nibble;
if (count == 0)
{
/* get the number of samples to play */
@ -370,7 +365,7 @@ void okim6376_device::generate_adpcm(struct ADPCMVoice *voice, int16_t *buffer,
}
/* compute the new amplitude and update the current step */
nibble = read_byte(base + sample / 2) >> (((sample & 1) << 2) ^ 4);
int nibble = read_byte(base + sample / 2) >> (((sample & 1) << 2) ^ 4);
/* output to the buffer, scaling by the volume */
/* signal in range -4096..4095, volume in range 2..16 => signal * volume / 2 in range -32768..32767 */
@ -386,7 +381,11 @@ void okim6376_device::generate_adpcm(struct ADPCMVoice *voice, int16_t *buffer,
voice->count = count;
}
if ((!voice->playing)&&(m_stage[channel]))//end of samples, load anything staged in
/* fill the rest with silence */
while (samples--)
*buffer++ = 0;
if (!voice->playing && m_stage[channel]) // end of samples, load anything staged in
{
m_stage[channel] = 0;
oki_process(channel,m_command[channel]);
@ -475,7 +474,7 @@ int okim6376_device::nar_r()
void okim6376_device::ch2_w(int state)
{
m_ch2_update = 0;//Clear flag
m_ch2_update = 0; // Clear flag
LOG("OKIM6376: CH2 %x\n",state);
if (m_ch2 != state)
@ -483,7 +482,7 @@ void okim6376_device::ch2_w(int state)
m_ch2 = state;
m_ch2_update = 1;
}
if((!m_ch2)&&(m_ch2_update))
if (!m_ch2 && m_ch2_update)
{
m_st_pulses = 0;
struct ADPCMVoice *voice0 = &m_voice[0];
@ -492,17 +491,17 @@ void okim6376_device::ch2_w(int state)
LOG("OKIM6376: Channel 1\n");
m_channel = 1;
if ((voice0->playing)&&(m_st))
if (voice0->playing && m_st)
{
//Echo functions when Channel 1 is playing, and ST is still high
m_command[1] = m_command[0];//copy sample over
voice1->volume = volume_table[1]; //echo is 6dB attenuated
// Echo functions when Channel 1 is playing, and ST is still high
m_command[1] = m_command[0]; // copy sample over
voice1->volume = volume_table[1]; // echo is 6dB attenuated
}
}
if((m_ch2)&&(m_ch2_update))
if (m_ch2 && m_ch2_update)
{
m_stage[1]=0;
m_stage[1] = 0;
oki_process(1, m_command[1]);
LOG("OKIM6376: Channel 0\n");
m_channel = 0;
@ -512,9 +511,9 @@ void okim6376_device::ch2_w(int state)
void okim6376_device::st_w(int state)
{
//As in STart, presumably, this triggers everything
// As in STart, presumably, this triggers everything
m_st_update = 0;//Clear flag
m_st_update = 0; // Clear flag
LOG("OKIM6376: ST %x\n",state);
if (m_st != state)
@ -522,7 +521,7 @@ void okim6376_device::st_w(int state)
m_st = state;
m_st_update = 1;
if ((m_channel == 1) & !m_st)//ST acts as attenuation for Channel 2 when low, and stays at that level until the channel is reset
if ((m_channel == 1) & !m_st) // ST acts as attenuation for Channel 2 when low, and stays at that level until the channel is reset
{
struct ADPCMVoice *voice = &m_voice[m_channel];
{
@ -530,7 +529,7 @@ void okim6376_device::st_w(int state)
LOG("OKIM6376: ST pulses %x\n",m_st_pulses);
if (m_st_pulses > 3)
{
m_st_pulses = 3; //undocumented behaviour beyond 3 pulses
m_st_pulses = 3; // undocumented behaviour beyond 3 pulses
}
voice->volume = volume_table[m_st_pulses - 1];
@ -539,13 +538,13 @@ void okim6376_device::st_w(int state)
if (m_st && m_st_update)
{
m_command[m_channel] = m_latch;
if (m_channel ==0 && m_nar)
if (m_channel == 0 && m_nar)
{
m_stage[m_channel]=0;
m_stage[m_channel] = 0;
oki_process(0, m_command[0]);
m_nar = 0;
m_nartimer = 4;
/*According to datasheet, NAR timing is ~375 us at 8KHz, and is inversely proportional to sample rate, effectively 6 stream updates. */
/* According to datasheet, NAR timing is ~375 us at 8KHz, and is inversely proportional to sample rate, effectively 6 stream updates. */
}
}
}

View File

@ -31562,6 +31562,16 @@ mirax
miraxa
miraxb
@source:misc/miuchiz.cpp
miuchiz
mcb_cloe
mcb_yasmin
mcm_creeper
mcm_inferno
mcm_roc
mcp_dash
mcp_spike
@source:misc/mirderby.cpp
mirderby
@ -43190,16 +43200,6 @@ minifram
@source:skeleton/minihock.cpp
minihockey
@source:misc/miuchiz.cpp
miuchiz
mcb_cloe
mcb_yasmin
mcm_creeper
mcm_inferno
mcm_roc
mcp_dash
mcp_spike
@source:skeleton/ml20.cpp
ml20