Exemple #1
0
        public static FabfilterProQ Convert2FabfilterProQ(float[] floatParameters, bool isIEEE = true)
        {
            var preset = new FabfilterProQ();

            preset.InitFromParameters(floatParameters, isIEEE);
            return(preset);
        }
Exemple #2
0
        private byte[] GetBandsContent()
        {
            var memStream = new MemoryStream();

            using (BinaryFile binFile = new BinaryFile(memStream, BinaryFile.ByteOrder.LittleEndian, Encoding.ASCII))
            {
                binFile.Write((int)Bands.Count * 7 + 12);

                // How many bands are enabled?
                var enabledBandCount = Bands.Count(b => b.Enabled);
                binFile.Write((float)enabledBandCount);

                for (int i = 0; i < 24; i++)
                {
                    if (i < Bands.Count)
                    {
                        binFile.Write((float)FabfilterProQ.FreqConvert(Bands[i].Frequency));
                        binFile.Write((float)Bands[i].Gain);
                        binFile.Write((float)FabfilterProQ.QConvert(Bands[i].Q));
                        binFile.Write((float)Bands[i].Shape);
                        binFile.Write((float)Bands[i].LPHPSlope);
                        binFile.Write((float)Bands[i].StereoPlacement);
                        binFile.Write((float)1);
                    }
                    else
                    {
                        binFile.Write((float)FabfilterProQ.FreqConvert(1000));
                        binFile.Write((float)0);
                        binFile.Write((float)FabfilterProQ.QConvert(1));
                        binFile.Write((float)ProQShape.Bell);
                        binFile.Write((float)ProQLPHPSlope.Slope24dB_oct);
                        binFile.Write((float)ProQStereoPlacement.Stereo);
                        binFile.Write((float)1);
                    }
                }

                binFile.Write((float)OutputGain);           // -1 to 1 (- Infinity to +36 dB , 0 = 0 dB)
                binFile.Write((float)OutputPan);            // -1 to 1 (0 = middle)
                binFile.Write((float)DisplayRange);         // 0 = 6dB, 1 = 12dB, 2 = 30dB, 3 = 3dB
                binFile.Write((float)ProcessMode);          // 0 = zero latency, 1 = lin.phase.low - medium - high - maximum
                binFile.Write((float)ChannelMode);          // 0 = Left/Right, 1 = Mid/Side
                binFile.Write((float)Bypass);               // 0 = No bypass
                binFile.Write((float)ReceiveMidi);          // 0 = Enabled?
                binFile.Write((float)Analyzer);             // 0 = Off, 1 = Pre, 2 = Post, 3 = Pre+Post
                binFile.Write((float)AnalyzerResolution);   // float ;  // 0 - 3 : low - medium[x] - high - maximum
                binFile.Write((float)AnalyzerSpeed);        // 0 - 3 : very slow, slow, medium[x], fast
                binFile.Write((float)SoloBand);             // -1
            }

            return(memStream.ToArray());
        }
Exemple #3
0
        public static SteinbergFrequency ToSteinbergFrequency(this FabfilterProQ eq)
        {
            var frequency = new SteinbergFrequency();

            // Frequency only support lowcut on the 1st band and highcut on the 8th band
            bool hasLowCutBand  = eq.Bands.Any(band => band.Shape == ProQShape.LowCut);
            bool hasHighCutBand = eq.Bands.Any(band => band.Shape == ProQShape.HighCut);

            // get remaining bands that are not lowcut or highcut and sort by frequency
            var band2To7 = eq.Bands.Where(b => b.Enabled)
                           .Where(b => b.Shape != ProQShape.LowCut)
                           .Where(b => b.Shape != ProQShape.HighCut)
                           .OrderBy(s => s.Frequency);

            if (hasLowCutBand)
            {
                int bandNumber = 1;
                var lowCutBand = eq.Bands.Where(band => band.Shape == ProQShape.LowCut)
                                 .OrderBy(s => s.Frequency).ElementAt(0);

                SetBand(lowCutBand, bandNumber, frequency);
            }

            if (hasHighCutBand)
            {
                int bandNumber  = 8;
                var highCutBand = eq.Bands.Where(band => band.Shape == ProQShape.HighCut)
                                  .OrderByDescending(s => s.Frequency).ElementAt(0);

                SetBand(highCutBand, bandNumber, frequency);
            }

            // rest of the bands (2-7)
            int startIndex = hasLowCutBand ? 2 : 1;
            int endIndex   = hasHighCutBand ? 7 : 8;
            int index      = 0;

            for (int bandNumber = startIndex; bandNumber <= endIndex; bandNumber++, index++)
            {
                var band = band2To7.ElementAtOrDefault(index);
                SetBand(band, bandNumber, frequency);
            }

            return(frequency);
        }
Exemple #4
0
        /// <summary>
        /// Initialize the class specific variables using float parameters
        /// </summary>
        public void InitFromParameters(float[] floatParameters, bool isIEEE = true)
        {
            this.Bands = new List <ProQBand>();

            float[] floatArray;
            if (isIEEE)
            {
                // convert the ieee float parameters to fabfilter floats
                floatArray = Convert2FabfilterProQFloats(floatParameters);
            }
            else
            {
                floatArray = floatParameters;
            }

            int index = 0;

            // Read in how many bands are enabled
            var numActiveBands = floatArray[index++]; // Number of active bands

            for (int i = 0; i < 24; i++)
            {
                var band = new ProQBand();

                band.Frequency = FabfilterProQ.FreqConvertBack(floatArray[index++]);
                band.Gain      = floatArray[index++]; // actual gain in dB
                band.Q         = FabfilterProQ.QConvertBack(floatArray[index++]);

                // filter type: 0 - 5
                var filterType = floatArray[index++];
                switch (filterType)
                {
                case (float)ProQShape.Bell:
                    band.Shape = ProQShape.Bell;
                    break;

                case (float)ProQShape.LowShelf:
                    band.Shape = ProQShape.LowShelf;
                    break;

                case (float)ProQShape.LowCut:
                    band.Shape = ProQShape.LowCut;
                    break;

                case (float)ProQShape.HighShelf:
                    band.Shape = ProQShape.HighShelf;
                    break;

                case (float)ProQShape.HighCut:
                    band.Shape = ProQShape.HighCut;
                    break;

                case (float)ProQShape.Notch:
                    band.Shape = ProQShape.Notch;
                    break;

                default:
                    throw new ArgumentOutOfRangeException(string.Format("Filter type is outside range: {0}", filterType));
                }

                // filterSlope: 0 - 3
                var filterSlope = floatArray[index++];
                switch (filterSlope)
                {
                case (float)ProQLPHPSlope.Slope6dB_oct:
                    band.LPHPSlope = ProQLPHPSlope.Slope6dB_oct;
                    break;

                case (float)ProQLPHPSlope.Slope12dB_oct:
                    band.LPHPSlope = ProQLPHPSlope.Slope12dB_oct;
                    break;

                case (float)ProQLPHPSlope.Slope24dB_oct:
                    band.LPHPSlope = ProQLPHPSlope.Slope24dB_oct;
                    break;

                case (float)ProQLPHPSlope.Slope48dB_oct:
                    band.LPHPSlope = ProQLPHPSlope.Slope48dB_oct;
                    break;

                default:
                    throw new ArgumentOutOfRangeException(string.Format("Filter slope is outside range: {0}", filterSlope));
                }

                // stereo placement: 0 = Left, 1 = Right, 2 = Stereo
                var filterStereoPlacement = floatArray[index++];
                switch (filterStereoPlacement)
                {
                case (float)ProQStereoPlacement.LeftOrMid:
                    band.StereoPlacement = ProQStereoPlacement.LeftOrMid;
                    break;

                case (float)ProQStereoPlacement.RightOrSide:
                    band.StereoPlacement = ProQStereoPlacement.RightOrSide;
                    break;

                case (float)ProQStereoPlacement.Stereo:
                    band.StereoPlacement = ProQStereoPlacement.Stereo;
                    break;

                default:
                    throw new ArgumentOutOfRangeException(string.Format("Filter stereo placement is outside range: {0}", filterStereoPlacement));
                }

                // enabled band: always 1.0
                var unknown = floatArray[index++];

                // check if band is enabled
                if (numActiveBands > 0 && numActiveBands > i)
                {
                    band.Enabled = true;
                }

                this.Bands.Add(band);
            }

            // read the remaining floats
            try
            {
                this.OutputGain         = floatArray[index++];   // -1 to 1 (- Infinity to +36 dB , 0 = 0 dB)
                this.OutputPan          = floatArray[index++];   // -1 to 1 (0 = middle)
                this.DisplayRange       = floatArray[index++];   // 0 = 6dB, 1 = 12dB, 2 = 30dB, 3 = 3dB
                this.ProcessMode        = floatArray[index++];   // 0 = zero latency, 1 = lin.phase.low - medium - high - maximum
                this.ChannelMode        = floatArray[index++];   // 0 = Left/Right, 1 = Mid/Side
                this.Bypass             = floatArray[index++];   // 0 = No bypass
                this.ReceiveMidi        = floatArray[index++];   // 0 = Enabled?
                this.Analyzer           = floatArray[index++];   // 0 = Off, 1 = Pre, 2 = Post, 3 = Pre+Post
                this.AnalyzerResolution = floatArray[index++];   // 0 - 3 : low - medium[x] - high - maximum
                this.AnalyzerSpeed      = floatArray[index++];   // 0 - 3 : very slow, slow, medium[x], fast
                this.SoloBand           = floatArray[index++];   // -1
            }
            catch { }

            // check if mid/side
            if (this.ChannelMode == 1)
            {
                this.Bands.ForEach(b => b.ChannelMode = ProQChannelMode.MidSide);
            }
        }
        public static FabfilterProQ ToFabfilterProQ(this REWEQFilters filters)
        {
            var preset = new FabfilterProQ();

            preset.Version = 2;
            preset.Bands   = new List <ProQBand>();

            foreach (REWEQBand filter in filters)
            {
                var band = new ProQBand();
                band.Frequency = filter.FilterFreq;
                band.Gain      = filter.FilterGain;
                band.Q         = filter.FilterQ;
                band.Enabled   = filter.Enabled;
                switch (filter.FilterType)
                {
                case REWEQFilterType.PK:
                    band.Shape = ProQShape.Bell;
                    break;

                case REWEQFilterType.LP:
                    band.Shape = ProQShape.HighCut;
                    break;

                case REWEQFilterType.HP:
                    band.Shape = ProQShape.LowCut;
                    break;

                case REWEQFilterType.LS:
                    band.Shape = ProQShape.LowShelf;
                    break;

                case REWEQFilterType.HS:
                    band.Shape = ProQShape.HighShelf;
                    break;

                default:
                    band.Shape = ProQShape.Bell;
                    break;
                }
                band.LPHPSlope       = ProQLPHPSlope.Slope24dB_oct;
                band.StereoPlacement = ProQStereoPlacement.Stereo;

                preset.Bands.Add(band);
            }

            // Add empty bands
            for (int i = preset.Bands.Count; i < 24; i++)
            {
                var band = new ProQBand();

                band.Frequency       = FabfilterProQ.FreqConvert(1000);
                band.Gain            = 0;
                band.Q               = FabfilterProQ.QConvert(1);
                band.Enabled         = true;
                band.Shape           = ProQShape.Bell;
                band.LPHPSlope       = ProQLPHPSlope.Slope24dB_oct;
                band.StereoPlacement = ProQStereoPlacement.Stereo;

                preset.Bands.Add(band);
            }

            preset.OutputGain         = 0;  // -1 to 1 (- Infinity to +36 dB , 0 = 0 dB)
            preset.OutputPan          = 0;  // -1 to 1 (0 = middle)
            preset.DisplayRange       = 2;  // 0 = 6dB, 1 = 12dB, 2 = 30dB, 3 = 3dB
            preset.ProcessMode        = 0;  // 0 = zero latency, 1 = lin.phase.low - medium - high - maximum
            preset.ChannelMode        = 0;  // 0 = Left/Right, 1 = Mid/Side
            preset.Bypass             = 0;  // 0 = No bypass
            preset.ReceiveMidi        = 0;  // 0 = Enabled?
            preset.Analyzer           = 3;  // 0 = Off, 1 = Pre, 2 = Post, 3 = Pre+Post
            preset.AnalyzerResolution = 1;  // 0 - 3 : low - medium[x] - high - maximum
            preset.AnalyzerSpeed      = 2;  // 0 - 3 : very slow, slow, medium[x], fast
            preset.SoloBand           = -1; // -1

            return(preset);
        }
        /// <summary>
        /// Initialize a VstPreset using a byte array and guid
        /// </summary>
        /// <param name="presetBytes">preset bytes</param>
        /// <param name="guid">plugin guid</param>
        /// <param name="pluginName">optional plugin name (only used for error messages)</param>
        /// <returns>a VstPreset object</returns>
        public static T GetVstPreset <T>(byte[] presetBytes, string guid, string pluginName = null) where T : VstPreset
        {
            VstPreset preset = null;

            switch (guid)
            {
            case VstPreset.VstIDs.SteinbergCompressor:
                preset = new SteinbergCompressor();
                break;

            case VstPreset.VstIDs.SteinbergFrequency:
                preset = new SteinbergFrequency();
                break;

            case VstPreset.VstIDs.SteinbergREVerence:
                preset = new SteinbergREVerence();
                break;

            case VstPreset.VstIDs.FabFilterProQ:
            case VstPreset.VstIDs.FabFilterProQx64:
                preset        = new FabfilterProQ();
                preset.Vst3ID = guid;
                break;

            case VstPreset.VstIDs.FabFilterProQ2:
            case VstPreset.VstIDs.FabFilterProQ2x64:
                preset        = new FabfilterProQ2();
                preset.Vst3ID = guid;
                break;

            case VstPreset.VstIDs.NIKontakt5:
                preset = new NIKontakt5();
                break;

            case VstPreset.VstIDs.NIKontakt6:
                preset = new NIKontakt6();
                break;

            case VstPreset.VstIDs.NIKontakt6_64out:
                preset = new NIKontakt6_64out();
                break;

            case VstPreset.VstIDs.EastWestPlay:
                preset = new EastWestPlay();
                break;

            default:
                preset        = new SteinbergVstPreset();
                preset.Vst3ID = guid;
                break;
            }

            preset.Parameters.Clear();
            preset.CompDataStartPos  = 0;
            preset.CompDataChunkSize = presetBytes.Length;
            preset.ContDataStartPos  = presetBytes.Length;
            preset.ContDataChunkSize = 0;
            preset.InfoXmlStartPos   = presetBytes.Length;

            try
            {
                preset.ReadData(new BinaryFile(presetBytes, BinaryFile.ByteOrder.LittleEndian, Encoding.ASCII), (UInt32)presetBytes.Length, false);

                if (preset.Vst3ID == VstPreset.VstIDs.SteinbergREVerence)
                {
                    // init wave paths and images from the parameters
                    var reverence = preset as SteinbergREVerence;
                    reverence.InitFromParameters();
                }

                else if (preset.Vst3ID == VstPreset.VstIDs.FabFilterProQ ||
                         preset.Vst3ID == VstPreset.VstIDs.FabFilterProQx64)
                {
                    // init variables from the parameters or FXP object
                    var fabFilterProQ = preset as FabfilterProQ;
                    fabFilterProQ.InitFromParameters();
                }

                else if (preset.Vst3ID == VstPreset.VstIDs.FabFilterProQ2 ||
                         preset.Vst3ID == VstPreset.VstIDs.FabFilterProQ2x64)
                {
                    // init variables from the parameters or FXP object
                    var fabFilterProQ2 = preset as FabfilterProQ2;
                    fabFilterProQ2.InitFromParameters();
                }

                else if (preset.Vst3ID == VstPreset.VstIDs.FabFilterProQ3)
                {
                    // init variables from the parameters or FXP object
                    var fabFilterProQ3 = preset as FabfilterProQ3;
                    fabFilterProQ3.InitFromParameters();
                }
            }
            catch (System.Exception e)
            {
                Log.Error("Failed initializing VstPreset using guid: {0}{1}. (Hex dump: {2}) {3}", guid, pluginName != null ? " and name " + pluginName : "", StringUtils.ToHexEditorString(presetBytes), e.Message);
            }

            return(preset as T);
        }
        /// <summary>
        /// Initialize a VstPreset using a file
        /// </summary>
        /// <param name="file">filename</param>
        /// <returns>a VstPreset object</returns>
        public static T GetVstPreset <T>(string file) where T : VstPreset
        {
            VstPreset vstPreset = new SteinbergVstPreset(file);

            VstPreset preset = null;

            switch (vstPreset.Vst3ID)
            {
            case VstPreset.VstIDs.SteinbergCompressor:
                preset            = new SteinbergCompressor();
                preset.Parameters = vstPreset.Parameters;
                preset.FXP        = vstPreset.FXP;
                break;

            case VstPreset.VstIDs.SteinbergFrequency:
                preset            = new SteinbergFrequency();
                preset.Parameters = vstPreset.Parameters;
                preset.FXP        = vstPreset.FXP;
                break;

            case VstPreset.VstIDs.SteinbergREVerence:
                preset            = new SteinbergREVerence();
                preset.Parameters = vstPreset.Parameters;
                preset.FXP        = vstPreset.FXP;

                // init wave paths and images from the parameters
                var reverence = preset as SteinbergREVerence;
                reverence.InitFromParameters();
                break;

            case VstPreset.VstIDs.FabFilterProQ:
            case VstPreset.VstIDs.FabFilterProQx64:
                preset            = new FabfilterProQ();
                preset.Parameters = vstPreset.Parameters;
                preset.FXP        = vstPreset.FXP;

                // init variables from the parameters or FXP object
                var fabFilterProQ = preset as FabfilterProQ;
                fabFilterProQ.InitFromParameters();
                break;

            case VstPreset.VstIDs.FabFilterProQ2:
            case VstPreset.VstIDs.FabFilterProQ2x64:
                preset            = new FabfilterProQ2();
                preset.Parameters = vstPreset.Parameters;
                preset.FXP        = vstPreset.FXP;

                // init variables from the parameters or FXP object
                var fabFilterProQ2 = preset as FabfilterProQ2;
                fabFilterProQ2.InitFromParameters();

                break;

            case VstPreset.VstIDs.FabFilterProQ3:
                preset            = new FabfilterProQ3();
                preset.Parameters = vstPreset.Parameters;
                preset.FXP        = vstPreset.FXP;

                // init variables from the parameters or FXP object
                var fabFilterProQ3 = preset as FabfilterProQ3;
                fabFilterProQ3.InitFromParameters();

                break;

            case VstPreset.VstIDs.WavesSSLChannelStereo:
                VstPreset.Parameter sslChannelXml = null;
                vstPreset.Parameters.TryGetValue("XmlContent", out sslChannelXml);
                if (sslChannelXml != null && sslChannelXml.String != null)
                {
                    List <WavesSSLChannel> channelPresetList = WavesPreset.ParseXml <WavesSSLChannel>(sslChannelXml.String);

                    // a single vstpreset likely (?) only contain one waves ssl preset, use the first
                    preset            = channelPresetList.FirstOrDefault();
                    preset.Parameters = vstPreset.Parameters;
                    preset.FXP        = vstPreset.FXP;
                }
                break;

            case VstPreset.VstIDs.WavesSSLCompStereo:
                VstPreset.Parameter sslCompXml = null;
                vstPreset.Parameters.TryGetValue("XmlContent", out sslCompXml);
                if (sslCompXml != null && sslCompXml.String != null)
                {
                    List <WavesSSLComp> channelPresetList = WavesPreset.ParseXml <WavesSSLComp>(sslCompXml.String);

                    // a single vstpreset likely (?) only contain one waves ssl preset, use the first
                    preset            = channelPresetList.FirstOrDefault();
                    preset.Parameters = vstPreset.Parameters;
                    preset.FXP        = vstPreset.FXP;
                }
                break;

            case VstPreset.VstIDs.NIKontakt5:
                preset            = new NIKontakt5();
                preset.Parameters = vstPreset.Parameters;
                preset.FXP        = vstPreset.FXP;
                break;

            case VstPreset.VstIDs.EastWestPlay:
                preset            = new EastWestPlay();
                preset.Parameters = vstPreset.Parameters;
                preset.FXP        = vstPreset.FXP;
                break;

            default:
                preset = vstPreset;
                break;
            }

            preset.Vst3ID = vstPreset.Vst3ID;

            return(preset as T);
        }