mirror of https://github.com/stella-emu/stella.git
fixed interrupted WAV continuing to play at restart
This commit is contained in:
parent
c53e0eabcb
commit
067cf7e021
|
@ -441,7 +441,26 @@ bool SoundSDL2::playWav(const string& fileName, const uInt32 position,
|
|||
myWavLen = length
|
||||
? std::min(length, myWavLength - position)
|
||||
: myWavLength;
|
||||
#ifndef RESAMPLE_WAV
|
||||
myWavPos = myWavBuffer + position;
|
||||
#else
|
||||
SDL_free(myCvt.buf);
|
||||
|
||||
//const double speed = BSPF::clamp(262 * 60 * 2. / myEmulationTiming->audioSampleRate(), 0.5, 2.0);
|
||||
const double speed = 262 * 60 * 2. / myEmulationTiming->audioSampleRate();
|
||||
|
||||
SDL_BuildAudioCVT(&myCvt, myWavSpec.format, myWavSpec.channels, myWavSpec.freq,
|
||||
myWavSpec.format, myWavSpec.channels, myWavSpec.freq * speed);
|
||||
SDL_assert(myCvt.needed); // Obviously, this one is always needed.
|
||||
myCvt.len = myWavLen * myWavSpec.channels; // Mono 8 bit sample frames
|
||||
myCvt.buf = (uInt8*)SDL_malloc(myCvt.len * myCvt.len_mult * 2); // Double buffer size to avoid memory access exception
|
||||
// Read original data into conversion buffer
|
||||
SDL_memcpy(myCvt.buf, myWavBuffer + position, myCvt.len);
|
||||
SDL_ConvertAudio(&myCvt);
|
||||
|
||||
myWavPos = myCvt.buf;
|
||||
myWavLen = myCvt.len_cvt;
|
||||
#endif
|
||||
|
||||
// Open audio device
|
||||
if(!myWavDevice)
|
||||
|
|
|
@ -20,6 +20,8 @@
|
|||
#ifndef SOUND_SDL2_HXX
|
||||
#define SOUND_SDL2_HXX
|
||||
|
||||
//#define RESAMPLE_WAV
|
||||
|
||||
class OSystem;
|
||||
class AudioQueue;
|
||||
class EmulationTiming;
|
||||
|
@ -192,6 +194,9 @@ class SoundSDL2 : public Sound
|
|||
uInt32 myWavLength{0};
|
||||
SDL_AudioDeviceID myWavDevice{0};
|
||||
uInt8* myWavBuffer{nullptr};
|
||||
#ifdef RESAMPLE_WAV
|
||||
SDL_AudioCVT myCvt{0};
|
||||
#endif
|
||||
|
||||
static float myWavVolumeFactor;
|
||||
static SDL_AudioSpec myWavSpec; // audio output format
|
||||
|
|
|
@ -253,6 +253,7 @@ Console::~Console()
|
|||
// Close audio to prevent invalid access to myConsoleTiming from the audio
|
||||
// callback
|
||||
myOSystem.sound().close();
|
||||
myOSystem.sound().stopWav();
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
|
Loading…
Reference in New Issue