- Removed the PortAudio sound driver because it was quite unstable on some systems
- Use the SDL sound driver
- Fixed the SDL include path
This commit is contained in:
bgk 2008-08-29 19:45:17 +00:00
parent c2a1300926
commit 5e5d025fd5
6 changed files with 34 additions and 189 deletions

View File

@ -42,7 +42,6 @@ IF(NOT NO_GTK)
PKG_CHECK_MODULES ( GTKMM gtkmm-2.4 )
PKG_CHECK_MODULES ( GLIBMM glibmm-2.4 )
PKG_CHECK_MODULES ( GLADEMM libglademm-2.4 )
PKG_CHECK_MODULES ( PORTAUDIO portaudio-2.0 )
PKG_CHECK_MODULES ( XV xv )
PKG_CHECK_MODULES ( GTKGLMM gtkglextmm-x11-1.2 )
ENDIF(NOT NO_GTK)
@ -61,9 +60,9 @@ ENDIF( WITH_LIRC )
# Check that the dependencies are met to build the GTK frontend
IF( NOT NO_GTK )
IF( GLIBMM_FOUND AND GTKMM_FOUND AND GLADEMM_FOUND AND PORTAUDIO_FOUND AND XV_FOUND )
IF( GLIBMM_FOUND AND GTKMM_FOUND AND GLADEMM_FOUND AND SDL_FOUND AND XV_FOUND )
SET( CAN_BUILD_GVBAM 1 )
ENDIF( GLIBMM_FOUND AND GTKMM_FOUND AND GLADEMM_FOUND AND PORTAUDIO_FOUND AND XV_FOUND )
ENDIF( GLIBMM_FOUND AND GTKMM_FOUND AND GLADEMM_FOUND AND SDL_FOUND AND XV_FOUND )
ENDIF( NOT NO_GTK )
# Set the default install dir
@ -207,7 +206,7 @@ SET(SRC_GTK
src/gtk/screenarea-opengl.cpp
src/gtk/tools.cpp
src/gtk/window.cpp
src/gtk/sndPortAudio.cpp
src/sdl/sndSDL.cpp
)
IF( NOT NO_DEBUGGER )
@ -226,7 +225,7 @@ ENDIF(CMAKE_ASM_COMPILER_LOADED AND USE_ASM_SCALERS)
INCLUDE_DIRECTORIES(
${ZLIB_INCLUDE_DIR}
${SDL_INCLUDE_DIRS}
${SDL_INCLUDE_DIR}
)
IF( CAN_BUILD_GVBAM )
@ -302,7 +301,7 @@ IF( CAN_BUILD_GVBAM )
${ZLIB_LIBRARY}
${PNG_LIBRARY}
${GLADEMM_LIBRARIES}
${PORTAUDIO_LIBRARIES}
${SDL_LIBRARY}
${XV_LIBRARIES}
${GTKGLMM_LIBRARIES}
)

View File

