ZeroSPU2: Add PortAudio, and make it possible for it to be compiled as Alsa, OSS, or PortAudio on the Linux side.

git-svn-id: http://pcsx2.googlecode.com/svn/trunk@2443 96395faa-99c1-11dd-bbfe-3dabce05a288
This commit is contained in:
arcum42 2010-01-17 11:19:01 +00:00
parent 78aa3de579
commit f04235177c
6 changed files with 248 additions and 23 deletions

View File

@ -6,8 +6,8 @@
<Option pch_mode="2" />
<Option compiler="gcc" />
<Build>
<Target title="Debug">
<Option output="../../../bin/plugins/libZeroSPU2.so.0.1.0" prefix_auto="0" extension_auto="0" />
<Target title="Alsa - Debug">
<Option output="../../../bin/plugins/libZeroSPU2d-alsa.so.0.4.6" prefix_auto="0" extension_auto="0" />
<Option object_output="obj/Debug/" />
<Option type="3" />
<Option compiler="gcc" />
@ -15,13 +15,14 @@
<Option createStaticLib="1" />
<Compiler>
<Add option="-g" />
<Add option="-DZEROSPU2_ALSA" />
</Compiler>
<Linker>
<Add library="../../../deps/debug/libsoundtouch-dbg.a" />
</Linker>
</Target>
<Target title="Release">
<Option output="../../../bin/plugins/libZeroSPU2.so.0.1.0" prefix_auto="0" extension_auto="0" />
<Target title="Alsa - Release">
<Option output="../../../bin/plugins/libZeroSPU2-alsa.so.0.4.6" prefix_auto="0" extension_auto="0" />
<Option object_output="obj/Release/" />
<Option type="3" />
<Option compiler="gcc" />
@ -29,12 +30,79 @@
<Option createStaticLib="1" />
<Compiler>
<Add option="-O2" />
<Add option="-DZEROSPU2_ALSA" />
</Compiler>
<Linker>
<Add option="-s" />
<Add library="../../../deps/libsoundtouch.a" />
</Linker>
</Target>
<Target title="PortAudio - Debug">
<Option output="../../../bin/plugins/libZeroSPU2d-pa.so.0.4.6" prefix_auto="0" extension_auto="0" />
<Option object_output="obj/Debug/" />
<Option type="3" />
<Option compiler="gcc" />
<Option createDefFile="1" />
<Option createStaticLib="1" />
<Compiler>
<Add option="-g" />
<Add option="-DZEROSPU2_PORTAUDIO" />
</Compiler>
<Linker>
<Add library="../../../deps/debug/libsoundtouch-dbg.a" />
<Add library="portaudio" />
</Linker>
</Target>
<Target title="PortAudio - Release">
<Option output="../../../bin/plugins/libZeroSPU2-pa.so.0.4.6" prefix_auto="0" extension_auto="0" />
<Option object_output="obj/Release/" />
<Option type="3" />
<Option compiler="gcc" />
<Option createDefFile="1" />
<Option createStaticLib="1" />
<Compiler>
<Add option="-O2" />
<Add option="-DZEROSPU2_PORTAUDIO" />
</Compiler>
<Linker>
<Add option="-s" />
<Add library="../../../deps/libsoundtouch.a" />
<Add library="portaudio" />
</Linker>
</Target>
<Target title="OSS - Debug">
<Option output="../../../bin/plugins/libZeroSPU2d-oss.so.0.4.6" prefix_auto="0" extension_auto="0" />
<Option object_output="obj/Debug/" />
<Option type="3" />
<Option compiler="gcc" />
<Option createDefFile="1" />
<Option createStaticLib="1" />
<Compiler>
<Add option="-g" />
<Add option="-DZEROSPU2_OSS" />
</Compiler>
<Linker>
<Add library="../../../deps/debug/libsoundtouch-dbg.a" />
<Add library="portaudio" />
</Linker>
</Target>
<Target title="OSS - Release">
<Option output="../../../bin/plugins/libZeroSPU2-oss.so.0.4.6" prefix_auto="0" extension_auto="0" />
<Option object_output="obj/Release/" />
<Option type="3" />
<Option compiler="gcc" />
<Option createDefFile="1" />
<Option createStaticLib="1" />
<Compiler>
<Add option="-O2" />
<Add option="-DZEROSPU2_OSS" />
</Compiler>
<Linker>
<Add option="-s" />
<Add library="../../../deps/libsoundtouch.a" />
<Add library="portaudio" />
</Linker>
</Target>
</Build>
<Compiler>
<Add option="-Wall" />
@ -71,6 +139,16 @@
<Unit filename="../Targets/Alsa.h" />
<Unit filename="../Targets/OSS.cpp" />
<Unit filename="../Targets/OSS.h" />
<Unit filename="../Targets/PortAudio.cpp">
<Option target="PortAudio - Debug" />
<Option target="PortAudio - Release" />
<Option target="OSS - Release" />
<Option target="OSS - Debug" />
</Unit>
<Unit filename="../Targets/PortAudio.h">
<Option target="Alsa - Debug" />
<Option target="Alsa - Release" />
</Unit>
<Unit filename="../Targets/SoundTargets.cpp" />
<Unit filename="../Targets/SoundTargets.h" />
<Unit filename="../misc.h" />

