Skip to content

Commit

Permalink
Fix Apple Lossless MD5 calculation.
Browse files Browse the repository at this point in the history
  • Loading branch information
enzo1982 committed Jan 22, 2022
1 parent 247c150 commit 385ed45
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
10 changes: 10 additions & 0 deletions components/decoder/alac/alac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ BoCA::DecoderALAC::DecoderALAC()
sampleId = 1;

skipSamples = 0;
samplesLeft = 0;
}

BoCA::DecoderALAC::~DecoderALAC()
Expand All @@ -183,6 +184,8 @@ Bool BoCA::DecoderALAC::Activate()

driver->Seek(0);

samplesLeft = track.length;

/* Get codec configuration.
*/
unsigned char *ascBuffer = NIL;
Expand Down Expand Up @@ -221,6 +224,7 @@ Bool BoCA::DecoderALAC::Seek(Int64 samplePosition)

sampleId = ex_MP4GetSampleIdFromTime(mp4File, mp4Track, time, true);
skipSamples = time - ex_MP4GetSampleTime(mp4File, mp4Track, sampleId);
samplesLeft = track.length - samplePosition;

return True;
}
Expand Down Expand Up @@ -267,6 +271,12 @@ Int BoCA::DecoderALAC::ReadData(Buffer<UnsignedByte> &data)
skipSamples -= samplesToSkip;
}

/* Cut data buffer on last frame.
*/
data.Resize(Math::Min(data.Size(), samplesLeft * bytesPerSample));

samplesLeft -= data.Size() / bytesPerSample;

/* Change to default channel order.
*/
if (format.channels == 3) Utilities::ChangeChannelOrder(data, format, Channel::AAC_3_0, Channel::Default_3_0);
Expand Down
3 changes: 2 additions & 1 deletion components/decoder/alac/alac.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* BoCA - BonkEnc Component Architecture
* Copyright (C) 2007-2021 Robert Kausch <[email protected]>
* Copyright (C) 2007-2022 Robert Kausch <[email protected]>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
Expand Down Expand Up @@ -29,6 +29,7 @@ namespace BoCA
MP4SampleId sampleId;

UnsignedInt skipSamples;
UnsignedInt64 samplesLeft;

Buffer<unsigned char> dataBuffer;

Expand Down

0 comments on commit 385ed45

Please sign in to comment.