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

Fix MusicBrainz TOC compute per current specs #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 14 additions & 12 deletions cd-discid.c
Expand Up @@ -133,7 +133,7 @@ void usage()
fprintf(stderr, "Usage: cd-discid [<option> ...]\n\n");
fprintf(stderr, "Options:\n");
fprintf(stderr, " --musicbrainz Output a TOC that is suitable "
"for calculating the MusicBrainz disc id.\n");
"for calculating the MusicBrainz Disc ID.\n");
fprintf(stderr, " --help Show this message.\n");
fprintf(stderr, " --version Show the version.\n");
fprintf(stderr, " devicename CD-ROM block device name that "
Expand Down Expand Up @@ -313,22 +313,24 @@ int main(int argc, char *argv[])
totaltime = ((TocEntry[last].cdte_track_address + CD_MSF_OFFSET) / CD_FRAMES) -
((TocEntry[0].cdte_track_address + CD_MSF_OFFSET) / CD_FRAMES);

/* print discid */
if (!musicbrainz)
printf("%08lx ", (cksum % 0xff) << 24 | totaltime << 8 | last);

/* print number of tracks */
printf("%d", last);
if (musicbrainz) {
/* print first track number (1), last track number, and lead-out track offset */
printf("1 %d %d", last, TocEntry[last].cdte_track_address + CD_MSF_OFFSET);
} else {
/* print discid, and last track number */
printf("%08lx %d", (cksum % 0xff) << 24 | totaltime << 8 | last, last);
}

/* print frame offsets of all tracks */
for (i = 0; i < last; i++)
printf(" %d", TocEntry[i].cdte_track_address + CD_MSF_OFFSET);

if (musicbrainz)
printf(" %d\n", TocEntry[last].cdte_track_address + CD_MSF_OFFSET);
else
/* print length of disc in seconds */
printf(" %d\n", (TocEntry[last].cdte_track_address + CD_MSF_OFFSET) / CD_FRAMES);
/* print length of disc in seconds */
if (!musicbrainz)
printf(" %d", (TocEntry[last].cdte_track_address + CD_MSF_OFFSET) / CD_FRAMES);

/* print final new-line */
printf("\n");

free(TocEntry);

Expand Down