@ -1,178 +0,0 @@
#include <stdio.h>
#include <string.h>
#include <portaudio.h>
#ifndef _WIN32
# include <unistd.h>
#else
# include <Windows.h>
#endif
#include "../System.h"
#include "../Sound.h"
#include "../Globals.h"
extern int emulating;
static PaStreamParameters outputParameters;
static PaStream *stream;
static PaError err;
static u16 *stereodata16;
static u32 soundoffset;
static volatile u32 soundpos;
static u32 soundbufsize;
static unsigned int audioFree()
{
if (soundoffset > soundpos)
return soundbufsize - soundoffset + soundpos;
else
return soundpos - soundoffset;
}
static int patestCallback( const void *inputBuffer, void *outputBuffer,
unsigned long framesPerBuffer,
const PaStreamCallbackTimeInfo* timeInfo,
PaStreamCallbackFlags statusFlags,
void *userData )
{
const unsigned int outBufferLength = framesPerBuffer * sizeof(u16) * 2;
u8 *out = (u8*)outputBuffer;
if (!emulating || soundPaused)
{
memset(out, 0, outBufferLength);
return paContinue;
}
// Not enough available data to fill the sound buffer
//if (soundbufsize - audioFree() < outBufferLength)
// fprintf(stderr, "** PortAudio : buffer underflow **\n");
u8 *soundbuf = (u8 *)stereodata16;
for (unsigned int i = 0; i < outBufferLength; i++)
{
if (soundpos >= soundbufsize)
soundpos = 0;
out[i] = soundbuf[soundpos];
soundpos++;
}
return paContinue;
}
void systemWriteDataToSoundBuffer()
{
u32 copy1size = 0, copy2size = 0;
while (emulating && !speedup & !systemThrottle && (audioFree() < (unsigned int)soundBufferLen))
{
#ifndef _WIN32
usleep(1000);
#else
Sleep(1);
#endif
}
if ((soundbufsize - soundoffset) < (unsigned int)soundBufferLen)
{
copy1size = (soundbufsize - soundoffset);
copy2size = soundBufferLen - copy1size;
}
else
{
copy1size = soundBufferLen;
copy2size = 0;
}
memcpy((((u8 *)stereodata16)+soundoffset), soundFinalWave, copy1size);
if (copy2size)
memcpy(stereodata16, ((u8 *)soundFinalWave)+copy1size, copy2size);
soundoffset += copy1size + copy2size;
soundoffset %= soundbufsize;
}
bool systemSoundInit()
{
int sampleRate;
err = Pa_Initialize();
if (err != paNoError) goto error;
outputParameters.device = Pa_GetDefaultOutputDevice(); /* default output device */
if (outputParameters.device == paNoDevice) goto error;
outputParameters.channelCount = 2; /* stereo output */
outputParameters.sampleFormat = paInt16;
outputParameters.suggestedLatency = Pa_GetDeviceInfo( outputParameters.device )->defaultHighOutputLatency;
outputParameters.hostApiSpecificStreamInfo = NULL;
switch(soundQuality) {
case 1:
sampleRate = 44100;
soundBufferLen = 1470*2;
break;
default:
case 2:
sampleRate = 22050;
soundBufferLen = 736*2;
break;
case 4:
sampleRate = 11025;
soundBufferLen = 368*2;
break;
}
soundbufsize = (soundBufferLen + 1) * 4;
stereodata16 = new u16[soundbufsize];
memset(stereodata16, 0, soundbufsize);
soundpos = 0;
err = Pa_OpenStream(
&stream,
NULL, /* no input */
&outputParameters,
sampleRate,
0,
paClipOff, /* we won't output out of range samples so don't bother clipping them */
patestCallback,
NULL );
if (err != paNoError) goto error;
err = Pa_StartStream( stream );
if (err != paNoError) goto error;
return true;
error:
Pa_Terminate();
fprintf(stderr, "An error occured while using the portaudio stream\n");
fprintf(stderr, "Error number: %d\n", err);
fprintf(stderr, "Error message: %s\n", Pa_GetErrorText(err));
return false;
}
void systemSoundShutdown()
{
Pa_CloseStream(stream);
Pa_Terminate();
delete[] stereodata16;
}
void systemSoundPause()
{
}
void systemSoundResume()
{
}
void systemSoundReset()
{
}

View File

@ -23,6 +23,8 @@
#include <stdio.h>
#include <time.h>
#include <SDL.h>
#include "../agb/GBA.h"
#include "../dmg/gb.h"
#include "../dmg/gbGlobals.h"
@ -101,6 +103,7 @@ Window::Window(GtkWindow * _pstWindow, const Glib::RefPtr<Xml> & _poXml) :
m_uiAutofireState = 0;
m_poKeymap = NULL;
vInitSDL();
vInitSystem();
vSetDefaultTitle();
@ -887,6 +890,8 @@ void Window::vInitSystem()
}
Init_2xSaI(32);
soundInit();
}
void Window::vUnInitSystem()
@ -894,6 +899,24 @@ void Window::vUnInitSystem()
systemSoundShutdown();
}
void Window::vInitSDL()
{
static bool bDone = false;
if (bDone)
return;
int iFlags = (SDL_INIT_AUDIO | SDL_INIT_NOPARACHUTE);
if (SDL_Init(iFlags) < 0)
{
fprintf(stderr, "Failed to init SDL: %s", SDL_GetError());
abort();
}
bDone = true;
}
void Window::vInitConfig()
{
m_oConfig.vClear();

View File

@ -274,6 +274,7 @@ private:
void vInitSystem();
void vUnInitSystem();
void vInitSDL();
void vInitConfig();
void vCheckConfig();
void vInitScreenArea(EVideoOutput _eVideoOutput);

View File

@ -35,7 +35,7 @@
#include "../AutoBuild.h"
#include <SDL/SDL.h>
#include <SDL.h>
#include "../agb/GBA.h"
#include "../agb/agbprint.h"
@ -2534,7 +2534,7 @@ int main(int argc, char **argv)
emulating = 1;
renderedFrames = 0;
soundInit();
soundInit();
autoFrameSkipLastTime = throttleLastTime = systemGetClock();

View File

@ -1,4 +1,4 @@
#include <SDL/SDL.h>
#include <SDL.h>
#include "../System.h"
#include "../Sound.h"
#include "../Globals.h"
@ -33,8 +33,8 @@ static inline int soundBufferUsed()
static void soundCallback(void *,u8 *stream,int len)
{
if (len <= 0 || !emulating)
return;
if (len <= 0 || !emulating)
return;
SDL_mutexP(sdlSoundMutex);
const int nAvail = soundBufferUsed();