spu2-x: Misc Alsa stuff. Added a few missing files into the pcsx2 codeblocks project.

git-svn-id: http://pcsx2.googlecode.com/svn/trunk@3917 96395faa-99c1-11dd-bbfe-3dabce05a288
This commit is contained in:
arcum42 2010-10-13 09:15:54 +00:00
parent fc99f79aac
commit 33214df091
4 changed files with 51 additions and 35 deletions

View File

@ -252,6 +252,7 @@
<Unit filename="../CDVD/IsoFileTools.cpp" /> <Unit filename="../CDVD/IsoFileTools.cpp" />
<Unit filename="../CDVD/IsoFileTools.h" /> <Unit filename="../CDVD/IsoFileTools.h" />
<Unit filename="../COP0.cpp" /> <Unit filename="../COP0.cpp" />
<Unit filename="../COP0.h" />
<Unit filename="../COP2.cpp" /> <Unit filename="../COP2.cpp" />
<Unit filename="../Cache.cpp" /> <Unit filename="../Cache.cpp" />
<Unit filename="../Cache.h" /> <Unit filename="../Cache.h" />
@ -317,6 +318,7 @@
<Unit filename="../IopMem.h" /> <Unit filename="../IopMem.h" />
<Unit filename="../IopSio2.cpp" /> <Unit filename="../IopSio2.cpp" />
<Unit filename="../IopSio2.h" /> <Unit filename="../IopSio2.h" />
<Unit filename="../Ipu_fifo.h" />
<Unit filename="LnxHostSys.cpp" /> <Unit filename="LnxHostSys.cpp" />
<Unit filename="LnxKeyCodes.cpp"> <Unit filename="LnxKeyCodes.cpp">
<Option compiler="gcc" use="1" buildCommand="$compiler $options $includes `pkg-config gtk+-2.0 --cflags` -c $file -o $object" /> <Option compiler="gcc" use="1" buildCommand="$compiler $options $includes `pkg-config gtk+-2.0 --cflags` -c $file -o $object" />
@ -325,6 +327,7 @@
<Unit filename="../MTGS.cpp" /> <Unit filename="../MTGS.cpp" />
<Unit filename="../Memory.cpp" /> <Unit filename="../Memory.cpp" />
<Unit filename="../Memory.h" /> <Unit filename="../Memory.h" />
<Unit filename="../MemoryTypes.h" />
<Unit filename="../NakedAsm.h" /> <Unit filename="../NakedAsm.h" />
<Unit filename="../Patch.cpp" /> <Unit filename="../Patch.cpp" />
<Unit filename="../Patch.h" /> <Unit filename="../Patch.h" />
@ -334,6 +337,7 @@
<Unit filename="../Pcsx2Config.cpp" /> <Unit filename="../Pcsx2Config.cpp" />
<Unit filename="../PluginManager.cpp" /> <Unit filename="../PluginManager.cpp" />
<Unit filename="../Plugins.h" /> <Unit filename="../Plugins.h" />
<Unit filename="../PrecompiledHeader.cpp" />
<Unit filename="../PrecompiledHeader.h" /> <Unit filename="../PrecompiledHeader.h" />
<Unit filename="../R3000A.cpp" /> <Unit filename="../R3000A.cpp" />
<Unit filename="../R3000A.h" /> <Unit filename="../R3000A.h" />
@ -362,6 +366,7 @@
<Unit filename="../Stats.cpp" /> <Unit filename="../Stats.cpp" />
<Unit filename="../Stats.h" /> <Unit filename="../Stats.h" />
<Unit filename="../StringUtils.h" /> <Unit filename="../StringUtils.h" />
<Unit filename="../SysForwardDefs.h" />
<Unit filename="../System.cpp" /> <Unit filename="../System.cpp" />
<Unit filename="../System.h" /> <Unit filename="../System.h" />
<Unit filename="../System/PageFaultSource.h" /> <Unit filename="../System/PageFaultSource.h" />
@ -582,6 +587,8 @@
<Unit filename="../ps2/Iop/IopHwWrite.cpp" /> <Unit filename="../ps2/Iop/IopHwWrite.cpp" />
<Unit filename="../ps2/Iop/IopHw_Internal.h" /> <Unit filename="../ps2/Iop/IopHw_Internal.h" />
<Unit filename="../ps2/LegacyDmac.cpp" /> <Unit filename="../ps2/LegacyDmac.cpp" />
<Unit filename="../ps2/eeHwTraceLog.inl" />
<Unit filename="../sio_internal.h" />
<Unit filename="../vtlb.cpp" /> <Unit filename="../vtlb.cpp" />
<Unit filename="../vtlb.h" /> <Unit filename="../vtlb.h" />
<Unit filename="../x86/BaseblockEx.cpp" /> <Unit filename="../x86/BaseblockEx.cpp" />

View File

@ -18,7 +18,7 @@
/* This code was based on the FPSE v0.08 Mdec decoder*/ /* This code was based on the FPSE v0.08 Mdec decoder*/
#ifdef 0 #if 0
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>

