I guess I found a bug in alacconvert. When building the packet table header of CAFF file, and any case of "mReminderFrames" should be zero, it goes to be the value of "kALACDefaultFramesPerPacket" due to the lack of a condition. As a result, mNumberPackets will be increased, against the code will. With this patch, we've confirmed better results come in various music source. The patch follows:
Thanks,
nt
$ diff -c CAFFileALAC.cpp~ CAFFileALAC.cpp
*** CAFFileALAC.cpp~ Sun Apr 13 22:21:11 2014
--- CAFFileALAC.cpp Wed Apr 23 21:27:03 2014
***************
*** 266,274 ****
thePacketTableHeader->mNumberPackets = thePacketTableHeader->mNumberValidFrames/kALACDefaultFramesPerPacket;
thePacketTableHeader->mPrimingFrames = 0;
thePacketTableHeader->mRemainderFrames = thePacketTableHeader->mNumberValidFrames - thePacketTableHeader->mNumberPackets * kALACDefaultFramesPerPacket;
! thePacketTableHeader->mRemainderFrames = kALACDefaultFramesPerPacket - thePacketTableHeader->mRemainderFrames;
! if (thePacketTableHeader->mRemainderFrames) thePacketTableHeader->mNumberPackets += 1;
!
// Ok, we have to assume the worst case scenario for packet sizes
theMaxPacketSize = (theInputFormat.mBitsPerChannel >> 3) * theInputFormat.mChannelsPerFrame * kALACDefaultFramesPerPacket + kALACMaxEscapeHeaderBytes;
--- 266,280 ----
thePacketTableHeader->mNumberPackets = thePacketTableHeader->mNumberValidFrames/kALACDefaultFramesPerPacket;
thePacketTableHeader->mPrimingFrames = 0;
thePacketTableHeader->mRemainderFrames = thePacketTableHeader->mNumberValidFrames - thePacketTableHeader->mNumberPackets * kALACDefaultFramesPerPacket;
! if (0) {
! thePacketTableHeader->mRemainderFrames = kALACDefaultFramesPerPacket - thePacketTableHeader->mRemainderFrames;
! if (thePacketTableHeader->mRemainderFrames) thePacketTableHeader->mNumberPackets += 1;
! } else { /* fixed by nt@ototoy.jp 20140423 */
! if (thePacketTableHeader->mRemainderFrames) {
! thePacketTableHeader->mRemainderFrames = kALACDefaultFramesPerPacket - thePacketTableHeader->mRemainderFrames;
! thePacketTableHeader->mNumberPackets += 1;
! }
! }
// Ok, we have to assume the worst case scenario for packet sizes
theMaxPacketSize = (theInputFormat.mBitsPerChannel >> 3) * theInputFormat.mChannelsPerFrame * kALACDefaultFramesPerPacket + kALACMaxEscapeHeaderBytes;
nt@… originally submitted this as ticket:19
Hello folks,
I guess I found a bug in alacconvert. When building the packet table header of CAFF file, and any case of "mReminderFrames" should be zero, it goes to be the value of "kALACDefaultFramesPerPacket" due to the lack of a condition. As a result, mNumberPackets will be increased, against the code will. With this patch, we've confirmed better results come in various music source. The patch follows:
Thanks, nt