^ What's the point?
^ Usage
^ Functions

Download :: Topics on this subject on the Forum :: Top
BASS Encoder Library

BASS Encoder Library is a COM/DLL MP3, Opus, FLAC, Ogg Vorbis and WAV encoder component that uses lame_enc.dll for encoding MP3, Opus, FLAC, Ogg Vorbis and WAV files for use in Win32 and Win64 (Windows XP/Vista/7/8/10) software.
Encodes audio file formats supported by BASS: WAV/RF64, AIFF, MP3, MP2, MP1, Ogg Vorbis (and formats supported by BASS plugins) and OS supported formats like AAC/MP4, Flac, etc. to MP3, Opus, FLAC, Ogg Vorbis and WAV format.

Features:
  • Encode various audio file formats into MP3, Opus, FLAC, Ogg Vorbis and WAV format
  • COM class usable by developer environments/platforms supporting COM classes like VBScript
  • Stream encoding interface for MP3 (send sample data to the component and receive the encoded MP3 data)
  • ID3v1, ID3v2, Lyrics3, APEv2, Flac, Ogg Vorbis, Opus, MP4, WAV LIST INFO, BEXT and CART and WMA tags are transfered to output file
  • Optionaly specify segment to encode or use silence detection to trim leading and trailing silence
  • Normalize the volume to arbitrary amount
  • Optional lowpass and highpass filtering
  • Supports using the BASSEncoder.dll itself natively without COM, Delphi and C++ API included
  • As no external .exe is started the library is usable for Windows Store apps


Requirements

Developer environment/platform supporting COM classes or DLLs.


Installation

Run an elevated command prompt, change dir into the folder where 'BASSEncoder.dll' is located, run the following: "regsvr32 BASSEncoder.dll". This should register the COM class. Do this for the desired Win32 and/or Win64 version.
When using the BASS method bass.dll and bass_fx.dll is needed on the search path, eg. beside your .exe, or copy the needed DLLs to \Windows\System32\ (Win64 DLLs on a 64 bit OS) and/or \Windows\SysWOW64\ (Win32 DLLs on a 64 bit OS) folder. If the OS is 32 bit then copy the needed DLLs to \Windows\System32\ (from the Win32 folder).
To use the library in VBScript, on a 64 bit OS, the VBScript process is 64 bit so the needed DLLs have to be from the Win64 folder, beside the .VBS file or in the System32 folder as written above.


Usage

After registering the DLL it can be accessed like:
    createobject("BASSEncoder.TLAMEEncodeFile");

    createobject("BASSEncoder.TBASSEncodeFileOpus");

    createobject("BASSEncoder.TBASSEncodeFileFLAC");

    createobject("BASSEncoder.TBASSEncodeFileVorbis");

    createobject("BASSEncoder.TBASSEncodeFileWAV");
VBScript usage example, output 320 kbps, 44 100 Hz, 2 channel CBR MP3 audio file:
    option explicit
    dim myobject
    set myobject = createobject("BASSEncoder.TLAMEEncodeFile")
    myobject.LoadBASSFormatPlugin "bass_ape.dll" 'optional, load needed BASS plugins here before calling 'EncodeFileWithBASS()'
    myobject.EncodeFileWithBASS "E:\Test.wav", "E:\Test.mp3", 320, 44100, 2, 0, 0, 0, 0, nothing
    set myobject = nothing
or using Opus, use source file's attributes:
    option explicit
    dim myobject
    set myobject = createobject("BASSEncoder.TBASSEncodeFileOpus")
    myobject.EncodeFile "E:\Test.wav", "E:\Test.mp3", '--bitrate 320', 0, 0, 0, 0, 0, nothing
    set myobject = nothing
Please see the Delphi tutorials on how to use the library with Delphi.

