private static bool EncodeFileInternal(string inputFile, string outputFile, BaseEncoder encoder, BaseEncoder.ENCODEFILEPROC proc, bool overwriteOutput, bool deleteInput, bool updateTags, double fromPos, double toPos) { if (encoder == null || (inputFile == null && encoder.ChannelHandle == 0)) { return(false); } if (toPos <= fromPos) { fromPos = -1.0; toPos = -1.0; } bool flag = false; string inputFile2 = encoder.InputFile; string outputFile2 = encoder.OutputFile; int channelHandle = encoder.ChannelHandle; int num = 0; try { if (inputFile == null) { if (encoder.ChannelHandle == 0 || encoder.ChannelInfo == null || string.IsNullOrEmpty(encoder.ChannelInfo.filename)) { return(false); } num = encoder.ChannelHandle; inputFile = encoder.ChannelInfo.filename; } else { num = Bass.BASS_StreamCreateFile(inputFile, 0L, 0L, BASSFlag.BASS_SAMPLE_FLOAT | BASSFlag.BASS_STREAM_DECODE | ((fromPos < 0.0 && toPos < 0.0) ? BASSFlag.BASS_DEFAULT : BASSFlag.BASS_STREAM_PRESCAN)); } flag = BaseEncoder.EncodeFileInternal2(num, inputFile, outputFile, encoder, proc, overwriteOutput, updateTags, Bass.BASS_ChannelSeconds2Bytes(num, fromPos), Bass.BASS_ChannelSeconds2Bytes(num, toPos)); } catch { flag = false; } finally { if (num != 0) { Bass.BASS_StreamFree(num); } encoder.InputFile = inputFile2; encoder.OutputFile = outputFile2; encoder.ChannelHandle = channelHandle; if (flag && deleteInput) { try { File.Delete(inputFile); } catch { } } } return(flag); }
private static bool EncodeFileInternal2(int stream, string inputFile, string outputFile, BaseEncoder encoder, BaseEncoder.ENCODEFILEPROC proc, bool overwriteOutput, bool updateTags, long fromPos, long toPos) { bool result = false; if (stream != 0) { long num = 0L; long num2 = Bass.BASS_ChannelGetLength(stream); if (toPos > 0L && toPos > num2) { toPos = num2; } if (updateTags) { TAG_INFO tags = new TAG_INFO(inputFile); if (BassTags.BASS_TAG_GetFromFile(stream, tags)) { encoder.TAGs = tags; } } if (num2 > 0L) { if (outputFile == null) { outputFile = Path.ChangeExtension(inputFile, encoder.DefaultOutputExtension); while (outputFile.Equals(inputFile)) { outputFile += encoder.DefaultOutputExtension; } } if (File.Exists(outputFile)) { if (!overwriteOutput) { throw new IOException(string.Format("The output file {0} already exists!", outputFile)); } File.Delete(outputFile); } encoder.InputFile = null; encoder.OutputFile = outputFile; encoder.ChannelHandle = stream; if (toPos > 0L) { num2 = toPos; } if (fromPos > 0L) { Bass.BASS_ChannelSetPosition(stream, fromPos); num2 -= fromPos; } int num3 = 262144; long num4 = toPos - fromPos; bool wma_UseNetwork = false; if (encoder is EncoderWMA) { wma_UseNetwork = ((EncoderWMA)encoder).WMA_UseNetwork; ((EncoderWMA)encoder).WMA_UseNetwork = false; } if (encoder.Start(null, IntPtr.Zero, false)) { byte[] buffer = new byte[num3]; while (Bass.BASS_ChannelIsActive(stream) == BASSActive.BASS_ACTIVE_PLAYING) { if (fromPos < 0L && toPos < 0L) { num += (long)Bass.BASS_ChannelGetData(stream, buffer, num3); if (proc != null) { proc(num2, num); } } else { int num5; if (num4 < (long)num3) { num5 = Bass.BASS_ChannelGetData(stream, buffer, (int)num4); } else { num5 = Bass.BASS_ChannelGetData(stream, buffer, num3); } num += (long)num5; num4 -= (long)num5; if (proc != null) { proc(num2, num); } if (num4 <= 0L) { break; } } } if (encoder.Stop()) { result = true; } } if (encoder is EncoderWMA) { ((EncoderWMA)encoder).WMA_UseNetwork = wma_UseNetwork; } } } return(result); }
public static bool EncodeFile(string inputFile, string outputFile, BaseEncoder encoder, BaseEncoder.ENCODEFILEPROC proc, bool overwriteOutput, bool deleteInput, bool updateTags, long fromPos, long toPos) { return(BaseEncoder.EncodeFileInternal(inputFile, outputFile, encoder, proc, overwriteOutput, deleteInput, updateTags, fromPos, toPos)); }
public static bool EncodeFile(BaseEncoder encoder, BaseEncoder.ENCODEFILEPROC proc, bool overwriteOutput, bool deleteInput, bool updateTags, double fromPos, double toPos) { return(BaseEncoder.EncodeFileInternal(encoder.InputFile, encoder.OutputFile, encoder, proc, overwriteOutput, deleteInput, updateTags, fromPos, toPos)); }
public static bool EncodeFile(BaseEncoder encoder, BaseEncoder.ENCODEFILEPROC proc, bool overwriteOutput, bool deleteInput) { return(BaseEncoder.EncodeFileInternal(encoder.InputFile, encoder.OutputFile, encoder, proc, overwriteOutput, deleteInput, false, -1L, -1L)); }