Hooked up the emulated wiimote speaker's sample rate and volume set by the game.

This commit is contained in:
skidau 2014-10-07 21:43:32 +11:00
parent 85086e1e6c
commit f5b23834b5
1 changed files with 27 additions and 10 deletions

View File

@ -71,6 +71,9 @@ void Wiimote::SpeakerData(wm_speaker_data* sd)
// TODO consider using static max size instead of new
s16 *samples = new s16[sd->length * 2];
unsigned int sample_rate_dividend;
u8 volume_divisor;
if (m_reg_speaker.format == 0x40)
{
// 8 bit PCM
@ -79,11 +82,9 @@ void Wiimote::SpeakerData(wm_speaker_data* sd)
samples[i] = (s16)(s8)sd->data[i];
}
// Speaker Pan
unsigned int vol = (unsigned int)(m_options->settings[4]->GetValue() * 100);
g_sound_stream->GetMixer()->SetWiimoteSpeakerVolume(128 + vol, 128 - vol);
g_sound_stream->GetMixer()->PushWiimoteSpeakerSamples(samples, sd->length, 1500);
// Following details from http://wiibrew.org/wiki/Wiimote#Speaker
sample_rate_dividend = 12000000;
volume_divisor = 0xff;
}
else if (m_reg_speaker.format == 0x00)
{
@ -94,13 +95,29 @@ void Wiimote::SpeakerData(wm_speaker_data* sd)
samples[i * 2 + 1] = adpcm_yamaha_expand_nibble(m_adpcm_state, sd->data[i] & 0xf);
}
// Speaker Pan
unsigned int vol = (unsigned int)(m_options->settings[4]->GetValue() * 100);
g_sound_stream->GetMixer()->SetWiimoteSpeakerVolume(128 + vol, 128 - vol);
g_sound_stream->GetMixer()->PushWiimoteSpeakerSamples(samples, sd->length, 3000);
// Following details from http://wiibrew.org/wiki/Wiimote#Speaker
sample_rate_dividend = 6000000;
volume_divisor = 0x40;
}
// Speaker Pan
unsigned int vol = (unsigned int)(m_options->settings[4]->GetValue() * 100);
float amp = 10.0f; // Boost the speaker volume relative to the rest of the game audio
unsigned int sample_rate = sample_rate_dividend / Common::swap16(m_reg_speaker.sample_rate);
float speaker_volume_ratio = (float)m_reg_speaker.volume / volume_divisor;
unsigned int left_volume = (unsigned int)((128 + vol) * speaker_volume_ratio * amp);
unsigned int right_volume = (unsigned int)((128 - vol) * speaker_volume_ratio * amp);
if (left_volume > 255)
left_volume = 255;
if (right_volume > 255)
right_volume = 255;
g_sound_stream->GetMixer()->SetWiimoteSpeakerVolume(left_volume, right_volume);
g_sound_stream->GetMixer()->PushWiimoteSpeakerSamples(samples, sd->length, sample_rate);
#ifdef WIIMOTE_SPEAKER_DUMP
static int num = 0;