Some sound code fixes, adding the following commandline arguments (which

can also be set in the Settings class):

-freq    : sets the sound sample output frequency, defaults to 31400
-tiafreq : sets the sound sample generation frequency, defaults to 31400
-clipvol : boolean which toggles volume clipping, defaults to true

Some fixes to the 'joystick button is an axis' code, so that it actually
works in GUI mode.


git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@938 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
stephena 2006-01-06 00:31:56 +00:00
parent 4388d801e5
commit d5981b3b6e
5 changed files with 103 additions and 70 deletions

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: SoundSDL.cxx,v 1.27 2005-12-17 01:23:07 stephena Exp $ // $Id: SoundSDL.cxx,v 1.28 2006-01-06 00:31:55 stephena Exp $
//============================================================================ //============================================================================
#ifdef SOUND_SUPPORT #ifdef SOUND_SUPPORT
@ -30,21 +30,20 @@
#include "Settings.hxx" #include "Settings.hxx"
#include "System.hxx" #include "System.hxx"
#include "OSystem.hxx" #include "OSystem.hxx"
#include "TIASnd.hxx"
#include "SoundSDL.hxx" #include "SoundSDL.hxx"
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
SoundSDL::SoundSDL(OSystem* osystem) SoundSDL::SoundSDL(OSystem* osystem)
: Sound(osystem), : Sound(osystem),
myIsEnabled(osystem->settings().getBool("sound")), myIsEnabled(osystem->settings().getBool("sound")),
myIsInitializedFlag(false), myIsInitializedFlag(false),
myLastRegisterSetCycle(0), myLastRegisterSetCycle(0),
myDisplayFrameRate(60), myDisplayFrameRate(60),
myNumChannels(1), myNumChannels(1),
myFragmentSizeLogBase2(0), myFragmentSizeLogBase2(0),
myIsMuted(false), myIsMuted(false),
myVolume(100) myVolume(100)
{ {
} }
@ -93,10 +92,12 @@ void SoundSDL::initialize()
else else
{ {
uInt32 fragsize = myOSystem->settings().getInt("fragsize"); uInt32 fragsize = myOSystem->settings().getInt("fragsize");
Int32 frequency = myOSystem->settings().getInt("freq");
Int32 tiafreq = myOSystem->settings().getInt("tiafreq");
SDL_AudioSpec desired; SDL_AudioSpec desired;
#ifndef PSP #ifndef PSP
desired.freq = 31400; desired.freq = frequency;
desired.format = AUDIO_U8; desired.format = AUDIO_U8;
#else #else
desired.freq = 44100; desired.freq = 44100;
@ -141,18 +142,25 @@ void SoundSDL::initialize()
// Now initialize the TIASound object which will actually generate sound // Now initialize the TIASound object which will actually generate sound
myTIASound.outputFrequency(myHardwareSpec.freq); myTIASound.outputFrequency(myHardwareSpec.freq);
myTIASound.tiaFrequency(tiafreq);
myTIASound.channels(myHardwareSpec.channels); myTIASound.channels(myHardwareSpec.channels);
bool clipvol = myOSystem->settings().getBool("clipvol");
myTIASound.clipVolume(clipvol);
// Adjust volume to that defined in settings // Adjust volume to that defined in settings
myVolume = myOSystem->settings().getInt("volume"); myVolume = myOSystem->settings().getInt("volume");
setVolume(myVolume); setVolume(myVolume);
// Show some info // Show some info
if(myOSystem->settings().getBool("showinfo")) if(myOSystem->settings().getBool("showinfo"))
cout << "Sound enabled:" << endl cout << "Sound enabled:" << endl
<< " Volume : " << myVolume << endl << " Volume : " << myVolume << endl
<< " Frag size: " << fragsize << endl << " Frag size : " << fragsize << endl
<< " Channels : " << myNumChannels << endl << endl; << " Frequency : " << myHardwareSpec.freq << endl
<< " TIA Freq. : " << tiafreq << endl
<< " Channels : " << myNumChannels << endl
<< " Clip volume: " << (int)clipvol << endl << endl;
} }
} }
@ -497,11 +505,11 @@ bool SoundSDL::save(Serializer& out)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
SoundSDL::RegWriteQueue::RegWriteQueue(uInt32 capacity) SoundSDL::RegWriteQueue::RegWriteQueue(uInt32 capacity)
: myCapacity(capacity), : myCapacity(capacity),
myBuffer(0), myBuffer(0),
mySize(0), mySize(0),
myHead(0), myHead(0),
myTail(0) myTail(0)
{ {
myBuffer = new RegWrite[myCapacity]; myBuffer = new RegWrite[myCapacity];
} }

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: Settings.cxx,v 1.69 2005-12-24 22:50:52 stephena Exp $ // $Id: Settings.cxx,v 1.70 2006-01-06 00:31:56 stephena Exp $
//============================================================================ //============================================================================
#include <cassert> #include <cassert>
@ -54,7 +54,10 @@ Settings::Settings(OSystem* osystem)
set("sound", "true"); set("sound", "true");
set("fragsize", "512"); set("fragsize", "512");
set("freq", "31400");
set("tiafreq", "31400");
set("volume", "100"); set("volume", "100");
set("clipvol", "true");
set("keymap", ""); set("keymap", "");
set("joymap", ""); set("joymap", "");
@ -228,6 +231,12 @@ void Settings::validate()
i = getInt("volume"); i = getInt("volume");
if(i < 0 || i > 100) if(i < 0 || i > 100)
set("volume", "100"); set("volume", "100");
i = getInt("freq");
if(i < 0 || i > 48000)
set("freq", "31400");
i = getInt("tiafreq");
if(i < 0 || i > 48000)
set("tiafreq", "31400");
#endif #endif
i = getInt("zoom"); i = getInt("zoom");
@ -284,7 +293,10 @@ void Settings::usage()
<< " -sound <1|0> Enable sound generation\n" << " -sound <1|0> Enable sound generation\n"
<< " -channels <1|2> Enable mono or stereo sound\n" << " -channels <1|2> Enable mono or stereo sound\n"
<< " -fragsize <number> The size of sound fragments (must be a power of two)\n" << " -fragsize <number> The size of sound fragments (must be a power of two)\n"
<< " -freq <number> Set sound sample output frequency (0 - 48000)\n"
<< " -tiafreq <number> Set sound sample generation frequency (0 - 48000)\n"
<< " -volume <number> Set the volume (0 - 100)\n" << " -volume <number> Set the volume (0 - 100)\n"
<< " -clipvol <1|0> Enable volume clipping (eliminates popping)\n"
<< endl << endl
#endif #endif
<< " -paddle <0|1|2|3> Indicates which paddle the mouse should emulate\n" << " -paddle <0|1|2|3> Indicates which paddle the mouse should emulate\n"

