Class Bass
Wraps bass.dll.
Supports: .mp3, .ogg, .wav, .mp2, .mp1, .aiff, .m2a, .mpa, .m1a, .mpg, .mpeg, .aif, .mp3pro, .bwf, .mus, .mod, .mo3, .s3m, .xm, .it, .mtm, .umx, .mdz, .s3z, .itz, .xmz
Hello World
A simple Windows console application for playing an Mp3.
using System;
using ManagedBass;
namespace HelloWorld
{
class Program
{
static void Main(string[] args)
{
// Init BASS using the default output device
if (Bass.Init())
{
// Create a stream from a file
var stream = Bass.CreateStream("FILE.mp3");
if (stream != 0)
Bass.ChannelPlay(stream); // Play the stream
// Error creating the stream
else Console.WriteLine("Error: {0}!", Bass.LastError);
// Wait till user presses a key
Console.WriteLine("Press any key to exit");
Console.ReadKey();
// Free the stream
Bass.StreamFree(stream);
// Free current device.
Bass.Free();
}
else Console.WriteLine("BASS could not be initialized!");
}
}
}
Namespace: System.Dynamic.ExpandoObject
Assembly: ManagedBass.dll
Syntax
public static class Bass : object
Remarks
BASS is a multiplatform audio library. It's purpose is to provide the most powerful and efficient (yet easy to use), sample, stream, MOD music, and recording functions. All in a tiny DLL, under 100KB in size.
Fields
DefaultDevice
NoSoundDevice
Properties
Algorithm3D
The 3D algorithm for software mixed 3D channels.
Declaration
public static Algorithm3D Algorithm3D { get; set; }
Property Value
Algorithm3D
|
Remarks
These algorithms only affect 3D channels that are being mixed in software. ChannelGetInfo(Int32, out ChannelInfo) can be used to check whether a channel is being software mixed.
Changing the algorithm only affects subsequently created or loaded samples, musics, or streams; it does not affect any that already exist.
Platform-specific
On Windows, DirectX 7 or above is required for this option to have effect. On other platforms, only the Default and Off options are available.
AsyncFileBufferLength
The Buffer Length (in bytes) for asynchronous file reading (default setting is 65536 bytes (64KB)).
Declaration
public static int AsyncFileBufferLength { get; set; }
Property Value
Int32
|
Remarks
This will be rounded up to the nearest 4096 byte (4KB) boundary. This determines the amount of file data that can be read ahead of time with asynchronous file reading. Changes only affect streams that are created afterwards, not any that already exist. So it is possible to have streams with differing Buffer lengths by using this config option before creating each of them. When asynchronous file reading is enabled, the Buffer level is available from StreamGetFilePosition(Int32, FileStreamPosition).
CPUUsage
Retrieves the current CPU usage of BASS as a percentage of total CPU time.
Declaration
public static double CPUUsage { get; }
Property Value
Double
|
Remarks
This function includes the time taken to render stream (HSTREAM) and MOD music (HMUSIC) channels during playback, and any DSP functions set on those channels. It slso includes any FX that are not using the "with FX flag" DX8 effect implementation.
The rendering of some add-on stream formats may not be entirely included, if they use additional decoding threads. See the add-on documentation for details.
This function does not strictly tell the CPU usage, but rather how timely the processing is. For example, if it takes 10ms to render 100ms of data, that would be 10%. If the reported usage gets to 100%, that means the channel data is being played faster than it can be rendered, and Buffer underruns are likely to occur.
If automatic updating is disabled, then the value returned by this function is only updated after each call to Update(Int32). ChannelUpdate(Int32, Int32) usage is not included. The CPU usage of an individual channel is available via the CPUUsage attribute.
Platform-specific
On Windows, the CPU usage does not include sample channels (HCHANNEL), which are mixed by the output device/drivers (hardware mixing) or Windows (software mixing). On other platforms, the CPU usage does include sample playback as well as the generation of the final output mix.
CurrentDevice
Gets or sets the device setting of the current thread... 0 = no sound, 1 = first real output device.
Example
Create a stream of an MP3 file on device 2.
Bass.CurrentDevice = 2; // select device 2
var stream = Bass.CreateStream("afile.mp3"); // create the stream
Declaration
public static int CurrentDevice { get; set; }
Property Value
Int32
|
Remarks
A return value of -1 indicates error. Use LastError to get the error code. Throws BassException on Error while setting value.
Simultaneously using multiple devices is supported in the BASS API via a context switching system - instead of there being an extra "device" parameter in the function calls, the device to be used is set prior to calling the functions. The device setting is local to the current thread, so calling functions with different devices simultaneously in multiple threads is not a problem.
The functions that use the device selection are the following: Free(), GetDSoundObject(int), GetInfo(out BassInfo), Start(), Stop(), Pause(), Volume, Set3DFactors(Single, Single, Single), Get3DFactors(ref Single, ref Single, ref Single), Set3DPosition(Vector3D, Vector3D, Vector3D, Vector3D), Get3DPosition(ref Vector3D, ref Vector3D, ref Vector3D, ref Vector3D), SetEAXParameters, GetEAXParameters. It also determines which device is used by a new sample/stream/music: MusicLoad(String, Int64, Int32, BassFlags, Int32), SampleLoad(String, Int64, Int32, Int32, BassFlags), CreateStream(String, Int64, Int64, BassFlags), etc...
When one of the above functions is called, BASS will check the current thread's device setting, and if no device is selected (or the selected device is not initialized), BASS will automatically select the lowest device that is initialized. This means that when using a single device, there is no need to use this function; BASS will automatically use the device that is initialized. Even if you free the device, and initialize another, BASS will automatically switch to the one that is initialized.
CurrentRecordingDevice
Gets or Sets the recording device setting in the current thread... 0 = first recording device.
Example
Start recording on device 2.
// select device 2
Bass.CurrentRecordingDevice = 2;
// start recording
var hrecord = Bass.RecordStart(44100, 2, 0, MyRecordProc, IntPtr.Zero);
Declaration
public static int CurrentRecordingDevice { get; set; }
Property Value
Int32
|
Remarks
A value of -1 indicates error. Use LastError to get the error code. Throws BassException on Error while setting value.
Simultaneously using multiple devices is supported in the BASS API via a context switching system - instead of there being an extra "device" parameter in the function calls, the device to be used is set prior to calling the functions. The device setting is local to the current thread, so calling functions with different devices simultaneously in multiple threads is not a problem.
The functions that use the recording device selection are the following: RecordFree(), RecordGetInfo(out RecordInfo), RecordGetInput(Int32, out Single), RecordGetInputName(Int32), RecordSetInput(Int32, InputFlags, Single), RecordStart(Int32, Int32, BassFlags, RecordProcedure, IntPtr).
When one of the above functions is called, BASS will check the current thread's recording device setting, and if no device is selected (or the selected device is not initialized), BASS will automatically select the lowest device that is initialized. This means that when using a single device, there is no need to use this function - BASS will automatically use the device that's initialized. Even if you free the device, and initialize another, BASS will automatically switch to the one that is initialized.
See Also
DeviceBufferLength
Linux, Android and CE only: The output device Buffer Length in milliseconds.
Declaration
public static int DeviceBufferLength { get; set; }
Property Value
Int32
|
Remarks
The device Buffer is where the final mix of all playing channels is placed, ready for the device to play. Its Length affects the latency of things like starting and stopping playback of a channel, so you will probably want to avoid setting it unnecessarily high, but setting it too short could result in breaks in the output. When using a large device Buffer, the NoBuffer attribute could be used to skip the channel buffering stage, to avoid further increasing latency for real-time generated sound and/or DSP/FX changes. Changes to this config setting only affect subsequently initialized devices, not any that are already initialized. This config option is only available on Linux, Android and Windows CE. The device's Buffer is determined automatically on other platforms. Platform-specific: On Linux, the driver may choose to use a different Buffer Length if it decides that the specified Length is too short or long. The Buffer Length actually being used can be obtained with BassInfo, like this: Latency + MinBufferLength / 2.
DeviceCount
Gets the number of Playback Devices available.
Declaration
public static int DeviceCount { get; }
Property Value
Int32
|
DeviceNonStop
Do not stop the output device when nothing is playing on it?
Declaration
public static bool DeviceNonStop { get; set; }
Property Value
Boolean
|
FileVerificationBytes
The amount of data (in bytes) to check in order to verify/detect the file format... 1000 (min) to 100000 (max). (default = 16000 bytes).
Declaration
public static int FileVerificationBytes { get; set; }
Property Value
Int32
|
Remarks
If the value specified is outside this range, it is automatically capped. Of the file formats supported as standard, this setting only affects the detection of MP3/MP2/MP1 formats, but it may also be used by add-ons (see the documentation). For internet (and "buffered" User file) streams, a quarter of the Length is used, up to a minimum of 1000 bytes. The verification Length excludes any tags that may be at the start of the file. For internet (and "buffered" User file) streams, the NetVerificationBytes setting determines how much data is checked.
Float
Gets if Floating-Point audio is supported on the current platform.
Declaration
public static bool Float { get; }
Property Value
Boolean
|
FloatingPointDSP
Pass 32-bit floating-point sample data to all DSPProcedure callback functions.
Declaration
public static bool FloatingPointDSP { get; set; }
Property Value
Boolean
|
Remarks
Normally DSP functions receive sample data in whatever format the channel is using, ie. it can be 8, 16 or 32-bit. But using this config option, BASS will convert 8/16-bit sample data to 32-bit floating-point before passing it to DSP functions, and then convert it back after all the DSP functions are done. As well as simplifying the DSP code (no need for 8/16-bit processing), this also means that there is no degradation of quality as sample data passes through a chain of DSP. This config option also applies to effects set via ChannelSetFX(Int32, EffectType, Int32), except for DX8 effects when using the "With FX flag" DX8 effect implementation. Changing the setting while there are DSP or FX set could cause problems, so should be avoided.
Platform-specific: On Android and Windows CE, 8.24 bit fixed-point is used instead of floating-point. Floating-point DX8 effect processing requires DirectX 9 (or above) on Windows.
FTPPassive
Use passive mode in FTP connections? (default = true) Changes take effect from the next internet stream creation call.
Declaration
public static bool FTPPassive { get; set; }
Property Value
Boolean
|
GlobalMusicVolume
Global music volume level... 0 (silent) - 10000 (full).
Declaration
public static int GlobalMusicVolume { get; set; }
Property Value
Int32
|
Remarks
This config option allows you to have control over the volume levels of all the MOD musics, which is useful for setup options (eg. separate music and fx volume controls). A channel's final volume = channel volume * global volume / max volume. So, for example, if a stream channel's volume is 0.5 and the global stream volume is 8000, then effectively the stream's volume level is 0.4 (0.5 * 8000 / 10000 = 0.4).
GlobalSampleVolume
Global sample volume level... 0 (silent) - 10000 (full).
Declaration
public static int GlobalSampleVolume { get; set; }
Property Value
Int32
|
Remarks
This config option allows you to have control over the volume levels of all the samples, which is useful for setup options (eg. separate music and fx volume controls). A channel's final volume = channel volume * global volume / max volume. So, for example, if a stream channel's volume is 0.5 and the global stream volume is 8000, then effectively the stream's volume level is 0.4 (0.5 * 8000 / 10000 = 0.4).
GlobalStreamVolume
Global stream volume level... 0 (silent) - 10000 (full).
Declaration
public static int GlobalStreamVolume { get; set; }
Property Value
Int32
|
Remarks
This config option allows you to have control over the volume levels of all streams, which is useful for setup options (eg. separate music and fx volume controls). A channel's final volume = channel volume * global volume / max volume. So, for example, if a stream channel's volume is 0.5 and the global stream volume is 8000, then effectively the stream's volume level is 0.4 (0.5 * 8000 / 10000 = 0.4).
HandleCount
Gets the total number of HSTREAM/HSAMPLE/HMUSIC/HRECORD handles.
Declaration
public static int HandleCount { get; }
Property Value
Int32
|
Remarks
The Handle count may not only include the app-created stuff but also internal stuff.
Info
Retrieves information on the device being used.
Declaration
public static BassInfo Info { get; }
Property Value
BassInfo
BassInfo structure with the retreived information. Throws BassException on Error. |
Remarks
When using multiple devices, the current thread's device setting (as set with CurrentDevice) determines which device this function call applies to.
LastError
Gets the Error that occured on the Last Bass function that was called.
Declaration
public static Errors LastError { get; }
Property Value
Errors
|
LogarithmicPanningCurve
Panning translation curve... false = Linear (Default), true = Logarithmic.
Declaration
public static bool LogarithmicPanningCurve { get; set; }
Property Value
Boolean
|
Remarks
The panning curve affects panning in exactly the same way as the LogarithmicVolumeCurve affects the volume.
LogarithmicVolumeCurve
Volume translation curve... false = Linear (Default), true = Logarithmic.
Declaration
public static bool LogarithmicVolumeCurve { get; set; }
Property Value
Boolean
|
Remarks
DirectSound uses logarithmic volume and panning curves, which can be awkward to work with. For example, with a logarithmic curve, the audible difference between 10000 and 9000, is not the same as between 9000 and 8000. With a linear "curve" the audible difference is spread equally across the whole range of values, so in the previous example the audible difference between 10000 and 9000, and between 9000 and 8000 would be identical. When using the linear curve, the volume range is from 0% (silent) to 100% (full). When using the logarithmic curve, the volume range is from -100 dB (effectively silent) to 0 dB (full). For example, a volume level of 0.5 is 50% linear or -50 dB logarithmic.
MusicVirtial
The maximum number of virtual channels to use in the rendering of IT files... 1 (min) to 512 (max). (default = 64).
Declaration
public static int MusicVirtial { get; set; }
Property Value
Int32
|
Remarks
If the value specified is outside this range, it is automatically capped. This setting only affects IT files, as the other MOD music formats do not have virtual channels. Changes only apply to subsequently loaded files, not any that are already loaded.
NetAgent
The "User-Agent" request header sent to servers.
Declaration
public static string NetAgent { get; set; }
Property Value
String
|
NetBufferLength
The internet download Buffer Length, in milliseconds.
Declaration
public static int NetBufferLength { get; set; }
Property Value
Int32
|
Remarks
Increasing the Buffer Length decreases the chance of the stream stalling, but also increases the time taken by CreateStream(String, Int32, BassFlags, DownloadProcedure, IntPtr) to create the stream, as it has to pre-Buffer more data (adjustable via the NetPreBuffer option). Aside from the pre-buffering, this setting has no effect on streams without either the StreamDownloadBlocks or RestrictDownloadRate flags. When streaming in blocks, this option determines the download Buffer Length. The effective Buffer Length can actually be a bit more than that specified, including data that has been read from the Buffer by the decoder but not yet decoded. This config option also determines the buffering used by "buffered" User file streams created with CreateStream(StreamSystem, BassFlags, FileProcedures, IntPtr). The default Buffer Length is 5 seconds (5000 milliseconds). The net Buffer Length should be larger than the Length of the playback Buffer (PlaybackBufferLength), otherwise the stream is likely to briefly stall soon after starting playback. Using this config option only affects streams created afterwards, not any that have already been created.
NetPlaylist
Process URLs in PLS, M3U, WPL or ASX playlists?... 0 = never (Default), 1 = in CreateStream(String, Int32, BassFlags, DownloadProcedure, IntPtr) only, 2 = in CreateStream(String, Int64, Int64, BassFlags) and CreateStream(StreamSystem, BassFlags, FileProcedures, IntPtr) too.
Declaration
public static int NetPlaylist { get; set; }
Property Value
Int32
|
Remarks
When enabled, BASS will process PLS, M3U, WPL and ASX playlists, going through each entry until it finds a URL that it can play.
NetPreBuffer
Amount (percentage) to pre-Buffer when opening internet streams. (default = 75%)
Declaration
public static int NetPreBuffer { get; set; }
Property Value
Int32
|
Remarks
This setting determines what percentage of the Buffer Length (NetBufferLength) should be filled by CreateStream(String, Int32, BassFlags, DownloadProcedure, IntPtr). Setting this lower (eg. 0) is useful if you want to display a "buffering progress" (using StreamGetFilePosition(Int32, FileStreamPosition)) when opening internet streams, but note that this setting is just a minimum. BASS will always pre-download a certain amount to verify the stream. As well as internet streams, this config setting also applies to "buffered" User file streams created with CreateStream(StreamSystem, BassFlags, FileProcedures, IntPtr).
NetProxy
Proxy server settings (in the form of "User:pass@server:port"... null = don't use a proxy). "" (empty string) = use the OS's default proxy settings.
Declaration
public static string NetProxy { get; set; }
Property Value
String
|
Remarks
If only the "User:pass@" part is specified, then those authorization credentials are used with the default proxy server. If only the "server:port" part is specified, then that proxy server is used without any authorization credentials. Changes take effect from the next internet stream creation call.
NetReadTimeOut
The time (in milliseconds) to wait for a server to deliver more data for an internet stream. (default=0, infinite). When the timeout is hit, the connection with the server will be closed.
Declaration
public static int NetReadTimeOut { get; set; }
Property Value
Int32
|
NetTimeOut
Time (in milliseconds) to wait for a server to respond to a connection request. The default timeout is 5 seconds (5000 milliseconds).
Declaration
public static int NetTimeOut { get; set; }
Property Value
Int32
|
NetVerificationBytes
The amount of data to check (in bytes) in order to verify/detect the file format of internet streams... 1000 (min) to 1000000 (max), or 0 = 25% of the FileVerificationBytes setting (with a minimum of 1000 bytes).
Declaration
public static int NetVerificationBytes { get; set; }
Property Value
Int32
|
Remarks
If the value specified is outside this range, it is automatically capped. Of the file formats supported as standard, this setting only affects the detection of MP3/MP2/MP1 formats, but it may also be used by add-ons (see the documentation). The verification Length excludes any tags that may be found at the start of the file. The default setting is 0, which means 25% of the FileVerificationBytes setting. As well as internet streams, this config setting also applies to "buffered" User file streams created with CreateStream(StreamSystem, BassFlags, FileProcedures, IntPtr).
OggPreScan
Pre-scan chained OGG files? (enabled by default)
Declaration
public static bool OggPreScan { get; set; }
Property Value
Boolean
|
Remarks
This option is equivalent to including the Prescan flag in a CreateStream(String, Int64, Int64, BassFlags) call when opening an OGG file. It can be disabled if seeking and an accurate Length reading are not required from chained OGG files, for faster stream creation.
PauseNoPlay
Prevent channels being played when the output is paused? (default = true)
Declaration
public static int PauseNoPlay { get; set; }
Property Value
Int32
|
Remarks
PlaybackBufferLength
The Buffer Length in milliseconds (default = 500).
Example
Use the recommended minimum buffer length with 1ms margin.
// get update period
var len = Bass.UpdatePeriod;
// retrieve device info
BassInfo info;
Bass.GetInfo(out info);
// add the 'minbuf' plus 1ms margin
len += info.MinimumBufferLength + 1;
// set the buffer length
Bass.PlaybackBufferLength = len;
Declaration
public static int PlaybackBufferLength { get; set; }
Property Value
Int32
|
Remarks
The minimum Length is 1ms above the update period (See UpdatePeriod), the maximum is 5000 milliseconds. If the Length specified is outside this range, it is automatically capped. Increasing the Length, decreases the chance of the sound possibly breaking-up on slower computers, but also increases the latency for DSP/FX.
Small Buffer lengths are only required if the sound is going to be changing in real-time, for example, in a soft-synth. If you need to use a small Buffer, then the MinBufferLength should be used to get the recommended minimum Buffer Length supported by the device and it's drivers. Even at this default Length, it's still possible that the sound could break up on some systems, it's also possible that smaller buffers may be fine. So when using small buffers, you should have an option in your software for the User to finetune the Length used, for optimal performance. Using this config option only affects the HMUSIC/HSTREAM channels that you create afterwards, not the ones that have already been created. So you can have channels with differing Buffer lengths by using this config option each time before creating them. If automatic updating is disabled, make sure you call Update(Int32) frequently enough to keep the buffers updated.
RecordingBufferLength
The Buffer Length for recording channels in milliseconds... 1000 (min) - 5000 (max). default = 2000.
Declaration
public static int RecordingBufferLength { get; set; }
Property Value
Int32
|
Remarks
If the Length specified is outside this range, it is automatically capped. Unlike a playback Buffer, where the aim is to keep the Buffer full, a recording Buffer is kept as empty as possible and so this setting has no effect on latency. Unless processing of the recorded data could cause significant delays, or you want to use a large recording period with RecordStart(Int32, Int32, BassFlags, RecordProcedure, IntPtr), there should be no need to increase this. Using this config option only affects the recording channels that are created afterwards, not any that have already been created. So you can have channels with differing Buffer lengths by using this config option each time before creating them.
RecordingDeviceCount
No of Recording devices available.
Declaration
public static int RecordingDeviceCount { get; }
Property Value
Int32
|
RecordingInfo
Retrieves information on the recording device being used.
Declaration
public static RecordInfo RecordingInfo { get; }
Property Value
RecordInfo
An instance of the RecordInfo structure is returned. Throws BassException on Error. |
SampleSRCQuality
Gets or Sets the default sample rate conversion quality for samples... 0 = linear interpolation (Default), 1 = 8 point sinc interpolation, 2 = 16 point sinc interpolation, 3 = 32 point sinc interpolation. Other values are also accepted.
Declaration
public static int SampleSRCQuality { get; set; }
Property Value
Int32
|
Remarks
This config option determines what sample rate conversion quality a new sample channel will initially have, following a SampleGetChannel(Int32, Boolean) call. The channel's sample rate conversion quality can subsequently be changed via the SampleRateConversion attribute (see ChannelSetAttribute(Int32, ChannelAttribute, Single)).
SRCQuality
Gets or Sets the default sample rate conversion quality... 0 = linear interpolation, 1 = 8 point sinc interpolation (Default), 2 = 16 point sinc interpolation, 3 = 32 point sinc interpolation. Other values are also accepted.
Declaration
public static int SRCQuality { get; set; }
Property Value
Int32
|
Remarks
This config option determines what sample rate conversion quality new channels will initially have, except for sample channels (HCHANNEL), which use the SampleSRCQuality setting. A channel's sample rate conversion quality can subsequently be changed via the SampleRateConversion attribute (see ChannelSetAttribute(Int32, ChannelAttribute, Single)).
SupportedFormats
Gets the Formats supported by Bass separated by ;
. The list is not necessarily complete.
Declaration
public static string SupportedFormats { get; }
Property Value
String
|
SuppressMP3ErrorCorruptionSilence
Suppress silencing for corrupted MP3 frames. (default is false).
Declaration
public static bool SuppressMP3ErrorCorruptionSilence { get; set; }
Property Value
Boolean
|
Remarks
When BASS is detecting some corruption in an MP3 file's Huffman coding, it silences the frame to avoid any unpleasent noises that can result from corruption. Set this parameter to true in order to suppress this behavior. This applies only to the regular BASS version and NOT the "mp3-free" version.
UpdatePeriod
The update period of HSTREAM and HMUSIC channel playback buffers in milliseconds.
Declaration
public static int UpdatePeriod { get; set; }
Property Value
Int32
|
Remarks
0 = disable automatic updating. The minimum period is 5ms, the maximum is 100ms. If the period specified is outside this range, it is automatically capped. The default period is 100ms.
The update period is the amount of time between updates of the playback buffers of HSTREAM/HMUSIC channels. Shorter update periods allow smaller buffers to be set with the PlaybackBufferLength option, but as the rate of updates increases, so the overhead of setting up the updates becomes a greater part of the CPU usage. The update period only affects HSTREAM and HMUSIC channels, it does not affect samples. Nor does it have any effect on decoding channels, as they are not played. BASS creates one or more threads (determined by UpdateThreads) specifically to perform the updating, except when automatic updating is disabled (period=0) - then you must regularly call Update(Int32) or ChannelUpdate(Int32, Int32) instead. This allows you to synchronize BASS's CPU usage with your program's. For example, in a game loop you could call Update(Int32) once per frame, which keeps all the processing in sync so that the frame rate is as smooth as possible. Update(Int32) should be called at least around 8 times per second, even more often if the PlaybackBufferLength option is used to set smaller buffers. The update period can be altered at any time, including during playback.
UpdateThreads
The number of threads to use for updating playback buffers... 0 = Disable automatic updating.
Declaration
public static int UpdateThreads { get; set; }
Property Value
Int32
|
Remarks
The number of update threads determines how many HSTREAM/HMUSIC channel playback buffers can be updated in parallel; each thread can process one channel at a time. The default is to use a single thread, but additional threads can be used to take advantage of multiple CPU cores. There is generally nothing much to be gained by creating more threads than there are CPU cores, but one benefit of using multiple threads even with a single CPU core is that a slow updating channel need not delay the updating of other channels. When automatic updating is disabled (threads = 0), Update(Int32) or ChannelUpdate(Int32, Int32) should be used instead. The number of update threads can be changed at any time, including during playback.
Platform-specific: The number of update threads is limited to 1 on Windows CE platforms.
Version
Retrieves the version of BASS that is loaded
Declaration
public static Version Version { get; }
Property Value
Version
|
Volume
Gets or sets the current output master volume level... 0 (silent) to 1 (max).
Declaration
public static double Volume { get; set; }
Property Value
Double
|
Remarks
When using multiple devices, the current thread's device setting (as set with CurrentDevice) determines which device this function call applies to.
A return value of -1 indicates error. Use LastError to get the error code. Throws BassException on Error while setting value.
The actual volume level may not be exactly the same as set, due to underlying precision differences.
This function affects the volume level of all applications using the same output device. If you wish to only affect the level of your app's sounds, ChannelSetAttribute(Int32, ChannelAttribute, Single) and/or the GlobalMusicVolume, GlobalSampleVolume and GlobalStreamVolume config options should be used instead.
Methods
Apply3D()
Applies changes made to the 3D system.
Declaration
public static void Apply3D()
Remarks
This function must be called to apply any changes made with Set3DFactors(Single, Single, Single), Set3DPosition(Vector3D, Vector3D, Vector3D, Vector3D), ChannelSet3DAttributes(Int32, Mode3D, Single, Single, Int32, Int32, Single) or ChannelSet3DPosition(Int32, Vector3D, Vector3D, Vector3D). This allows multiple changes to be synchronized, and also improves performance.
This function applies 3D changes on all the initialized devices. There's no need to re-call it for each individual device when using multiple devices.
See Also
ChannelAddFlag(Int32, BassFlags)
Adds a flag to a channel.
Declaration
public static bool ChannelAddFlag(int Handle, BassFlags Flag)
Parameters
Int32
Handle
The channel Handle... a HCHANNEL, HMUSIC, HSTREAM. |
BassFlags
Flag
see BassFlags |
Returns
Boolean
|
ChannelBytes2Seconds(Int32, Int64)
Translates a byte position into time (seconds), based on a channel's format.
Declaration
public static double ChannelBytes2Seconds(int Handle, long Position)
Parameters
Int32
Handle
The channel Handle... a HCHANNEL, HMUSIC, HSTREAM, or HRECORD. HSAMPLE handles may also be used. |
Int64
Position
The position in Bytes to translate. |
Returns
Double
If successful, then the translated Length in seconds is returned, else a negative value is returned. Use LastError to get the error code. |
Remarks
The translation is based on the channel's initial sample rate, when it was created.
ChannelFlags(Int32, BassFlags, BassFlags)
Modifies and retrieves a channel's flags.
Declaration
public static BassFlags ChannelFlags(int Handle, BassFlags Flags, BassFlags Mask)
Parameters
Int32
Handle
The channel Handle... a HCHANNEL, HMUSIC, HSTREAM. |
||||||||||||||||||||||||||||||||
BassFlags
Flags
A combination of these flags:
|
||||||||||||||||||||||||||||||||
BassFlags
Mask
The flags (as above) to modify. Flags that are not included in this are left as they are, so it can be set to 0 in order to just retrieve the current flags. To modify the speaker flags, any of the Speaker flags can be used in the mask (no need to include all of them). |
Returns
BassFlags
If successful, the channel's updated flags are returned, else -1 is returned. Use LastError to get the error code. |
Remarks
Some flags may not be adjustable in some circumstances, so the return value should be checked to confirm any changes. The flags listed above are just the flags that can be modified, and there may be additional flags present in the return value. See the ChannelInfo documentation for a full list of flags.
Streams that are created by add-ons may have additional flags available. There is a limited number of possible flag values though, so some add-ons may use the same flag value for different things. This means that when using add-on specific flags with a stream created via the plugin system, it is a good idea to first confirm that the add-on is handling the stream, by checking its ctype via ChannelGetInfo(Int32, out ChannelInfo).
During playback, the effects of flag changes are not heard instantaneously, due to buffering. To reduce the delay, use the PlaybackBufferLength config option to reduce the Buffer Length.
ChannelGet3DAttributes(Int32, ref Mode3D, ref Single, ref Single, ref Int32, ref Int32, ref Single)
Retrieves the 3D attributes of a sample, stream, or MOD music channel with 3D functionality.
Declaration
public static bool ChannelGet3DAttributes(int Handle, ref Mode3D Mode, ref float Min, ref float Max, ref int iAngle, ref int oAngle, ref float OutVol)
Parameters
Int32
Handle
The channel handle... a HCHANNEL, HMUSIC, HSTREAM. |
Mode3D
Mode
The 3D processing mode (see Mode3D). |
Single
Min
The minimum distance. |
Single
Max
The maximum distance. |
Int32
iAngle
The angle of the inside projection cone. |
Int32
oAngle
The angle of the outside projection cone. |
Single
OutVol
The delta-volume outside the outer projection cone. |
Returns
Boolean
If succesful, then true is returned, else false is returned. Use LastError to get the error code. |
Remarks
The iAngle
and oAngle
parameters must both be retrieved in a single call to this function (ie. you can't retrieve one without the other).
See Also
ChannelGet3DPosition(Int32, ref Vector3D, ref Vector3D, ref Vector3D)
Retrieves the 3D position of a sample, stream, or MOD music channel with 3D functionality.
Declaration
public static bool ChannelGet3DPosition(int Handle, ref Vector3D Position, ref Vector3D Orientation, ref Vector3D Velocity)
Parameters
Int32
Handle
The channel handle... a HCHANNEL, HMUSIC, HSTREAM. |
Vector3D
Position
Position of the sound. |
Vector3D
Orientation
Orientation of the sound. |
Vector3D
Velocity
Velocity of the sound. |
Returns
Boolean
If succesful, then true is returned, else false is returned. Use LastError to get the error code. |
See Also
ChannelGetAttribute(Int32, ChannelAttribute)
Retrieves the value of an attribute of a sample, stream or MOD music. Can also get the sample rate of a recording channel.
Declaration
public static double ChannelGetAttribute(int Handle, ChannelAttribute Attribute)
Parameters
Int32
Handle
The channel Handle... a HCHANNEL, HMUSIC, HSTREAM or HRECORD. |
ChannelAttribute
Attribute
The attribute to set the value of (one of ChannelAttribute) |
Returns
Double
If successful, the attribute value is returned. Use LastError to get the error code. |
ChannelGetAttribute(Int32, ChannelAttribute, IntPtr, Int32)
Retrieves the value of a channel's attribute.
Declaration
public static int ChannelGetAttribute(int Handle, ChannelAttribute Attribute, IntPtr Value, int Size)
Parameters
Int32
Handle
The channel handle... a HCHANNEL, HMUSIC, HSTREAM or HRECORD. |
ChannelAttribute
Attribute
The attribute to get the value of (e.g. ScannedInfo) |
IntPtr
Value
Pointer to a buffer to receive the attribute data. |
Int32
Size
The size of the attribute data... 0 = get the size of the attribute without getting the data. |
Returns
Int32
If successful, the size of the attribute data is returned, else 0 is returned. Use LastError to get the error code. |
Remarks
This function also supports the floating-point attributes supported by ChannelGetAttribute(Int32, ChannelAttribute, out Single).
ChannelGetAttribute(Int32, ChannelAttribute, out Single)
Retrieves the value of an attribute of a sample, stream or MOD music. Can also get the sample rate of a recording channel.
Declaration
public static bool ChannelGetAttribute(int Handle, ChannelAttribute Attribute, out float Value)
Parameters
Int32
Handle
The channel Handle... a HCHANNEL, HMUSIC, HSTREAM or HRECORD. |
ChannelAttribute
Attribute
The attribute to set the value of (one of ChannelAttribute) |
Single
Value
Reference to a float to receive the attribute value. |
Returns
Boolean
If successful, true is returned, else false is returned. Use LastError to get the error code. |
ChannelGetData(Int32, IntPtr, Int32)
Retrieves the immediate sample data (or an FFT representation of it) of a sample channel, stream, MOD music, or recording channel.
Declaration
public static int ChannelGetData(int Handle, IntPtr Buffer, int Length)
Parameters
Int32
Handle
The channel handle... a HCHANNEL, HMUSIC, HSTREAM, or HRECORD. |
IntPtr
Buffer
Location to write the data as an |
Int32
Length
Number of bytes wanted, and/or the DataFlags |
Returns
Int32
If an error occurs, -1 is returned, use LastError to get the error code. When requesting FFT data, the number of bytes read from the channel (to perform the FFT) is returned. When requesting sample data, the number of bytes written to buffer will be returned (not necessarily the same as the number of bytes read when using the Float or DataFlags.Fixed flag). When using the Available flag, the number of bytes in the channel's buffer is returned. |
Remarks
This function can only return as much data as has been written to the channel's buffer, so it may not always be possible to get the amount of data requested, especially if you request large amounts. If you really do need large amounts, then increase the buffer lengths (PlaybackBufferLength). The Available flag can be used to check how much data a channel's buffer contains at any time, including when stopped or stalled.
When requesting data from a decoding channel, data is decoded directly from the channel's source (no playback buffer) and as much data as the channel has available can be decoded at a time.
When retrieving sample data, 8-bit samples are unsigned (0 to 255), 16-bit samples are signed (-32768 to 32767), 32-bit floating-point samples range from -1 to +1 (not clipped, so can actually be outside this range). That is unless the Float flag is used, in which case, the sample data will be converted to 32-bit floating-point if it is not already, or if the DataFlags.Fixed flag is used, in which case the data will be coverted to 8.24 fixed-point.
Unless complex data is requested via the FFTComplex flag, the magnitudes of the first half of an FFT result are returned. For example, with a 2048 sample FFT, there will be 1024 floating-point values returned. If the DataFlags.Fixed flag is used, then the FFT values will be in 8.24 fixed-point form rather than floating-point. Each value, or "bin", ranges from 0 to 1 (can actually go higher if the sample data is floating-point and not clipped). The 1st bin contains the DC component, the 2nd contains the amplitude at 1/2048 of the channel's sample rate, followed by the amplitude at 2/2048, 3/2048, etc. A Hann window is applied to the sample data to reduce leakage, unless the FFTNoWindow flag is used. When a window is applied, it causes the DC component to leak into the next bin, but that can be removed (reduced to 0) by using the FFTRemoveDC flag. Doing so slightly increases the processing required though, so it should only be done when needed, which is when a window is applied and the 2nd bin value is important.
Channels that have 2 or more sample channels (ie. stereo or above) may have FFT performed on each individual channel, using the FFTIndividual flag. Without this flag, all of the channels are combined, and a single mono FFT is performed. Performing the extra individual FFTs of course increases the amount of processing required. The return values are interleaved in the same order as the channel's sample data, eg. stereo = left,right,left,etc.
This function is most useful if you wish to visualize (eg. spectrum analyze) the sound.
Platform-specific:
The DataFlags.Fixed flag is only available on Android and Windows CE.
ChannelGetData(Int32, Byte[], Int32)
Retrieves the immediate sample data (or an FFT representation of it) of a sample channel, stream, MOD music, or recording channel.
Declaration
public static int ChannelGetData(int Handle, byte[] Buffer, int Length)
Parameters
Int32
Handle
The channel handle... a HCHANNEL, HMUSIC, HSTREAM, or HRECORD. |
Byte[]
Buffer
Location to write the data as a byte[]. |
Int32
Length
Number of bytes wanted, and/or the DataFlags |
Returns
Int32
If an error occurs, -1 is returned, use LastError to get the error code. When requesting FFT data, the number of bytes read from the channel (to perform the FFT) is returned. When requesting sample data, the number of bytes written to buffer will be returned (not necessarily the same as the number of bytes read when using the Float or DataFlags.Fixed flag). When using the Available flag, the number of bytes in the channel's buffer is returned. |
ChannelGetData(Int32, Int16[], Int32)
Retrieves the immediate sample data (or an FFT representation of it) of a sample channel, stream, MOD music, or recording channel.
Declaration
public static int ChannelGetData(int Handle, short[] Buffer, int Length)
Parameters
Int32
Handle
The channel handle... a HCHANNEL, HMUSIC, HSTREAM, or HRECORD. |
Int16[]
Buffer
Location to write the data as a short[]. |
Int32
Length
Number of bytes wanted, and/or the DataFlags |
Returns
Int32
If an error occurs, -1 is returned, use LastError to get the error code. When requesting FFT data, the number of bytes read from the channel (to perform the FFT) is returned. When requesting sample data, the number of bytes written to buffer will be returned (not necessarily the same as the number of bytes read when using the Float or DataFlags.Fixed flag). When using the Available flag, the number of bytes in the channel's buffer is returned. |
ChannelGetData(Int32, Int32[], Int32)
Retrieves the immediate sample data (or an FFT representation of it) of a sample channel, stream, MOD music, or recording channel.
Declaration
public static int ChannelGetData(int Handle, int[] Buffer, int Length)
Parameters
Int32
Handle
The channel handle... a HCHANNEL, HMUSIC, HSTREAM, or HRECORD. |
Int32[]
Buffer
Location to write the data as a int[]. |
Int32
Length
Number of bytes wanted, and/or the DataFlags |
Returns
Int32
If an error occurs, -1 is returned, use LastError to get the error code. When requesting FFT data, the number of bytes read from the channel (to perform the FFT) is returned. When requesting sample data, the number of bytes written to buffer will be returned (not necessarily the same as the number of bytes read when using the Float or DataFlags.Fixed flag). When using the Available flag, the number of bytes in the channel's buffer is returned. |
ChannelGetData(Int32, Single[], Int32)
Retrieves the immediate sample data (or an FFT representation of it) of a sample channel, stream, MOD music, or recording channel.
Declaration
public static int ChannelGetData(int Handle, float[] Buffer, int Length)
Parameters
Int32
Handle
The channel handle... a HCHANNEL, HMUSIC, HSTREAM, or HRECORD. |
Single[]
Buffer
Location to write the data as a float[]. |
Int32
Length
Number of bytes wanted, and/or the DataFlags |
Returns
Int32
If an error occurs, -1 is returned, use LastError to get the error code. When requesting FFT data, the number of bytes read from the channel (to perform the FFT) is returned. When requesting sample data, the number of bytes written to buffer will be returned (not necessarily the same as the number of bytes read when using the Float or DataFlags.Fixed flag). When using the Available flag, the number of bytes in the channel's buffer is returned. |
ChannelGetDevice(Int32)
Retrieves the device that the channel is using.
Declaration
public static int ChannelGetDevice(int Handle)
Parameters
Int32
Handle
The channel handle... a HCHANNEL, HMUSIC, HSTREAM, or HRECORD. HSAMPLE handles may also be used. |
Returns
Int32
If successful, the device number is returned, else -1 is returned. Use LastError to get the error code. |
Remarks
Recording devices are indicated by the HIWORD of the return value being 1, when this function is called with a HRECORD channel.
ChannelGetInfo(Int32)
Retrieves information on a channel.
Declaration
public static ChannelInfo ChannelGetInfo(int Handle)
Parameters
Int32
Handle
The channel Handle... a HCHANNEL, HMUSIC, HSTREAM, or HRECORD. |
Returns
ChannelInfo
An instance of the ChannelInfo structure. Throws BassException on Error. |
ChannelGetInfo(Int32, out ChannelInfo)
Retrieves information on a channel.
Example
Check if a channel is an MP3 stream.
ChannelInfo info;
Bass.ChannelGetInfo(channel, out info); // get info
if (info.ChannelType == ChannelType.MP3)
{
// it's an MP3!
}
Declaration
public static bool ChannelGetInfo(int Handle, out ChannelInfo Info)
Parameters
Int32
Handle
The channel Handle... a HCHANNEL, HMUSIC, HSTREAM, or HRECORD. |
ChannelInfo
Info
ChannelInfo instance where to store the channel information at. |
Returns
Boolean
If successful, true is returned, else false is returned. Use LastError to get the error code. |
ChannelGetLength(Int32, PositionFlags)
Retrieves the playback Length of a channel.
Example
Get the duration (in seconds) of a channel.
// the length in bytes
var len = Bass.ChannelGetLength(channel);
// the length in seconds
var time = Bass.ChannelBytes2Seconds(channel, len);
Declaration
public static long ChannelGetLength(int Handle, PositionFlags Mode = PositionFlags.Bytes)
Parameters
Int32
Handle
The channel Handle... a HCHANNEL, HMUSIC, HSTREAM. HSAMPLE handles may also be used. |
PositionFlags
Mode
How to retrieve the Length (one of the PositionFlags flags). |
Returns
Int64
If succesful, then the channel's Length is returned, else -1 is returned. Use LastError to get the error code. |
Remarks
The exact Length of a stream will be returned once the whole file has been streamed, but until then it is not always possible to 100% accurately estimate the Length. The Length is always exact for MP3/MP2/MP1 files when the Prescan flag is used in the CreateStream(String, Int64, Int64, BassFlags) call, otherwise it is an (usually accurate) estimation based on the file size. The Length returned for OGG files will usually be exact (assuming the file is not corrupt), but when streaming from the internet (or "buffered" User file), it can be a very rough estimation until the whole file has been downloaded. It will also be an estimate for chained OGG files that are not pre-scanned.
Unless an OGG file contains a single bitstream, the number of bitstreams it contains will only be available if it was pre-scanned at the stream's creation.
Retrieving the Length of a MOD music requires that the Prescan flag was used in the MusicLoad(String, Int64, Int32, BassFlags, Int32) call.
ChannelGetLevel(Int32)
Retrieves the level (peak amplitude) of a sample, stream, MOD music or recording channel.
Example
Get the left and right levels of a stereo channel.
var level = Bass.ChannelGetLevel(channel);
var left = BitHelper.LoWord(level); // the left level
var right = BitHelper.HiWord(level); // the right level
Declaration
public static int ChannelGetLevel(int Handle)
Parameters
Int32
Handle
The channel handle... a HCHANNEL, HMUSIC, HSTREAM, or HRECORD. |
Returns
Int32
If an error occurs, -1 is returned, use LastError to get the error code. If successful, the level of the left channel is returned in the low word (low 16-bits), and the level of the right channel is returned in the high word (high 16-bits). If the channel is mono, then the low word is duplicated in the high word. The level ranges linearly from 0 (silent) to 32768 (max). 0 will be returned when a channel is stalled. |
Remarks
This function measures the level of the channel's sample data, not the level of the channel in the final output mix, so the channel's volume and panning/balance (as set with ChannelSetAttribute(Int32, ChannelAttribute, Single), Volume or Pan) does not affect it. The effect of any DSP/FX set on the channel is present in the measurement, except for DX8 effects when using the "With FX flag" DX8 effect implementation.
For channels that are more than stereo, the left level will include all left channels (eg. front-left, rear-left, center), and the right will include all right (front-right, rear-right, LFE). If there are an odd number of channels then the left and right levels will include all channels. If the level of each individual channel is required, that is available from the other overload(s).
20ms of data is inspected to calculate the level. When used with a decoding channel, that means 20ms of data needs to be decoded from the channel in order to calculate the level, and that data is then gone, eg. it is not available to a subsequent ChannelGetData(Int32, IntPtr, Int32) call.
ChannelGetLevel(Int32, Single, LevelRetrievalFlags)
Retrieves the level (peak amplitude) of a sample, stream, MOD music or recording channel.
Example Replicate ChannelGetLevel(Int32) but with floating-point levels.
var levels = new float[2];
Bass.ChannelGetLevel(handle, levels, 0.02f, LevelRetrievalFlags.Stereo);
Get a mono RMS level reading in decibels using 50ms of data.
var level = new float[1];
// get the level
Bass.ChannelGetLevel(handle, level, 0.05f, LevelRetrievalFlags.Mono | LevelRetrievalFlags.RMS);
// translate it to dB
var dblevel = level > 0 ? 20 * log10(level) : -1000;
Get a peak level reading for each channel using 20ms of data.
ChannelInfo ci;
Bass.ChannelGetInfo(handle, out ci);
// allocate an array for each channel's level
var levels = new float[ci.chans];
// get the levels
Bass.ChannelGetLevel(handle, levels, 0.02f, 0);
Declaration
public static float[] ChannelGetLevel(int Handle, float Length, LevelRetrievalFlags Flags)
Parameters
Int32
Handle
The channel handle... a HCHANNEL, HMUSIC, HSTREAM, or HRECORD. |
Single
Length
How much data (in seconds) to look at to get the level (limited to 1 second). |
LevelRetrievalFlags
Flags
What levels to retrieve. |
Returns
Single[]
Array of levels on success, else null. Use LastError to get the error code. |
Remarks
This function operates in the same way as ChannelGetLevel(Int32) but has greater flexibility on how the level is measured. The levels are not clipped, so may exceed +/-1.0 on floating-point channels.
ChannelGetLevel(Int32, Single[], Single, LevelRetrievalFlags)
Retrieves the level (peak amplitude) of a sample, stream, MOD music or recording channel.
Declaration
public static bool ChannelGetLevel(int Handle, float[] Levels, float Length, LevelRetrievalFlags Flags)
Parameters
Int32
Handle
The channel handle... a HCHANNEL, HMUSIC, HSTREAM, or HRECORD. |
Single[]
Levels
The array in which the levels are to be returned. |
Single
Length
How much data (in seconds) to look at to get the level (limited to 1 second). |
LevelRetrievalFlags
Flags
What levels to retrieve. |
Returns
Boolean
On success true is returned - else false, use LastError to get the error code. If successful, the requested levels are returned in the |
Remarks
This function operates in the same way as ChannelGetLevel(Int32) but has greater flexibility on how the level is measured. The levels are not clipped, so may exceed +/-1.0 on floating-point channels.
ChannelGetLevelLeft(Int32)
Gets the Level of the Left Channel.
Declaration
public static int ChannelGetLevelLeft(int Handle)
Parameters
Int32
Handle
|
Returns
Int32
|
ChannelGetLevelRight(Int32)
Gets the Level of the Right Channel.
Declaration
public static int ChannelGetLevelRight(int Handle)
Parameters
Int32
Handle
|
Returns
Int32
|
ChannelGetPosition(Int32, PositionFlags)
Retrieves the playback position of a sample, stream, or MOD music. Can also be used with a recording channel.
Declaration
public static long ChannelGetPosition(int Handle, PositionFlags Mode = PositionFlags.Bytes)
Parameters
Int32
Handle
The channel Handle... a HCHANNEL, HMUSIC, HSTREAM, or HRECORD. |
PositionFlags
Mode
How to retrieve the position |
Returns
Int64
If an error occurs, -1 is returned, use LastError to get the error code. If successful, the position is returned. |
Remarks
With MOD music you might use the LoWord(Int32) and HiWord(Int32) methods to retrieve the order and the row values respectively.
ChannelGetTags(Int32, TagType)
Retrieves the requested tags/headers from a channel, if they are available.
Examples
List an OGG stream's comments.
// get a pointer to the 1st comment
var comments = Bass.ChannelGetTags(channel, TagType.OGG);
if (comments != IntPtr.Zero)
{
foreach (var comment in Extensions.ExtractMultiStringAnsi(comments))
Console.WriteLine(comment);
}
List a MOD music's samples.
IntPtr ptr;
int n = 0;
while ((ptr = Bass.ChannelGetTags(channel, TagType.MusicSample + n)) != IntPtr.Zero)
{
// display the sample text
Console.WriteLine("sample {0} = {1}", n + 1, text);
++n; // move on to next sample
}
Declaration
public static IntPtr ChannelGetTags(int Handle, TagType Tags)
Parameters
Int32
Handle
The channel handle...a HMUSIC or HSTREAM. |
TagType
Tags
The tags/headers wanted... |
Returns
IntPtr
If succesful, a pointer to the data of the tags/headers is returned, else |
Remarks
Some tags (eg. ID3) are located at the end of the file, so when streaming a file from the internet, the tags will not be available until the download is complete. A Downloaded sync can be set via ChannelSetSync(Int32, SyncFlags, Int64, SyncProcedure, IntPtr), to be informed of when the download is complete. A MetadataReceived sync can be used to be informed of new Shoutcast metadata, and a OggChange sync for when a new logical bitstream begins in a chained OGG stream, which generally brings new OGG tags.
In a chained OGG file containing multiple bitstreams, each bitstream will have its own tags. To get the tags from a particular one, ChannelSetPosition(Int32, Int64, PositionFlags) can be first used to seek to it.
When a Media Foundation codec is in use, the WaveFormat tag can be used to find out what the source format is.
ChannelHasFlag(Int32, BassFlags)
Checks if a flag is present on a channel.
Declaration
public static bool ChannelHasFlag(int Handle, BassFlags Flag)
Parameters
Int32
Handle
The channel Handle... a HCHANNEL, HMUSIC, HSTREAM. |
BassFlags
Flag
see BassFlags |
Returns
Boolean
|
ChannelIsActive(Int32)
Checks if a sample, stream, or MOD music is active (playing) or stalled. Can also check if a recording is in progress.
Declaration
public static PlaybackState ChannelIsActive(int Handle)
Parameters
Int32
Handle
The channel Handle... a HCHANNEL, HMUSIC, HSTREAM, or HRECORD. |
Returns
PlaybackState
PlaybackState indicating whether the state of the channel. |
Remarks
When using this function with a decoding channel, Playing will be returned while there is still data to decode. Once the end has been reached, Stopped will be returned. Stalled is never returned for decoding channels; you can tell a decoding channel is stalled if ChannelGetData(Int32, IntPtr, Int32) returns less data than requested, and this function still returns Playing.
ChannelIsSliding(Int32, ChannelAttribute)
Checks if an attribute (or any attribute) of a sample, stream, or MOD music is sliding.
Declaration
public static bool ChannelIsSliding(int Handle, ChannelAttribute Attribute)
Parameters
Int32
Handle
The channel Handle... a HCHANNEL, HMUSIC, HSTREAM or HRECORD. |
ChannelAttribute
Attribute
The attribute to check for sliding (0 for any attribute). |
Returns
Boolean
If the attribute (or any) is sliding, then true is returned, else false is returned. |
ChannelLock(Int32, Boolean)
Locks a stream, MOD music or recording channel to the current thread.
Example
Lock a channel to ensure that 2 DSP functions start together.
// lock channel
Bass.ChannelLock(channel, true);
// set 1st DSP
Bass.ChannelSetDSP(channel, DspProc1, IntPtr.Zero, 0);
// set 2nd DSP
Bass.ChannelSetDSP(channel, DspProc2, IntPtr.Zero, 0);
// unlock channel
Bass.ChannelLock(channel, false);
Declaration
public static bool ChannelLock(int Handle, bool Lock = true)
Parameters
Int32
Handle
The channel Handle... a HMUSIC, HSTREAM or HRECORD Handle. |
Boolean
Lock
If false, unlock the channel, else lock it. |
Returns
Boolean
If succesful, then true is returned, else false is returned. Use LastError to get the error code. |
Remarks
Locking a channel prevents other threads from performing most functions on it, including Buffer updates. Other threads wanting to access a locked channel will block until it is unlocked, so a channel should only be locked very briefly. A channel must be unlocked in the same thread that it was locked.
ChannelPause(Int32)
Pauses a sample, stream, MOD music, or recording.
Declaration
public static bool ChannelPause(int Handle)
Parameters
Int32
Handle
The channel Handle... a HCHANNEL / HMUSIC / HSTREAM / HRECORD Handle. |
Returns
Boolean
If successful, true is returned, else false is returned. Use LastError to get the error code. |
Remarks
Use ChannelPlay(Int32, Boolean) to resume a paused channel. ChannelStop(Int32) can be used to stop a paused channel.
ChannelPlay(Int32, Boolean)
Starts (or resumes) playback of a sample, stream, MOD music, or recording.
Declaration
public static bool ChannelPlay(int Handle, bool Restart = false)
Parameters
Int32
Handle
The channel Handle... a HCHANNEL / HMUSIC / HSTREAM / HRECORD Handle. |
Boolean
Restart
Restart playback from the beginning? If Handle is a User stream, it's current Buffer contents are flushed. If it's a MOD music, it's BPM/etc are automatically reset to their initial values. |
Returns
Boolean
If successful, true is returned, else false is returned. Use LastError to get the error code. |
Remarks
When streaming in blocks (StreamDownloadBlocks), the restart parameter is ignored as it's not possible to go back to the start.
The Restart
parameter is also of no consequence with recording channels.
ChannelRemoveDSP(Int32, Int32)
Removes a DSP function from a stream, MOD music, or recording channel.
Declaration
public static bool ChannelRemoveDSP(int Handle, int DSP)
Parameters
Int32
Handle
The channel Handle... a HSTREAM, HMUSIC, or HRECORD. |
Int32
DSP
Handle of the DSP function to remove from the channel (return value of a previous ChannelSetDSP(Int32, DSPProcedure, IntPtr, Int32) call). |
Returns
Boolean
If succesful, true is returned, else false is returned. Use LastError to get the error code. |
ChannelRemoveFlag(Int32, BassFlags)
Removes a flag from a channel.
Declaration
public static bool ChannelRemoveFlag(int Handle, BassFlags Flag)
Parameters
Int32
Handle
The channel Handle... a HCHANNEL, HMUSIC, HSTREAM. |
BassFlags
Flag
see BassFlags |
Returns
Boolean
|
ChannelRemoveFX(Int32, Int32)
Removes an effect from a stream, MOD music, or recording channel.
Declaration
public static bool ChannelRemoveFX(int Handle, int FX)
Parameters
Int32
Handle
The channel Handle... a HSTREAM, HMUSIC, or HRECORD. |
Int32
FX
Handle of the effect to remove from the channel (return value of a previous ChannelSetFX(Int32, EffectType, Int32) call). |
Returns
Boolean
If succesful, true is returned, else false is returned. Use LastError to get the error code. |
Remarks
Depending on the DX8 effect implementation being used by the channel, the channel may have to be stopped before removing a DX8 effect on it. If necessary, that is done automatically and the channel is resumed afterwards.
ChannelRemoveDSP(Int32, Int32) can also be used to remove effects.
See Also
ChannelRemoveLink(Int32, Int32)
Removes a links between two MOD music or stream channels.
Declaration
public static bool ChannelRemoveLink(int Handle, int Channel)
Parameters
Int32
Handle
The channel Handle... a HMUSIC or HSTREAM. |
Int32
Channel
The Handle of the channel to have unlinked with it... a HMUSIC or HSTREAM. |
Returns
Boolean
If succesful, true is returned, else false is returned. Use LastError to get the error code. |
ChannelRemoveSync(Int32, Int32)
Removes a synchronizer from a MOD music or stream channel.
Declaration
public static bool ChannelRemoveSync(int Handle, int Sync)
Parameters
Int32
Handle
The channel Handle... a HMUSIC, HSTREAM or HRECORD. |
Int32
Sync
Handle of the synchronizer to remove (return value of a previous ChannelSetSync(Int32, SyncFlags, Int64, SyncProcedure, IntPtr) call). |
Returns
Boolean
If succesful, true is returned, else false is returned. Use LastError to get the error code. |
ChannelSeconds2Bytes(Int32, Double)
Translates a time (seconds) position into bytes, based on a channel's format.
Declaration
public static long ChannelSeconds2Bytes(int Handle, double Position)
Parameters
Int32
Handle
The channel Handle... a HCHANNEL, HMUSIC, HSTREAM, or HRECORD. HSAMPLE handles may also be used. |
Double
Position
The position to translate (in seconds, e.g. 0.03 = 30ms). |
Returns
Int64
If successful, then the translated Length in Bytes is returned, else -1 is returned. Use LastError to get the error code. |
Remarks
The translation is based on the channel's initial sample rate, when it was created.
The return value is rounded down to the position of the nearest sample.
ChannelSet3DAttributes(Int32, Mode3D, Single, Single, Int32, Int32, Single)
Sets the 3D attributes of a sample, stream, or MOD music channel with 3D functionality.
Declaration
public static bool ChannelSet3DAttributes(int Handle, Mode3D Mode, float Min, float Max, int iAngle, int oAngle, float OutVol)
Parameters
Int32
Handle
The channel handle... a HCHANNEL, HMUSIC, HSTREAM. |
Mode3D
Mode
The 3D processing mode |
Single
Min
The minimum distance. The channel's volume is at maximum when the listener is within this distance... less than 0.0 = leave current. |
Single
Max
The maximum distance. The channel's volume stops decreasing when the listener is beyond this distance... less than 0.0 = leave current. |
Int32
iAngle
The angle of the inside projection cone in degrees... 0 (no cone) - 360 (sphere), -1 = leave current. |
Int32
oAngle
The angle of the outside projection cone in degrees... 0 (no cone) - 360 (sphere), -1 = leave current. |
Single
OutVol
The delta-volume outside the outer projection cone... 0 (silent) - 100 (same as inside the cone), -1 = leave current. |
Returns
Boolean
If succesful, then true is returned, else false is returned. Use LastError to get the error code. |
Remarks
The iAngle
and oAngle
parameters must both be set in a single call to this function (ie. you can't set one without the other).
The iAngle
and oAngle
angles decide how wide the sound is projected around the orientation angle. Within the inside angle the volume level is the channel volume, as set with ChannelSetAttribute(Int32, ChannelAttribute, Single).
Outside the outer angle, the volume changes according to the OutVol
value. Between the inner and outer angles, the volume gradually changes between the inner and outer volume levels.
If the inner and outer angles are 360 degrees, then the sound is transmitted equally in all directions.
As with all 3D functions, use Apply3D() to apply the changes made.
See Also
ChannelSet3DPosition(Int32, Vector3D, Vector3D, Vector3D)
Sets the 3D position of a sample, stream, or MOD music channel with 3D functionality.
Declaration
public static bool ChannelSet3DPosition(int Handle, Vector3D Position, Vector3D Orientation, Vector3D Velocity)
Parameters
Int32
Handle
The channel handle... a HCHANNEL, HMUSIC, HSTREAM. |
Vector3D
Position
Position of the sound. |
Vector3D
Orientation
Orientation of the sound. |
Vector3D
Velocity
Velocity of the sound. This is only used to calculate the doppler effect, and has no effect on the sound's position. |
Returns
Boolean
If succesful, then true is returned, else false is returned. Use LastError to get the error code. |
Remarks
As with all 3D functions, Apply3D() must be called to apply the changes made.
See Also
ChannelSetAttribute(Int32, ChannelAttribute, IntPtr, Int32)
Sets the value of a channel's attribute.
Declaration
public static bool ChannelSetAttribute(int Handle, ChannelAttribute Attribute, IntPtr Value, int Size)
Parameters
Int32
Handle
The channel handle... a HCHANNEL, HMUSIC, HSTREAM or HRECORD. |
ChannelAttribute
Attribute
The attribute to set the value of. (e.g. ScannedInfo) |
IntPtr
Value
The pointer to the new attribute data. |
Int32
Size
The size of the attribute data. |
Returns
Boolean
If successful, true is returned, else false is returned. Use LastError to get the error code. |
ChannelSetAttribute(Int32, ChannelAttribute, Double)
Sets the value of an attribute of a sample, stream or MOD music.
Declaration
public static bool ChannelSetAttribute(int Handle, ChannelAttribute Attribute, double Value)
Parameters
Int32
Handle
The channel handle... a HCHANNEL, HMUSIC, HSTREAM or HRECORD. |
ChannelAttribute
Attribute
The attribute to set the value of. |
Double
Value
The new attribute value. See the attribute's documentation for details on the possible values. |
Returns
Boolean
If successful, true is returned, else false is returned. Use LastError to get the error code. |
Remarks
The actual attribute value may not be exactly the same as requested, due to precision differences. For example, an attribute might only allow whole number values. ChannelGetAttribute(Int32, ChannelAttribute) can be used to confirm what the value is.
ChannelSetAttribute(Int32, ChannelAttribute, Single)
Sets the value of an attribute of a sample, stream or MOD music.
Declaration
public static bool ChannelSetAttribute(int Handle, ChannelAttribute Attribute, float Value)
Parameters
Int32
Handle
The channel handle... a HCHANNEL, HMUSIC, HSTREAM or HRECORD. |
ChannelAttribute
Attribute
The attribute to set the value of. |
Single
Value
The new attribute value. See the attribute's documentation for details on the possible values. |
Returns
Boolean
If successful, true is returned, else false is returned. Use LastError to get the error code. |
Remarks
The actual attribute value may not be exactly the same as requested, due to precision differences. For example, an attribute might only allow whole number values. ChannelGetAttribute(Int32, ChannelAttribute, out Single) can be used to confirm what the value is.
ChannelSetDevice(Int32, Int32)
Changes the device that a stream, MOD music or sample is using.
Declaration
public static bool ChannelSetDevice(int Handle, int Device)
Parameters
Int32
Handle
The channel or sample handle... only HMUSIC, HSTREAM or HSAMPLE are supported. |
Int32
Device
The device to use...0 = no sound, 1 = first real output device. |
Returns
Boolean
If succesful, then true is returned, else false is returned. Use LastError to get the error code. |
Remarks
All of the channel's current settings are carried over to the new device, but if the channel is using the "with FX flag" DX8 effect implementation, the internal state (eg. buffers) of the DX8 effects will be reset. Using the "without FX flag" DX8 effect implementation, the state of the DX8 effects is preserved.
When changing a sample's device, all the sample's existing channels (HCHANNELs) are freed. It's not possible to change the device of an individual sample channel.
ChannelSetDSP(Int32, DSPProcedure, IntPtr, Int32)
Sets up a User DSP function on a stream, MOD music, or recording channel.
Declaration
public static int ChannelSetDSP(int Handle, DSPProcedure Procedure, IntPtr User = null, int Priority = 0)
Parameters
Int32
Handle
The channel Handle... a HSTREAM, HMUSIC, or HRECORD. |
DSPProcedure
Procedure
The callback function (see DSPProcedure). |
IntPtr
User
User instance data to pass to the callback function. |
Int32
Priority
The priority of the new DSP, which determines it's position in the DSP chain. DSPs with higher priority are called before those with lower. |
Returns
Int32
If succesful, then the new DSP's Handle is returned, else 0 is returned. Use LastError to get the error code. |
Remarks
The channel does not have to be playing to set a DSP function, they can be set before and while playing.
Equally, you can also remove them at any time. Use ChannelRemoveDSP(Int32, Int32) to remove a DSP function.
Multiple DSP functions may be used per channel, in which case the order that the functions are called is determined by their priorities. Any DSPs that have the same priority are called in the order that they were added.
DSP functions can be applied to MOD musics and streams, but not samples. If you want to apply a DSP function to a sample, then you should stream the sample.
Unlike Bass.Net, a reference to Procedure
doesn't need to be held by you manually.
ManagedBass automatically holds a reference and frees it when the Channel is freed or DSP is removed via ChannelRemoveDSP(Int32, Int32).
ChannelSetFX(Int32, EffectType, Int32)
Sets an effect on a stream, MOD music, or recording channel.
Declaration
public static int ChannelSetFX(int Handle, EffectType Type, int Priority)
Parameters
Int32
Handle
The channel Handle... a HSTREAM, HMUSIC, or HRECORD. |
EffectType
Type
Type of effect, one of EffectType. |
Int32
Priority
The priority of the new FX, which determines it's position in the DSP chain. DSP/FX with higher priority are applied before those with lower. This parameter has no effect with DX8 effects when the "with FX flag" DX8 effect implementation is used. |
Returns
Int32
If succesful, then the new effect's Handle is returned, else 0 is returned. Use LastError to get the error code. |
Remarks
Multiple effects may be used per channel. Use ChannelRemoveFX(Int32, Int32) to remove an effect. Use FXSetParameters(Int32, IntPtr) to set an effect's parameters.
Effects can be applied to MOD musics and streams, but not samples. If you want to apply an effect to a sample, you could use a stream instead.
Depending on the DX8 effect implementation being used by the channel, the channel may have to be stopped before adding or removing DX8 effects on it. If necessary, that is done automatically and the channel is resumed afterwards.
Platform-specific
DX8 effects are a Windows feature requiring DirectX 8, or DirectX 9 for floating-point support. On other platforms, they are emulated by BASS, except for the following which are currently unsupported: DXCompressor, DXGargle, and DX_I3DL2Reverb. On Windows CE, only PARAMEQ is supported.
See Also
ChannelSetLink(Int32, Int32)
Links two MOD music or stream channels together.
Example
Link 2 streams and play them together.
// link stream2 to stream1
Bass.ChannelSetLink(stream1, stream2);
// start both streams together
Bass.ChannelPlay(stream1);
Declaration
public static bool ChannelSetLink(int Handle, int Channel)
Parameters
Int32
Handle
The channel Handle... a HMUSIC or HSTREAM. |
Int32
Channel
The Handle of the channel to have linked with it... a HMUSIC or HSTREAM. |
Returns
Boolean
If succesful, true is returned, else false is returned. Use LastError to get the error code. |
Remarks
Linked channels are started/stopped/paused/resumed together.
Links are one-way, for example, channel Channel
will be started by channel Handle
,
but not vice versa unless another link has been set in that direction.
If a linked channel has reached the end, it will not be restarted when a channel it is linked to is started. If you want a linked channel to be restarted, you need to have resetted it's position using ChannelSetPosition(Int32, Int64, PositionFlags) beforehand.
Platform-specific
Except for on Windows, linked channels on the same device are guaranteed to start playing simultaneously. On Windows, it is possible for there to be a slight gap between them, but it will generally be shorter (and never longer) than starting them individually.
ChannelSetPosition(Int32, Int64, PositionFlags)
Sets the playback position of a sample, MOD music, or stream.
Example
Set the position of a channel to 1000000 bytes.
Bass.ChannelSetPosition(channel, 1000000);
Set the position of a MOD music to row 20 of order 10, and stop all currently playing notes.
Bass.ChannelSetPosition(music, BitHelper.MakeLong(10, 20), PositionFlags.MusicOrders | PositionFlags.MusicPositionReset);
Declaration
public static bool ChannelSetPosition(int Handle, long Position, PositionFlags Mode = PositionFlags.Bytes)
Parameters
Int32
Handle
The channel Handle... a HCHANNEL, HSTREAM or HMUSIC. |
Int64
Position
The position, in units determined by the |
PositionFlags
Mode
How to set the position. |
Returns
Boolean
If succesful, then true is returned, else false is returned. Use LastError to get the error code. |
Remarks
Setting the position of a MOD music in bytes (other than 0) requires that the Prescan flag was used in the MusicLoad(String, Int64, Int32, BassFlags, Int32) call. When setting the position in orders/rows, the channel's byte position (as reported by ChannelGetPosition(Int32, PositionFlags)) is reset to 0. This is because it's not possible to get the byte position of an order/row position - it's possible that a position may never be played in the normal cause of events, or it may be played multiple times.
When changing the position of a MOD music, and the MusicPositionReset flag is active on the channel, all notes that were playing before the position changed will be stopped. Otherwise, the notes will continue playing until they are stopped in the MOD music. When setting the position in bytes, the BPM, "speed" and "global volume" are updated to what they would normally be at the new position. Otherwise they are left as they were prior to the postion change, unless the seek position is 0 (the start), in which case they are also reset to the starting values (when using the MusicPositionReset flag). When the MusicPositionResetEx flag is active, the BPM, speed and global volume are reset with every seek.
For MP3/MP2/MP1 streams, unless the file is scanned via the Scan or the Prescan flag at stream creation, seeking will be approximate but generally still quite accurate. Besides scanning, exact seeking can also be achieved with the DecodeTo flag.
Seeking in internet file (and "buffered" User file) streams is possible once the download has reached the requested position, so long as the file is not being streamed in blocks StreamDownloadBlocks.
User streams (created with CreateStream(Int32, Int32, BassFlags, StreamProcedure, IntPtr)) are not seekable, but it is possible to reset a User stream (including its Buffer contents) by setting its position to byte 0.
The DecodeTo flag can be used to seek forwards in streams that are not normally seekable, like custom streams or internet streams that are using the StreamDownloadBlocks flag, but it will only go as far as what is currently available; it will not wait for more data to be downloaded, for example. ChannelGetPosition(Int32, PositionFlags) can be used to confirm what the new position actually is.
In some cases, particularly when the Inexact flag is used, the new position may not be what was requested. ChannelGetPosition(Int32, PositionFlags) can be used to confirm what the new position actually is.
The Scan flag works the same way as the CreateStream(String, Int64, Int64, BassFlags) Prescan flag, and can be used to delay the scanning until after the stream has been created. When a position beyond the end is requested, the call will fail (Position error code) but the seek table and exact Length will have been scanned. When a file has been scanned, all seeking (even without the Scan flag) within the scanned part of it will use the scanned infomation.
ChannelSetSync(Int32, SyncFlags, Int64, SyncProcedure, IntPtr)
Sets up a synchronizer on a MOD music, stream or recording channel.
Declaration
public static int ChannelSetSync(int Handle, SyncFlags Type, long Parameter, SyncProcedure Procedure, IntPtr User = null)
Parameters
Int32
Handle
The channel Handle... a HMUSIC, HSTREAM or HRECORD. |
SyncFlags
Type
The Type of sync (see SyncFlags). |
Int64
Parameter
The sync parameters, depends on the sync Type (see SyncFlags). |
SyncProcedure
Procedure
The callback function which should be invoked with the sync. |
IntPtr
User
User instance data to pass to the callback function. |
Returns
Int32
If succesful, then the new synchronizer's Handle is returned, else 0 is returned. Use LastError to get the error code. |
Remarks
Multiple synchronizers may be used per channel, and they can be set before and while playing. Equally, synchronizers can also be removed at any time, using ChannelRemoveSync(Int32, Int32). If the Onetime flag is used, then the sync is automatically removed after its first occurrence.
The Mixtime flag can be used with End or Position/MusicPosition syncs to implement custom looping, by using ChannelSetPosition(Int32, Int64, PositionFlags) in the callback. A Mixtime sync can also be used to add or remove DSP/FX at specific points, or change a HMUSIC channel's flags or attributes (see ChannelFlags(Int32, BassFlags, BassFlags)). The Mixtime flag can also be useful with a Seeking sync, to reset DSP states after seeking.
Several of the sync types are triggered in the process of rendering the channel's sample data; for example, Position and End syncs, when the rendering reaches the sync position or the end, respectively. Those sync types should be set before starting playback or pre-buffering (ie. before any rendering), to avoid missing any early sync events.
With recording channels, Position syncs are triggered just before the RecordProcedure receives the block of data containing the sync position.
Unlike Bass.Net, a reference to Procedure
doesn't need to be held by you manually.
ManagedBass automatically holds a reference and frees it when the Channel is freed or Sync is removed via ChannelRemoveSync(Int32, Int32).
ChannelSlideAttribute(Int32, ChannelAttribute, Single, Int32)
Slides a channel's attribute from its current value to a new value.
Example
Fadeout a channel's volume over a period of 1 second.
Bass.ChannelSlideAttribute(channel, ChannelAttribute.Volume, 0, 1000);
Declaration
public static bool ChannelSlideAttribute(int Handle, ChannelAttribute Attribute, float Value, int Time)
Parameters
Int32
Handle
The channel Handle... a HCHANNEL, HSTREAM or HMUSIC, or HRECORD. |
ChannelAttribute
Attribute
The attribute to slide the value of. |
Single
Value
The new attribute value. See the attribute's documentation for details on the possible values. |
Int32
Time
The Length of time (in milliseconds) that it should take for the attribute to reach the |
Returns
Boolean
If successful, then true is returned, else false is returned. Use LastError to get the error code. |
Remarks
This function is similar to ChannelSetAttribute(Int32, ChannelAttribute, Single), except that the attribute is ramped to the value over the specified period of time. Another difference is that the value is not pre-checked. If it is invalid, the slide will simply end early.
If an attribute is already sliding, then the old slide is stopped and replaced by the new one.
ChannelIsSliding(Int32, ChannelAttribute) can be used to check if an attribute is currently sliding. A BASS_SYNC_SLIDE sync can also be set via ChannelSetSync(Int32, SyncFlags, Int64, SyncProcedure, IntPtr), to be triggered at the end of a slide. The sync will not be triggered in the case of an existing slide being replaced by a new one.
Attribute slides are unaffected by whether the channel is playing, paused or stopped. They carry on regardless.
ChannelStop(Int32)
Stops a sample, stream, MOD music, or recording.
Declaration
public static bool ChannelStop(int Handle)
Parameters
Int32
Handle
The channel Handle... a HCHANNEL, HMUSIC, HSTREAM or HRECORD Handle. |
Returns
Boolean
If successful, true is returned, else false is returned. Use LastError to get the error code. |
Remarks
Stopping a User stream (created with CreateStream(Int32, Int32, BassFlags, StreamProcedure, IntPtr)) will clear its Buffer contents, and stopping a sample channel (HCHANNEL) will result in it being freed. Use ChannelPause(Int32) instead if you wish to stop a User stream and then resume it from the same point.
When used with a "decoding channel" (Decode was used at creation), this function will end the channel at its current position, so that it's not possible to decode any more data from it. Any End syncs that have been set on the channel will not be triggered by this, they are only triggered when reaching the natural end. ChannelSetPosition(Int32, Int64, PositionFlags) can be used to reset the channel and start decoding again.
ChannelUpdate(Int32, Int32)
Updates the playback buffer of a stream or MOD music.
Declaration
public static bool ChannelUpdate(int Handle, int Length)
Parameters
Int32
Handle
The channel handle... a HMUSIC or HSTREAM. |
Int32
Length
The amount to render, in milliseconds... 0 = default (2 x UpdatePeriod). This is capped at the space available in the buffer. |
Returns
Boolean
If successful, true is returned, else false is returned. Use LastError to get the error code. |
Remarks
When starting playback of a stream or MOD music, after creating it or changing its position, there will be a slight delay while the initial data is decoded for playback. Usually the delay is not noticeable or important, but if you need playback to start instantly when you call ChannelPlay(Int32, Boolean), then use this function first. The length parameter should be at least equal to the UpdatePeriod.
It may not always be possible to render the requested amount of data, in which case this function will still succeed. ChannelGetData(Int32, IntPtr, Int32) (Available) can be used to check how much data a channel has buffered for playback.
When automatic updating is disabled (UpdatePeriod = 0 or UpdateThreads = 0), this function could be used instead of Update(Int32) to implement different update periods for different channels, instead of a single update period for all. Unlike Update(Int32), this function can also be used while automatic updating is enabled.
The CPU usage of this function is not included in the CPUUsage reading.
Configure(Configuration, IntPtr)
Configure BASS.
Declaration
public static bool Configure(Configuration Option, IntPtr NewValue)
Parameters
Configuration
Option
One of Configuration values. |
IntPtr
NewValue
The New Value of the option. |
Returns
Boolean
If succesful, then true is returned, else false is returned. Use LastError to get the error code. |
Configure(Configuration, Boolean)
Configure BASS.
Declaration
public static bool Configure(Configuration Option, bool NewValue)
Parameters
Configuration
Option
One of Configuration values. |
Boolean
NewValue
The New Value of the option. |
Returns
Boolean
If succesful, then true is returned, else false is returned. Use LastError to get the error code. |
Configure(Configuration, Int32)
Configure BASS.
Declaration
public static bool Configure(Configuration Option, int NewValue)
Parameters
Configuration
Option
One of Configuration values. |
Int32
NewValue
The New Value of the option. |
Returns
Boolean
If succesful, then true is returned, else false is returned. Use LastError to get the error code. |
CreateSample(Int32, Int32, Int32, Int32, BassFlags)
Initiates the creation of a user generated sample.
Example
Create a 440 Hz sine wave sample.
// create sample
var sample = Bass.CreateSample(256, 28160, 1, 1, BassFlags.Loop | BassFlags.SampleOverrideLongestPlaying);
var data = new short[128]; // data buffer
for (var a = 0; a < 128; a++)
data[a]= (short)(32767 * Math.Sin((double)a * 6.283185 / 64)); // sine wave
// set the sample's data
Bass.SampleSetData(sample, data);
Declaration
public static int CreateSample(int Length, int Frequency, int Channels, int Max, BassFlags Flags)
Parameters
Int32
Length
The sample's length, in bytes. |
||||||||||||||||||||||
Int32
Frequency
The default sample rate. |
||||||||||||||||||||||
Int32
Channels
The number of channels... 1 = mono, 2 = stereo, etc... More than stereo requires WDM drivers in Windows. |
||||||||||||||||||||||
Int32
Max
Maximum number of simultaneous playbacks... 1 (min) - 65535 (max)... use one of the override 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). |
||||||||||||||||||||||
BassFlags
Flags
A combination of these flags:
|
Returns
Int32
If successful, the new sample's handle is returned, else 0 is returned. Use LastError to get the error code. |
Remarks
The sample's initial content is undefined. SampleSetData(Int32, IntPtr) should be used to set the sample's data.
Unless the BassFlags.SoftwareMixing flag is used, the sample will use hardware mixing if hardware resources are available. Use GetInfo(out BassInfo) to see if there are hardware mixing resources available, and which sample formats are supported by the hardware. The 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 SampleSetInfo(Int32, SampleInfo).
To play a sample, first a channel must be obtained using SampleGetChannel(Int32, Boolean), which can then be played using 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 CreateStream(Int32, Int32, BassFlags, StreamProcedure, IntPtr).
Platform-specific
The VAM flag requires DirectX 7 (or above).
CreateStream(IntPtr, Int64, Int64, BassFlags)
Creates a sample stream from an MP3, MP2, MP1, OGG, WAV, AIFF or plugin supported memory IntPtr.
Declaration
public static int CreateStream(IntPtr Memory, long Offset, long Length, BassFlags Flags = BassFlags.Default)
Parameters
IntPtr
Memory
An unmanaged pointer to the memory location as an IntPtr. |
Int64
Offset
Offset to begin streaming from. |
Int64
Length
Data length (needs to be set to the length of the memory stream in bytes which should be played). |
BassFlags
Flags
Any combination of BassFlags. |
Returns
Int32
If successful, the new stream's handle is returned, else 0 is returned. Use LastError to get the error code. |
Remarks
BASS has built-in support for MPEG, OGG, WAV and AIFF files. Support for additional formats is available via add-ons, which can be downloaded from the BASS website: www.un4seen.com.
MPEG 1.0, 2.0 and 2.5 layer 3 (MP3) files are supported, layers 1 (MP1) and 2 (MP2) are also supported. Standard RIFF and RF64 WAV files are supported, with the sample data in a PCM format or compressed with an ACM codec, but the codec is required to be installed on the user's system for the WAV to be decoded. So you should either distribute the codec with your software, or use a codec that comes with Windows (eg. Microsoft ADPCM). All PCM formats from 8 to 32-bit are supported in WAV and AIFF files, but the output will be restricted to 16-bit unless the Float flag is used. 64-bit floating-point WAV and AIFF files are also supported, but are rendered in 16-bit or 32-bit floating-point depending on the flags. The file's original resolution is available via ChannelGetInfo(Int32, out ChannelInfo).
Chained OGG files containing multiple logical bitstreams are supported, but seeking within them is only fully supported if the Prescan flag is used (or the OggPreScan config option is enabled) to have them pre-scanned. Without pre-scanning, seeking will only be possible back to the start. The OGG mode can be used with ChannelGetLength(Int32, PositionFlags) to get the number of bitstreams and with ChannelSetPosition(Int32, Int64, PositionFlags) to seek to a particular one. A OggChange sync can be set via ChannelSetSync(Int32, SyncFlags, Int64, SyncProcedure, IntPtr) to be informed of when a new bitstream begins during decoding/playback.
Multi-channel (ie. more than stereo) OGG, WAV and AIFF files are supported.
Use ChannelGetInfo(Int32, out ChannelInfo) to retrieve information on the format (sample rate, resolution, channels) of the stream. The playback length of the stream can be retrieved using ChannelGetLength(Int32, PositionFlags).
If Length
= 0 (use all data up to the end of the file), and the file length increases after creating the stream (ie. the file is still being written), then BASS will play the extra data too, but the length returned by ChannelGetLength(Int32, PositionFlags) will not be updated until the end is reached.
The StreamGetFilePosition(Int32, FileStreamPosition) return values will be updated during playback of the extra data though.
When streaming from memory, the memory must not be freed before the stream is freed. There may be exceptions to that with some add-ons (see the documentation).
To stream a file from the internet, use CreateStream(String, Int32, BassFlags, DownloadProcedure, IntPtr). To stream from other locations, see CreateStream(StreamSystem, BassFlags, FileProcedures, IntPtr).
The Memory buffer must be pinned when using this overload.
Platform-specific
On Windows and Windows CE, ACM codecs are supported with compressed WAV files. Media Foundation codecs are also supported on Windows 7 and updated versions of Vista, including support for AAC/MP4 and WMA. On iOS and OSX, CoreAudio codecs are supported, adding support for any file formats that have a codec installed. Media Foundation and CoreAudio codecs are only tried after the built-in decoders and any plugins have rejected the file.
CreateStream(StreamSystem, BassFlags, FileProcedures, IntPtr)
Creates a sample stream from an MP3, MP2, MP1, OGG, WAV, AIFF or plugin supported file via user callback functions.
Declaration
public static int CreateStream(StreamSystem System, BassFlags Flags, FileProcedures Procedures, IntPtr User = null)
Parameters
StreamSystem
System
File system to use. |
BassFlags
Flags
Any combination of BassFlags. |
FileProcedures
Procedures
The user defined file function (see FileProcedures). |
IntPtr
User
User instance data to pass to the callback functions. |
Returns
Int32
If successful, the new stream's handle is returned, else 0 is returned. Use LastError to get the error code. |
Remarks
The buffered file system (Buffer) is what is used by CreateStream(String, Int32, BassFlags, DownloadProcedure, IntPtr). As the name suggests, data from the file is buffered so that it's readily available for decoding - BASS creates a thread dedicated to "downloading" the data. This is ideal for when the data is coming from a source that has high latency, like the internet. It's not possible to seek in buffered file streams, until the download has reached the requested position - it's not possible to seek at all if it's being streamed in blocks.
The push buffered file system (BufferPush) is the same, except that instead of the file data being pulled from the FileReadProcedure function in a "download" thread, the data is pushed to BASS via StreamPutFileData(Int32, IntPtr, Int32). A FileReadProcedure function is still required, to get the initial data used in the creation of the stream.
The unbuffered file system (NoBuffer) is what is used by CreateStream(String, Int64, Int64, BassFlags). In this system, BASS does not do any intermediate buffering - it simply requests data from the file as and when it needs it. This means that reading (FileReadProcedure) must be quick, otherwise the decoding will be delayed and playback buffer underruns (old data repeated) are a possibility. It's not so important for seeking (FileSeekProcedure) to be fast, as that is generally not required during decoding, except when looping a file.
In all cases, BASS will automatically stall playback of the stream when insufficient data is available, and resume it when enough data does become available.
Platform-specific
On Windows and Windows CE, ACM codecs are supported with compressed WAV files. Media Foundation codecs are also supported on Windows 7 and updated versions of Vista, including support for AAC/MP4 and WMA. On iOS and OSX, CoreAudio codecs are supported, adding support for any file formats that have a codec installed. Media Foundation and CoreAudio codecs are only tried after the built-in decoders and any plugins have rejected the file.
A copy is made of the Procedures
callback function table, so it does not have to persist beyond this function call.
Unlike Bass.Net, a reference to Procedures
doesn't need to be held by you manually.
ManagedBass automatically holds a reference and frees it when the Channel is freed.
CreateStream(Byte[], Int64, Int64, BassFlags)
Creates a sample stream from an MP3, MP2, MP1, OGG, WAV, AIFF or plugin supported file in memory (byte[]).
Declaration
public static int CreateStream(byte[] Memory, long Offset, long Length, BassFlags Flags)
Parameters
Byte[]
Memory
A byte[] containing file data. |
||||||||||||||||||||||
Int64
Offset
Offset to begin streaming from. |
||||||||||||||||||||||
Int64
Length
Data length (needs to be set to the length of the memory stream in bytes which should be played). |
||||||||||||||||||||||
BassFlags
Flags
A combination of these flags:
|
Returns
Int32
If successful, the new stream's handle is returned, else 0 is returned. Use LastError to get the error code. |
Remarks
BASS has built-in support for MPEG, OGG, WAV and AIFF files. Support for additional formats is available via add-ons, which can be downloaded from the BASS website: www.un4seen.com.
MPEG 1.0, 2.0 and 2.5 layer 3 (MP3) files are supported, layers 1 (MP1) and 2 (MP2) are also supported. Standard RIFF and RF64 WAV files are supported, with the sample data in a PCM format or compressed with an ACM codec, but the codec is required to be installed on the user's system for the WAV to be decoded. So you should either distribute the codec with your software, or use a codec that comes with Windows (eg. Microsoft ADPCM). All PCM formats from 8 to 32-bit are supported in WAV and AIFF files, but the output will be restricted to 16-bit unless the Float flag is used. 64-bit floating-point WAV and AIFF files are also supported, but are rendered in 16-bit or 32-bit floating-point depending on the flags. The file's original resolution is available via ChannelGetInfo(Int32, out ChannelInfo).
Chained OGG files containing multiple logical bitstreams are supported, but seeking within them is only fully supported if the Prescan flag is used (or the OggPreScan config option is enabled) to have them pre-scanned. Without pre-scanning, seeking will only be possible back to the start. The OGG mode can be used with ChannelGetLength(Int32, PositionFlags) to get the number of bitstreams and with ChannelSetPosition(Int32, Int64, PositionFlags) to seek to a particular one. A OggChange sync can be set via ChannelSetSync(Int32, SyncFlags, Int64, SyncProcedure, IntPtr) to be informed of when a new bitstream begins during decoding/playback.
Multi-channel (ie. more than stereo) OGG, WAV and AIFF files are supported.
Use ChannelGetInfo(Int32, out ChannelInfo) to retrieve information on the format (sample rate, resolution, channels) of the stream. The playback length of the stream can be retrieved using ChannelGetLength(Int32, PositionFlags).
If Length
= 0 (use all data up to the end of the file), and the file length increases after creating the stream (ie. the file is still being written), then BASS will play the extra data too, but the length returned by ChannelGetLength(Int32, PositionFlags) will not be updated until the end is reached.
The StreamGetFilePosition(Int32, FileStreamPosition) return values will be updated during playback of the extra data though.
The Memory
is pinned by this overload and freed when the stream is freed.
To stream a file from the internet, use CreateStream(String, Int32, BassFlags, DownloadProcedure, IntPtr). To stream from other locations, see CreateStream(StreamSystem, BassFlags, FileProcedures, IntPtr).
Platform-specific
On Windows and Windows CE, ACM codecs are supported with compressed WAV files. Media Foundation codecs are also supported on Windows 7 and updated versions of Vista, including support for AAC/MP4 and WMA. On iOS and OSX, CoreAudio codecs are supported, adding support for any file formats that have a codec installed. Media Foundation and CoreAudio codecs are only tried after the built-in decoders and any plugins have rejected the file.
CreateStream(Int32, Int32, BassFlags, StreamProcedure, IntPtr)
Creates a user sample stream.
Declaration
public static int CreateStream(int Frequency, int Channels, BassFlags Flags, StreamProcedure Procedure, IntPtr User = null)
Parameters
Int32
Frequency
The default sample rate. The sample rate can be changed using ChannelSetAttribute(Int32, ChannelAttribute, Single). |
Int32
Channels
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. |
BassFlags
Flags
A combination of BassFlags. |
StreamProcedure
Procedure
The user defined stream writing function (see StreamProcedure). |
IntPtr
User
User instance data to pass to the callback function. |
Returns
Int32
If successful, the new stream's handle is returned, else 0 is returned. Use LastError to get the error code. |
Remarks
Sample streams allow any sample data to be played through Bass, and are particularly useful for playing a large amount of sample data without requiring a large amount of memory. If you wish to play a sample format that BASS does not support, then you can create a stream and decode the sample data into it.
Bass can automatically stream MP3, MP2, MP1, OGG, WAV and AIFF files, using CreateStream(String, Int64, Int64, BassFlags), and also from HTTP and FTP servers, using CreateStream(String, Int32, BassFlags, DownloadProcedure, IntPtr), CreateStream(StreamSystem, BassFlags, FileProcedures, IntPtr) allows streaming from other sources too.
However, the callback method must deliver PCM sample data as specified, so opening an MP3 file and just passing that file data will not work here.
Unlike Bass.Net, a reference to Procedure
doesn't need to be held by you manually.
ManagedBass automatically holds a reference and frees it when the Channel is freed.
CreateStream(Int32, Int32, BassFlags, StreamProcedureType)
Creates a Dummy or Push stream.
Declaration
public static int CreateStream(int Frequency, int Channels, BassFlags Flags, StreamProcedureType ProcedureType)
Parameters
Int32
Frequency
The default sample rate. The sample rate can be changed using ChannelSetAttribute(Int32, ChannelAttribute, Single). |
||||||||||||||||||
Int32
Channels
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. |
||||||||||||||||||
BassFlags
Flags
A combination of these flags:
|
||||||||||||||||||
StreamProcedureType
ProcedureType
The type of stream. |
Returns
Int32
If successful, the new stream's handle is returned, else 0 is returned. Use LastError to get the error code. |
Remarks
A dummy stream doesn't have any sample data of its own, but a decoding dummy stream (with Decode flag) can be used to apply DSP/FX processing to any sample data, by setting DSP/FX on the stream and feeding the data through ChannelGetData(Int32, IntPtr, Int32).
The dummy stream should have the same sample format as the data being fed through it.
CreateStream(String, Int32, BassFlags, DownloadProcedure, IntPtr)
Creates a sample stream from an MP3, MP2, MP1, OGG, WAV, AIFF or plugin supported file on the internet, optionally receiving the downloaded data in a callback.
Declaration
public static int CreateStream(string Url, int Offset, BassFlags Flags, DownloadProcedure Procedure, IntPtr User = null)
Parameters
String
Url
URL of the file to stream. Should begin with "http://", "https://" or "ftp://", or another add-on supported protocol. The URL can be followed by custom HTTP request headers to be sent to the server; the URL and each header should be terminated with a carriage return and line feed ("\r\n"). |
Int32
Offset
File position to start streaming from. This is ignored by some servers, specifically when the file length is unknown, for example a Shout/Icecast server. |
BassFlags
Flags
A combination of BassFlags |
DownloadProcedure
Procedure
Callback function to receive the file as it is downloaded... null = no callback. |
IntPtr
User
User instance data to pass to the callback function. |
Returns
Int32
If successful, the new stream's handle is returned, else 0 is returned. Use LastError to get the error code. |
Remarks
Use ChannelGetInfo(Int32, out ChannelInfo) to retrieve information on the format (sample rate, resolution, channels) of the stream. The playback length of the stream can be retrieved using ChannelGetLength(Int32, PositionFlags).
When playing the stream, BASS will stall the playback if there is insufficient data to continue playing. Playback will automatically be resumed when sufficient data has been downloaded. ChannelIsActive(Int32) can be used to check if the playback is stalled, and the progress of the file download can be checked with StreamGetFilePosition(Int32, FileStreamPosition).
When streaming in blocks (StreamDownloadBlocks), be careful not to stop/pause the stream for too long, otherwise the connection may timeout due to there being no activity and the stream will end prematurely.
When streaming from Shoutcast servers, metadata (track titles) may be sent by the server. The data can be retrieved with ChannelGetTags(Int32, TagType). A sync can also be set (using ChannelSetSync(Int32, SyncFlags, Int64, SyncProcedure, IntPtr)) so that you are informed when metadata is received. A OggChange sync can be used to be informed of when a new logical bitstream begins in an Icecast/OGG stream.
When using an Offset
, the file length returned by StreamGetFilePosition(Int32, FileStreamPosition) can be used to check that it was successful by comparing it with the original file length.
Another way to check is to inspect the HTTP headers retrieved with ChannelGetTags(Int32, TagType).
Custom HTTP request headers may be ignored by some plugins, notably BassWma.
Unlike Bass.Net, a reference to Procedure
doesn't need to be held by you manually.
ManagedBass automatically holds a reference and frees it when the Channel is freed.
Platform-specific
On Windows and Windows CE, ACM codecs are supported with compressed WAV files. Media Foundation codecs are also supported on Windows 7 and updated versions of Vista, including support for AAC and WMA. On iOS and OSX, CoreAudio codecs are supported, including support for AAC and ALAC. Media Foundation and CoreAudio codecs are only tried after the built-in decoders and any plugins have rejected the file. Built-in support for IMA and Microsoft ADPCM WAV files is provided on Linux/Android/Windows CE, while they are supported via ACM and CoreAudio codecs on Windows and OSX/iOS.
CreateStream(String, Int64, Int64, BassFlags)
Creates a sample stream from an MP3, MP2, MP1, OGG, WAV, AIFF or plugin supported file.
Declaration
public static int CreateStream(string File, long Offset = null, long Length = null, BassFlags Flags = BassFlags.Default)
Parameters
String
File
Filename for which a stream should be created. |
||||||||||||||||||||||||
Int64
Offset
File Offset to begin streaming from. |
||||||||||||||||||||||||
Int64
Length
Data length... 0 = use all data up to the end of the file. |
||||||||||||||||||||||||
BassFlags
Flags
A combination of these flags:
|
Returns
Int32
If successful, the new stream's handle is returned, else 0 is returned. Use LastError to get the error code. |
Remarks
BASS has built-in support for MPEG, OGG, WAV and AIFF files. Support for additional formats is available via add-ons, which can be downloaded from the BASS website: www.un4seen.com.
MPEG 1.0, 2.0 and 2.5 layer 3 (MP3) files are supported, layers 1 (MP1) and 2 (MP2) are also supported. Standard RIFF and RF64 WAV files are supported, with the sample data in a PCM format or compressed with an ACM codec, but the codec is required to be installed on the user's system for the WAV to be decoded. So you should either distribute the codec with your software, or use a codec that comes with Windows (eg. Microsoft ADPCM). All PCM formats from 8 to 32-bit are supported in WAV and AIFF files, but the output will be restricted to 16-bit unless the Float flag is used. 64-bit floating-point WAV and AIFF files are also supported, but are rendered in 16-bit or 32-bit floating-point depending on the flags. The file's original resolution is available via ChannelGetInfo(Int32, out ChannelInfo).
Chained OGG files containing multiple logical bitstreams are supported, but seeking within them is only fully supported if the Prescan flag is used (or the OggPreScan config option is enabled) to have them pre-scanned. Without pre-scanning, seeking will only be possible back to the start. The OGG mode can be used with ChannelGetLength(Int32, PositionFlags) to get the number of bitstreams and with ChannelSetPosition(Int32, Int64, PositionFlags) to seek to a particular one. A OggChange sync can be set via ChannelSetSync(Int32, SyncFlags, Int64, SyncProcedure, IntPtr) to be informed of when a new bitstream begins during decoding/playback.
Multi-channel (ie. more than stereo) OGG, WAV and AIFF files are supported.
Use ChannelGetInfo(Int32, out ChannelInfo) to retrieve information on the format (sample rate, resolution, channels) of the stream. The playback length of the stream can be retrieved using ChannelGetLength(Int32, PositionFlags).
If Length
= 0 (use all data up to the end of the file), and the file length increases after creating the stream (ie. the file is still being written), then BASS will play the extra data too, but the length returned by ChannelGetLength(Int32, PositionFlags) will not be updated until the end is reached.
The StreamGetFilePosition(Int32, FileStreamPosition) return values will be updated during playback of the extra data though.
To stream a file from the internet, use CreateStream(String, Int32, BassFlags, DownloadProcedure, IntPtr). To stream from other locations, see CreateStream(StreamSystem, BassFlags, FileProcedures, IntPtr).
Platform-specific
On Windows and Windows CE, ACM codecs are supported with compressed WAV files. Media Foundation codecs are also supported on Windows 7 and updated versions of Vista, including support for AAC/MP4 and WMA. On iOS and OSX, CoreAudio codecs are supported, adding support for any file formats that have a codec installed. Media Foundation and CoreAudio codecs are only tried after the built-in decoders and any plugins have rejected the file.
Free()
Frees all resources used by the output device, including all it's samples, streams, and MOD musics.
Declaration
public static bool Free()
Returns
Boolean
If successful, then true is returned, else false is returned. Use LastError to get the error code. |
Remarks
This function should be called for all initialized devices before your program exits. It's not necessary to individually free the samples/streams/musics as these are all automatically freed by this function.
When using multiple devices, the current thread's device setting (as set with CurrentDevice) determines which device this function call applies to.
FXGetParameters(Int32, IntPtr)
Retrieves the parameters of an effect
Declaration
public static bool FXGetParameters(int Handle, IntPtr Parameters)
Parameters
Int32
Handle
The effect handle |
IntPtr
Parameters
Pointer to the parameters structure to fill. The structure used depends on the effect type. |
Returns
Boolean
If successful, true is returned, else false is returned. Use LastError to get the error code. |
See Also
FXGetParameters(Int32, IEffectParameter)
Retrieves the parameters of an effect
Declaration
public static bool FXGetParameters(int Handle, IEffectParameter Parameters)
Parameters
Int32
Handle
The effect handle |
IEffectParameter
Parameters
The parameters structure to fill. The structure used depends on the effect type. |
Returns
Boolean
If successful, true is returned, else false is returned. Use LastError to get the error code. |
See Also
FXReset(Int32)
Resets the state of an effect or all effects on a channel.
Declaration
public static bool FXReset(int Handle)
Parameters
Int32
Handle
The effect or channel handle... a HFX, HSTREAM, HMUSIC, or HRECORD. |
Returns
Boolean
If successful, true is returned, else false is returned. Use LastError to get the error code. |
Remarks
This function flushes the internal buffers of the effect(s). Effects are automatically reset by ChannelSetPosition(Int32, Int64, PositionFlags), except when called from a "Mixtime" SyncProcedure.
See Also
FXSetParameters(Int32, IntPtr)
Sets the parameters of an effect
Declaration
public static bool FXSetParameters(int Handle, IntPtr Parameters)
Parameters
Int32
Handle
The effect handle |
IntPtr
Parameters
Pointer to the parameters structure. The structure used depends on the effect type. |
Returns
Boolean
If successful, true is returned, else false is returned. Use LastError to get the error code. |
See Also
FXSetParameters(Int32, IEffectParameter)
Sets the parameters of an effect
Declaration
public static bool FXSetParameters(int Handle, IEffectParameter Parameters)
Parameters
Int32
Handle
The effect handle |
IEffectParameter
Parameters
The parameters structure. The structure used depends on the effect type. |
Returns
Boolean
If successful, true is returned, else false is returned. Use LastError to get the error code. |
See Also
FXSetPriority(Int32, Int32)
Sets the priority of an effect or DSP function, which determines its position in the DSP chain.
Declaration
public static bool FXSetPriority(int Handle, int Priority)
Parameters
Int32
Handle
The DSP/FX handle... a HDSP or HFX. |
Int32
Priority
The new priority of the DSP/FX. |
Returns
Boolean
If successful, true is returned, else false is returned. Use LastError to get the error code. |
Remarks
If there are multiple DSP/FX with the same priority value, they will be applied in the order in which they were given that priority.
Get3DFactors(ref Single, ref Single, ref Single)
Retrieves the factors that affect the calculations of 3D sound.
Declaration
public static bool Get3DFactors(ref float Distance, ref float RollOff, ref float Doppler)
Parameters
Single
Distance
The distance factor. |
Single
RollOff
The rolloff factor. |
Single
Doppler
The doppler factor. |
Returns
Boolean
If succesful, then true is returned, else false is returned. Use LastError to get the error code. |
Remarks
When using multiple devices, the current thread's device setting (as set with CurrentDevice) determines which device this function call applies to.
See Also
Get3DPosition(ref Vector3D, ref Vector3D, ref Vector3D, ref Vector3D)
Retrieves the position, velocity, and orientation of the listener.
Declaration
public static bool Get3DPosition(ref Vector3D Position, ref Vector3D Velocity, ref Vector3D Front, ref Vector3D Top)
Parameters
Vector3D
Position
The position of the listener |
Vector3D
Velocity
The listener's velocity |
Vector3D
Front
The direction that the listener's front is pointing |
Vector3D
Top
The direction that the listener's top is pointing |
Returns
Boolean
If succesful, then true is returned, else false is returned. Use LastError to get the error code. |
Remarks
The Front
and Top
parameters must both be retrieved in a single call, they can not be retrieved individually.
When using multiple devices, the current thread's device setting (as set with CurrentDevice) determines which device this function call applies to.
See Also
GetConfig(Configuration)
Get Configuration value.
Declaration
public static int GetConfig(Configuration Option)
Parameters
Configuration
Option
One of Configuration values. |
Returns
Int32
The configuration value or -1 on error. Use LastError to get the error code. |
GetConfigBool(Configuration)
Get boolean Configuration value.
Declaration
public static bool GetConfigBool(Configuration Option)
Parameters
Configuration
Option
One of the Configuration values. |
Returns
Boolean
The configuration value. In case of error, false is returned. |
GetConfigPtr(Configuration)
Get Configuration value.
Declaration
public static IntPtr GetConfigPtr(Configuration Option)
Parameters
Configuration
Option
One of Configuration values. |
Returns
IntPtr
|
GetDeviceInfo(Int32)
Retrieves information on an output device.
Declaration
public static DeviceInfo GetDeviceInfo(int Device)
Parameters
Int32
Device
The device to get the information of... 0 = first. |
Returns
DeviceInfo
An instance of the DeviceInfo structure is returned. Throws BassException on Error. |
Remarks
This function can be used to enumerate the available devices for a setup dialog. Device 0 is always the NoSoundDevice device, so if you should start at device 1 if you only want to list real devices.
Platform-specific
On Linux, a "Default" device is hardcoded to device number 1, which uses the default output set in the ALSA config, and the real devices start at number 2. That is also the case on Windows when the IncludeDefaultDevice option is enabled.
GetDeviceInfo(Int32, out DeviceInfo)
Retrieves information on an output device.
Example
Get the total number of devices currently present.
var count = 0;
DeviceInfo info;
for (var a = 0; Bass.GetDeviceInfo(a, out info); a++)
if (info.IsEnabled) // device is enabled
count++; // count it
Declaration
public static bool GetDeviceInfo(int Device, out DeviceInfo Info)
Parameters
Int32
Device
The device to get the information of... 0 = first. |
DeviceInfo
Info
A DeviceInfo object to retrieve the information into. |
Returns
Boolean
If successful, then true is returned, else false is returned. Use LastError to get the error code. |
Remarks
This function can be used to enumerate the available devices for a setup dialog. Device 0 is always the NoSoundDevice device, so if you should start at device 1 if you only want to list real devices.
Platform-specific
On Linux, a "Default" device is hardcoded to device number 1, which uses the default output set in the ALSA config, and the real devices start at number 2. That is also the case on Windows when the IncludeDefaultDevice option is enabled.
GetInfo(out BassInfo)
Retrieves information on the device being used.
Example
Check if the current device can have multiple inputs enabled.
RecordInfo info;
Bass.RecordGetInfo(out info);
if (!info.SingleInput)
{
// device does allow multiple inputs to be enabled
}
Declaration
public static bool GetInfo(out BassInfo Info)
Parameters
BassInfo
Info
BassInfo object to receive the information. |
Returns
Boolean
If successful, then true is returned, else false is returned. Use LastError to get the error code. |
Remarks
When using multiple devices, the current thread's device setting (as set with CurrentDevice) determines which device this function call applies to.
Init(Int32, Int32, DeviceInitFlags, IntPtr, IntPtr)
Initializes an output device.
Declaration
public static bool Init(int Device = null, int Frequency = 44100, DeviceInitFlags Flags = DeviceInitFlags.Default, IntPtr Win = null, IntPtr ClsID = null)
Parameters
Int32
Device
The device to use... -1 = default device, 0 = no sound, 1 = first real output device. GetDeviceInfo(Int32, out DeviceInfo) or DeviceCount can be used to get the total number of devices. |
Int32
Frequency
Output sample rate. |
DeviceInitFlags
Flags
Any combination of DeviceInitFlags. |
IntPtr
Win
The application's main window... |
IntPtr
ClsID
Class identifier of the object to create, that will be used to initialize DirectSound... null = use default |
Returns
Boolean
If the device was successfully initialized, true is returned, else false is returned. Use LastError to get the error code. |
Remarks
This function must be successfully called before using any sample, stream or MOD music functions. The recording functions may be used without having called this function.
Playback is not possible with the NoSoundDevice device, but it does allow the use of "decoding channels", eg. to decode files.
When specifying a class identifier (ClsID
), after successful initialization, you can use GetDSoundObject(DSInterface) to retrieve the DirectSound object, and through that access any special interfaces that the object may provide.
Simultaneously using multiple devices is supported in the BASS API via a context switching system - instead of there being an extra "device" parameter in the function calls, the device to be used is set prior to calling the functions. CurrentDevice is used to switch the current device. When successful, Init(Int32, Int32, DeviceInitFlags, IntPtr, IntPtr) automatically sets the current thread's device to the one that was just initialized.
When using the default device (device = -1), CurrentDevice can be used to find out which device it was mapped to. On Windows, it'll always be the first device.
Platform-specific
On Linux, a 'Default' device is hardcoded to device number 1, which uses the default output set in the ALSA config; that could map directly to one of the other devices or it could use ALSA plugins. If the IncludeDefaultDevice config option has been enbled, a "Default" device is also available on Windows, who's output will follow default device changes on Windows 7. In both cases, the "Default" device will also be the default device (device = -1).
The sample format specified in the Frequency
and Flags
parameters has no effect on the device output on iOS or OSX, and not on Windows unless VxD drivers are used (on Windows 98/95);
with WDM drivers (on Windows XP/2000/Me/98SE), the output format is automatically set depending on the format of what is played and what the device supports, while on Vista and above, the output format is determined by the user's choice in the Sound control panel.
On Linux the output device will use the specified format if possible, but will otherwise use a format as close to it as possible.
If the Frequency flag is specified on iOS or OSX, then the device's output rate will be set to the freq parameter (if possible).
The Frequency flag has no effect on other platforms.
GetInfo(out BassInfo) can be used to check what the output format actually is.
The Win
and ClsID
parameters are only used on Windows and are ignored on other platforms.
That applies to the CPSpeakers and ForcedSpeakerAssignment flags too, as the number of available speakers is always accurately detected on the other platforms.
The Latency flag is also ignored on Linux/OSX/Android/Windows CE, as latency information is available without it.
The latency is also available without it on iOS, but not immediately following this function call unless the flag is used.
The DeviceInitFlags.DMix flag is only available on Linux, and allows multiple applications to share the device (if they all use 'dmix'). It may also be possible for multiple applications to use exclusive access if the device is capable of hardware mixing. If exclusive access initialization fails, the DeviceInitFlags.DMix flag will automatically be tried; if that happens, it can be detected via GetInfo(out BassInfo) and the InitFlags.
On Linux and Windows CE, the length of the device's buffer can be set via the PlaybackBufferLength config option.
See Also
MusicFree(Int32)
Frees a MOD music's resources, including any sync/DSP/FX it has.
Declaration
public static bool MusicFree(int Handle)
Parameters
Int32
Handle
The MOD music handle. |
Returns
Boolean
If successful, then true is returned, else false is returned. Use LastError to get the error code. |
MusicLoad(IntPtr, Int64, Int32, BassFlags, Int32)
Loads a MOD music file - MO3 / IT / XM / S3M / MTM / MOD / UMX formats from memory.
Declaration
public static int MusicLoad(IntPtr Memory, long Offset, int Length, BassFlags Flags = BassFlags.Default, int Frequency = 0)
Parameters
IntPtr
Memory
An unmanaged pointer to the memory location as an IntPtr. |
Int64
Offset
Memory offset to load the MOD music from. |
Int32
Length
Data length. |
BassFlags
Flags
A combination of BassFlags. |
Int32
Frequency
Sample rate to render/play the MOD music at... 0 = the rate specified in the Init(Int32, Int32, DeviceInitFlags, IntPtr, IntPtr) call. |
Returns
Int32
If successful, the loaded music's handle is returned, else 0 is returned. Use LastError to get the error code. |
Remarks
BASS uses the same code as XMPlay for it's MOD music support, giving the most accurate reproduction of MO3 / IT / XM / S3M / MTM / MOD / UMX files available from any sound system.
MO3s are treated and used in exactly the same way as normal MOD musics. The advantage of MO3s is that they can be a lot smaller with virtually identical quality. Playing a MO3 does not use any more CPU power than playing the original MOD version does. The only difference is a slightly longer load time as the samples are being decoded. MO3 files are created using the MO3 encoder available at the BASS website.
DMO effects (the same as available with ChannelSetFX(Int32, EffectType, Int32)) can be used in IT and XM files (and MO3 versions of them) created with Modplug Tracker. This allows effects to be added to a track without having to resort to an MP3 or OGG version, so it can remain small and still sound fancy. Of course, the effects require some CPU, so should not be used carelessly if performance is key. DirectX 8 (or above) is required for the effects to be heard - without that, the music can still be played, but the effects are disabled.
"Ramping" does not take a lot of extra processing and improves the sound quality by removing clicks, by ramping/smoothing volume and pan changes. The start of a sample may also be ramped-in. That is always the case with XM files (or MOD files in FT2 mode) when using normal ramping, and possibly with all formats when using sensitive ramping; senstitive ramping will only ramp-in when necessary to avoid a click. Generally, normal ramping is recommended for XM files, and sensitive ramping for the other formats, but some XM files may also sound better using sensitive ramping.
When loading a MOD music from memory, Bass does not use the memory after it has loaded the MOD music. So you can do whatever you want with the memory after calling this function. This means there is no need to pin the memory buffer for this method.
Platform-specific
DMO effects are not supported in MOD music on Windows CE, and DirectX 8 (or above) is required on Windows. They are always available on other platforms, except for the following: Compressor, Gargle, and I3DL2Reverb. When a DMO effect is unavailable, the MOD music can still be played, but the effect will be disabled.
MusicLoad(Byte[], Int64, Int32, BassFlags, Int32)
Loads a MOD music file - MO3 / IT / XM / S3M / MTM / MOD / UMX formats from memory.
Declaration
public static int MusicLoad(byte[] Memory, long Offset, int Length, BassFlags Flags = BassFlags.Default, int Frequency = 0)
Parameters
Byte[]
Memory
byte[] containing the music data. |
Int64
Offset
Memory offset to load the MOD music from. |
Int32
Length
Data length. |
BassFlags
Flags
A combination of BassFlags. |
Int32
Frequency
Sample rate to render/play the MOD music at... 0 = the rate specified in the Init(Int32, Int32, DeviceInitFlags, IntPtr, IntPtr) call. |
Returns
Int32
If successful, the loaded music's handle is returned, else 0 is returned. Use LastError to get the error code. |
Remarks
BASS uses the same code as XMPlay for it's MOD music support, giving the most accurate reproduction of MO3 / IT / XM / S3M / MTM / MOD / UMX files available from any sound system.
MO3s are treated and used in exactly the same way as normal MOD musics. The advantage of MO3s is that they can be a lot smaller with virtually identical quality. Playing a MO3 does not use any more CPU power than playing the original MOD version does. The only difference is a slightly longer load time as the samples are being decoded. MO3 files are created using the MO3 encoder available at the BASS website.
DMO effects (the same as available with ChannelSetFX(Int32, EffectType, Int32)) can be used in IT and XM files (and MO3 versions of them) created with Modplug Tracker. This allows effects to be added to a track without having to resort to an MP3 or OGG version, so it can remain small and still sound fancy. Of course, the effects require some CPU, so should not be used carelessly if performance is key. DirectX 8 (or above) is required for the effects to be heard - without that, the music can still be played, but the effects are disabled.
"Ramping" does not take a lot of extra processing and improves the sound quality by removing clicks, by ramping/smoothing volume and pan changes. The start of a sample may also be ramped-in. That is always the case with XM files (or MOD files in FT2 mode) when using normal ramping, and possibly with all formats when using sensitive ramping; senstitive ramping will only ramp-in when necessary to avoid a click. Generally, normal ramping is recommended for XM files, and sensitive ramping for the other formats, but some XM files may also sound better using sensitive ramping.
When loading a MOD music from memory, Bass does not use the memory after it has loaded the MOD music. So you can do whatever you want with the memory after calling this function.
Platform-specific
DMO effects are not supported in MOD music on Windows CE, and DirectX 8 (or above) is required on Windows. They are always available on other platforms, except for the following: Compressor, Gargle, and I3DL2Reverb. When a DMO effect is unavailable, the MOD music can still be played, but the effect will be disabled.
MusicLoad(String, Int64, Int32, BassFlags, Int32)
Loads a MOD music file - MO3 / IT / XM / S3M / MTM / MOD / UMX formats.
Declaration
public static int MusicLoad(string File, long Offset = null, int Length = 0, BassFlags Flags = BassFlags.Default, int Frequency = 0)
Parameters
String
File
The file name from where to load the music. |
||||||||||||||||||||||||||||||||||||||||||||||||||
Int64
Offset
File offset to load the MOD music from. |
||||||||||||||||||||||||||||||||||||||||||||||||||
Int32
Length
Data length... 0 = use all data up to the end of file. If length over-runs the end of the file, it'll automatically be lowered to the end of the file. |
||||||||||||||||||||||||||||||||||||||||||||||||||
BassFlags
Flags
A combination of these flags:
|
||||||||||||||||||||||||||||||||||||||||||||||||||
Int32
Frequency
Sample rate to render/play the MOD music at... 0 = the rate specified in the Init(Int32, Int32, DeviceInitFlags, IntPtr, IntPtr) call. |
Returns
Int32
If successful, the loaded music's handle is returned, else 0 is returned. Use LastError to get the error code. |
Remarks
BASS uses the same code as XMPlay for it's MOD music support, giving the most accurate reproduction of MO3 / IT / XM / S3M / MTM / MOD / UMX files available from any sound system.
MO3s are treated and used in exactly the same way as normal MOD musics. The advantage of MO3s is that they can be a lot smaller with virtually identical quality. Playing a MO3 does not use any more CPU power than playing the original MOD version does. The only difference is a slightly longer load time as the samples are being decoded. MO3 files are created using the MO3 encoder available at the BASS website.
DMO effects (the same as available with ChannelSetFX(Int32, EffectType, Int32)) can be used in IT and XM files (and MO3 versions of them) created with Modplug Tracker. This allows effects to be added to a track without having to resort to an MP3 or OGG version, so it can remain small and still sound fancy. Of course, the effects require some CPU, so should not be used carelessly if performance is key. DirectX 8 (or above) is required for the effects to be heard - without that, the music can still be played, but the effects are disabled.
"Ramping" does not take a lot of extra processing and improves the sound quality by removing clicks, by ramping/smoothing volume and pan changes. The start of a sample may also be ramped-in. That is always the case with XM files (or MOD files in FT2 mode) when using normal ramping, and possibly with all formats when using sensitive ramping; senstitive ramping will only ramp-in when necessary to avoid a click. Generally, normal ramping is recommended for XM files, and sensitive ramping for the other formats, but some XM files may also sound better using sensitive ramping.
Platform-specific
DMO effects are not supported in MOD music on Windows CE, and DirectX 8 (or above) is required on Windows. They are always available on other platforms, except for the following: DXCompressor, DXGargle, and DX_I3DL2Reverb. When a DMO effect is unavailable, the MOD music can still be played, but the effect will be disabled.
Pause()
Stops the output, pausing all musics/samples/streams.
Declaration
public static bool Pause()
Returns
Boolean
If successful, then true is returned, else false is returned. Use LastError to get the error code. |
Remarks
Use Start() to resume the output and paused channels.
When using multiple devices, the current thread's device setting (as set with CurrentDevice) determines which device this function call applies to.
PluginFree(Int32)
Unplugs an add-on.
Declaration
public static bool PluginFree(int Handle)
Parameters
Int32
Handle
The plugin handle... 0 = all plugins. |
Returns
Boolean
If successful, true is returned, else false is returned. Use LastError to get the error code. |
Remarks
If there are streams created by a plugin in existence when it is being freed, the streams will automatically be freed too. Samples loaded by the plugin are unaffected as the plugin has nothing to do with them once they are loaded (the sample data is already fully decoded).
PluginGetInfo(Int32)
Retrieves information on a plugin.
Example
List the formats supported by a plugin.
// get the plugin info
var info = Bass.PluginGetInfo(plugin);
foreach (var format in info.Formats)
{
// display the array of formats...
Console.WriteLine("Type={0} Name={1} Extensions={2}",
format.ChannelType,
format.Name,
format.FileExtensions);
}
Declaration
public static PluginInfo PluginGetInfo(int Handle)
Parameters
Int32
Handle
The plugin handle - or 0 to retrieve native BASS information. |
Returns
PluginInfo
An instance of PluginInfo is returned. Use LastError to get the error code. |
Remarks
The plugin information does not change, so the returned info remains valid for as long as the plugin is loaded.
Note: There is no guarantee that the check is complete or might contain formats not being supported on your particular OS/machine (due to additional or missing audio codecs).
PluginLoad(String)
Plugs on "add-on" into the standard stream and sample creation functions.
Declaration
public static int PluginLoad(string FilePath)
Parameters
String
FilePath
Filename of the add-on/plugin. |
Returns
Int32
If successful, the loaded plugin's handle is returned, else 0 is returned. Use LastError to get the error code. |
Remarks
There are 2 ways in which add-ons can provide support for additional formats. They can provide dedicated functions to create streams of the specific format(s) they support and/or they can plug into the standard stream creation functions: CreateStream(String, Int64, Int64, BassFlags), CreateStream(String, Int32, BassFlags, DownloadProcedure, IntPtr), and CreateStream(StreamSystem, BassFlags, FileProcedures, IntPtr). This function enables the latter method. Both methods can be used side by side. The obvious advantage of the plugin system is convenience, while the dedicated functions can provide extra options that are not possible via the shared function interfaces. See an add-on's documentation for more specific details on it.
As well as the stream creation functions, plugins also add their additional format support to SampleLoad(String, Int64, Int32, Int32, BassFlags).
Information on what file formats a plugin supports is available via the PluginGetInfo(Int32) function.
When using multiple plugins, the stream/sample creation functions will try each of them in the order that they were loaded via this function, until one that accepts the file is found. When an add-on is already loaded (eg. if you are using functions from it), the plugin system will use the same instance (the reference count will just be incremented); there will not be 2 copies of the add-on in memory.
Note: Only stream/music add-ons are loaded (e.g. BassFx or BassMix are NOT loaded).
Platform-specific:
Dynamic libraries are not permitted on iOS, so add-ons are provided as static libraries instead, which means this function has to work a little differently. The add-on needs to be linked into the executable, and a "plugin" symbol declared and passed to this function (instead of a filename).
RecordFree()
Frees all resources used by the recording device.
Declaration
public static bool RecordFree()
Returns
Boolean
If successful, then true is returned, else false is returned. Use LastError to get the error code. |
Remarks
This function should be called for all initialized recording devices before your program exits.
When using multiple recording devices, the current thread's device setting (as set with CurrentRecordingDevice) determines which device this function call applies to.
RecordGetDeviceInfo(Int32)
Retrieves information on a recording device.
Declaration
public static DeviceInfo RecordGetDeviceInfo(int Device)
Parameters
Int32
Device
The device to get the information of... 0 = first. |
Returns
DeviceInfo
An instance of the DeviceInfo structure is returned.A value of -1 indicates error. Use LastError to get the error code. Throws BassException on Error. |
Remarks
Platform-specific
Recording support requires DirectX 5 (or above) on Windows. On Linux, a "Default" device is hardcoded to device number 0, which uses the default input set in the ALSA config.
RecordGetDeviceInfo(Int32, out DeviceInfo)
Retrieves information on a recording device.
Example
Get the total number of devices currently present.
var count = 0;
DeviceInfo info;
for (var a = 0; Bass.RecordGetDeviceInfo(a, out info); a++)
if (info.IsEnabled) // device is enabled
count++; // count it
Find a microphone.
DeviceInfo info;
for (var a = 0; Bass.RecordGetDeviceInfo(a, out info); a++)
if (info.IsEnabled && info.Type == DeviceType.Microphone)
{
// found an enabled microphone
// do something
}
Declaration
public static bool RecordGetDeviceInfo(int Device, out DeviceInfo Info)
Parameters
Int32
Device
The device to get the information of... 0 = first. |
DeviceInfo
Info
A DeviceInfo object to retreive the information into. |
Returns
Boolean
If successful, then true is returned, else false is returned. Use LastError to get the error code. |
Remarks
This function can be used to enumerate the available recording devices for a setup dialog.
Platform-specific
Recording support requires DirectX 5 (or above) on Windows. On Linux, a "Default" device is hardcoded to device number 0, which uses the default input set in the ALSA config.
RecordGetInfo(out RecordInfo)
Retrieves information on the recording device being used.
Declaration
public static bool RecordGetInfo(out RecordInfo info)
Parameters
RecordInfo
info
A RecordInfo object to retrieve the information into. |
Returns
Boolean
If successful, true is returned, else false is returned. Use LastError to get the error code. |
RecordGetInput(Int32)
Retrieves the settings of a recording input source (does not retrieve Volume).
Declaration
public static int RecordGetInput(int Input)
Parameters
Int32
Input
The input to get the settings of... 0 = first, -1 = master. |
Returns
Int32
If an error occurs, -1 is returned, use LastError to get the error code. If successful, then the settings are returned. The Off flag will be set if the input is disabled, otherwise the input is enabled. The type of input (see InputTypeFlags) is also indicated in the high 8-bits. Use InputTypeMask to test the return value. If the volume is requested but not available, volume will receive -1. |
Remarks
Platform-specific
The input type information is only available on Windows. There is no "what you hear" type of input defined; if the device has one, it will typically come under Analog or Undefined.
On OSX, there is no master input (-1), and only the currently enabled input has its volume setting available (if it has a volume control).
RecordGetInput(Int32, out Single)
Retrieves the settings of a recording input source.
Declaration
public static int RecordGetInput(int Input, out float Volume)
Parameters
Int32
Input
The input to get the settings of... 0 = first, -1 = master. |
Single
Volume
Reference to a variable to receive the current volume. |
Returns
Int32
If an error occurs, -1 is returned, use LastError to get the error code. If successful, then the settings are returned. The Off flag will be set if the input is disabled, otherwise the input is enabled. The type of input (see InputTypeFlags) is also indicated in the high 8-bits. Use InputTypeMask to test the return value. If the volume is requested but not available, volume will receive -1. |
Remarks
Platform-specific
The input type information is only available on Windows. There is no "what you hear" type of input defined; if the device has one, it will typically come under Analog or Undefined.
On OSX, there is no master input (-1), and only the currently enabled input has its volume setting available (if it has a volume control).
RecordGetInputName(Int32)
Retrieves the text description of a recording input source.
Declaration
public static string RecordGetInputName(int Input)
Parameters
Int32
Input
The input to get the description of... 0 = first, -1 = master. |
Returns
String
If succesful, then the description is returned, else null is returned. Use LastError to get the error code. |
Remarks
Platform-specific
The returned string is in ANSI or UTF-8 form on Windows, depending on the UnicodeDeviceInformation setting. It is in UTF-16 form ("WCHAR" rather than "char") on Windows CE, and in UTF-8 form on other platforms.
On OSX, there is no master input (-1).
RecordInit(Int32)
Initializes a recording device.
Declaration
public static bool RecordInit(int Device = null)
Parameters
Int32
Device
The device to use... -1 = default device, 0 = first. RecordGetDeviceInfo(Int32, out DeviceInfo) or RecordingDeviceCount can be used to get the total number of devices. |
Returns
Boolean
If successful, true is returned, else false is returned. Use LastError to get the error code. |
Remarks
This function must be successfully called before using the recording features.
Simultaneously using multiple devices is supported in the BASS API via a context switching system - instead of there being an extra "device" parameter in the function calls, the device to be used is set prior to calling the functions. CurrentRecordingDevice is used to switch the current recording device. When successful, RecordInit(Int32) automatically sets the current thread's device to the one that was just initialized
When using the default device (device = -1), CurrentRecordingDevice can be used to find out which device it was mapped to. On Windows, it'll always be the first device.
Platform-specific
Recording support requires DirectX 5 (or above) on Windows. On Linux, a "Default" device is hardcoded to device number 0, which uses the default input set in the ALSA config; that could map directly to one of the other devices or it could use ALSA plugins.
RecordSetInput(Int32, InputFlags, Single)
Adjusts the settings of a recording input source.
Declaration
public static bool RecordSetInput(int Input, InputFlags Setting, float Volume)
Parameters
Int32
Input
The input to adjust the settings of... 0 = first, -1 = master. |
InputFlags
Setting
The new setting... a combination of InputFlags. |
Single
Volume
The volume level... 0 (silent) to 1 (max), less than 0 = leave current. |
Returns
Boolean
If successful, true is returned, else false is returned. Use LastError to get the error code. |
Remarks
The actual volume level may not be exactly the same as requested, due to underlying precision differences. RecordGetInput(Int32, out Single) can be used to confirm what the volume is.
The volume curve used by this function is always linear, the LogarithmicVolumeCurve config option setting has no effect on this.
Changes made by this function are system-wide, ie. other software using the device will be affected by it.
Platform-specific
On OSX, there is no master input (-1), and only the currently enabled input has its volume setting available (if it has a volume control).
RecordStart(Int32, Int32, BassFlags, RecordProcedure, IntPtr)
Starts recording.
Declaration
public static int RecordStart(int Frequency, int Channels, BassFlags Flags, RecordProcedure Procedure, IntPtr User = null)
Parameters
Int32
Frequency
The sample rate to record at. |
Int32
Channels
The number of channels... 1 = mono, 2 = stereo, etc. |
BassFlags
Flags
Any combination of Byte, Float and RecordPause. |
RecordProcedure
Procedure
The user defined function to receive the recorded sample data... can be null if you do not wish to use a callback. |
IntPtr
User
User instance data to pass to the callback function. |
Returns
Int32
If successful, the new recording's handle is returned, else false is returned. Use LastError to get the error code. |
Remarks
Use ChannelStop(Int32) to stop the recording, and ChannelPause(Int32) to pause it. Recording can also be started in a paused state (via the RecordPause flag), allowing DSP/FX to be set on it before any data reaches the callback function.
The sample data will generally arrive from the recording device in blocks rather than in a continuous stream, so when specifying a very short period between callbacks, some calls may be skipped due to there being no new data available since the last call.
When not using a callback (proc = null), the recorded data is instead retrieved via ChannelGetData(Int32, IntPtr, Int32). To keep latency at a minimum, the amount of data in the recording buffer should be monitored (also done via ChannelGetData(Int32, IntPtr, Int32), with the Available flag) to check that there is not too much data; freshly recorded data will only be retrieved after the older data in the buffer is.
Platform-specific
Multiple simultaneous recordings can be made from the same device on Windows XP and later, but generally not on older Windows. Multiple simultaneous recordings are possible on iOS and OSX, but may not always be on Linux or Windows CE. On OSX and iOS, the device is instructed (when possible) to deliver data at the period set in the HIWORD of flags, even when a callback function is not used. On other platforms, it is up the the system when data arrives from the device.
Unlike Bass.Net, a reference to Procedure
doesn't need to be held by you manually.
ManagedBass automatically holds a reference and frees it when the Channel is freed.
RecordStart(Int32, Int32, BassFlags, Int32, RecordProcedure, IntPtr)
Starts recording.
Declaration
public static int RecordStart(int Frequency, int Channels, BassFlags Flags, int Period, RecordProcedure Procedure, IntPtr User = null)
Parameters
Int32
Frequency
The sample rate to record at. |
Int32
Channels
The number of channels... 1 = mono, 2 = stereo. |
BassFlags
Flags
Any combination of Byte, Float and RecordPause. |
Int32
Period
Set the period (in milliseconds) between calls to the callback function (RecordProcedure). The minimum period is 5ms, the maximum the maximum is half the RecordingBufferLength setting. If the period specified is outside this range, it is automatically capped. The default is 100ms. |
RecordProcedure
Procedure
The user defined function to receive the recorded sample data... can be null if you do not wish to use a callback. |
IntPtr
User
User instance data to pass to the callback function. |
Returns
Int32
If successful, the new recording's handle is returned, else false is returned. Use LastError to get the error code. |
SampleFree(Int32)
Frees a sample's resources.
Declaration
public static bool SampleFree(int Handle)
Parameters
Int32
Handle
The sample handle. |
Returns
Boolean
If successful, true is returned, else false is returned. Use LastError to get the error code. |
SampleGetChannel(Int32, Boolean)
Creates/initializes a playback channel for a sample.
Example
Play a sample with its default settings.
// get a sample channel
var channel = Bass.SampleGetChannel(sample, false);
Bass.ChannelPlay(channel); // play it
Declaration
public static int SampleGetChannel(int Sample, bool OnlyNew = false)
Parameters
Int32
Sample
Handle of the sample to play. |
Boolean
OnlyNew
Do not recycle/override one of the sample's existing channels? |
Returns
Int32
If successful, the handle of the new channel is returned, else 0 is returned. Use LastError to get the error code. |
Remarks
Use SampleGetInfo(Int32, ref SampleInfo) and SampleSetInfo(Int32, SampleInfo) to set a sample's default attributes, which are used when creating a channel. After creation, a channel's attributes can be changed via ChannelSetAttribute(Int32, ChannelAttribute, Single), ChannelSet3DAttributes(Int32, Mode3D, Single, Single, Int32, Int32, Single) and ChannelSet3DPosition(Int32, Vector3D, Vector3D, Vector3D). Apply3D() should be called before starting playback of a 3D sample, even if you just want to use the default settings.
If a sample has a maximum number of simultaneous playbacks of 1 (the max parameter was 1 when calling SampleLoad(String, Int64, Int32, Int32, BassFlags) or CreateSample(Int32, Int32, Int32, Int32, BassFlags)), then the HCHANNEL handle returned will be identical to the HSAMPLE handle. That means you can use the HSAMPLE handle with functions that usually require a HCHANNEL handle, but you must still call this function first to initialize the channel.
A sample channel is automatically freed when it's overridden by a new channel, or when stopped manually via ChannelStop(Int32), SampleStop(Int32) or Stop(). If you wish to stop a channel and re-use it, it should be paused (ChannelPause(Int32)) instead of stopped. Determining whether a channel still exists can be done by trying to use the handle in a function call, eg. ChannelGetAttribute(Int32, ChannelAttribute, out Single).
When channel overriding has been enabled via an override flag and there are multiple candidates for overriding (eg. with identical volume), the oldest of them will be chosen to make way for the new channel.
The new channel will have an initial state of being paused (Paused). This prevents the channel being claimed by another call of this function before it has been played, unless it gets overridden due to a lack of free channels.
All of a sample's channels share the same sample data, and just have their own individual playback state information (volume/position/etc).
SampleGetChannels(Int32)
Retrieves an array of a sample's existing channels.
Declaration
public static int[] SampleGetChannels(int Handle)
Parameters
Int32
Handle
Handle of the sample. |
Returns
Int32[]
If successful, the array of existing channels is returned (which might have zero elements), else null is returned. Use LastError to get the error code. |
Remarks
This overload only returns the existing channels in the array.
If you need to determine whether a particular sample channel still exists, it is simplest to just try it in a function call.
SampleGetData(Int32, IntPtr)
Retrieves a copy of a sample's data.
Declaration
public static bool SampleGetData(int Handle, IntPtr Buffer)
Parameters
Int32
Handle
The sample handle. |
IntPtr
Buffer
Pointer to a buffer to receive the data. |
Returns
Boolean
If successful, true is returned, else false is returned. Use LastError to get the error code. |
Remarks
The buffer must be big enough to receive the sample's data, the size of which can be retrieved via SampleGetInfo(Int32, ref SampleInfo).
SampleGetData(Int32, Byte[])
Retrieves a copy of a sample's data.
Declaration
public static bool SampleGetData(int Handle, byte[] Buffer)
Parameters
Int32
Handle
The sample handle. |
Byte[]
Buffer
byte[] to receive the data. |
Returns
Boolean
If successful, true is returned, else false is returned. Use LastError to get the error code. |
Remarks
The buffer must be big enough to receive the sample's data, the size of which can be retrieved via SampleGetInfo(Int32, ref SampleInfo).
SampleGetData(Int32, Int16[])
Retrieves a copy of a sample's data.
Declaration
public static bool SampleGetData(int Handle, short[] Buffer)
Parameters
Int32
Handle
The sample handle. |
Int16[]
Buffer
short[] to receive the data. |
Returns
Boolean
If successful, true is returned, else false is returned. Use LastError to get the error code. |
Remarks
The buffer must be big enough to receive the sample's data, the size of which can be retrieved via SampleGetInfo(Int32, ref SampleInfo).
SampleGetData(Int32, Int32[])
Retrieves a copy of a sample's data.
Declaration
public static bool SampleGetData(int Handle, int[] Buffer)
Parameters
Int32
Handle
The sample handle. |
Int32[]
Buffer
int[] to receive the data. |
Returns
Boolean
If successful, true is returned, else false is returned. Use LastError to get the error code. |
Remarks
The buffer must be big enough to receive the sample's data, the size of which can be retrieved via SampleGetInfo(Int32, ref SampleInfo).
SampleGetData(Int32, Single[])
Retrieves a copy of a sample's data.
Declaration
public static bool SampleGetData(int Handle, float[] Buffer)
Parameters
Int32
Handle
The sample handle. |
Single[]
Buffer
float[] to receive the data. |
Returns
Boolean
If successful, true is returned, else false is returned. Use LastError to get the error code. |
Remarks
The buffer must be big enough to receive the sample's data, the size of which can be retrieved via SampleGetInfo(Int32, ref SampleInfo).
SampleGetInfo(Int32)
Retrieves a sample's default attributes and other information.
Declaration
public static SampleInfo SampleGetInfo(int Handle)
Parameters
Int32
Handle
The sample handle. |
Returns
SampleInfo
An instance of the SampleInfo class is returned. Throws BassException on Error. |
SampleGetInfo(Int32, ref SampleInfo)
Retrieves a sample's default attributes and other information.
Declaration
public static bool SampleGetInfo(int Handle, ref SampleInfo Info)
Parameters
Int32
Handle
The sample handle. |
SampleInfo
Info
An instance of the SampleInfo class to store the sample information at. |
Returns
Boolean
If successful, true is returned, else false is returned. Use LastError to get the error code. |
SampleLoad(IntPtr, Int64, Int32, Int32, BassFlags)
Loads a WAV, AIFF, MP3, MP2, MP1, OGG or plugin supported sample.
This overload uses an unmanaged IntPtr and implements loading a sample from memory.
Declaration
public static int SampleLoad(IntPtr Memory, long Offset, int Length, int MaxNoOfPlaybacks, BassFlags Flags)
Parameters
IntPtr
Memory
An unmanaged IntPtr to the allocated memory block at which the sample data resides. |
Int64
Offset
File offset to load the sample from. |
Int32
Length
Data length. Should be set to the length of the data contained in memory. |
Int32
MaxNoOfPlaybacks
Maximum number of simultaneous playbacks... 1 (min) - 65535 (max)... use one of the override 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). |
BassFlags
Flags
A combination of BassFlags flags. |
Returns
Int32
If successful, the loaded sample's handle is returned, else 0 is returned. Use LastError to get the error code. |
Remarks
Additional format support is available via the plugin system (see PluginLoad(String)).
Unless the BassFlags.SoftwareMixing flag is used, the sample will use hardware mixing if hardware resources are available. Use GetInfo(out BassInfo) to see if there are hardware mixing resources available, and which sample formats are supported by the hardware. The 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 SampleSetInfo(Int32, SampleInfo).
To play a sample, first a channel must be obtained using SampleGetChannel(Int32, Boolean), which can then be played using 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 CreateStream(IntPtr, Int64, Int64, BassFlags).
There is no need to pin the memory buffer for this method, since after loading a sample from memory, the memory can safely be discarded, as a copy is made.
Platform-specific
The VAM flag requires DirectX 7 (or above).
On Windows and Windows CE, ACM codecs are supported with compressed WAV files. On iOS and OSX, CoreAudio codecs are supported, adding support for any file formats that have a codec installed.
SampleLoad(Byte[], Int64, Int32, Int32, BassFlags)
Loads a WAV, AIFF, MP3, MP2, MP1, OGG or plugin supported sample.
This overload uses an unmanaged IntPtr and implements loading a sample from memory.
Declaration
public static int SampleLoad(byte[] Memory, long Offset, int Length, int MaxNoOfPlaybacks, BassFlags Flags)
Parameters
Byte[]
Memory
A byte[] with the sample data to load. |
Int64
Offset
File offset to load the sample from. |
Int32
Length
Data length. Should be set to the length of the data contained in memory. |
Int32
MaxNoOfPlaybacks
Maximum number of simultaneous playbacks... 1 (min) - 65535 (max)... use one of the override 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). |
BassFlags
Flags
A combination of BassFlags flags. |
Returns
Int32
If successful, the loaded sample's handle is returned, else 0 is returned. Use LastError to get the error code. |
Remarks
Additional format support is available via the plugin system (see PluginLoad(String)).
Unless the BassFlags.SoftwareMixing flag is used, the sample will use hardware mixing if hardware resources are available. Use GetInfo(out BassInfo) to see if there are hardware mixing resources available, and which sample formats are supported by the hardware. The 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 SampleSetInfo(Int32, SampleInfo).
To play a sample, first a channel must be obtained using SampleGetChannel(Int32, Boolean), which can then be played using 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 CreateStream(Byte[], Int64, Int64, BassFlags).
The Memory
can be safely discarded after calling this method, as a copy of it is made by Bass.
Platform-specific
The VAM flag requires DirectX 7 (or above).
On Windows and Windows CE, ACM codecs are supported with compressed WAV files. On iOS and OSX, CoreAudio codecs are supported, adding support for any file formats that have a codec installed.
SampleLoad(String, Int64, Int32, Int32, BassFlags)
Loads a WAV, AIFF, MP3, MP2, MP1, OGG or plugin supported sample.
Declaration
public static int SampleLoad(string File, long Offset, int Length, int MaxNoOfPlaybacks, BassFlags Flags)
Parameters
String
File
The file name to load the sample from. |
||||||||||||||||||||||
Int64
Offset
File offset to load the sample from. |
||||||||||||||||||||||
Int32
Length
Data length... 0 = use all data up to the end of file. If length over-runs the end of the file, it'll automatically be lowered to the end of the file. |
||||||||||||||||||||||
Int32
MaxNoOfPlaybacks
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). |
||||||||||||||||||||||
BassFlags
Flags
A combination of these flags:
|
Returns
Int32
If successful, the loaded sample's handle is returned, else 0 is returned. Use LastError to get the error code. |
Remarks
Additional format support is available via the plugin system (see PluginLoad(String)).
Unless the BassFlags.SoftwareMixing flag is used, the sample will use hardware mixing if hardware resources are available. Use GetInfo(out BassInfo) to see if there are hardware mixing resources available, and which sample formats are supported by the hardware. The 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 SampleSetInfo(Int32, SampleInfo).
To play a sample, first a channel must be obtained using SampleGetChannel(Int32, Boolean), which can then be played using 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 CreateStream(String, Int64, Int64, BassFlags).
Platform-specific
The VAM flag requires DirectX 7 (or above).
On Windows and Windows CE, ACM codecs are supported with compressed WAV files. On iOS and OSX, CoreAudio codecs are supported, adding support for any file formats that have a codec installed.
SampleSetData(Int32, IntPtr)
Sets a sample's data.
Declaration
public static bool SampleSetData(int Handle, IntPtr Buffer)
Parameters
Int32
Handle
The sample handle. |
IntPtr
Buffer
Pointer to the data to set. |
Returns
Boolean
If successful, true is returned, else false is returned. Use LastError to get the error code. |
Remarks
The required length and format of the data can be retrieved via SampleGetInfo(Int32, ref SampleInfo).
A sample's data can be set at any time, including during playback.
SampleSetData(Int32, Byte[])
Sets a sample's data.
Declaration
public static bool SampleSetData(int Handle, byte[] Buffer)
Parameters
Int32
Handle
The sample handle. |
Byte[]
Buffer
byte[] containing the data to set. |
Returns
Boolean
If successful, true is returned, else false is returned. Use LastError to get the error code. |
Remarks
The required length and format of the data can be retrieved via SampleGetInfo(Int32, ref SampleInfo).
A sample's data can be set at any time, including during playback.
SampleSetData(Int32, Int16[])
Sets a sample's data.
Declaration
public static bool SampleSetData(int Handle, short[] Buffer)
Parameters
Int32
Handle
The sample handle. |
Int16[]
Buffer
short[] containing the data to set. |
Returns
Boolean
If successful, true is returned, else false is returned. Use LastError to get the error code. |
Remarks
The required length and format of the data can be retrieved via SampleGetInfo(Int32, ref SampleInfo).
A sample's data can be set at any time, including during playback.
SampleSetData(Int32, Int32[])
Sets a sample's data.
Declaration
public static bool SampleSetData(int Handle, int[] Buffer)
Parameters
Int32
Handle
The sample handle. |
Int32[]
Buffer
int[] containing the data to set. |
Returns
Boolean
If successful, true is returned, else false is returned. Use LastError to get the error code. |
Remarks
The required length and format of the data can be retrieved via SampleGetInfo(Int32, ref SampleInfo).
A sample's data can be set at any time, including during playback.
SampleSetData(Int32, Single[])
Sets a sample's data.
Declaration
public static bool SampleSetData(int Handle, float[] Buffer)
Parameters
Int32
Handle
The sample handle. |
Single[]
Buffer
float[] containing the data to set. |
Returns
Boolean
If successful, true is returned, else false is returned. Use LastError to get the error code. |
Remarks
The required length and format of the data can be retrieved via SampleGetInfo(Int32, ref SampleInfo).
A sample's data can be set at any time, including during playback.
SampleSetInfo(Int32, SampleInfo)
Sets a sample's default attributes.
Example
Set a sample's default volume to 0.5.
// get the sample's current info
SampleInfo info;
Bass.SampleGetInfo(sample, ref info);
// set the default volume to 0.5
info.Volume = 0.5;
// set the updated info
Bass.SampleSetInfo(sample, info);
Declaration
public static bool SampleSetInfo(int Handle, SampleInfo Info)
Parameters
Int32
Handle
The sample handle. |
SampleInfo
Info
An instance of the SampleInfo class containing the sample information to set. |
Returns
Boolean
If successful, true is returned, else false is returned. Use LastError to get the error code. |
Remarks
Use this function and SampleGetInfo(Int32, ref SampleInfo) to edit a sample's default attributes. Changing a sample's default attributes does not affect any existing channels, it only affects channels subsequently created via SampleGetChannel(Int32, Boolean). The exception is the VAM settings, changes to that apply to all the sample's channels at their next playback (ChannelPlay(Int32, Boolean)). Use ChannelSetAttribute(Int32, ChannelAttribute, Single) and ChannelSet3DAttributes(Int32, Mode3D, Single, Single, Int32, Int32, Single) to change the attributes of an existing sample channel.
The sample's maximum number of simultaneous playbacks can be changed via the Max member. If the new maximum is lower than the existing number of channels, the channels will remain existing until they are stopped.
Length, OriginalResolution and Channels can't be modified - any changes are ignored. Byte, Mono, Bass3D, MuteMax, BassFlags.SoftwareMixing and VAM also cannot be changed.
SampleStop(Int32)
Stops all instances of a sample.
Declaration
public static bool SampleStop(int Handle)
Parameters
Int32
Handle
The sample handle. |
Returns
Boolean
If successful, true is returned, else false is returned. Use LastError to get the error code. |
Remarks
If a sample is playing simultaneously multiple times, calling this function will stop them all, which is obviously simpler than calling ChannelStop(Int32) multiple times.
Set3DFactors(Single, Single, Single)
Sets the factors that affect the calculations of 3D sound.
Example
Use yards as the distance measurement unit, while leaving the current rolloff and doppler factors untouched.
Bass.Set3DFactors(0.9144f, -1, -1);
Bass.Apply3D(); // apply the change
Declaration
public static bool Set3DFactors(float Distance, float RollOff, float Doppler)
Parameters
Single
Distance
The distance factor... less than 0.0 = leave current... examples: 1.0 = use meters, 0.9144 = use yards, 0.3048 = use feet. By default BASS measures distances in meters, you can change this setting if you are using a different unit of measurement. |
Single
RollOff
The rolloff factor, how fast the sound quietens with distance... 0.0 (min) - 10.0 (max), less than 0.0 = leave current... examples: 0.0 = no rolloff, 1.0 = real world, 2.0 = 2x real. |
Single
Doppler
The doppler factor... 0.0 (min) - 10.0 (max), less than 0.0 = leave current... examples: 0.0 = no doppler, 1.0 = real world, 2.0 = 2x real.
The doppler effect is the way a sound appears to change pitch when it is moving towards or away from you (say hello to Einstein!).
The listener and sound velocity settings are used to calculate this effect, this |
Returns
Boolean
If succesful, then true is returned, else false is returned. Use LastError to get the error code. |
Remarks
As with all 3D functions, use Apply3D() to apply the changes.
When using multiple devices, the current thread's device setting (as set with CurrentDevice) determines which device this function call applies to.
See Also
Set3DPosition(Vector3D, Vector3D, Vector3D, Vector3D)
Sets the position, velocity, and orientation of the listener (i.e. the player).
Declaration
public static bool Set3DPosition(Vector3D Position, Vector3D Velocity, Vector3D Front, Vector3D Top)
Parameters
Vector3D
Position
The position of the listener... null = Leave Current. |
Vector3D
Velocity
The listener's velocity... null = Leave Current. |
Vector3D
Front
The direction that the listener's front is pointing... null = Leave Current. |
Vector3D
Top
The direction that the listener's top is pointing... null = Leave Current. |
Returns
Boolean
If succesful, then true is returned, else false is returned. Use LastError to get the error code. |
Remarks
The Front
and Top
parameters must both be set in a single call, they can not be set individually.
When using multiple devices, the current thread's device setting (as set with CurrentDevice) determines which device this function call applies to.
See Also
Start()
Starts (or resumes) the output.
Declaration
public static bool Start()
Returns
Boolean
If successful, true is returned, else false is returned. Use LastError to get the error code. |
Remarks
The output is automatically started by Init(Int32, Int32, DeviceInitFlags, IntPtr, IntPtr), so there is no need to use this function unless you have stopped or paused the output.
When using multiple devices, the current thread's device setting (as set with CurrentDevice) determines which device this function call applies to.
See Also
Stop()
Stops the output, stopping all musics/samples/streams.
Declaration
public static bool Stop()
Returns
Boolean
If successful, then true is returned, else false is returned. Use LastError to get the error code. |
Remarks
This function can be used after Pause() to stop the paused channels, so that they will not be resumed the next time Start() is called.
When using multiple devices, the current thread's device setting (as set with CurrentDevice) determines which device this function call applies to.
StreamFree(Int32)
Frees a sample stream's resources, including any SYNC/DSP/FX it has.
Declaration
public static bool StreamFree(int Handle)
Parameters
Int32
Handle
The stream handle. |
Returns
Boolean
If successful, true is returned, else false is returned. Use LastError to get the error code. |
StreamGetFilePosition(Int32, FileStreamPosition)
Retrieves the decoding/download/end position of a file stream.
Examples
Get the percentage downloaded of an internet file stream, or the buffer level when streaming in blocks.
// file/buffer length
var len = Bass.StreamGetFilePosition(stream, FileStreamPosition.End);
// buffer level
var buf = Bass.StreamGetFilePosition(stream, FileStreamPosition.Buffer);
// percentage of buffer filled
var progress = 100 * buf / len;
Declaration
public static long StreamGetFilePosition(int Handle, FileStreamPosition Mode = FileStreamPosition.Current)
Parameters
Int32
Handle
The stream's handle. |
FileStreamPosition
Mode
The file position to retrieve. One of FileStreamPosition values. |
Returns
Int64
If succesful, then the requested file position is returned, else -1 is returned. Use LastError to get the error code. |
Remarks
ID3 tags (both v1 and v2) and WAVE headers, as well as any other rubbish at the start of the file, are excluded from the calculations of this function.
This is useful for average bitrate calculations, but it means that the Current position may not be the actual file position - the Start position can be added to it to get the actual file position.
When streaming a file from the internet or a "buffered" user file stream, the entire file is downloaded even if the audio data ends before that, in case there are tags to be read. This means that the Download position may go beyond the End position.
It's unwise to use this function (with mode = Current) for syncing purposes because it returns the position that's being decoded, not the position that's being heard. Use ChannelGetPosition(Int32, PositionFlags) for syncing instead.
StreamPutData(Int32, IntPtr, Int32)
Adds sample data to a "push" stream.
Declaration
public static int StreamPutData(int Handle, IntPtr Buffer, int Length)
Parameters
Int32
Handle
The stream handle (as created with CreateStream(Int32, Int32, BassFlags, StreamProcedureType)). |
IntPtr
Buffer
Pointer to the sample data ( |
Int32
Length
The amount of data in bytes, optionally using the End flag to signify the end of the stream. 0 can be used to just check how much data is queued. |
Returns
Int32
If successful, the amount of queued data is returned, else -1 is returned. Use LastError to get the error code. |
Remarks
As much data as possible will be placed in the stream's playback buffer, and any remainder will be queued for when more space becomes available, ie. as the buffered data is played. With a decoding channel, there is no playback buffer, so all data is queued in that case. There is no limit to the amount of data that can be queued, besides available memory. The queue buffer will be automatically enlarged as required to hold the data, but it can also be enlarged in advance. The queue buffer is freed when the stream ends or is reset, eg. via ChannelPlay(Int32, Boolean) (with restart = true) or ChannelSetPosition(Int32, Int64, PositionFlags) (with Position = 0).
DSP/FX are applied when the data reaches the playback buffer, or the ChannelGetData(Int32, IntPtr, Int32) call in the case of a decoding channel.
Data should be provided at a rate sufficent to sustain playback. If the buffer gets exhausted, Bass will automatically stall playback of the stream, until more data is provided. ChannelGetData(Int32, IntPtr, Int32) (Available) can be used to check the buffer level, and ChannelIsActive(Int32) can be used to check if playback has stalled. A Stalled sync can also be set via ChannelSetSync(Int32, SyncFlags, Int64, SyncProcedure, IntPtr), to be triggered upon playback stalling or resuming.
StreamPutData(Int32, Byte[], Int32)
Adds sample data to a "push" stream.
Declaration
public static int StreamPutData(int Handle, byte[] Buffer, int Length)
Parameters
Int32
Handle
The stream handle (as created with CreateStream(Int32, Int32, BassFlags, StreamProcedureType)). |
Byte[]
Buffer
byte sample data buffer (null = allocate space in the queue buffer so that there is at least length bytes of free space). |
Int32
Length
The amount of data in bytes, optionally using the End flag to signify the end of the stream. 0 can be used to just check how much data is queued. |
Returns
Int32
If successful, the amount of queued data is returned, else -1 is returned. Use LastError to get the error code. |
Remarks
As much data as possible will be placed in the stream's playback buffer, and any remainder will be queued for when more space becomes available, ie. as the buffered data is played. With a decoding channel, there is no playback buffer, so all data is queued in that case. There is no limit to the amount of data that can be queued, besides available memory. The queue buffer will be automatically enlarged as required to hold the data, but it can also be enlarged in advance. The queue buffer is freed when the stream ends or is reset, eg. via ChannelPlay(Int32, Boolean) (with restart = true) or ChannelSetPosition(Int32, Int64, PositionFlags) (with Position = 0).
DSP/FX are applied when the data reaches the playback buffer, or the ChannelGetData(Int32, IntPtr, Int32) call in the case of a decoding channel.
Data should be provided at a rate sufficent to sustain playback. If the buffer gets exhausted, Bass will automatically stall playback of the stream, until more data is provided. ChannelGetData(Int32, IntPtr, Int32) (Available) can be used to check the buffer level, and ChannelIsActive(Int32) can be used to check if playback has stalled. A Stalled sync can also be set via ChannelSetSync(Int32, SyncFlags, Int64, SyncProcedure, IntPtr), to be triggered upon playback stalling or resuming.
StreamPutData(Int32, Int16[], Int32)
Adds sample data to a "push" stream.
Declaration
public static int StreamPutData(int Handle, short[] Buffer, int Length)
Parameters
Int32
Handle
The stream handle (as created with CreateStream(Int32, Int32, BassFlags, StreamProcedureType)). |
Int16[]
Buffer
short sample data buffer (null = allocate space in the queue buffer so that there is at least length bytes of free space). |
Int32
Length
The amount of data in bytes, optionally using the End flag to signify the end of the stream. 0 can be used to just check how much data is queued. |
Returns
Int32
If successful, the amount of queued data is returned, else -1 is returned. Use LastError to get the error code. |
Remarks
As much data as possible will be placed in the stream's playback buffer, and any remainder will be queued for when more space becomes available, ie. as the buffered data is played. With a decoding channel, there is no playback buffer, so all data is queued in that case. There is no limit to the amount of data that can be queued, besides available memory. The queue buffer will be automatically enlarged as required to hold the data, but it can also be enlarged in advance. The queue buffer is freed when the stream ends or is reset, eg. via ChannelPlay(Int32, Boolean) (with restart = true) or ChannelSetPosition(Int32, Int64, PositionFlags) (with Position = 0).
DSP/FX are applied when the data reaches the playback buffer, or the ChannelGetData(Int32, IntPtr, Int32) call in the case of a decoding channel.
Data should be provided at a rate sufficent to sustain playback. If the buffer gets exhausted, Bass will automatically stall playback of the stream, until more data is provided. ChannelGetData(Int32, IntPtr, Int32) (Available) can be used to check the buffer level, and ChannelIsActive(Int32) can be used to check if playback has stalled. A Stalled sync can also be set via ChannelSetSync(Int32, SyncFlags, Int64, SyncProcedure, IntPtr), to be triggered upon playback stalling or resuming.
StreamPutData(Int32, Int32[], Int32)
Adds sample data to a "push" stream.
Declaration
public static int StreamPutData(int Handle, int[] Buffer, int Length)
Parameters
Int32
Handle
The stream handle (as created with CreateStream(Int32, Int32, BassFlags, StreamProcedureType)). |
Int32[]
Buffer
int sample data buffer (null = allocate space in the queue buffer so that there is at least length bytes of free space). |
Int32
Length
The amount of data in bytes, optionally using the End flag to signify the end of the stream. 0 can be used to just check how much data is queued. |
Returns
Int32
If successful, the amount of queued data is returned, else -1 is returned. Use LastError to get the error code. |
Remarks
As much data as possible will be placed in the stream's playback buffer, and any remainder will be queued for when more space becomes available, ie. as the buffered data is played. With a decoding channel, there is no playback buffer, so all data is queued in that case. There is no limit to the amount of data that can be queued, besides available memory. The queue buffer will be automatically enlarged as required to hold the data, but it can also be enlarged in advance. The queue buffer is freed when the stream ends or is reset, eg. via ChannelPlay(Int32, Boolean) (with restart = true) or ChannelSetPosition(Int32, Int64, PositionFlags) (with Position = 0).
DSP/FX are applied when the data reaches the playback buffer, or the ChannelGetData(Int32, IntPtr, Int32) call in the case of a decoding channel.
Data should be provided at a rate sufficent to sustain playback. If the buffer gets exhausted, Bass will automatically stall playback of the stream, until more data is provided. ChannelGetData(Int32, IntPtr, Int32) (Available) can be used to check the buffer level, and ChannelIsActive(Int32) can be used to check if playback has stalled. A Stalled sync can also be set via ChannelSetSync(Int32, SyncFlags, Int64, SyncProcedure, IntPtr), to be triggered upon playback stalling or resuming.
StreamPutData(Int32, Single[], Int32)
Adds sample data to a "push" stream.
Declaration
public static int StreamPutData(int Handle, float[] Buffer, int Length)
Parameters
Int32
Handle
The stream handle (as created with CreateStream(Int32, Int32, BassFlags, StreamProcedureType)). |
Single[]
Buffer
float sample data buffer (null = allocate space in the queue buffer so that there is at least length bytes of free space). |
Int32
Length
The amount of data in bytes, optionally using the End flag to signify the end of the stream. 0 can be used to just check how much data is queued. |
Returns
Int32
If successful, the amount of queued data is returned, else -1 is returned. Use LastError to get the error code. |
Remarks
As much data as possible will be placed in the stream's playback buffer, and any remainder will be queued for when more space becomes available, ie. as the buffered data is played. With a decoding channel, there is no playback buffer, so all data is queued in that case. There is no limit to the amount of data that can be queued, besides available memory. The queue buffer will be automatically enlarged as required to hold the data, but it can also be enlarged in advance. The queue buffer is freed when the stream ends or is reset, eg. via ChannelPlay(Int32, Boolean) (with restart = true) or ChannelSetPosition(Int32, Int64, PositionFlags) (with Position = 0).
DSP/FX are applied when the data reaches the playback buffer, or the ChannelGetData(Int32, IntPtr, Int32) call in the case of a decoding channel.
Data should be provided at a rate sufficent to sustain playback. If the buffer gets exhausted, Bass will automatically stall playback of the stream, until more data is provided. ChannelGetData(Int32, IntPtr, Int32) (Available) can be used to check the buffer level, and ChannelIsActive(Int32) can be used to check if playback has stalled. A Stalled sync can also be set via ChannelSetSync(Int32, SyncFlags, Int64, SyncProcedure, IntPtr), to be triggered upon playback stalling or resuming.
StreamPutFileData(Int32, IntPtr, Int32)
Adds data to a "push buffered" user file stream's buffer.
Declaration
public static int StreamPutFileData(int Handle, IntPtr Buffer, int Length)
Parameters
Int32
Handle
The stream handle (as created with CreateStream(StreamSystem, BassFlags, FileProcedures, IntPtr) and the BufferPush system flag.). |
IntPtr
Buffer
Pointer to the file data. |
Int32
Length
The amount of data in bytes, or End to end the file. |
Returns
Int32
If successful, the number of bytes read from buffer is returned, else -1 is returned. Use LastError to get the error code. |
Remarks
If there is not enough space in the stream's file buffer to receive all of the data, then only the amount that will fit is read from buffer. StreamGetFilePosition(Int32, FileStreamPosition) can be used to check the amount of space in the buffer.
File data should be provided at a rate sufficent to sustain playback. If there is insufficient file data, and the playback buffer is subsequently exhausted, Bass will automatically stall playback of the stream, until more data is available. A Stalled sync can be set via ChannelSetSync(Int32, SyncFlags, Int64, SyncProcedure, IntPtr), to be triggered upon playback stalling or resuming.
StreamPutFileData(Int32, Byte[], Int32)
Adds data to a "push buffered" user file stream's buffer.
Declaration
public static int StreamPutFileData(int Handle, byte[] Buffer, int Length)
Parameters
Int32
Handle
The stream handle (as created with CreateStream(StreamSystem, BassFlags, FileProcedures, IntPtr) and the BufferPush system flag.). |
Byte[]
Buffer
byte buffer. |
Int32
Length
The amount of data in bytes, or End to end the file. |
Returns
Int32
If successful, the number of bytes read from buffer is returned, else -1 is returned. Use LastError to get the error code. |
Remarks
If there is not enough space in the stream's file buffer to receive all of the data, then only the amount that will fit is read from buffer. StreamGetFilePosition(Int32, FileStreamPosition) can be used to check the amount of space in the buffer.
File data should be provided at a rate sufficent to sustain playback. If there is insufficient file data, and the playback buffer is subsequently exhausted, Bass will automatically stall playback of the stream, until more data is available. A Stalled sync can be set via ChannelSetSync(Int32, SyncFlags, Int64, SyncProcedure, IntPtr), to be triggered upon playback stalling or resuming.
StreamPutFileData(Int32, Int16[], Int32)
Adds data to a "push buffered" user file stream's buffer.
Declaration
public static int StreamPutFileData(int Handle, short[] Buffer, int Length)
Parameters
Int32
Handle
The stream handle (as created with CreateStream(StreamSystem, BassFlags, FileProcedures, IntPtr) and the BufferPush system flag.). |
Int16[]
Buffer
short buffer. |
Int32
Length
The amount of data in bytes, or End to end the file. |
Returns
Int32
If successful, the number of bytes read from buffer is returned, else -1 is returned. Use LastError to get the error code. |
Remarks
If there is not enough space in the stream's file buffer to receive all of the data, then only the amount that will fit is read from buffer. StreamGetFilePosition(Int32, FileStreamPosition) can be used to check the amount of space in the buffer.
File data should be provided at a rate sufficent to sustain playback. If there is insufficient file data, and the playback buffer is subsequently exhausted, Bass will automatically stall playback of the stream, until more data is available. A Stalled sync can be set via ChannelSetSync(Int32, SyncFlags, Int64, SyncProcedure, IntPtr), to be triggered upon playback stalling or resuming.
StreamPutFileData(Int32, Int32[], Int32)
Adds data to a "push buffered" user file stream's buffer.
Declaration
public static int StreamPutFileData(int Handle, int[] Buffer, int Length)
Parameters
Int32
Handle
The stream handle (as created with CreateStream(StreamSystem, BassFlags, FileProcedures, IntPtr) and the BufferPush system flag.). |
Int32[]
Buffer
int buffer. |
Int32
Length
The amount of data in bytes, or End to end the file. |
Returns
Int32
If successful, the number of bytes read from buffer is returned, else -1 is returned. Use LastError to get the error code. |
Remarks
If there is not enough space in the stream's file buffer to receive all of the data, then only the amount that will fit is read from buffer. StreamGetFilePosition(Int32, FileStreamPosition) can be used to check the amount of space in the buffer.
File data should be provided at a rate sufficent to sustain playback. If there is insufficient file data, and the playback buffer is subsequently exhausted, Bass will automatically stall playback of the stream, until more data is available. A Stalled sync can be set via ChannelSetSync(Int32, SyncFlags, Int64, SyncProcedure, IntPtr), to be triggered upon playback stalling or resuming.
StreamPutFileData(Int32, Single[], Int32)
Adds data to a "push buffered" user file stream's buffer.
Declaration
public static int StreamPutFileData(int Handle, float[] Buffer, int Length)
Parameters
Int32
Handle
The stream handle (as created with CreateStream(StreamSystem, BassFlags, FileProcedures, IntPtr) and the BufferPush system flag.). |
Single[]
Buffer
float buffer. |
Int32
Length
The amount of data in bytes, or End to end the file. |
Returns
Int32
If successful, the number of bytes read from buffer is returned, else -1 is returned. Use LastError to get the error code. |
Remarks
If there is not enough space in the stream's file buffer to receive all of the data, then only the amount that will fit is read from buffer. StreamGetFilePosition(Int32, FileStreamPosition) can be used to check the amount of space in the buffer.
File data should be provided at a rate sufficent to sustain playback. If there is insufficient file data, and the playback buffer is subsequently exhausted, Bass will automatically stall playback of the stream, until more data is available. A Stalled sync can be set via ChannelSetSync(Int32, SyncFlags, Int64, SyncProcedure, IntPtr), to be triggered upon playback stalling or resuming.
Update(Int32)
Updates the HSTREAM and HMUSIC channel playback buffers.
Declaration
public static bool Update(int Length)
Parameters
Int32
Length
The amount of data to render, in milliseconds. |
Returns
Boolean
If successful, then true is returned, else false is returned. Use LastError to get the error code. |
Remarks
When automatic updating is disabled, this function (or ChannelUpdate(Int32, Int32)) needs to be called to keep the playback buffers updated.
The Length
parameter should include some safety margin, in case the next update cycle gets delayed.
For example, if calling this function every 100ms, 200 would be a reasonable Length
parameter.