SPU2-X: Improved fix for wave recoding crashes; using thread-safe mutex locks. :)

git-svn-id: http://pcsx2.googlecode.com/svn/trunk@2662 96395faa-99c1-11dd-bbfe-3dabce05a288
This commit is contained in:
Jake.Stine 2010-03-03 19:06:22 +00:00
parent a93b0fe4a4
commit 1461281f5f
3 changed files with 20 additions and 7 deletions

View File

@ -310,7 +310,7 @@ void SndBuffer::Write( const StereoOut32& Sample )
// Log final output to wavefile.
WaveDump::WriteCore( 1, CoreSrc_External, Sample.DownSample() );
RecordWrite( Sample.DownSample() );
if( WavRecordEnabled ) RecordWrite( Sample.DownSample() );
if(mods[OutputModule] == &NullOut) // null output doesn't need buffering or stretching! :p
return;

View File

@ -492,6 +492,8 @@ extern SndOutModule* mods[];
// =====================================================================================================
extern bool WavRecordEnabled;
extern void RecordStart();
extern void RecordStop();
extern void RecordWrite( const StereoOut16& sample );

View File

@ -91,32 +91,43 @@ namespace WaveDump
}
}
WavOutFile* m_wavrecord = NULL;
#include "Utilities/Threading.h"
using namespace Threading;
bool WavRecordEnabled = false;
static WavOutFile* m_wavrecord = NULL;
static Mutex WavRecordMutex;
void RecordStart()
{
safe_delete( m_wavrecord );
WavRecordEnabled = false;
try
{
ScopedLock lock( WavRecordMutex );
safe_delete( m_wavrecord );
m_wavrecord = new WavOutFile( "recording.wav", 48000, 16, 2 );
WavRecordEnabled = true;
}
catch( std::runtime_error& )
{
m_wavrecord = NULL; // not needed, but what the heck. :)
SysMessage("SPU2-X couldn't open file for recording: %s.\nRecording to wavfile disabled.", "recording.wav");
m_wavrecord = NULL;
}
}
void RecordStop()
{
WavOutFile* t = m_wavrecord;
m_wavrecord = NULL;
delete t;
WavRecordEnabled = false;
ScopedLock lock( WavRecordMutex );
safe_delete( m_wavrecord );
}
void RecordWrite( const StereoOut16& sample )
{
ScopedLock lock( WavRecordMutex );
if( m_wavrecord == NULL ) return;
m_wavrecord->write( (s16*)&sample, 2 );
}