Ejemplo n.º 1
0
        public static FabfilterProQ2 Convert2FabfilterProQ2(float[] floatParameters, bool isIEEE = true)
        {
            var preset = new FabfilterProQ2();

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

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

                for (int i = 0; i < 24; i++)
                {
                    if (i < Bands.Count)
                    {
                        binFile.Write((float)(Bands[i].Enabled ? 1 : 0));
                        binFile.Write((float)(1)); // unknown 1
                        binFile.Write((float)FabfilterProQ2.FreqConvert(Bands[i].Frequency));
                        binFile.Write((float)Bands[i].Gain);
                        binFile.Write((float)Bands[i].DynamicRange);
                        binFile.Write((float)(1)); // unknown 3
                        binFile.Write((float)Bands[i].DynamicThreshold);
                        binFile.Write((float)FabfilterProQ2.QConvert(Bands[i].Q));
                        binFile.Write((float)Bands[i].Shape);
                        binFile.Write((float)Bands[i].Slope);
                        binFile.Write((float)Bands[i].StereoPlacement);
                        binFile.Write((float)(1)); // unknown 5
                        binFile.Write((float)(0)); // unknown 6
                    }
                    else
                    {
                        binFile.Write((float)0);
                        binFile.Write((float)(1));  // unknown 1
                        binFile.Write((float)FabfilterProQ2.FreqConvert(1000));
                        binFile.Write((float)0);    // gain
                        binFile.Write((float)0);    // dynamic range
                        binFile.Write((float)(1));  // unknown 3
                        binFile.Write((float)(1));  // dynamic threshold
                        binFile.Write((float)FabfilterProQ2.QConvert(1));
                        binFile.Write((float)ProQ2Shape.Bell);
                        binFile.Write((float)ProQSlope.Slope24dB_oct);
                        binFile.Write((float)ProQ2StereoPlacement.Stereo);
                        binFile.Write((float)(1));  // unknown 5
                        binFile.Write((float)(0));  // unknown 6
                    }
                }

                // write the remaining floats
                foreach (var fUnknown in UnknownParameters)
                {
                    binFile.Write((float)fUnknown); // unknown
                }
            }

            return(memStream.ToArray());
        }
