?? mmwave.pas
字號:
if (pi = nil) then
raise EMMWaveError.CreateFmt(LoadResStr(IDS_WFCHUNKNOTFOUND),[fcc]);
if (pi^.lpText <> Nil) then
{ Modified text }
lpstr := pi^.lpText
else if (pi^.dwINFOOffset <> 0) then
{ default text }
lpstr := (lpInfo^.lpChunk+pI^.dwINFOOffset)
else
{ no text }
lpstr := Nil;
if (lpstr <> Nil) then Result := StrPas(lpStr);
end;
end;
{-- TMMWave --------------------------------------------------------------}
procedure TMMWave.SetInfoChunk(fcc, Text: String);
var
pi: PInfoData;
aBuf: array[0..4] of Char;
aStr: PChar;
begin
if (FPWAVEIOCB <> Nil) then
with FPWaveIOCB^ do
begin
{ first search the Chunk to modify }
pi := RiffFindPIINFO(lpInfo, mmioStringToFOURCC(StrPCopy(aBuf,fcc),0));
if (pi = nil) then
raise EMMWaveError.CreateFmt(LoadResStr(IDS_WFCHUNKNOTFOUND),[fcc]);
{ the new text MUST allocated with GlobalAlloc }
aStr := GlobalAllocMem(System.Length(Text)+1);
{ now set the text to the chunk }
{$IFDEF WIN32}
RiffModifyINFO(lpInfo, pi, CHUNK_MODIFIED, 0, StrCopy(aStr,PChar(Text)));
{$ELSE}
RiffModifyINFO(lpInfo, pi, CHUNK_MODIFIED, 0, StrPCopy(aStr,Text));
{$ENDIF}
end;
end;
{-- TMMWave --------------------------------------------------------------}
procedure TMMWave.SetDispChunk(Text: String; aBitmap: TBitmap);
var
pd : PDISP;
lpDIB : PDIB;
lpText: PChar;
begin
if (FPWAVEIOCB <> Nil) then
with FPWaveIOCB^ do
begin
lpDIB := nil;
if (aBitmap <> nil) then
begin
pd := lpDisp^.pHead;
while pd <> nil do
begin
if (pd^.cfid = CF_DIB) then break;
pd := pd^.pNext;
end;
if (pd <> nil) then
begin
RiffModifyDISP(lpDisp, pd, CHUNK_MODIFIED, PChar(lpDIB));
end
else
begin
pd := RiffCreateDISP(CHUNK_MODIFIED, CF_DIB, nil, PChar(lpDIB));
RiffInsertDISP(lpDisp, pd);
end;
end;
if (Text <> '') then
begin
pd := lpDisp^.pHead;
while pd <> nil do
begin
if (pd^.cfid = CF_TEXT) then break;
pd := pd^.pNext;
end;
lpText := GlobalAllocMem(System.Length(Text)+1);
StrPCopy(lpText, Text);
if (pd <> nil) then
begin
RiffModifyDISP(lpDisp, pd, CHUNK_MODIFIED, lpText);
end
else if (lpText^ <> #0) then
begin
pd := RiffCreateDISP(CHUNK_MODIFIED, CF_TEXT, nil, lpText);
RiffInsertDISP(lpDisp,pd);
end;
end;
end;
end;
{-- TMMWave --------------------------------------------------------------}
procedure TMMWave.SetFileMustExist(aValue: Boolean);
begin
if (aValue <> FFileMustExist) and (FMemoryWave = nil) then
begin
FFileMustExist := aValue;
end;
end;
{-- TMMWave --------------------------------------------------------------}
procedure TMMWave.SetBits(aValue: Word);
begin;
{ Dummy }
end;
{-- TMMWave --------------------------------------------------------------}
function TMMWave.GetBits: Word;
begin
Result := 0;
if (PWaveFormat <> Nil) then
begin
Result := PWaveFormat^.wBitsPerSample;
end;
end;
{-- TMMWave --------------------------------------------------------------}
procedure TMMWave.SetMode(aValue: TMMMode);
begin;
{ Dummy }
end;
{-- TMMWave --------------------------------------------------------------}
function TMMWave.GetMode: TMMMode;
begin
Result := mMono;
if (PWaveFormat <> Nil) then
begin
if PWaveFormat^.nChannels = 2 then Result := mStereo;
end;
{$IFDEF WIN32}
{$IFDEF TRIAL}
{$DEFINE _HACK2}
{$I MMHACK.INC}
{$ENDIF}
{$ENDIF}
end;
{-- TMMWave --------------------------------------------------------------}
procedure TMMWave.SetFormatTag(aValue: Word);
begin;
{ Dummy }
end;
{-- TMMWave --------------------------------------------------------------}
function TMMWave.GetFormatTag: Word;
begin
Result := 0;
if (PWaveFormat <> Nil) then
begin
Result := PWaveFormat^.wFormatTag;
end;
end;
{-- TMMWave --------------------------------------------------------------}
procedure TMMWave.SetFormatString(aValue: String);
begin;
{ Dummy }
end;
{-- TMMWave --------------------------------------------------------------}
function TMMWave.GetFormatString: String;
begin
Result := LoadResStr(IDS_WAVEUNKNOWN);
if (PWaveFormat <> Nil) then
begin
wioGetFormatName(PWaveFormat, Result);
end;
end;
{-- TMMWave --------------------------------------------------------------}
procedure TMMWave.SetDummy(aValue: Longint);
begin;
end;
{-- TMMWave --------------------------------------------------------------}
function TMMWave.GetSampleRate: Longint;
begin
Result := 11025;
if (PWaveFormat <> Nil) then
begin
Result := PWaveFormat^.nSamplesPerSec;
end;
end;
{-- TMMWave --------------------------------------------------------------}
function TMMWave.GetFileSize: LongInt;
begin
Result := 0;
if (FPWAVEIOCB <> Nil) then
begin
Result := FPWAVEIOCB^.dwFileSize;
end;
end;
{-- TMMWave --------------------------------------------------------------}
function TMMWave.GetDataSize: LongInt;
begin
Result := 0;
if (FPWAVEIOCB <> Nil) then
begin
Result := SamplesToTimeFormat(FPWAVEIOCB^.dwDataSamples);
end;
end;
{-- TMMWave --------------------------------------------------------------}
function TMMWave.GetDataOffset: LongInt;
begin
if (FPWAVEIOCB <> Nil) then
Result := FPWAVEIOCB^.dwDataOffset
else
Result := 0;
end;
{-- TMMWave --------------------------------------------------------------}
procedure TMMWave.SetFileName(aValue: TFileName);
var
Stream: TFileStream;
aBuf : PChar;
lpwio : PWAVEIOCB;
begin
aValue := ExpandUNCFileName(aValue);
aBuf := StrAlloc(System.Length(aValue)+1);
try
StrPCopy(aBuf, aValue);
if (FMemoryWave <> nil) then
begin
if (aValue <> '') then
try
Stream := TFileStream.Create(aValue, fmOpenRead or fmShareDenyNone);
try
LoadFromStream(Stream);
finally
Stream.Free;
end;
except
on EMMWaveError do
begin
if wioFileExists(aBuf) and not wioIsWaveFile(FileName, RIFF_FILE) then
raise EMMWaveError.Create(LoadResStr(IDS_WFINVALIDFILE))
else
raise EMMWaveError.Create(LoadResStr(IDS_WFREADERROR))
end
else raise;
end;
end
else
begin
if (aValue <> FFileName) or (MMUtils.GetFileSize(aValue) <> FileSize) then
begin
if (aValue = '') then
begin
FreeWave;
end
else
begin
if wioFileExists(aBuf) and
(wioReadFileInfo(lpwio, aBuf,mmioFOURCC('W', 'A', 'V', 'E'),RIFF_FILE) = 0) then
begin
ClearWave;
FPWaveIOCB := lpwio;
FStartPos := lpwio^.dwFirstSample;
FEndPos := lpwio^.dwLastSample;
FPosition := lpwio^.dwPosition;
FBytesLeft := lpwio^.dwBytesLeft;
FFileName := aValue;
InitRegionList;
Changed;
end
else
begin
if not wioFileExists(aBuf) and not FFileMustExist then
begin
ClearWave;
FFileName := aValue;
Changed;
end
else if wioFileExists(aBuf) and not wioIsWaveFile(FileName, RIFF_FILE) then
raise EMMWaveError.Create(LoadResStr(IDS_WFINVALIDFILE))
else
raise EMMWaveError.Create(LoadResStr(IDS_WFREADERROR))
end;
end;
end;
end;
finally
StrDispose(aBuf);
end;
{$IFDEF WIN32}
{$IFDEF TRIAL}
{$DEFINE _HACK2}
{$I MMHACK.INC}
{$ENDIF}
{$ENDIF}
end;
{-- TMMWave --------------------------------------------------------------}
procedure TMMWave.LoadFromFile(const Filename: TFileName);
begin
SetFileName(FileName);
end;
{-- TMMWave --------------------------------------------------------------}
procedure TMMWave.ImportFromRaw(const FileName: TFileName; BitLength,
Channels, SampleRate: Cardinal);
Label ERROR_IMPORT;
Var
FHandle: THandle;
aResult: Boolean;
Cancel: Boolean;
DestFile: PChar;
lpwioDst: PWAVEIOCB;
wfx: TWaveFormatEx;
BufSize: Longint;
pBuf: PChar;
CurByte, NumBytes, NumRead: DWORD;
begin
aResult := False;
Cancel := False;
if (FileName = '') or
((BitLength <> 8) and (BitLength <> 16)) or
((Channels < 1) and (Channels > 2)) then
raise EMMWaveError.Create(LoadResStr(IDS_WFINVALIDPARAMS));
pcmBuildWaveHeader(@wfx, BitLength, Channels, SampleRate);
pBuf := nil;
lpwioDst := nil;
DestFile := StrAlloc(MAX_PATH+1);
{ open the source file }
FHandle := FileOpen(FileName, fmOpenRead or fmShareDenyNone);
if (Longint(FHandle) < 0) then
goto ERROR_IMPORT;
{ set the bytes we have to convert }
NumBytes := MMUtils.GetFileSize(FileName);
if (NumBytes <= 0) then
goto ERROR_IMPORT;
{ create the dest. WAVEIOINFO }
if wioCreateFileInfo(lpwioDst, @wfx) <> 0 then
goto ERROR_IMPORT;
{ first create a file name for the destination file }
StrPCopy(DestFile, ChangeFileExt(ExpandUNCFileName(FileName),'.WAV'));
{ write the new Header to disc }
if wioWriteFileInfo(lpwioDst, DestFile) <> 0 then
goto ERROR_IMPORT;
{ compute source bytes to read (round down to nearest }
{ block for one second of data) }
with wfx do
BufSize := nAvgBytesPerSec-(nAvgBytesPerSec mod nBlockAlign);
{ allocate the buffer for reading/converting data }
pBuf := GlobalAllocMem(BufSize);
if (pBuf = Nil) then goto ERROR_IMPORT;
CurByte := 0;
while CurByte < NumBytes do
begin
{ read the data to convert }
NumRead := min(BufSize, NumBytes - CurByte);
NumRead := FileRead(FHandle, pBuf^, NumRead);
if (NumRead <= 0) then break;
inc(CurByte, NumRead);
{ have we space on the drive ? }
if not GetDiskFree(DestFile,NumRead+DWORD(IOBufferSize)+10240) then
goto ERROR_IMPORT;
{ write the data out as we go... }
if wioWaveWriteData(lpwioDst, pBuf, NumRead) <> NumRead then
goto ERROR_IMPORT;
{ let the user have some time }
Application.ProcessMessages;
Progress(CurByte, NumBytes, Cancel);
if Cancel then goto ERROR_IMPORT;
end;
{ close new file }
wioWaveClose(lpwioDst);
{ set the FileName }
Self.FileName := StrPas(DestFile);
aResult := True;
ERROR_IMPORT:
FileClose(FHandle);
wioWaveClose(lpwioDst);
wioFreeFileInfo(lpwioDst);
GlobalFreeMem(Pointer(pBuf));
StrDispose(DestFile);
if not aResult then
if not Cancel then
raise EMMWaveError.Create(LoadResStr(IDS_WFIMPORTERROR))
else
raise EMMWaveError.Create(LoadResStr(IDS_WFIMPORTABORTED));
end;
{-- TMMWave --------------------------------------------------------------}
Procedure TMMWave.SetIOBufSize(aValue: Longint);
begin
if (aValue <> FIOBufSize) then
begin
FIOBufSize := Max(aValue,8192);
if (FPWAVEIOCB <> Nil) then
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -