BASS_MIDI_StreamCreate


Creates a sample stream to render real-time MIDI events.

HSTREAM BASS_MIDI_StreamCreate(
    DWORD channels,
    DWORD flags,
    DWORD freq
);

Parameters

channelsThe number of MIDI channels... 1 (min) - 128 (max). The number of channels can subsequently be changed via the BASS_ATTRIB_MIDI_CHANS attribute.
flagsA combination of these flags.
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. See Floating-point channels for more info.
BASS_SAMPLE_MONODecode/play the MIDI in mono (uses less CPU than stereo). This flag is automatically applied if BASS_DEVICE_MONO was specified when calling BASS_Init.
BASS_SAMPLE_SOFTWAREForce the stream to not use hardware DirectSound mixing.
BASS_SAMPLE_3DEnable 3D functionality. This requires that the BASS_DEVICE_3D flag was specified when calling BASS_Init. 3D channels must also be mono, so BASS_SAMPLE_MONO is automatically applied. The SPEAKER flags cannot be used together with this flag.
BASS_SAMPLE_FXEnable the old implementation of DirectX 8 effects. See the DX8 effect implementations section for details. Use BASS_ChannelSetFX to add effects to the stream.
BASS_STREAM_AUTOFREEAutomatically free the stream when playback ends.
BASS_STREAM_DECODEDecode/render the sample data, without playing it. Use BASS_ChannelGetData to retrieve decoded sample data. The BASS_SAMPLE_3D, BASS_STREAM_AUTOFREE and SPEAKER flags cannot be used together with this flag. The BASS_SAMPLE_SOFTWARE and BASS_SAMPLE_FX flags are also ignored.
BASS_SPEAKER_xxxSpeaker assignment flags. The BASS_SAMPLE_MONO flag is automatically applied when using a mono speaker assignment flag.
BASS_MIDI_NOFXDisable reverb and chorus processing, saving some CPU time. This flag can be toggled at any time using BASS_ChannelFlags.
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.
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.
freqSample rate to render/play the MIDI stream at... 0 = the rate specified in the BASS_Init call, 1 = the device's current output rate (or the BASS_Init rate if that is not available).

Return value

If successful, the new stream's handle is returned, else 0 is returned. Use BASS_ErrorGetCode to get the error code.

Error codes

BASS_ERROR_INITBASS_Init 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_ILLPARAMchannels is not valid.
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 or 3D functionality is enabled.
BASS_ERROR_MEMThere is insufficient memory.
BASS_ERROR_NO3DCould not initialize 3D support.
BASS_ERROR_UNKNOWNSome other mystery problem!

Remarks

This function creates a stream solely for real-time MIDI events. As it is not based on any file, the stream has no predetermined length and is never-ending. Seeking is not possible, but it is possible to reset everything, including playback buffer, by calling BASS_ChannelPlay (restart = TRUE) or BASS_ChannelSetPosition (pos = 0).

MIDI events are applied using the BASS_MIDI_StreamEvent and BASS_MIDI_StreamEvents functions. There may be some delay in the effect of the events being heard, due to buffering. This latency can be reduced via the BASS_ATTRIB_BUFFER attribute.

If the stream has 16 MIDI channels then channel 10 defaults to percussion/drums and the rest melodic, otherwise they are all melodic. That can be changed using BASS_MIDI_StreamEvent and the MIDI_EVENT_DRUMS event.

Soundfonts provide the sounds that are used to render a MIDI stream. A default soundfont configuration is applied initially to the new MIDI stream, which can subsequently be overridden using BASS_MIDI_StreamSetFonts. By default, linear interpolation will be used in playing the samples from the soundfonts. Sinc interpolation is also available via the BASS_ATTRIB_MIDI_SRC attribute, which increases the sound quality but also uses more CPU.

To play a MIDI file, use BASS_MIDI_StreamCreateFile.

See also

BASS_MIDI_StreamCreateEvents, BASS_MIDI_StreamCreateFile, BASS_MIDI_StreamEvent, BASS_MIDI_StreamEvents, BASS_MIDI_StreamGetChannel, BASS_MIDI_StreamSetFonts, BASS_ATTRIB_MIDI_CPU, BASS_ATTRIB_MIDI_SRC, BASS_CONFIG_MIDI_DEFFONT, BASS_CONFIG_MIDI_VOICES

BASS_ChannelGetInfo, BASS_ChannelPlay, BASS_ChannelSetAttribute, BASS_ChannelSetDSP, BASS_ChannelSetFX, BASS_ChannelSetLink, BASS_StreamFree