From 25b7bf6a9750f92bd75850740002d32dcf08470e Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Thu, 25 Oct 2018 03:38:09 +0200 Subject: tracker/wii: fix for mingw-w64 The module loses auto-pairing functionality, but it's at least useful to see GCC warnings. I don't intend to use GCC for actually running the module. Fix some warnings emitted by GCC, such as - memset(3) of non-POD struct - depending on "new T[0]" to return a null pointer - dependence on MSVC-specific pragmas for external libraries - lack of header guards - unintended usage of trigraph syntax Disable some GCC warnings for the "wiiyourself" library. It's not possible to patch it up, the code quality is that awful. Disable the builtin debug functionality since it depends on non-standard __VA_OPT__ (due in C++20). It's not possible to disable the warning emitted on the __VA_ARGS__ usage in GCC. --- tracker-wii/wiiyourself/wiimote.cpp | 45 ++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 23 deletions(-) (limited to 'tracker-wii/wiiyourself/wiimote.cpp') diff --git a/tracker-wii/wiiyourself/wiimote.cpp b/tracker-wii/wiiyourself/wiimote.cpp index f53e1acf..0da0113b 100644 --- a/tracker-wii/wiiyourself/wiimote.cpp +++ b/tracker-wii/wiiyourself/wiimote.cpp @@ -8,15 +8,17 @@ // // wiimote.cpp (tab = 4 spaces) +#include "warns-begin.hpp" + // VC-specifics: #ifdef _MSC_VER // disable warning "C++ exception handler used, but unwind semantics are not enabled." // in (I don't use it - or just enable C++ exceptions) # pragma warning(disable: 4530) // auto-link with the necessary libs -# pragma comment(lib, "setupapi.lib") -# pragma comment(lib, "hid.lib") // for HID API (from DDK) -# pragma comment(lib, "winmm.lib") // for timeGetTime() +//# pragma comment(lib, "setupapi.lib") +//# pragma comment(lib, "hid.lib") // for HID API (from DDK) +//# pragma comment(lib, "winmm.lib") // for timeGetTime() #endif // _MSC_VER #include "wiimote.h" @@ -24,14 +26,13 @@ extern "C" { #include // from WinDDK } + #include // for _stat #include // " +#include +#include #include // for _beginthreadex() -#ifdef __BORLANDC__ -# include // for orientation -#else -# include // " -#endif +#include // for orientation #include // for WAVEFORMATEXTENSIBLE #include // for timeGetTime() @@ -49,17 +50,12 @@ template inline T square(const T& val) { return val * val; } // ------------------------------------------------------------------------------------ // Tracing & Debugging // ------------------------------------------------------------------------------------ -#define PREFIX _T("WiiYourself! : ") +#define PREFIX "WiiYourself: " // comment these to auto-strip their code from the library: // (they currently use OutputDebugString() via _TRACE() - change to suit) -#if (_MSC_VER >= 1400) // VC 2005+ (earlier versions don't support variable args) -# define TRACE(fmt, ...) _TRACE(PREFIX fmt _T("\n"), __VA_ARGS__) -# define WARN(fmt, ...) _TRACE(PREFIX _T("* ") fmt _T(" *") _T("\n"), __VA_ARGS__) -#elif defined(__MINGW32__) -# define TRACE(fmt, ...) _TRACE(PREFIX fmt _T("\n") , ##__VA_ARGS__) -# define WARN(fmt, ...) _TRACE(PREFIX _T("* ") fmt _T(" *") _T("\n") , ##__VA_ARGS__) -#endif +# define TRACE _TRACE +# define WARN _TRACE // uncomment any of these for deeper debugging: //#define DEEP_TRACE(fmt, ...) _TRACE(PREFIX _T("|") fmt _T("\n"), __VA_ARGS__) // VC 2005+ //#define DEEP_TRACE(fmt, ...) _TRACE(PREFIX _T("|") fmt _T("\n") , ##__VA_ARGS__) // mingw @@ -745,7 +741,7 @@ void wiimote::SetReportType(input_report type, bool continuous) TYPE2NAME(IN_BUTTONS_ACCEL_EXT) : TYPE2NAME(IN_BUTTONS_ACCEL_IR_EXT) : TYPE2NAME(IN_BUTTONS_BALANCE_BOARD) : - _T("(unknown??)"); + _T("(unknown?)"); TRACE(_T("ReportType: %s (%s)"), name, (continuous ? _T("continuous") : _T("non-continuous"))); #endif @@ -2372,10 +2368,10 @@ unsigned __stdcall wiimote::SampleStreamThreadfunc(void* param) // ------------------------------------------------------------------------------------ bool wiimote::Load16bitMonoSampleWAV(const TCHAR* filepath, wiimote_sample &out) { + out = {}; // converts unsigned 16bit mono .wav audio data to the 4bit ADPCM variant // used by the Wiimote (at least the closest match so far), and returns // the data in a BYTE array (caller must delete[] it when no longer needed): - memset(&out, 0, sizeof(out)); TRACE(_T("Loading '%s'"), filepath); @@ -2543,10 +2539,10 @@ bool wiimote::Load16BitMonoSampleRAW(const TCHAR* filepath, speaker_freq freq, wiimote_sample &out) { + out = {}; // converts (.wav style) unsigned 16bit mono raw data to the 4bit ADPCM variant // used by the Wiimote, and returns the data in a BYTE array (caller must // delete[] it when no longer needed): - memset(&out, 0, sizeof(out)); // get the length of the file struct _stat file_info; @@ -2564,12 +2560,11 @@ bool wiimote::Load16BitMonoSampleRAW(const TCHAR* filepath, unsigned total_samples = (len + 1) / 2; // round up just in case file is corrupt // allocate a buffer to hold the samples to convert - short *samples = new short[total_samples]; - _ASSERT(samples); - if (!samples) { + if (!total_samples) { TRACE(_T("Couldn't open '%s"), filepath); return false; } + short *samples = new short[total_samples]; // load them FILE *file; @@ -2608,10 +2603,11 @@ bool wiimote::Convert16bitMonoSamples(const short* samples, speaker_freq freq, wiimote_sample &out) { + out = {}; + // converts 16bit mono sample data to the native 4bit format used by the Wiimote, // and returns the data in a BYTE array (caller must delete[] when no // longer needed): - memset(&out, 0, sizeof(0)); _ASSERT(samples && length); if (!samples || !length) @@ -2815,3 +2811,6 @@ void wiimote::StopRecording() } // ------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------ + +#include "warns-end.hpp" + -- cgit v1.2.3