📄 unadspdlib.pas
字号:
r.a2 := (A + 1.0) + (A - 1.0) * cosw - alpha2sqrtA;
end;
DSPL_BIQ_HS: begin
//
alpha2sqrtA := 2.0 * pow(A, 0.5) * alpha;
r.b0 := A * ((A + 1.0) + (A - 1.0) * cosw + alpha2sqrtA);
r.b1 := -2.0 * A * ((A - 1.0) + (A + 1.0) * cosw);
r.b2 := A * ((A + 1.0) + (A - 1.0) * cosw - alpha2sqrtA);
r.a0 := (A + 1.0) - (A - 1.0) * cosw + alpha2sqrtA;
r.a1 := 2.0 * ((A - 1.0) - (A + 1.0) * cosw);
r.a2 := (A + 1.0) - (A - 1.0) * cosw - alpha2sqrtA;
end;
end; // case
//
if (norm) then begin
//
a0_1 := 1.0 / r.a0;
//
r.a0 := 1.0;
r.b0 := r.b0 * a0_1;
r.b1 := r.b1 * a0_1;
r.b2 := r.b2 * a0_1;
r.a1 := r.a1 * (-a0_1);
r.a2 := r.a2 * (-a0_1);
end;
//
except
r.a0 := 1.0;
r.b0 := 0.0;
r.b1 := 0.0;
r.a1 := 0.0;
r.a2 := 0.0;
end;
end;
{ unaDspDLibRoot }
// -- --
constructor unaDspDLibRoot.create();
begin
f_libResult := DSPL_SUCCESS; // "library" is always linked into code
//
inherited create();
end;
// -- --
function unaDspDLibRoot.dspl_create(object_id: dspl_id): dspl_handle;
begin
case (object_id) of
(DSPL_OID or DSPL_EQ2B):
result := dspl_handle(unaDspDL_EQ2B.create());
(DSPL_OID or DSPL_EQMB):
result := dspl_handle(unaDspDL_EQMB.create());
(DSPL_OID or DSPL_LD):
result := dspl_handle(unaDspDL_LD.create());
(DSPL_OID or DSPL_DYNPROC):
result := dspl_handle(unaDspDL_DynProc.create());
(DSPL_OID or DSPL_SPEECHPROC):
result := dspl_handle(unaDspDL_SpeechProc.create());
(DSPL_OID or DSPL_ND):
result := dspl_handle(unaDspDL_ND.create());
(DSPL_OID or DSPL_MBSP):
result := dspl_handle(unaDspDL_MBSP.create());
else
result := DSPL_INVALID_HANDLE;
end
end;
// -- --
function unaDspDLibRoot.dspl_destroy(handle: dspl_handle): dspl_result;
begin
freeAndNil(handle);
//
result := DSPL_SUCCESS;
end;
// -- --
function unaDspDLibRoot.dspl_getc(handle: dspl_handle; param: dspl_id): pdspl_chunk;
begin
assert(0 <> handle);
result := unaDspDProcessor(handle).getc(param);
end;
// -- --
function unaDspDLibRoot.dspl_getf(handle: dspl_handle; param: dspl_id): dspl_float;
begin
assert(0 <> handle);
result := unaDspDProcessor(handle).getf(param);
end;
// -- --
function unaDspDLibRoot.dspl_geti(handle: dspl_handle; param: dspl_id): dspl_int;
begin
assert(0 <> handle);
result := unaDspDProcessor(handle).geti(param);
end;
// -- --
function unaDspDLibRoot.dspl_getID(handle: dspl_handle): dspl_int;
begin
assert(0 <> handle);
result := unaDspDProcessor(handle).id;
end;
// -- --
function unaDspDLibRoot.dspl_issetc(handle: dspl_handle; param: dspl_id): dspl_result;
begin
assert(0 <> handle);
result := unaDspDProcessor(handle).issetc(param);
end;
// -- --
function unaDspDLibRoot.dspl_issetf(handle: dspl_handle; param: dspl_id): dspl_result;
begin
assert(0 <> handle);
result := unaDspDProcessor(handle).issetf(param);
end;
// -- --
function unaDspDLibRoot.dspl_isseti(handle: dspl_handle; param: dspl_id): dspl_result;
begin
assert(0 <> handle);
result := unaDspDProcessor(handle).isseti(param);
end;
// -- --
function unaDspDLibRoot.dspl_process(handle: dspl_handle; nSamples: dspl_int): dspl_result;
begin
assert(0 <> handle);
result := unaDspDProcessor(handle).process(nSamples);
end;
// -- --
function unaDspDLibRoot.dspl_setc(handle: dspl_handle; param_id: dspl_id; chunk: pdspl_float; length: dspl_int): dspl_result;
begin
assert(0 <> handle);
result := unaDspDProcessor(handle).setc(param_id, chunk, length)
end;
// -- --
function unaDspDLibRoot.dspl_setf(handle: dspl_handle; param_id: dspl_id; value: dspl_float): dspl_result;
begin
assert(0 <> handle);
result := unaDspDProcessor(handle).setf(param_id, value)
end;
// -- --
function unaDspDLibRoot.dspl_seti(handle: dspl_handle; param_id: dspl_id; value: dspl_int): dspl_result;
begin
assert(0 <> handle);
result := unaDspDProcessor(handle).seti(param_id, value)
end;
// -- --
function unaDspDLibRoot.dspl_version(): pAnsiChar;
begin
result := '1.D.02';
end;
{ unaDspDProcessor }
// -- --
procedure unaDspDProcessor.AfterConstruction();
begin
f_modified := true;
//
inherited;
end;
// -- --
procedure unaDspDProcessor.BeforeDestruction;
begin
inherited;
//
freeAndNil(f_params);
end;
// -- --
constructor unaDspDProcessor.create(id: dspl_id);
begin
f_id := id;
//
f_params := unaDspDLibParams.create(self);
//
inherited create();
end;
// -- --
function unaDspDProcessor.getc(param_id: dspl_id): pdspl_chunk;
var
p: punaDspDLibParam;
begin
p := f_params.itemById(param_id or DSPL_P_TYPE_C);
if (nil <> p) then
result := @p.r2_chunk
else
result := nil;
end;
// -- --
function unaDspDProcessor.getf(param_id: dspl_id): dspl_float;
var
p: punaDspDLibParam;
begin
p := f_params.itemById(param_id or DSPL_P_TYPE_F);
if (nil <> p) then
result := p.r1_float
else
result := 0;
end;
// -- --
function unaDspDProcessor.geti(param_id: dspl_id): dspl_int;
var
p: punaDspDLibParam;
begin
p := f_params.itemById(param_id or DSPL_P_TYPE_I);
if (nil <> p) then
result := p.r0_int
else
result := 0;
end;
// -- --
function unaDspDProcessor.idIsINOUT(id: dspl_id): bool;
begin
result :=
(DSPL_P_TYPE_C = ($0F000000 and id))
and
(
( DSPL_PID or DSPL_P_IN = (id and $F0F00) )
or
( DSPL_PID or DSPL_P_OUT = (id and $F0F00) )
);
end;
// -- --
function unaDspDProcessor.issetc(param_id: dspl_id): dspl_result;
begin
result := (nil <> f_params.itemById(param_id or DSPL_P_TYPE_C));
end;
// -- --
function unaDspDProcessor.issetf(param_id: dspl_id): dspl_result;
begin
result := (nil <> f_params.itemById(param_id or DSPL_P_TYPE_F));
end;
// -- --
function unaDspDProcessor.isseti(param_id: dspl_id): dspl_result;
begin
result := (nil <> f_params.itemById(param_id or DSPL_P_TYPE_I));
end;
// -- --
function unaDspDProcessor.setc(param_id: dspl_id; chunk: pdspl_float; length: dspl_int): dspl_result;
var
p: punaDspDLibParam;
sz: int;
begin
p := f_params.itemById(param_id or DSPL_P_TYPE_C);
if (nil = p) then begin
//
p := malloc(sizeOf(p^), true, 0);
p.r_id := param_id or DSPL_P_TYPE_C;
//
f_params.add(p);
end;
//
if (idIsINOUT(p.r_id)) then begin
//
// IN/OUT buffers are always assigned by value, and no new memory is allocated
//
p.r2_chunk.r_fp := chunk;
p.r2_chunk.r_len := length;
end
else begin
// other buffers are always assigned by copy, so new memory is allocated
//
sz := length * sizeOf(p.r2_chunk.r_fp^);
if (length <= p.r2_chunk.r_len) then begin
//
// because new chunk may be assigned using "old" chunk pointer,
// in case of buffer shrinking we need to copy old values first.
// If "new" chunk pointer was passed, we copy the values anyway
if ((0 < sz) and (nil <> chunk)) then
move(chunk^, p.r2_chunk.r_fp^, sz);
end;
//
// Existing data in the block is not affected by the reallocation
mrealloc(p.r2_chunk.r_fp, sz);
//
if ((0 < sz) and (nil <> chunk) and (length > p.r2_chunk.r_len)) then begin
//
// since "old" chunk pointer cannot (should not) be used to address a
// larger buffer we may safely copy the entire data here
move(chunk^, p.r2_chunk.r_fp^, sz);
end;
//
p.r2_chunk.r_len := length;
end;
//
result := DSPL_SUCCESS;
f_modified := true;
end;
// -- --
function unaDspDProcessor.setf(param_id: dspl_id; value: dspl_float): dspl_result;
var
p: punaDspDLibParam;
begin
p := f_params.itemById(param_id or DSPL_P_TYPE_F);
if (nil = p) then begin
//
p := malloc(sizeOf(p^));
p.r_id := param_id or DSPL_P_TYPE_F;
//
f_params.add(p);
end;
//
p.r1_float := value;
//
result := DSPL_SUCCESS;
f_modified := true;
end;
// -- --
function unaDspDProcessor.seti(param_id: dspl_id; value: dspl_int): dspl_result;
var
p: punaDspDLibParam;
begin
p := f_params.itemById(param_id or DSPL_P_TYPE_I);
if (nil = p) then begin
//
p := malloc(sizeOf(p^));
p.r_id := param_id or DSPL_P_TYPE_I;
//
f_params.add(p);
end;
//
p.r0_int := value;
//
result := DSPL_SUCCESS;
f_modified := true;
end;
{ unaDspDL_EQ2B }
// -- --
procedure unaDspDL_EQ2B.AfterConstruction();
begin
inherited;
//
// seti(DSPL_PID or DSPL_P_NFRQ or DSPL_EQ2B_BOTH, DSPL_DEFAULT_SAMPLING_FRQ);
//
seti(DSPL_PID or DSPL_P_TYPE or DSPL_EQ2B_BAND1, DSPL_EQ2B_OFF);
seti(DSPL_PID or DSPL_P_TYPE or DSPL_EQ2B_BAND2, DSPL_EQ2B_OFF);
//
setf(DSPL_PID or DSPL_P_FRQ or DSPL_EQ2B_BAND1, 500.0 / DSPL_DEFAULT_SAMPLE_FRQ);
setf(DSPL_PID or DSPL_P_FRQ or DSPL_EQ2B_BAND2, 2000.0 / DSPL_DEFAULT_SAMPLE_FRQ);
setc(DSPL_PID or DSPL_P_FRQ or DSPL_EQ2B_BAND1, nil, 0);
setc(DSPL_PID or DSPL_P_FRQ or DSPL_EQ2B_BAND2, nil, 0);
setf(DSPL_PID or DSPL_P_GAIN or DSPL_EQ2B_BAND1, db2v(0.0));
setf(DSPL_PID or DSPL_P_GAIN or DSPL_EQ2B_BAND2, db2v(0.0));
setc(DSPL_PID or DSPL_P_GAIN or DSPL_EQ2B_BAND1, nil, 0);
setc(DSPL_PID or DSPL_P_GAIN or DSPL_EQ2B_BAND2, nil, 0);
setf(DSPL_PID or DSPL_P_Q or DSPL_EQ2B_BAND1, 1.0);
setf(DSPL_PID or DSPL_P_Q or DSPL_EQ2B_BAND2, 1.0);
setc(DSPL_PID or DSPL_P_Q or DSPL_EQ2B_BAND1, nil, 0);
setc(DSPL_PID or DSPL_P_Q or DSPL_EQ2B_BAND2, nil, 0);
setc(DSPL_PID or DSPL_P_IN or DSPL_EQ2B_BOTH, nil, 0);
setc(DSPL_PID or DSPL_P_OUT or DSPL_EQ2B_BOTH, nil, 0);
end;
// -- --
procedure unaDspDL_EQ2B.BeforeDestruction();
begin
inherited;
//
biq_f1_buff_size := 0;
biq_f2_buff_size := 0;
//
mrealloc(biq_f1);
mrealloc(biq_f2);
end;
// -- --
function unaDspDL_EQ2B.process(nSamples: dspl_int): dspl_result;
var
t: int;
in0: pFloatArray;
out0: pFloatArray;
in0p: int;
out0p: int;
in_len: int;
out_len: int;
f1biq_step,
f2biq_step: dspl_int;
f1on: bool;
f2on: bool;
f1: pdspl_biq_values;
f2: pdspl_biq_values;
//
f1in: dspl_double;
f1out: dspl_double;
f2out: dspl_double;
begin
in0 := pFloatArray(getc(DSPL_PID or DSPL_P_IN or DSPL_EQ2B_BOTH).r_fp);
out0 := pFloatArray(getc(DSPL_PID or DSPL_P_OUT or DSPL_EQ2B_BOTH).r_fp);
//
in_len := getc(DSPL_PID or DSPL_P_IN or DSPL_EQ2B_BOTH).r_len;
out_len := getc(DSPL_PID or DSPL_P_OUT or DSPL_EQ2B_BOTH).r_len;
//
if ((nil = in0) or (nil = out0) or (1 > out_len) or (in_len <> out_len)) then
result := DSPL_FAILURE
else begin
//
if (out_len < nSamples) then
nSamples := out_len;
//
f1biq_step :=0;
f2biq_step :=0;
//
f1on := (DSPL_EQ2B_OFF <> geti(DSPL_PID or DSPL_P_TYPE or DSPL_EQ2B_BAND1));
f2on := (DSPL_EQ2B_OFF <> geti(DSPL_PID or DSPL_P_TYPE or DSPL_EQ2B_BAND2));
//
f1 := nil;
f2 := nil;
//
if (f1on) then begin
//
biq_f1 := prepare_biq(DSPL_EQ2B_BAND1, nSamples, f1biq_step, biq_f1, biq_f1_buff_size);
f1 := biq_f1;
end;
//
if (f2on) then begin
//
biq_f2 := prepare_biq(DSPL_EQ2B_BAND2, nSamples, f2biq_step, biq_f2, biq_f2_buff_size);
f2 := biq_f2;
end;
//
in0p := 0;
out0p := 0;
//
for t := 0 to nSamples - 1 do begin
//
f1in := in0[in0p];
if (f1on) then
f1out := (f1.b0 * f1in +
f1.b1 * f1in1 +
f1.b2 * f1in2 +
f1.a1 * f1out1 +
f1.a2 * f1out2
)
else
f1out := f1in;
//
f1in2 := f1in1;
f1in1 := f1in;
f1out2 := f1out1;
f1out1 := f1out;
//
if (f2on) then
f2out := (f2.b0 * f1out +
f2.b1 * f2in1 +
f2.b2 * f2in2 +
f2.a1 * f2out1 +
f2.a2 * f2out2
)
else
f2out := f1out;
//
f2in2 := f2in1;
f2in1 := f1out;
f2out2 := f2out1;
f2out1 := f2out;
//
out0[out0p] := f2out;
//
inc(in0p);
inc(out0p);
//
inc(f1, f1biq_step);
inc(f2, f2biq_step);
end;
//
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -