BASS.NET API for the Un4seen BASS Audio LibraryBassMidiBASS_MIDI_StreamCreateFileUser Method BASS.NET API for the Un4seen BASS Audio Library
Creates a sample stream from a MIDI file via a user callback function.

Namespace: Un4seen.Bass.AddOn.Midi
Assembly: Bass.Net (in Bass.Net.dll) Version: 2.4.12.0
Syntax

[DllImportAttribute("bassmidi.dll", CharSet = CharSet.Unicode)]
public static int BASS_MIDI_StreamCreateFileUser(
	BASSStreamSystem system,
	BASSFlag flags,
	BASS_FILEPROCS procs,
	IntPtr user,
	int freq
)

Parameters

system
Type: Un4seen.BassBASSStreamSystem
File system to use, which must be STREAMFILE_NOBUFFER, as the entire MIDI file is preloaded.
flags
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 sample data will be 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 in Windows. See Floating-point channels for more info.
BASS_SAMPLE_MONODecode/play the stream (MP3/MP2/MP1 only) in mono, reducing the CPU usage (if it was originally stereo). This flag is automatically applied if BASS_DEVICE_MONO was specified when calling BASS_Init(Int32, Int32, BASSInit, IntPtr).
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). 3D streams must be mono. The SPEAKER flags can not be used together with this flag.
BASS_SAMPLE_LOOPLoop the file. This flag can be toggled at any time using BASS_ChannelFlags(Int32, BASSFlag, BASSFlag). This flag is ignored when streaming in blocks (BASS_STREAM_BLOCK).
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 when it ends. This allows you to stream a file and forget about it, as BASS will automatically 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.
BASS_MIDI_NOCROPDo not remove empty space (containing no events) from the end of the file.
BASS_MIDI_DECAYENDLet the ending decay naturally (including reverb), instead of stopping abruptly at the end of the file. This doesn't apply when looping. This flag can be toggled at any time using BASS_ChannelFlags(Int32, BASSFlag, BASSFlag).
BASS_MIDI_NOFXDisable reverb and chorus processing, saving some CPU time. This flag can be toggled at any time using BASS_ChannelFlags(Int32, BASSFlag, BASSFlag).
BASS_MIDI_NOSYSRESETIgnore system reset events (MIDI_EVENT_SYSTEM) when the system mode is unchanged. This flag can be toggled at any time using BASS_ChannelFlags(Int32, BASSFlag, BASSFlag).
BASS_MIDI_NOTEOFF1Only release the oldest instance upon a note off event (MIDI_EVENT_NOTE with velocity=0) when there are overlapping instances of the note. Otherwise all instances are released. This flag can be toggled at any time using BASS_ChannelFlags(Int32, BASSFlag, BASSFlag).
BASS_MIDI_SINCINTERUse sinc interpolated sample mixing. This increases the sound quality, but also requires more CPU. Otherwise linear interpolation is used.
procs
Type: Un4seen.BassBASS_FILEPROCS
The user defined file functions (see BASS_FILEPROCS).
user
Type: SystemIntPtr
User instance data to pass to the callback functions.
freq
Type: SystemInt32
Sample rate (in Hz) to render/play the MIDI at (0 = the rate specified in the BASS_Init(Int32, Int32, BASSInit, IntPtr) call; 1 = the device's current output rate or the BASS_Init rate if that is not available).

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.
Remarks

Works in the same way BASS_StreamCreateFileUser(BASSStreamSystem, BASSFlag, BASS_FILEPROCS, IntPtr) does - so for details look there.

As there is no file associated with a user file stream, it's not possible for BASSMIDI to look for a soundfont with the same name as the MIDI file. If there is a matching soundfont, it can be applied using BASS_MIDI_StreamSetFonts(Int32, BASS_MIDI_FONT, Int32).

Platform-specific

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. On Android and iOS, sinc interpolation requires a NEON-supporting CPU; the BASS_MIDI_SINCINTER flag will otherwise be ignored. Sinc interpolation is not available on Windows CE.

ERROR CODEDescription
BASS_ERROR_INITBASS_Init(Int32, Int32, BASSInit, 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_ILLPARAMsystem is not valid.
BASS_ERROR_FILEFORMThe file's format is not recognised/supported.
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 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!

Examples

See BASS_FILEPROCS.
See Also

Reference