From: yamat0jp Date: Sun, 13 May 2018 06:03:30 +0000 (+0900) Subject: chapter 7 X-Git-Url: http://git.osdn.net/view?p=sample-delphi%2Fsample-DELPHI.git;a=commitdiff_plain;h=e619fe138047371bf2bff5ae91ec3162ddfa9a97 chapter 7 よくわかっていません ReadBufferが使えませんでしたのでReadにかえました。なんで。 --- diff --git a/wav_proj.dpr b/wav_proj.dpr index 6753803..026a8fe 100644 --- a/wav_proj.dpr +++ b/wav_proj.dpr @@ -10,24 +10,6 @@ uses WriteHeader in 'WriteHeader.pas', spWav in 'spWav.pas'; -function cut(fpIn, fpOut: TFileStream; sp: SpParam): integer; -var - Buffer: array of ShortInt; - size: integer; -begin - result := 0; - size := (sp.endpos - sp.startpos + 1) * sp.channels * sp.samplePerSec * - sp.bitsPerSample div 8; - SetLength(Buffer, size); - try - fpIn.ReadBuffer(Pointer(Buffer)^, size); - fpOut.WriteBuffer(Pointer(Buffer)^, size); - Finalize(Buffer); - except - result := -1; - end; -end; - function checkRange(var sp: SpParam): integer; begin result := 0; @@ -45,9 +27,28 @@ begin end; function wavDataWrite(fpIn, fpOut: TFileStream; const sp: SpParam): integer; +var + Buffer: array of ShortInt; begin + result := 0; fpIn.Position := sp.posOfData; - result := cut(fpIn, fpOut, sp); + try + GetMem(Pointer(Buffer), sp.sizeOfData); + except + Writeln('ƒƒ‚ƒŠ‚ªŠm•Û‚Å‚«‚Ü‚¹‚ñ'); + result := -1; + end; + if fpIn.Read(Pointer(Buffer)^, sp.sizeOfData) = -1 then + begin + Writeln('“ǂݍž‚Ý‚ÉŽ¸”s'); + result := -1; + end; + if fpOut.Write(Pointer(Buffer)^, sp.sizeOfData) = -1 then + begin + Writeln('‘‚«ž‚Ý‚ÉŽ¸”s'); + result := -1; + end; + FreeMem(Pointer(Buffer)); end; function wavWrite(inFile, outFile: PChar; var sp: SpParam): integer; @@ -79,21 +80,25 @@ begin result := 0; end; +procedure usage; +begin + Writeln('ˆø”<“ü—̓tƒ@ƒCƒ‹–¼><o—̓tƒ@ƒCƒ‹–¼><‘¬“x”{—¦>'); +end; + var sp: SpParam; begin try { TODO -oUser -cConsole ƒƒCƒ“ : ‚±‚±‚ɃR[ƒh‚ð‹Lq‚µ‚Ä‚­‚¾‚³‚¢ } - sp.startpos := StrToInt(ParamStr(3)); - sp.endpos := StrToInt(ParamStr(4)); - if sp.startpos > sp.endpos then + if ParamCount <> 3 then begin - Writeln('ŠJŽn•b‚͏I—¹•b‚ð’´‚¦‚Ä‚Í‚È‚è‚Ü‚¹‚ñ'); + usage; Exit; end; if wavHdrRead(PChar(ParamStr(1)), sp) = -1 then Exit; + sp.samplePerSec := StrToInt(ParamStr(3)) * sp.samplePerSec; if wavWrite(PChar(ParamStr(1)), PChar(ParamStr(2)), sp) = -1 then Exit; Writeln('Š®—¹'); diff --git a/wav_proj.dproj b/wav_proj.dproj index 6f4f2c0..b7b391b 100644 --- a/wav_proj.dproj +++ b/wav_proj.dproj @@ -127,7 +127,7 @@ true - toujyo.wav effect.wav 1 3 + toujyo.wav effect.wav 2 false