BASS_SampleCreate

Creates a new sample.

HSAMPLE BASS_SampleCreate(
    DWORD length,
    DWORD freq,
    DWORD chans,
    DWORD max,
    DWORD flags
);

Parameters

lengthThe sample's length, in bytes.
freqThe default sample rate.
chansThe number of channels... 1 = mono, 2 = stereo, etc.
maxMaximum number of simultaneous playbacks... 1 (min) - 65535 (max)... use one of the BASS_SAMPLE_OVER flags to choose the override decider, in the case of there being no free channel available for playback (ie. the sample is already playing max times).
flagsA combination of these flags.
BASS_SAMPLE_8BITSUse 8-bit resolution. If neither this or the BASS_SAMPLE_FLOAT flags are specified, then the sample is 16-bit.
BASS_SAMPLE_FLOATUse 32-bit floating-point sample data. Not really recommended for samples as it (at least) doubles the memory usage.
BASS_SAMPLE_LOOPLoop the sample.
BASS_SAMPLE_3DEnable 3D functionality. The sample must be mono (chans=1).
BASS_SAMPLE_MUTEMAXMute the sample when it is at (or beyond) its max distance (3D samples only).
BASS_SAMPLE_OVER_VOLOverride: the channel with the lowest volume is overridden.
BASS_SAMPLE_OVER_POSOverride: the longest playing channel is overridden.
BASS_SAMPLE_OVER_DISTOverride: the channel furthest away (from the listener) is overridden (3D samples only).

Return value

If successful, the new sample'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_ILLPARAMmax and/or length is invalid.
BASS_ERROR_FORMATThe sample format is not supported.
BASS_ERROR_MEMThere is insufficient memory.
BASS_ERROR_NO3DCould not initialize 3D support.
BASS_ERROR_UNKNOWNSome other mystery problem!

Remarks

The sample's initial content is undefined. BASS_SampleSetData should be used to set the sample's data.

To play a sample, first a channel must be obtained using BASS_SampleGetChannel, which can then be played using BASS_ChannelStart or BASS_ChannelPlay.

If you want to play a large or one-off sample, then it would probably be better to stream it instead with BASS_StreamCreate.

Example

Create a 440 Hz sine wave sample.
HSAMPLE sample = BASS_SampleCreate(256, 440 * 64, 1, 1, BASS_SAMPLE_LOOP | BASS_SAMPLE_OVER_POS); // create sample
short data[128]; // data buffer
int a;
for (a = 0; a < 128; a++)
    data[a] = (short)(32767.0 * sin(a * 6.283185 / 64)); // sine wave
BASS_SampleSetData(sample, data); // set the sample's data

See also

BASS_SampleFree, BASS_SampleGetChannel, BASS_SampleLoad, BASS_SampleSetData, BASS_StreamCreate