SB16: fixed output volume calculation.
ES1370: fixed and improved output volume calculation similar to SB16. TODO: apply volume control to the FM output.
This commit is contained in:
parent
d93eeb98be
commit
10d79f2e9a
@ -504,10 +504,9 @@ void bx_es1370_c::write(Bit32u address, Bit32u value, unsigned io_len)
|
||||
#endif // !BX_USE_ES1370_SMF
|
||||
Bit16u offset;
|
||||
Bit32u shift, mask;
|
||||
Bit8u index, master_vol, dac_vol;
|
||||
Bit8u index;
|
||||
bx_bool set_wave_vol = 0;
|
||||
unsigned i;
|
||||
float tmp_vol;
|
||||
|
||||
BX_DEBUG(("register write to address 0x%04x - value = 0x%08x", address, value));
|
||||
|
||||
@ -588,17 +587,26 @@ void bx_es1370_c::write(Bit32u address, Bit32u value, unsigned io_len)
|
||||
}
|
||||
|
||||
if (set_wave_vol) {
|
||||
master_vol = (0x1f - (BX_ES1370_THIS s.codec_reg[0] & 0x1f));
|
||||
dac_vol = (0x1f - (BX_ES1370_THIS s.codec_reg[2] & 0x1f));
|
||||
tmp_vol = (float)master_vol/31.0f*pow(10.0f, (float)(31-dac_vol)*-0.065f);
|
||||
BX_ES1370_THIS s.wave_vol = (Bit8u)(255 * tmp_vol);
|
||||
master_vol = (0x1f - (BX_ES1370_THIS s.codec_reg[1] & 0x1f));
|
||||
dac_vol = (0x1f - (BX_ES1370_THIS s.codec_reg[3] & 0x1f));
|
||||
tmp_vol = (float)master_vol/31.0f*pow(10.0f, (float)(31-dac_vol)*-0.065f);
|
||||
BX_ES1370_THIS s.wave_vol |= ((Bit8u)(255 * tmp_vol) << 8);
|
||||
BX_ES1370_THIS s.wave_vol = calc_output_volume(0x00, 0x02, 0);
|
||||
BX_ES1370_THIS s.wave_vol |= calc_output_volume(0x01, 0x03, 1);
|
||||
}
|
||||
}
|
||||
|
||||
Bit16u bx_es1370_c::calc_output_volume(Bit8u reg1, Bit8u reg2, bx_bool shift)
|
||||
{
|
||||
Bit8u vol1, vol2;
|
||||
float fvol1, fvol2;
|
||||
Bit16u result;
|
||||
|
||||
vol1 = (0x1f - (BX_ES1370_THIS s.codec_reg[reg1] & 0x1f));
|
||||
vol2 = (0x1f - (BX_ES1370_THIS s.codec_reg[reg2] & 0x1f));
|
||||
fvol1 = pow(10.0f, (float)(31-vol1)*-0.065f);
|
||||
fvol2 = pow(10.0f, (float)(31-vol2)*-0.065f);
|
||||
result = (Bit8u)(255 * fvol1 * fvol2);
|
||||
if (shift) result <<= 8;
|
||||
return result;
|
||||
}
|
||||
|
||||
void bx_es1370_c::es1370_timer_handler(void *this_ptr)
|
||||
{
|
||||
bx_es1370_c *class_ptr = (bx_es1370_c *) this_ptr;
|
||||
|
@ -104,6 +104,7 @@ private:
|
||||
BX_ES1370_SMF void run_channel(unsigned channel, int timer_id, Bit32u buflen);
|
||||
BX_ES1370_SMF void sendwavepacket(unsigned channel, Bit32u buflen, Bit8u *buffer);
|
||||
BX_ES1370_SMF void closewaveoutput();
|
||||
BX_ES1370_SMF Bit16u calc_output_volume(Bit8u reg1, Bit8u reg2, bx_bool shift);
|
||||
|
||||
static void es1370_timer_handler(void *);
|
||||
void es1370_timer(void);
|
||||
|
@ -1589,13 +1589,14 @@ Bit16u bx_sb16_c::dma_write16(Bit16u *buffer, Bit16u maxlen)
|
||||
Bit16u bx_sb16_c::calc_output_volume(Bit8u reg1, Bit8u reg2, bx_bool shift)
|
||||
{
|
||||
Bit8u vol1, vol2;
|
||||
float tmp_vol;
|
||||
float fvol1, fvol2;
|
||||
Bit16u result;
|
||||
|
||||
vol1 = (MIXER.reg[reg1] >> 3);
|
||||
vol2 = (MIXER.reg[reg2] >> 3);
|
||||
tmp_vol = (float)vol1/31.0f*pow(10.0f, (float)(31-vol2)*-0.065f);
|
||||
result = (Bit8u)(255 * tmp_vol);
|
||||
fvol1 = pow(10.0f, (float)(31-vol1)*-0.065f);
|
||||
fvol2 = pow(10.0f, (float)(31-vol2)*-0.065f);
|
||||
result = (Bit8u)(255 * fvol1 * fvol2);
|
||||
if (shift) result <<= 8;
|
||||
return result;
|
||||
}
|
||||
@ -1604,7 +1605,7 @@ Bit16u bx_sb16_c::calc_output_volume(Bit8u reg1, Bit8u reg2, bx_bool shift)
|
||||
void bx_sb16_c::mixer_writedata(Bit32u value)
|
||||
{
|
||||
int i;
|
||||
bx_bool set_output_vol = 0;
|
||||
Bit8u set_output_vol = 0;
|
||||
|
||||
// do some action depending on what register was written
|
||||
switch (MIXER.regindex)
|
||||
@ -1630,7 +1631,7 @@ void bx_sb16_c::mixer_writedata(Bit32u value)
|
||||
MIXER.reg[i] = 0x80;
|
||||
|
||||
MIXER.regindex = 0; // next mixer register read is register 0
|
||||
set_output_vol = 1;
|
||||
set_output_vol = 3;
|
||||
return;
|
||||
|
||||
case 0x04: // DAC level
|
||||
@ -1646,13 +1647,13 @@ void bx_sb16_c::mixer_writedata(Bit32u value)
|
||||
case 0x22: // master volume
|
||||
MIXER.reg[0x30] = (value & 0xf0) | 0x08;
|
||||
MIXER.reg[0x31] = ((value & 0x0f) << 4) | 0x08;
|
||||
set_output_vol = 1;
|
||||
set_output_vol = 3;
|
||||
break;
|
||||
|
||||
case 0x26: // FM level
|
||||
MIXER.reg[0x34] = (value & 0xf0) | 0x08;
|
||||
MIXER.reg[0x35] = ((value & 0x0f) << 4) | 0x08;
|
||||
set_output_vol = 1;
|
||||
set_output_vol = 2;
|
||||
break;
|
||||
|
||||
case 0x28: // CD audio level
|
||||
@ -1668,13 +1669,13 @@ void bx_sb16_c::mixer_writedata(Bit32u value)
|
||||
case 0x30: // master volume left
|
||||
MIXER.reg[0x22] &= 0x0f;
|
||||
MIXER.reg[0x22] |= (value & 0xf0);
|
||||
set_output_vol = 1;
|
||||
set_output_vol = 3;
|
||||
break;
|
||||
|
||||
case 0x31: // master volume right
|
||||
MIXER.reg[0x22] &= 0xf0;
|
||||
MIXER.reg[0x22] |= (value >> 4);
|
||||
set_output_vol = 1;
|
||||
set_output_vol = 3;
|
||||
break;
|
||||
|
||||
case 0x32: // DAC level left
|
||||
@ -1692,13 +1693,13 @@ void bx_sb16_c::mixer_writedata(Bit32u value)
|
||||
case 0x34: // FM level left
|
||||
MIXER.reg[0x26] &= 0x0f;
|
||||
MIXER.reg[0x26] |= (value & 0xf0);
|
||||
set_output_vol = 1;
|
||||
set_output_vol = 2;
|
||||
break;
|
||||
|
||||
case 0x35: // FM level right
|
||||
MIXER.reg[0x26] &= 0xf0;
|
||||
MIXER.reg[0x26] |= (value >> 4);
|
||||
set_output_vol = 1;
|
||||
set_output_vol = 2;
|
||||
break;
|
||||
|
||||
case 0x36: // CD audio level left
|
||||
@ -1753,9 +1754,11 @@ void bx_sb16_c::mixer_writedata(Bit32u value)
|
||||
// store the value
|
||||
MIXER.reg[MIXER.regindex] = value;
|
||||
|
||||
if (set_output_vol) {
|
||||
if (set_output_vol & 1) {
|
||||
DSP.dma.param.volume = calc_output_volume(0x30, 0x32, 0);
|
||||
DSP.dma.param.volume |= calc_output_volume(0x31, 0x33, 1);
|
||||
}
|
||||
if (set_output_vol & 2) {
|
||||
BX_SB16_THIS fm_volume = calc_output_volume(0x30, 0x34, 0);
|
||||
BX_SB16_THIS fm_volume |= calc_output_volume(0x31, 0x35, 1);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user