Пример #1
0
        public static string CreateWaveForm(string name, QWaveForm wf, string timeVar)
        {
            if (wf == null)
            {
                return("float " + name + " = 0.0;");
            }

            if (timeVar.Equals(""))
            {
                timeVar = "g_time";
            }

            string funcName = "";

            switch (wf.Name)
            {
            case "sin":
                //retorna: float name = base + sin(( pha + t*freq )*2PI)*Amp;
                return("float " + name + " = " + ParserTools.ToString(wf.Bas) + " + sin((" + ParserTools.ToString(wf.Phase) + " + " +
                       timeVar + " * " + ParserTools.ToString(wf.Freq) + ") * 6.283) * " + ParserTools.ToString(wf.Amp) + ";");

            case "square":
                funcName = "square";
                break;

            case "triangle":
                funcName = "triangle";
                break;

            case "sawtooth":
                funcName = "frac";
                break;

            case "inversesawtooth":
                funcName = "1.0 - frac";
                break;

            default:
                return("float " + name + " = 0.0;");
            }
            //retorna: float varname = base + func(pha + t*freq)*Amp;
            return("float " + name + " = " + ParserTools.ToString(wf.Bas) + " + " + funcName + "(" + ParserTools.ToString(wf.Phase) + " + " +
                   timeVar + " * " + ParserTools.ToString(wf.Freq) + ") * " + ParserTools.ToString(wf.Amp) + ";");
        }
Пример #2
0
        public static string CreateWaveForm(string name, QWaveForm wf, string timeVar)
        {
            if(wf==null)
            {
                return "float " + name + " = 0.0;";
            }

            if(timeVar.Equals(""))
            {
                timeVar = "g_time";
            }

            string funcName = "";

            switch(wf.Name)
            {

                case "sin":
                    //retorna: float name = base + sin(( pha + t*freq )*2PI)*Amp;
                    return "float " + name + " = " + ParserTools.ToString(wf.Bas) + " + sin((" + ParserTools.ToString(wf.Phase) + " + " +
                           timeVar + " * " + ParserTools.ToString(wf.Freq) + ") * 6.283) * " + ParserTools.ToString(wf.Amp) + ";";

                case "square":
                    funcName = "square";
                    break;
                case "triangle":
                    funcName = "triangle";
                    break;
                case "sawtooth":
                    funcName = "frac";
                    break;
                case "inversesawtooth":
                    funcName = "1.0 - frac";
                    break;
                default:
                    return "float " + name + " = 0.0;";
            }
            //retorna: float varname = base + func(pha + t*freq)*Amp;
            return "float " + name + " = " + ParserTools.ToString(wf.Bas) + " + " + funcName + "(" + ParserTools.ToString(wf.Phase) + " + " +
                   timeVar + " * " + ParserTools.ToString(wf.Freq) + ") * " + ParserTools.ToString(wf.Amp) + ";";
        
            
        }