Exemplo n.º 1
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);
        }
Exemplo n.º 3
0
        public bool ReadFFP(string filePath)
        {
            BinaryFile binFile = new BinaryFile(filePath, BinaryFile.ByteOrder.LittleEndian);

            string header = binFile.ReadString(4);

            if (header != "FPQr")
            {
                return(false);
            }

            Version        = binFile.ReadInt32();
            ParameterCount = binFile.ReadInt32();

            // Read in how many bands are enabled
            var numActiveBands = binFile.ReadSingle();

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

                band.Frequency = FreqConvertBack(binFile.ReadSingle());
                band.Gain      = binFile.ReadSingle(); // actual gain in dB
                band.Q         = QConvertBack(binFile.ReadSingle());

                // 0 - 5
                var filterType = binFile.ReadSingle();
                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));
                }

                // 0 = 6 dB/oct, 1 = 12 dB/oct, 2 = 24 dB/oct, 3 = 48 dB/oct
                var filterSlope = binFile.ReadSingle();
                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));
                }

                // 0 = Left, 1 = Right, 2 = Stereo
                var filterStereoPlacement = binFile.ReadSingle();
                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));
                }

                // always 1.0 ?
                var unknown = binFile.ReadSingle();

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

                Bands.Add(band);
            }

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

            // check if mid/side
            if (ChannelMode == 1)
            {
                Bands.ForEach(b => b.ChannelMode = ProQChannelMode.MidSide);
            }

            binFile.Close();

            return(true);
        }
