Added native sound support for the SDL version. The SDL version no longer

requires the external stella-sound program.

Please test extensively.


git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@108 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
stephena 2002-08-15 00:29:40 +00:00
parent 35fcaec0ff
commit 5e03d45bad
5 changed files with 242 additions and 12 deletions

View File

@ -13,7 +13,7 @@
## See the file "license" for information on usage and redistribution of
## this file, and for a DISCLAIMER OF ALL WARRANTIES.
##
## $Id: makefile,v 1.20 2002-08-14 02:30:52 bwmott Exp $
## $Id: makefile,v 1.21 2002-08-15 00:29:39 stephena Exp $
##============================================================================
##============================================================================
@ -23,16 +23,11 @@
## Comment a line out to disable that option, remove comment to enable it.
##============================================================================
### this should work with all compilers
# OPTIMIZATIONS =
### for normal optimization, full warnings
# OPTIMIZATIONS = -O -Wall
### for common optimizations, full warnings except unused vars
OPTIMIZATIONS = -O2 -Wall -Wno-unused
### to get full optimization under gcc/x Intel based OS's..
# OPTIMIZATIONS = -O3 -mcpu=pentiumpro -march=pentiumpro -Wall -Wno-unused \
# -funroll-loops -fstrength-reduce -fomit-frame-pointer -ffast-math \
# -malign-functions=2 -malign-jumps=2 -malign-loops=2
# -falign-functions=2 -falign-jumps=2 -falign-loops=2
### to get full optimization under gcc/x Athlon based OS's..
# OPTIMIZATIONS = -O3 -mcpu=athlon -march=athlon -Wall -Wno-unused \
# -funroll-loops -fstrength-reduce -fomit-frame-pointer -ffast-math \
@ -192,7 +187,7 @@ linux-sdl:
LDFLAGS+="$(CFLAGS.SDL)" \
LDLIBS="-lX11 -lXext" \
LDLIBS+="$(LIBS.SDL)" \
OBJS="mainSDL.o SndUnix.o RectList.o" \
OBJS="mainSDL.o SndSDL.o RectList.o TIASound.o" \
OBJS+="$(OBJS.SDL)"
bsdi-x:
make stella.x11 \
@ -412,6 +407,9 @@ mainX11.o: $(UI)/x11/mainX11.cxx
mainSDL.o: $(UI)/sdl/mainSDL.cxx
$(CXX) -c $(CXXFLAGS) $(OPTIONS) $(LDFLAGS) $(UI)/sdl/mainSDL.cxx
SndSDL.o: $(UI)/sdl/SndSDL.cxx $(UI)/sdl/SndSDL.hxx
$(CXX) -c $(CXXFLAGS) $(OPTIONS) $(LDFLAGS) $(UI)/sdl/SndSDL.cxx
RectList.o: $(UI)/sdl/RectList.cxx $(UI)/sdl/RectList.hxx
$(CXX) -c $(CXXFLAGS) $(OPTIONS) $(LDFLAGS) $(UI)/sdl/RectList.cxx

View File

