OSDN Git Service

もう少しだと思います
authoryamat0jp <yamat0jp@yahoo.co.jp>
Tue, 15 May 2018 11:23:28 +0000 (20:23 +0900)
committeryamat0jp <yamat0jp@yahoo.co.jp>
Tue, 15 May 2018 11:23:28 +0000 (20:23 +0900)
ノイズが入ります

effect.pas
spWav.pas
wav_proj.dpr
wav_proj.dproj
wav_proj.identcache

index b538904..8a2c135 100644 (file)
@@ -14,6 +14,7 @@ implementation
 function effect8BitWav(const sp: SpParam): integer;
 var
   i, delayStart: integer;
+  k: Single;
   pMem, pCpy: array of Byte;
   s: TMemoryStream;
   L, R, DuetL, DuetR: SmallInt;
@@ -25,8 +26,9 @@ begin
     pMem := sp.pWav;
     pCpy := s.Memory;
     delayStart := sp.samplePerSec * sp.cycleuSec;
-    for i := delayStart to sp.sizeOfData div (sp.bitsPerSample *
-      SizeOf(Byte)) do
+    i := delayStart + sp.posOfData;
+    k := 8 * sp.sizeOfData / sp.bitsPerSample;
+    while i < k do
     begin
       L := pMem[i + 0];
       R := pMem[i + 1];
@@ -34,8 +36,10 @@ begin
       DuetR := pCpy[i + 1 - delayStart];
       inc(L, DuetL);
       inc(R, DuetR);
-      pMem[i+0]:=L;
-      pMem[i+1]:=R;
+
+      pMem[i + 0] := L;
+      pMem[i + 1] := R;
+      inc(i, 2);
     end;
   except
     result := -1;
@@ -45,19 +49,23 @@ end;
 function effect16BitWav(const sp: SpParam): integer;
 var
   i, delayStart: integer;
+  k: Single;
   pMem, pCpy: array of SmallInt;
   s: TMemoryStream;
   L, R, DuetL, DuetR: SmallInt;
 begin
   result := 0;
+  s := TMemoryStream.Create;
   try
-    s := TMemoryStream.Create;
-    s.ReadBuffer(sp.pWav^, sp.sizeOfData);
+    SetLength(pCpy, sp.sizeOfData);
+    s.Write(sp.pWav^, sp.sizeOfData);
+    s.Position := 0;
+    s.Read(Pointer(pCpy)^, sp.sizeOfData);
     pMem := sp.pWav;
-    pCpy := s.Memory;
-    delayStart := sp.samplePerSec * sp.cycleuSec;
-    for i := delayStart to sp.sizeOfData div (sp.bitsPerSample *
-      SizeOf(SmallInt)) do
+    delayStart := sp.posOfData + sp.samplePerSec * sp.cyclicSec;
+    i := delayStart + sp.posOfData;
+    k := 8 * sp.sizeOfData / sp.bitsPerSample;
+    while i < k do
     begin
       L := pMem[i + 0];
       R := pMem[i + 1];
@@ -65,14 +73,17 @@ begin
       DuetR := pCpy[i + 1 - delayStart];
       inc(L, DuetL);
       inc(R, DuetR);
-      L := SmallInt(max(-32768, min(32767, L)));
-      R := SmallInt(max(-32768, min(32767, R)));
+      L := max(-32768, min(32767, L));
+      R := max(-32768, min(32767, R));
       pMem[i + 0] := L;
       pMem[i + 1] := R;
+      inc(i, 2);
     end;
   except
     result := -1;
   end;
+  s.Free;
+  Finalize(pCpy);
 end;
 
 procedure usage;
index bb7eb79..cd91c99 100644 (file)
--- a/spWav.pas
+++ b/spWav.pas
@@ -45,7 +45,7 @@ type
     endpos: LongInt;
     cycleuSec: LongInt;
     pWav: Pointer;
-    cyclicSec: Single;
+    cyclicSec: integer;
   end;
 
 const
index 4f52bda..1d8052d 100644 (file)
@@ -48,7 +48,7 @@ begin
       PlaySound(nil, 0, SND_PURGE);
     end;
     pMem.Free;
-    Finalize(sp.pWav);
+    Finalize(sp.pWav^);
   except
     on E: Exception do
       Writeln(E.ClassName, ': ', E.Message);
index 9a990e9..15898fc 100644 (file)
         <DCC_RemoteDebug>true</DCC_RemoteDebug>
     </PropertyGroup>
     <PropertyGroup Condition="'$(Cfg_1_Win32)'!=''">
-        <Debugger_RunParams>toujyo.wav effect.wav</Debugger_RunParams>
+        <Debugger_RunParams>toujyo.wav </Debugger_RunParams>
         <DCC_RemoteDebug>false</DCC_RemoteDebug>
     </PropertyGroup>
     <PropertyGroup Condition="'$(Cfg_1_Win64)'!=''">
index 5c1e072..4d0a59c 100644 (file)
Binary files a/wav_proj.identcache and b/wav_proj.identcache differ