📄 mmfxgen.pas
字号:
FWaveForm := aValue;
FillWaveTable(TabLen);
end;
{$IFDEF WIN32}
{$IFDEF TRIAL}
{$DEFINE _HACK2}
{$I MMHACK.INC}
{$ENDIF}
{$ENDIF}
end;
{-- TMMGenerator --------------------------------------------------------}
procedure TMMGenerator.SetModulation(aValue: TMMModulation);
begin
if (aValue <> FModulation) then
begin
FModulation := aValue;
end;
{$IFDEF WIN32}
{$IFDEF TRIAL}
{$DEFINE _HACK3}
{$I MMHACK.INC}
{$ENDIF}
{$ENDIF}
end;
{-- TMMGenerator --------------------------------------------------------}
procedure TMMGenerator.SetFrequency(aValue: Double);
begin
if (aValue <> FFrequency) then
begin
FFrequency := MinMaxR(aValue,0.01,100000);
end;
end;
{-- TMMGenerator --------------------------------------------------------}
procedure TMMGenerator.SetAmplitudes(index: integer; aValue: TMMVolumeRange);
begin
case Index of
0: if (aValue = FAmplitude) then exit else FAmplitude := aValue;
1: if (aValue = FDryAmplitude) then exit else FDryAmplitude := aValue;
end;
end;
{-- TMMGenerator --------------------------------------------------------}
procedure TMMGenerator.GenerateData(Buffer: PChar; NumBytes: Cardinal);
type
TGetSample = function: Smallint;
var
i,ReIndex: integer;
pS: PSmallint;
pB: PByte;
Step: Double;
function GetSample: Smallint;
{$IFNDEF WIN32}
var
pt: PSmallint;
{$ENDIF}
begin
{$IFDEF WIN32}
Result := MulDiv32(FTable^[Round(FOffset)],FAmplitude,VOLUMEBASE);
{$ELSE}
pt := Pointer(FTable);
incHuge(pt, Round(FOffset)*sizeOf(pt^));
Result := MulDiv32(pt^,FAmplitude,VOLUMEBASE);
{$ENDIF}
FOffset := ModR(FOffset+Step,TabLen-1);
end;
begin
ReIndex := Ord(FChannel)-1;
Step := FFrequency*TabLen/FSampleRate;
if (FBits = b8bit) then
begin
pB := PByte(Buffer);
if (FMode = mMono) then
begin
for i := 0 to NumBytes-1 do
begin
pB^ := GetSample+128;
inc(pB);
end;
end
else if (FChannel = chBoth) then
begin
NumBytes := (NumBytes and not 1) shr 1;
for i := 0 to NumBytes-1 do
begin
pB^ := GetSample+128;
PByte(PChar(pB)+1)^ := pB^;
inc(pB,2);
end;
end
else
begin
inc(pB,ReIndex);
NumBytes := (NumBytes and not 1) shr 1;
for i := 0 to NumBytes-1 do
begin
pB^ := GetSample+128;
inc(pB,2);
end;
end;
end
else
begin
pS := PSmallInt(Buffer);
if (FMode = mMono) then
begin
NumBytes := (NumBytes and not 1) shr 1;
for i := 0 to NumBytes-1 do
begin
pS^ := GetSample;
inc(pS);
end;
end
else if (FChannel = chBoth) then
begin
NumBytes := (NumBytes and not 3) shr 2;
for i := 0 to NumBytes-1 do
begin
pS^ := GetSample;
PSmallInt(PChar(pS)+2)^ := pS^;
inc(pS,2);
end;
end
else
begin
inc(pS, ReIndex);
NumBytes := (NumBytes and not 3) shr 2;
for i := 0 to NumBytes-1 do
begin
pS^ := GetSample;
inc(pS,2);
end;
end;
end;
end;
{-- TMMGenerator --------------------------------------------------------}
procedure TMMGenerator.ModulateDataAM(Buffer: PChar; NumBytes: Cardinal);
type
TGetSample = function: Smallint;
var
i,ReIndex: integer;
s: Smallint;
Dry,Wet: Longint;
pS: PSmallint;
pB: PByte;
Step: Double;
function GetSample: Smallint;
{$IFNDEF WIN32}
var
pt: PSmallint;
{$ENDIF}
begin
{$IFDEF WIN32}
Result := MulDiv32(FTable^[Round(FOffset)],FAmplitude,VOLUMEBASE);
{$ELSE}
pt := Pointer(FTable);
incHuge(pt, Round(FOffset)*sizeOf(pt^));
Result := MulDiv32(pt^,FAmplitude,VOLUMEBASE);
{$ENDIF}
FOffset := ModR(FOffset+Step,TabLen-1);
end;
begin
{ Amplitude Modulation: y(t) = Ac * sin(Wct) * Am * sin(Wmt) }
ReIndex := Ord(FChannel)-1;
Step := FFrequency*TabLen/FSampleRate;
if (FBits = b8bit) then
begin
pB := PByte(Buffer);
if (FMode = mMono) then
begin
for i := 0 to NumBytes-1 do
begin
Dry := MulDiv32(pB^-128,FDryAmplitude,VOLUMEBASE);
Wet := (Smallint(pB^-128)*GetSample) div 128;
pB^ := pcmSampleClip8(Dry+Wet)+128;
inc(pB);
end;
end
else if (FChannel = chBoth) then
begin
NumBytes := (NumBytes and not 1) shr 1;
for i := 0 to NumBytes-1 do
begin
s := GetSample;
Dry := MulDiv32(pB^-128,FDryAmplitude,VOLUMEBASE);
Wet := (Smallint(pB^-128)*s) div 128;
pB^ := pcmSampleClip8(Dry+Wet)+128;
inc(pB);
Dry := MulDiv32(pB^-128,FDryAmplitude,VOLUMEBASE);
Wet := ((pB^-128)*s) div 128;
pB^ := pcmSampleClip8(Dry+Wet)+128;
inc(pB);
end;
end
else
begin
inc(pB,ReIndex);
NumBytes := (NumBytes and not 1) shr 1;
for i := 0 to NumBytes-1 do
begin
Dry := MulDiv32(pB^-128,FDryAmplitude,VOLUMEBASE);
Wet := (Smallint(pB^-128)*GetSample) div 128;
pB^ := pcmSampleClip8(Dry+Wet)+128;
inc(pB,2);
end;
end;
end
else
begin
pS := PSmallInt(Buffer);
if (FMode = mMono) then
begin
NumBytes := (NumBytes and not 1) shr 1;
for i := 0 to NumBytes-1 do
begin
Dry := MulDiv32(pS^,FDryAmplitude,VOLUMEBASE);
Wet := (Longint(pS^)*GetSample) div 32768;
pS^ := pcmSampleClip16(Dry+Wet);
inc(pS);
end;
end
else if (FChannel = chBoth) then
begin
NumBytes := (NumBytes and not 3) shr 2;
for i := 0 to NumBytes-1 do
begin
s := GetSample;
Dry := MulDiv32(pS^,FDryAmplitude,VOLUMEBASE);
Wet := (Longint(pS^)*s) div 32768;
pS^ := pcmSampleClip16(Dry+Wet);
inc(pS);
Dry := MulDiv32(pS^,FDryAmplitude,VOLUMEBASE);
Wet := (Longint(pS^)*s) div 32768;
pS^ := pcmSampleClip16(Dry+Wet);
inc(pS);
end;
end
else
begin
inc(pS, ReIndex);
NumBytes := (NumBytes and not 3) shr 2;
for i := 0 to NumBytes-1 do
begin
Dry := MulDiv32(pS^,FDryAmplitude,VOLUMEBASE);
Wet := (Longint(pS^)*GetSample) div 32768;
pS^ := pcmSampleClip16(Dry+Wet);
inc(pS,2);
end;
end;
end;
end;
{-- TMMGenerator --------------------------------------------------------}
procedure TMMGenerator.ModulateDataFM(Buffer: PChar; NumBytes: Cardinal);
type
TGetSample = function: Smallint;
var
i: integer;
//ReIndex: integer;
// s: Smallint;
// Dry,Wet: Longint;
pS: PSmallint;
// pB: PByte;
// Step: Double;
function GetSample(s: Float): Longint;
begin
Result := MulDiv32(FTable^[Round(FOffset)],FAmplitude,VOLUMEBASE);
FOffset := ModR(FOffset+FFrequency*TabLen/FSampleRate*(1+s),TabLen-1);
end;
begin
{ Frequency Modulation: y(t) = Ac * sin(Wct* Am * sin(Wmt)) }
// ReIndex := Ord(FChannel)-1;
// Step := FFrequency*TabLen/FSampleRate;
pS := PSmallInt(Buffer);
NumBytes := (NumBytes and not 1) shr 1;
for i := 0 to NumBytes-1 do
begin
{ Frequency Modulation: y(t) = Ac * sin(Wct* Am * sin(Wmt)) }
pS^ := GetSample(pS^/32768);
inc(pS);
end;
(* if (FBits = b8bit) then
begin
pB := PByte(Buffer);
if (FMode = mMono) then
begin
for i := 0 to NumBytes-1 do
begin
Dry := MulDiv32(pB^-128,FDryAmplitude,VOLUMEBASE);
Wet := ((pB^-128)*GetSample) div 128;
pB^ := pcmSampleClip8(Dry+Wet)+128;
inc(pB);
end;
end
else if (FChannel = chBoth) then
begin
NumBytes := (NumBytes and not 1) shr 1;
for i := 0 to NumBytes-1 do
begin
s := GetSample;
Dry := MulDiv32(pB^-128,FDryAmplitude,VOLUMEBASE);
Wet := ((pB^-128)*s) div 128;
pB^ := pcmSampleClip8(Dry+Wet)+128;
inc(pB);
Dry := MulDiv32(pB^-128,FDryAmplitude,VOLUMEBASE);
Wet := ((pB^-128)*s) div 128;
pB^ := pcmSampleClip8(Dry+Wet)+128;
inc(pB);
end;
end
else
begin
inc(pB,ReIndex);
NumBytes := (NumBytes and not 1) shr 1;
for i := 0 to NumBytes-1 do
begin
Dry := MulDiv32(pB^-128,FDryAmplitude,VOLUMEBASE);
Wet := ((pB^-128)*GetSample) div 128;
pB^ := pcmSampleClip8(Dry+Wet)+128;
inc(pB,2);
end;
end;
end
else
begin
pS := PSmallInt(Buffer);
if (FMode = mMono) then
begin
NumBytes := (NumBytes and not 1) shr 1;
for i := 0 to NumBytes-1 do
begin
{ Frequency Modulation: y(t) = Ac * sin(Wct* Am * sin(Wmt)) }
Dry := MulDiv32(pS^,FDryAmplitude,VOLUMEBASE);
Wet := (pS^*GetSample) div 32768;
pS^ := pcmSampleClip16(Dry+Wet);
inc(pS);
end;
end
else if (FChannel = chBoth) then
begin
NumBytes := (NumBytes and not 3) shr 2;
for i := 0 to NumBytes-1 do
begin
{ Frequency Modulation: y(t) = Ac * sin(Wct* Am * sin(Wmt)) }
s := GetSample;
Dry := MulDiv32(pS^,FDryAmplitude,VOLUMEBASE);
Wet := (pS^*s) div 32768;
pS^ := pcmSampleClip16(Dry+Wet);
inc(pS);
Dry := MulDiv32(pS^,FDryAmplitude,VOLUMEBASE);
Wet := (pS^*s) div 32768;
pS^ := pcmSampleClip16(Dry+Wet);
inc(pS);
end;
end
else
begin
inc(pS, ReIndex);
NumBytes := (NumBytes and not 3) shr 2;
for i := 0 to NumBytes-1 do
begin
Dry := MulDiv32(pS^,FDryAmplitude,VOLUMEBASE);
Wet := (pS^*GetSample) div 32768;
pS^ := pcmSampleClip16(Dry+Wet);
inc(pS,2);
end;
end;
end; *)
end;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -