Beispiel #1
0
            private void Update_Graph(object sender, EventArgs e)
            {
                Analysis_View.GraphPane.CurveList.Clear();

                int REC_ID = 0;

                try
                {
                    REC_ID = int.Parse(Receiver_Choice.Text);

                    int OCT_ID = PachTools.OctaveStr2Int(Graph_Octave.Text);
                    Analysis_View.GraphPane.Title.Text       = "Logarithmic Energy Time Curve";
                    Analysis_View.GraphPane.XAxis.Title.Text = "Time (seconds)";
                    Analysis_View.GraphPane.YAxis.Title.Text = "Sound Pressure Level (dB)";

                    List <int> SrcIDs = new List <int>();
                    foreach (int i in SourceList.CheckedIndices)
                    {
                        SrcIDs.Add(i);
                    }

                    //List<double[]> Filter = new List<double[]>();
                    List <System.Drawing.Color> C = new List <System.Drawing.Color> {
                        System.Drawing.Color.Red, System.Drawing.Color.OrangeRed, System.Drawing.Color.Orange, System.Drawing.Color.DarkGoldenrod, System.Drawing.Color.Olive, System.Drawing.Color.Green, System.Drawing.Color.Aquamarine, System.Drawing.Color.Azure, System.Drawing.Color.Blue, System.Drawing.Color.Indigo, System.Drawing.Color.Violet
                    };

                    double[][] Temp;

                    switch (DistributionType.Text)
                    {
                    case "Monaural":
                        Response    = new double[1][];
                        Response[0] = (AcousticalMath.PTCurve(Direct_Data, IS_Data, Receiver, CutoffTime, SampleRate, REC_ID, SrcIDs, false));
                        break;

                    case "First Order Ambisonics":
                        Response    = new double[4][];
                        Temp        = AcousticalMath.PTCurve_Fig8_3Axis(Direct_Data, IS_Data, Receiver, CutoffTime, SampleRate, Receiver_Choice.SelectedIndex, SelectedSources(), false, (double)Alt_Choice.Value, (double)Azi_Choice.Value, true);
                        Response[0] = AcousticalMath.PTCurve(Direct_Data, IS_Data, Receiver, CutoffTime, SampleRate, REC_ID, SrcIDs, false);
                        Response[1] = Temp[0];
                        Response[2] = Temp[1];
                        Response[3] = Temp[2];
                        break;

                    case "Second Order Ambisonics":
                        Response    = new double[9][];
                        Temp        = AcousticalMath.PTCurve_Fig8_3Axis(Direct_Data, IS_Data, Receiver, CutoffTime, SampleRate, Receiver_Choice.SelectedIndex, SelectedSources(), false, (double)Alt_Choice.Value, (double)Azi_Choice.Value, true);
                        Response[0] = AcousticalMath.PTCurve(Direct_Data, IS_Data, Receiver, CutoffTime, SampleRate, REC_ID, SrcIDs, false);
                        Response[1] = Temp[0];
                        Response[2] = Temp[1];
                        Response[3] = Temp[2];
                        Temp        = AcousticalMath.PTCurve_Ambisonics2(Direct_Data, IS_Data, Receiver, CutoffTime, SampleRate, Receiver_Choice.SelectedIndex, SelectedSources(), false, (double)Alt_Choice.Value, (double)Azi_Choice.Value, true);
                        Response[4] = Temp[0];
                        Response[5] = Temp[1];
                        Response[6] = Temp[2];
                        Response[7] = Temp[3];
                        Response[8] = Temp[4];
                        break;

                    case "Third Order Ambisonics":
                        Response     = new double[16][];
                        Temp         = AcousticalMath.PTCurve_Fig8_3Axis(Direct_Data, IS_Data, Receiver, CutoffTime, SampleRate, Receiver_Choice.SelectedIndex, SelectedSources(), false, (double)Alt_Choice.Value, (double)Azi_Choice.Value, true);
                        Response[0]  = AcousticalMath.PTCurve(Direct_Data, IS_Data, Receiver, CutoffTime, SampleRate, REC_ID, SrcIDs, false);
                        Response[1]  = Temp[0];
                        Response[2]  = Temp[1];
                        Response[3]  = Temp[2];
                        Temp         = AcousticalMath.PTCurve_Ambisonics2(Direct_Data, IS_Data, Receiver, CutoffTime, SampleRate, Receiver_Choice.SelectedIndex, SelectedSources(), false, (double)Alt_Choice.Value, (double)Azi_Choice.Value, true);
                        Response[4]  = Temp[0];
                        Response[5]  = Temp[1];
                        Response[6]  = Temp[2];
                        Response[7]  = Temp[3];
                        Response[8]  = Temp[4];
                        Temp         = AcousticalMath.PTCurve_Ambisonics3(Direct_Data, IS_Data, Receiver, CutoffTime, SampleRate, Receiver_Choice.SelectedIndex, SelectedSources(), false, (double)Alt_Choice.Value, (double)Azi_Choice.Value, true);
                        Response[9]  = Temp[0];
                        Response[10] = Temp[1];
                        Response[11] = Temp[2];
                        Response[12] = Temp[3];
                        Response[13] = Temp[4];
                        Response[14] = Temp[5];
                        Response[15] = Temp[6];
                        break;

                    default:
                        Response = new double[Channel_View.Items.Count][];
                        for (int i = 0; i < Channel_View.Items.Count; i++)
                        {
                            double alt = -(double)Alt_Choice.Value + 180 * Math.Asin((Channel_View.Items[i] as channel).V.z) / Math.PI;
                            double azi = (double)Azi_Choice.Value + 180 * Math.Atan2((Channel_View.Items[i] as channel).V.y, (Channel_View.Items[i] as channel).V.x) / Math.PI;
                            if (alt > 90)
                            {
                                alt -= 180;
                            }
                            if (alt < -90)
                            {
                                alt += 180;
                            }
                            if (azi > 360)
                            {
                                azi -= 360;
                            }
                            if (azi < 0)
                            {
                                azi += 360;
                            }
                            Response[i] = AcousticalMath.PTCurve_Directional(Direct_Data, IS_Data, Receiver, CutoffTime, SampleRate, PachTools.OctaveStr2Int(Graph_Octave.Text), REC_ID, SrcIDs, false, alt, azi, true);
                        }
                        break;
                    }

                    //Get the maximum value of the Direct Sound
                    double DirectMagnitude = 0;
                    foreach (int i in SourceList.CheckedIndices)
                    {
                        double[] E = Direct_Data[i].EnergyValue(OCT_ID, REC_ID);
                        for (int j = 0; j < E.Length; j++)
                        {
                            double D = AcousticalMath.SPL_Intensity(E[j]);
                            if (D > DirectMagnitude)
                            {
                                DirectMagnitude = D;
                            }
                        }
                    }

                    double[] time = new double[Response[0].Length];
                    for (int i = 0; i < Response[0].Length; i++)
                    {
                        time[i] = (double)i / SampleRate - 1024f / SampleRate;
                    }

                    for (int i = 0; i < Response.Length; i++)
                    {
                        double[] filter = Audio.Pach_SP.FIR_Bandpass(Response[i], OCT_ID, SampleRate, 0);
                        Analysis_View.GraphPane.AddCurve(String.Format("Channel {0}", i), time, AcousticalMath.SPL_Pressure_Signal(filter), C[i % 10], ZedGraph.SymbolType.None);
                    }
                    Analysis_View.GraphPane.XAxis.Scale.Max = time[time.Length - 1];
                    Analysis_View.GraphPane.XAxis.Scale.Min = time[0];
                    Analysis_View.GraphPane.YAxis.Scale.Max = DirectMagnitude + 15;
                    Analysis_View.GraphPane.YAxis.Scale.Min = 0;

                    //AuralisationConduit.Instance.set_direction(Receiver[0].Origin(Receiver_Choice.SelectedIndex), new Rhino.Geometry.Vector3d(Math.Cos((float)Azi_Choice.Value * Math.PI / 180.0f) * Math.Cos((float)Alt_Choice.Value * Math.PI / 180.0f), Math.Sin((float)Azi_Choice.Value * Math.PI / 180.0f) * Math.Cos((float)Alt_Choice.Value * Math.PI / 180.0f), Math.Sin((float)Alt_Choice.Value * Math.PI / 180.0f)));
                    Rhino.RhinoDoc.ActiveDoc.Views.Redraw();
                }
                catch { return; }
                Analysis_View.AxisChange();
                Analysis_View.Invalidate();
                Draw_Feedback();
            }