Get CD audio track frame?
Get CD audio track frame?
Is it possible to get the audio track frame of each track? (the starting location). And perhaps also the offset of the lead-out, or track 0xAA?
I need this because I am converting an algorithm from C to Purebasic.
I need this because I am converting an algorithm from C to Purebasic.
I Stepped On A Cornflake!!! Now I'm A Cereal Killer!
Ok, what I'm trying to do is to convert a C script into PB format.
Here's what I've got so far. Hopefully someone more experience could help me finish this code.
Here's what I've got so far. Hopefully someone more experience could help me finish this code.
Code: Select all
;
; *****************************************************************************
; * *
; * This is my poor attempt at converting the discid algo from C code to PB. *
; * Would be great if someone would help me to complete this. *
; * *
; * DISCID Algorithm conversion from C to PureBasic by GeoTrail. *
; * Original C code can be found at: *
; * http://www.freedb.org/modules.php?name=Sections&sop=viewarticle&artid=6 *
; * *
; *****************************************************************************
;
CDdrives = InitCDAudio()
If CDdrives < 1
MessageRequester("Error", "Could not initialize the CD device.")
End
EndIf
Structure toc
min.w
sec.w
frame.w
EndStructure
Dim cdtoc.toc(100)
Procedure read_cdtoc_from_drive(void)
; Do whatever is appropriate To Read the toc of the CD
; into the cdtoc[] Structure array.
ProcedureReturn tot_trks
EndProcedure
tot_trks = CDAudioTracks()
Procedure cddb_sum(n)
ret = 0
While n > 0
ret = ret + (n % 10)
n = n / 10
Wend
ProcedureReturn ret
EndProcedure
Procedure cddb_discid(tot_trks)
t = 0
n = 0
i = 0
While i < tot_trks
n = n + cddb_sum((cdtoc(i)\min * 60) + cdtoc(i)\sec)
i+1
Wend
t = ((cdtoc(tot_trks)\min * 60) + cdtoc(tot_trks)\sec) - ((cdtoc(0)\min * 60) + cdtoc(0)\sec)
ProcedureReturn ((n % 0xff) << 24 | t << 8 | tot_trks)
EndProcedure
tot_trks = read_cdtoc_from_drive()
MessageRequester("Result", "The discid is " + cddb_discid(tot_trks))I Stepped On A Cornflake!!! Now I'm A Cereal Killer!
Don't know if I understood your question but you won't get this
done with native PB-functions.
I guess we're talking about Windows, since a possible solution for
Linux is already inside the c-source.
On Windows I'd suggest you to do some research on ASPI or SPTI
(ASPI isn't officially supported on OS-Versions > Win98).
Don't know if this helps...
done with native PB-functions.
I guess we're talking about Windows, since a possible solution for
Linux is already inside the c-source.
On Windows I'd suggest you to do some research on ASPI or SPTI
(ASPI isn't officially supported on OS-Versions > Win98).
Don't know if this helps...
Good programmers don't comment their code. It was hard to write, should be hard to read.
You can find a nice introductory ASPI article here:
http://www.cdrlabs.com/articles/index.php?articleid=3
BTW, you'll need this
http://www.cdrlabs.com/articles/index.php?articleid=3
BTW, you'll need this
Code: Select all
;******************************************************************************
;**
;** Module Name: wnaspi32.h
;**
;** Description: Header file for ASPI for Win32. This header includes
;** macro and type declarations, and can be included without
;** modification when using Borland C++ or Microsoft Visual
;** C++ with 32-bit compilation. If you are using a different
;** compiler then you MUST ensure that structures are packed
;** onto byte alignments, and that C++ name mangling is turned
;** off.
;**
;** Notes: This file created using 4 spaces per tab.
;**
;**
;** PureBasic conversion done by (:t)raumatic!
;** This is 100% handmade - use at your own risk
;**
;**
;******************************************************************************
;*****************************************************************************
; %%% SCSI MISCELLANEOUS EQUATES %%%
;*****************************************************************************
#SENSE_LEN = 14 ; Default sense buffer length
#SRB_DIR_SCSI = $00 ; Direction determined by SCSI
#SRB_POSTING = $01 ; Enable ASPI posting
#SRB_ENABLE_RESIDUAL_COUNT = $04 ; Enable residual byte count reporting
#SRB_DIR_IN = $08 ; Transfer from SCSI target to host
#SRB_DIR_OUT = $10 ; Transfer from host to SCSI target
#SRB_EVENT_NOTIFY = $40 ; Enable ASPI event notification
;
#RESIDUAL_COUNT_SUPPORTED = $02 ; Extended buffer flag
#MAX_SRB_TIMEOUT = 108000 ; 30 hour maximum timeout in s
#DEFAULT_SRB_TIMEOUT = 108000 ; Max timeout by default
;*****************************************************************************
; %%% ASPI Command Definitions %%%
;*****************************************************************************
#SC_HA_INQUIRY = $00 ; Host adapter inquiry
#SC_GET_DEV_TYPE = $01 ; Get device type
#SC_EXEC_SCSI_CMD = $02 ; Execute SCSI command
#SC_ABORT_SRB = $03 ; Abort an SRB
#SC_RESET_DEV = $04 ; SCSI bus device reset
#SC_SET_HA_PARMS = $05 ; Set HA parameters
#SC_GET_DISK_INFO = $06 ; Get Disk information
#SC_RESCAN_SCSI_BUS = $07 ; ReBuild SCSI device map
#SC_GETSET_TIMEOUTS = $08 ; Get/Set target timeouts
;*****************************************************************************
; %%% SRB Status %%%
;*****************************************************************************
#SS_PENDING = $00 ; SRB being processed
#SS_COMP = $01 ; SRB completed without error
#SS_ABORTED = $02 ; SRB aborted
#SS_ABORT_FAIL = $03 ; Unable to abort SRB
#SS_ERR = $04 ; SRB completed with error
#SS_INVALID_CMD = $80 ; Invalid ASPI command
#SS_INVALID_HA = $81 ; Invalid host adapter number
#SS_NO_DEVICE = $82 ; SCSI device not installed
#SS_INVALID_SRB = $E0 ; Invalid parameter set in SRB
#SS_OLD_MANAGER = $E1 ; ASPI manager doesn't support Windows
#SS_BUFFER_ALIGN = $E1 ; Buffer not aligned (replaces OLD_MANAGER in Win32)
#SS_ILLEGAL_MODE = $E2 ; Unsupported Windows mode
#SS_NO_ASPI = $E3 ; No ASPI managers resident
#SS_FAILED_INIT = $E4 ; ASPI for windows failed init
#SS_ASPI_IS_BUSY = $E5 ; No resources available to execute cmd
#SS_BUFFER_TO_BIG = $E6 ; Buffer size to big to handle!
#SS_MISMATCHED_COMPONENTS = $E7 ; The DLLs/EXEs of ASPI don't version check
#SS_NO_ADAPTERS = $E8 ; No host adapters to manage
#SS_INSUFFICIENT_RESOURCES = $E9 ; Couldn't allocate resources needed to init
#SS_ASPI_IS_SHUTDOWN = $EA ; Call came to ASPI after PROCESS_DETACH
#SS_BAD_INSTALL = $EB ; The DLL or other components are installed wrong
;*****************************************************************************
; %%% Host Adapter Status %%%
;*****************************************************************************
#HASTAT_OK = $00 ; Host adapter did not detect an // error
#HASTAT_SEL_TO = $11 ; Selection Timeout
#HASTAT_DO_DU = $12 ; Data overrun data underrun
#HASTAT_BUS_FREE = $13 ; Unexpected bus free
#HASTAT_PHASE_ERR = $14 ; Target bus phase sequence // failure
#HASTAT_TIMEOUT = $09 ; Timed out while SRB was waiting to beprocessed.
#HASTAT_COMMAND_TIMEOUT = $0B ; Adapter timed out processing SRB.
#HASTAT_MESSAGE_REJECT = $0D ; While processing SRB, the // adapter received a MESSAGE
#HASTAT_BUS_RESET = $0E ; A bus reset was detected.
#HASTAT_PARITY_ERROR = $0F ; A parity error was detected.
#HASTAT_REQUEST_SENSE_FAILED = $10 ; The adapter failed in issuing
;*****************************************************************************
; %%% SRB - HOST ADAPTER INQUIRY - SC_HA_INQUIRY (0) %%%
;*****************************************************************************
Structure SRB_HAInquiry
; HX/DEC
SRB_Cmd.b ; 00/000 ASPI command code = #SC_HA_INQUIRY
SRB_Status.b ; 01/001 ASPI command status byte
SRB_HaId.b ; 02/002 ASPI host adapter number
SRB_Flags.b ; 03/003 ASPI request flags
SRB_Hdr_Rsvd.l ; 04/004 Reserved, MUST = 0
HA_Count.b ; 08/008 Number of host adapters present
HA_SCSI_ID.b ; 09/009 SCSI ID of host adapter
HA_ManagerId.b[16] ; 0A/010 String describing the manager
HA_Identifier.b[16] ; 1A/026 String describing the host adapter
HA_Unique.b[16] ; 2A/042 Host Adapter Unique parameters
HA_Rsvd1.w ; 3A/058 Reserved, MUST = 0
EndStructure
;*****************************************************************************
; %%% SRB - GET DEVICE TYPE - SC_GET_DEV_TYPE (1) %%%
;*****************************************************************************
Structure SRB_GDEVBlock
; HX/DEC
SRB_Cmd.b ; 00/000 ASPI command code = #SC_GET_DEV_TYPE
SRB_Status.b ; 01/001 ASPI command status byte
SRB_HaId.b ; 02/002 ASPI host adapter number
SRB_Flags.b ; 03/003 Reserved, MUST = 0
SRB_Hdr_Rsvd.l ; 04/004 Reserved, MUST = 0
SRB_Target.b ; 08/008 Target's SCSI ID
SRB_Lun.b ; 09/009 Target's LUN number
SRB_DeviceType.b ; 0A/010 Target's peripheral device type
SRB_Rsvd1.b ; 0B/011 Reserved, MUST = 0
EndStructure
;*****************************************************************************
; %%% SRB - EXECUTE SCSI COMMAND - SC_EXEC_SCSI_CMD (2) %%%
;*****************************************************************************
Structure SRB_ExecSCSICmd
; HX/DEC
SRB_Cmd.b ; 00/000 ASPI command code = #SC_EXEC_SCSI_CMD
SRB_Status.b ; 01/001 ASPI command status byte
SRB_HaId.b ; 02/002 ASPI host adapter number
SRB_Flags.b ; 03/003 ASPI request flags
SRB_Hdr_Rsvd.l ; 04/004 Reserved
SRB_Target.b ; 08/008 Target's SCSI ID
SRB_Lun.b ; 09/009 Target's LUN number
SRB_Rsvd1.w ; 0A/010 Reserved for Alignment
SRB_BufLen.l ; 0C/012 Data Allocation Length
SRB_BufPointer.l ; 10/016 Data Buffer Pointer
SRB_SenseLen.b ; 14/020 Sense Allocation Length
SRB_CDBLen.b ; 15/021 CDB Length
SRB_HaStat.b ; 16/022 Host Adapter Status
SRB_TargStat.b ; 17/023 Target Status
SRB_PostProc.l ; 18/024 Post routine
SRB_Rsvd2.b[20] ; 1C/028 Reserved, MUST = 0
CDBByte.b[16] ; 30/048 SCSI CDB
SenseArea.b[#SENSE_LEN+2] ;50/064 Request Sense buffer
EndStructure
;*****************************************************************************
; %%% SRB - ABORT AN SRB - SC_ABORT_SRB (3) %%%
;*****************************************************************************
Structure SRB_Abort
; HX/DEC
SRB_Cmd.b ; 00/000 ASPI command code = #SC_ABORT_SRB
SRB_Status.b ; 01/001 ASPI command status byte
SRB_HaId.b ; 02/002 ASPI host adapter number
SRB_Flags.b ; 03/003 Reserved
SRB_Hdr_Rsvd.l ; 04/004 Reserved
SRB_ToAbort.l ; 08/008 Pointer to SRB to abort
EndStructure
;*****************************************************************************
; %%% SRB - BUS DEVICE RESET - SC_RESET_DEV (4) %%%
;*****************************************************************************
Structure SRB_BusDeviceReset
; HX/DEC
SRB_Cmd.b ; 00/000 ASPI command code = #SC_RESET_DEV
SRB_Status.b ; 01/001 ASPI command status byte
SRB_HaId.b ; 02/002 ASPI host adapter number
SRB_Flags.b ; 03/003 ASPI request flags
SRB_Hdr_Rsvd.l ; 04/004 Reserved
SRB_Target.b ; 08/008 Target's SCSI ID
SRB_Lun.b ; 09/009 Target's LUN number
SRB_Rsvd1.b[12] ; 0A/010 Reserved for Alignment
SRB_HaStat.b ; 16/022 Host Adapter Status
SRB_TargStat.b ; 17/023 Target Status
SRB_PostProc.l ; 18/024 Post routine
SRB_Rsvd2.b[36] ; 1C/028 Reserved, MUST = 0
EndStructure
;*****************************************************************************
; %%% SRB - GET DISK INFORMATION - SC_GET_DISK_INFO %%%
;*****************************************************************************
Structure SRB_GetDiskInfo
; HX/DEC
SRB_Cmd.b ; 00/000 ASPI command code = #SC_GET_DISK_INFO
SRB_Status.b ; 01/001 ASPI command status byte
SRB_HaId.b ; 02/002 ASPI host adapter number
SRB_Flags.b ; 03/003 Reserved, MUST = 0
SRB_Hdr_Rsvd.l ; 04/004 Reserved, MUST = 0
SRB_Target.b ; 08/008 Target's SCSI ID
SRB_Lun.b ; 09/009 Target's LUN number
SRB_DriveFlags.b ; 0A/010 Driver flags
SRB_Int13HDriveInfo.b ; 0B/011 Host Adapter Status
SRB_Heads.b ; 0C/012 Preferred number of heads translation
SRB_Sectors.b ; 0D/013 Preferred number of sectors translation
SRB_Rsvd1.b[10] ; 0E/014 Reserved, MUST = 0
EndStructure
;*****************************************************************************
; %%% SRB - RESCAN SCSI BUS(ES) ON SCSIPORT %%%
;*****************************************************************************
Structure SRB_RescanPort
; HX/DEC
SRB_Cmd.b ; 00/000 ASPI command code = #SC_RESCAN_SCSI_BUS
SRB_Status.b ; 01/001 ASPI command status byte
SRB_HaId.b ; 02/002 ASPI host adapter number
SRB_Flags.b ; 03/003 Reserved, MUST = 0
SRB_Hdr_Rsvd.l ; 04/004 Reserved, MUST = 0
EndStructure
;*****************************************************************************
; %%% SRB - GET/SET TARGET TIMEOUTS %%%
;*****************************************************************************
Structure SRB_GetSetTimeouts
; HX/DEC
SRB_Cmd.b ; 00/000 ASPI command code = #SC_GETSET_TIMEOUTS
SRB_Status.b ; 01/001 ASPI command status byte
SRB_HaId.b ; 02/002 ASPI host adapter number
SRB_Flags.b ; 03/003 ASPI request flags
SRB_Hdr_Rsvd.l ; 04/004 Reserved, MUST = 0
SRB_Target.b ; 08/008 Target's SCSI ID
SRB_Lun.b ; 09/009 Target's LUN number
SRB_Timeout.l ; 0A/010 Timeout in half seconds
EndStructure
;*****************************************************************************
; %%% ASPIBUFF - Structure For Controllng I/O Buffers %%%
;*****************************************************************************
Structure ASPI32BUFF
; HX/DEC
AB_BufPointer.l ; 00/000 Pointer to the ASPI allocated buffer
AB_BufLen.l ; 04/004 Length in bytes of the buffer
AB_ZeroFill.l ; 08/008 Flag set to 1 if buffer should be zeroed
AB_Reserved.l ; 0C/012 Reserved
EndStructure
Good programmers don't comment their code. It was hard to write, should be hard to read.
I will, thanks 
But first I think I need some help with the commands using the library call functions.
When I run that it just returns 15364. I'm not really sure if I've done this right, or even how to issue the commands and functions to the dll.
But first I think I need some help with the commands using the library call functions.
Code: Select all
IncludeFile "wnaspi32.pbi"
If OpenLibrary(0, "WNASPI32.DLL")
func$ = "GetASPI32DLLVersion"
If IsFunction(0, func$)
Result = CallFunction(0, func$)
Debug "CallFunction result: " + Str(Result)
;MessageRequester("Result", "CallFunction result: " + Str(Result))
Else
MessageRequester("Invalid function", "Supplied function is invalid for selected dll.")
EndIf
Debug "Dll contains " + Str(CountLibraryFunctions(0)) + " functions."
;MessageRequester("Result", "Dll contains " + Str(CountLibraryFunctions(0)) + " functions.")
If ExamineLibraryFunctions(0)
i = 1
Debug "-------------------------------------------------------------------"
While NextLibraryFunction()
FuncName$ = LibraryFunctionName()
FuncAdr.l = LibraryFunctionAddress()
Debug "Function no: " + Str(i)
Debug "Function name: " + FuncName$
Debug "Function address: " + Str(FuncAdr)
Debug "-------------------------------------------------------------------"
i = i + 1
Wend
EndIf
CloseLibrary(0)
EndIfI Stepped On A Cornflake!!! Now I'm A Cereal Killer!
What do you mean? What returns 15364?GeoTrail wrote:When I run that it just returns 15364. I'm not really sure if I've done this right, or even how to issue the commands and functions to the dll.
However, the two vital functions that you should find inside every
wnaspi32.dll are GetASPI32SupportInfo() and SendASPI32Command().
Here are the first bits of the article translated, that should get you
started (?)
Code: Select all
Procedure.b HIBYTE(w.w)
ProcedureReturn (w>>8) & $FF
EndProcedure
Procedure.b LOBYTE(w.w)
ProcedureReturn w &$FF
EndProcedure
Procedure.w HIWORD(l.l)
ProcedureReturn (l>>16) & $FFFF
EndProcedure
Procedure.w LOWORD(l.l)
ProcedureReturn l & $FFFF
EndProcedure
;
;
;
wnaspi32.l = OpenLibrary(#PB_Any, "wnaspi32.dll")
*GetASPI32SupportInfo.l = IsFunction(wnaspi32, "GetASPI32SupportInfo")
*SendASPI32Command.l = IsFunction(wnaspi32, "SendASPI32Command")
SupportInfo.l = CallFunctionFast(*GetASPI32SupportInfo)
HACount.b = HIBYTE(LOWORD(SupportInfo))
ASPIStatus.b = LOBYTE(LOWORD(SupportInfo))
;
HAInquiry.SRB_HAInquiry ; Create a data struct for our command.
ZeroMemory_(@HAInquiry, SizeOf(SRB_HAInquiry)) ; Zero out the SRB
HAInquiry\SRB_Cmd = #SC_HA_INQUIRY
HAInquiry\SRB_HaId = 1
CallFunctionFast(*SendASPI32Command, @HAInquiry) ; Give it a pointer to our packet
;Now, the ASPI manager will query Host Adapter 1 with the packet we constructed.
; Next we'll check the SRB_Status byte to determine if it succeeded or not.
; ASPI will set it to #SS_COMP if it succeeded.
If HAInquiry\SRB_Status <> #SS_COMP
Debug "error..."
EndIf
; ...just for the fun of it
Debug PeekS(@HAInquiry\HA_ManagerId)
Debug PeekS(@HAInquiry\HA_Identifier)
CloseLibrary(wnaspi32)
Good programmers don't comment their code. It was hard to write, should be hard to read.
Don't know - it works here...GeoTrail wrote:thanks for your help
when I run it, it returns "error..."
what does that mean?
Did you actually read the article I suggested?
Here's another rather interesting one:
http://www.hochfeiler.it/alvise/ASPI_1.HTM
which will lead you to:
ftp://ftp.adaptec.com/obsolete/adaptec/aspi_w32.txt
Good programmers don't comment their code. It was hard to write, should be hard to read.
What does this return for you?
Code: Select all
SupportInfo.l = CallFunctionFast(*GetASPI32SupportInfo)
ASPIStatus.b = HIBYTE(LOWORD(SupportInfo))
HaCount.b = LOBYTE(LOWORD(SupportInfo))
If ASPIStatus&$FF <> #SS_COMP And ASPIStatus&$FF <> #SS_NO_ADAPTERS
MessageRequester("ASPI-Test", "ASPI not initialized", #MB_ICONSTOP)
Else
MessageRequester("ASPI-Test", "Looks fine... go for it!")
EndIf
Good programmers don't comment their code. It was hard to write, should be hard to read.
BTW: You can get the latest ASPI-drivers by Adaptec here
Chose this one:
and you'll the get the entire package including the a programmers documentation
and includefiles.
Chose this one:
Code: Select all
28 May 2002 ASPI Driver for Windows version 4.71
Updated ASPI drivers version 4.71 for Windows 98, NT 4, ME,
2000 and XP. Includes ASPICHK version checking utility.
and includefiles.
Good programmers don't comment their code. It was hard to write, should be hard to read.

