FUNCTION ConvertToWav(
const SourceDsn,DestDsn:
String):Boolean;
const
BSD=BASS_STREAM_DECODE
or BASS_UNICODE;
BMD=BASS_MUSIC_DECODE
or BASS_UNICODE;
BES=BASS_ENCODE_PCM
or BASS_ENCODE_FP_16BIT
or BASS_Encode_AutoFree;
MSC=BASS_SAMPLE_FLOAT
or BASS_STREAM_DECODE;
var Stream,Mixer,Channel,Flags:DWord; Buf:
Array [0..10000]
of Byte;
begin
Stream:=0;
Mixer:=0;
Channel:=0;
try
try
if (HIWORD(BASS_GetVersion)<>BASSVERSION)
then Error(sWrongBassVersion);
if not BASS_Init(-1,44100,0,Application.Handle,
nil)
then Error(sBassInit);
Stream:=BASS_StreamCreateFile(False,PChar(SourceDsn),0,0,BSD);
if Stream=0
then Stream:=BASS_MusicLoad(False,PChar(SourceDsn),0,0,BMD,0);
if Stream=0
then Error(sBassLoad);
Mixer:=BASS_Mixer_StreamCreate(8000,1,MSC);
if Mixer=0
then Error(sMixerCreate);
Result:=BASS_Mixer_StreamAddChannelEx(Mixer,Stream,BASS_MIXER_DOWNMIX,0,0);
if not Result
then Error(sMixerAdd);
Channel:=BASS_Encode_Start(Mixer,PChar(DestDsn),BES,
nil,
nil);
if Channel=0
then Error(sEncodeStart);
while (BASS_ChannelIsActive(Channel) > 0)
do
BASS_ChannelGetData(Channel, @Buf, 10000);
except
on E:
Exception do begin
ShowMessage(E.
Message);
Result:=False;
end;
end;
finally
BASS_StreamFree(Stream);
BASS_StreamFree(Channel);
BASS_Free;
end;
end;