Class BassCd
BassCd is a BASS addon enabling digital streaming and ripping of audio CDs. Also includes analog playback routines.
Namespace: System.Dynamic.ExpandoObject
Assembly: ManagedBass.Cd.dll
Syntax
public static class BassCd : object
Remarks
Supports: .cda
Fields
TrackPregap
Properties
AutoSpeedReduction
Automatically reduce the read speed when a read error occurs? (default is disabled). If true, the read speed will be halved when a read error occurs, before retrying (if the RetryCount setting allows).
Declaration
public static bool AutoSpeedReduction { get; set; }
Property Value
Boolean
|
CDDBServer
The server address to use in CDDB requests, in the form of "User:pass@server:port/path" (default = "freedb.freedb.org").
Declaration
public static string CDDBServer { get; set; }
Property Value
String
|
Remarks
The "User:pass@", ":port" and "/path" parts are optional; only the "server" part is required. If not provided, the port and path default to 80 and "/~cddb/cddb.cgi", respectively. The proxy server, as configured via the NetProxy option, is used when connecting to the CDDB server.
DriveCount
Gets the number of CD Drives available.
Declaration
public static int DriveCount { get; }
Property Value
Int32
|
FreeOld
Automatically free an existing stream when creating a new one on the same drive? (enabled by Default)
Declaration
public static bool FreeOld { get; set; }
Property Value
Boolean
|
Remarks
Only one stream can exist at a time per CD drive. So if a stream using the same drive already exists, stream creation function calls will fail, unless this config option is enabled to automatically free the existing stream.
RetryCount
Number of times to retry after a read error... 0 = don't retry, default = 2.
Declaration
public static int RetryCount { get; set; }
Property Value
Int32
|
SkipError
Skip past read errors? If true, reading will skip onto the next frame when a read error occurs, otherwise reading will stop. When skipping an error, it will be replaced with silence, so that the track Length is unaffected. Before skipping past an error, BassCd will first retry according to the RetryCount setting.
Declaration
public static bool SkipError { get; set; }
Property Value
Boolean
|
Methods
AnalogGetPosition(Int32)
Retrieves the current position and track on a drive.
Declaration
public static int AnalogGetPosition(int Drive)
Parameters
Int32
Drive
The drive... 0 = the first drive. |
Returns
Int32
If an error occurs, -1 is returned, use LastError to get the error code. If successful, the HIWORD contains the track number (0=first), and the LOWORD contains the offset (in frames). |
AnalogIsActive(Int32)
Checks if analog playback is in progress on a drive.
Declaration
public static bool AnalogIsActive(int Drive)
Parameters
Int32
Drive
The drive... 0 = the first drive. |
Returns
Boolean |
AnalogPlay(Int32, Int32, Int32)
Starts analog playback of an audio CD track.
Declaration
public static bool AnalogPlay(int Drive, int Track, int Position)
Parameters
Int32
Drive
The drive... 0 = the first drive. |
Int32
Track
The track... 0 = the first track. |
Int32
Position
Position (in frames) to start playback from. There are 75 frames per second. |
Returns
Boolean
If successful, true is returned, else false is returned. Use LastError to get the error code. |
Remarks
Some old CD drives may not be able to digitally extract audio data (or not quickly enough to sustain playback), so that it's not possible to use CreateStream(Int32, Int32, BassFlags) to stream CD tracks. This is where the analog playback option can come in handy.
In analog playback, the sound bypasses Bass - it goes directly from the CD drive to the soundcard (assuming the drive is cabled up to the soundcard). This means that Bass output does not need to be initialized to use analog playback. It also means it's not possible to apply any DSP/FX to the sound, and nor is it possible to visualise it (unless you record the sound from the soundcard).
Analog playback is not possible while digital streaming is in progress - the streaming will kill the analog playback. So if you wish to switch from digital to analog playback, you should first free the stream using StreamFree(Int32).
AnalogPlay(String, Int32)
Starts analog playback of an audio CD track, using a CDA file on the CD.
Declaration
public static bool AnalogPlay(string FileName, int Position)
Parameters
String
FileName
The CDA filename... for example, "D:\Track01.cda". |
Int32
Position
Position (in frames) to start playback from. There are 75 frames per second. |
Returns
Boolean
If successful, the number of the drive being used is returned, else -1 is returned. Use LastError to get the error code. |
Remarks
Some old CD drives may not be able to digitally extract audio data (or not quickly enough to sustain playback), so that it's not possible to use CreateStream(String, BassFlags) to stream CD tracks. This is where the analog playback option can come in handy.
In analog playback, the sound bypasses Bass - it goes directly from the CD drive to the soundcard (assuming the drive is cabled up to the soundcard). This means that Bass output does not need to be initialized to use analog playback. It also means it's not possible to apply any DSP/FX to the sound, and nor is it possible to visualise it (unless you record the sound from the soundcard).
Analog playback is not possible while digital streaming is in progress - the streaming will kill the analog playback. So if you wish to switch from digital to analog playback, you should first free the stream using StreamFree(Int32).
AnalogStop(Int32)
Stops analog playback on a drive.
Declaration
public static bool AnalogStop(int Drive)
Parameters
Int32
Drive
The drive... 0 = the first drive. |
Returns
Boolean
If successful, true is returned, else false is returned. Use LastError to get the error code. |
Remarks
Pausing can be achieved by getting the position (AnalogGetPosition(Int32)) just before stopping, and then using that position in a call to AnalogPlay(Int32, Int32, Int32) to resume.
CreateStream(Int32, Int32, BassFlags)
Creates a sample stream from an audio CD track.
Declaration
public static int CreateStream(int Drive, int Track, BassFlags Flags)
Parameters
Int32
Drive
The drive... 0 = the first drive. |
Int32
Track
The track... 0 = the first track, TrackPregap = 1st track pregap (not all drives support reading of the 1st track pregap). |
BassFlags
Flags
A combination of BassFlags |
Returns
Int32
If successful, the new stream's handle is returned, else 0 is returned. Use LastError to get the error code. |
Remarks
Only one stream can exist at a time per CD drive. If a stream using the drive already exists, this function will fail, unless the FreeOld config option is enabled. Note that StreamSetTrack(Int32, Int32) can be used to change track without creating a new stream.
The sample format of a CD audio stream is always 44100hz stereo 16-bit, unless the Float flag is used, in which case it's converted to 32-bit. When reading sub-channel data, the sample rate will be 45900hz, taking the additional sub-channel data into account.
When reading sub-channel data, BASSCD will automatically de-interleave the data if the drive can't. You can check whether the drive can de-interleave the data itself (or even read sub-channel data at all) in the the ReadWriteFlags member.
When using the Decode flag, it's not possible to play the stream, but seeking is still possible. Because the decoded sample data is not outputted, "decoding channels" can still be used when there is no output device (using the NoSoundDevice device with Init(Int32, Int32, DeviceInitFlags, IntPtr, IntPtr)).
CreateStream(Int32, Int32, BassFlags, CDDataProcedure, IntPtr)
Creates a sample stream from an audio CD track, optionally providing a callback function to receive sub-channel data and/or C2 error info.
Declaration
public static int CreateStream(int Drive, int Track, BassFlags Flags, CDDataProcedure Procedure, IntPtr User = null)
Parameters
Int32
Drive
The drive... 0 = the first drive. |
Int32
Track
The track... 0 = the first track, TrackPregap = 1st track pregap (not all drives support reading of the 1st track pregap). |
BassFlags
Flags
A combination of BassFlags. |
CDDataProcedure
Procedure
A callback function to receive sub-channel data and C2 error info... null = no callback. If a callback function is provided, sub-channel data and C2 error info will be delivered to it rather than being inserted amongst the sample data. |
IntPtr
User
User instance data to pass to the callback function. |
Returns
Int32
If successful, the new stream's handle is returned, else 0 is returned. Use LastError to get the error code. |
Remarks
This function is identical to CreateStream(Int32, Int32, BassFlags), but with the additional option of providing a callback function to receive sub-channel data and C2 error info.
CreateStream(String, BassFlags)
Creates a sample stream from an audio CD track, using a CDA file on the CD.
Declaration
public static int CreateStream(string File, BassFlags Flags)
Parameters
String
File
The CDA filename... for example, "D:\Track01.cda". |
BassFlags
Flags
A combination of BassFlags. |
Returns
Int32
If successful, the new stream's handle is returned, else 0 is returned. Use LastError to get the error code. |
Remarks
Only one stream can exist at a time per CD drive. If a stream using the drive already exists, this function will fail, unless the FreeOld config option is enabled. Note that StreamSetTrack(Int32, Int32) can be used to change track without creating a new stream.
The sample format of a CD audio stream is always 44100hz stereo 16-bit, unless the Float flag is used, in which case it's converted to 32-bit. When reading sub-channel data, the sample rate will be 45900hz, taking the additional sub-channel data into account.
When reading sub-channel data, BASSCD will automatically de-interleave the data if the drive can't. You can check whether the drive can de-interleave the data itself (or even read sub-channel data at all) in the the ReadWriteFlags member.
When using the Decode flag, it's not possible to play the stream, but seeking is still possible. Because the decoded sample data is not outputted, "decoding channels" can still be used when there is no output device (using the NoSoundDevice device with Init(Int32, Int32, DeviceInitFlags, IntPtr, IntPtr)).
CreateStream(String, BassFlags, CDDataProcedure, IntPtr)
Creates a sample stream from an audio CD track, using a CDA file on the CD, optionally providing a callback function to receive sub-channel data and/or C2 error info.
Declaration
public static int CreateStream(string File, BassFlags Flags, CDDataProcedure Procedure, IntPtr User = null)
Parameters
String
File
The CDA filename... for example, "D:\Track01.cda". |
BassFlags
Flags
A combination of BassFlags. |
CDDataProcedure
Procedure
A callback function to receive sub-channel data and C2 error info... null = no callback. If a callback function is provided, sub-channel data and C2 error info will be delivered to it rather than being inserted amongst the sample data. |
IntPtr
User
User instance data to pass to the callback function. |
Returns
Int32
If successful, the new stream's handle is returned, else 0 is returned. Use LastError to get the error code. |
Remarks
This function is identical to CreateStream(String, BassFlags), but with the additional option of providing a callback function to receive sub-channel data and C2 error info.
Door(Int32, CDDoorAction)
Opens, closes, locks or unlocks a drive door.
Declaration
public static bool Door(int Drive, CDDoorAction Action)
Parameters
Int32
Drive
The drive... 0 = the first drive. |
CDDoorAction
Action
The action to perform... one of CDDoorAction. |
Returns
Boolean
If successful, true is returned, else false is returned. Use LastError to get the error code. |
DoorIsLocked(Int32)
Checks if a drive door/tray is locked.
Declaration
public static bool DoorIsLocked(int Drive)
Parameters
Int32
Drive
The drive to check... 0 = the first drive. |
Returns
Boolean
true is returned if the door is locked, else false is returned. |
Remarks
It is not possible to get the drive's current door status via the WIO interface. So the last known status will be returned in that case, which may not be accurate if the door has been opened or closed by another application.
DoorIsOpen(Int32)
Checks if a drive door/tray is open.
Declaration
public static bool DoorIsOpen(int Drive)
Parameters
Int32
Drive
The drive to check... 0 = the first drive. |
Returns
Boolean
true is returned if the door is open, else false is returned. |
Remarks
It is not possible to get the drive's current door status via the WIO interface. So the last known status will be returned in that case, which may not be accurate if the door has been opened or closed by another application, or manually.
GetID(Int32, CDID)
Retrieves identification info from the CD in a drive.
Declaration
public static string GetID(int Drive, CDID ID)
Parameters
Int32
Drive
The drive... 0 = the first drive. |
CDID
ID
The identification to retrieve. For Text use GetIDText(Int32). |
Returns
String
The identication info on success, elsenull. Use LastError to get the error code. |
GetIDText(Int32)
Retrieves CD-Text identification info from the CD in a drive.
Declaration
public static string[] GetIDText(int Drive)
Parameters
Int32
Drive
The drive... 0 = the first drive. |
Returns
String[]
If an error occurs, null is returned, use LastError to get the error code. If successful, a string array of all CD-Text tags is returned in the form of "tag=text". |
Remarks
The returned identification string will remain in memory until the next call to this function, when it'll be overwritten by the next result. If you need to keep the contents of an identification string, then you should copy it before calling this function again.
GetInfo(Int32)
Retrieves information on a drive.
Declaration
public static CDInfo GetInfo(int Drive)
Parameters
Int32
Drive
The drive to get info on... 0 = the first drive. |
Returns
CDInfo
An instance of the CDInfo structure is returned. Throws BassException on Error. |
GetInfo(Int32, out CDInfo)
Retrieves information on a drive.
Declaration
public static bool GetInfo(int Drive, out CDInfo Info)
Parameters
Int32
Drive
The drive to get info on... 0 = the first drive. |
CDInfo
Info
An instance of the CDInfo structure to store the information at. |
Returns
Boolean
If successful, true is returned, else false is returned. Use LastError to get the error code. |
GetSpeed(Int32)
Retrieves the current read speed setting of a drive.
Declaration
public static int GetSpeed(int Drive)
Parameters
Int32
Drive
The drive... 0 = the first drive. |
Returns
Int32
If successful, the read speed (in KB/s) is returned, else -1 is returned. Use LastError to get the error code. |
Remarks
Divide the speed by 176.4 to get the real-time speed multiplier, eg. 5645 / 176.4 = "32x speed".
GetSpeedMultiplier(Int32)
Retrieves the current read speed multiplier of a drive.
Declaration
public static double GetSpeedMultiplier(int Drive)
Parameters
Int32
Drive
The drive... 0 = the first drive. |
Returns
Double
If successful, the read speed multiplier is returned, else -1 is returned. Use LastError to get the error code. |
GetTOC(Int32, TOCMode)
Retrieves the TOC from the CD in a drive.
Declaration
public static TOC GetTOC(int Drive, TOCMode Mode)
Parameters
Int32
Drive
The drive to get info on... 0 = the first drive. |
TOCMode
Mode
TOC Mode. |
Returns
TOC
If successful, an instance of the TOC strucure is returned. Throws BassException on Error. |
Remarks
This function gives the TOC in the form that it is delivered by the drive, except that the byte order may be changed to match the system's native byte order (the TOC is originally big-endian).
GetTOC(Int32, TOCMode, out TOC)
Retrieves the TOC from the CD in a drive.
Declaration
public static bool GetTOC(int Drive, TOCMode Mode, out TOC TOC)
Parameters
Int32
Drive
The drive to get info on... 0 = the first drive. |
TOCMode
Mode
TOC Mode. |
TOC
TOC
An instance of the TOC structure to store the information at. |
Returns
Boolean
If successful, true is returned, else false is returned. Use LastError to get the error code. |
Remarks
This function gives the TOC in the form that it is delivered by the drive, except that the byte order may be changed to match the system's native byte order (the TOC is originally big-endian).
GetTrackLength(Int32, Int32)
Retrieves the length (in bytes) of a track.
Declaration
public static int GetTrackLength(int Drive, int Track)
Parameters
Int32
Drive
The drive... 0 = the first drive. |
Int32
Track
The track to retrieve the length of... 0 = the first track. |
Returns
Int32
If an error occurs, -1 is returned, use LastError to get the error code. If successful, the length of the track is returned. |
Remarks
CD audio is always 44100hz stereo 16-bit. That's 176400 bytes per second. So dividing the track length by 176400 gives the length in seconds.
GetTrackPregap(Int32, Int32)
Retrieves the pregap length (in bytes) of a track.
Declaration
public static int GetTrackPregap(int Drive, int Track)
Parameters
Int32
Drive
The drive... 0 = the first drive. |
Int32
Track
The track to retrieve the pregap length of... 0 = the first track. |
Returns
Int32
If an error occurs, -1 is returned, use LastError to get the error code. If successful, the pregap length of the track is returned. To translate the pregap length from bytes to frames, divide by 2352. |
Remarks
The drive needs to support sub-channel reading in order to detect all but the first pregap length. ReadWriteFlags can be used to check whether the drive can read sub-channel data.
A track's pregap is actually played as part of the preceeding track. So to remove the gap from the end of a track, you would get the pregap length of the following track. The gap will usually contain silence, but it doesn't have to - it could contain crowd noise in a live recording, for example.
GetTracks(Int32)
Retrieves the number of tracks on the CD in a drive.
Declaration
public static int GetTracks(int Drive)
Parameters
Int32
Drive
The drive... 0 = the first drive. |
Returns
Int32
If an error occurs, -1 is returned, use LastError to get the error code. If successful, the number of tracks on the CD is returned. |
IsReady(Int32)
Checks if there is a CD ready in a drive.
Declaration
public static bool IsReady(int Drive)
Parameters
Int32
Drive
The drive to check... 0 = the first drive. |
Returns
Boolean
If there is a CD ready in the drive, then true is returned, else false is returned. |
Remarks
This function only returns true once there's a CD in the drive, and it's ready to be accessed.
Release(Int32)
Releases a drive to allow other applications to access it.
Declaration
public static bool Release(int Drive)
Parameters
Int32
Drive
The drive to release... 0 = the first drive. |
Returns
Boolean
If successful, then true is returned, else false is returned. Use LastError to get the error code. |
Remarks
When using the SPTI interface, some applications may require BassCd to release a CD drive before the app is able to use it. After a drive has been released, BassCd will attempt to re-acquire it in the next BassCd function call made on it.
SetInterface(CDInterface)
Sets the interface to use to access CD drives
Declaration
public static int SetInterface(CDInterface iface)
Parameters
CDInterface
iface
The interface to use, which can be one of the CDInterface values. |
Returns
Int32
If successful, the interface being used is returned, else -1 is returned. Use LastError to get the error code. |
Remarks
The interface can be changed at any time, but any existing CD streams will be freed in doing so. The current interface can also be reinitialized, to detect any newly connected drives.
Use of this function is optional. If it is not used, BassCd will automatically detect an available interface.
SetOffset(Int32, Int32)
Sets the read offset of a drive.
Declaration
public static bool SetOffset(int Drive, int Offset)
Parameters
Int32
Drive
The drive... 0 = the first drive. |
Int32
Offset
The offset (in samples; bytes/4) to set. |
Returns
Boolean
If successful, true is returned, else false is returned. Use LastError to get the error code. |
Remarks
This function can be used to compensate for the fact that most drives will read audio data from CDs at a slight offset from where they ideally should. Different drive models will have differing offsets.
When a negative offset is used, reading the beginning of the first track will require accessing the lead-in, and when a positive offset is used, reading the end of the last track will require accessing the lead-out. The drive may not support that (overreading), in which case those parts will be replaced with silence.
Changes do not affect an existing CD stream, unless StreamSetTrack(Int32, Int32) is called (and any sub-channel/C2 reading is using a CDDataProcedure).
SetSpeed(Int32, Int32)
Sets the read speed of a drive in KB/s.
Declaration
public static bool SetSpeed(int Drive, int Speed)
Parameters
Int32
Drive
The drive... 0 = the first drive. |
Int32
Speed
The speed, in KB/s. |
Returns
Boolean
If successful, true is returned, else false is returned. Use LastError to get the error code. |
Remarks
The speed is automatically restricted (rounded down) to what's supported by the drive, so may not be exactly what was requested. GetSpeed(Int32) can be used to check that. The maximum supported speed can be retrieved via GetInfo(Int32, out CDInfo).
To use a real-time speed multiplier, multiply it by 176.4 (and round up) to get the KB/s speed to use with this function, eg. "32x speed" = 32 * 176.4 = 5645.
StreamGetTrack(Int32)
Retrieves the drive and track number of a CD stream.
Declaration
public static int StreamGetTrack(int Handle)
Parameters
Int32
Handle
The CD stream handle. |
Returns
Int32
If an error occurs, -1 is returned, use LastError to get the error code. If successful, the track number is returned in the low word (low 16-bits), and the drive is returned in the high word (high 16-bits). |
Remarks
If the track has just changed, this function will give the new track number even if the old track is still being heard due to buffering.
The CDTrack mode can be used with
StreamSetTrack(Int32, Int32)
Changes the track of a CD stream.
Declaration
public static bool StreamSetTrack(int Handle, int Track)
Parameters
Int32
Handle
The CD stream handle. |
Int32
Track
The new track... 0 = the first track, TrackPregap = 1st track pregap (not all drives support reading of the 1st track pregap). |
Returns
Boolean
If successful, true is returned, else false is returned. Use LastError to get the error code. |