2009-02-15 05:15:39 +00:00
|
|
|
//GiGaHeRz's SPU2 Driver
|
|
|
|
//Copyright (c) 2003-2008, David Quintana <gigaherz@gmail.com>
|
|
|
|
//
|
|
|
|
//This library 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 Foundation; either
|
|
|
|
//version 2.1 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
//This library 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
|
|
|
|
//Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
//You should have received a copy of the GNU Lesser General Public
|
|
|
|
//License along with this library; if not, write to the Free Software
|
|
|
|
//Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
//
|
|
|
|
|
|
|
|
#include <stdexcept>
|
|
|
|
#include <new>
|
|
|
|
|
2009-02-20 21:48:59 +00:00
|
|
|
#include "Spu2.h"
|
2009-02-15 05:15:39 +00:00
|
|
|
|
|
|
|
#include "SoundTouch/WavFile.h"
|
|
|
|
|
|
|
|
static WavOutFile* _new_WavOutFile( const char* destfile )
|
|
|
|
{
|
|
|
|
return new WavOutFile( destfile, 48000, 16, 2 );
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace WaveDump
|
|
|
|
{
|
|
|
|
static WavOutFile* m_CoreWav[2][CoreSrc_Count] = { NULL };
|
|
|
|
|
|
|
|
static const char* m_tbl_CoreOutputTypeNames[CoreSrc_Count] =
|
|
|
|
{
|
|
|
|
"Input",
|
|
|
|
"DryVoiceMix",
|
|
|
|
"WetVoiceMix",
|
|
|
|
"PreReverb",
|
|
|
|
"PostReverb",
|
|
|
|
"External"
|
|
|
|
};
|
|
|
|
|
|
|
|
void Open()
|
|
|
|
{
|
2009-02-16 20:00:31 +00:00
|
|
|
if( !IsDevBuild ) return;
|
2009-02-15 05:15:39 +00:00
|
|
|
if( !WaveLog() ) return;
|
|
|
|
|
|
|
|
char wavfilename[256];
|
|
|
|
|
|
|
|
for( uint cidx=0; cidx<2; cidx++ )
|
|
|
|
{
|
|
|
|
for( int srcidx=0; srcidx<CoreSrc_Count; srcidx++ )
|
|
|
|
{
|
|
|
|
SAFE_DELETE_OBJ( m_CoreWav[cidx][srcidx] );
|
|
|
|
|
|
|
|
sprintf( wavfilename, "logs\\spu2x-Core%d-%s.wav",
|
|
|
|
cidx, m_tbl_CoreOutputTypeNames[ srcidx ] );
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
m_CoreWav[cidx][srcidx] = _new_WavOutFile( wavfilename );
|
|
|
|
}
|
|
|
|
catch( std::runtime_error& ex )
|
|
|
|
{
|
|
|
|
printf( "SPU2-X > %s.\n\tWave Log for this core source disabled.", ex.what() );
|
|
|
|
m_CoreWav[cidx][srcidx] = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Close()
|
|
|
|
{
|
2009-02-16 20:00:31 +00:00
|
|
|
if( !IsDevBuild ) return;
|
2009-02-15 05:15:39 +00:00
|
|
|
for( uint cidx=0; cidx<2; cidx++ )
|
|
|
|
{
|
|
|
|
for( int srcidx=0; srcidx<CoreSrc_Count; srcidx++ )
|
|
|
|
{
|
|
|
|
SAFE_DELETE_OBJ( m_CoreWav[cidx][srcidx] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-18 13:36:20 +00:00
|
|
|
void WriteCore( uint coreidx, CoreSourceType src, const StereoOut16& sample )
|
2009-02-15 05:15:39 +00:00
|
|
|
{
|
2009-02-16 20:00:31 +00:00
|
|
|
if( !IsDevBuild ) return;
|
2009-02-15 05:15:39 +00:00
|
|
|
if( m_CoreWav[coreidx][src] != NULL )
|
2009-02-18 13:36:20 +00:00
|
|
|
m_CoreWav[coreidx][src]->write( (s16*)&sample, 2 );
|
|
|
|
}
|
|
|
|
|
|
|
|
void WriteCore( uint coreidx, CoreSourceType src, s16 left, s16 right )
|
|
|
|
{
|
|
|
|
WriteCore( coreidx, src, StereoOut16( left, right ) );
|
2009-02-15 05:15:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
WavOutFile* m_wavrecord = NULL;
|
|
|
|
|
|
|
|
void RecordStart()
|
|
|
|
{
|
|
|
|
SAFE_DELETE_OBJ( m_wavrecord );
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
m_wavrecord = new WavOutFile( "recording.wav", 48000, 16, 2 );
|
|
|
|
}
|
|
|
|
catch( std::runtime_error& )
|
|
|
|
{
|
|
|
|
SysMessage("SPU2-X couldn't open file for recording: %s.\nRecording to wavfile disabled.", "recording.wav");
|
|
|
|
m_wavrecord = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void RecordStop()
|
|
|
|
{
|
|
|
|
SAFE_DELETE_OBJ( m_wavrecord );
|
|
|
|
}
|
|
|
|
|
2009-02-18 13:36:20 +00:00
|
|
|
void RecordWrite( const StereoOut16& sample )
|
2009-02-15 05:15:39 +00:00
|
|
|
{
|
|
|
|
if( m_wavrecord == NULL ) return;
|
2009-02-18 13:36:20 +00:00
|
|
|
m_wavrecord->write( (s16*)&sample, 2 );
|
2009-02-15 05:15:39 +00:00
|
|
|
}
|