Calculating cdplayer.ini id by algorithm
If you want to calculate the id - instead of using GetVolumeInformation
-
you may try this algorithm.
For Visual Basic sample, see here.
{ Delphi sample © Edy Hinzen 1997 }
type
tMSFRec = record
Minutes : Byte; {least significant byte}
Seconds : Byte;
Frames : Byte;
NotUsed : Byte; {most significant byte}
end;
const
FRAME_PER_SEC = 75;
function MilliSecsToFrames(milliSecs:LongInt):LongInt;
begin
Result := millisecs * FRAME_PER_SEC DIV 1000;
{ Did the division have a reminder? Then increment result by 1 }
if millisecs <> (Result * 1000 DIV FRAME_PER_SEC) then inc(Result);
end;
procedure TForm1.FormCreate(Sender: TObject);
var
tracknumb : Integer;
magicNumb : Byte;
dwTemp,
dwID : LongInt;
begin
{ activate MediaPlayer1 to get the DeviceID }
MediaPlayer1.DeviceType := dtCDAudio;
if not MediaPlayer1.AutoOpen then MediaPlayer1.Open;
With MediaPlayer1 do
begin
timeFormat := tfMSF; {set time format}
dwID := 0;
magicNumb := 0;
For tracknumb := 1 To Tracks do
begin
dwTemp := TrackPosition[tracknumb];
With tMSFRec(dwTemp) do
begin
dwID := dwID +
(Minutes SHL 16)+
(Seconds SHL 8)+
(Frames);
{ instead of typecasting this record you could code this MMSystem macros:
Minutes := mci_MSF_Minute(dwTemp);
Seconds := mci_MSF_Second(dwTemp);
Frames := mci_MSF_Frame(dwTemp);}
if (trackNumb = 1) and (tracks =2) then magicNumb := Frames;
end;
end;
if Tracks < 3 then
begin
timeFormat := tfMilliseconds;
dwID := dwID + magicNumb + MilliSecsToFrames(Length);
end;
{ Set text to unique value: }
Edit1.Text := IntToHex(dwID,1);
end;
Let's try to explain it for non Delphi / Pascal users:
- set DoubleWord
dwID
to 0
- for each track on cd do
- get track start (
TrackPosition
) in MSF-format:
this DoubleWord is coded as nnffssmm
(nn for notUsed, ff for frames, ss for seconds, mm for minutes)
- Split this value into
frames
, seconds
, minutes
- Add
(minutes * 65536)
plus (seconds * 256)
plus frames
to dwID
- if less than three tracks on cd
- if there are two tracks: add frame number (magicNumb) of first track
- add total number of frames on disk
- finally convert
dwID
to an hex string (without leading zeroes)
back to Q&A