Created
February 29, 2020 04:03
-
-
Save HemulGM/5bfa71fc68a3f114426af2248cc77e6e to your computer and use it in GitHub Desktop.
Convert Wav To Ogg
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
uses | |
bass, bassenc; | |
function ConvertWavToOgg(var Target: string; DeleteSource: Boolean): Boolean; | |
var | |
Stream: HSTREAM; | |
Encode: HENCODE; | |
Cmd, Old: string; | |
Bytes: TByteArray; | |
begin | |
Result := False; | |
Old := Target; | |
Stream := BASS_StreamCreateFile(False, PAnsiChar(AnsiString(Old)), 0, 0, BASS_STREAM_DECODE); | |
Target := StringReplace(Old, '.wav', '.ogg', [rfIgnoreCase, rfReplaceAll]); | |
FileClose(FileCreate(Target)); | |
Cmd := ExtractFilePath(Application.ExeName) + 'oggenc2.exe -o "' | |
+ Target + '" -'; | |
Encode := BASS_Encode_Start(Stream, PAnsiChar(AnsiString(Cmd)), BASS_ENCODE_AUTOFREE, nil, nil); | |
while (BASS_ChannelIsActive(Stream) <> BASS_ACTIVE_STOPPED) and (BASS_Encode_IsActive(Encode) <> | |
BASS_ACTIVE_STOPPED) do | |
begin | |
BASS_ChannelGetData(Stream, @Bytes, SizeOf(Bytes)); | |
Result := True; | |
end; | |
BASS_StreamFree(Stream); | |
if DeleteSource then | |
DeleteFile(Old); | |
end; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment