📄 mmwaveio.pas
字号:
{*************************************************************************}
function wioBytesToTime64(pwfx: PWaveFormatEx; dwBytes: int64): int64;
begin
Result := MulDiv64(dwBytes, 1000, pwfx^.nAvgBytesPerSec);
end;
{*************************************************************************}
{* *}
{* DESCRIPTION: *}
{* convert a sample offset into a byte offset, with correct alignment*}
{* to nBlockAlign. *}
{* *}
{* dwBytes = (dwSamples / nSamplesPerSec) * nBytesPerSec *}
{* *}
{*************************************************************************}
function wioSamplesToBytes64(pwfx: PWaveFormatEx; dwSamples: int64): int64;
{$IFNDEF DELPHI4}
var
Temp: int64;
{$ENDIF}
begin
Result := muldiv64(dwSamples,
pwfx^.nAvgBytesPerSec,
pwfx^.nSamplesPerSec);
{ now align the byte offset to nBlockAlign }
{$IFDEF ROUND_UP}
{$IFDEF DELPHI4}
Result := ((Result + pwfx^.nBlockAlign-1) div pwfx^.nBlockAlign) * pwfx^.nBlockAlign;
{$ELSE}
Temp := Result + pwfx^.nBlockAlign-1;
Result := ((Temp/pwfx^.nBlockAlign)-ModR(Temp,pwfx^.nBlockAlign))* pwfx^.nBlockAlign;
{$ENDIF}
{$ELSE}
{$IFDEF DELPHI4}
Result := (Result div pwfx^.nBlockAlign) * pwfx^.nBlockAlign;
{$ELSE}
Result := ((Result / pwfx^.nBlockAlign)-ModR(Result,pwfx^.nBlockAlign)) * pwfx^.nBlockAlign;
{$ENDIF}
{$ENDIF}
end;
{*************************************************************************}
{* *}
{* DESCRIPTION: *}
{* convert a sample offset into a time offset in milliseconds. *}
{* *}
{* dwTime = (dwSamples / nSamplesPerSec) * 1000 *}
{* *}
{*************************************************************************}
function wioSamplesToTime64(pwfx: PWaveFormatEx; dwSamples: int64): int64;
begin
Result := muldiv64(dwSamples, 1000, pwfx^.nSamplesPerSec);
end;
{*************************************************************************}
{* *}
{* DESCRIPTION: *}
{* convert a time index in milliseconds to a sample offset. *}
{* *}
{* dwSamples = (dwTime / 1000) * nSamplesPerSec *}
{* *}
{*************************************************************************}
function wioTimeToSamples64(pwfx: PWaveFormatEx; dwTime: int64): int64;
begin
Result := muldiv64(dwTime, pwfx^.nSamplesPerSec, 1000);
end;
{*************************************************************************}
{* *}
{* DESCRIPTION: *}
{* convert a time index in milliseconds to a byte offset, with *)
(* correct alignment to nBlockAlign. . *)
{* *}
{* dwBytes = ((dwTime / 1000) * nBytesPerSec) *}
{* *}
{*************************************************************************}
function wioTimeToBytes64(pwfx: PWaveFormatEx; dwTime: int64): int64;
{$IFNDEF DELPHI4}
var
Temp: int64;
{$ENDIf}
begin
Result := muldiv64(dwTime, pwfx^.nAvgBytesPerSec, 1000);
{ now align the byte offset to nBlockAlign }
{$IFDEF ROUND_UP}
{$IFDEF DELPHI4}
Result := ((Result + pwfx^.nBlockAlign-1) div pwfx^.nBlockAlign) * pwfx^.nBlockAlign;
{$ELSE}
Temp := Result + pwfx^.nBlockAlign-1;
Result := ((Temp/pwfx^.nBlockAlign)-ModR(Temp,pwfx^.nBlockAlign)) * pwfx^.nBlockAlign;
{$ENDIF}
{$ELSE}
{$IFDEF DELPHI4}
Result := (Result div pwfx^.nBlockAlign) * pwfx^.nBlockAlign;
{$ELSE}
Result := ((Result/pwfx^.nBlockAlign)-ModR(Result,pwfx^.nBlockAlign)) * pwfx^.nBlockAlign;
{$ENDIF}
{$ENDIF}
end;
{*************************************************************************}
{* *}
{* DESCRIPTION: *}
{* calculate the bytes per sample from the actual settings. *)
{* *}
{*************************************************************************}
function wioBytesPerSampleEx(lpwio: PWaveIOCB): integer;
begin
Result := wioSamplesToBytesEx(lpwio, 1);
end;
{*************************************************************************}
{* *}
{* DESCRIPTION: *}
{* convert a byte offset into a sample offset. *}
{* *}
{* dwSamples = (dwBytes / nAvgBytesPerSec) * nSamplesPerSec *}
{* *}
{*************************************************************************}
function wioBytesToSamplesEx(lpwio: PWaveIOCB; dwBytes: DWORD): DWORD;
begin
if (lpwio^.fAvgBytesPerSec <> 0) then
begin
Result := Round((dwBytes*lpwio^.wfx.nSamplesPerSec)/lpwio^.fAvgBytesPerSec);
end
else Result := wioBytesToSamples(@lpwio^.wfx,dwBytes);
end;
{*************************************************************************}
{* *}
{* DESCRIPTION: *}
{* convert a byte offset into a time offset in milliseconds. *}
{* *}
(* dwTime = (dwBytes / nAvgBytesPerSec) * 1000 *)
{* *}
{*************************************************************************}
function wioBytesToTimeEx(lpwio: PWaveIOCB; dwBytes: DWORD): DWORD;
begin
if (lpwio^.fAvgBytesPerSec <> 0) then
begin
Result := Round((dwBytes*1000)/lpwio^.fAvgBytesPerSec);
end
else Result := wioBytesToTime(@lpwio^.wfx,dwBytes);
end;
{*************************************************************************}
{* *}
{* DESCRIPTION: *}
{* convert a sample offset into a byte offset, with correct alignment*}
{* to nBlockAlign. *}
{* *}
{* dwBytes = (dwSamples / nSamplesPerSec) * nBytesPerSec *}
{* *}
{*************************************************************************}
function wioSamplesToBytesEx(lpwio: PWaveIOCB; dwSamples: DWORD): DWORD;
begin
if (lpwio^.fAvgBytesPerSec <> 0) then
begin
Result := Round((dwSamples*lpwio^.fAvgBytesPerSec)/lpwio^.wfx.nSamplesPerSec);
{ now align the byte offset to nBlockAlign }
{$IFDEF ROUND_UP}
Result := ((Result + lpwio^.wfx.nBlockAlign-1) div lpwio^.wfx.nBlockAlign) * lpwio^.wfx.nBlockAlign;
{$ELSE}
Result := (Result div lpwio^.wfx.nBlockAlign) * lpwio^.wfx.nBlockAlign;
{$ENDIF}
end
else Result := wioSamplesToBytes(@lpwio^.wfx,dwSamples);
end;
{*************************************************************************}
{* *}
{* DESCRIPTION: *}
{* convert a sample offset into a time offset in milliseconds. *}
{* *}
{* dwTime = (dwSamples / nSamplesPerSec) * 1000 *}
{* *}
{*************************************************************************}
function wioSamplesToTimeEx(lpwio: PWaveIOCB; dwSamples: DWORD): DWORD;
begin
if (lpwio^.fAvgBytesPerSec <> 0) then
begin
Result := Round((dwSamples*1000)/lpwio^.wfx.nSamplesPerSec);
end
else Result := wioSamplesToTime(@lpwio^.wfx,dwSamples);
end;
{*************************************************************************}
{* *}
{* DESCRIPTION: *}
{* convert a time index in milliseconds to a sample offset. *}
{* *}
{* dwSamples = (dwTime / 1000) * nSamplesPerSec *}
{* *}
{*************************************************************************}
function wioTimeToSamplesEx(lpwio: PWaveIOCB; dwTime: DWORD): DWORD;
begin
if (lpwio^.fAvgBytesPerSec <> 0) then
begin
Result := Round((dwTime*lpwio^.wfx.nSamplesPerSec)/1000);
end
else Result := wioTimeToSamples(@lpwio^.wfx,dwTime);
end;
{*************************************************************************}
{* *}
{* DESCRIPTION: *}
{* convert a time index in milliseconds to a byte offset, with *)
(* correct alignment to nBlockAlign. . *)
{* *}
{* dwBytes = ((dwTime / 1000) * nAvgBytesPerSec) *}
{* *}
{*************************************************************************}
function wioTimeToBytesEx(lpwio: PWaveIOCB; dwTime: DWORD): DWORD;
begin
if (lpwio^.fAvgBytesPerSec <> 0) then
begin
Result := Round((dwTime*lpwio^.fAvgBytesPerSec)/1000);
{ now align the byte offset to nBlockAlign }
{$IFDEF ROUND_UP}
Result := ((Result + lpwio^.wfx.nBlockAlign-1) div lpwio^.wfx.nBlockAlign) * lpwio^.wfx.nBlockAlign;
{$ELSE}
Result := (Result div lpwio^.wfx.nBlockAlign) * lpwio^.wfx.nBlockAlign;
{$ENDIF}
end
else Result := wioTimeToBytes(@lpwio^.wfx, dwTime);
end;
{*************************************************************************}
{* *}
{* DESCRIPTION: *}
{* returns the size of the wave format structure pwfx *}
{* *}
{*************************************************************************}
function wioSizeOfWaveFormat(pwfx: PWaveFormatEx): integer;
begin
if (pwfx <> nil) then
begin
if pwfx^.wFormatTag = WAVE_FORMAT_PCM then
Result := sizeOf(TWaveFormatEx)
else
Result := sizeOf(TWaveFormatEx)+pwfx^.cbSize
end
else Result := 0;
end;
{*************************************************************************}
{* *}
{* DESCRIPTION: *}
{* duplicates the wave format structure pwfx *}
{* *}
{*************************************************************************}
function wioCopyWaveFormat(pwfx: PWaveFormatEx): PWaveFormatEx;
var
Size: integer;
begin
Result := nil;
if (pwfx <> nil) then
begin
Size := wioSizeOfWaveFormat(pwfx);
if (Size > 0) then
begin
{ get the memory }
Result := GlobalAllocMem(Size);
{ copy the WaveFormatEx struc }
Move(pwfx^, Result^, Size);
if (Result^.wFormatTag = 1) then
Result^.cbSize := 0;
end;
end;
end;
{*************************************************************************}
type
TStrFormat = packed record
szformat: String;
wFormat : Word;
end;
const
Formats: array[0..38] of TStrFormat = (
(szformat:'Unknown' ; wFormat: WAVE_FORMAT_UNKNOWN),
(szformat:'PCM' ; wFormat: WAVE_FORMAT_PCM),
(szformat:'PCM 32' ; wFormat: WAVE_FORMAT_PCM32),
(szformat:'Microsoft ADPCM' ; wFormat: WAVE_FORMAT_ADPCM),
(szformat:'Mediavision''s ADPCM' ; wFormat: WAVE_FORMAT_MEDIAVISION_ADPCM),
(szformat:'IBM CVSD' ; wFormat: WAVE_FORMAT_IBM_CVSD),
(szformat:'CCITT A-Law' ; wFormat: WAVE_FORMAT_ALAW),
(szformat:'CCITT mu-Law' ; wFormat: WAVE_FORMAT_MULAW),
(szformat:'OKI ADPCM' ; wFormat: WAVE_FORMAT_OKI_ADPCM),
(szformat:'IMA ADPCM' ; wFormat: WAVE_FORMAT_IMA_ADPCM),
(szformat:'DVI ADPCM' ; wFormat: WAVE_FORMAT_DVI_ADPCM),
(szformat:'Mediaspace''s ADPCM' ; wFormat: WAVE_FORMAT_MEDIASPACE_ADPCM),
(szformat:'Sierra''s ADPCM' ; wFormat: WAVE_FORMAT_SIERRA_ADPCM),
(szformat:'CCITT G.723 ADPCM' ; wFormat: WAVE_FORMAT_G723_ADPCM),
(szformat:'Digisound DIGISTD' ; wFormat: WAVE_FORMAT_DIGISTD),
(szformat:'Digisound DIGIFIX' ; wFormat: WAVE_FORMAT_DIGIFIX),
(szformat:'Dialogic OKI ADPCM' ; wFormat: WAVE_FORMAT_DIALOGIC_OKI_ADPCM),
(szformat:'Yamaha ADPCM' ; wFormat: WAVE_FORMAT_YAMAHA_ADPCM),
(szformat:'Sonarc' ; wFormat: WAVE_FORMAT_SONARC),
(szformat:'DSP Group''s Truespeech' ; wFormat: WAVE_FORMAT_DSPGROUP_TRUESPEECH),
(szformat:'Echo SC1' ; wFormat: WAVE_FORMAT_ECHOSC1),
(szformat:'Audiofile AF36' ; wFormat: WAVE_FORMAT_AUDIOFILE_AF36),
(szformat:'Audio Processing Technology'; wFormat: WAVE_FORMAT_APTX),
(szformat:'Audiofile AF10' ; wFormat: WAVE_FORMAT_AUDIOFILE_AF10),
(szformat:'Dolby AC2' ; wFormat: WAVE_FORMAT_DOLBY_AC2),
(szformat:'Dolby AC2' ; wFormat: WAVE_FORMAT_DOLBY_AC2_REVA),
(szformat:'GSM 6.10' ; wFormat: WAVE_FORMAT_GSM610),
(szformat:'Antex ADPCME' ; wFormat: WAVE_FORMAT_ANTEX_ADPCME),
(szformat:'CS IMA ADPCM' ; wFormat: WAVE_FORMAT_CS_IMAADPCM),
(szformat:'CCITT G.721 ADPCM' ; wFormat: WAVE_FORMAT_G721_ADPCM),
(szformat:'MPEG 1' ; wFormat: WAVE_FORMAT_MPEG),
(szformat:'MPEG Layer-3' ; wFormat: WAVE_FORMAT_MPEG_LAYER3),
(szformat:'Creative''s ADPCM' ; wFormat: WAVE_FORMAT_CREATIVE_ADPCM),
(szformat:'Olivetti''s ADPCM' ; wFormat: WAVE_FORMAT_OLIADPCM),
(szFormat:'CDI-C' ; wFormat: WAVE_FORMAT_CDIC),
(szFormat:'CDI-B' ; wFormat: WAVE_FORMAT_CDIB),
(szFormat:'Antex-DVI-OKI ADPCME' ; wFormat: WAVE_FORMAT_ADPCME),
(szformat:'*DEVELOPMENT ONLY TAG*' ; wFormat: WAVE_FORMAT_DEVELOPMENT),
(szformat:'' ; wFormat: 0));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -