Applied patch from Daniel Richard G. (with modifications) concerning the

default behaviour of the volume settings.  Now, if no volume settings
have been specified, this means that changing the volume is disabled,
and the volume won't be changed on program start or exit.  Specifying '-1'
for the volume will have the same effect.

This is the new default behaviour.  If you want a different volume, you
now have to specify it.

Updated the documentation concerning using '-volume -1'.


git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@172 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
stephena 2003-02-25 03:12:55 +00:00
parent 69d189c15f
commit ec407e7c60
11 changed files with 72 additions and 67 deletions

View File

@ -692,7 +692,8 @@
<tr>
<td><pre>-volume &lt;number&gt;</pre></td>
<td>Set the volume (0 - 100)</td>
<td>Set the volume (0 - 100). Use -1 to completely disable
changing the volume</td>
</tr>
<tr>

View File

@ -13,10 +13,10 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: Sound.cxx,v 1.4 2002-11-13 16:19:20 stephena Exp $
// $Id: Sound.cxx,v 1.5 2003-02-25 03:12:54 stephena Exp $
//============================================================================
#include "SoundOSS.hxx"
#include "Sound.hxx"
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Sound::Sound()
@ -46,7 +46,7 @@ bool Sound::isSuccessfullyInitialized() const
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Sound::setSoundVolume(uInt32 volume)
void Sound::setSoundVolume(Int32 volume)
{
}

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.4 2002-11-13 16:19:20 stephena Exp $
// $Id: Sound.hxx,v 1.5 2003-02-25 03:12:55 stephena Exp $
//============================================================================
#ifndef SOUND_HXX
@ -28,7 +28,7 @@
to compile Stella with no sound support whatsoever.
@author Stephen Anthony
@version $Id: Sound.hxx,v 1.4 2002-11-13 16:19:20 stephena Exp $
@version $Id: Sound.hxx,v 1.5 2003-02-25 03:12:55 stephena Exp $
*/
class Sound
{
@ -65,11 +65,12 @@ class Sound
/**
Sets the volume of the sound device to the specified level. The
volume is given as a precentage from 0 to 100.
volume is given as a percentage from 0 to 100. A -1 indicates
that the volume shouldn't be changed at all.
@param volume The new volume for the sound device
@param percent The new volume percentage level for the sound device
*/
virtual void setSoundVolume(uInt32 volume);
virtual void setSoundVolume(Int32 percent);
/**
Update the sound device using the audio sample from the specified

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: Settings.cxx,v 1.8 2002-12-01 17:06:18 stephena Exp $
// $Id: Settings.cxx,v 1.9 2003-02-25 03:12:55 stephena Exp $
//============================================================================
#ifdef DEVELOPER_SUPPORT
@ -33,7 +33,7 @@ Settings::Settings()
theUsePrivateColormapFlag = false;
theMultipleSnapShotFlag = true;
theAccurateTimingFlag = true;
theDesiredVolume = 75;
theDesiredVolume = -1;
theDesiredFrameRate = 60;
thePaddleMode = 0;
theAlternateProFile = "";
@ -163,9 +163,9 @@ bool Settings::handleCommandLineArgs(int argc, char* argv[])
{
// They're setting the desired volume
Int32 volume = atoi(argv[++i]);
if(volume < 0)
volume = 0;
if(volume > 100)
if(volume < -1)
volume = -1;
else if(volume > 100)
volume = 100;
theDesiredVolume = volume;
@ -369,10 +369,10 @@ void Settings::handleRCFile(istream& in)
else if(key == "volume")
{
// They're setting the desired volume
uInt32 volume = atoi(value.c_str());
if(volume < 0)
volume = 0;
if(volume > 100)
Int32 volume = atoi(value.c_str());
if(volume < -1)
volume = -1;
else if(volume > 100)
volume = 100;
theDesiredVolume = volume;

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: Settings.hxx,v 1.6 2002-11-13 16:19:20 stephena Exp $
// $Id: Settings.hxx,v 1.7 2003-02-25 03:12:55 stephena Exp $
//============================================================================
#ifndef SETTINGS_HXX
@ -62,7 +62,7 @@ class Settings
bool theAccurateTimingFlag;
// Indicates what the desired volume is
uInt32 theDesiredVolume;
Int32 theDesiredVolume;
// Indicates what the desired frame rate is
uInt32 theDesiredFrameRate;

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: SoundALSA.cxx,v 1.2 2002-12-05 16:43:57 stephena Exp $
// $Id: SoundALSA.cxx,v 1.3 2003-02-25 03:12:55 stephena Exp $
//============================================================================
#include <alsa/asoundlib.h>
@ -215,27 +215,25 @@ bool SoundALSA::isSuccessfullyInitialized() const
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void SoundALSA::setSoundVolume(uInt32 volume)
void SoundALSA::setSoundVolume(Int32 percent)
{
if(myIsInitializedFlag && myMixerElem)
{
if(volume < 0)
if((percent >= 0) && (percent <= 100))
{
volume = 0;
long int lowerBound, upperBound, newVolume;
snd_mixer_selem_get_playback_volume_range(myMixerElem, &lowerBound, &upperBound);
newVolume = (long int) (((upperBound - lowerBound) * percent / 100.0) + lowerBound);
snd_mixer_selem_set_playback_volume(myMixerElem, (_snd_mixer_selem_channel_id) 0,
newVolume);
snd_mixer_selem_set_playback_volume(myMixerElem, (_snd_mixer_selem_channel_id) 1,
newVolume);
}
if(volume > 100)
else if(percent == -1) // If -1 has been specified, play sound at default volume
{
volume = 100;
myOriginalVolumeRight = myOriginalVolumeRight = -1;
}
long int lowerBound, upperBound, newVolume;
snd_mixer_selem_get_playback_volume_range(myMixerElem, &lowerBound, &upperBound);
newVolume = (long int) (((upperBound - lowerBound) * volume / 100.0) + lowerBound);
snd_mixer_selem_set_playback_volume(myMixerElem, (_snd_mixer_selem_channel_id) 0,
newVolume);
snd_mixer_selem_set_playback_volume(myMixerElem, (_snd_mixer_selem_channel_id) 1,
newVolume);
}
}

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: SoundALSA.hxx,v 1.2 2002-12-05 16:43:57 stephena Exp $
// $Id: SoundALSA.hxx,v 1.3 2003-02-25 03:12:55 stephena Exp $
//============================================================================
#ifndef SOUNDALSA_HXX
@ -30,7 +30,7 @@
Advanced Linux Sound Architecture (ALSA) version 0.9.x API.
@author Stephen Anthony
@version $Id: SoundALSA.hxx,v 1.2 2002-12-05 16:43:57 stephena Exp $
@version $Id: SoundALSA.hxx,v 1.3 2003-02-25 03:12:55 stephena Exp $
*/
class SoundALSA : public Sound
{
@ -67,11 +67,12 @@ class SoundALSA : public Sound
/**
Sets the volume of the sound device to the specified level. The
volume is given as a precentage from 0 to 100.
volume is given as a percentage from 0 to 100. A -1 indicates
that the volume shouldn't be changed at all.
@param volume The new volume for the sound device
@param percent The new volume percentage level for the sound device
*/
void setSoundVolume(uInt32 volume);
void setSoundVolume(Int32 percent);
/**
Update the sound device using the audio sample from the specified

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: SoundOSS.cxx,v 1.1 2002-11-13 16:19:21 stephena Exp $
// $Id: SoundOSS.cxx,v 1.2 2003-02-25 03:12:55 stephena Exp $
//============================================================================
#include <fcntl.h>
@ -171,26 +171,24 @@ bool SoundOSS::isSuccessfullyInitialized() const
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void SoundOSS::setSoundVolume(uInt32 volume)
void SoundOSS::setSoundVolume(Int32 percent)
{
if(myIsInitializedFlag && (myMixerFd != -1))
{
if(volume < 0)
if((percent >= 0) && (percent <= 100))
{
volume = 0;
int v = percent | (percent << 8);
if(ioctl(myMixerFd, MIXER_WRITE(SOUND_MIXER_PCM), &v) == -1)
{
perror(MIXER_DEVICE);
close(myMixerFd);
myMixerFd = -1;
}
}
if(volume > 100)
else if(percent == -1) // If -1 has been specified, play sound at default volume
{
volume = 100;
}
int v = volume | (volume << 8);
if(ioctl(myMixerFd, MIXER_WRITE(SOUND_MIXER_PCM), &v) == -1)
{
perror(MIXER_DEVICE);
close(myMixerFd);
myMixerFd = -1;
}
myOriginalVolume = -1;
}
}
}

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: SoundOSS.hxx,v 1.1 2002-11-13 16:19:21 stephena Exp $
// $Id: SoundOSS.hxx,v 1.2 2003-02-25 03:12:55 stephena Exp $
//============================================================================
#ifndef SOUNDOSS_HXX
@ -28,7 +28,7 @@
Open Sound System (OSS) API.
@author Bradford W. Mott
@version $Id: SoundOSS.hxx,v 1.1 2002-11-13 16:19:21 stephena Exp $
@version $Id: SoundOSS.hxx,v 1.2 2003-02-25 03:12:55 stephena Exp $
*/
class SoundOSS : public Sound
{
@ -65,11 +65,12 @@ class SoundOSS : public Sound
/**
Sets the volume of the sound device to the specified level. The
volume is given as a precentage from 0 to 100.
volume is given as a percentage from 0 to 100. A -1 indicates
that the volume shouldn't be changed at all.
@param volume The new volume for the sound device
@param percent The new volume percentage level for the sound device
*/
void setSoundVolume(uInt32 volume);
void setSoundVolume(Int32 percent);
/**
Update the sound device using the audio sample from the specified

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.1 2002-11-13 16:19:21 stephena Exp $
// $Id: SoundSDL.cxx,v 1.2 2003-02-25 03:12:55 stephena Exp $
//============================================================================
#include <SDL.h>
@ -143,7 +143,7 @@ void SoundSDL::closeDevice()
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void SoundSDL::setSoundVolume(uInt32 percent)
void SoundSDL::setSoundVolume(Int32 percent)
{
if(myIsInitializedFlag)
{
@ -153,6 +153,10 @@ void SoundSDL::setSoundVolume(uInt32 percent)
myCurrentVolume = (uInt32)(((float)percent / 100.0) * SDL_MIX_MAXVOLUME);
SDL_UnlockAudio();
}
else if(percent == -1) // If -1 has been specified, play sound at default volume
{
myCurrentVolume = SDL_MIX_MAXVOLUME;
}
}
}

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.1 2002-11-13 16:19:21 stephena Exp $
// $Id: SoundSDL.hxx,v 1.2 2003-02-25 03:12:55 stephena Exp $
//============================================================================
#ifndef SOUNDSDL_HXX
@ -29,7 +29,7 @@
This class implements the sound API for SDL.
@author Stephen Anthony and Bradford W. Mott
@version $Id: SoundSDL.hxx,v 1.1 2002-11-13 16:19:21 stephena Exp $
@version $Id: SoundSDL.hxx,v 1.2 2003-02-25 03:12:55 stephena Exp $
*/
class SoundSDL : public Sound
{
@ -73,11 +73,12 @@ class SoundSDL : public Sound
/**
Sets the volume of the sound device to the specified level. The
volume is given as a precentage from 0 to 100.
volume is given as a percentage from 0 to 100. A -1 indicates
that the volume shouldn't be changed at all.
@param volume The new volume for the sound device
@param percent The new volume percentage level for the sound device
*/
void setSoundVolume(uInt32 volume);
void setSoundVolume(Int32 percent);
/**
Update the sound device using the audio sample from the specified