mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-04-24 22:34:54 +00:00
IOS/USB: Implement Wii Speak SAMPLER_FREQ register properly
Fix the default sampling rate which should be 16KHz
This commit is contained in:
parent
61e539ca33
commit
76387cbd6c
4 changed files with 19 additions and 11 deletions
|
@ -45,7 +45,7 @@ void Microphone::StreamInit()
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Not here but rather inside the WiiSpeak device if possible?
|
// TODO: Not here but rather inside the WiiSpeak device if possible?
|
||||||
StreamStart();
|
StreamStart(m_sampler.DEFAULT_SAMPLING_RATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Microphone::StreamTerminate()
|
void Microphone::StreamTerminate()
|
||||||
|
@ -60,12 +60,12 @@ static void state_callback(cubeb_stream* stream, void* user_data, cubeb_state st
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void Microphone::StreamStart()
|
void Microphone::StreamStart(u32 sampling_rate)
|
||||||
{
|
{
|
||||||
if (!m_cubeb_ctx)
|
if (!m_cubeb_ctx)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
m_worker.Execute([this] {
|
m_worker.Execute([this, sampling_rate] {
|
||||||
#ifdef ANDROID
|
#ifdef ANDROID
|
||||||
JNIEnv* env = IDCache::GetEnvForThread();
|
JNIEnv* env = IDCache::GetEnvForThread();
|
||||||
if (jboolean result = env->CallStaticBooleanMethod(
|
if (jboolean result = env->CallStaticBooleanMethod(
|
||||||
|
@ -81,7 +81,7 @@ void Microphone::StreamStart()
|
||||||
|
|
||||||
cubeb_stream_params params{};
|
cubeb_stream_params params{};
|
||||||
params.format = CUBEB_SAMPLE_S16LE;
|
params.format = CUBEB_SAMPLE_S16LE;
|
||||||
params.rate = SAMPLING_RATE;
|
params.rate = sampling_rate;
|
||||||
params.channels = 1;
|
params.channels = 1;
|
||||||
params.layout = CUBEB_LAYOUT_MONO;
|
params.layout = CUBEB_LAYOUT_MONO;
|
||||||
|
|
||||||
|
@ -249,6 +249,12 @@ Microphone::FloatType Microphone::ComputeGain(FloatType relative_db) const
|
||||||
return m_loudness.ComputeGain(relative_db);
|
return m_loudness.ComputeGain(relative_db);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Microphone::SetSamplingRate(u32 sampling_rate)
|
||||||
|
{
|
||||||
|
StreamStop();
|
||||||
|
StreamStart(sampling_rate);
|
||||||
|
}
|
||||||
|
|
||||||
const Microphone::FloatType Microphone::Loudness::DB_MIN =
|
const Microphone::FloatType Microphone::Loudness::DB_MIN =
|
||||||
20 * std::log10(FloatType(1) / MAX_AMPLITUDE);
|
20 * std::log10(FloatType(1) / MAX_AMPLITUDE);
|
||||||
const Microphone::FloatType Microphone::Loudness::DB_MAX = 20 * std::log10(FloatType(1));
|
const Microphone::FloatType Microphone::Loudness::DB_MAX = 20 * std::log10(FloatType(1));
|
||||||
|
|
|
@ -37,6 +37,7 @@ public:
|
||||||
void UpdateLoudness(std::ranges::input_range auto&& samples);
|
void UpdateLoudness(std::ranges::input_range auto&& samples);
|
||||||
const WiiSpeakState& GetSampler() const;
|
const WiiSpeakState& GetSampler() const;
|
||||||
FloatType ComputeGain(FloatType relative_db) const;
|
FloatType ComputeGain(FloatType relative_db) const;
|
||||||
|
void SetSamplingRate(u32 sampling_rate);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static long DataCallback(cubeb_stream* stream, void* user_data, const void* input_buffer,
|
static long DataCallback(cubeb_stream* stream, void* user_data, const void* input_buffer,
|
||||||
|
@ -44,12 +45,11 @@ private:
|
||||||
|
|
||||||
void StreamInit();
|
void StreamInit();
|
||||||
void StreamTerminate();
|
void StreamTerminate();
|
||||||
void StreamStart();
|
void StreamStart(u32 sampling_rate);
|
||||||
void StreamStop();
|
void StreamStop();
|
||||||
|
|
||||||
static constexpr u32 SAMPLING_RATE = 8000;
|
|
||||||
using SampleType = s16;
|
using SampleType = s16;
|
||||||
static constexpr u32 BUFF_SIZE_SAMPLES = 16;
|
static constexpr u32 BUFF_SIZE_SAMPLES = 32;
|
||||||
static constexpr u32 STREAM_SIZE = BUFF_SIZE_SAMPLES * 500;
|
static constexpr u32 STREAM_SIZE = BUFF_SIZE_SAMPLES * 500;
|
||||||
|
|
||||||
std::array<SampleType, STREAM_SIZE> m_stream_buffer{};
|
std::array<SampleType, STREAM_SIZE> m_stream_buffer{};
|
||||||
|
@ -96,8 +96,8 @@ private:
|
||||||
void Reset();
|
void Reset();
|
||||||
void LogStats();
|
void LogStats();
|
||||||
|
|
||||||
// Samples used to compute the loudness level
|
// Samples used to compute the loudness level (arbitrarily chosen)
|
||||||
static constexpr u16 SAMPLES_NEEDED = SAMPLING_RATE / 125;
|
static constexpr u16 SAMPLES_NEEDED = 128;
|
||||||
static_assert((SAMPLES_NEEDED % BUFF_SIZE_SAMPLES) == 0);
|
static_assert((SAMPLES_NEEDED % BUFF_SIZE_SAMPLES) == 0);
|
||||||
|
|
||||||
static constexpr FloatType MAX_AMPLITUDE =
|
static constexpr FloatType MAX_AMPLITUDE =
|
||||||
|
|
|
@ -250,8 +250,6 @@ void WiiSpeak::SetRegister(const std::unique_ptr<CtrlMessage>& cmd)
|
||||||
m_sampler.sample_on = !!arg1;
|
m_sampler.sample_on = !!arg1;
|
||||||
break;
|
break;
|
||||||
case SAMPLER_FREQ:
|
case SAMPLER_FREQ:
|
||||||
WARN_LOG_FMT(IOS_USB, "Wii Speak SAMPLER_FREQ set (arg1={:04x}, arg2={:04x}) not implemented",
|
|
||||||
arg1, arg2);
|
|
||||||
switch (arg1)
|
switch (arg1)
|
||||||
{
|
{
|
||||||
case FREQ_8KHZ:
|
case FREQ_8KHZ:
|
||||||
|
@ -271,6 +269,8 @@ void WiiSpeak::SetRegister(const std::unique_ptr<CtrlMessage>& cmd)
|
||||||
m_sampler.freq = 16000;
|
m_sampler.freq = 16000;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
if (m_microphone)
|
||||||
|
m_microphone->SetSamplingRate(m_sampler.freq);
|
||||||
break;
|
break;
|
||||||
case SAMPLER_GAIN:
|
case SAMPLER_GAIN:
|
||||||
WARN_LOG_FMT(IOS_USB, "Wii Speak SAMPLER_GAIN set (arg1={:04x}, arg2={:04x}) not implemented",
|
WARN_LOG_FMT(IOS_USB, "Wii Speak SAMPLER_GAIN set (arg1={:04x}, arg2={:04x}) not implemented",
|
||||||
|
|
|
@ -20,6 +20,8 @@ struct WiiSpeakState
|
||||||
int gain;
|
int gain;
|
||||||
bool ec_reset;
|
bool ec_reset;
|
||||||
bool sp_on;
|
bool sp_on;
|
||||||
|
|
||||||
|
static constexpr u32 DEFAULT_SAMPLING_RATE = 16000;
|
||||||
};
|
};
|
||||||
|
|
||||||
class WiiSpeak final : public Device
|
class WiiSpeak final : public Device
|
||||||
|
|
Loading…
Add table
Reference in a new issue