Creates a sample stream from a DSD file.

HSTREAM BASS_DSD_StreamCreateFile(
    BOOL mem,
    void *file,
    QWORD offset,
    QWORD length,
    DWORD flags,
    DWORD freq


memTRUE = stream the file from memory.
fileFilename (mem = FALSE) or a memory location (mem = TRUE).
offsetFile offset to begin streaming from (only used if mem = FALSE).
lengthData length... 0 = use all data up to the end of the file (if mem = FALSE).
flagsA combination of these flags.
BASS_SAMPLE_FLOATUse 32-bit floating-point sample data. See Floating-point channels for info. Otherwise the sample data will be 16-bit.
BASS_SAMPLE_3DEnable 3D functionality. The stream must be mono. The SPEAKER flags cannot be used together with this flag.
BASS_SAMPLE_LOOPLoop the file. This flag can be toggled at any time using BASS_ChannelFlags.
BASS_STREAM_AUTOFREEAutomatically free the stream when playback ends.
BASS_STREAM_DECODEDecode the sample data, without playing it. Use BASS_ChannelGetData to retrieve decoded sample data. The BASS_SAMPLE_3D, BASS_STREAM_AUTOFREE and SPEAKER flags cannot be used together with this flag.
BASS_DSD_DOPProduce DSD-over-PCM data with 0x05/0xFA markers. DSD-over-PCM data is 24-bit, so the BASS_SAMPLE_FLOAT flag is required.
BASS_DSD_DOP_AAProduce DSD-over-PCM data with 0xAA markers. DSD-over-PCM data is 24-bit, so the BASS_SAMPLE_FLOAT flag is required.
BASS_DSD_RAWProduce raw DSD data instead of PCM. The DSD data is in blocks of 8 bits (1 byte) per-channel with the MSB being first/oldest. DSD data is not playable by BASS, so the BASS_STREAM_DECODE flag is required.
BASS_SPEAKER_xxxSpeaker assignment flags. These flags have no effect when the stream is more than stereo.
BASS_ASYNCFILERead the file asynchronously. When enabled, the file is read and buffered in parallel with the decoding, to reduce the chances of the decoder being affected by I/O delays. This can be particularly useful with slow storage media and/or low latency output. The size of the file buffer is determined by the BASS_CONFIG_ASYNCFILE_BUFFER config option. This flag is ignored when streaming from memory (mem = TRUE).
BASS_UNICODEfile is in UTF-16 form. Otherwise it is ANSI on Windows or Windows CE, and UTF-8 on other platforms.
freqSample rate to convert the DSD data to PCM at... 0 = use the BASS_CONFIG_DSD_FREQ config setting. The rate will be rounded up (or down if there are none higher) to the nearest valid rate; the valid rates are 1/8, 1/16, 1/32, etc of the DSD rate down to a minimum of 44100 Hz. This parameter is ignored when the BASS_DSD_DOP or BASS_DSD_DOP_AA or BASS_DSD_RAW flag is specified.

Return value

If successful, the new stream's handle is returned, else 0 is returned. Use BASS_ErrorGetCode to get the error code.

Error codes

BASS_ERROR_INITBASS_Init has not been successfully called.
BASS_ERROR_ILLPARAMThe length must be specified when streaming from memory.
BASS_ERROR_FILEOPENThe file could not be opened.
BASS_ERROR_FILEFORMThe file's format is not recognised/supported.
BASS_ERROR_FORMATThe sample format is not supported.
BASS_ERROR_SPEAKERThe specified SPEAKER flags are invalid.
BASS_ERROR_MEMThere is insufficient memory.
BASS_ERROR_NO3DCould not initialize 3D support.
BASS_ERROR_UNKNOWNSome other mystery problem!


All DSD rates (including 48000 Hz variants like 3.072 MHz) with any number of channels are supported, in DSDIFF and DSF containers (DST encoding is not supported). WavPack DSD files are also supported if the BASSWV add-on (v2.4.6 or above) is loaded. The file's DSD sample rate is available via the BASS_ATTRIB_DSD_RATE attribute.

There are a few types of tag that may be available via BASS_ChannelGetTags. DSDIFF files may include artist and title information, which is available via the BASS_TAG_DSD_ARTIST and BASS_TAG_DSD_TITLE tags, which are ASCII strings. DSDIFF files can also include comments, which are available via the BASS_TAG_DSD_COMMENT+<index> tag (index=0 is the first comment), which gives a pointer to a TAG_DSD_COMMENT structure. DSF files may include ID3v2 tags, which are available via the BASS_TAG_ID3V2 tag. WavPack files may have ID3 and APEv2 tags, which are available via BASS_TAG_ID3 and BASS_TAG_APE.

DSD is 6dB quieter than PCM, so a 6dB gain will be applied by default when converting to PCM. That can be changed via the BASS_CONFIG_DSD_GAIN config option and the BASS_ATTRIB_DSD_GAIN attribute.

The DSD-over-PCM (BASS_DSD_DOP or BASS_DSD_DOP_AA) and raw DSD data (BASS_DSD_RAW) options allow supporting devices to play the DSD data directly, without converting to PCM. In both cases, the data needs to reach the device unmodified, so there can be no effects/resampling/mixing or anything else that will modify the data. Raw DSD data is playable with ASIO drivers that support DSD, eg. via BASSASIO. DSD-over-PCM data can be sent to a supporting device in any way that does not modify the data. If DSD-over-PCM data is played on a device that doesn't support it, then it will produce a low level noise. It is possible to switch between the 2 DSD-over-PCM options via BASS_ChannelFlags.

To stream a file from the internet, use BASS_DSD_StreamCreateURL. To stream from other locations, see BASS_DSD_StreamCreateFileUser.


Create a stream of a DSDIFF file with a sample rate of (at least) 88200 Hz.
HSTREAM stream=BASS_DSD_StreamCreateFile(FALSE, "file.dff", 0, 0, 0, 88200);

Play a DSDIFF file via WASAPI in DSD-over-PCM form.

stream=BASS_DSD_StreamCreateFile(FALSE, "file.dff", 0, 0, BASS_DSD_DOP|BASS_SAMPLE_FLOAT|BASS_STREAM_DECODE, 0); // open the DSD file in DoP mode
BASS_ChannelGetInfo(stream, &ci); // get the sample format
BASS_WASPAPI_Init(-1, ci.freq, ci.chans, BASS_WASAPI_EXCLUSIVE, 0.4, 0, WasapiProc, 0); // initialize the WASAPI output device


DWORD CALLBACK WasapiProc(void *buffer, DWORD length, void *user)
    DWORD r=BASS_ChannelGetData(stream, buffer, length); // get data from the DSD stream
    if (r==(DWORD)-1) r=0;
    return r;

See also


BASS_ChannelGetInfo, BASS_ChannelGetLength, BASS_ChannelGetTags, BASS_ChannelPlay, BASS_ChannelSetAttribute, BASS_ChannelSetDSP, BASS_ChannelSetFX, BASS_StreamFree, BASS_StreamGetFilePosition