예제 #1
0
        private FXP GenerateFXP(bool isBank)
        {
            FXP.FxContent fxpContent;
            FXP           fxp = new FXP();

            if (isBank)
            {
                // FBCh = FXB (bank)
                fxpContent = new FXP.FxChunkSet();
                ((FXP.FxChunkSet)fxpContent).NumPrograms = 1;                     // I.e. number of programs (number of presets in one file)
                ((FXP.FxChunkSet)fxpContent).Future      = new string('\0', 128); // 128 bytes long
            }
            else
            {
                // FPCh = FXP (preset)
                fxpContent = new FXP.FxProgramSet();
                ((FXP.FxProgramSet)fxpContent).NumPrograms = 1; // I.e. number of programs (number of presets in one file)
                ((FXP.FxProgramSet)fxpContent).Name        = PresetName;
            }

            fxp.Content           = fxpContent;
            fxpContent.ChunkMagic = "CcnK";
            fxpContent.ByteSize   = 0; // will be set correctly by FXP class

            // Preset (Program) (.fxp) with chunk (magic = 'FPCh')
            fxpContent.FxMagic   = isBank ? "FBCh" : "FPCh";
            fxpContent.Version   = 1; //isBank ? 2 : 1; // Format Version (should be 1)
            fxpContent.FxID      = "J9AU";
            fxpContent.FxVersion = 1;

            byte[] chunkData = GetChunkData(fxpContent.FxMagic);

            if (fxp.Content is FXP.FxProgramSet)
            {
                ((FXP.FxProgramSet)fxp.Content).ChunkSize = chunkData.Length;
                ((FXP.FxProgramSet)fxp.Content).ChunkData = chunkData;
            }
            else if (fxp.Content is FXP.FxChunkSet)
            {
                ((FXP.FxChunkSet)fxp.Content).ChunkSize = chunkData.Length;
                ((FXP.FxChunkSet)fxp.Content).ChunkData = chunkData;
            }

            return(fxp);
        }
예제 #2
0
        public static bool Convert2ReaEQ(REWEQFilters filters, string filePath)
        {
            List <ReaEQBand> ReaEqBands = new List <ReaEQBand>();

            foreach (REWEQBand filter in filters)
            {
                ReaEQBand band = new ReaEQBand();
                band.LogScaleAutoFreq = true;
                band.FilterFreq       = filter.FilterFreq;
                band.FilterGain       = filter.FilterGain;
                band.FilterBWOct      = filter.FilterBWOct;
                band.Enabled          = filter.Enabled;
                switch (filter.FilterType)
                {
                case REWEQFilterType.PK:
                    band.FilterType = ReaEQFilterType.Band;
                    break;

                case REWEQFilterType.LP:
                    band.FilterType = ReaEQFilterType.LowPass;
                    break;

                case REWEQFilterType.HP:
                    band.FilterType = ReaEQFilterType.HighPass;
                    break;

                case REWEQFilterType.LS:
                    band.FilterType = ReaEQFilterType.LowShelf;
                    break;

                case REWEQFilterType.HS:
                    band.FilterType = ReaEQFilterType.HighShelf;
                    break;

                default:
                    band.FilterType = ReaEQFilterType.Band;
                    break;
                }
                ReaEqBands.Add(band);
            }

            // store to file
            FXP fxp = new FXP();

            FXP.FxProgramSet fxpContent = new FXP.FxProgramSet();
            fxp.Content            = fxpContent;
            fxpContent.ChunkMagic  = "CcnK";
            fxpContent.ByteSize    = 0;      // will be set correctly by FXP class
            fxpContent.FxMagic     = "FPCh"; // FPCh = FXP (preset), FBCh = FXB (bank)
            fxpContent.Version     = 1;      // Format Version (should be 1)
            fxpContent.FxID        = "reeq";
            fxpContent.FxVersion   = 1100;
            fxpContent.NumPrograms = 1;
            fxpContent.Name        = "";

            using (MemoryStream memStream = new MemoryStream(10))
            {
                BinaryFile binFile = new BinaryFile(memStream, BinaryFile.ByteOrder.LittleEndian);
                binFile.Write((int)33);
                binFile.Write((int)ReaEqBands.Count);
                foreach (ReaEQBand band in ReaEqBands)
                {
                    binFile.Write((int)band.FilterType);
                    binFile.Write((int)(band.Enabled ? 1 : 0));
                    binFile.Write((double)band.FilterFreq);
                    binFile.Write((double)Decibel2AmplitudeRatio(band.FilterGain));
                    binFile.Write((double)band.FilterBWOct);
                    binFile.Write((byte)1);
                }

                binFile.Write((int)1);
                binFile.Write((int)1);

                binFile.Write((double)Decibel2AmplitudeRatio(0.00));
                binFile.Write((int)0);

                memStream.Flush();
                byte[] chunkData = memStream.GetBuffer();
                fxpContent.ChunkSize = chunkData.Length;
                fxpContent.ChunkData = chunkData;
            }

            fxp.Write(filePath);
            return(true);
        }