Exemplo n.º 4
0
        private static void SetBand(ProQBand band, int bandNumber, SteinbergFrequency frequency)
        {
            if (band != null)
            {
                frequency.Parameters[String.Format("equalizerAbandon{0}", bandNumber)].Number = band.Enabled ? 1.00 : 0.00;

                string channel = ""; // empty for main channel (channel 1). 'Ch2' for secondary channel

                // due to the way fabfilter have only one stereo placement per band (frequency has two) we need to modify both channels in frequency
                // we could have in theory instead updated both channels per band in frequency
                if (band.StereoPlacement != ProQStereoPlacement.Stereo)
                {
                    switch (band.StereoPlacement)
                    {
                    case ProQStereoPlacement.LeftOrMid:
                        frequency.Parameters[String.Format("equalizerAon{0}", bandNumber)].Number    = 1.0;
                        frequency.Parameters[String.Format("equalizerAon{0}Ch2", bandNumber)].Number = 0.0;

                        if (band.ChannelMode == ProQChannelMode.LeftRight)
                        {
                            frequency.Parameters[String.Format("equalizerAeditchannel{0}", bandNumber)].Number = SteinbergFrequency.ChannelMode.LeftRightModeLeft;
                        }
                        else
                        {
                            frequency.Parameters[String.Format("equalizerAeditchannel{0}", bandNumber)].Number = SteinbergFrequency.ChannelMode.MidSideModeMid;
                        }
                        break;

                    case ProQStereoPlacement.RightOrSide:
                        frequency.Parameters[String.Format("equalizerAon{0}", bandNumber)].Number    = 0.0;
                        frequency.Parameters[String.Format("equalizerAon{0}Ch2", bandNumber)].Number = 1.0;
                        channel = "Ch2";

                        if (band.ChannelMode == ProQChannelMode.LeftRight)
                        {
                            frequency.Parameters[String.Format("equalizerAeditchannel{0}", bandNumber)].Number = SteinbergFrequency.ChannelMode.LeftRightModeRight;
                        }
                        else
                        {
                            frequency.Parameters[String.Format("equalizerAeditchannel{0}", bandNumber)].Number = SteinbergFrequency.ChannelMode.MidSideModeSide;
                        }
                        break;

                    case ProQStereoPlacement.Stereo:
                        // don't change - this is the default
                        break;
                    }
                }

                frequency.Parameters[String.Format("equalizerAgain{0}{1}", bandNumber, channel)].Number = band.Gain;
                frequency.Parameters[String.Format("equalizerAfreq{0}{1}", bandNumber, channel)].Number = band.Frequency;
                frequency.Parameters[String.Format("equalizerAq{0}{1}", bandNumber, channel)].Number    = band.Q;

                switch (band.Shape)
                {
                case ProQShape.Bell:
                    if (bandNumber == 1 || bandNumber == 8)
                    {
                        frequency.Parameters[String.Format("equalizerAtype{0}{1}", bandNumber, channel)].Number = SteinbergFrequency.BandMode1And8.Peak;
                    }
                    else
                    {
                        frequency.Parameters[String.Format("equalizerAtype{0}{1}", bandNumber, channel)].Number = SteinbergFrequency.BandMode2To7.Peak;
                    }
                    break;

                case ProQShape.LowShelf:
                    if (bandNumber == 1 || bandNumber == 8)
                    {
                        frequency.Parameters[String.Format("equalizerAtype{0}{1}", bandNumber, channel)].Number = SteinbergFrequency.BandMode1And8.LowShelf;
                    }
                    else
                    {
                        frequency.Parameters[String.Format("equalizerAtype{0}{1}", bandNumber, channel)].Number = SteinbergFrequency.BandMode2To7.LowShelf;
                    }
                    break;

                case ProQShape.LowCut:
                    switch (band.LPHPSlope)
                    {
                    case ProQLPHPSlope.Slope6dB_oct:
                        frequency.Parameters[String.Format("equalizerAtype{0}{1}", bandNumber, channel)].Number = SteinbergFrequency.BandMode1And8.Cut6;
                        break;

                    case ProQLPHPSlope.Slope12dB_oct:
                        frequency.Parameters[String.Format("equalizerAtype{0}{1}", bandNumber, channel)].Number = SteinbergFrequency.BandMode1And8.Cut12;
                        break;

                    case ProQLPHPSlope.Slope24dB_oct:
                        frequency.Parameters[String.Format("equalizerAtype{0}{1}", bandNumber, channel)].Number = SteinbergFrequency.BandMode1And8.Cut24;
                        break;

                    case ProQLPHPSlope.Slope48dB_oct:
                        frequency.Parameters[String.Format("equalizerAtype{0}{1}", bandNumber, channel)].Number = SteinbergFrequency.BandMode1And8.Cut48;
                        break;
                    }
                    break;

                case ProQShape.HighShelf:
                    if (bandNumber == 1 || bandNumber == 8)
                    {
                        frequency.Parameters[String.Format("equalizerAtype{0}{1}", bandNumber, channel)].Number = SteinbergFrequency.BandMode1And8.HighShelf;
                    }
                    else
                    {
                        frequency.Parameters[String.Format("equalizerAtype{0}{1}", bandNumber, channel)].Number = SteinbergFrequency.BandMode2To7.HighShelf;
                    }
                    break;

                case ProQShape.HighCut:
                    switch (band.LPHPSlope)
                    {
                    case ProQLPHPSlope.Slope6dB_oct:
                        frequency.Parameters[String.Format("equalizerAtype{0}{1}", bandNumber, channel)].Number = SteinbergFrequency.BandMode1And8.Cut6;
                        break;

                    case ProQLPHPSlope.Slope12dB_oct:
                        frequency.Parameters[String.Format("equalizerAtype{0}{1}", bandNumber, channel)].Number = SteinbergFrequency.BandMode1And8.Cut12;
                        break;

                    case ProQLPHPSlope.Slope24dB_oct:
                        frequency.Parameters[String.Format("equalizerAtype{0}{1}", bandNumber, channel)].Number = SteinbergFrequency.BandMode1And8.Cut24;
                        break;

                    case ProQLPHPSlope.Slope48dB_oct:
                        frequency.Parameters[String.Format("equalizerAtype{0}{1}", bandNumber, channel)].Number = SteinbergFrequency.BandMode1And8.Cut48;
                        break;
                    }
                    break;

                case ProQShape.Notch:
                    if (bandNumber == 1 || bandNumber == 8)
                    {
                        frequency.Parameters[String.Format("equalizerAtype{0}{1}", bandNumber, channel)].Number = SteinbergFrequency.BandMode1And8.Notch;
                    }
                    else
                    {
                        frequency.Parameters[String.Format("equalizerAtype{0}{1}", bandNumber, channel)].Number = SteinbergFrequency.BandMode2To7.Notch;
                    }
                    break;
                }

                Log.Debug(band.ToString());
            }
            else
            {
                // disable band
                frequency.Parameters[String.Format("equalizerAbandon{0}", bandNumber)].Number = 0.00;
            }
        }