Ejemplo n.º 3
0
        public static SteinbergFrequency ToSteinbergFrequency(this FabfilterProQ2 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 == ProQ2Shape.LowCut);
            bool hasHighCutBand = eq.Bands.Any(band => band.Shape == ProQ2Shape.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 != ProQ2Shape.LowCut)
                           .Where(b => b.Shape != ProQ2Shape.HighCut)
                           .OrderBy(s => s.Frequency);

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

                SetBand(lowCutBand, bandNumber, frequency);
            }

            if (hasHighCutBand)
            {
                int bandNumber  = 8;
                var highCutBand = eq.Bands.Where(band => band.Shape == ProQ2Shape.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);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Initialize the class specific variables using float parameters
        /// </summary>
        public void InitFromParameters(float[] floatParameters, bool isIEEE = true)
        {
            this.Bands = new List <ProQ2Band>();

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

            int index = 0;

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

                // 1 = Enabled, 2 = Disabled
                band.Enabled = floatArray[index++] == 1 ? true : false;

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

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

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

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

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

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

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

                case (float)ProQ2Shape.BandPass:
                    band.Shape = ProQ2Shape.BandPass;
                    break;

                case (float)ProQ2Shape.TiltShelf:
                    band.Shape = ProQ2Shape.TiltShelf;
                    break;

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

                // 0 - 8
                var filterSlope = floatArray[index++];
                switch (filterSlope)
                {
                case (float)ProQSlope.Slope6dB_oct:
                    band.Slope = ProQSlope.Slope6dB_oct;
                    break;

                case (float)ProQSlope.Slope12dB_oct:
                    band.Slope = ProQSlope.Slope12dB_oct;
                    break;

                case (float)ProQSlope.Slope18dB_oct:
                    band.Slope = ProQSlope.Slope18dB_oct;
                    break;

                case (float)ProQSlope.Slope24dB_oct:
                    band.Slope = ProQSlope.Slope24dB_oct;
                    break;

                case (float)ProQSlope.Slope30dB_oct:
                    band.Slope = ProQSlope.Slope30dB_oct;
                    break;

                case (float)ProQSlope.Slope36dB_oct:
                    band.Slope = ProQSlope.Slope36dB_oct;
                    break;

                case (float)ProQSlope.Slope48dB_oct:
                    band.Slope = ProQSlope.Slope48dB_oct;
                    break;

                case (float)ProQSlope.Slope72dB_oct:
                    band.Slope = ProQSlope.Slope72dB_oct;
                    break;

                case (float)ProQSlope.Slope96dB_oct:
                    band.Slope = ProQSlope.Slope96dB_oct;
                    break;

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

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

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

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

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

                this.Bands.Add(band);
            }

            // read the remaining floats
            try
            {
                this.ProcessingMode       = floatArray[index++];         // Zero Latency: 0.0, Natural Phase: 1.0, Linear Phase: 2.0
                this.ProcessingResolution = floatArray[index++];         // 0 - 4, Medium
                this.ChannelMode          = floatArray[index++];         // 0 = Left/Right, 1 = Mid/Side
                this.GainScale            = floatArray[index++];         // 100%
                this.OutputLevel          = floatArray[index++];         // 0.0 dB, -1 to 1 (- Infinity to +36 dB , 0 = 0 dB)
                this.OutputPan            = floatArray[index++];         // Left 0 dB, Right: 0 dB, -1 to 1 (0 = middle)
                this.ByPass                     = floatArray[index++];   // Not Bypassed
                this.OutputInvertPhase          = floatArray[index++];   // Normal
                this.AutoGain                   = floatArray[index++];   // Off
                this.AnalyzerShowPreProcessing  = floatArray[index++];   // Disabled - 0: Off, 1: On
                this.AnalyzerShowPostProcessing = floatArray[index++];   // Disabled - 0: Off, 1: On
                this.AnalyzerShowSidechain      = floatArray[index++];   // Disabled - 0: Off, 1: On
                this.AnalyzerRange              = floatArray[index++];   // Analyzer Range in dB. 0.0: 60dB, 1.0: 90dB, 2.0: 120dB
                this.AnalyzerResolution         = floatArray[index++];   // Analyzer Resolution. 0.0: Low, 1.0: Medium, 2.0: High, 3.00: Maximum
                this.AnalyzerSpeed              = floatArray[index++];   // Analyzer Speed. 0.0: Very Slow, 1.0: Slow, 2.0: Medium, 3.0 Fast, 4.0: Very Fast
                this.AnalyzerTilt               = floatArray[index++];   // Analyzer Tilt in dB/oct. 0.0: 0.0, 1.0: 1.5, 2.0: 3.0, 3.0: 4.5, 4.0: 6.0
                this.AnalyzerFreeze             = floatArray[index++];   // 0: Off, 1: On
                this.SpectrumGrab               = floatArray[index++];   // Enabled
                this.DisplayRange               = floatArray[index++];   // 12dB
                this.ReceiveMidi                = floatArray[index++];   // Enabled
                this.SoloBand                   = floatArray[index++];   // -1, -1 to 1
                this.SoloGain                   = floatArray[index++];   // 0.00, -1 to 1
            }
            catch { }

            // check if mid/side
            if (this.ChannelMode == 1)
            {
                this.Bands.ForEach(b => b.ChannelMode = ProQ2ChannelMode.MidSide);
            }
        }
Ejemplo n.º 5
0
        private byte[] GetBandsContent()
        {
            var memStream = new MemoryStream();

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

                for (int i = 0; i < 24; i++)
                {
                    if (i < Bands.Count)
                    {
                        binFile.Write((float)(Bands[i].Enabled ? 1 : 2));
                        binFile.Write((float)FabfilterProQ2.FreqConvert(Bands[i].Frequency));
                        binFile.Write((float)Bands[i].Gain);
                        binFile.Write((float)FabfilterProQ2.QConvert(Bands[i].Q));
                        binFile.Write((float)Bands[i].Shape);
                        binFile.Write((float)Bands[i].Slope);
                        binFile.Write((float)Bands[i].StereoPlacement);
                    }
                    else
                    {
                        binFile.Write((float)2);
                        binFile.Write((float)FabfilterProQ2.FreqConvert(1000));
                        binFile.Write((float)0);
                        binFile.Write((float)FabfilterProQ2.QConvert(1));
                        binFile.Write((float)ProQ2Shape.Bell);
                        binFile.Write((float)ProQSlope.Slope24dB_oct);
                        binFile.Write((float)ProQ2StereoPlacement.Stereo);
                    }
                }

                // write the remaining floats
                binFile.Write((float)ProcessingMode);               // Zero Latency: 0.0, Natural Phase: 1.0, Linear Phase: 2.0
                binFile.Write((float)ProcessingResolution);         // 0 - 4, Medium
                binFile.Write((float)ChannelMode);                  // 0 = Left/Right, 1 = Mid/Side
                binFile.Write((float)GainScale);                    // 100%
                binFile.Write((float)OutputLevel);                  // 0.0 dB, -1 to 1 (- Infinity to +36 dB , 0 = 0 dB)
                binFile.Write((float)OutputPan);                    // Left 0 dB, Right: 0 dB, -1 to 1 (0 = middle)
                binFile.Write((float)ByPass);                       // Not Bypassed
                binFile.Write((float)OutputInvertPhase);            // Normal
                binFile.Write((float)AutoGain);                     // Off
                binFile.Write((float)AnalyzerShowPreProcessing);    // Disabled - 0: Off, 1: On
                binFile.Write((float)AnalyzerShowPostProcessing);   // Disabled - 0: Off, 1: On
                binFile.Write((float)AnalyzerShowSidechain);        // Disabled - 0: Off, 1: On
                binFile.Write((float)AnalyzerRange);                // Analyzer Range in dB. 0.0: 60dB, 1.0: 90dB, 2.0: 120dB
                binFile.Write((float)AnalyzerResolution);           // Analyzer Resolution. 0.0: Low, 1.0: Medium, 2.0: High, 3.00: Maximum
                binFile.Write((float)AnalyzerSpeed);                // Analyzer Speed. 0.0: Very Slow, 1.0: Slow, 2.0: Medium, 3.0 Fast, 4.0: Very Fast
                binFile.Write((float)AnalyzerTilt);                 // Analyzer Tilt in dB/oct. 0.0: 0.0, 1.0: 1.5, 2.0: 3.0, 3.0: 4.5, 4.0: 6.0
                binFile.Write((float)AnalyzerFreeze);               // 0: Off, 1: On
                binFile.Write((float)SpectrumGrab);                 // Enabled
                binFile.Write((float)DisplayRange);                 // 12dB
                binFile.Write((float)ReceiveMidi);                  // Enabled
                binFile.Write((float)SoloBand);                     // -1
                binFile.Write((float)SoloGain);                     // 0.00

                // Don't write the ex fields
                // binFile.Write((float)ExAutoGain);                   // (Other)
            }

            return(memStream.ToArray());
        }
Ejemplo n.º 6
0
        /// <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);
        }
Ejemplo n.º 7
0
        /// <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);
        }