Skip to content

Commit

Permalink
Compile for Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
noahpistilli committed Feb 7, 2024
1 parent c308aa8 commit 99e60d2
Show file tree
Hide file tree
Showing 14 changed files with 35 additions and 213 deletions.
6 changes: 0 additions & 6 deletions Source/Core/Core/Config/MainSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -566,12 +566,6 @@ const Info<bool> MAIN_EMULATE_SKYLANDER_PORTAL{
const Info<bool> MAIN_EMULATE_INFINITY_BASE{
{System::Main, "EmulatedUSBDevices", "EmulateInfinityBase"}, false};

const Info<bool> MAIN_EMULATE_WII_SPEAK{{System::Main, "EmulatedUSBDevices", "EmulateWiiSpeak"},
false};

const Info<std::string> MAIN_WII_SPEAK_MICROPHONE{{System::Main, "General", "WiiSpeakMicrophone"},
""};

// The reason we need this function is because some memory card code
// expects to get a non-NTSC-K region even if we're emulating an NTSC-K Wii.
DiscIO::Region ToGameCubeRegion(DiscIO::Region region)
Expand Down
2 changes: 0 additions & 2 deletions Source/Core/Core/Config/MainSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -351,8 +351,6 @@ void SetUSBDeviceWhitelist(const std::set<std::pair<u16, u16>>& devices);

extern const Info<bool> MAIN_EMULATE_SKYLANDER_PORTAL;
extern const Info<bool> MAIN_EMULATE_INFINITY_BASE;
extern const Info<bool> MAIN_EMULATE_WII_SPEAK;
extern const Info<std::string> MAIN_WII_SPEAK_MICROPHONE;

// GameCube path utility functions

Expand Down
66 changes: 17 additions & 49 deletions Source/Core/Core/IOS/USB/Emulated/Microphone.cpp
Original file line number Diff line number Diff line change
@@ -1,25 +1,31 @@
//
// Created by Noah Pistilli on 2023-07-09.
//
// Copyright 2024 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later

#include <cubeb/cubeb.h>

#include "AudioCommon/CubebUtils.h"
#include <Common/Logging/Log.h>
#include "Common/Logging/Log.h"

#include "Microphone.h"
#include "Common/ScopeGuard.h"
#include "Common/Swap.h"
#include "Core/IOS/USB/Emulated/Microphone.h"

#include <algorithm>
#include <mutex>

#ifdef _WIN32
#include <Objbase.h>
#endif

namespace IOS::HLE::USB
{
Microphone::Microphone() {
Microphone::Microphone()
{
StreamInit();
}

Microphone::~Microphone() {
Microphone::~Microphone()
{
StreamTerminate();

#ifdef _WIN32
Expand Down Expand Up @@ -110,8 +116,8 @@ void Microphone::StreamStart()

if (cubeb_stream_init(m_cubeb_ctx.get(), &m_cubeb_stream,
"Dolphin Emulated GameCube Microphone", nullptr, &params, nullptr,
nullptr, std::max<u32>(16, minimum_latency), DataCallback,
state_callback, this) != CUBEB_OK)
nullptr, std::max<u32>(16, minimum_latency), DataCallback, state_callback,
this) != CUBEB_OK)
{
ERROR_LOG_FMT(IOS_USB, "Error initializing cubeb stream");
return;
Expand Down Expand Up @@ -151,7 +157,7 @@ void Microphone::StopStream()
}

long Microphone::DataCallback(cubeb_stream* stream, void* user_data, const void* input_buffer,
void* /*output_buffer*/, long nframes)
void* /*output_buffer*/, long nframes)
{
auto* mic = static_cast<Microphone*>(user_data);

Expand All @@ -173,44 +179,6 @@ long Microphone::DataCallback(cubeb_stream* stream, void* user_data, const void*
return nframes;
}

void Microphone::PerformAudioCapture()
{
/*m_num_of_samples = BUFFER_SIZE / 2;
ALCint samples_in{};
alcGetIntegerv(m_device, ALC_CAPTURE_SAMPLES, 1, &samples_in);
m_num_of_samples = std::min(m_num_of_samples, static_cast<u32>(samples_in));
if (m_num_of_samples == 0)
return;
alcCaptureSamples(m_device, m_dsp_data.data(), m_num_of_samples);*/
}

void Microphone::ByteSwap(const void* src, void* dst) const
{
*static_cast<u16*>(dst) = Common::swap16(*static_cast<const u16*>(src));
}

void Microphone::GetSoundData()
{
/*if (m_num_of_samples == 0)
return;
u8* ptr = const_cast<u8*>(m_temp_buffer.data());
// Convert LE to BE
for (u32 i = 0; i < m_num_of_samples; i++)
{
for (u32 indchan = 0; indchan < 1; indchan++)
{
const u32 curindex = (i * 2) + indchan * (16 / 8);
ByteSwap(m_dsp_data.data() + curindex, ptr + curindex);
}
}
m_rbuf_dsp.write_bytes(ptr, m_num_of_samples * 2);*/
}

void Microphone::ReadIntoBuffer(u8* dst, u32 size)
{
std::lock_guard lk(ring_lock);
Expand All @@ -231,4 +199,4 @@ bool Microphone::HasData() const
{
return samples_avail > 0;
}
} // namespace IOS::HLE::USB
} // namespace IOS::HLE::USB
13 changes: 6 additions & 7 deletions Source/Core/Core/IOS/USB/Emulated/Microphone.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
#pragma once
// Copyright 2024 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later

#include <OpenAL/al.h>
#include <OpenAL/alc.h>
#pragma once

#include <mutex>
#include <string>
#include <vector>
#include <mutex>

#include "Common/CommonTypes.h"
#include "Common/Event.h"
#include "Common/WorkQueueThread.h"

struct cubeb;
struct cubeb_stream;
Expand All @@ -22,8 +24,6 @@ class Microphone final

void StreamInit();
void StreamTerminate();
void PerformAudioCapture();
void GetSoundData();
void ReadIntoBuffer(u8* dst, u32 size);
bool HasData() const;

Expand All @@ -33,7 +33,6 @@ class Microphone final

void StreamStart();
void StopStream();
void ByteSwap(const void* src, void* dst) const;

static constexpr u32 SAMPLING_RATE = 8000;
static constexpr u32 BUFFER_SIZE = SAMPLING_RATE / 2;
Expand Down
16 changes: 4 additions & 12 deletions Source/Core/Core/IOS/USB/Emulated/WiiSpeak.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 Dolphin Emulator Project
// Copyright 2024 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later

#include "Core/IOS/USB/Emulated/WiiSpeak.h"
Expand Down Expand Up @@ -26,11 +26,6 @@ WiiSpeak::WiiSpeak(IOS::HLE::EmulationKernel& ios, const std::string& device_nam
m_microphone = std::make_unique<Microphone>();
}

WiiSpeak::~WiiSpeak()
{

}

DeviceDescriptor WiiSpeak::GetDeviceDescriptor() const
{
return m_device_descriptor;
Expand Down Expand Up @@ -106,9 +101,6 @@ int WiiSpeak::SubmitTransfer(std::unique_ptr<CtrlMessage> cmd)
m_vid, m_pid, m_active_interface, cmd->request_type, cmd->request, cmd->value,
cmd->index, cmd->length);

if (!b_is_mic_connected)
return IPC_ENOENT;

switch (cmd->request_type << 8 | cmd->request)
{
case USBHDR(DIR_DEVICE2HOST, TYPE_STANDARD, REC_INTERFACE, REQUEST_GET_INTERFACE):
Expand Down Expand Up @@ -176,8 +168,7 @@ int WiiSpeak::SubmitTransfer(std::unique_ptr<IsoMessage> cmd)
if (cmd->endpoint == 0x81 && m_microphone->HasData())
m_microphone->ReadIntoBuffer(packets, cmd->length);

// Anything more causes the visual cue to not appear.
// Anything less is more choppy audio.
// TODO: Figure out proper timings.
cmd->ScheduleTransferCompletion(IPC_SUCCESS, 2500);
return IPC_SUCCESS;
};
Expand All @@ -199,6 +190,7 @@ void WiiSpeak::SetRegister(std::unique_ptr<CtrlMessage>& cmd)
switch (arg1)
{
case FREQ_8KHZ:
// TODO: I have never seen it not be 8000 kHz
sampler.freq = 8000;
break;
case FREQ_11KHZ:
Expand Down Expand Up @@ -319,4 +311,4 @@ void WiiSpeak::GetRegister(std::unique_ptr<CtrlMessage>& cmd)
break;
}
}
} // namespace IOS::HLE::USB
} // namespace IOS::HLE::USB
10 changes: 4 additions & 6 deletions Source/Core/Core/IOS/USB/Emulated/WiiSpeak.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 Dolphin Emulator Project
// Copyright 2024 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later

#pragma once
Expand All @@ -19,7 +19,6 @@ class WiiSpeak final : public Device
{
public:
WiiSpeak(EmulationKernel& ios, const std::string& device_name);
~WiiSpeak();
DeviceDescriptor GetDeviceDescriptor() const override;
std::vector<ConfigDescriptor> GetConfigurations() const override;
std::vector<InterfaceDescriptor> GetInterfaces(u8 config) const override;
Expand Down Expand Up @@ -57,13 +56,13 @@ class WiiSpeak final : public Device
FREQ_8KHZ = 0,
FREQ_11KHZ = 1,
FREQ_RESERVED = 2,
FREQ_16KHZ = 3, // default
FREQ_16KHZ = 3,

SAMPLER_GAIN = 4,
GAIN_00dB = 0,
GAIN_15dB = 1,
GAIN_30dB = 2,
GAIN_36dB = 3, // default
GAIN_36dB = 3,

EC_STATE = 0x14,

Expand All @@ -83,7 +82,6 @@ class WiiSpeak final : public Device
u8 m_active_interface = 0;
bool m_device_attached = false;
bool init = false;
bool b_is_mic_connected = true;
std::unique_ptr<Microphone> m_microphone;
DeviceDescriptor m_device_descriptor{};
std::vector<ConfigDescriptor> m_config_descriptor;
Expand All @@ -92,4 +90,4 @@ class WiiSpeak final : public Device
std::mutex m_mutex;
Common::Event m_shutdown_event;
};
} // namespace IOS::HLE::USB
} // namespace IOS::HLE::USB
4 changes: 4 additions & 0 deletions Source/Core/DolphinLib.props
Original file line number Diff line number Diff line change
Expand Up @@ -395,9 +395,11 @@
<ClInclude Include="Core\IOS\USB\Bluetooth\WiimoteHIDAttr.h" />
<ClInclude Include="Core\IOS\USB\Common.h" />
<ClInclude Include="Core\IOS\USB\Emulated\Infinity.h" />
<ClInclude Include="Core\IOS\USB\Emulated\Microphone.h" />
<ClInclude Include="Core\IOS\USB\Emulated\Skylanders\Skylander.h" />
<ClInclude Include="Core\IOS\USB\Emulated\Skylanders\SkylanderCrypto.h" />
<ClInclude Include="Core\IOS\USB\Emulated\Skylanders\SkylanderFigure.h" />
<ClInclude Include="Core\IOS\USB\Emulated\WiiSpeak.h" />
<ClInclude Include="Core\IOS\USB\Host.h" />
<ClInclude Include="Core\IOS\USB\LibusbDevice.h" />
<ClInclude Include="Core\IOS\USB\OH0\OH0.h" />
Expand Down Expand Up @@ -1051,9 +1053,11 @@
<ClCompile Include="Core\IOS\USB\Bluetooth\WiimoteHIDAttr.cpp" />
<ClCompile Include="Core\IOS\USB\Common.cpp" />
<ClCompile Include="Core\IOS\USB\Emulated\Infinity.cpp" />
<ClCompile Include="Core\IOS\USB\Emulated\Microphone.cpp" />
<ClCompile Include="Core\IOS\USB\Emulated\Skylanders\Skylander.cpp" />
<ClCompile Include="Core\IOS\USB\Emulated\Skylanders\SkylanderCrypto.cpp" />
<ClCompile Include="Core\IOS\USB\Emulated\Skylanders\SkylanderFigure.cpp" />
<ClCompile Include="Core\IOS\USB\Emulated\WiiSpeak.cpp" />
<ClCompile Include="Core\IOS\USB\Host.cpp" />
<ClCompile Include="Core\IOS\USB\LibusbDevice.cpp" />
<ClCompile Include="Core\IOS\USB\OH0\OH0.cpp" />
Expand Down
2 changes: 0 additions & 2 deletions Source/Core/DolphinQt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,6 @@ add_executable(dolphin-emu
DiscordHandler.h
DiscordJoinRequestDialog.cpp
DiscordJoinRequestDialog.h
EmulatedUSB/WiiSpeakWindow.cpp
EmulatedUSB/WiiSpeakWindow.h
FIFO/FIFOAnalyzer.cpp
FIFO/FIFOAnalyzer.h
FIFO/FIFOPlayerWindow.cpp
Expand Down
77 changes: 0 additions & 77 deletions Source/Core/DolphinQt/EmulatedUSB/WiiSpeakWindow.cpp

This file was deleted.

0 comments on commit 99e60d2

Please sign in to comment.