mirror of https://github.com/jorio/Pomme.git
Fix memory leak in SndStartFilePlay
This commit is contained in:
parent
d8e7457b95
commit
08dd1e61b6
|
@ -119,7 +119,7 @@ OSErr SndChannelStatus(SndChannelPtr chan, short theLength, SCStatusPtr theStatu
|
||||||
}
|
}
|
||||||
|
|
||||||
// Install a sampled sound as a voice in a channel.
|
// Install a sampled sound as a voice in a channel.
|
||||||
static void InstallSoundInChannel(SndChannelPtr chan, const Ptr sampledSoundHeader)
|
static void InstallSoundInChannel(SndChannelPtr chan, const Ptr sampledSoundHeader, bool forceCopy=false)
|
||||||
{
|
{
|
||||||
//---------------------------------
|
//---------------------------------
|
||||||
// Get internal channel
|
// Get internal channel
|
||||||
|
@ -146,6 +146,12 @@ static void InstallSoundInChannel(SndChannelPtr chan, const Ptr sampledSoundHead
|
||||||
codec->Decode(info.nChannels, spanIn, spanOut);
|
codec->Decode(info.nChannels, spanIn, spanOut);
|
||||||
impl.source.Init(info.sampleRate, 16, info.nChannels, false, spanOut);
|
impl.source.Init(info.sampleRate, 16, info.nChannels, false, spanOut);
|
||||||
}
|
}
|
||||||
|
else if (forceCopy)
|
||||||
|
{
|
||||||
|
auto spanOut = impl.source.GetBuffer(info.decompressedLength);
|
||||||
|
memcpy(spanOut.data(), spanIn.data(), spanIn.size());
|
||||||
|
impl.source.Init(info.sampleRate, info.codecBitDepth, info.nChannels, info.bigEndian, spanOut);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
impl.source.Init(info.sampleRate, info.codecBitDepth, info.nChannels, info.bigEndian, spanIn);
|
impl.source.Init(info.sampleRate, info.codecBitDepth, info.nChannels, info.bigEndian, spanIn);
|
||||||
|
@ -313,7 +319,9 @@ OSErr SndStartFilePlay(
|
||||||
SndListHandle sndListHandle = Pomme_SndLoadFileAsResource(fRefNum);
|
SndListHandle sndListHandle = Pomme_SndLoadFileAsResource(fRefNum);
|
||||||
long offset = 0;
|
long offset = 0;
|
||||||
GetSoundHeaderOffset(sndListHandle, &offset);
|
GetSoundHeaderOffset(sndListHandle, &offset);
|
||||||
InstallSoundInChannel(chan, ((Ptr) *sndListHandle) + offset);
|
InstallSoundInChannel(chan, ((Ptr) *sndListHandle) + offset, true);
|
||||||
|
DisposeHandle((Handle) sndListHandle);
|
||||||
|
sndListHandle = nullptr;
|
||||||
|
|
||||||
auto& impl = GetChannelImpl(chan);
|
auto& impl = GetChannelImpl(chan);
|
||||||
if (theCompletion)
|
if (theCompletion)
|
||||||
|
|
Loading…
Reference in New Issue