mirror of https://github.com/stella-emu/stella.git
fixed interrupted WAV continuing to play at restart
This commit is contained in:
parent
077366f34b
commit
af5272cff4
|
@ -441,7 +441,26 @@ bool SoundSDL2::playWav(const string& fileName, const uInt32 position,
|
||||||
myWavLen = length
|
myWavLen = length
|
||||||
? std::min(length, myWavLength - position)
|
? std::min(length, myWavLength - position)
|
||||||
: myWavLength;
|
: myWavLength;
|
||||||
|
#ifndef RESAMPLE_WAV
|
||||||
myWavPos = myWavBuffer + position;
|
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
|
// Open audio device
|
||||||
if(!myWavDevice)
|
if(!myWavDevice)
|
||||||
|
|
|
@ -20,6 +20,8 @@
|
||||||
#ifndef SOUND_SDL2_HXX
|
#ifndef SOUND_SDL2_HXX
|
||||||
#define SOUND_SDL2_HXX
|
#define SOUND_SDL2_HXX
|
||||||
|
|
||||||
|
//#define RESAMPLE_WAV
|
||||||
|
|
||||||
class OSystem;
|
class OSystem;
|
||||||
class AudioQueue;
|
class AudioQueue;
|
||||||
class EmulationTiming;
|
class EmulationTiming;
|
||||||
|
@ -192,6 +194,9 @@ class SoundSDL2 : public Sound
|
||||||
uInt32 myWavLength{0};
|
uInt32 myWavLength{0};
|
||||||
SDL_AudioDeviceID myWavDevice{0};
|
SDL_AudioDeviceID myWavDevice{0};
|
||||||
uInt8* myWavBuffer{nullptr};
|
uInt8* myWavBuffer{nullptr};
|
||||||
|
#ifdef RESAMPLE_WAV
|
||||||
|
SDL_AudioCVT myCvt{0};
|
||||||
|
#endif
|
||||||
|
|
||||||
static float myWavVolumeFactor;
|
static float myWavVolumeFactor;
|
||||||
static SDL_AudioSpec myWavSpec; // audio output format
|
static SDL_AudioSpec myWavSpec; // audio output format
|
||||||
|
|
|
@ -253,6 +253,7 @@ Console::~Console()
|
||||||
// Close audio to prevent invalid access to myConsoleTiming from the audio
|
// Close audio to prevent invalid access to myConsoleTiming from the audio
|
||||||
// callback
|
// callback
|
||||||
myOSystem.sound().close();
|
myOSystem.sound().close();
|
||||||
|
myOSystem.sound().stopWav();
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
|
Loading…
Reference in New Issue