BASS.NET API for the Un4seen BASS Audio Library

BassCdBASS_CD_StreamCreate Method

BASS.NET API for the Un4seen BASS Audio Library
Creates a sample stream from an audio CD track.

Namespace:  Un4seen.Bass.AddOn.Cd
Assembly:  Bass.Net (in Bass.Net.dll) Version: 2.4.17.5
Syntax

[DllImportAttribute("basscd")]
public static int BASS_CD_StreamCreate(
	int drive,
	int track,
	BASSFlag flags
)

Parameters

drive
Type: SystemInt32
The drive... 0 = the first drive.
track
Type: SystemInt32
The track... 0 = the first track, BASS_CD_TRACK_PREGAP = 1st track pregap (not all drives support reading of the 1st track pregap).
flags
Type: Un4seen.BassBASSFlag
Any combination of these flags (see BASSFlag):
BASS_SAMPLE_FLOATUse 32-bit floating-point sample data. WDM drivers or the BASS_STREAM_DECODE flag are required to use this flag. See Floating-point channels for more info.
BASS_SAMPLE_SOFTWAREForce the stream to not use hardware mixing.
BASS_SAMPLE_LOOPLoop the file. This flag can be toggled at any time using BASS_ChannelFlags(Int32, BASSFlag, BASSFlag).
BASS_SAMPLE_FXRequires DirectX 8 or above: Enable the old implementation of DirectX 8 effects. See the DX8 effect implementations section for details. Use BASS_ChannelSetFX(Int32, BASSFXType, Int32) to add effects to the stream.
BASS_STREAM_AUTOFREEAutomatically free the stream's resources when it has reached the end, or when BASS_ChannelStop(Int32) (or BASS_Stop) is called.
BASS_STREAM_DECODEDecode the sample data, without outputting it. Use BASS_ChannelGetData(Int32, IntPtr, Int32) to retrieve decoded sample data. The BASS_SAMPLE_SOFTWARE, BASS_SAMPLE_3D, BASS_SAMPLE_FX, BASS_STREAM_AUTOFREE and SPEAKER flags can not be used together with this flag.
BASS_SPEAKER_xxxSpeaker assignment flags.
BASS_CD_SUBCHANNELRead sub-channel data. 96 bytes of de-interleaved sub-channel data will be returned after each 2352 bytes of audio. This flag can not be used with the BASS_SAMPLE_FLOAT flag, and is ignored if the BASS_STREAM_DECODE flag is not used.
BASS_CD_SUBCHANNEL_NOHWRead sub-channel data, without using any hardware de-interleaving. This is identical to the BASS_CD_SUBCHANNEL flag, except that the de-interleaving is always performed by BASSCD even if the drive is apparently capable of de-interleaving itself.
BASS_CD_C2ERRORSInclude C2 error info. 296 bytes of C2 error info is inserted after each 2352 bytes of audio (and optionally 96 bytes of sub-channel data). The first 294 bytes contain the C2 error bits (one bit for each byte of audio), followed by a byte containing the logical "OR" of all 294 bytes, which can be used to quickly check if there were any C2 errors. The final byte is just padding. This flag cannot be used without the BASS_STREAM_DECODE flag or with the BASS_SAMPLE_FLOAT flag; see BASS_CD_StreamCreateEx(Int32, Int32, BASSFlag, CDDATAPROC, IntPtr).

Return Value

Type: Int32
If successful, the new stream's handle is returned, else 0 is returned. Use BASS_ErrorGetCode 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 BASS_CONFIG_CD_FREEOLD config option is enabled (see BASS_SetConfig(BASSConfig, Int32)). Note that BASS_CD_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 BASS_SAMPLE_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 rwflags member of BASS_CD_INFO.

When using the BASS_STREAM_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 "no sound" device with BASS_Init(Int32, Int32, BASSInit, IntPtr, IntPtr)).

ERROR CODEDescription
BASS_ERROR_INITBASS_Init(Int32, Int32, BASSInit, IntPtr, IntPtr) has not been successfully called.
BASS_ERROR_DEVICEdrive is invalid.
BASS_ERROR_ALREADYA stream using this drive already exists.
BASS_ERROR_ILLPARAMThe BASS_CD_SUBCHANNEL and BASS_CD_C2ERRORS flags cannot be used without the BASS_STREAM_DECODE flag or with the BASS_SAMPLE_FLOAT flag. See BASS_CD_StreamCreateEx(Int32, Int32, BASSFlag, CDDATAPROC, IntPtr).
BASS_ERROR_NOCDThere's no CD in the drive.
BASS_ERROR_CDTRACKtrack is invalid.
BASS_ERROR_NOTAUDIOThe track is not an audio track.
BASS_ERROR_NOTAVAILReading sub-channel data and/or C2 error info is not supported by the drive, or a read offset is in effect. In case of the latter, see BASS_CD_StreamCreateEx(Int32, Int32, BASSFlag, CDDATAPROC, IntPtr).
BASS_ERROR_FORMATThe sample format is not supported by the device/drivers. If using the BASS_SAMPLE_FLOAT flag, it could be that floating-point channels are not supported (ie. no WDM drivers).
BASS_ERROR_SPEAKERThe device/drivers do not support the requested speaker(s), or you're attempting to assign a stereo stream to a mono speaker.
BASS_ERROR_MEMThere is insufficient memory.
BASS_ERROR_UNKNOWNSome other mystery problem!

Examples

Play an entire CD without any gap between tracks:
private SYNCPROC _mySync;  // make it global, so that the GC can not collect it
...
// create CD stream
int stream = BassCd.BASS_CD_StreamCreate(0, track, BASSFlag.BASS_DEFAULT | BASS_STREAM_AUTOFREE);
_mySync = new SYNCPROC(EndSync);
Bass.BASS_ChannelSetSync(stream, BASSSync.BASS_SYNC_END | BASSSync.BASS_SYNC_MIXTIME, 0, _mySync, IntPtr.Zero);
// start playing
Bass.BASS_ChannelPlay(stream, false);
...
private void EndSync(int handle, int channel, int data, IntPtr user)
{
  // get current track
  int track = Utils.LowWord32(BassCd.BASS_CD_StreamGetTrack(channel));
  // jump to next track
  BassCd.BASS_CD_StreamSetTrack(channel, track + 1);
}
See Also

Reference