-
-
Notifications
You must be signed in to change notification settings - Fork 23
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
LIB-11: raw (low level) ISRC reads #6
Open
JonnyJD
wants to merge
47
commits into
master
Choose a base branch
from
isrc_raw
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
47 commits
Select commit
Hold shift + click to select a range
fbf133a
read ISRCs raw on Linux
JonnyJD 5fbf4d4
remove TODO comment
JonnyJD c31d46b
Merge branch 'master' into isrc_raw
JonnyJD f8a82dd
move read_track_isrc to disc_scsi.c
JonnyJD a1d73d6
rename disc_scsi.c -> scsi.c
JonnyJD 261aac8
move scsi function declarations in scsi header
JonnyJD d5a059b
add HACKING file
JonnyJD b1616d3
prepend mb_scsi to scsi functions
JonnyJD 63c6dc8
include info about SCSI standards
JonnyJD de09b17
linux: stop the device after reading
JonnyJD 1b859ac
Merge branch 'master' into isrc_raw
JonnyJD 1c013f8
add scsi.h to distribution
JonnyJD 20b7fcb
locate CRC in q-channel
JonnyJD 81e062b
Merge branch 'master' into isrc_raw
JonnyJD 4df857c
Merge branch 'master' into isrc_raw
JonnyJD 0618e64
Merge branch 'master' into isrc_raw
JonnyJD a470a34
implement CRC check for raw ISRCs
JonnyJD 5dd8ca2
Merge branch 'master' into crc
JonnyJD 867889f
improve comments and names for raw isrcs
JonnyJD e77dd95
LIB-11: read ISRCs until CRC is valid
JonnyJD b8d3ed3
free raw disc read data
JonnyJD d163282
raw isrcs: don't return main channel data
JonnyJD fd63dc9
LIB-11: read every sector separately
JonnyJD 02b733d
implement scsi_cmd for Windows
JonnyJD 9e5e389
prepare autotools build with windows scsi_cmd
JonnyJD 80d627e
work around windows dllexport issue
JonnyJD fb400d6
add ntddscsi.h for MSVC
JonnyJD ecd2d58
msvc: remove new warnings
JonnyJD f3ba048
Windows: fix scsi_cmd (return, GENERIC_WRITE)
JonnyJD 724df7c
scsi_cmd: fix return code documentation
JonnyJD bc102db
add more debug output for w32 scsi_cmd
JonnyJD 4a4ebab
check if there are ISRCs at all
JonnyJD 73e1fa6
define SECTORS_ISRC and read 10 more
JonnyJD ee22ed7
check for data_len, rather than 96
JonnyJD aed1d9f
create mb_scsi_handle struct
JonnyJD e34d987
Merge branch 'scsi_handle' into scsi_windows
JonnyJD e2fc17f
Merge branch 'scsi_windows' into isrc_raw
JonnyJD 2803ca0
return usable error codes from scsi_cmd
JonnyJD bdd74be
fix warnings on MinGW
JonnyJD 046d1c0
fall back to normal when raw ISRC fails
JonnyJD cd58b5d
implement scsi feature detection
JonnyJD 7031c1b
rename subchannel feature to isrc
JonnyJD 55d274f
windows: restructure isrc section
JonnyJD 3923e5a
add newline to stderr message
JonnyJD 6533105
Merge branch 'master' into isrc_raw
JonnyJD 90dbfe5
Merge branch 'master' into isrc_raw
JonnyJD 477da28
Merge branch 'master' into isrc_raw
JonnyJD File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
/* -------------------------------------------------------------------------- | ||
|
||
MusicBrainz -- The Internet music metadatabase | ||
|
||
Copyright (C) 2013 Johannes Dewender | ||
|
||
This library is free software; you can redistribute it and/or | ||
modify it under the terms of the GNU Lesser General Public | ||
License as published by the Free Software Foundation; either | ||
version 2.1 of the License, or (at your option) any later version. | ||
|
||
This library is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
Lesser General Public License for more details. | ||
|
||
You should have received a copy of the GNU Lesser General Public | ||
License along with this library; if not, write to the Free Software | ||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
|
||
|
||
--------------------------------------------------------------------------- */ | ||
|
||
#include <stdio.h> | ||
#include <string.h> | ||
|
||
#include "discid/discid_private.h" | ||
|
||
/* Send a scsi command and receive data. */ | ||
int scsi_cmd(int fd, unsigned char *cmd, int cmd_len, | ||
const char *data, int data_len); | ||
|
||
static void decode_isrc(unsigned char *q_channel, char *isrc) { | ||
int isrc_pos; | ||
int data_pos; | ||
int bit_pos; | ||
int bit; | ||
unsigned char buffer; | ||
|
||
isrc_pos = 0; | ||
/* q_channel[0] = 0x03 -> mode 3 -> ISRC data */ | ||
data_pos = 1; | ||
bit_pos = 7; | ||
buffer = 0; | ||
/* first 5 chars of ISRC are alphanumeric and 6-bit BCD encoded */ | ||
for (bit = 0; bit < 5*6; bit++) { | ||
buffer = buffer << 1; | ||
if ((q_channel[data_pos] & (1 << bit_pos)) == (1 << bit_pos)) { | ||
buffer++; | ||
} | ||
bit_pos--; | ||
if ((bit + 1)%8 == 0) { | ||
bit_pos = 7; | ||
data_pos++; | ||
} | ||
if ((bit + 1)%6 == 0) { | ||
/* 0x3f = only lowest 6 bits set */ | ||
isrc[isrc_pos] = '0' + (buffer & 0x3f); | ||
isrc_pos++; | ||
buffer = 0; | ||
} | ||
} | ||
/* buffer[4] includes 2 zero bits | ||
* last 7 chars of ISRC are only numeric and 4-bit encoded | ||
*/ | ||
isrc[5] = '0' + (q_channel[5] >> 4); | ||
isrc[6] = '0' + (q_channel[5] & 0x0f); | ||
isrc[7] = '0' + (q_channel[6] >> 4); | ||
isrc[8] = '0' + (q_channel[6] & 0x0f); | ||
isrc[9] = '0' + (q_channel[7] >> 4); | ||
isrc[10] = '0' + (q_channel[7] & 0x0f); | ||
isrc[11] = '0' + (q_channel[8] >> 4); | ||
/* q_channel[9] are zero bits | ||
* q_channel 10-12 are AFRAME | ||
*/ | ||
|
||
} | ||
|
||
void read_track_isrc_raw(int fd, mb_disc_private *disc, int track_num) { | ||
/* there should be at least one ISRC in 100 sectors per spec | ||
* We try 150 (= 2 seconds) to be sure, but break when successfull | ||
*/ | ||
const int SEC_NUM = 150; | ||
unsigned char cmd[12]; | ||
unsigned char data[SEC_NUM*2448]; /* overall data */ | ||
unsigned char q_buffer; | ||
unsigned char q_data[12]; /* sub-channel data in 1 sector */ | ||
char isrc[ISRC_STR_LENGTH+1]; | ||
unsigned long offset; | ||
int char_num; | ||
int sector; | ||
int i; | ||
|
||
memset(cmd, 0, sizeof cmd); | ||
memset(data, 0, sizeof data); | ||
memset(isrc, 0, sizeof isrc); | ||
|
||
offset = disc->track_offsets[track_num]; | ||
|
||
/* 0xbe = READ CD, implementation optional in contrast to 0x42 | ||
* support given with GET CONFIGURATION (0x46) | ||
* Support part of: | ||
* Multi-Read Feature (0x001d) and | ||
* CD Read Feature (0x001e), | ||
*/ | ||
cmd[0] = 0xbe; /* READ CD */ | ||
cmd[2] = offset >> 32; | ||
cmd[3] = offset >> 16; | ||
cmd[4] = offset >> 8; | ||
cmd[5] = offset; /* from where to start reading */ | ||
cmd[6] = SEC_NUM >> 16; | ||
cmd[7] = SEC_NUM >> 8; | ||
cmd[8] = SEC_NUM; /* sectors to read */ | ||
cmd[9] = 0xF8; /* 11111000 sync=1 all-header=11 user=1, ecc=1 | ||
* no-error=00 */ | ||
cmd[10] = 0x01; /* Sub-Channel Selection raw P-W=001*/ | ||
/* cmd[11] = control byte */ | ||
|
||
if (scsi_cmd(fd, cmd, sizeof cmd, data, sizeof data) != 0) { | ||
fprintf(stderr, "Warning: Cannot get ISRC code for track %d\n", | ||
track_num); | ||
return; | ||
} | ||
|
||
/* each sector has 96 bytes for one Q-channel type | ||
* We try until we finde an ISRC Q-channel | ||
*/ | ||
for (sector = 0; sector < SEC_NUM; sector++) { | ||
char_num = 0; | ||
memset(q_data, 0, sizeof q_data); | ||
q_buffer = 0; | ||
/* the first 2352 bytes are raw data without sub-channels | ||
* We only want the 96 bit sub-channel data | ||
*/ | ||
for (i = 2352; i < 2448; i++) { | ||
q_buffer = q_buffer << 1; | ||
/* the 6th bit is the Q-channel bit | ||
* we want to collect these bits | ||
*/ | ||
if ((data[i + (sector*2448)] & (1 << 6)) == (1 << 6)) { | ||
q_buffer++; | ||
} | ||
if ((i+1)%8 == 0) { | ||
/* we have gathered one complete byte */ | ||
q_data[char_num] = q_buffer; | ||
if (char_num == 0) { | ||
/* test if we got the right type | ||
* of q-channel (ADR = 0x03) | ||
* upper 4 bit are CONTROL | ||
* Go to next sector otherwise | ||
*/ | ||
if ((q_buffer & 0x0F) != 0x03) { | ||
break; | ||
} | ||
} | ||
char_num++; | ||
q_buffer = 0; | ||
} | ||
} | ||
if ((q_data[0] & 0x0F) == 0x03) { | ||
/* we found a Q-channel with ISRC data */ | ||
decode_isrc(q_data, isrc); | ||
break; | ||
} | ||
} | ||
strncpy(disc->isrc[track_num], isrc, ISRC_STR_LENGTH); | ||
} | ||
|
||
|
||
/* EOF */ |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should make sure that these 150 sectors (= 2 seconds) are part of the track and check less sectors for VERY short tracks.