mirror of https://github.com/stella-emu/stella.git
Some fixes to the latest SDL sound code. Sounds seem to keep better
sync with the video updates in this version. git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@116 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
parent
1810444904
commit
88b0994efb
|
@ -13,15 +13,15 @@
|
||||||
// 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.1 2002-10-11 13:07:00 stephena Exp $
|
// $Id: SoundSDL.cxx,v 1.2 2002-10-12 15:24:49 stephena Exp $
|
||||||
//============================================================================
|
//============================================================================
|
||||||
|
|
||||||
#include <SDL.h>
|
#include <SDL.h>
|
||||||
|
|
||||||
#include "SoundSDL.hxx"
|
#include "SoundSDL.hxx"
|
||||||
|
|
||||||
static uInt8 currentVolume;
|
static uInt8 _myCurrentVolume;
|
||||||
static MediaSource* _mediaSource;
|
static MediaSource* _myMediaSource;
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
SoundSDL::SoundSDL(bool activate)
|
SoundSDL::SoundSDL(bool activate)
|
||||||
|
@ -64,8 +64,8 @@ SoundSDL::SoundSDL(bool activate)
|
||||||
mySampleRate = obtained.freq;
|
mySampleRate = obtained.freq;
|
||||||
|
|
||||||
// Take care of the static stuff ...
|
// Take care of the static stuff ...
|
||||||
currentVolume = 0;
|
_myCurrentVolume = 0;
|
||||||
_mediaSource = (MediaSource*) NULL;
|
_myMediaSource = (MediaSource*) NULL;
|
||||||
|
|
||||||
SDL_PauseAudio(0);
|
SDL_PauseAudio(0);
|
||||||
}
|
}
|
||||||
|
@ -73,6 +73,7 @@ SoundSDL::SoundSDL(bool activate)
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
SoundSDL::~SoundSDL()
|
SoundSDL::~SoundSDL()
|
||||||
{
|
{
|
||||||
|
close();
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
@ -105,8 +106,6 @@ void SoundSDL::mute(bool state)
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
void SoundSDL::close()
|
void SoundSDL::close()
|
||||||
{
|
{
|
||||||
SDL_PauseAudio(0);
|
|
||||||
|
|
||||||
if(myIsInitializedFlag)
|
if(myIsInitializedFlag)
|
||||||
SDL_CloseAudio();
|
SDL_CloseAudio();
|
||||||
|
|
||||||
|
@ -120,28 +119,26 @@ void SoundSDL::setSoundVolume(uInt32 percent)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if((percent >= 0) && (percent <= 100))
|
if((percent >= 0) && (percent <= 100))
|
||||||
currentVolume = (int) (((float) percent / 100.0) * (float) SDL_MIX_MAXVOLUME);
|
_myCurrentVolume = (int) (((float) percent / 100.0) * (float) SDL_MIX_MAXVOLUME);
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
void SoundSDL::updateSound(MediaSource& mediaSource)
|
void SoundSDL::setMediaSource(MediaSource& mediaSource)
|
||||||
{
|
{
|
||||||
// this is a HUGE HACK and will disappear soon
|
_myMediaSource = &mediaSource;
|
||||||
_mediaSource = &mediaSource;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
void SoundSDL::fillAudio(void* udata, uInt8* stream, Int32 len)
|
void SoundSDL::fillAudio(void* udata, uInt8* stream, Int32 len)
|
||||||
{
|
{
|
||||||
if(!_mediaSource)
|
if(!_myMediaSource)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
uInt32 samples = _mediaSource->numberOfAudioSamples();
|
// Dequeue samples as long as full fragments are available
|
||||||
if(samples == 0)
|
if(_myMediaSource->numberOfAudioSamples() >= (uInt32) len)
|
||||||
return;
|
{
|
||||||
|
uInt8 buffer[len];
|
||||||
uInt8 buffer[len];
|
_myMediaSource->dequeueAudioSamples(buffer, (uInt32)len);
|
||||||
_mediaSource->dequeueAudioSamples(buffer, len);
|
SDL_MixAudio(stream, buffer, len, _myCurrentVolume);
|
||||||
|
}
|
||||||
SDL_MixAudio(stream, buffer, len, currentVolume);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.hxx,v 1.1 2002-10-11 13:07:01 stephena Exp $
|
// $Id: SoundSDL.hxx,v 1.2 2002-10-12 15:24:49 stephena Exp $
|
||||||
//============================================================================
|
//============================================================================
|
||||||
|
|
||||||
#ifndef SOUNDSDL_HXX
|
#ifndef SOUNDSDL_HXX
|
||||||
|
@ -28,7 +28,7 @@
|
||||||
This class implements the sound API for SDL.
|
This class implements the sound API for SDL.
|
||||||
|
|
||||||
@author Stephen Anthony
|
@author Stephen Anthony
|
||||||
@version $Id: SoundSDL.hxx,v 1.1 2002-10-11 13:07:01 stephena Exp $
|
@version $Id: SoundSDL.hxx,v 1.2 2002-10-12 15:24:49 stephena Exp $
|
||||||
*/
|
*/
|
||||||
class SoundSDL
|
class SoundSDL
|
||||||
{
|
{
|
||||||
|
@ -52,9 +52,9 @@ class SoundSDL
|
||||||
uInt32 getSampleRate() const;
|
uInt32 getSampleRate() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Return true iff the sound device was successfully initlaized.
|
Return true iff the sound device was successfully initialized.
|
||||||
|
|
||||||
@return true iff the sound device was successfully initlaized.
|
@return true iff the sound device was successfully initialized
|
||||||
*/
|
*/
|
||||||
bool isSuccessfullyInitialized() const;
|
bool isSuccessfullyInitialized() const;
|
||||||
|
|
||||||
|
@ -67,25 +67,27 @@ class SoundSDL
|
||||||
void setSoundVolume(uInt32 volume);
|
void setSoundVolume(uInt32 volume);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Update the sound device using the audio sample from the specified
|
Notifies this class of the MediaSource object where sample data
|
||||||
media source.
|
may be obtained. The SDL sound api is thread-based, so the SDL
|
||||||
|
audio callback directly queries the MediaSource when it requires
|
||||||
|
more audio samples.
|
||||||
|
|
||||||
@param mediaSource The media source to get audio samples from.
|
@param mediaSource The MediaSource where sample data is obtained
|
||||||
*/
|
*/
|
||||||
void updateSound(MediaSource& mediaSource);
|
void setMediaSource(MediaSource& mediaSource);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Closes the soudn device
|
Set the mute state of the sound object.
|
||||||
*/
|
|
||||||
void close();
|
|
||||||
|
|
||||||
/**
|
@param state Mutes sound if true, unmute if false
|
||||||
Set the mute state of the sound object
|
|
||||||
|
|
||||||
@param state Mutes sound iff true
|
|
||||||
*/
|
*/
|
||||||
void mute(bool state);
|
void mute(bool state);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Closes the sound device
|
||||||
|
*/
|
||||||
|
void close();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Indicates if the sound device was successfully initialized
|
// Indicates if the sound device was successfully initialized
|
||||||
bool myIsInitializedFlag;
|
bool myIsInitializedFlag;
|
||||||
|
@ -99,12 +101,11 @@ class SoundSDL
|
||||||
// Indicates if the sound is currently muted
|
// Indicates if the sound is currently muted
|
||||||
bool myIsMuted;
|
bool myIsMuted;
|
||||||
|
|
||||||
/**
|
|
||||||
Some stuff which is required to be static since the SDL audio
|
|
||||||
callback is a C-style function.
|
|
||||||
*/
|
|
||||||
private:
|
private:
|
||||||
|
/**
|
||||||
|
The callback used by the SDL sound API. It obtains samples
|
||||||
|
from the MediaSource as it needs them.
|
||||||
|
*/
|
||||||
static void fillAudio(void* udata, uInt8* stream, Int32 len);
|
static void fillAudio(void* udata, uInt8* stream, Int32 len);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -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: mainSDL.cxx,v 1.30 2002-10-11 13:07:01 stephena Exp $
|
// $Id: mainSDL.cxx,v 1.31 2002-10-12 15:24:49 stephena Exp $
|
||||||
//============================================================================
|
//============================================================================
|
||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
@ -587,7 +587,7 @@ void togglePause()
|
||||||
thePauseIndicator = true;
|
thePauseIndicator = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pause the console
|
// Pause the console and the audio
|
||||||
theConsole->mediaSource().pause(thePauseIndicator);
|
theConsole->mediaSource().pause(thePauseIndicator);
|
||||||
|
|
||||||
// Show a different palette depending on pause state
|
// Show a different palette depending on pause state
|
||||||
|
@ -1573,6 +1573,10 @@ int main(int argc, char* argv[])
|
||||||
theConsole = new Console(image, size, filename,
|
theConsole = new Console(image, size, filename,
|
||||||
theEvent, propertiesSet, sound.getSampleRate());
|
theEvent, propertiesSet, sound.getSampleRate());
|
||||||
|
|
||||||
|
// Let the sound object know about the MediaSource.
|
||||||
|
// The sound object takes care of getting samples from the MediaSource.
|
||||||
|
sound.setMediaSource(theConsole->mediaSource());
|
||||||
|
|
||||||
// Free the image since we don't need it any longer
|
// Free the image since we don't need it any longer
|
||||||
delete[] image;
|
delete[] image;
|
||||||
|
|
||||||
|
@ -1625,7 +1629,6 @@ int main(int argc, char* argv[])
|
||||||
|
|
||||||
startTime = getTicks();
|
startTime = getTicks();
|
||||||
theConsole->mediaSource().update();
|
theConsole->mediaSource().update();
|
||||||
sound.updateSound(theConsole->mediaSource());
|
|
||||||
updateDisplay(theConsole->mediaSource());
|
updateDisplay(theConsole->mediaSource());
|
||||||
handleEvents();
|
handleEvents();
|
||||||
|
|
||||||
|
@ -1665,7 +1668,6 @@ int main(int argc, char* argv[])
|
||||||
if(!thePauseIndicator)
|
if(!thePauseIndicator)
|
||||||
{
|
{
|
||||||
theConsole->mediaSource().update();
|
theConsole->mediaSource().update();
|
||||||
sound.updateSound(theConsole->mediaSource());
|
|
||||||
}
|
}
|
||||||
updateDisplay(theConsole->mediaSource());
|
updateDisplay(theConsole->mediaSource());
|
||||||
handleEvents();
|
handleEvents();
|
||||||
|
|
Loading…
Reference in New Issue