private void PrepareChannelsToSplit(int index, IList <int> ArrangedChannels, int channels, float vol, string file, MoggSplitFormat format, string quality, bool slave = true) { var channel_map = new int[channels == 2 ? 3 : 2]; channel_map[0] = ArrangedChannels[index]; channel_map[1] = channels == 2 ? ArrangedChannels[index + 1] : -1; if (channels == 2) { channel_map[2] = -1; } var flags = slave ? BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_SPLIT_SLAVE : BASSFlag.BASS_STREAM_DECODE; var out_stream = BassMix.BASS_Split_StreamCreate(SourceStream, flags, channel_map); var volumeFX = Bass.BASS_ChannelSetFX(out_stream, BASSFXType.BASS_FX_BFX_VOLUME, 0); var volume = new BASS_BFX_VOLUME { lChannel = 0, fVolume = vol }; Bass.BASS_FXSetParameters(volumeFX, volume); Splits.Add(out_stream); if (format == MoggSplitFormat.OGG) { var cmd = "bin\\oggenc2.exe -q" + quality + " - -o\"" + file + "\""; BassEnc.BASS_Encode_Start(out_stream, cmd, BASSEncode.BASS_ENCODE_FP_24BIT | BASSEncode.BASS_ENCODE_AUTOFREE, null, IntPtr.Zero); } else { BassEnc.BASS_Encode_Start(out_stream, file, BASSEncode.BASS_ENCODE_PCM | BASSEncode.BASS_ENCODE_AUTOFREE, null, IntPtr.Zero); } }
private bool DoSplitMogg(string folder, string StemsToSplit, MoggSplitFormat format, string quality) { var ext = "ogg"; if (format == MoggSplitFormat.WAV) { ext = "wav"; } if (!Directory.Exists(folder)) { Directory.CreateDirectory(folder); } var drums = folder + "drums." + ext; var drums1 = folder + "drums_1." + ext; var drums2 = folder + "drums_2." + ext; var drums3 = folder + "drums_3." + ext; var bass = folder + "bass." + ext; var rhythm = folder + "rhythm." + ext; var guitar = folder + "guitar." + ext; var keys = folder + "keys." + ext; var vocals = folder + "vocals." + ext; var backing = folder + "backing." + ext; var song = folder + "song." + ext; var crowd = folder + "crowd." + ext; var tracks = new List <string> { drums, drums1, drums2, drums3, bass, guitar, keys, vocals, backing, crowd }; foreach (var track in tracks) { Tools.DeleteFile(track); } try { if (!InitBass()) { return(false); } SourceStream = Bass.BASS_StreamCreateFile(Tools.GetOggStreamIntPtr(), 0, Tools.PlayingSongOggData.Length, BASSFlag.BASS_STREAM_DECODE); var info = Bass.BASS_ChannelGetInfo(SourceStream); var ArrangedChannels = ArrangeStreamChannels(info.chans, true); var isSlave = false; if (Parser.Songs[0].ChannelsDrums > 0 && (StemsToSplit.Contains("allstems") || StemsToSplit.Contains("drums"))) { switch (Parser.Songs[0].ChannelsDrums) { case 2: PrepareChannelsToSplit(0, ArrangedChannels, 2, GetStemVolume(0), drums, format, quality, false); break; case 3: PrepareChannelsToSplit(0, ArrangedChannels, 1, GetStemVolume(0), drums1, format, quality, false); PrepareChannelsToSplit(1, ArrangedChannels, 2, GetStemVolume(1), drums2, format, quality); break; case 4: PrepareChannelsToSplit(0, ArrangedChannels, 1, GetStemVolume(0), drums1, format, quality, false); PrepareChannelsToSplit(1, ArrangedChannels, 1, GetStemVolume(1), drums2, format, quality); PrepareChannelsToSplit(2, ArrangedChannels, 2, GetStemVolume(2), drums3, format, quality); break; case 5: PrepareChannelsToSplit(0, ArrangedChannels, 1, GetStemVolume(0), drums1, format, quality, false); PrepareChannelsToSplit(1, ArrangedChannels, 2, GetStemVolume(1), drums2, format, quality); PrepareChannelsToSplit(3, ArrangedChannels, 2, GetStemVolume(3), drums3, format, quality); break; case 6: PrepareChannelsToSplit(0, ArrangedChannels, 2, GetStemVolume(0), drums1, format, quality, false); PrepareChannelsToSplit(2, ArrangedChannels, 2, GetStemVolume(2), drums2, format, quality); PrepareChannelsToSplit(4, ArrangedChannels, 2, GetStemVolume(4), drums3, format, quality); break; } isSlave = true; } var channel = Parser.Songs[0].ChannelsDrums; if (Parser.Songs[0].ChannelsBass > 0 && (StemsToSplit.Contains("allstems") || StemsToSplit.Contains("bass") || StemsToSplit.Contains("rhythm"))) { PrepareChannelsToSplit(channel, ArrangedChannels, Parser.Songs[0].ChannelsBass, GetStemVolume(channel), StemsToSplit.Contains("rhythm") ? rhythm : bass, format, quality, isSlave); isSlave = true; } channel += Parser.Songs[0].ChannelsBass; if (Parser.Songs[0].ChannelsGuitar > 0 && (StemsToSplit.Contains("allstems") || StemsToSplit.Contains("guitar"))) { PrepareChannelsToSplit(channel, ArrangedChannels, Parser.Songs[0].ChannelsGuitar, GetStemVolume(channel), guitar, format, quality, isSlave); isSlave = true; } channel += Parser.Songs[0].ChannelsGuitar; if (Parser.Songs[0].ChannelsVocals > 0 && (StemsToSplit.Contains("allstems") || StemsToSplit.Contains("vocals"))) { PrepareChannelsToSplit(channel, ArrangedChannels, Parser.Songs[0].ChannelsVocals, GetStemVolume(channel), vocals, format, quality, isSlave); isSlave = true; } channel += Parser.Songs[0].ChannelsVocals; if (Parser.Songs[0].ChannelsKeys > 0 && (StemsToSplit.Contains("allstems") || StemsToSplit.Contains("keys"))) { PrepareChannelsToSplit(channel, ArrangedChannels, Parser.Songs[0].ChannelsKeys, GetStemVolume(channel), keys, format, quality, isSlave); isSlave = true; } channel += Parser.Songs[0].ChannelsKeys; if (Parser.Songs[0].ChannelsBacking() > 0 && (StemsToSplit.Contains("allstems") || StemsToSplit.Contains("backing") || StemsToSplit.Contains("song"))) { PrepareChannelsToSplit(channel, ArrangedChannels, Parser.Songs[0].ChannelsBacking(), GetStemVolume(channel), StemsToSplit.Contains("song") ? song : backing, format, quality, isSlave); isSlave = true; } channel += Parser.Songs[0].ChannelsBacking(); if (Parser.Songs[0].ChannelsCrowd > 0 && (StemsToSplit.Contains("allstems") || StemsToSplit.Contains("crowd"))) { PrepareChannelsToSplit(channel, ArrangedChannels, Parser.Songs[0].ChannelsCrowd, GetStemVolume(channel), crowd, format, quality, isSlave); } while (true) { var buffer = new byte[20000]; var c = Bass.BASS_ChannelGetData(Splits[0], buffer, buffer.Length); if (c < 0) { break; } for (var i = 1; i < Splits.Count; i++) { while (Bass.BASS_ChannelGetData(Splits[i], buffer, buffer.Length) > 0) { } } } foreach (var split in Splits) { Bass.BASS_StreamFree(split); } UnloadLibraries(); Tools.ReleaseStreamHandle(); } catch (Exception ex) { ErrorLog.Add("Error splitting mogg file:"); ErrorLog.Add(ex.Message); foreach (var split in Splits) { Bass.BASS_StreamFree(split); } UnloadLibraries(); Tools.ReleaseStreamHandle(); return(false); } return(true); }
public bool DownmixMogg(string CON_file, string output, MoggSplitFormat format, string quality, bool doWii = false, double start = 0.0, double length = 0.0, double fadeIn = 0.0, double fadeOut = 0.0, double volume = 0.0, string stems = "allstems") { if (!ExtractDecryptMogg(CON_file, true)) { return(false); } try { if (!InitBass()) { return(false); } var BassStream = Bass.BASS_StreamCreateFile(Tools.GetOggStreamIntPtr(), 0, Tools.PlayingSongOggData.Length, BASSFlag.BASS_STREAM_DECODE); var channel_info = Bass.BASS_ChannelGetInfo(BassStream); var BassMixer = BassMix.BASS_Mixer_StreamCreate(doWii ? 22050 : channel_info.freq, 2, BASSFlag.BASS_MIXER_END | BASSFlag.BASS_STREAM_DECODE); if (doWii) { BassMix.BASS_Mixer_StreamAddChannelEx(BassMixer, BassStream, BASSFlag.BASS_MIXER_MATRIX, 0, Bass.BASS_ChannelSeconds2Bytes(BassMixer, length)); var track_vol = (float)Utils.DBToLevel(Convert.ToDouble(volume), 1.0); Bass.BASS_ChannelSetPosition(BassStream, Bass.BASS_ChannelSeconds2Bytes(BassStream, start)); BASS_MIXER_NODE[] nodes = { new BASS_MIXER_NODE(0, 0), new BASS_MIXER_NODE(Bass.BASS_ChannelSeconds2Bytes(BassMixer, fadeIn), track_vol), new BASS_MIXER_NODE(Bass.BASS_ChannelSeconds2Bytes(BassMixer, length - fadeOut),track_vol), new BASS_MIXER_NODE(Bass.BASS_ChannelSeconds2Bytes(BassMixer, length), 0) }; BassMix.BASS_Mixer_ChannelSetEnvelope(BassStream, BASSMIXEnvelope.BASS_MIXER_ENV_VOL, nodes, nodes.Count()); } else { BassMix.BASS_Mixer_StreamAddChannel(BassMixer, BassStream, BASSFlag.BASS_MIXER_MATRIX); } var matrix = GetChannelMatrix(Parser.Songs[0], channel_info.chans, stems); BassMix.BASS_Mixer_ChannelSetMatrix(BassStream, matrix); var output_file = output; if (string.IsNullOrWhiteSpace(output)) { output_file = Path.GetDirectoryName(CON_file) + "\\" + Parser.Songs[0].InternalName + (format == MoggSplitFormat.WAV ? ".wav" : ".ogg"); } if (format == MoggSplitFormat.OGG) { var cmd = "bin\\oggenc2.exe -q" + quality + " - -o\"" + output_file + "\""; BassEnc.BASS_Encode_Start(BassMixer, cmd, BASSEncode.BASS_ENCODE_FP_24BIT | BASSEncode.BASS_ENCODE_AUTOFREE, null, IntPtr.Zero); } else { BassEnc.BASS_Encode_Start(BassMixer, output_file, BASSEncode.BASS_ENCODE_PCM | BASSEncode.BASS_ENCODE_AUTOFREE, null, IntPtr.Zero); } while (true) { var buffer = new byte[20000]; var c = Bass.BASS_ChannelGetData(BassMixer, buffer, buffer.Length); if (c < 0) { break; } } UnloadLibraries(); Tools.ReleaseStreamHandle(); return(File.Exists(output_file)); } catch (Exception ex) { ErrorLog.Add("Error downmixing mogg file:"); ErrorLog.Add(ex.Message); UnloadLibraries(); Tools.ReleaseStreamHandle(); return(false); } }
public bool SplitMogg(string CON_file, string output_folder, string StemsToSplit, MoggSplitFormat format, string quality) { return(ExtractDecryptMogg(CON_file, false) && DoSplitMogg(output_folder, StemsToSplit, format, quality)); }
public bool DownmixMogg(string CON_file, string output, MoggSplitFormat format, string quality, string stems) { return(DownmixMogg(CON_file, output, format, quality, false, 0.0, 0.0, 0.0, 0.0, 0.0, stems)); }