MMFade.pas
上传用户:hylc_2004
上传日期:2014-01-23
资源大小:46800k
文件大小:27k
- {========================================================================}
- {= (c) 1995-98 SwiftSoft Ronald Dittrich =}
- {========================================================================}
- {= All Rights Reserved =}
- {========================================================================}
- {= D 01099 Dresden = Fax.: +49(0)351-8037944 =}
- {= Loewenstr.7a = info@swiftsoft.de =}
- {========================================================================}
- {= Actual versions on http://www.swiftsoft.de/index.html =}
- {========================================================================}
- {= This code is for reference purposes only and may not be copied or =}
- {= distributed in any format electronic or otherwise except one copy =}
- {= for backup purposes. =}
- {= =}
- {= No Delphi Component Kit or Component individually or in a collection=}
- {= subclassed or otherwise from the code in this unit, or associated =}
- {= .pas, .dfm, .dcu, .asm or .obj files may be sold or distributed =}
- {= without express permission from SwiftSoft. =}
- {= =}
- {= For more licence informations please refer to the associated =}
- {= HelpFile. =}
- {========================================================================}
- {= $Date: 01.11.98 - 03:53:31 $ =}
- {========================================================================}
- unit MMFade;
- {$I COMPILER.INC}
- interface
- uses
- {$IFDEF WIN32}
- Windows,
- {$ELSE}
- WinProcs,
- WinTypes,
- {$ENDIF}
- SysUtils,
- Messages,
- Classes,
- Controls,
- MMSystem,
- MMObj,
- MMutils,
- MMMulDiv,
- MMRegs,
- MMPCMSup;
- const
- Overflow : Boolean = False;
- type
- PMMFadePoint = ^TMMFadePoint;
- TMMFadePoint = record
- Offset : Longint;
- Volume : Longint;
- VolumeL : Longint;
- VolumeR : Longint;
- Selected : LongBool;
- end;
- PMMFadeSeg = ^TMMFadeSeg;
- TMMFadeSeg = record
- ptStart : TMMFadePoint;
- ptEnd : TMMFadePoint;
- end;
- const
- { Maximum List size }
- MaxFadeListSize = Maxint div (sizeOf(TMMFadePoint)*sizeOf(TMMFadePoint));
- type
- PMMFadeArray = ^TMMFadeArray;
- TMMFadeArray = array[0..MaxFadeListSize-1] of TMMFadePoint;
- {-- TMMFadeList -----------------------------------------------------}
- TMMFadeList = class(TMMObject)
- private
- FList : PMMFadeArray;
- FCount : Integer;
- FCapacity : Integer;
- FCurIndex : Longint;
- FStartOffset : Longint;
- FStartVolume : Longint;
- FStartVolumeL: Longint;
- FStartVolumeR: Longint;
- protected
- procedure Error; virtual;
- procedure Grow; virtual;
- function Get(Index: Integer): PMMFadePoint;
- procedure Put(Index: Integer; Point: PMMFadePoint);
- procedure SetCapacity(NewCapacity: Integer);
- procedure SetCount(NewCount: Integer);
- public
- destructor Destroy; override;
- procedure Clear;
- procedure Sort;
- function Add(Point: TMMFadePoint): Integer;
- procedure Insert(Index: Integer; Point: TMMFadePoint);
- procedure Delete(Index: Integer);
- function Selected(Index: Integer): Boolean;
- function QueryFadePoint(Point: TMMFadePoint): Boolean;
- function AddFadePoint(Point: TMMFadePoint; Align: Boolean): Boolean;
- function LocateFadePoint(Offset: Longint): integer;
- function FindFadePoint(Offset: Longint): integer;
- function CalcFadeVolume(Offset: Longint): Longint;
- procedure Assign(Source: TPersistent); override;
- procedure AssignEnvelope(Source: TPersistent); virtual;
- procedure AssignToEnvelope(Dest: TPersistent); virtual;
- function First: PMMFadePoint;
- function Last: PMMFadePoint;
- function Expand: TMMFadeList;
- property Capacity: Integer read FCapacity write SetCapacity;
- property Count: Integer read FCount write SetCount;
- property Points[Index: Integer]: PMMFadePoint read Get write Put; default;
- property List: PMMFadeArray read FList;
- property CurIndex: Longint read FCurIndex write FCurIndex;
- property StartOffset: Longint read FStartOffset write FStartOffset;
- property StartVolumeL: Longint read FStartVolumeL write FStartVolumeL;
- property StartVolumeR: Longint read FStartVolumeR write FStartVolumeR;
- end;
- function pcmVolumeFade(pwfx: PWaveFormatEx; lpData: PChar;
- dwSrcLen: TDataSize; FadeList: TMMFadeList): Boolean;
- function pcmVolumeFade8(pwfx: PWaveFormatEx; lpData: PChar;
- dwSrcLen: TDataSize; FadeList: TMMFadeList): Boolean;
- function pcmVolumeFade16(pwfx: PWaveFormatEx; lpData: PChar;
- dwSrcLen: TDataSize; FadeList: TMMFadeList): Boolean;
- implementation
- uses
- Consts,
- {$IFDEF DELPHI6}
- RTLConsts,
- {$ENDIF}
- MMEnvelp;
- {------------------------------------------------------------------------}
- {$IFDEF DELPHI3}
- procedure ListError(const Ident: string);
- begin
- raise EListError.Create(Ident);
- end;
- {$ELSE}
- procedure ListError(Ident: Word);
- begin
- raise EListError.CreateRes(Ident);
- end;
- {$ENDIF}
- {------------------------------------------------------------------------}
- procedure ListIndexError;
- begin
- ListError(SListIndexError);
- end;
- {== TMMFadeList =========================================================}
- destructor TMMFadeList.Destroy;
- begin
- FStartVolume := 0;
- Clear;
- end;
- {-- TMMFadeList ---------------------------------------------------------}
- procedure TMMFadeList.Error;
- begin
- ListIndexError;
- end;
- {-- TMMFadeList ---------------------------------------------------------}
- procedure TMMFadeList.Clear;
- begin
- SetCount(0);
- SetCapacity(0);
- end;
- {-- TMMFadeList ---------------------------------------------------------}
- { QueryPoint sagt, ob dieser punkt eingefuegt werden kann. }
- function TMMFadeList.QueryFadePoint(Point: TMMFadePoint): Boolean;
- var
- i: integer;
- begin
- Result := True;
- for i := 0 to Count-1 do
- begin
- if ((i = 0) and (Point.Offset <= Points[i]^.Offset)) or
- ((i = Count-1) and (Point.Offset >= Points[i]^.Offset)) or
- (Points[i]^.Offset = Point.Offset) then
- begin
- Result := False;
- exit;
- end;
- end;
- end;
- {-- TMMFadeList ---------------------------------------------------------}
- function TMMFadeList.AddFadePoint(Point: TMMFadePoint; Align: Boolean): Boolean;
- var
- i: integer;
- begin
- Result := False;
- if QueryFadePoint(Point) then { passt hier Punkt ueberhaupt hin ? }
- begin
- i := LocateFadePoint(Point.Offset);
- if (i < 1) or (i >= Count) then Add(Point)
- else
- begin
- { neuen Punkt genau auf Linie zwischen zwei Punken einf黦en }
- if Align then
- with Point do
- begin
- Volume := CalcFadeVolume(Offset);
- end;
- Insert(i, Point);
- end;
- Result := True;
- end;
- end;
- {-- TMMFadeList ---------------------------------------------------------}
- function TMMFadeList.Add(Point: TMMFadePoint): Integer;
- begin
- Result := FCount;
- if Result = FCapacity then Grow;
- FList^[Result] := Point;
- inc(FCount);
- end;
- {-- TMMFadeList ---------------------------------------------------------}
- procedure TMMFadeList.Insert(Index: Integer; Point: TMMFadePoint);
- begin
- if (Index < 0) or (Index > FCount) then Error;
- if FCount = FCapacity then Grow;
- if Index < FCount then
- System.Move(FList^[Index], FList^[Index + 1],
- (FCount - Index) * SizeOf(TMMFadePoint));
- FList^[Index] := Point;
- Inc(FCount);
- end;
- {-- TMMFadeList ---------------------------------------------------------}
- procedure TMMFadeList.Delete(Index: Integer);
- begin
- if (Index < 0) or (Index >= FCount) then Error;
- Dec(FCount);
- if Index < FCount then
- System.Move(FList^[Index + 1], FList^[Index],
- (FCount - Index) * SizeOf(TMMFadePoint));
- end;
- {-- TMMFadeList ---------------------------------------------------------}
- function TMMFadeList.Selected(Index: Integer): Boolean;
- begin
- if (Index < 0) or (Index >= FCount) then Error;
- Result := FList^[Index].Selected;
- end;
- {-- TMMFadeList ---------------------------------------------------------}
- function TMMFadeList.First: PMMFadePoint;
- begin
- Result := Get(0);
- end;
- {-- TMMFadeList ---------------------------------------------------------}
- function TMMFadeList.Last: PMMFadePoint;
- begin
- Result := Get(FCount-1);
- end;
- {-- TMMFadeList ---------------------------------------------------------}
- function TMMFadeList.Get(Index: Integer): PMMFadePoint;
- begin
- if (Index < 0) or (Index >= FCount) then Error;
- Result := @FList^[Index];
- end;
- {-- TMMFadeList ---------------------------------------------------------}
- procedure TMMFadeList.Put(Index: Integer; Point: PMMFadePoint);
- begin
- if (Index < 0) or (Index >= FCount) then Error;
- FList^[Index] := Point^;
- end;
- {-- TMMFadeList ---------------------------------------------------------}
- procedure TMMFadeList.Grow;
- var
- Delta: Integer;
- begin
- if FCapacity > 8 then
- Delta := 16
- else if FCapacity > 4 then
- Delta := 8
- else
- Delta := 4;
- SetCapacity(FCapacity + Delta);
- end;
- {-- TMMFadeList ---------------------------------------------------------}
- procedure TMMFadeList.SetCapacity(NewCapacity: Integer);
- begin
- if (NewCapacity < FCount) or (NewCapacity > MaxListSize) then Error;
- if NewCapacity <> FCapacity then
- begin
- {$IFDEF WIN32}
- ReallocMem(FList, NewCapacity * SizeOf(TMMFadePoint));
- {$ELSE}
- if NewCapacity = 0 then
- begin
- GlobalFreePtr(FList);
- FList := nil;
- end
- else
- begin
- if FCapacity = 0 then
- FList := GlobalAllocPtr(HeapAllocFlags, NewCapacity*sizeOf(TMMFadePoint))
- else
- FList := GlobalReallocPtr(FList, NewCapacity*sizeOf(TMMFadePoint), HeapAllocFlags);
- if FList = nil then
- raise EStreamError.Create(LoadStr(SMemoryStreamError));
- end;
- {$ENDIF}
- FCapacity := NewCapacity;
- end;
- end;
- {-- TMMFadeList ---------------------------------------------------------}
- function TMMFadeList.Expand: TMMFadeList;
- begin
- if FCount = FCapacity then Grow;
- Result := Self;
- end;
- {-- TMMFadeList ---------------------------------------------------------}
- procedure TMMFadeList.SetCount(NewCount: Integer);
- begin
- if (NewCount < 0) or (NewCount > MaxListSize) then Error;
- if NewCount > FCapacity then SetCapacity(NewCount);
- if NewCount > FCount then
- FillChar(FList^[FCount], (NewCount - FCount) * SizeOf(TMMFadePoint), 0);
- FCount := NewCount;
- end;
- {-- TMMFadeList ---------------------------------------------------------}
- procedure TMMFadeList.Assign(Source: TPersistent);
- var
- i: integer;
- p: TMMFadePoint;
- begin
- if (Source is TMMFadeList) or (Source = nil) then
- begin
- if (Source <> Self) then
- begin
- Clear;
- if (Source <> nil) then
- begin
- Capacity := TMMFadeList(Source).Count;
- for i := 0 to TMMFadeList(Source).Count-1 do
- begin
- p := TMMFadeList(Source).Points[i]^;
- p.Selected := False;
- Add(p);
- end;
- end;
- end;
- end
- else inherited assign(Source);
- end;
- {-- TMMFadeList ---------------------------------------------------------}
- procedure TMMFadeList.AssignEnvelope(Source: TPersistent);
- var
- i: integer;
- p: TMMFadePoint;
- begin
- if (Source is TMMEnvelope) or (Source = nil) then
- begin
- Clear;
- if (Source <> nil) then
- begin
- Capacity := TMMEnvelope(Source).Count;
- for i := 0 to TMMEnvelope(Source).Count-1 do
- begin
- p.Offset := TMMEnvelope(Source).Points[i].X_Value;
- p.Volume := TMMEnvelope(Source).Points[i].Y_Value;
- p.Selected := False;
- Add(p);
- end;
- end;
- end
- else inherited assign(Source);
- end;
- {-- TMMFadeList ---------------------------------------------------------}
- procedure TMMFadeList.AssignToEnvelope(Dest: TPersistent);
- var
- i: integer;
- aPoint: TMMEnvelopePoint;
- begin
- if (Dest <> nil) and (Dest is TMMEnvelope) then
- begin
- TMMEnvelope(Dest).Clear;
- aPoint := TMMEnvelopePoint.Create;
- try
- for i := 0 to Count-1 do
- begin
- aPoint.X_Value := Points[i]^.Offset;
- aPoint.Y_Value := Points[i]^.Volume;
- aPoint.Selected := False;
- TMMEnvelope(Dest).AddPoint(aPoint,False);
- end;
- finally
- aPoint.Free;
- end;
- end;
- end;
- {-- TMMFadeList --------------------------------------------------------}
- function TMMFadeList.LocateFadePoint(Offset: Longint): integer;
- { LocatePoint returns the Index of the first point, which lies right }
- { from Offset. Is the list empty -1, is there no other element Count(!) }
- var
- L, H : integer;
- begin
- if (Count = 0) then
- begin
- Result := -1;
- end
- else
- begin
- if Points[Count-1]^.Offset <= Offset then
- begin
- Result := Count;
- end
- else
- begin
- L := 0;
- H := Count-1;
- Result := H shr 1;
- while L < H do
- begin
- if Points[Result]^.Offset <= Offset then
- L := Result+1
- else
- H := Result;
- Result := (L + H) shr 1;
- end;
- end;
- end;
- end;
- {-- TMMFadeList --------------------------------------------------------}
- { FindPoint gibt genau den Index des Punktes zurueck, oder -1 }
- function TMMFadeList.FindFadePoint(Offset: Longint): integer;
- var
- i : integer;
- begin
- Result := -1;
- i := LocateFadePoint(Offset);
- if (i > 0) and (i <= Count) then
- begin
- if Offset = Points[i-1]^.Offset then
- begin
- Result := i-1;
- end;
- end;
- end;
- {-- TMMFadeList --------------------------------------------------------}
- function TMMFadeList.CalcFadeVolume(Offset: Longint): Longint;
- var
- i: integer;
- begin
- Result := 0;
- i := LocateFadePoint(Offset);
- if (i > 0) then
- begin
- i := Min(i,Count-1);
- if (i > 0) then
- if Points[i]^.Offset > Points[i-1]^.Offset then
- Result := Points[i-1]^.Volume +
- MulDiv32(Points[i]^.Volume - Points[i-1]^.Volume,
- Offset - Points[i-1]^.Offset,
- Points[i]^.Offset - Points[i-1]^.Offset);
- end;
- end;
- {-- TMMFadeList --------------------------------------------------------}
- procedure TMMFadeList.Sort;
- var
- i,j,h: integer;
- p: TMMFadePoint;
- begin { Start Shell-Sort }
- h := 1;
- while h <= Count div 9 do h := h*3 + 1;
- while h > 0 do
- begin
- for i := h to Count-1 do
- begin
- p := Points[i]^;
- j := i;
- while ( j >= h ) and (Points[j-h]^.Offset > p.Offset) do
- begin
- Points[j]^ := Points[j-h]^;
- dec(j, h);
- end;
- Points[j]^ := p;
- end;
- h := h div 3;
- end;
- end;
- {*************************************************************************}
- {$IFDEF USEASM}
- {$IFDEF WIN32}{$L MMFADE32.OBJ}{$ELSE}{$L MMFADE16.OBJ}{$ENDIF}
- {$F+}
- function pcmFade8(nChannles: integer; lpData: PChar; dwSrcLen: Longint;
- pFade: PMMFadeSeg): TMMFadePoint;
- {$IFDEF WIN32}pascal;{$ENDIF}external;
- function pcmFade16(nChannels: integer; lpData: PChar; dwSrcLen: Longint;
- pFade: PMMFadeSeg): TMMFadePoint;
- {$IFDEF WIN32}pascal;{$ENDIF}external;
- {$F-}
- {$ELSE}
- (*************************************************************************)
- function pcmFade8(nChannels: integer; lpData: PChar;
- dwSrcLen: Longint; pFade: PMMFadeSeg): TMMFadePoint;
- Label Loop,Next;
- var
- ACC, M, R: Longint; { Hilfsvariablen }
- Dir : integer; { kann nur +1 oder -1 sein }
- DY,DX : Longint;
- sVolume : Longint;
- eVolume : Longint;
- Count : Longint;
- pB : PByte;
- ch : integer;
- begin
- with pFade^ do
- begin
- pB := Pointer(lpData); { start with left channel }
- ch := 1;
- sVolume := ptStart.VolumeL;
- eVolume := ptEnd.VolumeL;
- Loop:
- { nichts zu tun ? }
- if (sVolume = VOLUMEBASE) and (eVolume = VOLUMEBASE) then
- goto next;
- Count := Min(ptEnd.Offset-ptStart.Offset,dwSrcLen)div (nChannels);
- if Count < 1 then
- goto Next;
- { silence ? }
- if (sVolume = 0) and (eVolume = 0) then
- begin
- while (Count > 0) do
- begin
- pB^ := 128;
- inc(pB,nChannels);
- dec(Count);
- end;
- goto Next;
- end;
- { Byte Abstand da Delta-T immer positiv da TB rechts ist }
- DX := (ptEnd.Offset-ptStart.Offset) div nChannels;
- { Fehler Accu wird auf 50% initialisiert }
- ACC := DX shr 1;
- DY := eVolume-sVolume;{ Volume-Diff }
- if DY < 0 then DY := -DY;
- M := DY div DX; { Steigung abgrundet }
- R := DY mod DX;
- Dir := 1; { Vorgabe : Anstieg }
- if (eVolume < sVolume) then
- begin
- Dir := -Dir; { Abstieg }
- M := -M;
- end;
- if (DY = 0) then
- begin { ebene Volumekurve }
- while Count > 0 do
- begin
- pB^ := pcmSampleClip8(((pB^-128) * sVolume) div VOLUMEBASE) + 128;
- inc(pB,nChannels);
- dec(Count);
- end;
- end
- else
- begin
- if (M <> 0) then { grosse Steigung }
- begin
- while Count > 0 do
- begin
- pB^ := pcmSampleClip8(((pB^-128) * sVolume) div VOLUMEBASE) + 128;
- inc(pB,nChannels);
- Inc(sVolume,M);
- Dec(Acc,R);
- if Acc < 0 then
- begin
- Inc(Acc, DX);
- inc(sVolume,Dir);
- end;
- dec(Count);
- end;
- end
- else { flache Steigung }
- begin
- while Count > 0 do
- begin
- pB^ := pcmSampleClip8(((pB^-128) * sVolume) div VOLUMEBASE) + 128;
- inc(pB,nChannels);
- Dec(Acc,R);
- if Acc < 0 then
- begin
- Inc(Acc, DX);
- Inc(sVolume,Dir);
- end;
- dec(Count);
- end;
- end;
- end;
- Next:
- if (ch = 1) then
- begin
- inc(ch);
- Result.VolumeL := sVolume;
- if (nChannels = 2) then
- begin
- { go to right channel }
- pB := Pointer(lpData+sizeOf(Byte));
- sVolume := ptStart.VolumeR;
- eVolume := ptEnd.VolumeR;
- goto Loop;
- end;
- end
- else
- begin
- Result.VolumeR := sVolume;
- end;
- end;
- end;
- (*************************************************************************)
- function pcmFade16(nChannels: integer; lpData: PChar;
- dwSrcLen: Longint; pFade: PMMFadeSeg): TMMFadePoint;
- Label Loop,Next;
- var
- ACC, M, R: Longint; { Hilfsvariablen }
- Dir : integer; { kann nur +1 oder -1 sein }
- DY,DX : Longint;
- sVolume : Longint;
- eVolume : Longint;
- Count : Longint;
- pS : PSmallint;
- ch : integer;
- begin
- with pFade^ do
- begin
- pS := Pointer(lpData); { start with left channel }
- ch := 1;
- sVolume := ptStart.VolumeL;
- eVolume := ptEnd.VolumeL;
- Loop:
- { nothing to do ? }
- if (sVolume = VOLUMEBASE) and (eVolume = VOLUMEBASE) then
- goto Next;
- Count := Min(ptEnd.Offset-ptStart.Offset,dwSrcLen)div (2*nChannels);
- if Count < 1 then
- goto Next;
- { silence ? }
- if (sVolume = 0) and (eVolume = 0) then
- begin
- while (Count > 0) do
- begin
- pS^ := 0;
- inc(pS,nChannels);
- dec(Count);
- end;
- goto Next;
- end;
- { Byte Abstand da Delta-T immer positiv da TB rechts ist }
- DX := (ptEnd.Offset-ptStart.Offset) div (2*nChannels);
- { Fehler Accu wird auf 50% initialisiert }
- ACC := DX shr 1;
- Dir := 1; { Vorgabe : Anstieg }
- DY := eVolume-sVolume; { Volume-Diff }
- if DY < 0 then
- begin
- DY := -DY;
- Dir := -Dir; { Abstieg }
- end;
- M := DY div DX; { Steigung abgrundet }
- R := DY mod DX;
- if Dir < 0 then M := -M;
- if (DY = 0) then
- begin { ebene Volumekurve }
- while Count > 0 do
- begin
- pS^ := pcmSampleClip16((pS^ * sVolume) div VOLUMEBASE);
- inc(pS,nChannels);
- dec(Count);
- end;
- end
- else
- begin
- if (M <> 0) then { grosse Steigung }
- begin
- while (Count > 0) do
- begin
- pS^ := pcmSampleClip16((pS^ * sVolume) div VOLUMEBASE);
- inc(pS,nChannels);
- sVolume := sVolume + M;
- Dec(Acc,R);
- if Acc < 0 then
- begin
- Inc(Acc, DX);
- sVolume := sVolume - 1;
- end;
- dec(Count);
- end;
- end
- else { flache Steigung }
- begin
- while Count > 0 do
- begin
- pS^ := pcmSampleClip16((pS^ * sVolume) div VOLUMEBASE);
- inc(pS,nChannels);
- Dec(Acc,R);
- if Acc < 0 then
- begin
- Inc(Acc, DX);
- sVolume := sVolume + Dir;
- end;
- dec(Count);
- end;
- end;
- end;
- Next:
- if (ch = 1) then
- begin
- inc(ch);
- Result.VolumeL := sVolume;
- if (nChannels = 2) then
- begin
- { go to right channel }
- pS := Pointer(lpData+sizeOf(Smallint));
- sVolume := ptStart.VolumeR;
- eVolume := ptEnd.VolumeR;
- goto Loop;
- end;
- end
- else
- begin
- Result.VolumeR := sVolume;
- end;
- end;
- end;
- {$ENDIF}
- (*************************************************************************)
- function pcmVolumeFade(pwfx: PWaveFormatEx; lpData: PChar;
- dwSrcLen: TDataSize; FadeList: TMMFadeList): Boolean;
- begin
- Result := False;
- if (pwfx = nil) or (pwfx^.wFormatTag <> WAVE_FORMAT_PCM) then exit;
- if (pwfx^.wBitsPerSample = 8) then
- begin
- Result := pcmVolumeFade8(pwfx, lpData, dwSrcLen, FadeList);
- end
- else
- begin
- Result := pcmVolumeFade16(pwfx, lpData, dwSrcLen, FadeList);
- end;
- end;
- (*************************************************************************)
- function pcmVolumeFade8(pwfx: PWaveFormatEx; lpData: PChar;
- dwSrcLen: TDataSize; FadeList: TMMFadeList): Boolean;
- var
- Fade: TMMFadeSeg;
- p : TMMFadePoint;
- nBytes: Longint;
- begin
- Overflow := False;
- if (pwfx^.wFormatTag = 1) then
- with FadeList do
- begin
- CurIndex := Max(LocateFadePoint(StartOffset)-1,0);
- while (dwSrcLen > 0) and (CurIndex < Count) do
- with Points[CurIndex]^ do
- begin
- nBytes := Min(dwSrcLen,(Offset-StartOffset));
- if (nBytes > 0) then
- begin
- { start point }
- Fade.ptStart.Offset := StartOffset;
- Fade.ptStart.VolumeL := StartVolumeL;
- Fade.ptStart.VolumeR := StartVolumeR;
- { end point }
- Fade.ptEnd.Offset := Offset;
- Fade.ptEnd.VolumeL := VolumeL;
- Fade.ptEnd.VolumeR := VolumeR;
- p := pcmFade8(pwfx^.nChannels,lpData,nBytes,@Fade);
- StartVolumeL := p.VolumeL;
- StartVolumeR := p.VolumeR;
- {$IFDEF WIN32}
- inc(lpData,nBytes);
- {$ELSE}
- incHuge(lpData,nBytes);
- {$ENDIF}
- dec(dwSrcLen,nBytes);
- StartOffset := StartOffset + nBytes;
- end;
- { aktuall segment done ? }
- if StartOffset >= Offset then
- CurIndex := CurIndex+1;
- end;
- end;
- Result := Overflow;
- end;
- (*************************************************************************)
- function pcmVolumeFade16(pwfx: PWaveFormatEx; lpData: PChar;
- dwSrcLen: TDataSize; FadeList: TMMFadeList): Boolean;
- var
- Fade: TMMFadeSeg;
- p : TMMFadePoint;
- nBytes: Longint;
- begin
- Overflow := False;
- if (pwfx^.wFormatTag = 1) then
- with FadeList do
- begin
- CurIndex := Max(LocateFadePoint(StartOffset)-1,0);
- while (dwSrcLen > 0) and (CurIndex < Count) do
- with Points[CurIndex]^ do
- begin
- nBytes := Min(dwSrcLen,(Offset-StartOffset));
- if (nBytes > 0) then
- begin
- { start point }
- Fade.ptStart.Offset := StartOffset;
- Fade.ptStart.VolumeL := StartVolumeL;
- Fade.ptStart.VolumeR := StartVolumeR;
- { end point }
- Fade.ptEnd.Offset := Offset;
- Fade.ptEnd.VolumeL := VolumeL;
- Fade.ptEnd.VolumeR := VolumeR;
- p := pcmFade16(pwfx^.nChannels,lpData,nBytes,@Fade);
- StartVolumeL := p.VolumeL;
- StartVolumeR := p.VolumeR;
- {$IFDEF WIN32}
- inc(lpData,nBytes);
- {$ELSE}
- incHuge(lpData,nBytes);
- {$ENDIF}
- dec(dwSrcLen,nBytes);
- StartOffset := StartOffset + nBytes;
- end;
- { aktuall segment done ? }
- if StartOffset >= Offset then
- CurIndex := CurIndex+1;
- end;
- end;
- Result := Overflow;
- end;
- end.