Пример #1
0
        public MainWindow()
        {
            lesdatas = new SoundPArameters(this);

            InitializeComponent();

            lesseries = new SeriesCollection
            {
                new LineSeries
                {
                    Values = new ChartValues <ObservablePoint>
                    {
                        new ObservablePoint(0, 0),
                        new ObservablePoint(100, 0),
                        new ObservablePoint(100, 50),
                        new ObservablePoint(110, 50),
                        new ObservablePoint(110, 0),
                        new ObservablePoint(600, 0)
                    },

                    LineSmoothness    = 0,
                    PointGeometrySize = 0,
                    StrokeThickness   = 1,
                    Stroke            = new SolidColorBrush(Colors.DarkRed),
                    Fill = new SolidColorBrush(Colors.Pink)
                },


                new LineSeries
                {
                    Values = new ChartValues <ObservablePoint>
                    {
                        new ObservablePoint(0, 0),
                        new ObservablePoint(500, 0),
                        new ObservablePoint(500, 100),
                        new ObservablePoint(510, 100),
                        new ObservablePoint(510, 0),
                        new ObservablePoint(600, 0)
                    },

                    LineSmoothness    = 0,
                    PointGeometrySize = 0,
                    StrokeThickness   = 1,
                    Stroke            = new SolidColorBrush(Colors.DarkRed),
                    Fill = new SolidColorBrush(Colors.Red)
                },

                new LineSeries
                {
                    Values = new ChartValues <ObservablePoint>
                    {
                        new ObservablePoint(490, 0),
                        new ObservablePoint(490, 80),
                        new ObservablePoint(505, 80),
                        new ObservablePoint(505, 0)
                    },
                    LineSmoothness    = 0,
                    PointGeometrySize = 0,
                    StrokeThickness   = 1,
                    Opacity           = .2,
                    Fill = new SolidColorBrush(new Color {
                        R = Colors.AliceBlue.R, G = Colors.AliceBlue.G, B = Colors.AliceBlue.B, A = 150
                    }),
                    Stroke = new SolidColorBrush(new Color {
                        R = 0, A = 150, G = 0, B = 255
                    })
                }
            };

            DataContext           = this;
            ReglPulse.DataContext = this.lesdatas;
            ReglPpi.DataContext   = this.lesdatas;
            ReglLight.DataContext = this.lesdatas;
            //txtPulsDelay.DataContext = this;
        }
Пример #2
0
        // genere le buffer
        public int gendata(SoundPArameters lesdata)
        {
            int  freq         = int.Parse(lesdata.stimFreq);
            int  ppiatt       = int.Parse(lesdata.ppiAtten);
            int  ppistart     = lesdata.debPPi;
            uint ppinbcycles  = uint.Parse(lesdata.ppiDuration);
            int  stimstart    = int.Parse(lesdata.stimDelay);
            uint stimnbcycles = uint.Parse(lesdata.stimDuration);
            int  stimduree    = (int)float.Parse(lesdata.stimAbsDur);

            int    totaldur      = stimstart + stimduree + 100; // rajouote 100ms de silence a la fin
            uint   nbsample      = (uint)totaldur * 96;         // a 96 khz
            int    levelstim     = int.Parse(lesdata.stimAtten);
            double stimamplit    = Math.Pow(-levelstim / 10.0, 10);
            int    levelppi      = int.Parse(lesdata.ppiAtten);
            int    lightstrt     = int.Parse(lesdata.lightDelay);
            uint   lightnbcycles = uint.Parse(lesdata.lightDuration);

            lightnbcycles = (uint)(lightnbcycles * 10000.0 / (double)freq);  // calcul du nb ech de lumiere sachant qu'on definit sa longueur en nb cycles audio

            uint buffersize = (uint)totaldur * 2 * 96;

            //taille complete du uffer
            ledata.floatArray = new float[buffersize];
            uint i;

            for (i = 0; i < buffersize; i++)
            {
                ledata.floatArray[i] = (float)0.0;
            }

            //int amplitude = 32000;
            double stimlevel = Math.Pow(10, -levelstim / 10);
            double ppilevel  = stimlevel * Math.Pow(10, -levelppi / 10);
            double t         = (double)(lechunk.dwSamplesPerSec) / (double)freq;// ombre echantilllons d'un cycle

            int canal = 0;
            //double freqpi = 2.0 * Math.PI * freq;
            double freqpi = 2.0 * Math.PI / lechunk.dwSamplesPerSec * freq;

            uint nbsamplespulse = (uint)t * ppinbcycles;
            int  offsetppi      = ppistart * 96;

            for (i = 0; i < nbsamplespulse; i++)
            {
                ledata.floatArray[2 * offsetppi + 2 * i + canal] = (float)ppilevel * (float)(Math.Sin(freqpi * (double)i));
            }

            nbsamplespulse = (uint)t * stimnbcycles;
            int offsetstim = 2 * (stimstart * 96); // x2 car en stereo il faut 2 echantillons pour chaque ecahntillon

            for (i = 0; i < nbsamplespulse; i++)
            {
                ledata.floatArray[offsetstim + 2 * i + canal] = (float)stimlevel * (float)(Math.Sin(freqpi * (double)i));
            }

            // envoi lumiere sur lautre canal
            freqpi         = 2.0 * Math.PI / lechunk.dwSamplesPerSec * 10000.0;
            canal          = 1 - canal;                                         // on passe sur l'autre canal
            t              = (double)(lechunk.dwSamplesPerSec) / (double)10000; // ombre echantilllons d'un cycle
            nbsamplespulse = (uint)t * lightnbcycles;
            int    offsetlight = 2 * (lightstrt * 96);                          // x2 car en stereo il faut 2 echantillons pour chaque ecahntillon
            double lightamplit = 1.0;

            for (i = 0; i < nbsamplespulse; i++)
            {
                float Value = (float)lightamplit * (float)(Math.Sin(freqpi * (double)i));
                //String outputstr = Value.ToString()+" ";
                //Debug.Write(outputstr);
                ledata.floatArray[offsetlight + 2 * i + canal] = Value;
            }

            ledata.dwChunkSize = buffersize * 4;

            return(0);
        }