OSDN Git Service

chapter 7 chapter_7
authoryamat0jp <yamat0jp@yahoo.co.jp>
Sun, 13 May 2018 06:03:30 +0000 (15:03 +0900)
committeryamat0jp <yamat0jp@yahoo.co.jp>
Sun, 13 May 2018 06:03:30 +0000 (15:03 +0900)
よくわかっていません ReadBufferが使えませんでしたのでReadにかえました。なんで。

wav_proj.dpr
wav_proj.dproj

index 6753803..026a8fe 100644 (file)
@@ -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('\83\81\83\82\83\8a\82ª\8am\95Û\82Å\82«\82Ü\82¹\82ñ');
+    result := -1;
+  end;
+  if fpIn.Read(Pointer(Buffer)^, sp.sizeOfData) = -1 then
+  begin
+    Writeln('\93Ç\82Ý\8d\9e\82Ý\82É\8e¸\94s');
+    result := -1;
+  end;
+  if fpOut.Write(Pointer(Buffer)^, sp.sizeOfData) = -1 then
+  begin
+    Writeln('\8f\91\82«\8d\9e\82Ý\82É\8e¸\94s');
+    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('\88ø\90\94<\93ü\97Í\83t\83@\83C\83\8b\96¼><\8fo\97Í\83t\83@\83C\83\8b\96¼><\91¬\93x\94{\97¦>');
+end;
+
 var
   sp: SpParam;
 
 begin
   try
     { TODO -oUser -cConsole \83\81\83C\83\93 : \82±\82±\82É\83R\81[\83h\82ð\8bL\8fq\82µ\82Ä\82­\82¾\82³\82¢ }
-    sp.startpos := StrToInt(ParamStr(3));
-    sp.endpos := StrToInt(ParamStr(4));
-    if sp.startpos > sp.endpos then
+    if ParamCount <> 3 then
     begin
-      Writeln('\8aJ\8en\95b\82Í\8fI\97¹\95b\82ð\92´\82¦\82Ä\82Í\82È\82è\82Ü\82¹\82ñ');
+      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('\8a®\97¹');
index 6f4f2c0..b7b391b 100644 (file)
         <DCC_RemoteDebug>true</DCC_RemoteDebug>
     </PropertyGroup>
     <PropertyGroup Condition="'$(Cfg_1_Win32)'!=''">
-        <Debugger_RunParams>toujyo.wav effect.wav 1 3</Debugger_RunParams>
+        <Debugger_RunParams>toujyo.wav effect.wav 2</Debugger_RunParams>
         <DCC_RemoteDebug>false</DCC_RemoteDebug>
     </PropertyGroup>
     <PropertyGroup Condition="'$(Cfg_1_Win64)'!=''">