View File

@ -0,0 +1,101 @@
/* 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
*/
// PortAudio support implemented by Zedr0n.
#include "PortAudio.h"
#include "Linux.h"
PaStream *stream;
#define FRAMES_PER_BUFFER 4096
int paSetupSound()
{
// initialize portaudio
PaError err = Pa_Initialize();
if( err != paNoError) {
ERROR_LOG("ZeroSPU2: Error initializing portaudio: %s\n", Pa_GetErrorText(err) );
return -1;
}
else
ERROR_LOG("ZeroSPU2: Initialized portaudio... \n");
/* Open an audio I/O stream. */
err = Pa_OpenDefaultStream( &stream,
0, /* no input channels */
2, /* stereo output */
paInt16, /* 16 bit integer point output */
SAMPLE_RATE,
FRAMES_PER_BUFFER, /* frames per buffer, i.e. the number
of sample frames that PortAudio will
request from the callback. Many apps
may want to use
paFramesPerBufferUnspecified, which
tells PortAudio to pick the best,
possibly changing, buffer size.*/
NULL, /* this is your callback function */
NULL ); /*This is a pointer that will be passed to
your callback*/
if( err != paNoError )
{
ERROR_LOG("ZeroSPU2: Error opening sound stream...\n");
return -1;
}
else ERROR_LOG("ZeroSPU2: Created sound stream successfully...\n");
MaxBuffer = 0;
err = Pa_StartStream( stream );
if( err != paNoError )
{
ERROR_LOG("ZeroSPU2: Error starting sound stream...\n");
return -1;
}
else ERROR_LOG("ZeroSPU2: Started sound stream successfully...\n");
return 0;
}
void paRemoveSound()
{
PaError err = Pa_StopStream( stream );
if( err != paNoError )
ERROR_LOG("ZeroSPU2: PortAudio error: %s\n", Pa_GetErrorText( err ) );
else
ERROR_LOG("ZeroSPU2: stream stopped... \n");
err = Pa_Terminate();
if( err != paNoError )
ERROR_LOG("PortAudio error: %s\n", Pa_GetErrorText( err ) );
else
ERROR_LOG("ZeroSPU2: portaudio terminated... \n");
}
int paSoundGetBytesBuffered()
{
unsigned long l = Pa_GetStreamWriteAvailable(stream);
if(MaxBuffer == 0) MaxBuffer = l;
return MaxBuffer - l;
}
void paSoundFeedVoiceData(unsigned char* pSound, long lBytes)
{
Pa_WriteStream(stream, (void*) pSound, (unsigned long) lBytes / 4);
}

