From 02dc164611c74246e1e12657e6a75876ddc04264 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Wed, 28 Dec 2022 15:33:24 +1000 Subject: [PATCH] SPU2: Move files from host into main directory And get rid of the questionable WavFile. --- pcsx2/CMakeLists.txt | 43 +++--- pcsx2/SPU2/{Host => }/Config.cpp | 3 +- pcsx2/SPU2/Config.h | 43 +++++- pcsx2/SPU2/{Host => }/ConfigDebug.cpp | 3 +- pcsx2/SPU2/{Host => }/ConfigSoundTouch.cpp | 1 - pcsx2/SPU2/Host/Config.h | 102 ------------- pcsx2/SPU2/Host/Dialogs.h | 24 ---- pcsx2/SPU2/{Windows => }/SndOut_XAudio2.cpp | 0 pcsx2/SPU2/WavFile.cpp | 150 -------------------- pcsx2/SPU2/WavFile.h | 109 -------------- pcsx2/SPU2/Wavedump_wav.cpp | 97 +++++-------- pcsx2/SPU2/spu2.cpp | 9 +- pcsx2/pcsx2core.vcxproj | 17 ++- pcsx2/pcsx2core.vcxproj.filters | 51 ++++--- 14 files changed, 123 insertions(+), 529 deletions(-) rename pcsx2/SPU2/{Host => }/Config.cpp (98%) rename pcsx2/SPU2/{Host => }/ConfigDebug.cpp (98%) rename pcsx2/SPU2/{Host => }/ConfigSoundTouch.cpp (98%) delete mode 100644 pcsx2/SPU2/Host/Config.h delete mode 100644 pcsx2/SPU2/Host/Dialogs.h rename pcsx2/SPU2/{Windows => }/SndOut_XAudio2.cpp (100%) delete mode 100644 pcsx2/SPU2/WavFile.cpp delete mode 100644 pcsx2/SPU2/WavFile.h diff --git a/pcsx2/CMakeLists.txt b/pcsx2/CMakeLists.txt index c2b4f92164..cceb9716ef 100644 --- a/pcsx2/CMakeLists.txt +++ b/pcsx2/CMakeLists.txt @@ -277,6 +277,9 @@ set(pcsx2CDVDHeaders # SPU2 sources set(pcsx2SPU2Sources SPU2/ADSR.cpp + SPU2/Config.cpp + SPU2/ConfigDebug.cpp + SPU2/ConfigSoundTouch.cpp SPU2/Debug.cpp SPU2/DplIIdecoder.cpp SPU2/Dma.cpp @@ -291,13 +294,7 @@ set(pcsx2SPU2Sources SPU2/spu2sys.cpp SPU2/Timestretcher.cpp SPU2/Wavedump_wav.cpp - ) - -if(CUBEB_API) - list(APPEND pcsx2SPU2Sources SPU2/SndOut_Cubeb.cpp) - target_compile_definitions(PCSX2_FLAGS INTERFACE "SPU2X_CUBEB") - target_link_libraries(PCSX2_FLAGS INTERFACE cubeb) -endif() +) # SPU2 headers set(pcsx2SPU2Headers @@ -312,9 +309,20 @@ set(pcsx2SPU2Headers SPU2/regs.h SPU2/SndOut.h SPU2/spdif.h - SPU2/WavFile.h ) +if(CUBEB_API) + list(APPEND pcsx2SPU2Sources SPU2/SndOut_Cubeb.cpp) + target_compile_definitions(PCSX2_FLAGS INTERFACE "SPU2X_CUBEB") + target_link_libraries(PCSX2_FLAGS INTERFACE cubeb) +endif() + +if(WIN32) + list(APPEND pcsx2SPU2Sources + SPU2/SndOut_XAudio2.cpp + ) +endif() + # DEV9 sources set(pcsx2DEV9Sources DEV9/AdapterUtils.cpp @@ -636,26 +644,7 @@ set(pcsx2GSMetalShaders GS/Renderers/Metal/fxaa.metal ) -list(APPEND pcsx2SPU2Headers - SPU2/Host/Config.cpp - SPU2/Host/ConfigDebug.cpp - SPU2/Host/ConfigSoundTouch.cpp -) -list(APPEND pcsx2SPU2Headers - SPU2/Host/Config.h - SPU2/Host/Dialogs.h -) -if(NOT WIN32) - list(APPEND pcsx2SPU2Headers - SPU2/WavFile.cpp - ) -endif() - if(WIN32) - list(APPEND pcsx2SPU2Sources - SPU2/Windows/SndOut_XAudio2.cpp - ) - list(APPEND pcsx2DEV9Sources DEV9/Win32/pcap_io_win32.cpp DEV9/Win32/tap-win32.cpp diff --git a/pcsx2/SPU2/Host/Config.cpp b/pcsx2/SPU2/Config.cpp similarity index 98% rename from pcsx2/SPU2/Host/Config.cpp rename to pcsx2/SPU2/Config.cpp index 96b639b79d..9520c0c5b7 100644 --- a/pcsx2/SPU2/Host/Config.cpp +++ b/pcsx2/SPU2/Config.cpp @@ -20,8 +20,7 @@ #include #include "SPU2/Global.h" -#include "SPU2/Host/Config.h" -#include "SPU2/Host/Dialogs.h" +#include "SPU2/Config.h" #include "HostSettings.h" int AutoDMAPlayRate[2] = {0, 0}; diff --git a/pcsx2/SPU2/Config.h b/pcsx2/SPU2/Config.h index 7279a6e649..b5a35e9a69 100644 --- a/pcsx2/SPU2/Config.h +++ b/pcsx2/SPU2/Config.h @@ -17,9 +17,11 @@ #include "Global.h" #include -#ifdef _WIN32 -#include -#endif + +namespace soundtouch +{ + class SoundTouch; +} extern bool DebugEnabled; @@ -66,6 +68,7 @@ extern std::string MemDumpFileName; extern std::string RegDumpFileName; extern int Interpolation; + extern int numSpeakers; extern float FinalVolume; // Global / pre-scale extern bool AdvancedVolumeControl; @@ -80,15 +83,43 @@ extern float VolumeAdjustLFEdb; extern int dplLevel; +extern int AutoDMAPlayRate[2]; + extern u32 OutputModule; extern int SndOutLatencyMS; extern int SynchMode; +#ifdef PCSX2_DEVBUILD +const int LATENCY_MAX = 3000; +#else +const int LATENCY_MAX = 750; +#endif + +const int LATENCY_MIN = 3; +const int LATENCY_MIN_TIMESTRETCH = 15; + namespace SoundtouchCfg { - extern void ApplySettings(soundtouch::SoundTouch& sndtouch); -} + extern const int SequenceLen_Min; + extern const int SequenceLen_Max; -////// + extern const int SeekWindow_Min; + extern const int SeekWindow_Max; + + extern const int Overlap_Min; + extern const int Overlap_Max; + + extern int SequenceLenMS; + extern int SeekWindowMS; + extern int OverlapMS; + + extern void ReadSettings(); + extern void ApplySettings(soundtouch::SoundTouch& sndtouch); +}; // namespace SoundtouchCfg + +namespace DebugConfig +{ + extern void ReadSettings(); +} // namespace DebugConfig extern void ReadSettings(); diff --git a/pcsx2/SPU2/Host/ConfigDebug.cpp b/pcsx2/SPU2/ConfigDebug.cpp similarity index 98% rename from pcsx2/SPU2/Host/ConfigDebug.cpp rename to pcsx2/SPU2/ConfigDebug.cpp index 26f69fcdd2..3b0dad3335 100644 --- a/pcsx2/SPU2/Host/ConfigDebug.cpp +++ b/pcsx2/SPU2/ConfigDebug.cpp @@ -18,8 +18,7 @@ #include "pcsx2/Config.h" #include "SPU2/Global.h" -#include "SPU2/Host/Dialogs.h" -#include "SPU2/Host/Config.h" +#include "SPU2/Config.h" #include "common/FileSystem.h" #include "common/Path.h" #include "common/StringUtil.h" diff --git a/pcsx2/SPU2/Host/ConfigSoundTouch.cpp b/pcsx2/SPU2/ConfigSoundTouch.cpp similarity index 98% rename from pcsx2/SPU2/Host/ConfigSoundTouch.cpp rename to pcsx2/SPU2/ConfigSoundTouch.cpp index 5ad4d52ece..94e8c94af3 100644 --- a/pcsx2/SPU2/Host/ConfigSoundTouch.cpp +++ b/pcsx2/SPU2/ConfigSoundTouch.cpp @@ -16,7 +16,6 @@ #include "PrecompiledHeader.h" #include "SPU2/Global.h" -#include "SPU2/Host/Dialogs.h" #include "SPU2/Config.h" #include "SoundTouch.h" #include "HostSettings.h" diff --git a/pcsx2/SPU2/Host/Config.h b/pcsx2/SPU2/Host/Config.h deleted file mode 100644 index e63fd5d7ff..0000000000 --- a/pcsx2/SPU2/Host/Config.h +++ /dev/null @@ -1,102 +0,0 @@ -/* PCSX2 - PS2 Emulator for PCs - * Copyright (C) 2002-2020 PCSX2 Dev Team - * - * PCSX2 is free software: you can redistribute it and/or modify it under the terms - * of the GNU Lesser General Public License as published by the Free Software Found- - * ation, either version 3 of the License, or (at your option) any later version. - * - * PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with PCSX2. - * If not, see . - */ - -#pragma once - -#include - -extern bool DebugEnabled; - -extern bool _MsgToConsole; -extern bool _MsgKeyOnOff; -extern bool _MsgVoiceOff; -extern bool _MsgDMA; -extern bool _MsgAutoDMA; -extern bool _MsgOverruns; -extern bool _MsgCache; - -extern bool _AccessLog; -extern bool _DMALog; -extern bool _WaveLog; - -extern bool _CoresDump; -extern bool _MemDump; -extern bool _RegDump; -extern bool _visual_debug_enabled; - -/*static __forceinline bool MsgToConsole() { return _MsgToConsole & DebugEnabled; } - -static __forceinline bool MsgKeyOnOff() { return _MsgKeyOnOff & MsgToConsole(); } -static __forceinline bool MsgVoiceOff() { return _MsgVoiceOff & MsgToConsole(); } -static __forceinline bool MsgDMA() { return _MsgDMA & MsgToConsole(); } -static __forceinline bool MsgAutoDMA() { return _MsgAutoDMA & MsgDMA(); } -static __forceinline bool MsgOverruns() { return _MsgOverruns & MsgToConsole(); } -static __forceinline bool MsgCache() { return _MsgCache & MsgToConsole(); } - -static __forceinline bool AccessLog() { return _AccessLog & DebugEnabled; } -static __forceinline bool DMALog() { return _DMALog & DebugEnabled; } -static __forceinline bool WaveLog() { return _WaveLog & DebugEnabled; } - -static __forceinline bool CoresDump() { return _CoresDump & DebugEnabled; } -static __forceinline bool MemDump() { return _MemDump & DebugEnabled; } -static __forceinline bool RegDump() { return _RegDump & DebugEnabled; }*/ - - -//extern wchar_t AccessLogFileName[255]; -//extern wchar_t WaveLogFileName[255]; -//extern wchar_t DMA4LogFileName[255]; -//extern wchar_t DMA7LogFileName[255]; -//extern wchar_t CoresDumpFileName[255]; -//extern wchar_t MemDumpFileName[255]; -//extern wchar_t RegDumpFileName[255]; - -extern int Interpolation; -extern float FinalVolume; - -extern int AutoDMAPlayRate[2]; - -extern u32 OutputModule; -extern int SndOutLatencyMS; - -extern int SynchMode; - -#ifdef PCSX2_DEVBUILD -const int LATENCY_MAX = 3000; -#else -const int LATENCY_MAX = 750; -#endif - -const int LATENCY_MIN = 3; -const int LATENCY_MIN_TIMESTRETCH = 15; - -namespace SoundtouchCfg -{ - extern const int SequenceLen_Min; - extern const int SequenceLen_Max; - - extern const int SeekWindow_Min; - extern const int SeekWindow_Max; - - extern const int Overlap_Min; - extern const int Overlap_Max; - - extern int SequenceLenMS; - extern int SeekWindowMS; - extern int OverlapMS; - - void ReadSettings(); -}; // namespace SoundtouchCfg - -void ReadSettings(); diff --git a/pcsx2/SPU2/Host/Dialogs.h b/pcsx2/SPU2/Host/Dialogs.h deleted file mode 100644 index d819f80ecd..0000000000 --- a/pcsx2/SPU2/Host/Dialogs.h +++ /dev/null @@ -1,24 +0,0 @@ -/* PCSX2 - PS2 Emulator for PCs - * Copyright (C) 2002-2020 PCSX2 Dev Team - * - * PCSX2 is free software: you can redistribute it and/or modify it under the terms - * of the GNU Lesser General Public License as published by the Free Software Found- - * ation, either version 3 of the License, or (at your option) any later version. - * - * PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with PCSX2. - * If not, see . - */ - -#pragma once - -#include "SPU2/Global.h" -#include "SPU2/Config.h" - -namespace DebugConfig -{ - extern void ReadSettings(); -} // namespace DebugConfig diff --git a/pcsx2/SPU2/Windows/SndOut_XAudio2.cpp b/pcsx2/SPU2/SndOut_XAudio2.cpp similarity index 100% rename from pcsx2/SPU2/Windows/SndOut_XAudio2.cpp rename to pcsx2/SPU2/SndOut_XAudio2.cpp diff --git a/pcsx2/SPU2/WavFile.cpp b/pcsx2/SPU2/WavFile.cpp deleted file mode 100644 index 9cc186c8c2..0000000000 --- a/pcsx2/SPU2/WavFile.cpp +++ /dev/null @@ -1,150 +0,0 @@ -/* PCSX2 - PS2 Emulator for PCs - * Copyright (C) 2002-2020 PCSX2 Dev Team - * - * PCSX2 is free software: you can redistribute it and/or modify it under the terms - * of the GNU Lesser General Public License as published by the Free Software Found- - * ation, either version 3 of the License, or (at your option) any later version. - * - * PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with PCSX2. - * If not, see . - */ - -// Note the file is mostly a copy paste of the WavFile.h from SoundTouch library. It was -// shrunken to support only output 16 bits wav files - -#include "PrecompiledHeader.h" -#include -#include -#include -#include -#include -#include - -#include "WavFile.h" - -using namespace std; - -static const char riffStr[] = "RIFF"; -static const char waveStr[] = "WAVE"; -static const char fmtStr[] = "fmt "; -static const char dataStr[] = "data"; - -////////////////////////////////////////////////////////////////////////////// -// -// Class WavOutFile -// - -WavOutFile::WavOutFile(const char* fileName, int sampleRate, int bits, int channels) -{ - bytesWritten = 0; - fptr = fopen(fileName, "wb"); - if (fptr == nullptr) - { - string msg = "Error : Unable to open file \""; - msg += fileName; - msg += "\" for writing."; - //pmsg = msg.c_str; - throw runtime_error(msg); - } - - fillInHeader(sampleRate, bits, channels); - writeHeader(); -} - - -WavOutFile::~WavOutFile() -{ - if (fptr) - { - finishHeader(); - fclose(fptr); - } -} - - - -void WavOutFile::fillInHeader(uint sampleRate, uint bits, uint channels) -{ - // fill in the 'riff' part.. - - // copy string 'RIFF' to riff_char - memcpy(&(header.riff.riff_char), riffStr, 4); - // package_len unknown so far - header.riff.package_len = 0; - // copy string 'WAVE' to wave - memcpy(&(header.riff.wave), waveStr, 4); - - - // fill in the 'format' part.. - - // copy string 'fmt ' to fmt - memcpy(&(header.format.fmt), fmtStr, 4); - - header.format.format_len = 0x10; - header.format.fixed = 1; - header.format.channel_number = (short)channels; - header.format.sample_rate = (int)sampleRate; - header.format.bits_per_sample = (short)bits; - header.format.byte_per_sample = (short)(bits * channels / 8); - header.format.byte_rate = header.format.byte_per_sample * (int)sampleRate; - header.format.sample_rate = (int)sampleRate; - - // fill in the 'data' part.. - - // copy string 'data' to data_field - memcpy(&(header.data.data_field), dataStr, 4); - // data_len unknown so far - header.data.data_len = 0; -} - - -void WavOutFile::finishHeader() -{ - // supplement the file length into the header structure - header.riff.package_len = bytesWritten + 36; - header.data.data_len = bytesWritten; - - writeHeader(); -} - - - -void WavOutFile::writeHeader() -{ - int res; - - // write the supplemented header in the beginning of the file - fseek(fptr, 0, SEEK_SET); - res = fwrite(&header, sizeof(header), 1, fptr); - if (res != 1) - { - throw runtime_error("Error while writing to a wav file."); - } - - // jump back to the end of the file - fseek(fptr, 0, SEEK_END); -} - - -void WavOutFile::write(const short* buffer, int numElems) -{ - int res; - - // 16bit format & 16 bit samples - - assert(header.format.bits_per_sample == 16); - if (numElems < 1) - return; // nothing to do - - res = fwrite(buffer, 2, numElems, fptr); - - if (res != numElems) - { - throw runtime_error("Error while writing to a wav file."); - } - bytesWritten += 2 * numElems; -} diff --git a/pcsx2/SPU2/WavFile.h b/pcsx2/SPU2/WavFile.h deleted file mode 100644 index 65565b3fa8..0000000000 --- a/pcsx2/SPU2/WavFile.h +++ /dev/null @@ -1,109 +0,0 @@ -/* PCSX2 - PS2 Emulator for PCs - * Copyright (C) 2002-2020 PCSX2 Dev Team - * - * PCSX2 is free software: you can redistribute it and/or modify it under the terms - * of the GNU Lesser General Public License as published by the Free Software Found- - * ation, either version 3 of the License, or (at your option) any later version. - * - * PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with PCSX2. - * If not, see . - */ - -// Note the file is mostly a copy paste of the WavFile.h from SoundTouch library. It was -// shrunken to support only output 16 bits wav files - -#ifndef WAVFILE_H -#define WAVFILE_H - -#include - -#ifndef uint -typedef unsigned int uint; -#endif - - -/// WAV audio file 'riff' section header -typedef struct -{ - char riff_char[4]; - int package_len; - char wave[4]; -} WavRiff; - -/// WAV audio file 'format' section header -typedef struct -{ - char fmt[4]; - int format_len; - short fixed; - short channel_number; - int sample_rate; - int byte_rate; - short byte_per_sample; - short bits_per_sample; -} WavFormat; - -/// WAV audio file 'data' section header -typedef struct -{ - char data_field[4]; - uint data_len; -} WavData; - - -/// WAV audio file header -typedef struct -{ - WavRiff riff; - WavFormat format; - WavData data; -} WavHeader; - - -/// Class for writing WAV audio files. -class WavOutFile -{ -private: - /// Pointer to the WAV file - FILE* fptr; - - /// WAV file header data. - WavHeader header; - - /// Counter of how many bytes have been written to the file so far. - int bytesWritten; - - /// Fills in WAV file header information. - void fillInHeader(const uint sampleRate, const uint bits, const uint channels); - - /// Finishes the WAV file header by supplementing information of amount of - /// data written to file etc - void finishHeader(); - - /// Writes the WAV file header. - void writeHeader(); - -public: - /// Constructor: Creates a new WAV file. Throws a 'runtime_error' exception - /// if file creation fails. - WavOutFile(const char* fileName, ///< Filename - int sampleRate, ///< Sample rate (e.g. 44100 etc) - int bits, ///< Bits per sample (8 or 16 bits) - int channels ///< Number of channels (1=mono, 2=stereo) - ); - - /// Destructor: Finalizes & closes the WAV file. - ~WavOutFile(); - - /// Write data to WAV file. Throws a 'runtime_error' exception if writing to - /// file fails. - void write(const short* buffer, ///< Pointer to sample data buffer. - int numElems ///< How many array items are to be written to file. - ); -}; - -#endif diff --git a/pcsx2/SPU2/Wavedump_wav.cpp b/pcsx2/SPU2/Wavedump_wav.cpp index dadc7b2236..2d7e0fcac9 100644 --- a/pcsx2/SPU2/Wavedump_wav.cpp +++ b/pcsx2/SPU2/Wavedump_wav.cpp @@ -14,24 +14,21 @@ */ #include "PrecompiledHeader.h" -#include "Global.h" -#ifdef __POSIX__ -#include "WavFile.h" -#else -#include "soundtouch/source/SoundStretch/WavFile.h" + +#include "SPU2/Global.h" +#include "pcsx2/Config.h" +#include "fmt/format.h" + +#include "common/Path.h" #include "common/StringUtil.h" -#endif +#include "common/WAVWriter.h" +#include #include -static WavOutFile* _new_WavOutFile(const char* destfile) -{ - return new WavOutFile(destfile, SampleRate, 16, 2); -} - namespace WaveDump { - static WavOutFile* m_CoreWav[2][CoreSrc_Count]; + static std::unique_ptr m_CoreWav[2][CoreSrc_Count]; static const char* m_tbl_CoreOutputTypeNames[CoreSrc_Count] = { @@ -49,29 +46,18 @@ namespace WaveDump if (!WaveLog()) return; - char wavfilename[256]; - for (uint cidx = 0; cidx < 2; cidx++) { for (int srcidx = 0; srcidx < CoreSrc_Count; srcidx++) { - safe_delete(m_CoreWav[cidx][srcidx]); -#ifdef __POSIX__ - sprintf(wavfilename, "logs/spu2x-Core%ud-%s.wav", - cidx, m_tbl_CoreOutputTypeNames[srcidx]); -#else - sprintf(wavfilename, "logs\\spu2x-Core%ud-%s.wav", - cidx, m_tbl_CoreOutputTypeNames[srcidx]); -#endif - - try + m_CoreWav[cidx][srcidx].reset(); + + std::string wavfilename(Path::Combine(EmuFolders::Logs, fmt::format("spu2x-Core{}d-{}.wav", cidx, m_tbl_CoreOutputTypeNames[srcidx]))); + m_CoreWav[cidx][srcidx] = std::make_unique(); + if (!m_CoreWav[cidx][srcidx]->Open(wavfilename.c_str(), SampleRate, 2)) { - m_CoreWav[cidx][srcidx] = _new_WavOutFile(wavfilename); - } - catch (std::runtime_error& ex) - { - printf("SPU2 > %s.\n\tWave Log for this core source disabled.", ex.what()); - m_CoreWav[cidx][srcidx] = nullptr; + Console.Error(fmt::format("Failed to open '{}'. Wave Log for this core source disabled.", wavfilename)); + m_CoreWav[cidx][srcidx].reset(); } } } @@ -84,9 +70,7 @@ namespace WaveDump for (uint cidx = 0; cidx < 2; cidx++) { for (int srcidx = 0; srcidx < CoreSrc_Count; srcidx++) - { - safe_delete(m_CoreWav[cidx][srcidx]); - } + m_CoreWav[cidx][srcidx].reset(); } } @@ -95,7 +79,7 @@ namespace WaveDump if (!IsDevBuild) return; if (m_CoreWav[coreidx][src] != nullptr) - m_CoreWav[coreidx][src]->write((s16*)&sample, 2); + m_CoreWav[coreidx][src]->WriteFrames(reinterpret_cast(&sample), 1); } void WriteCore(uint coreidx, CoreSourceType src, s16 left, s16 right) @@ -104,54 +88,39 @@ namespace WaveDump } } // namespace WaveDump -#include "common/Threading.h" - -using namespace Threading; - bool WavRecordEnabled = false; -static WavOutFile* m_wavrecord = nullptr; +static std::unique_ptr m_wavrecord; static std::mutex WavRecordMutex; bool RecordStart(const std::string* filename) { - try + std::unique_lock lock(WavRecordMutex); + m_wavrecord.reset(); + m_wavrecord = std::make_unique(); + if (!m_wavrecord->Open(m_wavrecord ? filename->c_str() : "audio_recording.wav", SampleRate, 2)) { - std::unique_lock lock(WavRecordMutex); - safe_delete(m_wavrecord); - if (filename) -#ifdef _WIN32 - m_wavrecord = new WavOutFile(_wfopen(StringUtil::UTF8StringToWideString(*filename).c_str(), L"wb"), SampleRate, 16, 2); -#else - m_wavrecord = new WavOutFile(filename->c_str(), SampleRate, 16, 2); -#endif - else - m_wavrecord = new WavOutFile("audio_recording.wav", SampleRate, 16, 2); - WavRecordEnabled = true; - return true; - } - catch (std::runtime_error&) - { - m_wavrecord = nullptr; // not needed, but what the heck. :) - if (filename) - Console.Error("SPU2 couldn't open file for recording: %s.\nWavfile capture disabled.", filename->c_str()); - else - Console.Error("SPU2 couldn't open file for recording: audio_recording.wav.\nWavfile capture disabled."); + Console.Error("SPU2 couldn't open file for recording: %s.\nWavfile capture disabled.", filename ? filename->c_str() : "audio_recording.wav"); + m_wavrecord.reset(); + WavRecordEnabled = false; return false; } + + WavRecordEnabled = true; + return true; } void RecordStop() { - WavRecordEnabled = false; std::unique_lock lock(WavRecordMutex); - safe_delete(m_wavrecord); + WavRecordEnabled = false; + m_wavrecord.reset(); } void RecordWrite(const StereoOut16& sample) { std::unique_lock lock(WavRecordMutex); - if (m_wavrecord == nullptr) + if (!m_wavrecord) return; - m_wavrecord->write((s16*)&sample, 2); + m_wavrecord->WriteFrames(reinterpret_cast(&sample), 2); } diff --git a/pcsx2/SPU2/spu2.cpp b/pcsx2/SPU2/spu2.cpp index 0aac1987db..5cdc0ec8ea 100644 --- a/pcsx2/SPU2/spu2.cpp +++ b/pcsx2/SPU2/spu2.cpp @@ -14,14 +14,11 @@ */ #include "PrecompiledHeader.h" -#include "Global.h" -#include "spu2.h" -#include "Dma.h" -#include "Host/Dialogs.h" +#include "SPU2/Global.h" +#include "SPU2/spu2.h" +#include "SPU2/Dma.h" #include "R3000A.h" -using namespace Threading; - static int ConsoleSampleRate = 48000; int SampleRate = 48000; diff --git a/pcsx2/pcsx2core.vcxproj b/pcsx2/pcsx2core.vcxproj index e824a57963..71669e86ff 100644 --- a/pcsx2/pcsx2core.vcxproj +++ b/pcsx2/pcsx2core.vcxproj @@ -243,17 +243,18 @@ + + + + + - - - - + - @@ -330,7 +331,6 @@ - @@ -600,14 +600,13 @@ + + - - - diff --git a/pcsx2/pcsx2core.vcxproj.filters b/pcsx2/pcsx2core.vcxproj.filters index 252d1fa698..b419dd8130 100644 --- a/pcsx2/pcsx2core.vcxproj.filters +++ b/pcsx2/pcsx2core.vcxproj.filters @@ -833,9 +833,6 @@ System\Ps2\Iop\FW - - System\Ps2\SPU2 - System\Ps2\SPU2 @@ -851,9 +848,6 @@ System\Ps2\SPU2 - - System\Ps2\SPU2 - System\Ps2\SPU2 @@ -1232,15 +1226,6 @@ Host - - System\Ps2\SPU2 - - - System\Ps2\SPU2 - - - System\Ps2\SPU2 - Host @@ -1256,9 +1241,6 @@ System\Ps2\PAD - - System\Ps2\SPU2 - Host @@ -1416,6 +1398,24 @@ System\Ps2\USB\usb-pad + + System\Ps2\SPU2 + + + System\Ps2\SPU2 + + + System\Ps2\SPU2 + + + System\Ps2\SPU2 + + + System\Ps2\SPU2 + + + System\Ps2\SPU2 + @@ -1787,9 +1787,6 @@ System\Ps2\SPU2 - - System\Ps2\SPU2 - System\Ps2\SPU2 @@ -2172,12 +2169,6 @@ Host - - System\Ps2\SPU2 - - - System\Ps2\SPU2 - Host @@ -2363,6 +2354,12 @@ System\Ps2\USB\usb-pad + + System\Ps2\SPU2 + + + System\Ps2\SPU2 +