下面的代碼使用 DrawGrid() 繪制對數網格。看起來垂直線沒問題。當我使用函式 SetPositionHzValue() 時,結果位置似乎沒問題(它使用與 DrawGrid() 相同的邏輯并且似乎與網格匹配)。但是如何將這個線性使用顯示寬度的 0 - 1.0 歸一化值轉換為實際的 Hz 值?為什么函式 GetPositionsHzValue() 錯誤?
更復雜的是,顯示幕有一個起始頻率(在這種情況下為 20 Hz)和一個結束頻率(在這種情況下為 44100 Hz)。
procedure TAudioBezierCurves.DrawGrid(Bitmap32: TBitmap32);
var
GridPosition: Integer;
GridPositionF: Double;
i: Integer;
Base: Double;
LogOffsetValue: Double;
LogMaxValue: Double;
begin
GridPosition := 0;
Base := 1;
if GridFrequencyMin = 0 then begin
LogOffsetValue := 0;
end else begin
LogOffsetValue := Log10(GridFrequencyMin);
end;
LogMaxValue := Log10(GridFrequencyMax) - LogOffsetValue;
repeat
for i := 2 to 10 do begin
if Base * i < GridFrequencyMin then begin
Continue;
end;
//* This gives the % value relative to the total scale
GridPositionF := (Log10(Base * i) - LogOffsetValue) / LogMaxValue;
GridPositionF := GridPositionF * Bitmap32.Width;
GridPosition := Trunc(GridPositionF);
Bitmap32.VertLineS(GridPosition, 0, Bitmap32.Height - 1, GridColor);
end;
Base := Base * 10;
until GridPosition > Bitmap32.Width;
end;
procedure TAudioBezierCurve.SetPositionHzValue(AValue: Double);
var
LogOffsetValue: Double;
LogMaxValue: Double;
begin
if AValue = 0 then begin
Self.Position := 0;
end else begin
if Parent.GridFrequencyMin = 0 then begin
LogOffsetValue := 0;
end else begin
LogOffsetValue := Log10(Parent.GridFrequencyMin);
end;
LogMaxValue := Log10(Parent.GridFrequencyMax) - LogOffsetValue;
//* This gives the % value relative to the total scale
AValue := (Log10(AValue) - LogOffsetValue) / LogMaxValue;
Self.Position := AValue;
end;
end;
function TAudioBezierCurve.GetPositionsHzValue: Double;
var
AValue: Double;
begin
AValue := Self.Position;
AValue := Power(AValue, 2);
Result := AValue * (Parent.GridFrequencyMax);
Result := Result - (AValue * Parent.GridFrequencyMin) Parent.GridFrequencyMin;
end;
編輯:好的,現在幾乎可以了。所以看起來正確的功能是:
AValue := Power(AValue, 10);
但仍然不完美。將顯示范圍更改為最小。0 到 44100,為簡單起見,設定為上限值 44100 是可以的,函式 GetPositionsHzValue() 報告 41100。但是呼叫將位置值設定為 20,GetPositionsHzValue() 報告為 0。嘗試減少位置一切都很好,直到44085,但 44084 值報告為 44085,并且此差異隨著值的減小而增加。從較低的值開始,它是 0 到 39,40 個結果為 1。
uj5u.com熱心網友回復:
在函式 GetPositionsHzValue 中,行“AValue := Power(AValue, 2);” “AValue”的價值從何而來?
也許你應該像在“SetPositionHzValue(AValue: Double);”中那樣做一些事情。AValue 應該是一個引數,而不是一個區域變數。
uj5u.com熱心網友回復:
找到了解決辦法,應該是:
function TAudioBezierCurve.GetPositionsHzValue: Double;
var
AValue: Double;
begin
AValue := Self.Position;
AValue := AValue * Log10(Parent.GridFrequencyMax) (Log10(Parent.GridFrequencyMin) * (1 - AValue)); //* Results "min." at 0
Result := Power(10, AValue);
end;
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/522343.html
標籤:德尔福
