📄 unabladeencapi.pas
字号:
//
r_lameInitStream : proc_beInitStream; // same stubs as for Blade
r_lameEncodeChunk : proc_beEncodeChunk;
r_lameDeinitStream: proc_beDeinitStream;
r_lameCloseStream : proc_beCloseStream;
r_lameVersion : proc_beVersion;
r_lameWriteVBRHeader: proc_lameWriteVBRHeader;
end;
{DP:METHOD
This function is the first to call before starting an encoding stream.
}
function lameInitStream(const lameProc: tLameLibrary_proc; config: PBE_CONFIG_FORMATLAME; out nSamples: DWORD; out minOutputBufSize: DWORD; out stream: HBE_STREAM): BE_ERR;
{DP:METHOD
Encodes a chunk of samples. Please note that if you have set the output to
generate mono MP3 files you must feed beEncodeChunk() with mono samples!
}
function lameEncodeChunk(const lameProc: tLameLibrary_proc; stream: HBE_STREAM; nSamples: DWORD; samplesBuf: pointer; outputBuf: pointer; out outputUsed: DWORD): BE_ERR;
{DP:METHOD
This function should be called after encoding the last chunk in order to
flush the encoder. It writes any encoded data that still might be left inside
the encoder to the output buffer. This function should NOT be called unless you
have encoded all of the chunks in your stream.
}
function lameDeinitStream(const lameProc: tLameLibrary_proc; stream: HBE_STREAM; outputBuf: pointer; out outputUsed: DWORD): BE_ERR;
{DP:METHOD
Last function to be called when finished encoding a stream.
Should unlike beDeinitStream() also be called if the encoding is canceled.
}
function lameCloseStream(const lameProc: tLameLibrary_proc; stream: HBE_STREAM): BE_ERR;
{DP:METHOD
Returns information like version numbers (both of the DLL and encoding engine),
release date and URL for BladeEnc's homepage. All this information should be made
available to the user of your product through a dialog box or something similar.
}
function lameVersion(const lameProc: tLameLibrary_proc; out version: BE_VERSION): bool;
{DP:METHOD
Writes a Xing Header in front of the MP3 file. Make sure that the MP3 file is
closed, and the the beConfig.format.LHV1.bWriteVBRHeader has been set to TRUE.
In addition, it is always safe to call beWriteVBRHeader after the encoding has
been finished, even when the beConfig.format.LHV1.bWriteVBRHeader is not set to TRUE.
}
function lameWriteVBRHeader(const lameProc: tLameLibrary_proc; const fileName: string): BE_ERR;
// NOT SUPPORTED:
// added for floating point audio -- DSPguru, jd
//__declspec(dllexport) BE_ERR beEncodeChunkFloatS16NI(HBE_STREAM hbeStream, DWORD nSamples, PFLOAT buffer_l, PFLOAT buffer_r, PBYTE pOutput, PDWORD pdwOutput);
//__declspec(dllexport) BE_ERR beFlushNoGap(HBE_STREAM hbeStream, PBYTE pOutput, PDWORD pdwOutput);
// -- DLL specific --
const
c_lameEncDLL = 'lame_enc.dll';
{DP:METHOD
Loads a Lame DLL.
Returns 0 if successuf, or Windows specific error code.
}
function lame_loadDLL(var lameProc: tLameLibrary_proc; const pathAndName: string = c_lameEncDLL): integer;
{DP:METHOD
Unloads Lame DLL.
Returns 0 if successuf, or Windows specific error code.
}
function lame_unloadDLL(var lameProc: tLameLibrary_proc): integer;
implementation
uses
unaUtils;
// ============= Blade ========================
// -- --
function blade_loadDLL(var bladeProc: tBladeLibrary_proc; const pathAndName: string): integer;
var
libFile: string;
begin
with bladeProc do begin
//
if (0 = r_be_module) then begin
r_be_module := 1; // not zero
//
libFile := trim(pathAndName);
if ('' = libFile) then
libFile := c_bladeEncDLL;
//
result := Windows.LoadLibrary(pChar(libFile));
if (0 = result) then begin
result := Windows.getLastError();
r_be_module := 0;
end
else begin
r_be_module := result;
//
@r_beInitStream := Windows.GetProcAddress(r_be_module, 'beInitStream');
@r_beEncodeChunk := Windows.GetProcAddress(r_be_module, 'beEncodeChunk');
@r_beDeinitStream := Windows.GetProcAddress(r_be_module, 'beDeinitStream');
@r_beCloseStream := Windows.GetProcAddress(r_be_module, 'beCloseStream');
@r_beVersion := Windows.GetProcAddress(r_be_module, 'beVersion');
//
r_be_moduleRefCount := 1; // also, makes it not zero
// (see below for mscand)
//
if (nil <> mscand(@bladeProc, sizeOf(bladeProc) shr 2, 0)) then begin
// something is missing, close the library
Windows.freeLibrary(r_be_module);
r_be_module := 0;
result := -1;
end
else
result := 0;
end;
end
else begin
if (0 < r_be_moduleRefCount) then
inc(r_be_moduleRefCount);
//
result := 0;
end;
end;
end;
//
function blade_unloadDLL(var bladeProc: tBladeLibrary_proc): integer;
begin
result := 0;
//
with bladeProc do begin
//
if (0 <> r_be_module) then begin
//
if (0 < r_be_moduleRefCount) then
dec(r_be_moduleRefCount);
//
if (1 > r_be_moduleRefCount) then begin
//
if (Windows.freeLibrary(r_be_module)) then
fillChar(bladeProc, sizeOf(bladeProc), #0)
else
result := Windows.getLastError();
end;
end;
end;
end;
// -- --
function checkBladeDllProc(const bladeProc: tBladeLibrary_proc): BE_ERR;
begin
if (0 = bladeProc.r_be_module) then
result := UNA_ENCODER_ERR_NO_DLL
else
result := BE_ERR_SUCCESSFUL;
end;
// -- --
function beInitStream(const bladeProc: tBladeLibrary_proc; config: PBE_CONFIG; out nSamples: DWORD; out minOutputBufSize: DWORD; out stream: HBE_STREAM): BE_ERR;
begin
result := checkBladeDllProc(bladeProc);
//
if (BE_ERR_SUCCESSFUL = result) then
result := bladeProc.r_beInitStream(config, nSamples, minOutputBufSize, stream);
end;
// -- --
function beEncodeChunk(const bladeProc: tBladeLibrary_proc; stream: HBE_STREAM; nSamples: DWORD; samplesBuf: pointer; outputBuf: pointer; out outputUsed: DWORD): BE_ERR;
begin
result := checkBladeDllProc(bladeProc);
//
if (BE_ERR_SUCCESSFUL = result) then
result := bladeProc.r_beEncodeChunk(stream, nSamples, samplesBuf, outputBuf, outputUsed);
end;
// -- --
function beDeinitStream(const bladeProc: tBladeLibrary_proc; stream: HBE_STREAM; outputBuf: pointer; out outputUsed: DWORD): BE_ERR;
begin
result := checkBladeDllProc(bladeProc);
//
if (BE_ERR_SUCCESSFUL = result) then
result := bladeProc.r_beDeinitStream(stream, outputBuf, outputUsed);
end;
// -- --
function beCloseStream(const bladeProc: tBladeLibrary_proc; stream: HBE_STREAM): BE_ERR;
begin
result := checkBladeDllProc(bladeProc);
//
if (BE_ERR_SUCCESSFUL = result) then
result := bladeProc.r_beCloseStream(stream);
end;
// -- --
function beVersion(const bladeProc: tBladeLibrary_proc; out version: BE_VERSION): bool;
begin
if (BE_ERR_SUCCESSFUL = checkBladeDllProc(bladeProc)) then begin
bladeProc.r_beVersion(version);
result := true;
end
else
result := false;
end;
// ============= Lame ========================
// -- --
function lame_loadDLL(var lameProc: tLameLibrary_proc; const pathAndName: string): integer;
var
libFile: string;
begin
with lameProc do begin
//
if (0 = r_lame_module) then begin
//
r_lame_module := 1;
//
libFile := trim(pathAndName);
if ('' = libFile) then
libFile := c_lameEncDLL;
//
result := Windows.loadLibrary(pChar(libFile));
if (0 = result) then begin
result := Windows.GetLastError();
r_lame_module := 0;
end
else begin
r_lame_module := result;
//
r_lameInitStream := Windows.GetProcAddress(r_lame_module, 'beInitStream');
r_lameEncodeChunk := Windows.GetProcAddress(r_lame_module, 'beEncodeChunk');
r_lameDeinitStream:= Windows.GetProcAddress(r_lame_module, 'beDeinitStream');
r_lameCloseStream := Windows.GetProcAddress(r_lame_module, 'beCloseStream');
r_lameVersion := Windows.GetProcAddress(r_lame_module, 'beVersion');
r_lameWriteVBRHeader := Windows.GetProcAddress(r_lame_module, 'beWriteVBRHeader');
//
r_lame_moduleRefCount := 1; // also, makes it not zero
// (see below for mscand)
//
if (nil <> mscand(@lameProc, sizeOf(lameProc) shr 2, 0)) then begin
// something is missing, close the library
Windows.freeLibrary(r_lame_module);
r_lame_module := 0;
result := -1;
end
else
result := 0;
end;
end
else begin
if (0 < r_lame_moduleRefCount) then
inc(r_lame_moduleRefCount);
//
result := 0;
end;
end;
end;
//
function lame_unloadDLL(var lameProc: tLameLibrary_proc): integer;
begin
result := 0;
//
with lameProc do begin
//
if (0 <> r_lame_module) then begin
//
if (0 < r_lame_moduleRefCount) then
dec(r_lame_moduleRefCount);
//
if (1 > r_lame_moduleRefCount) then begin
//
if (Windows.freeLibrary(r_lame_module)) then
fillChar(lameProc, sizeOf(lameProc), #0)
else
result := Windows.getLastError();
end;
end;
end;
end;
// -- --
function checkLameDllProc(const lameProc: tLameLibrary_proc): BE_ERR;
begin
if (0 = lameProc.r_lame_module) then
result := UNA_ENCODER_ERR_NO_DLL
else
result := BE_ERR_SUCCESSFUL;
end;
// -- --
function lameInitStream(const lameProc: tLameLibrary_proc; config: PBE_CONFIG_FORMATLAME; out nSamples: DWORD; out minOutputBufSize: DWORD; out stream: HBE_STREAM): BE_ERR;
begin
result := checkLameDllProc(lameProc);
//
if (BE_ERR_SUCCESSFUL = result) then
result := lameProc.r_lameInitStream(PBE_CONFIG(config), nSamples, minOutputBufSize, stream);
end;
// -- --
function lameEncodeChunk(const lameProc: tLameLibrary_proc; stream: HBE_STREAM; nSamples: DWORD; samplesBuf: pointer; outputBuf: pointer; out outputUsed: DWORD): BE_ERR;
begin
result := checkLameDllProc(lameProc);
//
if (BE_ERR_SUCCESSFUL = result) then
result := lameProc.r_lameEncodeChunk(stream, nSamples, samplesBuf, outputBuf, outputUsed);
end;
// -- --
function lameDeinitStream(const lameProc: tLameLibrary_proc; stream: HBE_STREAM; outputBuf: pointer; out outputUsed: DWORD): BE_ERR;
begin
result := checkLameDllProc(lameProc);
//
if (BE_ERR_SUCCESSFUL = result) then
result := lameProc.r_lameDeinitStream(stream, outputBuf, outputUsed);
end;
// -- --
function lameCloseStream(const lameProc: tLameLibrary_proc; stream: HBE_STREAM): BE_ERR;
begin
result := checkLameDllProc(lameProc);
//
if (BE_ERR_SUCCESSFUL = result) then
result := lameProc.r_lameCloseStream(stream);
end;
// -- --
function lameVersion(const lameProc: tLameLibrary_proc; out version: BE_VERSION): bool;
begin
if (BE_ERR_SUCCESSFUL = checkLameDllProc(lameProc)) then begin
lameProc.r_lameVersion(version);
result := true;
end
else
result := false;
end;
// -- --
function lameWriteVBRHeader(const lameProc: tLameLibrary_proc; const fileName: string): BE_ERR;
begin
result := checkLameDllProc(lameProc);
//
if (BE_ERR_SUCCESSFUL = result) then
result := lameProc.r_lameWriteVBRHeader(pChar(fileName));
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -