BASS_SampleCreate

Initiates the creation of a custom generated sample.

void* WINAPI BASS_SampleCreate(
    DWORD length,
    DWORD freq,
    DWORD max,
    DWORD flags
);

Parameters
lengthThe sample's length, in samples (ie. not bytes).
freqThe default sample rate... 100 (min) - 100000 (max)
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, else 16 bit.
BASS_SAMPLE_MONOMono, else stereo.
BASS_SAMPLE_LOOPLooped? Note that only complete sample loops are allowed by DirectSound (ie. you can't loop just part of a sample).
BASS_SAMPLE_SOFTWAREForce the sample to not use hardware mixing.
BASS_SAMPLE_VAM
requires DirectX 7.0 or above
Enables the DX7 voice allocation and management features on the sample, which allows the sample to be played in software or hardware. Do not use together with the BASS_SAMPLE_SOFTWARE flag.
BASS_SAMPLE_3DUse 3D functionality. This is ignored if BASS_DEVICE_3D wasn't specified when calling BASS_Init.
BASS_SAMPLE_MUTEMAXMute the sample when it is at (or beyond) it's max distance (3D samples only).
BASS_SAMPLE_OVER_VOLOverride: the channel with the lowest volume is overriden.
BASS_SAMPLE_OVER_POSOverride: the longest playing channel is overriden.
BASS_SAMPLE_OVER_DISTOverride: the channel furthest away (from the listener) is overriden (3D samples only).

Return value
If successful, a pointer to the memory location at which the sample data should be written is returned. If an error occured, NULL is returned. Use BASS_ErrorGetCode to get the error code.

Error codes
BASS_ERROR_INITBASS_Init has not been successfully called.
BASS_ERROR_ALREADYA sample is already being created. BASS_SampleCreateDone must be called to finish creating the previous sample, before trying to create another one.
BASS_ERROR_FREQfreq is out of range... DirectSound only allows sample rates between 100 and 100000.
BASS_ERROR_MEMThere is insufficent memory.
BASS_ERROR_NO3DCouldn't initialize 3D support for the sample.
BASS_ERROR_UNKNOWNSome other mystery problem!

Remarks
After writing the sample data to the memory location returned, call BASS_SampleCreateDone to finish the sample's creation and get a handle for the new sample.

The BASS_SAMPLE_VAM flag is ignored if the version of DirectX used is less than 7.0, you can check which version of DirectSound is being used with BASS_GetInfo.

Example
To create a 440hz sine-wave.

HSAMPLE handle;
int a;
short *data=BASS_SampleCreate(128, 28160, 1, BASS_SAMPLE_MONO|BASS_SAMPLE_LOOP|BASS_SAMPLE_OVER_POS);
for (a=0;a<128;a++)
    *data++=(int)(32767.0*sin((double)a*6.283185/64.0));
handle=BASS_SampleCreateDone(); // get the new sample's handle

See also
BASS_SampleCreateDone, BASS_SampleLoad