diff --git a/plugins/zerospu2/Linux/Linux.cpp b/plugins/zerospu2/Linux/Linux.cpp index a987844db8..3918bbda80 100644 --- a/plugins/zerospu2/Linux/Linux.cpp +++ b/plugins/zerospu2/Linux/Linux.cpp @@ -1,5 +1,5 @@ /* ZeroSPU2 - * Copyright (C) 2006-2007 zerofrog + * Copyright (C) 2006-2010 zerofrog * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -31,40 +31,6 @@ extern "C" { extern char *libraryName; -// This is a bit ugly. I'll see if I can work out a better way to do this later. -int SetupSound() -{ -#ifdef ZEROSPU2_OSS - return OSSSetupSound(); -#else - return AlsaSetupSound(); -#endif -} -void RemoveSound() -{ -#ifdef ZEROSPU2_OSS - OSSRemoveSound(); -#else - AlsaRemoveSound(); -#endif -} -int SoundGetBytesBuffered() -{ -#ifdef ZEROSPU2_OSS - return OSSSoundGetBytesBuffered(); -#else - return AlsaSoundGetBytesBuffered(); -#endif -} -void SoundFeedVoiceData(unsigned char* pSound,long lBytes) -{ -#ifdef ZEROSPU2_OSS - OSSSoundFeedVoiceData(pSound, lBytes); -#else - AlsaSoundFeedVoiceData(pSound, lBytes); -#endif -} - GtkWidget *MsgDlg, *ConfDlg; void OnMsg_Ok() diff --git a/plugins/zerospu2/Linux/Linux.h b/plugins/zerospu2/Linux/Linux.h index 489b1ace63..dd6886eee3 100644 --- a/plugins/zerospu2/Linux/Linux.h +++ b/plugins/zerospu2/Linux/Linux.h @@ -1,5 +1,5 @@ /* ZeroSPU2 - * Copyright (C) 2006-2007 zerofrog + * Copyright (C) 2006-2010 zerofrog * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -30,46 +30,10 @@ #include #include +#include "Targets/SoundTargets.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) -// Alsa & OSS defines -#ifdef ZEROSPU2_OSS - -#define OSS_MODE_STEREO 1 -#define SOUNDSIZE 76800 - -// Pull in from OSS.cpp -extern int OSSSetupSound(); -extern void OSSRemoveSound(); -extern int OSSSoundGetBytesBuffered(); -extern void OSSSoundFeedVoiceData(unsigned char* pSound,long lBytes); - -#else - -#define ALSA_PCM_NEW_HW_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 - -// Pull in from Alsa.cpp -extern int AlsaSetupSound(); -extern void AlsaRemoveSound(); -extern int AlsaSoundGetBytesBuffered(); -extern void AlsaSoundFeedVoiceData(unsigned char* pSound,long lBytes); -#endif - -extern int SetupSound(); -extern void RemoveSound(); -extern int SoundGetBytesBuffered(); -extern void SoundFeedVoiceData(unsigned char* pSound,long lBytes); - -#endif // __LINUX_H__ \ No newline at end of file +#endif // __LINUX_H__ diff --git a/plugins/zerospu2/Makefile.am b/plugins/zerospu2/Makefile.am index 3d6a00768a..ee09c0ff6b 100644 --- a/plugins/zerospu2/Makefile.am +++ b/plugins/zerospu2/Makefile.am @@ -24,6 +24,6 @@ libZeroSPU2_LDADD=$(libZeroSPU2_a_OBJECTS) libSoundTouch.a libZeroSPU2_a_SOURCES = zerospu2.cpp voices.cpp zerodma.cpp libZeroSPU2_a_SOURCES += zerospu2.h reg.h misc.h -libZeroSPU2_a_SOURCES += Linux/interface.c Linux/Linux.cpp Linux/Alsa.cpp Linux/OSS.cpp Linux/support.c +libZeroSPU2_a_SOURCES += Linux/interface.c Linux/Linux.cpp Targets/Alsa.cpp Targets/OSS.cpp Targets/SoundTargets.cpp Linux/support.c #SUBDIRS = ../../3rdparty/SoundTouch diff --git a/plugins/zerospu2/Linux/Alsa.cpp b/plugins/zerospu2/Targets/Alsa.cpp similarity index 95% rename from plugins/zerospu2/Linux/Alsa.cpp rename to plugins/zerospu2/Targets/Alsa.cpp index 8a72e98840..121118e7a3 100644 --- a/plugins/zerospu2/Linux/Alsa.cpp +++ b/plugins/zerospu2/Targets/Alsa.cpp @@ -1,5 +1,5 @@ /* ZeroSPU2 - * Copyright (C) 2006-2007 zerofrog + * Copyright (C) 2006-2010 zerofrog * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -18,12 +18,8 @@ // Modified by arcum42@gmail.com - #ifndef ZEROSPU2_OSS - // ALSA -#include - -#define ALSA_MEM_DEF +#include "Alsa.h" #include "Linux.h" static snd_pcm_t *handle = NULL; @@ -136,7 +132,10 @@ void AlsaRemoveSound() int AlsaSoundGetBytesBuffered() { - int l; + unsigned long l = snd_pcm_avail_update(handle); + if (MaxBuffer == 0) MaxBuffer = l; + return MaxBuffer - l; + /*int l; // failed to open? if(handle == NULL) return SOUNDSIZE; @@ -150,7 +149,7 @@ int AlsaSoundGetBytesBuffered() else l=0; // -> else go on - return l; + return l;*/ } void AlsaSoundFeedVoiceData(unsigned char* pSound,long lBytes) @@ -161,5 +160,3 @@ void AlsaSoundFeedVoiceData(unsigned char* pSound,long lBytes) snd_pcm_prepare(handle); snd_pcm_writei(handle,pSound, lBytes/4); } - -#endif \ No newline at end of file diff --git a/plugins/zerospu2/Targets/Alsa.h b/plugins/zerospu2/Targets/Alsa.h new file mode 100644 index 0000000000..c08f912552 --- /dev/null +++ b/plugins/zerospu2/Targets/Alsa.h @@ -0,0 +1,50 @@ +/* ZeroSPU2 + * Copyright (C) 2006-2010 zerofrog + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef ALSA_H_INCLUDED +#define ALSA_H_INCLUDED + +#include "SoundTargets.h" + +#include +#define ALSA_MEM_DEF + +#define ALSA_PCM_NEW_HW_PARAMS_API +#define ALSA_PCM_NEW_SW_PARAMS_API + +#ifdef ALSA_MEM_DEF +#define ALSA_MEM_EXTERN +#else +#define ALSA_MEM_EXTERN extern +#endif + +extern int AlsaSetupSound(); +extern void AlsaRemoveSound(); +extern int AlsaSoundGetBytesBuffered(); +extern void AlsaSoundFeedVoiceData(unsigned char* pSound,long lBytes); + +// Pull in from Alsa.cpp +static SoundCallbacks AlsaCmds = +{ + (intFunction)AlsaSetupSound, + (voidFunction)AlsaRemoveSound, + (intFunction)AlsaSoundGetBytesBuffered, + (soundFeedFunction)AlsaSoundFeedVoiceData +}; + +#endif // ALSA_H_INCLUDED diff --git a/plugins/zerospu2/Linux/OSS.cpp b/plugins/zerospu2/Targets/OSS.cpp similarity index 96% rename from plugins/zerospu2/Linux/OSS.cpp rename to plugins/zerospu2/Targets/OSS.cpp index aaa369d1a0..22ca32c556 100644 --- a/plugins/zerospu2/Linux/OSS.cpp +++ b/plugins/zerospu2/Targets/OSS.cpp @@ -1,5 +1,5 @@ /* ZeroSPU2 - * Copyright (C) 2006-2007 zerofrog + * Copyright (C) 2006-2010 zerofrog * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -18,9 +18,8 @@ // Modified by arcum42@gmail.com -#ifdef ZEROSPU2_OSS - #include "Linux.h" +#include "OSS.h" static int oss_audio_fd = -1; extern int errno; @@ -81,7 +80,7 @@ int OSSSetupSound() } err = ioctl(oss_audio_fd,SNDCTL_DSP_SPEED,&oss_speed); - if ((err == -1) || (oss_speed!=pspeed) + if ((err == -1) || (oss_speed!=pspeed)) { ERROR_LOG("Sound frequency not supported\n"); return -1; @@ -123,5 +122,3 @@ void OSSSoundFeedVoiceData(unsigned char* pSound,long lBytes) if(oss_audio_fd == -1) return; write(oss_audio_fd,pSound,lBytes); } - -#endif \ No newline at end of file diff --git a/plugins/zerospu2/Targets/OSS.h b/plugins/zerospu2/Targets/OSS.h new file mode 100644 index 0000000000..633ac0d8fc --- /dev/null +++ b/plugins/zerospu2/Targets/OSS.h @@ -0,0 +1,37 @@ +/* ZeroSPU2 + * Copyright (C) 2006-2010 zerofrog + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef OSS_H_INCLUDED +#define OSS_H_INCLUDED + +#define OSS_MODE_STEREO 1 + +extern int OSSSetupSound(); +extern void OSSRemoveSound(); +extern int OSSSoundGetBytesBuffered(); +extern void OSSSoundFeedVoiceData(unsigned char* pSound,long lBytes); + +static SoundCallbacks OSSCmds = +{ + (intFunction)OSSSetupSound, + (voidFunction)OSSRemoveSound, + (intFunction)OSSSoundGetBytesBuffered, + (soundFeedFunction)OSSSoundFeedVoiceData +}; + +#endif // OSS_H_INCLUDED diff --git a/plugins/zerospu2/Targets/SoundTargets b/plugins/zerospu2/Targets/SoundTargets new file mode 100644 index 0000000000..e69de29bb2 diff --git a/plugins/zerospu2/Targets/SoundTargets.cpp b/plugins/zerospu2/Targets/SoundTargets.cpp new file mode 100644 index 0000000000..fdce657384 --- /dev/null +++ b/plugins/zerospu2/Targets/SoundTargets.cpp @@ -0,0 +1,83 @@ +/* ZeroSPU2 + * Copyright (C) 2006-2010 zerofrog; modified by arcum42 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "SoundTargets.h" + +SoundCallbacks *SoundCmds; +u32 SOUNDSIZE; +u32 MaxBuffer; + +#ifdef __LINUX__ + +#include "Linux.h" + +#ifdef ZEROSPU2_ALSA +#include "Alsa.h" +void InitAlsa() +{ + SoundCmds = &AlsaCmds; + SOUNDSIZE = 500000; + //MaxBuffer = 80000; +} +#endif + +#ifdef ZEROSPU2_OSS +#include "OSS.h" +#endif + +void InitOSS() +{ + SoundCmds = &OSSCmds; + SOUNDSIZE = 76800; + MaxBuffer = 80000; +} +#else +/*#include "dsound51.h" + +void InitDSound() +{ + SoundCmds = &DSCmds; + SOUNDSIZE = 76800; + MaxBuffer = 80000; +}*/ +#endif + +/*#include "PulseAudio.h" + +void InitPulseAudio() +{ + SoundCmds = &PACmds; + SOUNDSIZE = 4096; +}*/ + +int SetupSound() +{ + return SoundCmds->SetupSound(); +} +void RemoveSound() +{ + SoundCmds->RemoveSound(); +} +int SoundGetBytesBuffered() +{ + return SoundCmds->SoundGetBytesBuffered(); +} +void SoundFeedVoiceData(unsigned char* pSound,long lBytes) +{ + SoundCmds->SoundFeedVoiceData(pSound, lBytes); +} diff --git a/plugins/zerospu2/Targets/SoundTargets.h b/plugins/zerospu2/Targets/SoundTargets.h new file mode 100644 index 0000000000..6a71d5aee8 --- /dev/null +++ b/plugins/zerospu2/Targets/SoundTargets.h @@ -0,0 +1,62 @@ +/* ZeroSPU2 + * Copyright (C) 2006-2010 zerofrog; modified by arcum42 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef SOUNDTARGETS_H_INCLUDED +#define SOUNDTARGETS_H_INCLUDED + +#include "Pcsx2Defs.h" + +typedef void (*voidFunction)(); +typedef int (*intFunction)(); +typedef bool (*boolFunction)(); +typedef void (*soundFeedFunction)(unsigned char *, long); + +struct SoundCallbacks +{ + intFunction SetupSound; + voidFunction RemoveSound; + intFunction SoundGetBytesBuffered; + soundFeedFunction SoundFeedVoiceData; +}; + +extern SoundCallbacks *SoundCmds; +extern u32 SOUNDSIZE; +extern u32 MaxBuffer; + +// Target List +#define ZEROSPU2_ALSA // Comment if Alsa isn't on the system. +#define ZEROSPU2_OSS // Comment if OSS isn't on the system. + +#ifdef ZEROSPU2_OSS +#include "Targets/OSS.h" + +extern void InitOSS(); +#endif + +#ifdef ZEROSPU2_ALSA +#include "Targets/Alsa.h" + +extern void InitAlsa(); +#endif + +extern int SetupSound(); +extern void RemoveSound(); +extern int SoundGetBytesBuffered(); +extern void SoundFeedVoiceData(unsigned char* pSound,long lBytes); + +#endif // SOUNDTARGETS_H_INCLUDED diff --git a/plugins/zerospu2/misc.h b/plugins/zerospu2/misc.h index dab6876483..d8b6efd446 100644 --- a/plugins/zerospu2/misc.h +++ b/plugins/zerospu2/misc.h @@ -1,5 +1,5 @@ /* ZeroSPU2 - * Copyright (C) 2006-2007 zerofrog + * Copyright (C) 2006-2010 zerofrog * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/plugins/zerospu2/reg.h b/plugins/zerospu2/reg.h index 27f5931fc7..87b6f99917 100644 --- a/plugins/zerospu2/reg.h +++ b/plugins/zerospu2/reg.h @@ -1,5 +1,5 @@ /* ZeroSPU2 - * Copyright (C) 2006-2007 zerofrog + * Copyright (C) 2006-2010 zerofrog * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -179,4 +179,4 @@ R_MIX_DEST_B1 = 0x0338, #define SPU_AUTODMA_LOOP 1 //spu2 #define SPU_AUTODMA_START_ADDR (1 << 1) //spu2 -#endif \ No newline at end of file +#endif diff --git a/plugins/zerospu2/voices.cpp b/plugins/zerospu2/voices.cpp index b2f3776f60..3b3e138c47 100644 --- a/plugins/zerospu2/voices.cpp +++ b/plugins/zerospu2/voices.cpp @@ -1,5 +1,5 @@ /* ZeroSPU2 - * Copyright (C) 2006-2007 zerofrog + * Copyright (C) 2006-2010 zerofrog * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/plugins/zerospu2/zerodma.cpp b/plugins/zerospu2/zerodma.cpp index e25c6027c0..4590d4f586 100644 --- a/plugins/zerospu2/zerodma.cpp +++ b/plugins/zerospu2/zerodma.cpp @@ -1,5 +1,5 @@ /* ZeroSPU2 - * Copyright (C) 2006-2007 zerofrog + * Copyright (C) 2006-2010 zerofrog * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -268,4 +268,4 @@ void CALLBACK SPU2interruptDMA7() { LOG_CALLBACK("SPU2interruptDMA7()\n"); SPU2interruptDMA(1); -} \ No newline at end of file +} diff --git a/plugins/zerospu2/zerospu2.cpp b/plugins/zerospu2/zerospu2.cpp index 84b4abc07d..061b9bd4e6 100644 --- a/plugins/zerospu2/zerospu2.cpp +++ b/plugins/zerospu2/zerospu2.cpp @@ -1,5 +1,5 @@ /* ZeroSPU2 - * Copyright (C) 2006-2007 zerofrog + * Copyright (C) 2006-2010 zerofrog * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,15 +16,18 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#ifdef _WIN32 +#include "svnrev.h" + u32 MaxBuffer = 80000; // Until I put this in properly, avoid breaking Windows. +#else +#include "Targets/SoundTargets.h" +#endif + #include "zerospu2.h" #include #include -#ifdef _WIN32 -#include "svnrev.h" -#endif - #include "SoundTouch/SoundTouch.h" #include "SoundTouch/WavFile.h" @@ -218,6 +221,14 @@ s32 CALLBACK SPU2init() #ifdef _WIN32 QueryPerformanceFrequency(&g_counterfreq); +#else + +#if defined(ZEROSPU2_ALSA) + InitAlsa(); +#elif defined(ZEROSPU2_OSS) + InitOSS(); +#endif + #endif spu2regs = (s8*)malloc(0x10000); @@ -908,10 +919,10 @@ void* SPU2ThreadProc(void* lpParam) { s32 bytesbuf = SoundGetBytesBuffered(); - if ( bytesbuf < 8000 ) + if ( bytesbuf < MaxBuffer / 10 ) NewSamples += 1000; // check the current timestamp, if too far apart, speed up audio - else if ( bytesbuf > 40000 ) + else if ( bytesbuf > MaxBuffer / 2 ) { //WARN_LOG("making faster %d\n", timeGetTime() - s_pAudioBuffers[nReadBuf].timestamp); NewSamples -= (bytesbuf-40000)/10;//*(ps2delay-NewSamples*8/1000); diff --git a/plugins/zerospu2/zerospu2.h b/plugins/zerospu2/zerospu2.h index 0ca4130940..1e81c9c161 100644 --- a/plugins/zerospu2/zerospu2.h +++ b/plugins/zerospu2/zerospu2.h @@ -1,5 +1,5 @@ /* ZeroSPU2 - * Copyright (C) 2006-2007 zerofrog + * Copyright (C) 2006-2010 zerofrog * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by