mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-03-28 04:56:52 +01:00
Merge pull request #13441 from jordan-woyak/wm-speaker-cleanup
WiimoteEmu: Eliminate dynamic memory allocation in speaker data decoding.
This commit is contained in:
commit
18979129f3
@ -149,11 +149,12 @@ static_assert(sizeof(OutputReportReadData) == 6, "Wrong size");
|
|||||||
struct OutputReportSpeakerData
|
struct OutputReportSpeakerData
|
||||||
{
|
{
|
||||||
static constexpr OutputReportID REPORT_ID = OutputReportID::SpeakerData;
|
static constexpr OutputReportID REPORT_ID = OutputReportID::SpeakerData;
|
||||||
|
static constexpr size_t DATA_SIZE = 20;
|
||||||
|
|
||||||
u8 rumble : 1;
|
u8 rumble : 1;
|
||||||
u8 : 2;
|
u8 : 2;
|
||||||
u8 length : 5;
|
u8 length : 5;
|
||||||
u8 data[20];
|
std::array<u8, DATA_SIZE> data;
|
||||||
};
|
};
|
||||||
static_assert(sizeof(OutputReportSpeakerData) == 21, "Wrong size");
|
static_assert(sizeof(OutputReportSpeakerData) == 21, "Wrong size");
|
||||||
|
|
||||||
|
@ -390,7 +390,7 @@ void Wiimote::HandleSpeakerData(const WiimoteCommon::OutputReportSpeakerData& rp
|
|||||||
{
|
{
|
||||||
// Speaker data reports result in a write to the speaker hardware at offset 0x00.
|
// Speaker data reports result in a write to the speaker hardware at offset 0x00.
|
||||||
m_i2c_bus.BusWrite(SpeakerLogic::I2C_ADDR, SpeakerLogic::SPEAKER_DATA_OFFSET, rpt.length,
|
m_i2c_bus.BusWrite(SpeakerLogic::I2C_ADDR, SpeakerLogic::SPEAKER_DATA_OFFSET, rpt.length,
|
||||||
rpt.data);
|
std::data(rpt.data));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,14 +3,17 @@
|
|||||||
|
|
||||||
#include "Core/HW/WiimoteEmu/Speaker.h"
|
#include "Core/HW/WiimoteEmu/Speaker.h"
|
||||||
|
|
||||||
#include <memory>
|
#include <cassert>
|
||||||
|
|
||||||
#include "AudioCommon/AudioCommon.h"
|
#include "AudioCommon/AudioCommon.h"
|
||||||
|
|
||||||
#include "Common/CommonTypes.h"
|
#include "Common/CommonTypes.h"
|
||||||
#include "Common/Logging/Log.h"
|
#include "Common/Logging/Log.h"
|
||||||
|
|
||||||
#include "Core/ConfigManager.h"
|
#include "Core/ConfigManager.h"
|
||||||
#include "Core/HW/WiimoteEmu/WiimoteEmu.h"
|
#include "Core/HW/WiimoteEmu/WiimoteEmu.h"
|
||||||
#include "Core/System.h"
|
#include "Core/System.h"
|
||||||
|
|
||||||
#include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h"
|
#include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h"
|
||||||
#include "InputCommon/ControllerEmu/Setting/NumericSetting.h"
|
#include "InputCommon/ControllerEmu/Setting/NumericSetting.h"
|
||||||
|
|
||||||
@ -62,8 +65,9 @@ void SpeakerLogic::SpeakerData(const u8* data, int length, float speaker_pan)
|
|||||||
|
|
||||||
// Even if volume is zero we process samples to maintain proper decoder state.
|
// Even if volume is zero we process samples to maintain proper decoder state.
|
||||||
|
|
||||||
// TODO consider using static max size instead of new
|
// Potentially 40 resulting samples.
|
||||||
std::unique_ptr<s16[]> samples(new s16[length * 2]);
|
std::array<s16, WiimoteCommon::OutputReportSpeakerData::DATA_SIZE * 2> samples;
|
||||||
|
assert(length * 2 <= samples.size());
|
||||||
|
|
||||||
unsigned int sample_rate_dividend, sample_length;
|
unsigned int sample_rate_dividend, sample_length;
|
||||||
u8 volume_divisor;
|
u8 volume_divisor;
|
||||||
@ -130,7 +134,7 @@ void SpeakerLogic::SpeakerData(const u8* data, int length, float speaker_pan)
|
|||||||
// ADPCM sample rate is thought to be x2.(3000 x2 = 6000).
|
// ADPCM sample rate is thought to be x2.(3000 x2 = 6000).
|
||||||
const unsigned int sample_rate = sample_rate_dividend / reg_data.sample_rate;
|
const unsigned int sample_rate = sample_rate_dividend / reg_data.sample_rate;
|
||||||
sound_stream->GetMixer()->PushWiimoteSpeakerSamples(
|
sound_stream->GetMixer()->PushWiimoteSpeakerSamples(
|
||||||
samples.get(), sample_length, Mixer::FIXED_SAMPLE_RATE_DIVIDEND / (sample_rate * 2));
|
samples.data(), sample_length, Mixer::FIXED_SAMPLE_RATE_DIVIDEND / (sample_rate * 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpeakerLogic::Reset()
|
void SpeakerLogic::Reset()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user