Parameters: Specifying 0 for 'ResampleSampleRate' and/or 'Channels' means automatic, best quality, values. If the input file's attribute is larger than the allowed maximum value the maximum supported value is used, if the source file's attribute is supported by the output format the source file's attribute is used.
Note that encoding to Opus format is always (resampled to) 48 000 Hz.
  • function EncodeFileWithBASS (const FileName, OutputFileName: WideString; BitRate: Integer; ResampleSampleRate, Channels: SYSUINT; VBR: Integer; StartPosition, Length, Normalize: Double; const ProgressCallback: IProgress): HResult;
    • If 'ResampleSampleRate' is 0 then the source file's sample rate is used. Valid range is 8000 to 48000.
    • If 'Channels' is 0 then the source file's channel count is used. Valid value is 1 or 2.
    • Set 'VBR' to a non-zero value to enable VBR encoding mode.
    • 'StartPosition' and 'Length' are in seconds. Use 0 for all.
    • Set 'Normalize' to 1.0 (100%) or specify 0 (don't change).
    • 'ProgressCallback' is an interface callback for encoding progress reporting. Set to nil if you don't wish to use a progress callback.
  • function EncodeFileSilenceDetected (const FileName, OutputFileName: WideString; BitRate: Integer; ResampleSampleRate, Channels: SYSUINT; VBR: Integer; MaxSilenceVolume, PrependLength, AppendLength, Normalize: Double; const ProgressCallback: IProgress): HResult; stdcall;
    • Same as EncodeFileWithBASS() with 3 different parameters:
    • 'MaxSilenceVolume' set to 1.0 for 100%, usualy value is 0.05 - 0.1.
    • 'PrependLength' and 'AppendLength' are in seconds, extend the detected segment by this amount.
Using BASSEncoder.dll natively: There are 17 exported functions available:
  • function LAMEEncodeWAVFile(FileName, OutputFileName: PWideChar; BitRate: Integer; TransferTags: LongBool; StartPosition, Length, Normalize: Double; ProgressCallback: IProgress): HResult; stdcall;
  • function LAMEEncodeFileWithBASS(FileName, OutputFileName: PWideChar; BitRate, ResampleSampleRate, Channels, VBR: Integer; TransferTags: LongBool; StartPosition, Length, Normalize: Double; ProgressCallback: IProgress): HResult; stdcall;
  • function BASSEncodeFileOpus(FileName, OutputFileName, Parameters: PWideChar; ResampleSampleRate, Channels: Integer; TransferTags: LongBool; StartPosition, Length, Normalize: Double; ProgressCallback: IProgress): HResult; stdcall;
  • function BASSEncodeFileFLAC(FileName, OutputFileName, Parameters: PWideChar; ResampleSampleRate, Channels: Integer; TransferTags: LongBool; StartPosition, Length, Normalize: Double; ProgressCallback: IProgress): HResult; stdcall;
  • function BASSEncodeFileOggVorbis(FileName, OutputFileName, Parameters: PWideChar; ResampleSampleRate, Channels: Integer; TransferTags: LongBool; StartPosition, Length, Normalize: Double; ProgressCallback: IProgress): HResult; stdcall;
  • function BASSEncodeFileWAV(FileName, OutputFileName, Parameters: PWideChar; ResampleSampleRate, Channels: Integer; TransferTags: LongBool; StartPosition, Length, Normalize: Double; ProgressCallback: IProgress): HResult; stdcall;
  • function BASSEncodeFileWithBASSSilenceDetected(FileName, OutputFileName: PWideChar; BitRate, ResampleSampleRate, Channels, VBR: Integer; TransferTags: LongBool; MaxSilenceVolume, PrependLength, AppendLength, Normalize: Double; ProgressCallback: IProgress): HResult; stdcall;
  • function BASSEncodeFileOpusSilenceDetected(FileName, OutputFileName, Parameters: PWideChar; ResampleSampleRate, Channels: Integer; TransferTags: LongBool; MaxSilenceVolume, PrependLength, AppendLength, Normalize: Double; ProgressCallback: IProgress): HResult; stdcall;
  • function BASSEncodeFileFLACSilenceDetected(FileName, OutputFileName, Parameters: PWideChar; ResampleSampleRate, Channels: Integer; TransferTags: LongBool; MaxSilenceVolume, PrependLength, AppendLength, Normalize: Double; ProgressCallback: IProgress): HResult; stdcall;
  • function BASSEncodeFileOggVorbisSilenceDetected(FileName, OutputFileName, Parameters: PWideChar; ResampleSampleRate, Channels: Integer; TransferTags: LongBool; MaxSilenceVolume, PrependLength, AppendLength, Normalize: Double; ProgressCallback: IProgress): HResult; stdcall;
  • function BASSEncodeFileWAVSilenceDetected(FileName, OutputFileName, Parameters: PWideChar; ResampleSampleRate, Channels: Integer; TransferTags: LongBool; MaxSilenceVolume, PrependLength, AppendLength, Normalize: Double; ProgressCallback: IProgress): HResult; stdcall;
  • function LAMEEncoderGetFile: ILAMEEncodeFile; stdcall;
  • function LAMEEncoderGetStream: ILAMEEncodeStream; stdcall;
  • function BASSEncoderGetFileOpus: IBASSEncodeFile; stdcall;
  • function BASSEncoderGetFileFLAC: IBASSEncodeFile; stdcall;
  • function BASSEncoderGetFileVorbis: IBASSEncodeFile; stdcall;
  • function BASSEncoderGetFileWAV: IBASSEncodeFile; stdcall;
The first 6 functions can be used to directly call the 6 encoder functions.
The last 6 functions return the interface for the 'ILAMEEncodeFile', 'ILAMEEncodeStream' and Opus/FLAC/Ogg Vorbis/WAV 'IBASSEncodeFile' classes.


HResult error codes
  • S_OK: Success.
  • S_FALSE: Unknown error occured or catastrophic failure.
  • 2: lame_enc.dll could not be loaded.
  • 3: bass.dll could not be loaded.
  • 4: bassmix.dll could not be loaded.
  • 5: bassenc_opus.dll could not be loaded.
  • 6: bassenc_flac.dll could not be loaded.
  • 7: bassenc_ogg.dll could not be loaded.
  • 8: bass_fx.dll could not be loaded.
  • 9: Input file could not be opened.
  • 10: Output file could not be created.
  • E_INVALIDARG: Parameters specified are invalid.


BASS Encoder Library in shareware and commercial software?

The component is free for use in free software. If you like it and use it in a shareware or commercial (or any other money making - advertising, in app. selling, etc.) product you need one of the licenses.


Useful information


[Top]