BASS.NET API for the Un4seen BASS Audio Library

BassEncBASS_Encode_CastInit Method

BASS.NET API for the Un4seen BASS Audio Library
Initializes sending an encoder's output to a Shoutcast or Icecast server.

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

public static bool BASS_Encode_CastInit(
	int handle,
	string server,
	string pass,
	string content,
	string name,
	string url,
	string genre,
	string desc,
	string headers,
	int bitrate,
	BASSEncodeCast flags


Type: SystemInt32
The encoder handle.
Type: SystemString
The server to send to, in the form of "address:port" (Shoutcast v1) resp. "address:port,sid" (Shoutcast v2) or "address:port/mount" (Icecast).
Type: SystemString
The server password. A username can be included in the form of "username:password" when connecting to an Icecast or Shoutcast 2 server.
Type: SystemString
The MIME type of the encoder output. This can be one of the following:


Type: SystemString
The stream name... = no name.
Type: SystemString
The URL, for example, of the radio station's webpage... = no URL.
Type: SystemString
The genre... = no genre.
Type: SystemString
Description... = no description. This applies to Icecast only.
Type: SystemString
Other headers to send to the server... = none. Each header should end with a carriage return and line feed ("\r\n").
Type: SystemInt32
The bitrate (in kbps) of the encoder output... 0 = undefined bitrate. In cases where the bitrate is a "quality" (rather than CBR) setting, the headers parameter can be used to communicate that instead, eg. "ice-bitrate: Quality 0\r\n".
Type: Un4seen.Bass.AddOn.EncBASSEncodeCast
A combination of these flags:
BASS_ENCODE_CAST_PUBLICAdd the stream to the public directory at or (or as defined in the server config).
BASS_ENCODE_CAST_PUTUse the PUT method when connecting to an Icecast server, else the SOURCE method is used. This flag has no effect on Shoutcast servers, and is applied automatically when the BASS_ENCODE_CAST_SSL flag is specified.
BASS_ENCODE_CAST_SSLUse SSL/TLS encryption. This requires the OpenSSL library, and that the server is configured to accept encrypted connections.

Return Value

Type: Boolean
If successful, is returned, else is returned. Use BASS_ErrorGetCode to get the error code.

This function sets up a Shoutcast/Icecast source client, sending the encoder's output to a server, which listeners can then connect to and receive the data from. The Shoutcast and Icecast server software is available from and, respectively.

An encoder needs to be started (but with no data sent to it yet) before using this function to setup the sending of the encoder's output to a Shoutcast or Icecast server. If BASS_Encode_Start(Int32, String, BASSEncode, ENCODEPROC, IntPtr) is used, the encoder should be setup to write its output to STDOUT. Due to the length restrictions of WAVE headers/files, the encoder should also be started with the BASS_ENCODE_NOHEAD flag, and the sample format details sent via the command-line.

Unless the BASS_ENCODE_CAST_NOLIMIT flag is set on the encoder, BASSenc automatically limits the rate that data is processed to real-time speed to avoid overflowing the server's buffer, which means that it is safe to simply try to process data as quickly as possible, eg. when the source is a decoding channel. Encoders set on recording channels are automatically exempt from the rate limiting, as they are inherently real-time. With BASS 2.4.6 or above, also exempt are encoders that are fed in a playback buffer update cycle (including BASS_Update(Int32) and BASS_ChannelUpdate(Int32, Int32) calls), eg. when the source is a playing channel; that is to avoid delaying the update thread, which could result in playback buffer underruns.

Normally, BASSenc will produce the encoded data (with the help of an encoder) that is sent to a Shoutcast/Icecast server, but it is also possible to send already encoded data to a server (without first decoding and re-encoding it) via the PCM encoding option. The encoder can be set on any BASS channel, as rather than feeding on sample data from the channel, BASS_Encode_Write(Int32, IntPtr, Int32) would be used to feed in the already encoded data. BASSenc does not know what the data's bitrate is in that case, so it is up to the user to process the data at the correct rate (real-time speed).

BASS_Encode_ServerInit(Int32, String, Int32, Int32, BASSEncodeServer, ENCODECLIENTPROC, IntPtr) can be used to setup a server that listeners can connect to directly, without a Shoutcast/Icecast server intermediary.

ERROR CODEDescription
BASS_ERROR_HANDLEhandle is not valid.
BASS_ERROR_ALREADYThere is already a cast set on the encoder.
BASS_ERROR_ILLPARAMserver doesn't include a port number.
BASS_ERROR_FILEOPENCouldn't connect to the server.
BASS_ERROR_CAST_DENIEDpass is not valid.
BASS_ERROR_UNKNOWNSome other mystery problem!


Start encoding a stereo 44100hz channel to 128kb/s MP3, and send the output to a Shoutcast server:
// setup the encoder
int encoder = BassEnc.BASS_Encode_Start(channel, "lame -r -x -s 44100 -b 128 -", 
                      BASS_ENCODE_NOHEAD, null, 0);
// setup the encoder
BassEnc.BASS_Encode_CastInit(encoder, "", "password", BassEnc.BASS_ENCODE_TYPE_MP3, 
                             "name", "url", "genre", null, null, 128, true);
See Also