📄 audioacm.pas
字号:
case SamplesPerSec of
ss8000Hz: nSamplesPerSec := 8000;
ss11025Hz: nSamplesPerSec := 11025;
ss22050Hz: nSamplesPerSec := 22050;
ss44100Hz: nSamplesPerSec := 44100;
ss48000Hz: nSamplesPerSec := 48000;
end;
{ case BitsPerSample of
bs8Bit: wBitsPerSample := 8;
bs16Bit: wBitsPerSample := 16;
end;
nBlockAlign := MulDiv(nChannels, wBitsPerSample, 8);
nAvgBytesPerSec := nSamplesPerSec * nBlockAlign;
cbSize := 0; }
end;
end;
// Initializes a standard MP3 wave format header (shorcut form). The size of
// memory referenced by the pWaveFormat parameter must not be less than the
// size of TWaveFormatEx record.
procedure SetMP3AudioFormatS(const pWaveFormat: PWaveFormatEx; PCMFormat: TPCMFormat);
begin
case PCMFormat of
Mono8Bit8000Hz:
SetMP3AudioFormat(pWaveFormat, cMono, ss8000Hz, bs8Bit);
Mono8Bit11025Hz:
SetMP3AudioFormat(pWaveFormat, cMono, ss11025Hz, bs8Bit);
Mono8Bit22050Hz:
SetMP3AudioFormat(pWaveFormat, cMono, ss22050Hz, bs8Bit);
Mono8Bit44100Hz:
SetMP3AudioFormat(pWaveFormat, cMono, ss44100Hz, bs8Bit);
Mono8Bit48000Hz:
SetMP3AudioFormat(pWaveFormat, cMono, ss48000Hz, bs8Bit);
Mono16Bit8000Hz:
SetMP3AudioFormat(pWaveFormat, cMono, ss8000Hz, bs16Bit);
Mono16Bit11025Hz:
SetMP3AudioFormat(pWaveFormat, cMono, ss11025Hz, bs16Bit);
Mono16Bit22050Hz:
SetMP3AudioFormat(pWaveFormat, cMono, ss22050Hz, bs16Bit);
Mono16Bit44100Hz:
SetMP3AudioFormat(pWaveFormat, cMono, ss44100Hz, bs16Bit);
Mono16Bit48000Hz:
SetMP3AudioFormat(pWaveFormat, cMono, ss48000Hz, bs16Bit);
Stereo8bit8000Hz:
SetMP3AudioFormat(pWaveFormat, cStereo, ss8000Hz, bs8Bit);
Stereo8bit11025Hz:
SetMP3AudioFormat(pWaveFormat, cStereo, ss11025Hz, bs8Bit);
Stereo8bit22050Hz:
SetMP3AudioFormat(pWaveFormat, cStereo, ss22050Hz, bs8Bit);
Stereo8bit44100Hz:
SetMP3AudioFormat(pWaveFormat, cStereo, ss44100Hz, bs8Bit);
Stereo8bit48000Hz:
SetMP3AudioFormat(pWaveFormat, cStereo, ss48000Hz, bs8Bit);
Stereo16bit8000Hz:
SetMP3AudioFormat(pWaveFormat, cStereo, ss8000Hz, bs16Bit);
Stereo16bit11025Hz:
SetMP3AudioFormat(pWaveFormat, cStereo, ss11025Hz, bs16Bit);
Stereo16bit22050Hz:
SetMP3AudioFormat(pWaveFormat, cStereo, ss22050Hz, bs16Bit);
Stereo16bit44100Hz:
SetMP3AudioFormat(pWaveFormat, cStereo, ss44100Hz, bs16Bit);
Stereo16bit48000Hz:
SetMP3AudioFormat(pWaveFormat, cStereo, ss48000Hz, bs16Bit);
end;
end;
// Returns the standard MP3 format specifier of a wave format.
function GetMP3AudioFormat(const pWaveFormat: PWaveFormatEx): TPCMFormat;
begin
Result := nonePCM;
with pWaveFormat^ do
if wFormatTag = WAVE_FORMAT_MPEGLAYER3 then
begin
if (nChannels = 1) and (nSamplesPerSec = 8000) and (wBitsPerSample = 8) then
Result := Mono8Bit8000Hz
else if (nChannels = 2) and (nSamplesPerSec = 8000) and (wBitsPerSample = 8) then
Result := Stereo8Bit8000Hz
else if (nChannels = 1) and (nSamplesPerSec = 8000) and (wBitsPerSample = 16) then
Result := Mono16bit8000Hz
else if (nChannels = 2) and (nSamplesPerSec = 8000) and (wBitsPerSample = 16) then
Result := Stereo16Bit8000Hz
else if (nChannels = 1) and (nSamplesPerSec = 11025) and (wBitsPerSample = 8) then
Result := Mono8Bit11025Hz
else if (nChannels = 2) and (nSamplesPerSec = 11025) and (wBitsPerSample = 8) then
Result := Stereo8Bit11025Hz
else if (nChannels = 1) and (nSamplesPerSec = 11025) and (wBitsPerSample = 16) then
Result := Mono16bit11025Hz
else if (nChannels = 2) and (nSamplesPerSec = 11025) and (wBitsPerSample = 16) then
Result := Stereo16Bit11025Hz
else if (nChannels = 1) and (nSamplesPerSec = 22050) and (wBitsPerSample = 8) then
Result := Mono8Bit22050Hz
else if (nChannels = 2) and (nSamplesPerSec = 22050) and (wBitsPerSample = 8) then
Result := Stereo8Bit22050Hz
else if (nChannels = 1) and (nSamplesPerSec = 22050) and (wBitsPerSample = 16) then
Result := Mono16bit22050Hz
else if (nChannels = 2) and (nSamplesPerSec = 22050) and (wBitsPerSample = 16) then
Result := Stereo16Bit22050Hz
else if (nChannels = 1) and (nSamplesPerSec = 44100) and (wBitsPerSample = 8) then
Result := Mono8Bit44100Hz
else if (nChannels = 2) and (nSamplesPerSec = 44100) and (wBitsPerSample = 8) then
Result := Stereo8Bit44100Hz
else if (nChannels = 1) and (nSamplesPerSec = 44100) and (wBitsPerSample = 16) then
Result := Mono16bit44100Hz
else if (nChannels = 2) and (nSamplesPerSec = 44100) and (wBitsPerSample = 16) then
Result := Stereo16Bit44100Hz
else if (nChannels = 1) and (nSamplesPerSec = 48000) and (wBitsPerSample = 8) then
Result := Mono8Bit48000Hz
else if (nChannels = 2) and (nSamplesPerSec = 48000) and (wBitsPerSample = 8) then
Result := Stereo8Bit48000Hz
else if (nChannels = 1) and (nSamplesPerSec = 48000) and (wBitsPerSample = 16) then
Result := Mono16bit48000Hz
else if (nChannels = 2) and (nSamplesPerSec = 48000) and (wBitsPerSample = 16) then
Result := Stereo16Bit48000Hz
end;
end;
// Initializes a standard PCM wave format header. The size of memory referenced
// by the pWaveFormat parameter must not be less than the size of TWaveFormatEx
// record.
procedure SetPCMAudioFormat(const pWaveFormat: PWaveFormatEx;
Channels: TPCMChannel; SamplesPerSec: TPCMSamplesPerSec;
BitsPerSample: TPCMBitsPerSample);
begin
with pWaveFormat^ do
begin
wFormatTag := WAVE_FORMAT_PCM;
case Channels of
cMono: nChannels := 1;
cStereo: nChannels := 2;
end;
case SamplesPerSec of
ss8000Hz: nSamplesPerSec := 8000;
ss11025Hz: nSamplesPerSec := 11025;
ss22050Hz: nSamplesPerSec := 22050;
ss44100Hz: nSamplesPerSec := 44100;
ss48000Hz: nSamplesPerSec := 48000;
end;
case BitsPerSample of
bs8Bit: wBitsPerSample := 8;
bs16Bit: wBitsPerSample := 16;
end;
nBlockAlign := MulDiv(nChannels, wBitsPerSample, 8);
nAvgBytesPerSec := nSamplesPerSec * nBlockAlign;
cbSize := 0;
end;
end;
// Initializes a standard PCM wave format header (shorcut form). The size of
// memory referenced by the pWaveFormat parameter must not be less than the
// size of TWaveFormatEx record.
procedure SetPCMAudioFormatS(const pWaveFormat: PWaveFormatEx; PCMFormat: TPCMFormat);
begin
case PCMFormat of
Mono8Bit8000Hz:
SetPCMAudioFormat(pWaveFormat, cMono, ss8000Hz, bs8Bit);
Mono8Bit11025Hz:
SetPCMAudioFormat(pWaveFormat, cMono, ss11025Hz, bs8Bit);
Mono8Bit22050Hz:
SetPCMAudioFormat(pWaveFormat, cMono, ss22050Hz, bs8Bit);
Mono8Bit44100Hz:
SetPCMAudioFormat(pWaveFormat, cMono, ss44100Hz, bs8Bit);
Mono8Bit48000Hz:
SetPCMAudioFormat(pWaveFormat, cMono, ss48000Hz, bs8Bit);
Mono16Bit8000Hz:
SetPCMAudioFormat(pWaveFormat, cMono, ss8000Hz, bs16Bit);
Mono16Bit11025Hz:
SetPCMAudioFormat(pWaveFormat, cMono, ss11025Hz, bs16Bit);
Mono16Bit22050Hz:
SetPCMAudioFormat(pWaveFormat, cMono, ss22050Hz, bs16Bit);
Mono16Bit44100Hz:
SetPCMAudioFormat(pWaveFormat, cMono, ss44100Hz, bs16Bit);
Mono16Bit48000Hz:
SetPCMAudioFormat(pWaveFormat, cMono, ss48000Hz, bs16Bit);
Stereo8bit8000Hz:
SetPCMAudioFormat(pWaveFormat, cStereo, ss8000Hz, bs8Bit);
Stereo8bit11025Hz:
SetPCMAudioFormat(pWaveFormat, cStereo, ss11025Hz, bs8Bit);
Stereo8bit22050Hz:
SetPCMAudioFormat(pWaveFormat, cStereo, ss22050Hz, bs8Bit);
Stereo8bit44100Hz:
SetPCMAudioFormat(pWaveFormat, cStereo, ss44100Hz, bs8Bit);
Stereo8bit48000Hz:
SetPCMAudioFormat(pWaveFormat, cStereo, ss48000Hz, bs8Bit);
Stereo16bit8000Hz:
SetPCMAudioFormat(pWaveFormat, cStereo, ss8000Hz, bs16Bit);
Stereo16bit11025Hz:
SetPCMAudioFormat(pWaveFormat, cStereo, ss11025Hz, bs16Bit);
Stereo16bit22050Hz:
SetPCMAudioFormat(pWaveFormat, cStereo, ss22050Hz, bs16Bit);
Stereo16bit44100Hz:
SetPCMAudioFormat(pWaveFormat, cStereo, ss44100Hz, bs16Bit);
Stereo16bit48000Hz:
SetPCMAudioFormat(pWaveFormat, cStereo, ss48000Hz, bs16Bit);
end;
end;
// Returns the standard PCM format specifier of a wave format.
function GetPCMAudioFormat(const pWaveFormat: PWaveFormatEx): TPCMFormat;
begin
Result := nonePCM;
with pWaveFormat^ do
if wFormatTag = WAVE_FORMAT_PCM then
begin
if (nChannels = 1) and (nSamplesPerSec = 8000) and (wBitsPerSample = 8) then
Result := Mono8Bit8000Hz
else if (nChannels = 2) and (nSamplesPerSec = 8000) and (wBitsPerSample = 8) then
Result := Stereo8Bit8000Hz
else if (nChannels = 1) and (nSamplesPerSec = 8000) and (wBitsPerSample = 16) then
Result := Mono16bit8000Hz
else if (nChannels = 2) and (nSamplesPerSec = 8000) and (wBitsPerSample = 16) then
Result := Stereo16Bit8000Hz
else if (nChannels = 1) and (nSamplesPerSec = 11025) and (wBitsPerSample = 8) then
Result := Mono8Bit11025Hz
else if (nChannels = 2) and (nSamplesPerSec = 11025) and (wBitsPerSample = 8) then
Result := Stereo8Bit11025Hz
else if (nChannels = 1) and (nSamplesPerSec = 11025) and (wBitsPerSample = 16) then
Result := Mono16bit11025Hz
else if (nChannels = 2) and (nSamplesPerSec = 11025) and (wBitsPerSample = 16) then
Result := Stereo16Bit11025Hz
else if (nChannels = 1) and (nSamplesPerSec = 22050) and (wBitsPerSample = 8) then
Result := Mono8Bit22050Hz
else if (nChannels = 2) and (nSamplesPerSec = 22050) and (wBitsPerSample = 8) then
Result := Stereo8Bit22050Hz
else if (nChannels = 1) and (nSamplesPerSec = 22050) and (wBitsPerSample = 16) then
Result := Mono16bit22050Hz
else if (nChannels = 2) and (nSamplesPerSec = 22050) and (wBitsPerSample = 16) then
Result := Stereo16Bit22050Hz
else if (nChannels = 1) and (nSamplesPerSec = 44100) and (wBitsPerSample = 8) then
Result := Mono8Bit44100Hz
else if (nChannels = 2) and (nSamplesPerSec = 44100) and (wBitsPerSample = 8) then
Result := Stereo8Bit44100Hz
else if (nChannels = 1) and (nSamplesPerSec = 44100) and (wBitsPerSample = 16) then
Result := Mono16bit44100Hz
else if (nChannels = 2) and (nSamplesPerSec = 44100) and (wBitsPerSample = 16) then
Result := Stereo16Bit44100Hz
else if (nChannels = 1) and (nSamplesPerSec = 48000) and (wBitsPerSample = 8) then
Result := Mono8Bit48000Hz
else if (nChannels = 2) and (nSamplesPerSec = 48000) and (wBitsPerSample = 8) then
Result := Stereo8Bit48000Hz
else if (nChannels = 1) and (nSamplesPerSec = 48000) and (wBitsPerSample = 16) then
Result := Mono16bit48000Hz
else if (nChannels = 2) and (nSamplesPerSec = 48000) and (wBitsPerSample = 16) then
Result := Stereo16Bit48000Hz
end;
end;
// Converts milliseconds to string
function MS2Str(Milliseconds: DWORD; Fmt: TMS2StrFormat): String;
var
HSecs, Secs, Mins, Hours: DWORD;
begin
HSecs := Milliseconds div 10;
Secs := HSecs div 100;
Mins := Secs div 60;
Hours := Mins div 60;
if Fmt in [msAh, msA] then
begin
if Hours <> 0 then
if Fmt = msAh then Fmt := msHMSh else Fmt := msHMS
else if Mins <> 0 then
if Fmt = msAh then Fmt := msMSh else Fmt := msMS
else
if Fmt = msAh then Fmt := msSh else Fmt := msS
end;
case Fmt of
msHMSh:
Result := Format('%u%s%2.2u%s%2.2u%s%2.2u',
[Hours, TimeSeparator, Mins mod 60, TimeSeparator, Secs mod 60, DecimalSeparator, HSecs mod 100]);
msHMS:
Result := Format('%u%s%2.2u%s%2.2u',
[Hours, TimeSeparator, Mins mod 60, TimeSeparator, Secs mod 60]);
msMSh:
Result := Format('%u%s%2.2u%s%2.2u',
[Mins, TimeSeparator, Secs mod 60, DecimalSeparator, HSecs mod 100]);
msMS:
Result := Format('%u%s%2.2u',
[Mins, TimeSeparator, Secs mod 60]);
msSh:
Result := Format('%u%s%2.2u',
[Secs, DecimalSeparator, HSecs mod 100]);
msS:
Result := Format('%u', [Secs]);
else
Result := IntToStr(Milliseconds);
end;
end;
// Waits for the scnchronize object while lets the caller thread processes
// its messages.
function WaitForSyncObject(SyncObject: THandle; Timeout: DWORD): DWORD;
const
EVENTMASK = QS_PAINT or QS_TIMER or QS_SENDMESSAGE or QS_POSTMESSAGE;
var
Msg: TMsg;
StartTime: DWORD;
EllapsedTime: DWORD;
Handle: THandle;
begin
Handle := SyncObject;
if (SyncObject = GetCurrentThread) or (SyncObject = GetCurrentProcess) then
DuplicateHandle(GetCurrentProcess, SyncObject, GetCurrentProcess, @Handle, SYNCHRONIZE, False, 0);
try
repeat
StartTime := GetTickCount;
Result := MsgWaitForMultipleObjects(1, Handle, False, Timeout, EVENTMASK);
if Result = WAIT_OBJECT_0 + 1 then
begin
while PeekMessage(Msg, 0, 0, 0, PM_REMOVE) do
begin
if ((Msg.message < WM_KEYFIRST) or (Msg.message > WM_KEYLAST)) and
((Msg.message < WM_MOUSEFIRST) or (Msg.message > WM_MOUSELAST)) then
begin
TranslateMessage(Msg);
DispatchMessage(Msg);
if Msg.message = WM_QUIT then Exit;
end;
end;
if Timeout <> INFINITE then
begin
EllapsedTime := GetTickCount - StartTime;
if EllapsedTime < Timeout then
Dec(Timeout, EllapsedTime)
else
Timeout := 0;
end;
end;
until Result <> WAIT_OBJECT_0 + 1;
finally
if SyncObject <> Handle then
CloseHandle(Handle);
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -