OSDN Git Service

仕上げました
[sample-delphi/sample-DELPHI.git] / wav_proj.dpr
index 17bfa24..a59ce19 100644 (file)
@@ -6,117 +6,47 @@ program wav_proj;
 uses
   System.SysUtils,
   System.Classes,
+  MMSystem,
+  spWav in 'spWav.pas',
   wav in 'wav.pas',
-  WriteHeader in 'WriteHeader.pas';
+  selectFile in 'selectFile.pas',
+  effect in 'effect.pas';
 
-function effect8BitWav(fpIn, fpOut: TFileStream; sizeOfData: Word): integer;
 var
-  i: integer;
-  s: Single;
-  c: array [0 .. 1] of Byte;
-begin
-  result := 0;
-  i := 0;
-  s := sizeOfData / SizeOf(c);
-  while i < s do
-  begin
-    try
-      fpIn.ReadBuffer(c, SizeOf(c));
-      c[0] := 128;
-      fpOut.WriteBuffer(c, SizeOf(c));
-    except
-      result := -1;
-      break;
-    end;
-    Writeln(c[0], ' : ', c[1]);
-    inc(i);
-  end;
-end;
+  sp: SpParam;
+  pMem: TMemoryStream;
+  fileName: string;
 
-function effect16BitWav(fpIn, fpOut: TFileStream; sizeOfData: Word)
-  : integer;
+function getPara(var sp: SpParam): integer;
 var
   i: integer;
-  s: Single;
-  c: array [0 .. 1] of ShortInt;
 begin
-  result := 0;
-  i := 0;
-  s := sizeOfData / SizeOf(c);
-  while i < s do
-  begin
-    try
-      fpIn.ReadBuffer(c, SizeOf(c));
-      c[0] := 0;
-      fpOut.WriteBuffer(c, SizeOf(c));
-    except
-      result := -1;
-      break;
-    end;
-    Writeln(c[0], ' : ', c[1]);
-    inc(i);
-  end;
-end;
-
-function wavDataWrite(fpIn, fpOut: TFileStream; posOfData, sizeOfData: LongInt;
-  bytesPerSingleCh: SmallInt): integer;
-begin
-  fpIn.Seek(posOfData, soFromCurrent);
-  if bytesPerSingleCh = 1 then
-    result := effect8BitWav(fpIn, fpOut, sizeOfData)
-  else
-    result := effect16BitWav(fpIn, fpOut, sizeOfData);
+  sp.pWav:=pMem.Memory;
+  sp.cyclicSec:=i;
+  result:=0;
 end;
 
-function wavWrite(inFile, outFile: PChar; sampRate: LongWord; sampBits: Word;
-  posOfData, sizeOfData: integer): integer;
-var
-  bytesPerSingleCh: Word;
-  fpIn, fpOut: TFileStream;
 begin
   try
-    if FileExists(inFile) = true then
-      fpIn := TFileStream.Create(inFile, fmOpenRead)
-    else
-    begin
-      result := -1;
-      Writeln(inFile, '\82ð\83I\81[\83v\83\93\82Å\82«\82Ü\82¹\82ñ');
+    { TODO -oUser -cConsole \83\81\83C\83\93 : \82±\82±\82É\83R\81[\83h\82ð\8bL\8fq\82µ\82Ä\82­\82¾\82³\82¢ }
+    fileName := ExtractFileName(ParamStr(1));
+    if wavHdrRead(PChar(ParamStr(1)), sp) < 0 then
       Exit;
-    end;
-    fpOut := TFileStream.Create(outFile, fmCreate);
-    bytesPerSingleCh := sampBits div 8;
-    if waveHeaderWrite(fpOut, sizeOfData, bytesPerSingleCh, sampRate, sampBits)
-      = -1 then
+    if readWav(ParamStr(1), pMem) = false then
+      Exit;
+    if getPara(sp) = -1 then
     begin
-      result := -1;
-      Writeln('\83w\83b\83_\82ð\8f\91\82«\8d\9e\82ß\82Ü\82¹\82ñ');
+      pMem.Free;
       Exit;
     end;
-    if wavDataWrite(fpIn, fpOut, posOfData, sizeOfData, bytesPerSingleCh) = -1
-    then
+    if effectWav(sp) = 0 then
     begin
-      result := -1;
-      Write('\83G\83\89\81[\94­\90¶');
-      Exit;
+      PlaySound(pMem.Memory, 0, SND_ASYNC or SND_NODEFAULT or SND_MEMORY);
+      Readln;
+      PlaySound(nil, 0, SND_PURGE);
     end;
-  finally
-    fpIn.Free;
-    fpOut.Free;
-  end;
-  result:=0;
-end;
-
-var
-  sampRate, sampBits: SmallInt;
-  posOfData, sizeOfData: LongWord;
-
-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¢ }
-    wavHdrRead(PChar(ParamStr(1)), sampRate, sampBits, posOfData, sizeOfData);
-    wavWrite(PChar(ParamStr(1)), PChar(ParamStr(2)), sampRate, sampBits,
-      posOfData, sizeOfData);
-    Writeln('\8a®\97¹');
+    pMem.Free;
+    Finalize(sp.pWav^);
   except
     on E: Exception do
       Writeln(E.ClassName, ': ', E.Message);