@ -0,0 +1,148 @@
//============================================================================
//
// SSSS tt lll lll
// SS SS tt ll ll
// SS tttttt eeee ll ll aaaa
// SSSS tt ee ee ll ll aa
// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator"
// SS SS tt ee ll ll aa aa
// SSSS ttt eeeee llll llll aaaaa
//
// Copyright (c) 1995-1998 by Bradford W. Mott
//
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: SndSDL.cxx,v 1.1 2002-08-15 00:29:40 stephena Exp $
//============================================================================
#include <SDL.h>
#include "TIASound.h"
#include "SndSDL.hxx"
#define FRAGSIZE 1 << 10
static int currentVolume = 0;
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
static void fill_audio(void* udata, Uint8* stream, int len)
{
Uint8 buffer[FRAGSIZE];
if(len > FRAGSIZE)
len = FRAGSIZE;
Tia_process(buffer, len);
SDL_MixAudio(stream, buffer, len, currentVolume);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
SoundSDL::SoundSDL(int volume, bool activate)
{
myEnabled = activate;
if(!myEnabled)
return;
if(SDL_InitSubSystem(SDL_INIT_AUDIO) < 0)
{
cerr << "Couldn't init SDL audio system: " << SDL_GetError() << endl;
myEnabled = false;
return;
}
SDL_AudioSpec desired, obtained;
desired.freq = 31400;
desired.samples = FRAGSIZE;
desired.format = AUDIO_U8;
desired.callback = fill_audio;
desired.userdata = NULL;
desired.channels = 1;
if(SDL_OpenAudio(&desired, &obtained) < 0)
{
cerr << "Couldn't open SDL audio: " << SDL_GetError() << endl;
myEnabled = false;
return;
}
/* Initialize the TIA Sound Library */
Tia_sound_init(31400, obtained.freq);
isMuted = false;
setVolume(volume);
SDL_PauseAudio(0);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
SoundSDL::~SoundSDL()
{
if(myEnabled)
SDL_CloseAudio();
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void SoundSDL::set(Sound::Register reg, uInt8 value)
{
if(!myEnabled)
return;
switch(reg)
{
case AUDC0:
Update_tia_sound(0x15, value);
break;
case AUDC1:
Update_tia_sound(0x16, value);
break;
case AUDF0:
Update_tia_sound(0x17, value);
break;
case AUDF1:
Update_tia_sound(0x18, value);
break;
case AUDV0:
Update_tia_sound(0x19, value);
break;
case AUDV1:
Update_tia_sound(0x1A, value);
break;
default:
return;
break;
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void SoundSDL::mute(bool state)
{
if(!myEnabled)
return;
// Ignore multiple calls to do the same thing
if(isMuted == state)
return;
isMuted = state;
SDL_PauseAudio(isMuted ? 1 : 0);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void SoundSDL::setVolume(int percent)
{
if(!myEnabled)
return;
if((percent >= 0) && (percent <= 100))
currentVolume = (int) (((float) percent / 100.0) * (float) SDL_MIX_MAXVOLUME);
}

View File

@ -0,0 +1,77 @@
//============================================================================
//
// SSSS tt lll lll
// SS SS tt ll ll
// SS tttttt eeee ll ll aaaa
// SSSS tt ee ee ll ll aa
// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator"
// SS SS tt ee ll ll aa aa
// SSSS ttt eeeee llll llll aaaaa
//
// Copyright (c) 1995-1998 by Bradford W. Mott
//
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: SndSDL.hxx,v 1.1 2002-08-15 00:29:40 stephena Exp $
//============================================================================
#ifndef SOUNDSDL_HXX
#define SOUNDSDL_HXX
#include <SDL.h>
#include "bspf.hxx"
#include "Sound.hxx"
/**
This class implements the sound API for SDL.
@author Stephen Anthony
@version $Id: SndSDL.hxx,v 1.1 2002-08-15 00:29:40 stephena Exp $
*/
class SoundSDL : public Sound
{
public:
/**
Create a new sound object
*/
SoundSDL(int volume, bool activate = true);
/**
Destructor
*/
virtual ~SoundSDL();
public:
/**
Set the value of the specified sound register
@param reg The sound register to set
@param val The new value for the sound registers
*/
virtual void set(Sound::Register reg, uInt8 val);
/**
Set the mute state of the sound object
@param state Mutes sound iff true
*/
virtual void mute(bool state);
/**
Set the current volume according to the given percentage
@param percent Scaled value (0-100) indicating the desired volume
*/
void setVolume(int percent);
private:
// Indicates if the sound system was initialized
bool myEnabled;
// Indicates if the sound is currently muted
bool isMuted;
};
#endif

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: mainSDL.cxx,v 1.25 2002-08-04 00:28:18 stephena Exp $
// $Id: mainSDL.cxx,v 1.26 2002-08-15 00:29:40 stephena Exp $
//============================================================================
#include <fstream>
@ -39,6 +39,7 @@
#include "SndUnix.hxx"
#include "RectList.hxx"
#include "Settings.hxx"
#include "SndSDL.hxx"
#ifdef HAVE_PNG
#include "Snapshot.hxx"
@ -213,7 +214,7 @@ static uInt32 currentState = 0;
*/
bool setupDisplay()
{
Uint32 initflags = SDL_INIT_VIDEO | SDL_INIT_JOYSTICK;
Uint32 initflags = SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_TIMER;
if(SDL_Init(initflags) < 0)
return false;
@ -1550,7 +1551,7 @@ int main(int argc, char* argv[])
}
// Create a sound object for use with the console
SoundUnix sound(settings->theDesiredVolume);
SoundSDL sound(settings->theDesiredVolume);
// Get just the filename of the file containing the ROM image
const char* filename = (!strrchr(file, '/')) ? file : strrchr(file, '/') + 1;

View File

@ -32,6 +32,10 @@
/* */
/*****************************************************************************/
#ifdef __cplusplus
extern "C" {
#endif
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
@ -609,4 +613,6 @@ void Tia_process (register unsigned char *buffer, register uint16 n)
}
#ifdef __cplusplus
}
#endif