View File

@ -19,11 +19,11 @@
#include <alsa/asoundlib.h> #include <alsa/asoundlib.h>
#define ALSA_MEM_DEF
#include "Global.h" #include "Global.h"
#include "Alsa.h" #include "Alsa.h"
#include "SndOut.h" #include "SndOut.h"
// Does not work, except as effectively a null plugin.
class AlsaMod: public SndOutModule class AlsaMod: public SndOutModule
{ {
protected: protected:
@ -44,7 +44,7 @@ protected:
void _InternalCallback() void _InternalCallback()
{ {
snd_pcm_sframes_t avail; snd_pcm_sframes_t avail;
//int err; fprintf(stderr,"* SPU2-X:Iz in your internal callback.\n");
avail = snd_pcm_avail_update( handle ); avail = snd_pcm_avail_update( handle );
while (avail >= period_time ) while (avail >= period_time )
@ -62,15 +62,20 @@ protected:
// Preps and invokes the _InternalCallback above. This provides a cdecl-compliant // Preps and invokes the _InternalCallback above. This provides a cdecl-compliant
// entry point for our C++ified object state. :) // entry point for our C++ified object state. :)
static void ExternalCallback( snd_async_handler_t *pcm_callback ) static void ExternalCallback( snd_async_handler_t *pcm_call)
{ {
AlsaMod *data = (AlsaMod*)snd_async_handler_get_callback_private( pcm_callback ); fprintf(stderr,"* SPU2-X:Iz in your external callback.\n");
AlsaMod *data = (AlsaMod*)snd_async_handler_get_callback_private( pcm_call );
jASSUME( data != NULL ); jASSUME( data != NULL );
jASSUME( data->handle == snd_async_handler_get_pcm(pcm_callback) ); //jASSUME( data->handle == snd_async_handler_get_pcm(pcm_call) );
// Not sure if we just need an assert, or something like this: // Not sure if we just need an assert, or something like this:
//if( data->handle != snd_async_handler_get_pcm(pcm_callback) ) return; if (data->handle != snd_async_handler_get_pcm(pcm_call))
{
fprintf(stderr,"* SPU2-X: Failed to handle sound.\n");
return;
}
data->_InternalCallback(); data->_InternalCallback();
} }
@ -79,6 +84,7 @@ public:
s32 Init() s32 Init()
{ {
//fprintf(stderr,"* SPU2-X: Initing Alsa\n");
snd_pcm_hw_params_t *hwparams; snd_pcm_hw_params_t *hwparams;
snd_pcm_sw_params_t *swparams; snd_pcm_sw_params_t *swparams;
snd_pcm_status_t *status; snd_pcm_status_t *status;
@ -96,17 +102,17 @@ public:
int err; int err;
err = snd_pcm_open(&handle, "default", SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK); err = snd_pcm_open(&handle, "default", SND_PCM_STREAM_PLAYBACK, SND_PCM_ASYNC /*| SND_PCM_NONBLOCK*/);
if(err < 0) if(err < 0)
{ {
ERROR_LOG("Audio open error: %s\n", snd_strerror(err)); fprintf(stderr,"Audio open error: %s\n", snd_strerror(err));
return -1; return -1;
} }
err = snd_pcm_nonblock(handle, 0); err = snd_pcm_nonblock(handle, 0);
if(err < 0) if(err < 0)
{ {
ERROR_LOG("Can't set blocking mode: %s\n", snd_strerror(err)); fprintf(stderr,"Can't set blocking mode: %s\n", snd_strerror(err));
return -1; return -1;
} }
@ -116,54 +122,54 @@ public:
err = snd_pcm_hw_params_any(handle, hwparams); err = snd_pcm_hw_params_any(handle, hwparams);
if (err < 0) if (err < 0)
{ {
ERROR_LOG("Broken configuration for this PCM: %s\n", snd_strerror(err)); fprintf(stderr,"Broken configuration for this PCM: %s\n", snd_strerror(err));
return -1; return -1;
} }
err = snd_pcm_hw_params_set_access(handle, hwparams, SND_PCM_ACCESS_RW_INTERLEAVED); err = snd_pcm_hw_params_set_access(handle, hwparams, SND_PCM_ACCESS_RW_INTERLEAVED);
if (err < 0) if (err < 0)
{ {
ERROR_LOG("Access type not available: %s\n", snd_strerror(err)); fprintf(stderr,"Access type not available: %s\n", snd_strerror(err));
return -1; return -1;
} }
err = snd_pcm_hw_params_set_format(handle, hwparams, format); err = snd_pcm_hw_params_set_format(handle, hwparams, format);
if (err < 0) if (err < 0)
{ {
ERROR_LOG("Sample format not available: %s\n", snd_strerror(err)); fprintf(stderr,"Sample format not available: %s\n", snd_strerror(err));
return -1; return -1;
} }
err = snd_pcm_hw_params_set_channels(handle, hwparams, pchannels); err = snd_pcm_hw_params_set_channels(handle, hwparams, pchannels);
if (err < 0) if (err < 0)
{ {
ERROR_LOG("Channels count not available: %s\n", snd_strerror(err)); fprintf(stderr,"Channels count not available: %s\n", snd_strerror(err));
return -1; return -1;
} }
err = snd_pcm_hw_params_set_rate_near(handle, hwparams, &pspeed, 0); err = snd_pcm_hw_params_set_rate_near(handle, hwparams, &pspeed, 0);
if (err < 0) if (err < 0)
{ {
ERROR_LOG("Rate not available: %s\n", snd_strerror(err)); fprintf(stderr,"Rate not available: %s\n", snd_strerror(err));
return -1; return -1;
} }
err = snd_pcm_hw_params_set_buffer_time_near(handle, hwparams, &buffer_time, 0); err = snd_pcm_hw_params_set_buffer_time_near(handle, hwparams, &buffer_time, 0);
if(err < 0) { if(err < 0) {
ERROR_LOG("Buffer time error: %s\n", snd_strerror(err)); fprintf(stderr,"Buffer time error: %s\n", snd_strerror(err));
return -1; return -1;
} }
err = snd_pcm_hw_params_set_period_time_near(handle, hwparams, &period_time, 0); err = snd_pcm_hw_params_set_period_time_near(handle, hwparams, &period_time, 0);
if (err < 0) if (err < 0)
{ {
ERROR_LOG("Period time error: %s\n", snd_strerror(err)); fprintf(stderr,"Period time error: %s\n", snd_strerror(err));
return -1; return -1;
} }
err = snd_pcm_hw_params(handle, hwparams); err = snd_pcm_hw_params(handle, hwparams);
if (err < 0) if (err < 0)
{ {
ERROR_LOG("Unable to install hw params: %s\n", snd_strerror(err)); fprintf(stderr,"Unable to install hw params: %s\n", snd_strerror(err));
return -1; return -1;
} }
@ -171,23 +177,33 @@ public:
err = snd_pcm_status(handle, status); err = snd_pcm_status(handle, status);
if(err < 0) if(err < 0)
{ {
ERROR_LOG("Unable to get status: %s\n", snd_strerror(err)); fprintf(stderr,"Unable to get status: %s\n", snd_strerror(err));
return -1; return -1;
} }
// Bind our asynchronous callback magic: // Bind our asynchronous callback magic:
if (handle == NULL) fprintf(stderr, "No handle.");
//fprintf(stderr,"* SPU2-X:Iz setting your internal callback.\n");
// The external handler never seems to get called after this.
snd_async_add_pcm_handler( &pcm_callback, handle, ExternalCallback, this ); snd_async_add_pcm_handler( &pcm_callback, handle, ExternalCallback, this );
err = snd_pcm_start( handle );
snd_pcm_start( handle ); if(err < 0)
{
fprintf(stderr,"Pcm start failed: %s\n", snd_strerror(err));
return -1;
}
// Diagnostic code: // Diagnostic code:
//buffer_size = snd_pcm_status_get_avail(status); //buffer_size = snd_pcm_status_get_avail(status);
//fprintf(stderr,"All set up.\n");
return 0; return 0;
} }
void Close() void Close()
{ {
//fprintf(stderr,"* SPU2-X: Closing Alsa\n");
if(handle == NULL) return; if(handle == NULL) return;
snd_pcm_drop(handle); snd_pcm_drop(handle);
@ -208,7 +224,11 @@ public:
int GetEmptySampleCount() int GetEmptySampleCount()
{ {
if(handle == NULL) return 0; if(handle == NULL)
{
fprintf(stderr,"Handle is NULL!\n");
return 0;
}
// Returns the amount of free buffer space, in samples. // Returns the amount of free buffer space, in samples.
uint l = snd_pcm_avail_update(handle); uint l = snd_pcm_avail_update(handle);

View File

@ -29,22 +29,11 @@
#include <sys/soundcard.h> #include <sys/soundcard.h>
#include <unistd.h> #include <unistd.h>
// Make it easier to check and set checkmarks in the gui
#define is_checked(main_widget, widget_name) (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(main_widget, widget_name))))
#define set_checked(main_widget,widget_name, state) gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(lookup_widget(main_widget, widget_name)), state)
#define ALSA_PCM_NEW_HW_PARAMS_API #define ALSA_PCM_NEW_HW_PARAMS_API
#define ALSA_PCM_NEW_SW_PARAMS_API #define ALSA_PCM_NEW_SW_PARAMS_API
#ifdef ALSA_MEM_DEF
#define ALSA_MEM_EXTERN
#else
#define ALSA_MEM_EXTERN extern
#endif
#define SOUNDSIZE 500000 #define SOUNDSIZE 500000
#define SAMPLE_RATE 48000L #define SAMPLE_RATE 48000L
#define ERROR_LOG printf
// Pull in from Alsa.cpp // Pull in from Alsa.cpp
extern int AlsaSetupSound(); extern int AlsaSetupSound();