mirror of https://github.com/PCSX2/pcsx2.git
ZeroSPU2: Made the way different sound archetectures are done a bit more flexable so we could conceivably switch them at run time rather then compilation. And it occurred to me that the dynamic sound buffering Zedr0n is doing with PulseAudio is probably how it should be done in Alsa as well...
git-svn-id: http://pcsx2.googlecode.com/svn/trunk@2437 96395faa-99c1-11dd-bbfe-3dabce05a288
This commit is contained in:
parent
37611e4eb0
commit
e3687d6027
|
@ -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()
|
||||
|
|
|
@ -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 <unistd.h>
|
||||
|
||||
#include <zerospu2.h>
|
||||
#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__
|
||||
#endif // __LINUX_H__
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 <alsa/asoundlib.h>
|
||||
|
||||
#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
|
|
@ -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 <alsa/asoundlib.h>
|
||||
#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
|
|
@ -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
|
|
@ -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
|
|
@ -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);
|
||||
}
|
|
@ -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
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
#endif
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 <assert.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#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);
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue