### Start file-based MP3 encoding with BassEnc_Mp3.Start Source: https://deepwiki.com/ManagedBass/ManagedBass/4.1-mp3-encoding Starts MP3 encoding to a file. Returns an encoder handle, or 0 on error. The options parameter can be null for defaults. ```csharp int encoderHandle = BassEnc_Mp3.Start( channelHandle, // Audio channel to encode options, // LAME encoder options (can be null for defaults) flags, // EncodeFlags enumeration values outputFileName // Path to output MP3 file ); ``` -------------------------------- ### Start callback-based MP3 encoding with BassEnc_Mp3.Start Source: https://deepwiki.com/ManagedBass/ManagedBass/4.1-mp3-encoding Starts MP3 encoding and passes encoded data to a callback. Returns an encoder handle, or 0 on error. The options parameter can be null for defaults. ```csharp int encoderHandle = BassEnc_Mp3.Start( channelHandle, // Audio channel to encode options, // LAME encoder options (can be null for defaults) flags, // EncodeFlags enumeration values encodeProcedure, // Callback to receive encoded data userData // User data to pass to callback ); ``` -------------------------------- ### Position Control Examples in C# Source: https://deepwiki.com/ManagedBass/ManagedBass/7-advanced-topics Shows how to get the current position in bytes and seconds, seek relative to the current position, seek to an absolute time, and seek to a specific pattern/row in MOD music using PositionFlags. ```csharp // Get current position in bytes long posBytes = Bass.ChannelGetPosition(channel); // Get current position in seconds double posSeconds = Bass.ChannelBytes2Seconds(channel, posBytes); // Seek 5 seconds forward (relative) Bass.ChannelSetPosition( channel, Bass.ChannelSeconds2Bytes(channel, 5.0), PositionFlags.Relative ); // Seek to a specific time precisely Bass.ChannelSetPosition( channel, Bass.ChannelSeconds2Bytes(channel, 60.0), // 1 minute PositionFlags.Bytes ); // For MOD music: Seek to pattern 1, row 32 Bass.ChannelSetPosition( channel, (1 << 16) | 32, PositionFlags.MusicOrders ); ``` -------------------------------- ### BassWasapi.Start() Source: https://deepwiki.com/ManagedBass/ManagedBass/5.1-wasapi-integration Starts the WASAPI device to begin audio processing. Must be called after initialization. ```APIDOC ## [POST] BassWasapi.Start() ### Description Starts the WASAPI device to begin audio processing. ### Method Start ### Endpoint BassWasapi.Start() ### Parameters None ### Response No return value documented. ``` -------------------------------- ### Start WASAPI device Source: https://deepwiki.com/ManagedBass/ManagedBass/5.1-wasapi-integration Starts the initialized WASAPI device to begin audio processing. ```csharp BassWasapi.Start(); ``` -------------------------------- ### Install core ManagedBass package via NuGet Source: https://deepwiki.com/ManagedBass/ManagedBass Use this command to install the core ManagedBass NuGet package. This is the first step in setting up ManagedBass in your project. ```powershell Install-Package ManagedBass ``` -------------------------------- ### AAC Encoding Example with BassEnc_Acc.Start Source: https://deepwiki.com/ManagedBass/ManagedBass/4.3-aac-encoding Shows how to encode an audio stream to an AAC file using BassEnc_Acc.Start. The function returns 0 on error; use Bass.LastError to get the specific error. The example creates a stream from 'input.mp3', starts encoding with options '--object-type 29 --bitrate 128', and plays the source stream to process audio. ```csharp // Create or obtain a BASS channel handle int channelHandle = Bass.CreateStream("input.mp3", 0, 0, BassFlags.Default); // Start AAC encoding to a file with specific settings int encoderHandle = BassEnc_Acc.Start( channelHandle, "--object-type 29 --bitrate 128", EncodeFlags.Autofree, "output.aac" ); if (encoderHandle == 0) { // Handle error Console.WriteLine($"Error starting AAC encoder: {Bass.LastError}"); } else { // Play the source stream (encoder will process the audio) Bass.ChannelPlay(channelHandle); } ``` -------------------------------- ### BassEnc_Mp3.Start (Callback-based) Source: https://deepwiki.com/ManagedBass/ManagedBass/4.1-mp3-encoding Starts MP3 encoding of an audio channel and passes the encoded data to a callback function. Returns an encoder handle on success, or 0 on error. ```APIDOC ## [METHOD] BassEnc_Mp3.Start (Callback-based) ### Description Starts MP3 encoding of an audio channel and passes the encoded data to a callback function. Returns an encoder handle on success, or 0 on error. ### Method Start ### Parameters - **channelHandle** (int) - Required - Audio channel to encode - **options** (string) - Optional - LAME encoder options (can be null for defaults) - **flags** (EncodeFlags) - Required - EncodeFlags enumeration values - **encodeProcedure** (callback) - Required - Callback to receive encoded data - **userData** (object) - Required - User data to pass to callback ### Response #### Success Response - **encoderHandle** (int) - Handle to the encoder if successful, or 0 if an error occurs ### Request Example ``` int encoderHandle = BassEnc_Mp3.Start( channelHandle, // Audio channel to encode options, // LAME encoder options (can be null for defaults) flags, // EncodeFlags enumeration values encodeProcedure, // Callback to receive encoded data userData // User data to pass to callback ); ``` ``` -------------------------------- ### Install ManagedBass add-on packages via NuGet Source: https://deepwiki.com/ManagedBass/ManagedBass Use these commands to install additional ManagedBass add-on packages (Fx, Enc, Mix) as needed. These are separate packages for extended functionality. ```powershell Install-Package ManagedBass.Fx ``` ```powershell Install-Package ManagedBass.Enc ``` ```powershell Install-Package ManagedBass.Mix ``` -------------------------------- ### BassEnc_Mp3.Start (File-based) Source: https://deepwiki.com/ManagedBass/ManagedBass/4.1-mp3-encoding Starts MP3 encoding of an audio channel and writes the encoded data directly to a file. Returns an encoder handle on success, or 0 on error. ```APIDOC ## [METHOD] BassEnc_Mp3.Start (File-based) ### Description Starts MP3 encoding of an audio channel and writes the encoded data directly to a file. Returns an encoder handle on success, or 0 on error. ### Method Start ### Parameters - **channelHandle** (int) - Required - Audio channel to encode - **options** (string) - Optional - LAME encoder options (can be null for defaults) - **flags** (EncodeFlags) - Required - EncodeFlags enumeration values - **outputFileName** (string) - Required - Path to output MP3 file ### Response #### Success Response - **encoderHandle** (int) - Handle to the encoder if successful, or 0 if an error occurs ### Request Example ``` int encoderHandle = BassEnc_Mp3.Start( channelHandle, // Audio channel to encode options, // LAME encoder options (can be null for defaults) flags, // EncodeFlags enumeration values outputFileName // Path to output MP3 file ); ``` ``` -------------------------------- ### Start AAC Encoding to File Source: https://deepwiki.com/ManagedBass/ManagedBass/4.3-aac-encoding Starts AAC encoding of an audio channel directly to a file. The output file path is specified in the fileName parameter. ```csharp int encoderHandle = BassEnc_Acc.Start( channelHandle, // The audio channel to encode options, // Encoder options string flags, // Encoding flags fileName // Output file path ); ``` -------------------------------- ### BassEnc.EncodeStart Source: https://deepwiki.com/ManagedBass/ManagedBass/2-core-audio-system Starts encoding a channel. This is part of the BassEnc add-on module and uses core channel handles as input. ```APIDOC ## [START] BassEnc.EncodeStart ### Description Starts encoding a channel. ### Method EncodeStart ### Endpoint BassEnc.EncodeStart ### Parameters #### Parameters - **channel** (int) - Required - The channel handle to encode. - **command** (string) - Required - The encoding command. - **flags** (int) - Required - Flags for encoding. - **proc** (Procedure) - Required - Callback procedure. ### Response #### Success Response - **int** (handle) - The encoding handle. ``` -------------------------------- ### Create empty sample with Bass.CreateSample Source: https://deepwiki.com/ManagedBass/ManagedBass/7-advanced-topics Creates an empty sample buffer for custom audio data. The example allocates 1 second of stereo 16-bit audio at 44100 Hz, allowing up to 5 simultaneous playbacks. ```csharp int sampleHandle = Bass.CreateSample( length: 44100 * 4, // 1 second stereo 16-bit frequency: 44100, channels: 2, max: 5, // Maximum simultaneous playbacks flags: BassFlags.Default ); ``` -------------------------------- ### Load, play, and free a sample with Bass.SampleLoad Source: https://deepwiki.com/ManagedBass/ManagedBass/2-core-audio-system Loads a sample from a file, gets a playback channel, plays it, and frees the sample's resources. The sample handle is created with a maximum of 5 simultaneous playbacks and default flags. Call SampleFree when done to release resources. ```csharp // Load a sample int sampleHandle = Bass.SampleLoad("sound.wav", 0, 0, 5, BassFlags.Default); // Get a channel to play the sample int channelHandle = Bass.SampleGetChannel(sampleHandle, false); // Play the sample Bass.ChannelPlay(channelHandle, false); // When done with the sample Bass.SampleFree(sampleHandle); ``` -------------------------------- ### BassEnc_Flac.Start (File) Source: https://deepwiki.com/ManagedBass/ManagedBass/4.2-flac-encoding Starts FLAC encoding directly to a file. This method is used when you want to save the encoded FLAC data to a file on disk. ```APIDOC ## BassEnc_Flac.Start(int Handle, string Options, EncodeFlags Flags, string FileName) ### Description Starts FLAC encoding directly to a file. ### Method Start ### Parameters - **Handle** (int) - Required - The channel handle to encode - **Options** (string) - Required - FLAC encoding options (passed to the native FLAC encoder) - **Flags** (EncodeFlags) - Required - A combination of EncodeFlags values - **FileName** (string) - Required - Output file path ``` -------------------------------- ### Start or resume playback with Bass.ChannelPlay Source: https://deepwiki.com/ManagedBass/ManagedBass/2.2-audio-playback-controls Starts or resumes playback on any channel type. The optional restart parameter defaults to false; when true, playback starts from the beginning and for MOD music channels resets BPM and other music parameters. ```csharp // Start or resume playback bool success = Bass.ChannelPlay(channelHandle, restart); ``` -------------------------------- ### SampleGetChannel Source: https://deepwiki.com/ManagedBass/ManagedBass/2.2-audio-playback-controls Gets a playback channel for a sample, allowing you to control playback of that sample. ```APIDOC ## SampleGetChannel ### Description Gets a playback channel for a sample. ### Method SampleGetChannel ### Parameters - **sample** (int) - Required - The sample handle. ### Response Returns a channel handle for the sample. ``` -------------------------------- ### BassEnc_Flac.Start(Handle, Options, Flags, ProcedureEx, User) Source: https://deepwiki.com/ManagedBass/ManagedBass/4.2-flac-encoding Starts FLAC encoding of a channel with a callback procedure. Returns a non-zero encoder handle on success, or 0 on failure; use Bass.LastError to retrieve the error code. ```APIDOC ## [POST] BassEnc_Flac.Start(Handle, Options, Flags, ProcedureEx, User) ### Description Starts FLAC encoding of a channel with a callback procedure. Returns a non-zero encoder handle on success, or 0 on failure; use Bass.LastError to retrieve the error code. ### Method POST ### Endpoint BassEnc_Flac.Start(Handle, Options, Flags, ProcedureEx, User) ### Parameters #### Path Parameters - **Handle** (channel handle) - Required - The channel to encode - **Options** (encoder options) - Required - FLAC encoding options - **Flags** (flags) - Required - Encoding flags - **ProcedureEx** (callback) - Required - Callback procedure for encoded data - **User** (user data) - Required - User-defined data passed to callback ### Response #### Success Response (200) - **encoder handle** (integer) - Non-zero value on success #### Error Response (0) - **Bass.LastError** - Error code; see error table ``` -------------------------------- ### BassEnc_Flac.Start(Handle, Options, Flags, FileName) Source: https://deepwiki.com/ManagedBass/ManagedBass/4.2-flac-encoding Starts FLAC encoding of a channel to a file. Returns a non-zero encoder handle on success, or 0 on failure; use Bass.LastError to retrieve the error code. ```APIDOC ## [POST] BassEnc_Flac.Start(Handle, Options, Flags, FileName) ### Description Starts FLAC encoding of a channel to a file. Returns a non-zero encoder handle on success, or 0 on failure; use Bass.LastError to retrieve the error code. ### Method POST ### Endpoint BassEnc_Flac.Start(Handle, Options, Flags, FileName) ### Parameters #### Path Parameters - **Handle** (channel handle) - Required - The channel to encode - **Options** (encoder options) - Required - FLAC encoding options - **Flags** (flags) - Required - Encoding flags - **FileName** (string) - Required - Output file path ### Response #### Success Response (200) - **encoder handle** (integer) - Non-zero value on success #### Error Response (0) - **Bass.LastError** - Error code; see error table ``` -------------------------------- ### BassEnc_Acc.Start Source: https://deepwiki.com/ManagedBass/ManagedBass/4.3-aac-encoding Starts AAC encoding of a BASS channel to a file or callback. Returns an encoder handle if successful, or 0 if an error occurs. ```APIDOC ## [START] BassEnc_Acc.Start ### Description Starts AAC encoding of a BASS channel to a file or callback. Returns an encoder handle if successful, or 0 if an error occurs. ### Method START ### Endpoint BassEnc_Acc.Start ### Parameters #### Request Body - **channelHandle** (int) - Required - The BASS channel handle to encode. - **options** (string) - Required - Encoding options string (e.g., "--object-type 29 --bitrate 128"). - **flags** (EncodeFlags) - Required - Encoding flags (e.g., EncodeFlags.Autofree). - **filename** (string) - Required - Output file path for file encoding. ### Response #### Success Response (0) - **encoderHandle** (int) - Encoder handle if successful, or 0 if an error occurs. ### Request Example ```csharp int encoderHandle = BassEnc_Acc.Start( channelHandle, "--object-type 29 --bitrate 128", EncodeFlags.Autofree, "output.aac" ); ``` ### Response Example ```csharp if (encoderHandle == 0) { Console.WriteLine($"Error starting AAC encoder: {Bass.LastError}"); } ``` ``` -------------------------------- ### BassEnc_Aac.Start (Callback) Source: https://deepwiki.com/ManagedBass/ManagedBass/4.3-aac-encoding Starts AAC encoding of an audio channel and delivers encoded data through a callback. ```APIDOC ## BassEnc_Aac.Start (Callback) ### Description Starts AAC encoding of an audio channel and delivers encoded data through a callback. ### Method Start ### Endpoint BassEnc_Aac.Start ### Parameters #### Parameters - **channelHandle** (int) - Required - The audio channel to encode. - **options** (string) - Required - Encoder options string. - **flags** (int) - Required - Encoding flags. - **procedureCallback** (ProcedureCallback) - Required - Callback to receive encoded data. - **userData** (IntPtr) - Required - User data passed to callback. ### Response #### Success Response - **encoderHandle** (int) - The handle of the encoder. ### Request Example ```csharp int encoderHandle = BassEnc_Acc.Start( channelHandle, // The audio channel to encode options, // Encoder options string flags, // Encoding flags procedureCallback,// Callback to receive encoded data userData // User data passed to callback ); ``` ``` -------------------------------- ### BassEnc_Flac.Start (Callback) Source: https://deepwiki.com/ManagedBass/ManagedBass/4.2-flac-encoding Starts FLAC encoding and sends the encoded data to a callback function. This method is used when you need to process the encoded FLAC data in memory or stream it to a custom destination. ```APIDOC ## BassEnc_Flac.Start(int Handle, string Options, EncodeFlags Flags, EncodeProcedureEx ProcedureEx, IntPtr User) ### Description Starts FLAC encoding and sends the encoded data to a callback function. ### Method Start ### Parameters - **Handle** (int) - Required - The channel handle to encode - **Options** (string) - Required - FLAC encoding options (passed to the native FLAC encoder) - **Flags** (EncodeFlags) - Required - A combination of EncodeFlags values - **ProcedureEx** (EncodeProcedureEx) - Required - Callback function to receive encoded data - **User** (IntPtr) - Required - User instance data to pass to the callback ``` -------------------------------- ### Start AAC Encoding to Callback Source: https://deepwiki.com/ManagedBass/ManagedBass/4.3-aac-encoding Starts AAC encoding of an audio channel, delivering encoded data to a callback. The callback receives the encoded data and user data. ```csharp int encoderHandle = BassEnc_Acc.Start( channelHandle, // The audio channel to encode options, // Encoder options string flags, // Encoding flags procedureCallback,// Callback to receive encoded data userData // User data passed to callback ); ``` -------------------------------- ### BassEnc_Aac.Start (File) Source: https://deepwiki.com/ManagedBass/ManagedBass/4.3-aac-encoding Starts AAC encoding of an audio channel and writes the encoded data directly to a file. ```APIDOC ## BassEnc_Aac.Start (File) ### Description Starts AAC encoding of an audio channel and writes the encoded data directly to a file. ### Method Start ### Endpoint BassEnc_Aac.Start ### Parameters #### Parameters - **channelHandle** (int) - Required - The audio channel to encode. - **options** (string) - Required - Encoder options string. - **flags** (int) - Required - Encoding flags. - **fileName** (string) - Required - Output file path. ### Response #### Success Response - **encoderHandle** (int) - The handle of the encoder. ### Request Example ```csharp int encoderHandle = BassEnc_Acc.Start( channelHandle, // The audio channel to encode options, // Encoder options string flags, // Encoding flags fileName // Output file path ); ``` ``` -------------------------------- ### Get all active sample channels with SampleGetChannels Source: https://deepwiki.com/ManagedBass/ManagedBass/7.4-sample-management Retrieves all active channel handles for a sample, allowing manipulation of each instance individually, such as setting the pan attribute. ```csharp // Get all active channels for a sample int[] channels = Bass.SampleGetChannels(sampleHandle); // Do something with each channel foreach (int channelHandle in channels) { // Manipulate individual channels Bass.ChannelSetAttribute(channelHandle, ChannelAttribute.Pan, -1.0f); } ``` -------------------------------- ### Get a sample channel with SampleGetChannel Source: https://deepwiki.com/ManagedBass/ManagedBass/7.4-sample-management Retrieves a channel for a sample before playback. The first call recycles an existing channel; passing true or BassFlags.SampleChannelNew forces a new channel; BassFlags.SampleChannelStream returns a stream channel instead of a sample channel. ```csharp // Get a channel for the sample int channel = Bass.SampleGetChannel(sampleHandle); // Get a new channel (don't recycle existing) int channel = Bass.SampleGetChannel(sampleHandle, true); // or int channel = Bass.SampleGetChannel(sampleHandle, BassFlags.SampleChannelNew); // Get a stream channel instead of a sample channel int channel = Bass.SampleGetChannel(sampleHandle, BassFlags.SampleChannelStream); ``` -------------------------------- ### Get sample channel and stream channel with Bass.SampleGetChannel Source: https://deepwiki.com/ManagedBass/ManagedBass/7.4-sample-management Shows how to retrieve a standard sample channel or a stream channel using BassFlags.SampleChannelStream. Use the standard channel for multiple playback of the same sound with channel reuse; use the stream channel for single playback with full DSP/FX support and position control. ```csharp // Get a standard sample channel int sampleChannel = Bass.SampleGetChannel(sampleHandle); // Get a stream channel for the sample int streamChannel = Bass.SampleGetChannel(sampleHandle, BassFlags.SampleChannelStream); ``` -------------------------------- ### Retrieve Sample Data and FFT for Visualization Source: https://deepwiki.com/ManagedBass/ManagedBass/2.1-channel-management Use Bass.ChannelGetData to retrieve raw sample data for processing or FFT data for spectrum analysis. The FFT example uses DataFlags.FFT1024 to request a 1024-point FFT. ```csharp // Get raw sample data byte[] buffer = new byte[1024]; int bytesRead = Bass.ChannelGetData(channelHandle, buffer, buffer.Length); // Get FFT data for spectrum analysis float[] fftData = new float[512]; int bytesProcessed = Bass.ChannelGetData(channelHandle, fftData, (int)DataFlags.FFT1024); ``` -------------------------------- ### Get CD drive information with BassCd.GetInfo Source: https://deepwiki.com/ManagedBass/ManagedBass/6.3-cd-audio-support Retrieves a CDInfo structure containing vendor, product, revision, read capabilities, and maximum read speed for the specified drive. ```csharp CDInfo info = BassCd.GetInfo(drive); ``` -------------------------------- ### Bass.ChannelPlay Source: https://deepwiki.com/ManagedBass/ManagedBass/7.4-sample-management Starts playback of a sample channel. Use this to begin playing a sample after obtaining a channel. ```APIDOC ## Bass.ChannelPlay ### Description Starts playback of a sample channel. Use this to begin playing a sample after obtaining a channel. ### Method ChannelPlay ### Parameters - **channel** (int) - Required - Handle of the channel to play. ### Return Value - **bool** - True on success, false on failure. ### Request Example ```csharp // Play the sample Bass.ChannelPlay(channel); ``` ``` -------------------------------- ### Bass.SampleGetChannels Source: https://deepwiki.com/ManagedBass/ManagedBass/7.4-sample-management Retrieves all active channels for a sample. Use this to get an array of channel handles for individual manipulation. ```APIDOC ## Bass.SampleGetChannels ### Description Retrieves all active channels for a sample. Use this to get an array of channel handles for individual manipulation. ### Method SampleGetChannels ### Parameters - **sampleHandle** (int) - Required - Handle of the sample. ### Return Value - **int[]** - Array of channel handles. ### Request Example ```csharp // Get all active channels for a sample int[] channels = Bass.SampleGetChannels(sampleHandle); // Do something with each channel foreach (int channelHandle in channels) { // Manipulate individual channels Bass.ChannelSetAttribute(channelHandle, ChannelAttribute.Pan, -1.0f); } ``` ``` -------------------------------- ### Get Audio Data from Input Device Buffer Source: https://deepwiki.com/ManagedBass/ManagedBass/5.1-wasapi-integration Retrieves immediate sample data or FFT representation from the device's buffer for input devices with buffering enabled. ```csharp int bytesRead = BassWasapi.GetData(buffer, length); ``` -------------------------------- ### Get and modify sample info with SampleGetInfo and SampleSetInfo Source: https://deepwiki.com/ManagedBass/ManagedBass/7-advanced-topics Retrieves the SampleInfo object for a sample, modifies default attributes (frequency, volume, pan) that apply to all channel instances, then applies changes with SampleSetInfo. ```csharp // Get sample info SampleInfo info = Bass.SampleGetInfo(sampleHandle); // Modify attributes info.Frequency = 22050; // Half-speed playback info.Volume = 0.8f; // 80% volume info.Pan = -0.3f; // Slightly to the left // Apply changes Bass.SampleSetInfo(sampleHandle, info); ``` -------------------------------- ### Retrieve WASAPI device info Source: https://deepwiki.com/ManagedBass/ManagedBass/5.1-wasapi-integration Gets detailed configuration info after initialization, including sample format, rate, channels, buffer/period lengths, and input/exclusive mode. ```csharp WasapiInfo info = BassWasapi.Info; ``` -------------------------------- ### ChannelPlay Source: https://deepwiki.com/ManagedBass/ManagedBass/2.2-audio-playback-controls Starts or resumes playback of a channel. Use this method to begin playback from the current position or resume after pausing. ```APIDOC ## ChannelPlay ### Description Starts or resumes playback of a channel. ### Method ChannelPlay ### Parameters - **handle** (int) - Required - The channel handle. ### Response Returns a boolean indicating success. ``` -------------------------------- ### Extract order and row from MOD music position using BitHelper Source: https://deepwiki.com/ManagedBass/ManagedBass/2.1-channel-management Uses Bass.ChannelGetPosition with PositionFlags.MusicOrders to get a packed MOD music position, then extracts the order and row components via LoWord() and HiWord() helper methods from the BitHelper class. Source: src/Bass/Shared/BitHelper.cs1-50. ```csharp // For MOD music positions which pack order/row in one value int position = Bass.ChannelGetPosition(musicChannel, PositionFlags.MusicOrders); int order = position.LoWord(); // Get order from low word int row = position.HiWord(); // Get row from high word ``` -------------------------------- ### Get and modify sample attributes with Bass.SampleGetInfo and Bass.SampleSetInfo Source: https://deepwiki.com/ManagedBass/ManagedBass/7.4-sample-management Retrieves a SampleInfo object, modifies its Frequency and Volume properties, then applies the changes. The SampleInfo class controls default playback properties such as sample rate and volume. ```csharp // Get sample attributes SampleInfo info = Bass.SampleGetInfo(sampleHandle); // Modify attributes info.Frequency = 22050; // Change sample rate info.Volume = 0.8f; // Set volume to 80% // Apply changes Bass.SampleSetInfo(sampleHandle, info); ``` -------------------------------- ### Get and modify sample data with Bass.SampleGetData and Bass.SampleSetData Source: https://deepwiki.com/ManagedBass/ManagedBass/7.4-sample-management Retrieves raw audio data into a float[] buffer, applies a gain reduction of 0.8f, and writes the modified data back to the sample. Supported buffer types are byte[] for 8-bit, short[] for 16-bit, int[] for 32-bit integer, and float[] for 32-bit floating-point samples. ```csharp // Get sample data float[] buffer = new float[dataLength]; Bass.SampleGetData(sampleHandle, buffer); // Modify buffer data (e.g., apply gain) for (int i = 0; i < buffer.Length; i++) { buffer[i] *= 0.8f; // Reduce volume } // Set the modified data back to the sample Bass.SampleSetData(sampleHandle, buffer); ``` -------------------------------- ### Get channel info with Bass.ChannelGetInfo Source: https://deepwiki.com/ManagedBass/ManagedBass/2.1-channel-management Retrieves information about a channel using the ChannelGetInfo function. The first overload returns a boolean success flag and fills a ChannelInfo structure; the second overload throws an exception on error and returns the ChannelInfo directly. ```csharp // Get info about a channel bool success = Bass.ChannelGetInfo(channelHandle, out ChannelInfo info); // Alternative that throws an exception on error ChannelInfo info = Bass.ChannelGetInfo(channelHandle); ``` -------------------------------- ### Create sample with BassFlags.VAM and configure VAM options Source: https://deepwiki.com/ManagedBass/ManagedBass/7.4-sample-management Creates a sample with the BassFlags.VAM flag to enable DirectX 7 voice allocation and management, then retrieves its SampleInfo, sets VAM to Hardware with TerminatePriority, sets priority to 100, and applies the changes with Bass.SampleSetInfo. ```csharp // Create a sample with VAM enabled int sampleHandle = Bass.CreateSample( length, frequency, channels, max, BassFlags.VAM ); // Configure VAM options SampleInfo info = Bass.SampleGetInfo(sampleHandle); info.VAM = VAMMode.Hardware | VAMMode.TerminatePriority; info.Priority = 100; Bass.SampleSetInfo(sampleHandle, info); ``` -------------------------------- ### Get and Set Channel Position with PositionFlags Source: https://deepwiki.com/ManagedBass/ManagedBass/2.1-channel-management Use ChannelGetPosition, ChannelSetPosition, ChannelGetLength, ChannelBytes2Seconds, and ChannelSeconds2Bytes to control playback position. Position can be specified in bytes (default) or seconds using PositionFlags. ```csharp // Get overall level (returns packed left/right channels) int level = Bass.ChannelGetLevel(channelHandle); // Get individual levels int leftLevel = Bass.ChannelGetLevelLeft(channelHandle); int rightLevel = Bass.ChannelGetLevelRight(channelHandle); // Advanced level retrieval with more control float[] levels = Bass.ChannelGetLevel(channelHandle, 0.05f, LevelRetrievalFlags.RMS); ``` -------------------------------- ### Position Control: ChannelSetPosition and ChannelGetPosition Source: https://deepwiki.com/ManagedBass/ManagedBass/2-core-audio-system Sets and retrieves the playback position within a channel. ChannelSetPosition sets the position to 30 seconds from the start using PositionFlags.Bytes, and ChannelGetPosition retrieves the current position in bytes, which is then converted to seconds with ChannelBytes2Seconds. ```csharp // Set position to 30 seconds from the start Bass.ChannelSetPosition(channelHandle, Bass.ChannelSeconds2Bytes(channelHandle, 30), PositionFlags.Bytes); // Get current position in seconds double currentPosInSeconds = Bass.ChannelBytes2Seconds( channelHandle, Bass.ChannelGetPosition(channelHandle, PositionFlags.Bytes) ); ``` -------------------------------- ### Core Playback Functions: ChannelPlay, ChannelPause, ChannelStop, ChannelIsActive Source: https://deepwiki.com/ManagedBass/ManagedBass/2-core-audio-system Controls playback of an audio channel. ChannelPlay starts or resumes playback, ChannelPause pauses while maintaining position, ChannelStop stops and resets position, and ChannelIsActive returns the current playback state. The example checks if the channel is playing before pausing and stopping. ```csharp // Start playback Bass.ChannelPlay(channelHandle, false); // Check if channel is playing if (Bass.ChannelIsActive(channelHandle) == PlaybackState.Playing) { // Channel is currently playing } // Pause playback Bass.ChannelPause(channelHandle); // Stop playback Bass.ChannelStop(channelHandle); ``` -------------------------------- ### Get RMS levels with volume/pan applied Source: https://deepwiki.com/ManagedBass/ManagedBass/7-advanced-topics Efficiently retrieves stereo RMS levels with current volume and pan applied using a 50ms window. More efficient than alternative level retrieval methods. ```csharp // More efficient: Get RMS levels with current volume/pan applied float[] levels = new float[2]; // Stereo levels Bass.ChannelGetLevel( channel, levels, 0.05f, // 50ms window LevelRetrievalFlags.RMS | LevelRetrievalFlags.VolPan ); ``` -------------------------------- ### BassWasapi.Init Source: https://deepwiki.com/ManagedBass/ManagedBass/5.1-wasapi-integration Initializes a WASAPI device with the specified parameters. This is the main entry point for setting up audio capture or playback. ```APIDOC ## [METHOD] BassWasapi.Init ### Description Initializes a WASAPI device with the specified parameters. This is the main entry point for setting up audio capture or playback. ### Method Init ### Parameters - **device** (int) - Required - The device ID (0 = first device, -1 = default output, -2 = default input) - **frequency** (int) - Required - Sample rate (0 = use device's mix format) - **channels** (int) - Required - Number of channels (0 = use device's mix format) - **flags** (WasapiInitFlags) - Required - Combination of WasapiInitFlags values - **buffer** (float) - Required - Buffer length in seconds - **period** (float) - Required - Update period in seconds (time between callback function calls) - **procedure** (Procedure) - Required - Callback function for processing audio, or null for push-based operation - **user** (IntPtr) - Required - User-defined data passed to the callback ### Request Example ``` BassWasapi.Init(device, frequency, channels, flags, buffer, period, procedure, user); ``` ``` -------------------------------- ### Bass.ChannelPlay Source: https://deepwiki.com/ManagedBass/ManagedBass/2.2-audio-playback-controls Starts or resumes playback of a channel. The restart parameter determines whether playback starts from the beginning or resumes from the current position. ```APIDOC ## [METHOD] Bass.ChannelPlay ### Description Starts or resumes playback of a channel. When restart is true, playback starts from the beginning; when false, it resumes from the current position. For MOD music channels, restarting also resets BPM and other music parameters. ### Method ChannelPlay ### Parameters - **channelHandle** (HCHANNEL/HSTREAM/HMUSIC/HRECORD) - Required - The handle of the channel to play. - **restart** (bool) - Optional - If true, start from the beginning; if false, resume from current position. Defaults to false. ### Response #### Success Response - **bool** - Returns true on success, false on failure. ### Request Example ```csharp // Start or resume playback bool success = Bass.ChannelPlay(channelHandle, restart); ``` ``` -------------------------------- ### Initialize BASS with platform-specific parameters Source: https://deepwiki.com/ManagedBass/ManagedBass/2-core-audio-system Initializes the BASS audio library with default device and sample rate. If initialization fails, retrieves the last error via Bass.LastError. ```csharp // Initialize BASS with platform-specific parameters bool success = Bass.Init(-1, 44100, DeviceInitFlags.Default); if (!success) { // Handle initialization failure Errors error = Bass.LastError; } ``` -------------------------------- ### Get channel CPU usage and overall BASS CPU usage Source: https://deepwiki.com/ManagedBass/ManagedBass/2.1-channel-management Retrieves CPU usage for a specific channel via Bass.ChannelGetAttribute with ChannelAttribute.CPUUsage, and overall BASS CPU usage via Bass.CPUUsage. Useful for identifying channels consuming excessive CPU resources. Source: src/Bass/Shared/Bass/PInvoke/Bass.cs52-85. ```csharp // Get channel CPU usage double cpuUsage = Bass.ChannelGetAttribute(channelHandle, ChannelAttribute.CPUUsage); // Get overall BASS CPU usage double overallCpu = Bass.CPUUsage; ``` -------------------------------- ### WASAPI Device Notification Callback Setup Source: https://deepwiki.com/ManagedBass/ManagedBass/5-low-latency-audio Sets up a notification callback using BassWasapi.SetNotify to handle audio device changes. The callback receives a WasapiNotificationType and device ID, allowing the app to respond to enabled, disabled, default output/input, or failure events. On failure, the device may need to be reinitialized. ```csharp // Set up a notification callback BassWasapi.SetNotify(OnWasapiNotify); // Notification callback private void OnWasapiNotify(WasapiNotificationType type, int device) { switch (type) { case WasapiNotificationType.Enabled: // Device has been enabled break; case WasapiNotificationType.Disabled: // Device has been disabled break; case WasapiNotificationType.DefaultOutput: // Device is now the default output break; case WasapiNotificationType.DefaultInput: // Device is now the default input break; case WasapiNotificationType.Fail: // Device has failed // May need to reinitialize break; } } ``` -------------------------------- ### Play a sample channel with SampleGetChannel and ChannelPlay Source: https://deepwiki.com/ManagedBass/ManagedBass/7-advanced-topics Obtains a channel handle from a sample, optionally sets channel-specific attributes, and begins playback. Multiple channels can be obtained for simultaneous instances. ```csharp // Get a channel from the sample int channelHandle = Bass.SampleGetChannel(sampleHandle, false); // Set any channel-specific attributes if needed Bass.ChannelSetAttribute(channelHandle, ChannelAttribute.Volume, 0.9f); // Begin playback Bass.ChannelPlay(channelHandle); ``` -------------------------------- ### Set and Get Channel Attributes (Volume, Pan) Source: https://deepwiki.com/ManagedBass/ManagedBass/2.3-channel-attributes Use Bass.ChannelSetAttribute and Bass.ChannelGetAttribute to control basic playback attributes like Volume and Pan. Volume range is 0.0 (silent) to 1.0 (full), Pan range is -1.0 (left) to +1.0 (right). ```csharp // Set volume to 50% Bass.ChannelSetAttribute(channelHandle, ChannelAttribute.Volume, 0.5f); // Get current panning position float panValue; Bass.ChannelGetAttribute(channelHandle, ChannelAttribute.Pan, out panValue); ``` -------------------------------- ### Create user-generated sample with Bass.CreateSample and fill with Bass.SampleSetData Source: https://deepwiki.com/ManagedBass/ManagedBass/7.4-sample-management Creates a 16-bit stereo sample at 44100Hz with up to 10 simultaneous playbacks, then fills it with audio data. The length parameter (44100 * 4) represents 1 second of 16-bit stereo audio (4 bytes per sample). ```csharp // Create a new sample (16-bit stereo at 44100Hz, max 10 simultaneous playbacks) int sampleHandle = Bass.CreateSample( length: 44100 * 4, // 1 second of 16-bit stereo audio (4 bytes per sample) frequency: 44100, channels: 2, max: 10, flags: BassFlags.Default ); // Fill the sample with audio data Bass.SampleSetData(sampleHandle, audioDataBuffer); ``` -------------------------------- ### Create an 8-bit sample Source: https://deepwiki.com/ManagedBass/ManagedBass/7-advanced-topics Creates a sample with 8-bit resolution for a smaller memory footprint. Suitable for applications with many sound effects. ```csharp // Create an 8-bit sample (smaller memory footprint) int sample = Bass.CreateSample( length, frequency, channels, max, BassFlags.Byte ); ``` -------------------------------- ### Channel Flags: Get, Set, and Helper Methods Source: https://deepwiki.com/ManagedBass/ManagedBass/2.1-channel-management Use Bass.ChannelFlags to get or set channel flags, and the helper methods ChannelHasFlag, ChannelAddFlag, and ChannelRemoveFlag to manage flags. Common flags include BassFlags.Loop, BassFlags.3D, and BassFlags.AutoFree. ```csharp // Get current flags BassFlags flags = Bass.ChannelFlags(channelHandle, 0, 0); // Set flags BassFlags newFlags = Bass.ChannelFlags(channelHandle, BassFlags.Loop, BassFlags.Loop); // Helper methods bool hasLoop = Bass.ChannelHasFlag(channelHandle, BassFlags.Loop); bool addedFlag = Bass.ChannelAddFlag(channelHandle, BassFlags.Loop); bool removedFlag = Bass.ChannelRemoveFlag(channelHandle, BassFlags.Loop); ``` -------------------------------- ### Get and set CD read speed with BassCd.GetSpeed and SetSpeed Source: https://deepwiki.com/ManagedBass/ManagedBass/6.3-cd-audio-support Gets current read speed in KB/s or as a multiplier, and sets speed in KB/s (e.g., 5645 KB/s ≈ 32x). Conversion: KB/s = multiplier × 176.4. ```csharp // Get current read speed in KB/s int speed = BassCd.GetSpeed(drive); // Get current read speed as multiplier (e.g., 32x) double multiplier = BassCd.GetSpeedMultiplier(drive); // Set read speed in KB/s BassCd.SetSpeed(drive, 5645); // Approximately 32x ``` -------------------------------- ### CheckFormat: Check device sample format support Source: https://deepwiki.com/ManagedBass/ManagedBass/5.1-wasapi-integration Use before initializing a device to verify it supports a particular sample format. Especially important in exclusive mode, as devices may support different formats than in shared mode. ```csharp WasapiFormat format = BassWasapi.CheckFormat(device, frequency, channels, flags); ``` -------------------------------- ### ChannelGetPosition Source: https://deepwiki.com/ManagedBass/ManagedBass/2.2-audio-playback-controls Gets the current playback position of a channel. ```APIDOC ## ChannelGetPosition ### Description Gets the current playback position of a channel. ### Method ChannelGetPosition ### Parameters - **handle** (int) - Required - The channel handle. ### Response Returns the current playback position. ``` -------------------------------- ### Bass.SampleGetInfo Source: https://deepwiki.com/ManagedBass/ManagedBass/7.4-sample-management Retrieves information about a sample, including VAM settings and priority. ```APIDOC ## Bass.SampleGetInfo ### Description Retrieves information about a sample, including VAM settings and priority. ### Method SampleGetInfo ### Parameters - **sampleHandle** (int) - Required - The handle of the sample. ### Response #### Success Response - **info** (SampleInfo) - The sample information structure. ### Request Example ```csharp SampleInfo info = Bass.SampleGetInfo(sampleHandle); ``` ``` -------------------------------- ### BassCd.GetSpeed(drive) Source: https://deepwiki.com/ManagedBass/ManagedBass/6.3-cd-audio-support Gets the current read speed of the CD drive in KB/s. ```APIDOC ## BassCd.GetSpeed(drive) ### Description Gets the current read speed of the CD drive in KB/s. ### Method GetSpeed ### Parameters - **drive** - Required - The CD drive to query. ### Returns - **int** - Current read speed in KB/s. ### Request Example ```csharp int speed = BassCd.GetSpeed(drive); ``` ``` -------------------------------- ### ChannelGetAttribute Source: https://deepwiki.com/ManagedBass/ManagedBass/2.1-channel-management Gets the current value of a channel attribute, such as volume, panning, or playback speed. ```APIDOC ## ChannelGetAttribute ### Description Gets the current value of a channel attribute, such as volume, panning, or playback speed. ### Method Function ### Parameters - **Handle** (int) - Required - The channel handle. - **Attribute** (type not specified) - Required - The attribute to retrieve. ### Response Returns a float/double value representing the attribute's current value. ``` -------------------------------- ### Load sample from file with Bass.SampleLoad Source: https://deepwiki.com/ManagedBass/ManagedBass/7-advanced-topics Loads a WAV file into memory as a sample, allowing up to 5 simultaneous playback instances. Use for sound effects or short clips. ```csharp int sampleHandle = Bass.SampleLoad("sound.wav", 0, 0, 5, BassFlags.Default); ``` -------------------------------- ### Free WASAPI device resources with BassWasapi.Free() Source: https://deepwiki.com/ManagedBass/ManagedBass/5.1-wasapi-integration Call when finished with a device to free resources. Should be called for all initialized devices before the program closes. ```csharp BassWasapi.Free(); ``` -------------------------------- ### BassCd.GetSpeedMultiplier(drive) Source: https://deepwiki.com/ManagedBass/ManagedBass/6.3-cd-audio-support Gets the current read speed of the CD drive as a multiplier (e.g., 32x). ```APIDOC ## BassCd.GetSpeedMultiplier(drive) ### Description Gets the current read speed of the CD drive as a multiplier (e.g., 32x). ### Method GetSpeedMultiplier ### Parameters - **drive** - Required - The CD drive to query. ### Returns - **double** - Current read speed as a multiplier. ### Request Example ```csharp double multiplier = BassCd.GetSpeedMultiplier(drive); ``` ``` -------------------------------- ### Basic CD playback with BassCd Source: https://deepwiki.com/ManagedBass/ManagedBass/6.3-cd-audio-support Checks if a CD is ready in drive 0, creates a stream from the first track, plays it, and frees the stream when done. ```csharp // Check if a CD is in the drive if (BassCd.IsReady(0)) { // Create a stream from the first track int stream = BassCd.CreateStream(0, 0, BassFlags.Default); if (stream != 0) { // Play the stream Bass.ChannelPlay(stream, false); // When done Bass.StreamFree(stream); } } ``` -------------------------------- ### Init: Initialize WASAPI device Source: https://deepwiki.com/ManagedBass/ManagedBass/5.1-wasapi-integration Initializes a WASAPI device with the given parameters. Key parameters: device (0 = first, -1 = default output, -2 = default input), frequency (0 = device mix format), channels (0 = device mix format), flags (WasapiInitFlags), buffer (seconds), period (seconds between callbacks), procedure (callback or null for push-based). ```csharp BassWasapi.Init(device, frequency, channels, flags, buffer, period, procedure, user); ``` -------------------------------- ### Get BassEnc_Aac Version Source: https://deepwiki.com/ManagedBass/ManagedBass/4.3-aac-encoding Retrieves the version of the loaded BassEnc_Aac module. Use this to verify the module is available and check its version. ```csharp Version version = BassEnc_Acc.Version; ``` -------------------------------- ### Setting up and removing a DSP with automatic reference management Source: https://deepwiki.com/ManagedBass/ManagedBass/2-core-audio-system Shows how to attach a DSP callback to a channel and later remove it. The ChannelReferences class internally maintains references to the callback to prevent garbage collection, and cleans up when the DSP is removed. ```csharp // Example: Setting up a DSP with automatic reference management int dspHandle = Bass.ChannelSetDSP(channelHandle, MyDspProcedure); // ChannelReferences.Add() is called internally to maintain the reference // Later, when removing the DSP Bass.ChannelRemoveDSP(channelHandle, dspHandle); // ChannelReferences.Remove() is called internally to clean up ``` -------------------------------- ### Get Multi-Channel Audio Levels Source: https://deepwiki.com/ManagedBass/ManagedBass/5.1-wasapi-integration Retrieves level information for multiple channels using the provided levels array, length, and flags. ```csharp BassWasapi.GetLevel(levels, length, flags); ``` -------------------------------- ### Bass.CPUUsage Source: https://deepwiki.com/ManagedBass/ManagedBass/2.1-channel-management Gets the overall BASS CPU usage as a double value. This property helps monitor total CPU consumption across all channels. ```APIDOC ## [GET] Bass.CPUUsage ### Description Gets the overall BASS CPU usage. ### Method GET ### Endpoint Bass.CPUUsage ### Response #### Success Response (200) - **overallCpu** (double) - The overall CPU usage. ### Request Example ```csharp // Get overall BASS CPU usage double overallCpu = Bass.CPUUsage; ``` ``` -------------------------------- ### Bass.CreateSample Source: https://deepwiki.com/ManagedBass/ManagedBass/7.4-sample-management Creates a new sample with specified parameters and flags. The VAM flag enables voice allocation management. ```APIDOC ## Bass.CreateSample ### Description Creates a new sample with specified parameters and flags. The VAM flag enables voice allocation management. ### Method CreateSample ### Parameters - **length** (int) - Required - The sample length in bytes. - **frequency** (int) - Required - The sample frequency. - **channels** (int) - Required - The number of channels. - **max** (int) - Required - The maximum number of simultaneous plays. - **flags** (BassFlags) - Required - Flags for sample creation, e.g., `BassFlags.VAM`. ### Response #### Success Response - **sampleHandle** (int) - The handle of the created sample. ### Request Example ```csharp int sampleHandle = Bass.CreateSample( length, frequency, channels, max, BassFlags.VAM ); ``` ``` -------------------------------- ### Get Audio Level (Peak Amplitude) Source: https://deepwiki.com/ManagedBass/ManagedBass/5.1-wasapi-integration Returns the peak amplitude of the current device, with left channel in the low word and right channel in the high word. ```csharp int level = BassWasapi.GetLevel(); ```