1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130:
| private Start_Point : DWORD; End_Point : DWORD;
Procedure TAudioEngine.Get_SilenceLength_16Bit(FileName: string; threshold: Integer; var StartPoint, EndPoint: DWORD); var a, b: Integer; pos, count, chan: DWORD; buf16: array[0..50000] of Smallint; flags : DWORD; begin count := 0; flags:= BASS_STREAM_DECODE;
chan:= (BASS_StreamCreateFile(FALSE, PChar(FileName), 0, 0, flags)); if (chan = 0) then chan:= (BASS_CD_StreamCreateFile(PChar(FileName), flags)); if (chan = 0) then chan:= (BASS_FLAC_StreamCreateFile(False, PChar(FileName), 0, 0, flags)); if (Channel_Song = 0) then chan:= (BASS_WMA_StreamCreateFile(False, PChar(FileName), 0, 0, flags)); if (chan = 0) then chan:= (BASS_APE_StreamCreateFile(PChar(FileName), flags)); if (chan = 0) then chan:= (BASS_MPC_StreamCreateFile(PChar(FileName), flags)); if (chan = 0) then chan:= (BASS_WV_StreamCreateFile(PChar(FileName), flags)); if (chan = 0) then chan:= (BASS_OFR_StreamCreateFile(PChar(FileName), flags)); if (chan = 0) then chan:= (BASS_LA_StreamCreateFile(PChar(FileName), flags)); if (chan = 0) then chan:= (BASS_AAC_StreamCreateFile(PChar(FileName), flags)); if (chan = 0) then chan:= (BASS_MP4_StreamCreateFile(PChar(FileName), flags));
if chan = 0 then Exit;
while Bass_ChannelIsActive(chan) <> 0 do begin b := BASS_ChannelGetData(chan, @buf16, 20000); b := b div 2; a := 0; while (a < b) and (Abs(buf16[a]) <= threshold) do a := a + 1; count := count + (a * 2); if (a < b) then begin while (a <> 0) and (Abs(buf16[a]) > (threshold div 4)) do begin a := a - 1; count := count - 2; end; Break; end; end; StartPoint := count; pos := BASS_StreamGetLength(chan); while (pos > count) do begin if pos < 100000 then pos := 0 else pos := pos - 100000; BASS_ChannelSetPosition(chan, pos); b := BASS_ChannelGetData(chan, @buf16, 100000); b := b div 2; a := b; while (a > 0) and (Abs(buf16[a - 1]) <= (threshold div 2)) do a := a - 1; if a > 0 then begin count := pos + (a * 4); Break; end; end; EndPoint := Count; BASS_StreamFree(chan); end;
Procedure Load_File(FileName : String) begin
if FRemoveSilence then begin if Use_Floatingpoint then Get_SilenceLength_32Bit(Pchar(FileName), 500, Start_Point, End_Point) else Get_SilenceLength_16Bit(Pchar(FileName), 500, Start_Point, End_Point); end;
procedure SongEndSync(SyncHandle : HSYNC; Channel, data, user : DWORD); stdcall; var pos : Qword; begin with AudioPlayer do begin BASS_ChannelStop(Channel_Song); Player_State:= ENGINE_SONG_END; end; end;
procedure TAudioEngine.Play(); begin
if BASS_ChannelPlay(Channel_Song, true) then begin
if FRemoveSilence then begin BASS_ChannelRemoveSync(Channel_Song, SyncEnd); BASS_ChannelSetPosition(Channel_Song, Start_Point); SyncEnd:= BASS_ChannelSetSync(Channel_Song, BASS_SYNC_POS or BASS_SYNC_MIXTIME, End_Point, @SongEndSync, 0); end else |