BASS.NET API for the Un4seen BASS Audio LibraryBassBASS_ChannelSetSync Method BASS.NET API for the Un4seen BASS Audio Library
Sets up a synchronizer on a MOD music, stream or recording channel.

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

[DllImportAttribute("bass.dll", CharSet = CharSet.Unicode)]
public static int BASS_ChannelSetSync(
	int handle,
	BASSSync type,
	long param,
	IntPtr user


Type: SystemInt32
The channel handle... a HMUSIC, HSTREAM or HRECORD.
Type: Un4seen.BassBASSSync
The type of sync (see the table below or BASSSync), you may also use these flags:
BASS_SYNC_ONETIMECall the sync only once, and then remove it from the channel.
BASS_SYNC_MIXTIMECall the sync function when the sync occurs during decoding/mixing, instead of delaying the call until the sync is actually heard. This is automatically applied with decoding channels, as they can not be played/heard.
Type: SystemInt64
The sync parameters, depends on the sync type... see the table below.
Type: Un4seen.BassSYNCPROC
The callback function which should be invoked with the sync.
Type: SystemIntPtr
User instance data to pass to the callback function.

Return Value

Type: Int32
If succesful, then the new synchronizer's handle is returned, else 0 is returned. Use BASS_ErrorGetCode to get the error code.

Sync types, with param and SYNCPROC data definitions:

(mixtime only)

Sync when downloading of an internet (or "buffered" user file) stream is done.

param : not used.

data : not used.

BASS_SYNC_ENDSync when a channel reaches the end. Note that some MOD musics never reach the end, they may jump to another position first. If the BASS_MUSIC_STOPBACK flag is used with a MOD music (through BASS_MusicLoad(String, Int64, Int32, BASSFlag, Int32) or BASS_ChannelFlags(Int32, BASSFlag, BASSFlag)), then this sync will also be called when a backward jump effect is played.

param : not used.

data : 1 = the sync is triggered by a backward jump in a MOD music, otherwise not used


(mixtime only)

Sync when a channel is freed. This can be useful when you need to release some resources associated with the channel. Note that you will not be able to use any BASS functions with the channel in the callback (the channel will no longer exist).

param : not used.

data : not used.


(mixtime only)

Sync when metadata is received in a Shoutcast stream. This sync is also triggered when a new logical-bitstream begins in a chained OGG stream (multiple streams are strung one-after-another), in which case the metadata is the updated OGG tags. (see example below)

param : not used.

data : not used - the updated metadata is available from BASS_ChannelGetTags(Int32, BASSTag) (BASS_TAG_META)

BASS_SYNC_MUSICFXSync when the sync effect is used in a MOD music. The sync effect is E8x or Wxx for the XM/MTM/MOD formats, and S2x for the IT/S3M formats (where x = any value).

param : 0 = the position is passed to the callback (data : LOWORD = order, HIWORD = row),

param : 1 = the value of x is passed to the callback (data : x value).

BASS_SYNC_MUSICINSTSync when an instrument (sample for the MOD/S3M/MTM formats) is played in a MOD music (not including retrigs).

param : LOWORD = instrument (1=first), HIWORD = note (0=c0...119=b9, -1=all).

data : LOWORD = note, HIWORD = volume (0-64).

BASS_SYNC_MUSICPOSSync when a MOD music reaches an order:row position.

param : LOWORD = order (0=first, -1=all), HIWORD = row (0=first, -1=all).

data : LOWORD = order, HIWORD = row.

BASS_SYNC_OGG_CHANGESync when a new logical bitstream begins in a chained OGG stream. Updated tags are available from BASS_ChannelGetTags(Int32, BASSTag).

param : not used.

data : not used.

BASS_SYNC_POSSync when a channel reaches a position.

param : position in bytes (automatically rounded down to nearest sample).

data : not used.

BASS_SYNC_SETPOSSync when a channel's position is set, including when looping/restarting.

param : not used.

data : 0 = playback buffer is not flushed, 1 = playback buffer is flushed.


(mixtime only)

Sync when an attribute slide has completed.

param : not used.

data : the type of slide completed (one of the BASS_SLIDE_xxx values).


(mixtime only)

Sync when playback of the channel is stalled/resumed.

param : not used.

data : 0 = stalled, 1 = resumed.

Other sync types may be supported by add-ons, see the documentation.

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 BASS_ChannelRemoveSync(Int32, Int32). If the BASS_SYNC_ONETIME flag is used, then the sync is automatically removed after its first occurrence.

The BASS_SYNC_MIXTIME flag can be used with BASS_SYNC_END or BASS_SYNC_POS/MUSICPOS syncs to implement custom looping, by using BASS_ChannelSetPosition(Int32, Int64, BASSMode) 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 BASS_ChannelFlags(Int32, BASSFlag, BASSFlag)). The BASS_SYNC_MIXTIME flag can also be useful with a BASS_SYNC_SETPOS 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, BASS_SYNC_POS and BASS_SYNC_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, BASS_SYNC_POS syncs are triggered just before the RECORDPROC receives the block of data containing the sync position.

ERROR CODEDescription
BASS_ERROR_HANDLEhandle is not a valid channel.
BASS_ERROR_ILLTYPEAn illegal type was specified.
BASS_ERROR_ILLPARAMAn illegal param was specified.


Set a sync to get notified when the channel reaches the end:
Private _mySync As SYNCPROC
_mySync = New SYNCPROC(AddressOf EndSync)
                         0, _mySync, IntPtr.Zero)
Private Sub EndSync(ByVal handle As Integer, ByVal channel As Integer, 
                    ByVal data As Integer, ByVal user As IntPtr)
  ' the 'channel' has ended - jump to the beginning
  Bass.BASS_ChannelSetPosition(channel, 0L)
End Sub
private SYNCPROC _mySync;
_mySync = new SYNCPROC(EndSync);
                         0, _mySync, IntPtr.Zero);
private void EndSync(int handle, int channel, int data, IntPtr user)
  // the 'channel' has ended - jump to the beginning
  Bass.BASS_ChannelSetPosition(channel, 0L);
Process metadata received from an internet stream:
Private _mySync As SYNCPROC
Dim stream As Integer =  Bass.BASS_StreamCreateURL(url, 0, BASSFlag.BASS_DEFAULT, Nothing, 0) 
' set a sync to get notified on stream title updates
_mySync = New SYNCPROC(AddressOf MetaSync)
Bass.BASS_ChannelSetSync(stream, BASSSync.BASS_SYNC_META, 0, _mySync, IntPtr.Zero)
Bass.BASS_ChannelPlay(stream, False)
Private Sub MetaSync(ByVal handle As Integer, ByVal channel As Integer, 
                     ByVal data As Integer, ByVal user As IntPtr)
  ' BASS_SYNC_META is triggered
  Dim tags() As String = Bass.BASS_ChannelGetTagsMETA(channel) 
  Dim tag As String
  For Each tag In tags
End Sub
private SYNCPROC _mySync;
int stream = Bass.BASS_StreamCreateURL(url, 0, BASSFlag.BASS_DEFAULT, null, 0);
// set a sync to get notified on stream title updates
_mySync = new SYNCPROC(MetaSync);
Bass.BASS_ChannelSetSync(stream, BASSSync.BASS_SYNC_META, 0, _mySync, IntPtr.Zero);
Bass.BASS_ChannelPlay(stream, false);
private void MetaSync(int handle, int channel, int data, IntPtr user)
  // BASS_SYNC_META is triggered
  string[] tags = Bass.BASS_ChannelGetTagsMETA(channel);
  foreach (string tag in tags)
See Also