View File

@ -13,18 +13,20 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: TIASnd.cxx,v 1.3 2005-10-09 17:31:47 stephena Exp $ // $Id: TIASnd.cxx,v 1.4 2006-01-06 00:31:56 stephena Exp $
//============================================================================ //============================================================================
#include "System.hxx" #include "System.hxx"
#include "TIASnd.hxx" #include "TIASnd.hxx"
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
TIASound::TIASound(Int32 outputFrequency, uInt32 channels) TIASound::TIASound(Int32 outputFrequency, Int32 tiaFrequency, uInt32 channels)
: myOutputFrequency(outputFrequency), : myOutputFrequency(outputFrequency),
myChannels(channels), myTIAFrequency(tiaFrequency),
myOutputCounter(0), myChannels(channels),
myVolumePercentage(100) myOutputCounter(0),
myVolumePercentage(100),
myVolumeClip(128)
{ {
reset(); reset();
} }
@ -45,18 +47,27 @@ void TIASound::reset()
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void TIASound::outputFrequency(uInt32 freq) void TIASound::outputFrequency(Int32 freq)
{ {
myOutputFrequency = freq; myOutputFrequency = freq;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void TIASound::tiaFrequency(Int32 freq)
{
myTIAFrequency = freq;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void TIASound::channels(uInt32 number) void TIASound::channels(uInt32 number)
{ {
if(number == 2) myChannels = number == 2 ? 2 : 1;
myChannels = 2; }
else
myChannels = 1; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void TIASound::clipVolume(bool clip)
{
myVolumeClip = clip ? 128 : 0;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -127,9 +138,7 @@ uInt8 TIASound::get(uInt16 address)
void TIASound::volume(uInt32 percent) void TIASound::volume(uInt32 percent)
{ {
if((percent >= 0) && (percent <= 100)) if((percent >= 0) && (percent <= 100))
{
myVolumePercentage = percent; myVolumePercentage = percent;
}
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -350,27 +359,24 @@ void TIASound::process(uInt8* buffer, uInt32 samples)
if(myChannels == 1) if(myChannels == 1)
{ {
// Handle mono sample generation // Handle mono sample generation
while((samples > 0) && (myOutputCounter >= TIASoundFrequency)) while((samples > 0) && (myOutputCounter >= myTIAFrequency))
{ {
*(buffer++) = (((myP4[0] & 8) ? v0 : 0) + *(buffer++) = (((myP4[0] & 8) ? v0 : 0) +
((myP4[1] & 8) ? v1 : 0)) + 128; ((myP4[1] & 8) ? v1 : 0)) + myVolumeClip;
myOutputCounter -= TIASoundFrequency; myOutputCounter -= myTIAFrequency;
samples--; samples--;
} }
} }
else else
{ {
// Handle stereo sample generation // Handle stereo sample generation
while((samples > 0) && (myOutputCounter >= TIASoundFrequency)) while((samples > 0) && (myOutputCounter >= myTIAFrequency))
{ {
*(buffer++) = ((myP4[0] & 8) ? v0 : 0) + 128; *(buffer++) = ((myP4[0] & 8) ? v0 : 0) + myVolumeClip;
*(buffer++) = ((myP4[1] & 8) ? v1 : 0) + 128; *(buffer++) = ((myP4[1] & 8) ? v1 : 0) + myVolumeClip;
myOutputCounter -= TIASoundFrequency; myOutputCounter -= myTIAFrequency;
samples--; samples--;
} }
} }
} }
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
const int TIASound::TIASoundFrequency = 31400;

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: TIASnd.hxx,v 1.3 2005-10-09 17:31:47 stephena Exp $ // $Id: TIASnd.hxx,v 1.4 2006-01-06 00:31:56 stephena Exp $
//============================================================================ //============================================================================
#ifndef TIASOUND_HXX #ifndef TIASOUND_HXX
@ -26,18 +26,16 @@
hardware. hardware.
@author Bradford W. Mott @author Bradford W. Mott
@version $Id: TIASnd.hxx,v 1.3 2005-10-09 17:31:47 stephena Exp $ @version $Id: TIASnd.hxx,v 1.4 2006-01-06 00:31:56 stephena Exp $
*/ */
class TIASound class TIASound
{ {
public:
static const int TIASoundFrequency;
public: public:
/** /**
Create a new TIA Sound object using the specified output frequency Create a new TIA Sound object using the specified output frequency
*/ */
TIASound(Int32 outputFrequency = TIASoundFrequency, uInt32 channels = 1); TIASound(Int32 outputFrequency = 31400, Int32 tiaFrequency = 31400,
uInt32 channels = 1);
/** /**
Destructor Destructor
@ -53,13 +51,23 @@ class TIASound
/** /**
Set the frequency output samples should be generated at Set the frequency output samples should be generated at
*/ */
void outputFrequency(uInt32 freq); void outputFrequency(Int32 freq);
/**
Set the frequency the of the TIA device
*/
void tiaFrequency(Int32 freq);
/** /**
Selects the number of audio channels per sample (1 = mono, 2 = stereo) Selects the number of audio channels per sample (1 = mono, 2 = stereo)
*/ */
void channels(uInt32 number); void channels(uInt32 number);
/**
Set volume clipping (decrease volume range by half to eliminate popping)
*/
void clipVolume(bool clip);
public: public:
/** /**
Sets the specified sound register to the given value Sets the specified sound register to the given value
@ -134,9 +142,11 @@ class TIASound
uInt8 myP5[2]; // 5-bit register LFSR (lower 5 bits used) uInt8 myP5[2]; // 5-bit register LFSR (lower 5 bits used)
Int32 myOutputFrequency; Int32 myOutputFrequency;
Int32 myTIAFrequency;
uInt32 myChannels; uInt32 myChannels;
Int32 myOutputCounter; Int32 myOutputCounter;
uInt32 myVolumePercentage; uInt32 myVolumePercentage;
uInt8 myVolumeClip;
}; };
#endif #endif

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: DialogContainer.cxx,v 1.24 2006-01-05 18:53:23 stephena Exp $ // $Id: DialogContainer.cxx,v 1.25 2006-01-06 00:31:56 stephena Exp $
//============================================================================ //============================================================================
#include "OSystem.hxx" #include "OSystem.hxx"
@ -274,7 +274,20 @@ void DialogContainer::handleJoyEvent(int stick, int button, uInt8 state)
// Send the event to the dialog box on the top of the stack // Send the event to the dialog box on the top of the stack
Dialog* activeDialog = myDialogStack.top(); Dialog* activeDialog = myDialogStack.top();
if(activeDialog->wantsEvents()) // Some buttons act as directions. In those cases, translate them
// to axis events instead of mouse button events
int up, down, left, right = -1;
int value = state > 0 ? 32767 : 0;
myOSystem->getJoyButtonDirections(up, down, left, right);
if(button == up)
handleJoyAxisEvent(stick, 1, -value); // axis 1, -value ==> UP
else if(button == down)
handleJoyAxisEvent(stick, 1, value); // axis 1, +value ==> DOWN
else if(button == left)
handleJoyAxisEvent(stick, 0, -value); // axis 0, -value ==> LEFT
else if(button == right)
handleJoyAxisEvent(stick, 0, value); // axis 0, +value ==> RIGHT
else if(activeDialog->wantsEvents())
{ {
if(state == 1) if(state == 1)
activeDialog->handleJoyDown(stick, button); activeDialog->handleJoyDown(stick, button);
@ -282,24 +295,8 @@ void DialogContainer::handleJoyEvent(int stick, int button, uInt8 state)
activeDialog->handleJoyUp(stick, button); activeDialog->handleJoyUp(stick, button);
} }
else else
{
// Some buttons act as directions. In those cases, translate them
// to axis events instead of mouse button events
int up, down, left, right = -1;
int value = state > 0 ? 32767 : 0;
myOSystem->getJoyButtonDirections(up, down, left, right);
if(button == up)
handleJoyAxisEvent(stick, 1, value); // axis 1, +value ==> UP
else if(button == down)
handleJoyAxisEvent(stick, 1, -value); // axis 1, -value ==> DOWN
else if(button == left)
handleJoyAxisEvent(stick, 0, value); // axis 0, +value ==> LEFT
else if(button == right)
handleJoyAxisEvent(stick, 0, -value); // axis 0, -value ==> RIGHT
else
myOSystem->eventHandler().createMouseButtonEvent( myOSystem->eventHandler().createMouseButtonEvent(
ourJoyMouse.x, ourJoyMouse.y, state); ourJoyMouse.x, ourJoyMouse.y, state);
}
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -