Fixed crash in resampling WAV playing; forgot to create an array.

Make WAV resampling default behaviour.
This commit is contained in:
Stephen Anthony 2022-09-19 01:33:36 -02:30
parent b927f214f3
commit f98fef11db
2 changed files with 7 additions and 16 deletions

View File

@ -175,9 +175,7 @@ void SoundSDL2::open(shared_ptr<AudioQueue> audioQueue,
openDevice();
myEmulationTiming = emulationTiming;
#ifdef RESAMPLE_WAV
myWavSpeed = 262 * 60 * 2. / myEmulationTiming->audioSampleRate();
#endif
Logger::debug("SoundSDL2::open started ...");
mute(true);
@ -493,12 +491,12 @@ void SoundSDL2::wavCallback(void* udata, uInt8* stream, int len)
SDL_memset(stream, myWavSpec.silence, len);
if(myWavLen)
{
#ifdef RESAMPLE_WAV
if(myWavSpeed != 1.0)
{
const int origLen = len;
len = std::round(len / myWavSpeed);
const int newFreq = std::round(static_cast<double>(myWavSpec.freq) * origLen / len);
const int newFreq =
std::round(static_cast<double>(myWavSpec.freq) * origLen / len);
if(static_cast<uInt32>(len) > myWavLen)
len = myWavLen;
@ -513,7 +511,7 @@ void SoundSDL2::wavCallback(void* udata, uInt8* stream, int len)
myWavCvtBufferSize < static_cast<uInt32>(cvt.len * cvt.len_mult))
{
myWavCvtBufferSize = cvt.len * cvt.len_mult;
myWavCvtBuffer = make_unique<uInt8>(myWavCvtBufferSize);
myWavCvtBuffer = make_unique<uInt8[]>(myWavCvtBufferSize);
}
cvt.buf = myWavCvtBuffer.get();
@ -525,7 +523,6 @@ void SoundSDL2::wavCallback(void* udata, uInt8* stream, int len)
SDL_MIX_MAXVOLUME * myWavVolumeFactor);
}
else
#endif
{
if(static_cast<uInt32>(len) > myWavLen)
len = myWavLen;
@ -544,10 +541,8 @@ float SoundSDL2::myWavVolumeFactor = 0xffff;
SDL_AudioSpec SoundSDL2::myWavSpec; // audio output format
uInt8* SoundSDL2::myWavPos = nullptr; // pointer to the audio buffer to be played
uInt32 SoundSDL2::myWavLen = 0; // remaining length of the sample we have to play
#ifdef RESAMPLE_WAV
double SoundSDL2::myWavSpeed = 1.0;
unique_ptr<uInt8> SoundSDL2::myWavCvtBuffer = nullptr;
unique_ptr<uInt8[]> SoundSDL2::myWavCvtBuffer;
uInt32 SoundSDL2::myWavCvtBufferSize = 0;
#endif
#endif // SOUND_SUPPORT

View File

@ -20,8 +20,6 @@
#ifndef SOUND_SDL2_HXX
#define SOUND_SDL2_HXX
#define RESAMPLE_WAV
class OSystem;
class AudioQueue;
class EmulationTiming;
@ -194,12 +192,10 @@ class SoundSDL2 : public Sound
uInt32 myWavLength{0};
SDL_AudioDeviceID myWavDevice{0};
uInt8* myWavBuffer{nullptr};
#ifdef RESAMPLE_WAV
static double myWavSpeed;
static unique_ptr<uInt8> myWavCvtBuffer;
static uInt32 myWavCvtBufferSize;
#endif
static double myWavSpeed;
static unique_ptr<uInt8[]> myWavCvtBuffer;
static uInt32 myWavCvtBufferSize;
static float myWavVolumeFactor;
static SDL_AudioSpec myWavSpec; // audio output format
static uInt8* myWavPos; // pointer to the audio buffer to be played