Namespace: Un4seen.Bass
Assembly: Bass.Net (in Bass.Net.dll) Version: 2.4.17.2
[DllImportAttribute("bass")] public static int BASS_SampleCreate( int length, int freq, int chans, int max, BASSFlag flags )
Parameters
- length
- Type: SystemInt32
The sample's length, in bytes. - freq
- Type: SystemInt32
The default sample rate. - chans
- Type: SystemInt32
The number of channels... 1 = mono, 2 = stereo, etc... More than stereo requires WDM drivers in Windows. - max
- Type: SystemInt32
Maximum 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). - flags
- Type: Un4seen.BassBASSFlag
A combination of these flags (BASSFlag):BASS_SAMPLE_8BITS Use 8-bit resolution. If neither this or the BASS_SAMPLE_FLOAT flags are specified, then the sample is 16-bit. BASS_SAMPLE_FLOAT Use 32-bit floating-point sample data (not really recommended for samples). WDM drivers are required to use this flag in Windows. See Floating-point channels for more info. BASS_SAMPLE_LOOP Looped? Note that only complete sample loops are allowed, you can't loop just a part of the sample. More fancy looping can be achieved via streaming. BASS_SAMPLE_SOFTWARE Force the sample to not use hardware mixing. BASS_SAMPLE_VAM requires DirectX 7 or above: Enables the DX7 voice allocation and management features on the sample, which allows the sample to be played in software or hardware. This flag is ignored if the BASS_SAMPLE_SOFTWARE flag is also specified. BASS_SAMPLE_3D Use 3D functionality. This is ignored if BASS_DEVICE_3D wasn't specified when calling BASS_Init(Int32, Int32, BASSInit, IntPtr, IntPtr). 3D samples must be mono (use BASS_SAMPLE_MONO). BASS_SAMPLE_MUTEMAX Mute the sample when it is at (or beyond) it's max distance (software 3D samples only). BASS_SAMPLE_OVER_VOL Override: the channel with the lowest volume is overriden. BASS_SAMPLE_OVER_POS Override: the longest playing channel is overriden. BASS_SAMPLE_OVER_DIST Override: the channel furthest away (from the listener) is overriden (3D samples only).
Return Value
Type: Int32If successful, the new sample's handle is returned, else 0 is returned. Use BASS_ErrorGetCode to get the error code.
The sample's initial content is undefined. BASS_SampleSetData(Int32, IntPtr) should be used to set the sample's data.
Unless the BASS_SAMPLE_SOFTWARE flag is used, the sample will use hardware mixing if hardware resources are available. Use BASS_GetInfo(BASS_INFO) to see if there are hardware mixing resources available, and which sample formats are supported by the hardware. The BASS_SAMPLE_VAM flag allows a sample to be played by both hardware and software, with the decision made when the sample is played rather than when it's loaded. A sample's VAM options are set via BASS_SampleSetInfo(Int32, BASS_SAMPLE).
To play a sample, first a channel must be obtained using BASS_SampleGetChannel(Int32, BASSFlag), which can then be played using BASS_ChannelPlay(Int32, Boolean).
If you want to play a large or one-off sample, then it would probably be better to stream it instead with BASS_StreamCreate(Int32, Int32, BASSFlag, STREAMPROC, IntPtr).
ERROR CODE | Description |
---|---|
BASS_ERROR_INIT | BASS_Init(Int32, Int32, BASSInit, IntPtr, IntPtr) has not been successfully called. |
BASS_ERROR_NOTAVAIL | Sample functions are not available when using the "no sound" device. |
BASS_ERROR_ILLPARAM | max is invalid.. |
BASS_ERROR_FORMAT | The sample format is not supported by the device/drivers. If the sample is more than stereo or the BASS_SAMPLE_FLOAT flag is used, it could be that they are not supported. |
BASS_ERROR_MEM | There is insufficient memory. |
BASS_ERROR_NO3D | Could not initialize 3D support. |
BASS_ERROR_UNKNOWN | Some other mystery problem! |
Platform-specific
The BASS_SAMPLE_VAM flag requires DirectX 7 (or above). Away from Windows, all mixing is done in software (by BASS), so the BASS_SAMPLE_SOFTWARE flag is unnecessary.
// create the sample int sample = Bass.BASS_SampleCreate(256, 28160, 1, 1, BASSFlag.BASS_SAMPLE_LOOP | BASSFlag.BASS_SAMPLE_OVER_POS ); // the data buffer (256 byte = 128 Int16) short[] data = new short[128]; // create the sine wave for (int a=0; a<128; a++) data[a] = (short)(32767.0 * Math.Sin((double)a * 6.283185 / 64d)); // set the sample's data Bass.BASS_SampleSetData(sample, data); // get a sample channel int channel = Bass.BASS_SampleGetChannel(sample, false); // play it Bass.BASS_ChannelPlay(channel, false);