Esempio n. 1
0
        private void loadProgramFile(string file)
        {
            //StreamReader reader = new StreamReader(File.Open(file, FileMode.Open));
            StreamReader reader = new StreamReader(Application.GetResourceStream(new Uri(file, UriKind.Relative)).Stream);

            if (!reader.ReadLine().Trim().ToUpper().Equals("[FM INSTRUMENT]"))
            {
                reader.Close();
                throw new InvalidDataException("Invalid Program file: Incorrect Header!");
            }
            string[] args = reader.ReadLine().Split(new string[] { "|" }, StringSplitOptions.None);
            if (args.Length < 4)
            {
                reader.Close();
                throw new InvalidDataException("Invalid Program file: Parameters are missing");
            }
            this.baseWaveType = SynthHelper.getTypeFromString(args[0]);
            this.modWaveType  = SynthHelper.getTypeFromString(args[1]);
            this.mfreq        = getOpsAndValues(args[2], true);
            this.mamp         = getOpsAndValues(args[3], false);
            args = reader.ReadLine().Split(new string[] { "|" }, StringSplitOptions.None);
            if (args.Length < 3)
            {
                reader.Close();
                throw new InvalidDataException("Invalid Program file: Parameters are missing");
            }
            if (int.Parse(args[0]) == 0)
            {
                looping = true;
            }
            start_time = double.Parse(args[1]);
            end_time   = double.Parse(args[2]);
            args       = reader.ReadLine().Split(new string[] { "|" }, StringSplitOptions.None);
            if (args.Length < 3)
            {
                reader.Close();
                throw new InvalidDataException("Invalid Program file: Parameters are missing");
            }
            switch (args[0].ToLower().Trim())
            {
            case "fadein":
                env = Envelope.CreateBasicFadeIn(double.Parse(args[2]));
                break;

            case "fadeout":
                env = Envelope.CreateBasicFadeOut(double.Parse(args[2]));
                break;

            case "fadein&out":
                double p = double.Parse(args[2]) / 2.0;
                env = Envelope.CreateBasicFadeInAndOut(p, p);
                break;

            default:
                env = Envelope.CreateBasicConstant();
                break;
            }
            env.Peak = double.Parse(args[1]);
            reader.Close();
        }
Esempio n. 2
0
        private void loadProgramFile(string file)
        {
            StreamReader reader = new StreamReader(PlatformHelper.StreamLoad(file));

            if (!reader.ReadLine().Trim().ToUpper().Equals("[FM INSTRUMENT]"))
            {
                reader.Close();
                throw new Exception("Invalid Program file: Incorrect Header!");
            }
            string[] args = reader.ReadLine().Split(new string[] { "|" }, StringSplitOptions.None);
            if (args.Length < 4)
            {
                reader.Close();
                throw new Exception("Invalid Program file: Parameters are missing");
            }
            this.baseWaveType = SynthHelper.getTypeFromString(args[0]);
            this.modWaveType  = SynthHelper.getTypeFromString(args[1]);
            this.mfreq        = (ModulatorFrequencyFunction)getOpsAndValues(args[2], true);
            this.mamp         = (ModulatorAmplitudeFunction)getOpsAndValues(args[3], false);
            args = reader.ReadLine().Split(new string[] { "|" }, StringSplitOptions.None);
            if (args.Length < 3)
            {
                reader.Close();
                throw new Exception("Invalid Program file: Parameters are missing");
            }
            if (int.Parse(args[0]) == 0)
            {
                looping = true;
            }
            start_time = double.Parse(args[1]);
            end_time   = double.Parse(args[2]);
            args       = reader.ReadLine().Split(new string[] { "|" }, StringSplitOptions.None);
            if (args.Length < 3)
            {
                reader.Close();
                throw new Exception("Invalid Program file: Parameters are missing");
            }
            switch (args[0].ToLower().Trim())
            {
            case "fadein":
                env = Envelope.CreateBasicFadeIn(double.Parse(args[2]));
                break;

            case "fadeout":
                env = Envelope.CreateBasicFadeOut(double.Parse(args[2]));
                break;

            case "fadein&out":
                double p = double.Parse(args[2]) / 2.0;
                env = Envelope.CreateBasicFadeInAndOut(p, p);
                break;

            default:
                env = Envelope.CreateBasicConstant();
                break;
            }
            env.Peak = double.Parse(args[1]);
            reader.Close();
        }
Esempio n. 3
0
        private void loadProgramFile(string file)
        {
            //Debug.LogError("dload :" + file);
            //UnitySynth
            //StreamReader reader = new StreamReader(File.Open(file, FileMode.Open));
            //Debug.Log(this.ToString() + " AppDataPath " + Application.dataPath + " Filename: " + file);
            var          bytes  = Resources.Load <TextAsset>(file).bytes;
            StreamReader reader = new StreamReader(new System.IO.MemoryStream(bytes));

            //StreamReader reader = new StreamReader(Application.dataPath + "/Resources/" + file);

            if (!reader.ReadLine().Trim().ToUpper().Equals("[FM INSTRUMENT]"))
            {
                reader.Close();
                throw new Exception("Invalid Program file: Incorrect Header!");
            }
            string[] args = reader.ReadLine().Split(new string[] { "|" }, StringSplitOptions.None);
            if (args.Length < 4)
            {
                reader.Close();
                throw new Exception("Invalid Program file: Parameters are missing");
            }
            this.baseWaveType = SynthHelper.getTypeFromString(args[0]);
            this.modWaveType  = SynthHelper.getTypeFromString(args[1]);
            this.mfreq        = getOpsAndValues(args[2], true);
            this.mamp         = getOpsAndValues(args[3], false);
            args = reader.ReadLine().Split(new string[] { "|" }, StringSplitOptions.None);
            if (args.Length < 3)
            {
                reader.Close();
                throw new Exception("Invalid Program file: Parameters are missing");
            }
            if (int.Parse(args[0]) == 0)
            {
                looping = true;
            }
            start_time = double.Parse(args[1]);
            end_time   = double.Parse(args[2]);
            args       = reader.ReadLine().Split(new string[] { "|" }, StringSplitOptions.None);
            if (args.Length < 3)
            {
                reader.Close();
                throw new Exception("Invalid Program file: Parameters are missing");
            }
            switch (args[0].ToLower().Trim())
            {
            case "fadein":
                env = Envelope.CreateBasicFadeIn(double.Parse(args[2]));
                break;

            case "fadeout":
                env = Envelope.CreateBasicFadeOut(double.Parse(args[2]));
                break;

            case "fadein&out":
                double p = double.Parse(args[2]) / 2.0;
                env = Envelope.CreateBasicFadeInAndOut(p, p);
                break;

            default:
                env = Envelope.CreateBasicConstant();
                break;
            }
            env.Peak = double.Parse(args[1]);
            reader.Close();
        }