Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

header building seems to be potential broken #13

Open
macosforgebot opened this issue Apr 23, 2014 · 1 comment
Open

header building seems to be potential broken #13

macosforgebot opened this issue Apr 23, 2014 · 1 comment

Comments

@macosforgebot
Copy link

nt@… originally submitted this as ticket:19

  • Version: 1.0

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

$ 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 [email protected] 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;
@macosforgebot
Copy link
Author

@ryandesign originally submitted this as comment:1:⁠ticket:19

  • Description modified

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant