BASS.NET API for the Un4seen BASS Audio LibraryBassMixBASS_Mixer_StreamCreate Method BASS.NET API for the Un4seen BASS Audio Library
Creates a mixer stream.

Namespace: Un4seen.Bass.AddOn.Mix
Assembly: Bass.Net (in Bass.Net.dll) Version:

[DllImportAttribute("bassmix.dll", CharSet = CharSet.Unicode)]
public static int BASS_Mixer_StreamCreate(
	int freq,
	int chans,
	BASSFlag flags


Type: SystemInt32
The sample rate of the mixer output (e.g. 44100).
Type: SystemInt32
The number of channels... 1 = mono, 2 = stereo, 4 = quadraphonic, 6 = 5.1, 8 = 7.1. More than stereo requires WDM drivers (or the BASS_STREAM_DECODE flag) in Windows, and the SPEAKER flags are ignored.
Type: Un4seen.BassBASSFlag
Any combination of these flags (see BASSFlag):
BASS_SAMPLE_8BITSProduce 8-bit output. If neither this or the BASS_SAMPLE_FLOAT flags are specified, then the stream is 16-bit.
BASS_SAMPLE_FLOATProduce 32-bit floating-point output. WDM drivers or the BASS_STREAM_DECODE flag are required to use this flag in Windows. See Floating-point channels for more info.
BASS_SAMPLE_SOFTWAREForce the stream to not use hardware mixing. Note this only applies to playback of the mixer's output - the mixing of the source channels is always performed by BASSmix.
BASS_SAMPLE_3DUse 3D functionality. This is ignored if BASS_DEVICE_3D wasn't specified when calling BASS_Init(Int32, Int32, BASSInit, IntPtr). 3D streams must be mono (chans=1). The SPEAKER flags can not be used together with this flag.
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_MIXER_ENDEnd the stream when there are no active (including stalled) source channels, else it's never-ending.
BASS_MIXER_NONSTOPDon't stop producing output when there are no active source channels, else it will be stalled until there are active sources.
BASS_MIXER_RESUMEWhen stalled, resume the mixer immediately upon a new or unpaused source, else it will be resumed at the next update cycle.
BASS_MIXER_POSEXKeep a record of the source positions, making it possible to account for output latency when retrieving a source position. How far back the position record goes is determined by the BASS_CONFIG_MIXER_POSEX config option. If this flag is not used and neither is the BASS_STREAM_DECODE flag, then the mixer will automatically have a position record of equal length to the BASS_CONFIG_BUFFER setting.
BASS_STREAM_AUTOFREEAutomatically free the stream's resources 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.

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.

Source channels are "plugged" into a mixer using the BASS_Mixer_StreamAddChannel(Int32, Int32, BASSFlag) or BASS_Mixer_StreamAddChannelEx(Int32, Int32, BASSFlag, Int64, Int64) functions, and "unplugged" using the BASS_Mixer_ChannelRemove(Int32) function. Sources can be added and removed at any time, so a mixer does not have a predetermined length and BASS_ChannelGetLength(Int32, BASSMode) is not applicable. Likewise, seeking is not possible, except to position 0, as described below.

If the mixer output is being played (it is not a decoding channel), then there will be some delay in the effect of adding/removing source channels or changing their attributes being heard. This latency can be reduced by making use of the BASS_CONFIG_BUFFER and BASS_CONFIG_UPDATEPERIOD config options. The playback buffer can be flushed by calling BASS_ChannelPlay(Int32, Boolean) (restart = TRUE) or BASS_ChannelSetPosition(Int32, Int64, BASSMode) (pos = 0). That can also be done to restart a mixer that has ended.

Unless the BASS_MIXER_END flag is specified, a mixer stream will never end. When there are no sources (or the sources have ended/stalled), it'll produce no output until there's an active source. That's unless the BASS_MIXER_NONSTOP flag is used, in which case it will produce silent output while there are no active sources. The BASS_MIXER_END and BASS_MIXER_NONSTOP flags can be toggled at any time, using BASS_ChannelFlags(Int32, BASSFlag, BASSFlag).

Besides mixing channels, a mixer stream can be used as a resampler. In that case the freq parameter would be set the new sample rate, and the source channel's attributes would be left at their defaults. A mixer stream can also be used to downmix, upmix and generally rearrange channels, using the matrix mixing features.

ERROR CODEDescription
BASS_ERROR_INITBASS_Init(Int32, Int32, BASSInit, IntPtr) has not been successfully called.
BASS_ERROR_NOTAVAILOnly decoding streams (BASS_STREAM_DECODE) are allowed when using the "no sound" device.
BASS_ERROR_FREQfreq is out of range. See the minrate and maxrate members of the BASS_INFO structure.
BASS_ERROR_FORMATThe sample format is not supported by the device/drivers. If the stream is more than stereo or the BASS_SAMPLE_FLOAT flag is used, it could be that they 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 insufficent memory.
BASS_ERROR_NO3DCouldn't initialize 3D support for the stream.
BASS_ERROR_UNKNOWNSome other mystery problem!


Create a new mixer stream at 44kHz, stereo using floats - out of two source streams:
' this will be the final mixer output stream being played
Dim mixer As Integer = BassMix.BASS_Mixer_StreamCreate(44100, 2, BASSFlag.BASS_SAMPLE_FLOAT)
' now we need some channels to plug them in...create two decoding sources
Dim streamA As Integer = Bass.BASS_StreamCreateFile("testA.mp3", 0, 0, 
                              BASSFlag.BASS_STREAM_DECODE Or BASSFlag.BASS_SAMPLE_FLOAT)
Dim streamB As Integer = Bass.BASS_StreamCreateFile("testB.mp3", 0, 0, 
                              BASSFlag.BASS_STREAM_DECODE Or BASSFlag.BASS_SAMPLE_FLOAT)
' finally we plug them into the mixer (no downmix, since we assume the sources to be stereo)
Dim okA As Boolean = BassMix.BASS_Mixer_StreamAddChannel(mixer, streamA, BASSFlag.BASS_DEFAULT)
Dim okB As Boolean = BassMix.BASS_Mixer_StreamAddChannel(mixer, streamB, BASSFlag.BASS_DEFAULT)
' and play it...
Bass.BASS_ChannelPlay(mixer, False)
// this will be the final mixer output stream being played
int mixer = BassMix.BASS_Mixer_StreamCreate(44100, 2, BASSFlag.BASS_SAMPLE_FLOAT );
// now we need some channels to plug them in...create two decoding sources
int streamA = Bass.BASS_StreamCreateFile("testA.mp3", 0, 0, 
int streamB = Bass.BASS_StreamCreateFile("testB.mp3", 0, 0, 
// finally we plug them into the mixer (no downmix, since we assume the sources to be stereo)
bool okA = BassMix.BASS_Mixer_StreamAddChannel(mixer, streamA, BASSFlag.BASS_DEFAULT);
bool okB = BassMix.BASS_Mixer_StreamAddChannel(mixer, streamB, BASSFlag.BASS_DEFAULT);
// and play it...
Bass.BASS_ChannelPlay(mixer, false);
See Also