Added a public close() method to the sound classes so that the game

launcher can close the sound device while the user is selecting a
new game. This prevents the intermittent problem of a left-over sound
fragment from the old game being played when the new game starts.


git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@773 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
bwmott 2005-09-10 16:19:20 +00:00
parent 17352bb0e9
commit 79313cc4c4
6 changed files with 46 additions and 42 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: SoundNull.hxx,v 1.3 2005-09-06 19:42:35 stephena Exp $
// $Id: SoundNull.hxx,v 1.4 2005-09-10 16:19:20 bwmott Exp $
//============================================================================
#ifndef SOUND_NULL_HXX
@ -31,7 +31,7 @@ class Deserializer;
is completely disabled.
@author Stephen Anthony
@version $Id: SoundNull.hxx,v 1.3 2005-09-06 19:42:35 stephena Exp $
@version $Id: SoundNull.hxx,v 1.4 2005-09-10 16:19:20 bwmott Exp $
*/
class SoundNull : public Sound
{
@ -82,10 +82,14 @@ class SoundNull : public Sound
/**
Initializes the sound device. This must be called before any
calls are made to derived methods.
@param forcerestart Do a soft or hard reset of the sound subsystem
*/
void initialize(bool forcerestart = false) { }
void initialize() { }
/**
Should be called to close the sound device. Once called the sound
device can be started again using the initialize method.
*/
void close() { }
/**
Return true iff the sound device was successfully initialized.

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: SoundSDL.cxx,v 1.24 2005-09-06 19:42:35 stephena Exp $
// $Id: SoundSDL.cxx,v 1.25 2005-09-10 16:19:20 bwmott Exp $
//============================================================================
#ifdef SOUND_SUPPORT
@ -52,7 +52,7 @@ SoundSDL::SoundSDL(OSystem* osystem)
SoundSDL::~SoundSDL()
{
// Close the SDL audio system if it's initialized
closeAudio();
close();
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -63,25 +63,21 @@ void SoundSDL::setEnabled(bool state)
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void SoundSDL::initialize(bool forcerestart)
void SoundSDL::initialize()
{
// Check whether to start the sound subsystem
if(!myIsEnabled)
{
closeAudio();
close();
if(myOSystem->settings().getBool("showinfo"))
cout << "Sound disabled." << endl << endl;
return;
}
// Clear the sound queue FIXME - still an annoying partial sound playing?
SDL_PauseAudio(1);
// Make sure the sound queue is clear
myRegWriteQueue.clear();
myTIASound.reset();
if(forcerestart && myIsInitializedFlag)
closeAudio();
if(!((SDL_WasInit(SDL_INIT_AUDIO) & SDL_INIT_AUDIO) > 0))
{
myIsInitializedFlag = false;
@ -167,6 +163,16 @@ void SoundSDL::initialize(bool forcerestart)
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void SoundSDL::close()
{
if(myIsInitializedFlag)
{
SDL_CloseAudio();
myIsInitializedFlag = false;
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool SoundSDL::isSuccessfullyInitialized() const
{
@ -395,17 +401,6 @@ void SoundSDL::callback(void* udata, uInt8* stream, int len)
sound->processFragment(stream, (Int32)len);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void SoundSDL::closeAudio()
{
if(myIsInitializedFlag)
{
SDL_PauseAudio(1);
SDL_CloseAudio();
myIsInitializedFlag = false;
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool SoundSDL::load(Deserializer& in)
{

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: SoundSDL.hxx,v 1.15 2005-09-06 19:42:35 stephena Exp $
// $Id: SoundSDL.hxx,v 1.16 2005-09-10 16:19:20 bwmott Exp $
//============================================================================
#ifndef SOUND_SDL_HXX
@ -34,7 +34,7 @@ class OSystem;
This class implements the sound API for SDL.
@author Stephen Anthony and Bradford W. Mott
@version $Id: SoundSDL.hxx,v 1.15 2005-09-06 19:42:35 stephena Exp $
@version $Id: SoundSDL.hxx,v 1.16 2005-09-10 16:19:20 bwmott Exp $
*/
class SoundSDL : public Sound
{
@ -84,10 +84,14 @@ class SoundSDL : public Sound
/**
Initializes the sound device. This must be called before any
calls are made to derived methods.
@param forcerestart Do a soft or hard reset of the sound subsystem
*/
void initialize(bool forcerestart = false);
void initialize();
/**
Should be called to close the sound device. Once called the sound
device can be started again using the initialize method.
*/
void close();
/**
Return true iff the sound device was successfully initialized.
@ -272,9 +276,6 @@ class SoundSDL : public Sound
private:
// Callback function invoked by the SDL Audio library when it needs data
static void callback(void* udata, uInt8* stream, int len);
// Closes the audio device
void closeAudio();
};
#endif // SOUND_SUPPORT

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: OSystem.cxx,v 1.36 2005-09-06 19:42:35 stephena Exp $
// $Id: OSystem.cxx,v 1.37 2005-09-10 16:19:20 bwmott Exp $
//============================================================================
#include <cassert>
@ -333,6 +333,7 @@ bool OSystem::createConsole(const string& romfile)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void OSystem::createLauncher()
{
mySound->close();
setFramerate(60);
myEventHandler->reset(EventHandler::S_LAUNCHER);
@ -346,7 +347,6 @@ void OSystem::createLauncher()
myEventHandler->refreshDisplay();
myFrameBuffer->setCursorState();
mySound->mute(true);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

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: Sound.hxx,v 1.20 2005-09-06 19:42:35 stephena Exp $
// $Id: Sound.hxx,v 1.21 2005-09-10 16:19:20 bwmott Exp $
//============================================================================
#ifndef SOUND_HXX
@ -30,7 +30,7 @@ class Deserializer;
It has no functionality whatsoever.
@author Stephen Anthony
@version $Id: Sound.hxx,v 1.20 2005-09-06 19:42:35 stephena Exp $
@version $Id: Sound.hxx,v 1.21 2005-09-10 16:19:20 bwmott Exp $
*/
class Sound
{
@ -80,10 +80,14 @@ class Sound
/**
Initializes the sound device. This must be called before any
calls are made to derived methods.
@param forcerestart Do a soft or hard reset of the sound subsystem
*/
virtual void initialize(bool forcerestart = false) = 0;
virtual void initialize() = 0;
/**
Should be called to close the sound device. Once called the sound
device can be started again using the initialize method.
*/
virtual void close() = 0;
/**
Return true iff the sound device was successfully initialized.

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: AudioDialog.cxx,v 1.14 2005-09-06 19:42:35 stephena Exp $
// $Id: AudioDialog.cxx,v 1.15 2005-09-10 16:19:20 bwmott Exp $
//
// Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project
@ -167,7 +167,7 @@ void AudioDialog::saveConfig()
// be a time-consuming operation
if(restart)
{
instance()->sound().initialize(true);
instance()->sound().initialize();
instance()->sound().mute(true);
}
}