mirror of https://github.com/stella-emu/stella.git
- Added support for digital sound again. It didn't work as well as I
would have liked in the 1.3 release, and it still doesn't. The background music in Pitfall2 is there, but it's scratchy. And in Quadrun, you only hear one 'quadrun' instead of 'quadrun, quadrun, quadrun'. - For now, you can disable/enable it by (un)-commenting the line '#define DIGITAL_SOUND' near the top of the SoundSDL.cxx file. - For those of you that care, here's the problem: Previously, the correct number of sound samples were created and the audio system had delays inserted to account for it. Problem was, the delays were causing 'jumps' in the video rendering, since the sound code was delaying every frame. Now, the audio system only takes as many samples as is needed. This eliminates the audio/video sync problems, since there are no delays at all. But the problem now is that if more samples are generated than the audio system requires, some are lost and/or overwritten. I do place them in a queue, but the samples are being generated faster than they're being removed. So things don't sound quite right. - At least that's what I think. We need some way to combine both approaches, so that the audio system only gets as many samples as it needs, but in *those* samples, all the sound information up to that point must be present. I guess the samples will have to be mixed, or something. - If anyone has ANY suggestions at all, they would be greatly appreciated. - And for anyone who doesn't have a clue what I'm talking about, let me say I really &&%*(&* hate sound programming. git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@240 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
parent
87277a770f
commit
6c3b06d19e
|
@ -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: Console.cxx,v 1.25 2004-04-20 21:07:40 stephena Exp $
|
||||
// $Id: Console.cxx,v 1.26 2004-04-26 17:27:31 stephena Exp $
|
||||
//============================================================================
|
||||
|
||||
#include <assert.h>
|
||||
|
@ -174,7 +174,7 @@ Console::Console(const uInt8* image, uInt32 size, const char* filename,
|
|||
myFrameBuffer.initDisplay(this, myMediaSource);
|
||||
|
||||
// Initialize the sound interface.
|
||||
mySound.init(this, myMediaSource);
|
||||
mySound.init(this, myMediaSource, mySystem);
|
||||
|
||||
#ifdef SNAPSHOT_SUPPORT
|
||||
// Create a snapshot object which will handle taking snapshots
|
||||
|
|
|
@ -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.cxx,v 1.9 2004-04-04 02:03:15 stephena Exp $
|
||||
// $Id: Sound.cxx,v 1.10 2004-04-26 17:27:31 stephena Exp $
|
||||
//============================================================================
|
||||
|
||||
#include "Serializer.hxx"
|
||||
|
@ -23,7 +23,8 @@
|
|||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Sound::Sound(uInt32 fragsize, uInt32 queuesize)
|
||||
: myPauseStatus(false)
|
||||
: myPauseStatus(false),
|
||||
myLastSoundUpdateCycle(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -33,10 +34,11 @@ Sound::~Sound()
|
|||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
void Sound::init(Console* console, MediaSource* mediasrc)
|
||||
void Sound::init(Console* console, MediaSource* mediasrc, System* system)
|
||||
{
|
||||
myConsole = console;
|
||||
myMediaSource = mediasrc;
|
||||
mySystem = system;
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
|
|
@ -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.9 2004-04-04 02:03:15 stephena Exp $
|
||||
// $Id: Sound.hxx,v 1.10 2004-04-26 17:27:31 stephena Exp $
|
||||
//============================================================================
|
||||
|
||||
#ifndef SOUND_HXX
|
||||
|
@ -23,6 +23,7 @@ class Console;
|
|||
class MediaSource;
|
||||
class Serializer;
|
||||
class Deserializer;
|
||||
class System;
|
||||
|
||||
#include "bspf.hxx"
|
||||
|
||||
|
@ -32,7 +33,7 @@ class Deserializer;
|
|||
to compile Stella with no sound support whatsoever.
|
||||
|
||||
@author Stephen Anthony
|
||||
@version $Id: Sound.hxx,v 1.9 2004-04-04 02:03:15 stephena Exp $
|
||||
@version $Id: Sound.hxx,v 1.10 2004-04-26 17:27:31 stephena Exp $
|
||||
*/
|
||||
class Sound
|
||||
{
|
||||
|
@ -54,8 +55,9 @@ class Sound
|
|||
|
||||
@param console The console
|
||||
@param mediasrc The mediasource
|
||||
@param system The system
|
||||
*/
|
||||
void init(Console* console, MediaSource* mediasrc);
|
||||
void init(Console* console, MediaSource* mediasrc, System* system);
|
||||
|
||||
/**
|
||||
Return true iff the sound device was successfully initialized.
|
||||
|
@ -110,6 +112,16 @@ class Sound
|
|||
*/
|
||||
void pause(bool status) { myPauseStatus = status; }
|
||||
|
||||
/**
|
||||
Resets the sound device.
|
||||
*/
|
||||
void reset() { myLastSoundUpdateCycle = 0; }
|
||||
|
||||
/**
|
||||
Resets the sound device.
|
||||
*/
|
||||
void setCycles(Int32 cycles) { myLastSoundUpdateCycle += cycles; }
|
||||
|
||||
protected:
|
||||
// The Console for the system
|
||||
Console* myConsole;
|
||||
|
@ -117,8 +129,14 @@ class Sound
|
|||
// The Mediasource for the system
|
||||
MediaSource* myMediaSource;
|
||||
|
||||
// The System for the system
|
||||
System* mySystem;
|
||||
|
||||
// The pause status
|
||||
bool myPauseStatus;
|
||||
|
||||
// Indicates the CPU cycle when a TIA sound register was last updated
|
||||
Int32 myLastSoundUpdateCycle;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -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: TIA.cxx,v 1.30 2004-04-21 16:27:30 stephena Exp $
|
||||
// $Id: TIA.cxx,v 1.31 2004-04-26 17:27:31 stephena Exp $
|
||||
//============================================================================
|
||||
|
||||
#include <cassert>
|
||||
|
@ -37,7 +37,6 @@
|
|||
TIA::TIA(const Console& console, Sound& sound)
|
||||
: myConsole(console),
|
||||
mySound(sound),
|
||||
myLastSoundUpdateCycle(0), // FIXME this may disappear
|
||||
myColorLossEnabled(false),
|
||||
myCOLUBK(myColor[0]),
|
||||
myCOLUPF(myColor[1]),
|
||||
|
@ -116,8 +115,8 @@ const char* TIA::name() const
|
|||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
void TIA::reset()
|
||||
{
|
||||
// Reset sound cycle indicator
|
||||
myLastSoundUpdateCycle = 0;
|
||||
// Reset the sound device
|
||||
mySound.reset();
|
||||
|
||||
// Clear frame buffers
|
||||
for(uInt32 i = 0; i < 160 * 300; ++i)
|
||||
|
@ -237,7 +236,7 @@ void TIA::systemCyclesReset()
|
|||
uInt32 cycles = mySystem->cycles();
|
||||
|
||||
// Adjust the sound cycle indicator
|
||||
myLastSoundUpdateCycle -= cycles;
|
||||
mySound.setCycles(-cycles);
|
||||
|
||||
// Adjust the dump cycle
|
||||
myDumpDisabledCycle -= cycles;
|
||||
|
@ -289,7 +288,7 @@ bool TIA::save(Serializer& out)
|
|||
{
|
||||
out.putString(device);
|
||||
|
||||
out.putLong(myLastSoundUpdateCycle);
|
||||
//FIXME out.putLong(myLastSoundUpdateCycle);
|
||||
out.putLong(myClockWhenFrameStarted);
|
||||
out.putLong(myClockStartDisplay);
|
||||
out.putLong(myClockStopDisplay);
|
||||
|
@ -386,7 +385,7 @@ bool TIA::load(Deserializer& in)
|
|||
if(in.getString() != device)
|
||||
return false;
|
||||
|
||||
myLastSoundUpdateCycle = (Int32) in.getLong();
|
||||
//FIXME myLastSoundUpdateCycle = (Int32) in.getLong();
|
||||
myClockWhenFrameStarted = (Int32) in.getLong();
|
||||
myClockStartDisplay = (Int32) in.getLong();
|
||||
myClockStopDisplay = (Int32) in.getLong();
|
||||
|
|
|
@ -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: TIA.hxx,v 1.12 2004-04-04 02:03:15 stephena Exp $
|
||||
// $Id: TIA.hxx,v 1.13 2004-04-26 17:27:31 stephena Exp $
|
||||
//============================================================================
|
||||
|
||||
#ifndef TIA_HXX
|
||||
|
@ -43,7 +43,7 @@ class Deserializer;
|
|||
be displayed on screen.
|
||||
|
||||
@author Bradford W. Mott
|
||||
@version $Id: TIA.hxx,v 1.12 2004-04-04 02:03:15 stephena Exp $
|
||||
@version $Id: TIA.hxx,v 1.13 2004-04-26 17:27:31 stephena Exp $
|
||||
*/
|
||||
class TIA : public Device , public MediaSource
|
||||
{
|
||||
|
@ -211,9 +211,6 @@ class TIA : public Device , public MediaSource
|
|||
Sound& mySound;
|
||||
|
||||
private:
|
||||
// Indicates the CPU cycle when a TIA sound register was last updated
|
||||
Int32 myLastSoundUpdateCycle;
|
||||
|
||||
// Indicates if color loss should be enabled or disabled. Color loss
|
||||
// occurs on PAL (and maybe SECAM) systems when the previous frame
|
||||
// contains an odd number of scanlines.
|
||||
|
|
|
@ -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.8 2004-04-20 21:08:03 stephena Exp $
|
||||
// $Id: SoundSDL.cxx,v 1.9 2004-04-26 17:27:32 stephena Exp $
|
||||
//============================================================================
|
||||
|
||||
#include <SDL.h>
|
||||
|
@ -21,9 +21,12 @@
|
|||
#include "TIASound.h"
|
||||
#include "Serializer.hxx"
|
||||
#include "Deserializer.hxx"
|
||||
#include "System.hxx"
|
||||
|
||||
#include "SoundSDL.hxx"
|
||||
|
||||
#define DIGITAL_SOUND
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
SoundSDL::SoundSDL(uInt32 fragsize, uInt32 queuesize)
|
||||
: myCurrentVolume(SDL_MIX_MAXVOLUME),
|
||||
|
@ -159,7 +162,7 @@ void SoundSDL::setVolume(Int32 percent)
|
|||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
void SoundSDL::update()
|
||||
{
|
||||
|
||||
#if !defined(DIGITAL_SOUND)
|
||||
if(!myPauseStatus && myIsInitializedFlag)
|
||||
{
|
||||
// Make sure we have exclusive access to the sample queue
|
||||
|
@ -174,12 +177,41 @@ void SoundSDL::update()
|
|||
// Release lock on the sample queue
|
||||
// SDL_UnlockAudio();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
void SoundSDL::set(uInt16 addr, uInt8 value)
|
||||
{
|
||||
#if defined(DIGITAL_SOUND)
|
||||
// Calculate the number of samples that need to be generated based on the
|
||||
// number of CPU cycles which have passed since the last sound update
|
||||
uInt32 samplesToGenerate =
|
||||
(mySampleRate * (mySystem->cycles() - myLastSoundUpdateCycle)) / 1190000;
|
||||
|
||||
// Update counters and create samples if there's one sample to generate
|
||||
// TODO: This doesn't handle rounding quite right (10/08/2002)
|
||||
if(samplesToGenerate >= 1)
|
||||
{
|
||||
uInt8 buffer[1024];
|
||||
|
||||
for(Int32 sg = (Int32)samplesToGenerate; sg > 0; sg -= 1024)
|
||||
{
|
||||
Tia_process(buffer, ((sg >= 1024) ? 1024 : sg));
|
||||
mySampleQueue.enqueue(buffer, ((sg >= 1024) ? 1024 : sg));
|
||||
}
|
||||
|
||||
myLastSoundUpdateCycle = myLastSoundUpdateCycle +
|
||||
((samplesToGenerate * 1190000) / mySampleRate);
|
||||
}
|
||||
|
||||
if(addr != 0)
|
||||
{
|
||||
Update_tia_sound(addr, value);
|
||||
}
|
||||
#else
|
||||
Update_tia_sound(addr, value);
|
||||
#endif
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
|
Loading…
Reference in New Issue