我正在尝试定义TWaveFormatExtensible类型,但是我不确定是否正确声明了Samples联合。这是头文件(Windows SDK 10.0.17763.0)中的原始声明:
typedef struct {
WAVEFORMATEX Format;
union {
WORD wValidBitsPerSample; /* bits of precision */
WORD wSamplesPerBlock; /* valid if wBitsPerSample==0 */
WORD wReserved; /* If neither applies, set to zero. */
} Samples;
DWORD dwChannelMask; /* which channels are */
/* present in stream */
GUID SubFormat;
}
Run Code Online (Sandbox Code Playgroud)
这就是我尝试过的:
type
TWAVEFORMATEX = record
wFormatTag: Word;
nChannels: LongWord;
nSamplesPerSec: Word;
nAvgBytesPerSec: LongWord;
nBlockAlign: Word;
wBitsPerSample: Word;
cbSize: Word;
end;
TWaveFormatExtensible = record
Format: TWAVEFORMATEX; …Run Code Online (Sandbox Code Playgroud) 我从来都不擅长数学,所以我需要帮助如何将线性值转换为dB。
首先,我向您展示如何从-24dB计算线性值。
var dB, linearLevel: integer;
begin
dB := -24;
linearLevel := Round( 1/exp( 2.30258509299 * (abs(dB)/20) ) *32767);
end;
Run Code Online (Sandbox Code Playgroud)
1/exp( 2.30258509299 * (abs(-24)/20) ) ;归一化值在哪里。
为了转换为样本值,我使用 1/exp(...)*32767
我的问题在这里:转换回来
有人告诉我要使用公式20*log10(linearLevel)。因此,我尝试创建它,但结果是18 dB,而不是24(或-24)dB。
linearValue := 2067; // the result of the formula above
db := round( exp( 20*2.30258509299*(linearLevel / 32767) ) );
Run Code Online (Sandbox Code Playgroud)
如何计算dB?
我写了这个简单的课:
unit Test;
interface
uses
SysUtils;
type
TGram = class
private
instanceCreated: boolean;
constructor Create;
public
procedure test;
end;
implementation
constructor TGram.Create;
begin
instanceCreated := true;
end;
procedure TGram.test;
begin
if not instanceCreated
then raise Exception.Create('The object has not been created.');
end;
end.
Run Code Online (Sandbox Code Playgroud)
当我调用方法测试时,我得到一个例外,那就是它没有被创建。
var test: TGram;
begin
test := TGram.create;
test.test;
end
Run Code Online (Sandbox Code Playgroud)
在构造函数中,instanceCreated设置为true(我相信是),但是当我稍后尝试访问它时,它不存在。为什么?如何纠正呢?
我正在尝试创建并运行新的 Delphi 应用程序。但是在下面的项目文件中,当我尝试 CreateForm 时出现此错误:调试器异常:项目...引发异常类 EReadError 并带有消息无效属性值。过程停止。
program Project1;
uses
Forms,
OCR in 'OCR.pas' {Form1};
{$R *.res}
begin
Application.Initialize;
Application.Title := 'OCR';
Application.CreateForm(TForm1, OCR1);
Application.Run;
end.
Run Code Online (Sandbox Code Playgroud)
单元:
unit OCR;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;
type
TForm1 = class(TForm)
private
public
procedure FormCreate(Sender: TObject);
end;
var
OCR1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
var list: TStringList;
begin
list := TStringList.create;
list.loadFromFile('OCR.txt');
end;
end.
Run Code Online (Sandbox Code Playgroud)
DFM 文件:
object Form1: TForm1
Left = 210
Top = 181 …Run Code Online (Sandbox Code Playgroud) 我需要将值分配给线性,但是当我检查它时,结果是错误的。表达式1/exp( 2.30258509299 * (abs(dB)/20) )结果为0,063095734448(是正确值),但线性为-3,6854775808e + 4863,n为1,805186914e-307。
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
procedure OnCreate(Sender: TObject);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.OnCreate;
var dB: integer;
linear: extended;
n: Double;
begin
dB := -24;
linear := 1/exp( 2.30258509299 * (abs(dB)/20) );
n := 0.063095734448;
showmessage(inttostr(db));
end;
end.
Run Code Online (Sandbox Code Playgroud)
我在做什么错了,如何获得正确的价值?
注意:为了评估表达式,我使用了调试器的“评估/修改”命令。