View File

@ -0,0 +1,40 @@
/* 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
*/
// PortAudio support implemented by Zedr0n.
#ifndef PORTAUDIO_H_INCLUDED
#define PORTAUDIO_H_INCLUDED
#include "portaudio.h"
#include "SoundTargets.h"
extern int paSetupSound();
extern void paRemoveSound();
extern int paSoundGetBytesBuffered();
extern void paSoundFeedVoiceData(unsigned char* pSound,long lBytes);
// Pull in from Alsa.cpp
static SoundCallbacks PACmds =
{
(intFunction)paSetupSound,
(voidFunction)paRemoveSound,
(intFunction)paSoundGetBytesBuffered,
(soundFeedFunction)paSoundFeedVoiceData
};
#endif // PORTAUDIO_H_INCLUDED

View File

@ -23,11 +23,9 @@ u32 SOUNDSIZE;
s32 MaxBuffer;
#ifdef __LINUX__
#include "Linux.h"
#ifdef ZEROSPU2_ALSA
#include "Alsa.h"
void InitAlsa()
{
SoundCmds = &AlsaCmds;
@ -37,8 +35,6 @@ void InitAlsa()
#endif
#ifdef ZEROSPU2_OSS
#include "OSS.h"
#endif
void InitOSS()
{
@ -46,6 +42,8 @@ void InitOSS()
SOUNDSIZE = 76800;
MaxBuffer = 80000;
}
#endif
#else
#include "dsound51.h"
@ -57,13 +55,15 @@ void InitDSound()
}
#endif
/*#include "PortAudio.h"
#ifdef ZEROSPU2_PORTAUDIO
#include "PortAudio.h"
void InitPortAudio()
{
SoundCmds = &PACmds;
SOUNDSIZE = 4096;
}*/
}
#endif
int SetupSound()
{

View File

@ -16,14 +16,14 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef SOUNDTARGETS_H_INCLUDED
#define SOUNDTARGETS_H_INCLUDED
#ifndef SOUNDTARGETS_H_INCLUDED
#define SOUNDTARGETS_H_INCLUDED
#include "Pcsx2Defs.h"
typedef void (*voidFunction)();
typedef int (*intFunction)();
typedef bool (*boolFunction)();
typedef void (*voidFunction)();
typedef int (*intFunction)();
typedef bool (*boolFunction)();
typedef void (*soundFeedFunction)(unsigned char *, long);
struct SoundCallbacks
@ -33,19 +33,23 @@ struct SoundCallbacks
intFunction SoundGetBytesBuffered;
soundFeedFunction SoundFeedVoiceData;
};
extern SoundCallbacks *SoundCmds;
extern u32 SOUNDSIZE;
extern s32 MaxBuffer;
// Target List
#ifdef __LINUX__
#if (!defined(ZEROSPU2_ALSA) && !defined(ZEROSPU2_OSS) && !defined(ZEROSPU2_PORTAUDIO))
#define ZEROSPU2_ALSA // Comment if Alsa isn't on the system.
#define ZEROSPU2_OSS // Comment if OSS isn't on the system.
#else
#define ZEROSPU2_DS
#endif
//#define ZEROSPU2_PORTAUDIO
#else
#define ZEROSPU2_DS
#endif
#ifdef ZEROSPU2_OSS
#include "OSS.h"
@ -75,5 +79,5 @@ extern int SetupSound();
extern void RemoveSound();
extern int SoundGetBytesBuffered();
extern void SoundFeedVoiceData(unsigned char* pSound,long lBytes);
#endif // SOUNDTARGETS_H_INCLUDED
#endif // SOUNDTARGETS_H_INCLUDED

View File

@ -220,6 +220,8 @@ void InitApi()
InitAlsa();
#elif defined(ZEROSPU2_OSS)
InitOSS();
#elif defined(ZEROSPU2_PORTAUDIO)
InitPortAudio();
#endif
#endif
}