mirror of https://github.com/stella-emu/stella.git
Use unique_ptr instead of C-style allocations.
This commit is contained in:
parent
79bf02f5e3
commit
3b073054ff
|
@ -476,8 +476,7 @@ void SoundSDL2::stopWav()
|
|||
}
|
||||
if(myWavCvtBuffer)
|
||||
{
|
||||
SDL_free(myWavCvtBuffer);
|
||||
myWavCvtBuffer = nullptr;
|
||||
myWavCvtBuffer.reset();
|
||||
myWavCvtBufferSize = 0;
|
||||
}
|
||||
}
|
||||
|
@ -510,15 +509,14 @@ void SoundSDL2::wavCallback(void* udata, uInt8* stream, int len)
|
|||
SDL_assert(cvt.needed); // Obviously, this one is always needed.
|
||||
cvt.len = len * myWavSpec.channels; // Mono 8 bit sample frames
|
||||
|
||||
if(!myWavCvtBuffer || myWavCvtBufferSize < static_cast<uInt32>(cvt.len * cvt.len_mult))
|
||||
if(!myWavCvtBuffer ||
|
||||
myWavCvtBufferSize < static_cast<uInt32>(cvt.len * cvt.len_mult))
|
||||
{
|
||||
if(myWavCvtBuffer)
|
||||
SDL_free(myWavCvtBuffer);
|
||||
myWavCvtBufferSize = cvt.len * cvt.len_mult;
|
||||
myWavCvtBuffer = static_cast<uInt8*>(SDL_malloc(myWavCvtBufferSize));
|
||||
myWavCvtBuffer = make_unique<uInt8>(myWavCvtBufferSize);
|
||||
}
|
||||
//cvt.buf = static_cast<uInt8*>(SDL_malloc(cvt.len * cvt.len_mult));
|
||||
cvt.buf = myWavCvtBuffer;
|
||||
cvt.buf = myWavCvtBuffer.get();
|
||||
|
||||
// Read original data into conversion buffer
|
||||
SDL_memcpy(cvt.buf, myWavPos, cvt.len);
|
||||
SDL_ConvertAudio(&cvt);
|
||||
|
@ -548,7 +546,7 @@ uInt8* SoundSDL2::myWavPos = nullptr; // pointer to the audio buffer to be playe
|
|||
uInt32 SoundSDL2::myWavLen = 0; // remaining length of the sample we have to play
|
||||
#ifdef RESAMPLE_WAV
|
||||
double SoundSDL2::myWavSpeed = 1.0;
|
||||
uInt8* SoundSDL2::myWavCvtBuffer = nullptr;
|
||||
unique_ptr<uInt8> SoundSDL2::myWavCvtBuffer = nullptr;
|
||||
uInt32 SoundSDL2::myWavCvtBufferSize = 0;
|
||||
#endif
|
||||
|
||||
|
|
|
@ -196,7 +196,7 @@ class SoundSDL2 : public Sound
|
|||
uInt8* myWavBuffer{nullptr};
|
||||
#ifdef RESAMPLE_WAV
|
||||
static double myWavSpeed;
|
||||
static uInt8* myWavCvtBuffer;
|
||||
static unique_ptr<uInt8> myWavCvtBuffer;
|
||||
static uInt32 myWavCvtBufferSize;
|
||||
#endif
|
||||
|
||||
|
|
Loading…
Reference in New Issue