BASS.NET API for the Un4seen BASS Audio LibraryBassBASS_StreamCreatePush Method BASS.NET API for the Un4seen BASS Audio Library
Creates a "push" stream (using the STREAMPROC_PUSH option).

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

public static int BASS_StreamCreatePush(
	int freq,
	int chans,
	BASSFlag flags,
	IntPtr user


Type: SystemInt32
The default sample rate. The sample rate can be changed using BASS_ChannelSetAttribute(Int32, BASSAttribute, Single).
Type: SystemInt32
The number of channels... 1 = mono, 2 = stereo, 4 = quadraphonic, 6 = 5.1, 8 = 7.1. More than stereo requires WDM drivers, and the SPEAKER flags are ignored.
Type: Un4seen.BassBASSFlag
Any combination of these flags (see BASSFlag):
BASS_SAMPLE_8BITSUse 8-bit resolution. If neither this or the BASS_SAMPLE_FLOAT flags are specified, then the stream is 16-bit.
BASS_SAMPLE_FLOATUse 32-bit floating-point sample data. WDM drivers or the BASS_STREAM_DECODE flag are required to use this flag. See Floating-point channels for more info.
BASS_SAMPLE_SOFTWAREForce the stream to not use hardware mixing.
BASS_SAMPLE_3DUse 3D functionality. This is ignored if BASS_DEVICE_3D wasn't specified when calling BASS_Init(Int32, Int32, BASSInit, IntPtr, 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_STREAM_AUTOFREEAutomatically free the stream's resources when it has reached the end, or 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.
Type: SystemIntPtr
User instance data to pass to the callback function.

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.

Instead of BASS pulling data from a STREAMPROC function, data is pushed to BASS via BASS_StreamPutData(Int32, IntPtr, Int32).

ERROR CODEDescription
BASS_ERROR_INITBASS_Init(Int32, Int32, BASSInit, IntPtr, IntPtr) has not been successfully called.
BASS_ERROR_NOTAVAILOnly decoding channels (BASS_STREAM_DECODE) are allowed when using the "no sound" device. The BASS_STREAM_AUTOFREE flag is also unavailable to decoding channels.
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.
BASS_ERROR_SPEAKERThe specified SPEAKER flags are invalid. The device/drivers do not support them, they are attempting to assign a stereo stream to a mono speaker or 3D functionality is enabled.
BASS_ERROR_MEMThere is insufficient memory.
BASS_ERROR_NO3DCould not initialize 3D support.
BASS_ERROR_UNKNOWNSome other mystery problem!


Away from Windows, all mixing is done in software (by BASS), so the BASS_SAMPLE_SOFTWARE flag is unnecessary. The BASS_SAMPLE_FX flag is also ignored.


Creating a stream duplicate:
Private _dupCallback As DSPPROC
' create stream on device 1
Dim orig As Integer = Bass.BASS_StreamCreateFile("test.mp3", 0, 0, BASSFlag.BASS_SAMPLE_LOOP)
Bass.BASS_ChannelPlay(orig, False)
' create a clone on device 2
Dim info As BASS_CHANNELINFO = Bass.BASS_ChannelGetInfo(stream)
Dim clone As Integer = Bass.BASS_StreamCreatePush(info.freq, info.chans, info.flags, IntPtr.Zero)
' pause source stream to synchonise buffer contents
Dim c As Integer = Bass.BASS_ChannelGetData(stream, IntPtr.Zero, CInt(BASSData.BASS_DATA_AVAILABLE))
Dim buf(c) As Byte
Bass.BASS_ChannelGetData(stream, buf, c)
Bass.BASS_StreamPutData(clone, buf, c)
' set DSP to copy new data from source stream
_dupCallback = New DSPPROC(DupDSP)
Bass.BASS_ChannelSetDSP(orig, _dupCallback, New IntPtr(clone), 0)
Bass.BASS_ChannelPlay(orig, False) ' resume source
Bass.BASS_ChannelPlay(clone, False) ' play clone
Private Sub DupDSP(handle As Integer, channel As Integer, 
                   buffer As IntPtr, length As Integer, user As IntPtr)
  Bass.BASS_StreamPutData(user.ToInt32(), buffer, length)
End Sub
private DSPPROC _dupCallback;
// create stream on device 1
int orig = Bass.BASS_StreamCreateFile("test.mp3", 0, 0, BASSFlag.BASS_SAMPLE_LOOP);
Bass.BASS_ChannelPlay(orig, false);
// create a clone on device 2
BASS_CHANNELINFO info = Bass.BASS_ChannelGetInfo(stream);
int clone = Bass.BASS_StreamCreatePush(info.freq, info.chans, info.flags, IntPtr.Zero);
// pause source stream to synchonise buffer contents
int c = Bass.BASS_ChannelGetData(stream, IntPtr.Zero, (int)BASSData.BASS_DATA_AVAILABLE);
byte[] buf = new byte[c];
Bass.BASS_ChannelGetData(stream, buf, c);
Bass.BASS_StreamPutData(clone, buf, c);
// set DSP to copy new data from source stream
_dupCallback = new DSPPROC(DupDSP);
Bass.BASS_ChannelSetDSP(orig, _dupCallback, new IntPtr(clone), 0);
Bass.BASS_ChannelPlay(orig, false); // resume source
Bass.BASS_ChannelPlay(clone, false); // play clone
private void DupDSP(int handle, int channel, IntPtr buffer, int length, IntPtr user)
  Bass.BASS_StreamPutData(user.ToInt32(), buffer, length);
See Also