Esempio n. 1
0
void Wiimote::SpeakerData(wm_speaker_data* sd)
{
    // TODO consider using static max size instead of new
    s16 *samples = new s16[sd->length * 2];

    if (m_reg_speaker.format == 0x40)
    {
        // 8 bit PCM
        for (int i = 0; i < sd->length; ++i)
        {
            samples[i] = (s16)(s8)sd->data[i];
        }
    }
    else if (m_reg_speaker.format == 0x00)
    {
        // 4 bit Yamaha ADPCM (same as dreamcast)
        for (int i = 0; i < sd->length; ++i)
        {
            samples[i * 2] = adpcm_yamaha_expand_nibble(m_adpcm_state, (sd->data[i] >> 4) & 0xf);
            samples[i * 2 + 1] = adpcm_yamaha_expand_nibble(m_adpcm_state, sd->data[i] & 0xf);
        }
    }

#ifdef WIIMOTE_SPEAKER_DUMP
    static int num = 0;

    if (num == 0)
    {
        File::Delete("rmtdump.wav");
        File::Delete("rmtdump.bin");
        atexit(stopdamnwav);
        OpenFStream(ofile, "rmtdump.bin", ofile.binary | ofile.out);
        wav.Start("rmtdump.wav", 6000/*Common::swap16(m_reg_speaker.sample_rate)*/);
    }
    wav.AddMonoSamples(samples, sd->length*2);
    if (ofile.good())
    {
        for (int i = 0; i < sd->length; i++)
        {
            ofile << sd->data[i];
        }
    }
    num++;
#endif

    delete[] samples;
}
Esempio n. 2
0
void Wiimote::SpeakerData(wm_speaker_data* sd)
{
	if (!SConfig::GetInstance().m_WiimoteEnableSpeaker)
		return;
	if (m_reg_speaker.volume == 0 || m_reg_speaker.sample_rate == 0 || sd->length == 0)
		return;

	// TODO consider using static max size instead of new
	std::unique_ptr<s16[]> samples(new s16[sd->length * 2]);

	unsigned int sample_rate_dividend, sample_length;
	u8 volume_divisor;

	if (m_reg_speaker.format == 0x40)
	{
		// 8 bit PCM
		for (int i = 0; i < sd->length; ++i)
		{
			samples[i] = ((s16)(s8)sd->data[i]) << 8;
		}

		// Following details from http://wiibrew.org/wiki/Wiimote#Speaker
		sample_rate_dividend = 12000000;
		volume_divisor = 0xff;
		sample_length = (unsigned int)sd->length;
	}
	else if (m_reg_speaker.format == 0x00)
	{
		// 4 bit Yamaha ADPCM (same as dreamcast)
		for (int i = 0; i < sd->length; ++i)
		{
			samples[i * 2] = adpcm_yamaha_expand_nibble(m_adpcm_state, (sd->data[i] >> 4) & 0xf);
			samples[i * 2 + 1] = adpcm_yamaha_expand_nibble(m_adpcm_state, sd->data[i] & 0xf);
		}

		// Following details from http://wiibrew.org/wiki/Wiimote#Speaker
		sample_rate_dividend = 6000000;

		// 0 - 127
		// TODO: does it go beyond 127 for format == 0x40?
		volume_divisor = 0x7F;
		sample_length = (unsigned int)sd->length * 2;
	}
	else
	{